diff --git a/Source/Charts/Jobs/AnimatedMoveViewJob.swift b/Source/Charts/Jobs/AnimatedMoveViewJob.swift index b2dc5d2205..b6ea8c28e5 100644 --- a/Source/Charts/Jobs/AnimatedMoveViewJob.swift +++ b/Source/Charts/Jobs/AnimatedMoveViewJob.swift @@ -18,28 +18,6 @@ import CoreGraphics open class AnimatedMoveViewJob: AnimatedViewPortJob { - public override init( - viewPortHandler: ViewPortHandler, - xValue: Double, - yValue: Double, - transformer: Transformer, - view: ChartViewBase, - xOrigin: CGFloat, - yOrigin: CGFloat, - duration: TimeInterval, - easing: ChartEasingFunctionBlock?) - { - super.init(viewPortHandler: viewPortHandler, - xValue: xValue, - yValue: yValue, - transformer: transformer, - view: view, - xOrigin: xOrigin, - yOrigin: yOrigin, - duration: duration, - easing: easing) - } - internal override func animationUpdate() { guard diff --git a/Source/Charts/Jobs/AnimatedViewPortJob.swift b/Source/Charts/Jobs/AnimatedViewPortJob.swift index 00fc1f1fb4..483c716d1b 100644 --- a/Source/Charts/Jobs/AnimatedViewPortJob.swift +++ b/Source/Charts/Jobs/AnimatedViewPortJob.swift @@ -71,13 +71,14 @@ open class AnimatedViewPortJob: ViewPortJob updateAnimationPhase(_startTime) _displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop)) - _displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) + _displayLink.add(to: .main, forMode: .commonModes) } @objc open func stop(finish: Bool) { guard _displayLink != nil else { return } - _displayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes) + + _displayLink.remove(from: .main, forMode: .commonModes) _displayLink = nil if finish @@ -85,7 +86,6 @@ open class AnimatedViewPortJob: ViewPortJob if phase != 1.0 { phase = 1.0 - animationUpdate() } @@ -95,22 +95,13 @@ open class AnimatedViewPortJob: ViewPortJob fileprivate func updateAnimationPhase(_ currentTime: TimeInterval) { - let elapsedTime: TimeInterval = currentTime - _startTime - let duration: TimeInterval = _duration - var elapsed: TimeInterval = elapsedTime - if elapsed > duration - { - elapsed = duration - } - - if _easing != nil - { - phase = CGFloat(_easing!(elapsed, duration)) - } - else - { - phase = CGFloat(elapsed / duration) - } + let elapsedTime = currentTime - _startTime + let duration = _duration + var elapsed = elapsedTime + + elapsed = min(elapsed, duration) + + phase = CGFloat(_easing?(elapsed, duration) ?? elapsed / duration) } @objc fileprivate func animationLoop() diff --git a/Source/Charts/Jobs/MoveViewJob.swift b/Source/Charts/Jobs/MoveViewJob.swift index 81a8774ee0..acc8165d39 100644 --- a/Source/Charts/Jobs/MoveViewJob.swift +++ b/Source/Charts/Jobs/MoveViewJob.swift @@ -28,8 +28,8 @@ open class MoveViewJob: ViewPortJob else { return } var pt = CGPoint( - x: CGFloat(xValue), - y: CGFloat(yValue) + x: xValue, + y: yValue ) transformer.pointValueToPixel(&pt) diff --git a/Source/Charts/Jobs/ZoomViewJob.swift b/Source/Charts/Jobs/ZoomViewJob.swift index 0ef36ff43c..7bd805c425 100644 --- a/Source/Charts/Jobs/ZoomViewJob.swift +++ b/Source/Charts/Jobs/ZoomViewJob.swift @@ -21,7 +21,7 @@ open class ZoomViewJob: ViewPortJob { internal var scaleX: CGFloat = 0.0 internal var scaleY: CGFloat = 0.0 - internal var axisDependency: YAxis.AxisDependency = YAxis.AxisDependency.left + internal var axisDependency: YAxis.AxisDependency = .left @objc public init( viewPortHandler: ViewPortHandler, @@ -60,8 +60,8 @@ open class ZoomViewJob: ViewPortJob let xValsInView = (view as! BarLineChartViewBase).xAxis.axisRange / Double(viewPortHandler.scaleX) var pt = CGPoint( - x: CGFloat(xValue - xValsInView / 2.0), - y: CGFloat(yValue + yValsInView / 2.0) + x: CGFloat(xValue - xValsInView) / 2.0, + y: CGFloat(yValue + yValsInView) / 2.0 ) transformer.pointValueToPixel(&pt)