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

Refactoring in ChartViewPortHandler #1187

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions Charts/Classes/Animation/ChartAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public class ChartAnimator: NSObject

if (_enabledX || _enabledY)
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(ChartAnimator.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public class ChartAnimator: NSObject
{
if _displayLink === nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(ChartAnimator.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ public class ChartAnimator: NSObject
{
if _displayLink === nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(ChartAnimator.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

self.highlighter = ChartHighlighter(chart: self)

_tapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(BarLineChartViewBase.tapGestureRecognized(_:)))
_doubleTapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(BarLineChartViewBase.doubleTapGestureRecognized(_:)))
_tapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(tapGestureRecognized))
_doubleTapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(doubleTapGestureRecognized))
_doubleTapGestureRecognizer.nsuiNumberOfTapsRequired = 2
_panGestureRecognizer = NSUIPanGestureRecognizer(target: self, action: #selector(BarLineChartViewBase.panGestureRecognized(_:)))
_panGestureRecognizer = NSUIPanGestureRecognizer(target: self, action: #selector(panGestureRecognized))

_panGestureRecognizer.delegate = self

Expand All @@ -127,7 +127,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
_panGestureRecognizer.enabled = _dragEnabled

#if !os(tvOS)
_pinchGestureRecognizer = NSUIPinchGestureRecognizer(target: self, action: #selector(BarLineChartViewBase.pinchGestureRecognized(_:)))
_pinchGestureRecognizer = NSUIPinchGestureRecognizer(target: self, action: #selector(pinchGestureRecognized))
_pinchGestureRecognizer.delegate = self
self.addGestureRecognizer(_pinchGestureRecognizer)
_pinchGestureRecognizer.enabled = _pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled
Expand Down Expand Up @@ -824,7 +824,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
_decelerationLastTime = CACurrentMediaTime()
_decelerationVelocity = recognizer.velocityInView(self)

_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(BarLineChartViewBase.decelerationLoop))
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(decelerationLoop))
_decelerationDisplayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}

Expand Down
8 changes: 4 additions & 4 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public class PieRadarChartViewBase: ChartViewBase
{
super.initialize()

_tapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(PieRadarChartViewBase.tapGestureRecognized(_:)))
_tapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(tapGestureRecognized))

self.addGestureRecognizer(_tapGestureRecognizer)

#if !os(tvOS)
_rotationGestureRecognizer = NSUIRotationGestureRecognizer(target: self, action: #selector(PieRadarChartViewBase.rotationGestureRecognized(_:)))
_rotationGestureRecognizer = NSUIRotationGestureRecognizer(target: self, action: #selector(rotationGestureRecognized))
self.addGestureRecognizer(_rotationGestureRecognizer)
_rotationGestureRecognizer.enabled = rotationWithTwoFingers
#endif
Expand Down Expand Up @@ -556,7 +556,7 @@ public class PieRadarChartViewBase: ChartViewBase
if _decelerationAngularVelocity != 0.0
{
_decelerationLastTime = CACurrentMediaTime()
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(PieRadarChartViewBase.decelerationLoop))
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(decelerationLoop))
_decelerationDisplayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down Expand Up @@ -958,7 +958,7 @@ public class PieRadarChartViewBase: ChartViewBase
if (_decelerationAngularVelocity != 0.0)
{
_decelerationLastTime = CACurrentMediaTime()
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(PieRadarChartViewBase.decelerationLoop))
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(decelerationLoop))
_decelerationDisplayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Jobs/AnimatedViewPortJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class AnimatedViewPortJob: ChartViewPortJob

updateAnimationPhase(_startTime)

_displayLink = NSUIDisplayLink(target: self, selector: #selector(AnimatedViewPortJob.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}

Expand Down
71 changes: 11 additions & 60 deletions Charts/Classes/Utils/ChartViewPortHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,7 @@ public class ChartViewPortHandler: NSObject

public var hasChartDimens: Bool
{
if (_chartHeight > 0.0 && _chartWidth > 0.0)
{
return true
}
else
{
return false
}
return _chartHeight > 0.0 && _chartWidth > 0.0
}

public func restrainViewPort(offsetLeft offsetLeft: CGFloat, offsetTop: CGFloat, offsetRight: CGFloat, offsetBottom: CGFloat)
Expand Down Expand Up @@ -388,60 +381,39 @@ public class ChartViewPortHandler: NSObject

public func isInBoundsX(x: CGFloat) -> Bool
{
if (isInBoundsLeft(x) && isInBoundsRight(x))
{
return true
}
else
{
return false
}
return isInBoundsLeft(x) && isInBoundsRight(x)
}

public func isInBoundsY(y: CGFloat) -> Bool
{
if (isInBoundsTop(y) && isInBoundsBottom(y))
{
return true
}
else
{
return false
}
return isInBoundsTop(y) && isInBoundsBottom(y)
}

public func isInBounds(x x: CGFloat, y: CGFloat) -> Bool
{
if (isInBoundsX(x) && isInBoundsY(y))
{
return true
}
else
{
return false
}
return isInBoundsX(x) && isInBoundsY(y)
}

public func isInBoundsLeft(x: CGFloat) -> Bool
{
return _contentRect.origin.x <= x ? true : false
return _contentRect.origin.x <= x
}

public func isInBoundsRight(x: CGFloat) -> Bool
{
let normalizedX = CGFloat(Int(x * 100.0)) / 100.0
return (_contentRect.origin.x + _contentRect.size.width) >= normalizedX ? true : false
return (_contentRect.origin.x + _contentRect.size.width) >= normalizedX
}

public func isInBoundsTop(y: CGFloat) -> Bool
{
return _contentRect.origin.y <= y ? true : false
return _contentRect.origin.y <= y
}

public func isInBoundsBottom(y: CGFloat) -> Bool
{
let normalizedY = CGFloat(Int(y * 100.0)) / 100.0
return (_contentRect.origin.y + _contentRect.size.height) >= normalizedY ? true : false
return (_contentRect.origin.y + _contentRect.size.height) >= normalizedY
}

/// - returns: the current x-scale factor
Expand Down Expand Up @@ -495,40 +467,19 @@ public class ChartViewPortHandler: NSObject
/// if the chart is fully zoomed out, return true
public var isFullyZoomedOut: Bool
{
if (isFullyZoomedOutX && isFullyZoomedOutY)
{
return true
}
else
{
return false
}
return isFullyZoomedOutX && isFullyZoomedOutY
}

/// - returns: true if the chart is fully zoomed out on it's y-axis (vertical).
public var isFullyZoomedOutY: Bool
{
if (_scaleY > _minScaleY || _minScaleY > 1.0)
{
return false
}
else
{
return true
}
return (1.0..._scaleY).contains(_minScaleX)
}

/// - returns: true if the chart is fully zoomed out on it's x-axis (horizontal).
public var isFullyZoomedOutX: Bool
{
if (_scaleX > _minScaleX || _minScaleX > 1.0)
{
return false
}
else
{
return true
}
return (1.0..._scaleX).contains(_minScaleX)
}

/// Set an offset in pixels that allows the user to drag the chart over it's bounds on the x-axis.
Expand Down