Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewportjob minor cleanup #3041

Merged
merged 4 commits into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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()
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