09 August 2015

ChartEasingOption


// 平滑过度选项
@objc
public enum ChartEasingOption: Int
{
    case Linear
    case EaseInQuad
    case EaseOutQuad
    case EaseInOutQuad
    case EaseInCubic
    case EaseOutCubic
    case EaseInOutCubic
    case EaseInQuart
    case EaseOutQuart
    case EaseInOutQuart
    case EaseInQuint
    case EaseOutQuint
    case EaseInOutQuint
    case EaseInSine
    case EaseOutSine
    case EaseInOutSine
    case EaseInExpo
    case EaseOutExpo
    case EaseInOutExpo
    case EaseInCirc
    case EaseOutCirc
    case EaseInOutCirc
    case EaseInElastic
    case EaseOutElastic
    case EaseInOutElastic
    case EaseInBack
    case EaseOutBack
    case EaseInOutBack
    case EaseInBounce
    case EaseOutBounce
    case EaseInOutBounce
}

// elapsed: v. 时间过去;消逝(elapse的过去分词) // duration: n. 持续,持续的时间,期间 public typealias ChartEasingFunctionBlock = ((elapsed: NSTimeInterval, duration: NSTimeInterval) -> CGFloat)

// 根据动画过渡类型,获取动画函数 internal func easingFunctionFromOption(easing: ChartEasingOption) -> ChartEasingFunctionBlock { switch easing { case .Linear: return EasingFunctions.Linear case .EaseInQuad: return EasingFunctions.EaseInQuad case .EaseOutQuad: return EasingFunctions.EaseOutQuad case .EaseInOutQuad: return EasingFunctions.EaseInOutQuad case .EaseInCubic: return EasingFunctions.EaseInCubic case .EaseOutCubic: return EasingFunctions.EaseOutCubic case .EaseInOutCubic: return EasingFunctions.EaseInOutCubic case .EaseInQuart: return EasingFunctions.EaseInQuart case .EaseOutQuart: return EasingFunctions.EaseOutQuart case .EaseInOutQuart: return EasingFunctions.EaseInOutQuart case .EaseInQuint: return EasingFunctions.EaseInQuint case .EaseOutQuint: return EasingFunctions.EaseOutQuint case .EaseInOutQuint: return EasingFunctions.EaseInOutQuint case .EaseInSine: return EasingFunctions.EaseInSine case .EaseOutSine: return EasingFunctions.EaseOutSine case .EaseInOutSine: return EasingFunctions.EaseInOutSine case .EaseInExpo: return EasingFunctions.EaseInExpo case .EaseOutExpo: return EasingFunctions.EaseOutExpo case .EaseInOutExpo: return EasingFunctions.EaseInOutExpo case .EaseInCirc: return EasingFunctions.EaseInCirc case .EaseOutCirc: return EasingFunctions.EaseOutCirc case .EaseInOutCirc: return EasingFunctions.EaseInOutCirc case .EaseInElastic: return EasingFunctions.EaseInElastic case .EaseOutElastic: return EasingFunctions.EaseOutElastic case .EaseInOutElastic: return EasingFunctions.EaseInOutElastic case .EaseInBack: return EasingFunctions.EaseInBack case .EaseOutBack: return EasingFunctions.EaseOutBack case .EaseInOutBack: return EasingFunctions.EaseInOutBack case .EaseInBounce: return EasingFunctions.EaseInBounce case .EaseOutBounce: return EasingFunctions.EaseOutBounce case .EaseInOutBounce: return EasingFunctions.EaseInOutBounce } }

// 平滑过度函数 internal struct EasingFunctions { internal static let Linear = { (elapsed: NSTimeInterval, duration: NSTimeInterval) -> CGFloat in return CGFloat(elapsed / duration); }

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInQuad</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutQuad</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="k">return</span> <span class="o">-</span><span class="n">position</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">-</span> <span class="mf">2.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutQuad</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">))</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="p">((</span><span class="o">--</span><span class="n">position</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">-</span> <span class="mf">2.0</span><span class="p">)</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInCubic</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutCubic</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="n">position</span><span class="o">--</span>
    <span class="nf">return</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutCubic</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">))</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
    <span class="p">}</span>
    <span class="n">position</span> <span class="o">-=</span> <span class="mf">2.0</span>
    <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">2.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInQuart</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutQuart</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="n">position</span><span class="o">--</span>
    <span class="k">return</span> <span class="o">-</span><span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutQuart</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">))</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
    <span class="p">}</span>
    <span class="n">position</span> <span class="o">-=</span> <span class="mf">2.0</span>
    <span class="k">return</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">-</span> <span class="mf">2.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInQuint</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutQuint</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="n">position</span><span class="o">--</span>
    <span class="nf">return</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutQuint</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">))</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span>
    <span class="p">}</span>
    <span class="k">else</span>
    <span class="p">{</span>
        <span class="n">position</span> <span class="o">-=</span> <span class="mf">2.0</span>
        <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInSine</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="o">-</span><span class="nf">cos</span><span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="kt">M_PI_2</span><span class="p">)</span> <span class="o">+</span> <span class="mf">1.0</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutSine</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="nf">sin</span><span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="kt">M_PI_2</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutSine</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="nf">cos</span><span class="p">(</span><span class="kt">M_PI</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInExpo</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="nf">return</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">?</span> <span class="mf">0.0</span> <span class="p">:</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="mf">10.0</span> <span class="o">*</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)))</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutExpo</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="nf">return</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="n">duration</span><span class="p">)</span> <span class="p">?</span> <span class="mf">1.0</span> <span class="p">:</span> <span class="p">(</span><span class="o">-</span><span class="kt">CGFloat</span><span class="p">(</span><span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="o">-</span><span class="mf">10.0</span> <span class="o">*</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">))</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutExpo</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.0</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="n">duration</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">1.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="mf">10.0</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">))</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="o">-</span><span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="o">-</span><span class="mf">10.0</span> <span class="o">*</span> <span class="o">--</span><span class="n">position</span><span class="p">)</span> <span class="o">+</span> <span class="mf">2.0</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInCirc</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="k">return</span> <span class="o">-</span><span class="p">(</span><span class="kt">CGFloat</span><span class="p">(</span><span class="nf">sqrt</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span><span class="p">))</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutCirc</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
    <span class="n">position</span><span class="o">--</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="nf">sqrt</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutCirc</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="nf">sqrt</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="n">position</span> <span class="o">-=</span> <span class="mf">2.0</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="nf">sqrt</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInElastic</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">==</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">1.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">p</span> <span class="o">=</span> <span class="n">duration</span> <span class="o">*</span> <span class="mf">0.3</span>
    <span class="k">var</span> <span class="nv">s</span> <span class="o">=</span> <span class="n">p</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">*</span> <span class="nf">asin</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
    <span class="n">position</span> <span class="o">-=</span> <span class="mf">1.0</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="o">-</span><span class="p">(</span><span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="mf">10.0</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">*</span> <span class="nf">sin</span><span class="p">((</span><span class="n">position</span> <span class="o">*</span> <span class="n">duration</span> <span class="o">-</span> <span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span><span class="p">))</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutElastic</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">==</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">1.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">p</span> <span class="o">=</span> <span class="n">duration</span> <span class="o">*</span> <span class="mf">0.3</span>
    <span class="k">var</span> <span class="nv">s</span> <span class="o">=</span> <span class="n">p</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">*</span> <span class="nf">asin</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="o">-</span><span class="mf">10.0</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">*</span> <span class="nf">sin</span><span class="p">((</span><span class="n">position</span> <span class="o">*</span> <span class="n">duration</span> <span class="o">-</span> <span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span><span class="p">)</span> <span class="o">+</span> <span class="mf">1.0</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutElastic</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">0.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">==</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="mf">1.0</span>
    <span class="p">}</span>

    <span class="k">var</span> <span class="nv">p</span> <span class="o">=</span> <span class="n">duration</span> <span class="o">*</span> <span class="p">(</span><span class="mf">0.3</span> <span class="o">*</span> <span class="mf">1.5</span><span class="p">)</span>
    <span class="k">var</span> <span class="nv">s</span> <span class="o">=</span> <span class="n">p</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">*</span> <span class="nf">asin</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">position</span> <span class="o">-=</span> <span class="mf">1.0</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="mf">10.0</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">*</span> <span class="nf">sin</span><span class="p">((</span><span class="n">position</span> <span class="o">*</span> <span class="n">duration</span> <span class="o">-</span> <span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span><span class="p">))</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="n">position</span> <span class="o">-=</span> <span class="mf">1.0</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="nf">pow</span><span class="p">(</span><span class="mf">2.0</span><span class="p">,</span> <span class="o">-</span><span class="mf">10.0</span> <span class="o">*</span> <span class="n">position</span><span class="p">)</span> <span class="o">*</span> <span class="nf">sin</span><span class="p">((</span><span class="n">position</span> <span class="o">*</span> <span class="n">duration</span> <span class="o">-</span> <span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="kt">M_PI</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span> <span class="o">+</span> <span class="mf">1.0</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInBack</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">let</span> <span class="nv">s</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">1.70158</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="p">((</span><span class="n">s</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span> <span class="o">*</span> <span class="n">position</span> <span class="o">-</span> <span class="n">s</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutBack</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">let</span> <span class="nv">s</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">1.70158</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="n">position</span><span class="o">--</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="p">((</span><span class="n">s</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="n">s</span><span class="p">)</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutBack</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">s</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">1.70158</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">s</span> <span class="o">*=</span> <span class="mf">1.525</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="p">((</span><span class="n">s</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span> <span class="o">*</span> <span class="n">position</span> <span class="o">-</span> <span class="n">s</span><span class="p">))</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="n">s</span> <span class="o">*=</span> <span class="mf">1.525</span>
    <span class="n">position</span> <span class="o">-=</span> <span class="mf">2.0</span>
    <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="p">((</span><span class="n">s</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="n">s</span><span class="p">)</span> <span class="o">+</span> <span class="mf">2.0</span><span class="p">)</span> <span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInBounce</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">return</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="kt">EaseOutBounce</span><span class="p">(</span><span class="n">duration</span> <span class="o">-</span> <span class="n">elapsed</span><span class="p">,</span> <span class="n">duration</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseOutBounce</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">var</span> <span class="nv">position</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">/</span> <span class="mf">2.75</span><span class="p">))</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">7.5625</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">/</span> <span class="mf">2.75</span><span class="p">))</span>
    <span class="p">{</span>
        <span class="n">position</span> <span class="o">-=</span> <span class="p">(</span><span class="mf">1.5</span> <span class="o">/</span> <span class="mf">2.75</span><span class="p">)</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">7.5625</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">0.75</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">position</span> <span class="o">&lt;</span> <span class="p">(</span><span class="mf">2.5</span> <span class="o">/</span> <span class="mf">2.75</span><span class="p">))</span>
    <span class="p">{</span>
        <span class="n">position</span> <span class="o">-=</span> <span class="p">(</span><span class="mf">2.25</span> <span class="o">/</span> <span class="mf">2.75</span><span class="p">)</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">7.5625</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">0.9375</span> <span class="p">)</span>
    <span class="p">}</span>
    <span class="k">else</span>
    <span class="p">{</span>
        <span class="n">position</span> <span class="o">-=</span> <span class="p">(</span><span class="mf">2.625</span> <span class="o">/</span> <span class="mf">2.75</span><span class="p">)</span>
        <span class="k">return</span> <span class="kt">CGFloat</span><span class="p">(</span> <span class="mf">7.5625</span> <span class="o">*</span> <span class="n">position</span> <span class="o">*</span> <span class="n">position</span> <span class="o">+</span> <span class="mf">0.984375</span> <span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">internal</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">EaseInOutBounce</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CGFloat</span> <span class="k">in</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">&lt;</span> <span class="p">(</span><span class="n">duration</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">))</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="kt">EaseInBounce</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">*</span> <span class="mf">2.0</span><span class="p">,</span> <span class="n">duration</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="kt">EaseOutBounce</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">*</span> <span class="mf">2.0</span> <span class="o">-</span> <span class="n">duration</span><span class="p">,</span> <span class="n">duration</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span> <span class="o">+</span> <span class="mf">0.5</span>
<span class="p">}</span>

}

ChartAnimator


@objc
public protocol ChartAnimatorDelegate
{
    /// Called when the Animator has stepped.
    /// 动画执行时调用
    func chartAnimatorUpdated(chartAnimator: ChartAnimator)

<span class="c1">/// Called when the Animator has stopped.</span>
<span class="c1">/// 动画结束时调用</span>
<span class="kd">func</span> <span class="nf">chartAnimatorStopped</span><span class="p">(</span><span class="nv">chartAnimator</span><span class="p">:</span> <span class="kt">ChartAnimator</span><span class="p">)</span>

}

public class ChartAnimator: NSObject { public weak var delegate: ChartAnimatorDelegate? public var updateBlock: (() -> Void)? public var stopBlock: (() -> Void)?

<span class="c1">/// the phase that is animated and influences the drawn values on the y-axis</span>
<span class="c1">/// x相位 影响y轴绘值</span>
<span class="kd">public</span> <span class="k">var</span> <span class="nv">phaseX</span><span class="p">:</span> <span class="kt">CGFloat</span> <span class="o">=</span> <span class="mf">1.0</span>

<span class="c1">/// the phase that is animated and influences the drawn values on the y-axis</span>
<span class="c1">/// y相位 影响y轴绘值</span>
<span class="kd">public</span> <span class="k">var</span> <span class="nv">phaseY</span><span class="p">:</span> <span class="kt">CGFloat</span> <span class="o">=</span> <span class="mf">1.0</span>

<span class="kd">private</span> <span class="k">var</span> <span class="nv">_startTime</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="kd">private</span> <span class="k">var</span> <span class="nv">_displayLink</span><span class="p">:</span> <span class="kt">CADisplayLink</span><span class="o">!</span>

<span class="kd">private</span> <span class="k">var</span> <span class="nv">_xDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="kd">private</span> <span class="k">var</span> <span class="nv">_yDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">0.0</span>

<span class="kd">private</span> <span class="k">var</span> <span class="nv">_endTimeX</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="kd">private</span> <span class="k">var</span> <span class="nv">_endTimeY</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="kd">private</span> <span class="k">var</span> <span class="nv">_endTime</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="mf">0.0</span>

<span class="kd">private</span> <span class="k">var</span> <span class="nv">_enabledX</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">false</span>
<span class="kd">private</span> <span class="k">var</span> <span class="nv">_enabledY</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">false</span>

<span class="kd">private</span> <span class="k">var</span> <span class="nv">_easingX</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?</span>
<span class="kd">private</span> <span class="k">var</span> <span class="nv">_easingY</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?</span>

<span class="kd">public</span> <span class="k">override</span> <span class="nf">init</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">init</span><span class="p">()</span>
<span class="p">}</span>

<span class="kd">deinit</span>
<span class="p">{</span>
    <span class="nf">stop</span><span class="p">()</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="kd">func</span> <span class="nf">stop</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_displayLink</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_displayLink</span><span class="o">.</span><span class="nf">removeFromRunLoop</span><span class="p">(</span><span class="kt">NSRunLoop</span><span class="o">.</span><span class="nf">mainRunLoop</span><span class="p">(),</span> <span class="nv">forMode</span><span class="p">:</span> <span class="kt">NSRunLoopCommonModes</span><span class="p">)</span>
        <span class="n">_displayLink</span> <span class="o">=</span> <span class="kc">nil</span>

        <span class="n">_enabledX</span> <span class="o">=</span> <span class="kc">false</span>
        <span class="n">_enabledY</span> <span class="o">=</span> <span class="kc">false</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">delegate</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">delegate</span><span class="o">!.</span><span class="nf">chartAnimatorStopped</span><span class="p">(</span><span class="k">self</span><span class="p">)</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">stopBlock</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="nf">stopBlock</span><span class="p">?()</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">private</span> <span class="kd">func</span> <span class="nf">updateAnimationPhases</span><span class="p">(</span><span class="nv">currentTime</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">var</span> <span class="nv">elapsedTime</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">currentTime</span> <span class="o">-</span> <span class="n">_startTime</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_enabledX</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">var</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">_xDuration</span>
        <span class="k">var</span> <span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsedTime</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">&gt;</span> <span class="n">duration</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">elapsed</span> <span class="o">=</span> <span class="n">duration</span>
        <span class="p">}</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">_easingX</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">phaseX</span> <span class="o">=</span> <span class="nf">_easingX</span><span class="o">!</span><span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="n">elapsed</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="n">duration</span><span class="p">)</span>
        <span class="p">}</span>
        <span class="k">else</span>
        <span class="p">{</span>
            <span class="n">phaseX</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_enabledY</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">var</span> <span class="nv">duration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">_yDuration</span>
        <span class="k">var</span> <span class="nv">elapsed</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="n">elapsedTime</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">elapsed</span> <span class="o">&gt;</span> <span class="n">duration</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">elapsed</span> <span class="o">=</span> <span class="n">duration</span>
        <span class="p">}</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">_easingY</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">phaseY</span> <span class="o">=</span> <span class="nf">_easingY</span><span class="o">!</span><span class="p">(</span><span class="nv">elapsed</span><span class="p">:</span> <span class="n">elapsed</span><span class="p">,</span> <span class="nv">duration</span><span class="p">:</span> <span class="n">duration</span><span class="p">)</span>
        <span class="p">}</span>
        <span class="k">else</span>
        <span class="p">{</span>
            <span class="n">phaseY</span> <span class="o">=</span> <span class="kt">CGFloat</span><span class="p">(</span><span class="n">elapsed</span> <span class="o">/</span> <span class="n">duration</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">@objc</span> <span class="kd">private</span> <span class="kd">func</span> <span class="nf">animationLoop</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">var</span> <span class="nv">currentTime</span><span class="p">:</span> <span class="kt">NSTimeInterval</span> <span class="o">=</span> <span class="kt">CACurrentMediaTime</span><span class="p">()</span>

    <span class="nf">updateAnimationPhases</span><span class="p">(</span><span class="n">currentTime</span><span class="p">)</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">delegate</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">delegate</span><span class="o">!.</span><span class="nf">chartAnimatorUpdated</span><span class="p">(</span><span class="k">self</span><span class="p">)</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">updateBlock</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="nf">updateBlock</span><span class="o">!</span><span class="p">()</span>
    <span class="p">}</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">currentTime</span> <span class="o">&gt;=</span> <span class="n">_endTime</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="nf">stop</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="c1">/// :param: easingX an easing function for the animation on the x axis</span>
<span class="c1">/// :param: easingY an easing function for the animation on the y axis</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easingX</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?,</span> <span class="nv">easingY</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?)</span>
<span class="p">{</span>
    <span class="nf">stop</span><span class="p">()</span>

    <span class="n">_displayLink</span> <span class="o">=</span> <span class="kt">CADisplayLink</span><span class="p">(</span><span class="nv">target</span><span class="p">:</span> <span class="k">self</span><span class="p">,</span> <span class="nv">selector</span><span class="p">:</span> <span class="kt">Selector</span><span class="p">(</span><span class="s">"animationLoop"</span><span class="p">))</span>

    <span class="n">_startTime</span> <span class="o">=</span> <span class="kt">CACurrentMediaTime</span><span class="p">()</span>
    <span class="n">_xDuration</span> <span class="o">=</span> <span class="n">xAxisDuration</span>
    <span class="n">_yDuration</span> <span class="o">=</span> <span class="n">yAxisDuration</span>
    <span class="n">_endTimeX</span> <span class="o">=</span> <span class="n">_startTime</span> <span class="o">+</span> <span class="n">xAxisDuration</span>
    <span class="n">_endTimeY</span> <span class="o">=</span> <span class="n">_startTime</span> <span class="o">+</span> <span class="n">yAxisDuration</span>
    <span class="n">_endTime</span> <span class="o">=</span> <span class="n">_endTimeX</span> <span class="o">&gt;</span> <span class="n">_endTimeY</span> <span class="p">?</span> <span class="nv">_endTimeX</span> <span class="p">:</span> <span class="n">_endTimeY</span>
    <span class="n">_enabledX</span> <span class="o">=</span> <span class="n">xAxisDuration</span> <span class="o">&gt;</span> <span class="mf">0.0</span>
    <span class="n">_enabledY</span> <span class="o">=</span> <span class="n">yAxisDuration</span> <span class="o">&gt;</span> <span class="mf">0.0</span>

    <span class="n">_easingX</span> <span class="o">=</span> <span class="n">easingX</span>
    <span class="n">_easingY</span> <span class="o">=</span> <span class="n">easingY</span>

    <span class="c1">// Take care of the first frame if rendering is already scheduled...</span>
    <span class="nf">updateAnimationPhases</span><span class="p">(</span><span class="n">_startTime</span><span class="p">)</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">_enabledX</span> <span class="o">||</span> <span class="n">_enabledY</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_displayLink</span><span class="o">.</span><span class="nf">addToRunLoop</span><span class="p">(</span><span class="kt">NSRunLoop</span><span class="o">.</span><span class="nf">mainRunLoop</span><span class="p">(),</span> <span class="nv">forMode</span><span class="p">:</span> <span class="kt">NSRunLoopCommonModes</span><span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="c1">/// :param: easingOptionX the easing function for the animation on the x axis</span>
<span class="c1">/// :param: easingOptionY the easing function for the animation on the y axis</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easingOptionX</span><span class="p">:</span> <span class="kt">ChartEasingOption</span><span class="p">,</span> <span class="nv">easingOptionY</span><span class="p">:</span> <span class="kt">ChartEasingOption</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easingX</span><span class="p">:</span> <span class="nf">easingFunctionFromOption</span><span class="p">(</span><span class="n">easingOptionX</span><span class="p">),</span> <span class="nv">easingY</span><span class="p">:</span> <span class="nf">easingFunctionFromOption</span><span class="p">(</span><span class="n">easingOptionY</span><span class="p">))</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="c1">/// :param: easing an easing function for the animation</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easingX</span><span class="p">:</span> <span class="n">easing</span><span class="p">,</span> <span class="nv">easingY</span><span class="p">:</span> <span class="n">easing</span><span class="p">)</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="c1">/// :param: easingOption the easing function for the animation</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easingOption</span><span class="p">:</span> <span class="kt">ChartEasingOption</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="nf">easingFunctionFromOption</span><span class="p">(</span><span class="n">easingOption</span><span class="p">))</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easingOption</span><span class="p">:</span> <span class="o">.</span><span class="kt">EaseInOutSine</span><span class="p">)</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart the x-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: easing an easing function for the animation</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="n">easing</span><span class="p">)</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart the x-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="c1">/// :param: easingOption the easing function for the animation</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easingOption</span><span class="p">:</span> <span class="kt">ChartEasingOption</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="nf">easingFunctionFromOption</span><span class="p">(</span><span class="n">easingOption</span><span class="p">))</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart the x-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: xAxisDuration duration for animating the x axis</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#xAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="n">xAxisDuration</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nv">easingOption</span><span class="p">:</span> <span class="o">.</span><span class="kt">EaseInOutSine</span><span class="p">)</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart the y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="c1">/// :param: easing an easing function for the animation</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="kt">ChartEasingFunctionBlock</span><span class="p">?)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="n">easing</span><span class="p">)</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart the y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="c1">/// :param: easingOption the easing function for the animation</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">,</span> <span class="nv">easingOption</span><span class="p">:</span> <span class="kt">ChartEasingOption</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easing</span><span class="p">:</span> <span class="nf">easingFunctionFromOption</span><span class="p">(</span><span class="n">easingOption</span><span class="p">))</span>
<span class="p">}</span>

<span class="c1">/// Animates the drawing / rendering of the chart the y-axis with the specified animation time.</span>
<span class="c1">/// If animate(...) is called, no further calling of invalidate() is necessary to refresh the chart.</span>
<span class="c1">/// :param: yAxisDuration duration for animating the y axis</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">animate</span><span class="p">(</span><span class="nv">#yAxisDuration</span><span class="p">:</span> <span class="kt">NSTimeInterval</span><span class="p">)</span>
<span class="p">{</span>
    <span class="nf">animate</span><span class="p">(</span><span class="nv">xAxisDuration</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nv">yAxisDuration</span><span class="p">:</span> <span class="n">yAxisDuration</span><span class="p">,</span> <span class="nv">easingOption</span><span class="p">:</span> <span class="o">.</span><span class="kt">EaseInOutSine</span><span class="p">)</span>
<span class="p">}</span>

}



blog comments powered by Disqus