Skip to content

Commit

Permalink
Minor logic cleanup (#3041)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatie authored and liuxuan30 committed Dec 9, 2017
1 parent 6fee51c commit d321093
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
22 changes: 0 additions & 22 deletions Source/Charts/Jobs/AnimatedMoveViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 10 additions & 19 deletions Source/Charts/Jobs/AnimatedViewPortJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ 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
{
if phase != 1.0
{
phase = 1.0

animationUpdate()
}

Expand All @@ -95,22 +95,13 @@ open class AnimatedViewPortJob: ViewPortJob

private 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 private func animationLoop()
Expand Down
4 changes: 2 additions & 2 deletions Source/Charts/Jobs/MoveViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Source/Charts/Jobs/ZoomViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d321093

Please sign in to comment.