Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into minor-formatter-l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
jjatie committed Dec 11, 2017
2 parents 9ea3c20 + 159e0f7 commit 3ab6706
Show file tree
Hide file tree
Showing 62 changed files with 645 additions and 946 deletions.
108 changes: 35 additions & 73 deletions Source/Charts/Animation/Animator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ open class Animator: NSObject
/// the phase that is animated and influences the drawn values on the y-axis
@objc open var phaseY: Double = 1.0

fileprivate var _startTimeX: TimeInterval = 0.0
fileprivate var _startTimeY: TimeInterval = 0.0
fileprivate var _displayLink: NSUIDisplayLink?
private var _startTimeX: TimeInterval = 0.0
private var _startTimeY: TimeInterval = 0.0
private var _displayLink: NSUIDisplayLink?

fileprivate var _durationX: TimeInterval = 0.0
fileprivate var _durationY: TimeInterval = 0.0
private var _durationX: TimeInterval = 0.0
private var _durationY: TimeInterval = 0.0

fileprivate var _endTimeX: TimeInterval = 0.0
fileprivate var _endTimeY: TimeInterval = 0.0
fileprivate var _endTime: TimeInterval = 0.0
private var _endTimeX: TimeInterval = 0.0
private var _endTimeY: TimeInterval = 0.0
private var _endTime: TimeInterval = 0.0

fileprivate var _enabledX: Bool = false
fileprivate var _enabledY: Bool = false

fileprivate var _easingX: ChartEasingFunctionBlock?
fileprivate var _easingY: ChartEasingFunctionBlock?
private var _enabledX: Bool = false
private var _enabledY: Bool = false

private var _easingX: ChartEasingFunctionBlock?
private var _easingY: ChartEasingFunctionBlock?

public override init()
{
super.init()
Expand All @@ -68,11 +68,10 @@ open class Animator: NSObject

@objc open func stop()
{
guard let _displayLink = _displayLink else {
return
}
_displayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes)
self._displayLink = nil
guard _displayLink != nil else { return }

_displayLink?.remove(from: .main, forMode: .commonModes)
_displayLink = nil

_enabledX = false
_enabledY = false
Expand All @@ -91,7 +90,7 @@ open class Animator: NSObject
stopBlock?()
}

fileprivate func updateAnimationPhases(_ currentTime: TimeInterval)
private func updateAnimationPhases(_ currentTime: TimeInterval)
{
if _enabledX
{
Expand All @@ -103,7 +102,7 @@ open class Animator: NSObject
elapsed = duration
}

phaseX = _easingX?(elapsed, duration) ?? Double(elapsed / duration)
phaseX = _easingX?(elapsed, duration) ?? elapsed / duration
}

if _enabledY
Expand All @@ -115,26 +114,18 @@ open class Animator: NSObject
{
elapsed = duration
}

if let _easingY = _easingY
{
phaseY = _easingY(elapsed, duration)
}
else
{
phaseY = Double(elapsed / duration)
}

phaseY = _easingY?(elapsed, duration) ?? elapsed / duration
}
}

@objc fileprivate func animationLoop()
@objc private func animationLoop()
{
let currentTime: TimeInterval = CACurrentMediaTime()

updateAnimationPhases(currentTime)

delegate?.animatorUpdated(self)

updateBlock?()

if currentTime >= _endTime
Expand Down Expand Up @@ -202,20 +193,11 @@ open class Animator: NSObject
/// - parameter xAxisDuration: duration for animating the x axis
/// - parameter yAxisDuration: duration for animating the y axis
/// - parameter easingOption: the easing function for the animation
@objc open func animate(xAxisDuration: TimeInterval, yAxisDuration: TimeInterval, easingOption: ChartEasingOption)
@objc open func animate(xAxisDuration: TimeInterval, yAxisDuration: TimeInterval, easingOption: ChartEasingOption = .easeInOutSine)
{
animate(xAxisDuration: xAxisDuration, yAxisDuration: yAxisDuration, easing: easingFunctionFromOption(easingOption))
}

/// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter xAxisDuration: duration for animating the x axis
/// - parameter yAxisDuration: duration for animating the y axis
@objc open func animate(xAxisDuration: TimeInterval, yAxisDuration: TimeInterval)
{
animate(xAxisDuration: xAxisDuration, yAxisDuration: yAxisDuration, easingOption: .easeInOutSine)
}


/// Animates the drawing / rendering of the chart the x-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter xAxisDuration: duration for animating the x axis
Expand All @@ -233,33 +215,23 @@ open class Animator: NSObject
// Take care of the first frame if rendering is already scheduled...
updateAnimationPhases(_startTimeX)

if _enabledX || _enabledY
if _enabledX || _enabledY,
_displayLink == nil
{
if _displayLink == nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink?.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink?.add(to: .main, forMode: .commonModes)
}
}

/// Animates the drawing / rendering of the chart the x-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter xAxisDuration: duration for animating the x axis
/// - parameter easingOption: the easing function for the animation
@objc open func animate(xAxisDuration: TimeInterval, easingOption: ChartEasingOption)
@objc open func animate(xAxisDuration: TimeInterval, easingOption: ChartEasingOption = .easeInOutSine)
{
animate(xAxisDuration: xAxisDuration, easing: easingFunctionFromOption(easingOption))
}

/// Animates the drawing / rendering of the chart the x-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter xAxisDuration: duration for animating the x axis
@objc open func animate(xAxisDuration: TimeInterval)
{
animate(xAxisDuration: xAxisDuration, easingOption: .easeInOutSine)
}


/// Animates the drawing / rendering of the chart the y-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter yAxisDuration: duration for animating the y axis
Expand All @@ -277,30 +249,20 @@ open class Animator: NSObject
// Take care of the first frame if rendering is already scheduled...
updateAnimationPhases(_startTimeY)

if _enabledX || _enabledY
if _enabledX || _enabledY,
_displayLink == nil
{
if _displayLink == nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink?.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink?.add(to: .main, forMode: .commonModes)
}
}

/// Animates the drawing / rendering of the chart the y-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter yAxisDuration: duration for animating the y axis
/// - parameter easingOption: the easing function for the animation
@objc open func animate(yAxisDuration: TimeInterval, easingOption: ChartEasingOption)
@objc open func animate(yAxisDuration: TimeInterval, easingOption: ChartEasingOption = .easeInOutSine)
{
animate(yAxisDuration: yAxisDuration, easing: easingFunctionFromOption(easingOption))
}

/// Animates the drawing / rendering of the chart the y-axis with the specified animation time.
/// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart.
/// - parameter yAxisDuration: duration for animating the y axis
@objc open func animate(yAxisDuration: TimeInterval)
{
animate(yAxisDuration: yAxisDuration, easingOption: .easeInOutSine)
}
}
4 changes: 2 additions & 2 deletions Source/Charts/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import CoreGraphics
open class BarChartView: BarLineChartViewBase, BarChartDataProvider
{
/// if set to true, all values are drawn above their bars, instead of below their top
fileprivate var _drawValueAboveBarEnabled = true
private var _drawValueAboveBarEnabled = true

/// if set to true, a grey area is drawn behind each bar that indicates the maximum value
fileprivate var _drawBarShadowEnabled = false
private var _drawBarShadowEnabled = false

internal override func initialize()
{
Expand Down
Loading

0 comments on commit 3ab6706

Please sign in to comment.