From d322fba3df6b6d61fb19e5ee3d05f1126ffe147d Mon Sep 17 00:00:00 2001 From: Adam Nemecek Date: Tue, 28 Jun 2016 17:59:57 -0700 Subject: [PATCH 1/2] * refactoring in ChartViewPortHandler --- .../Classes/Utils/ChartViewPortHandler.swift | 71 +++---------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/Charts/Classes/Utils/ChartViewPortHandler.swift b/Charts/Classes/Utils/ChartViewPortHandler.swift index 606063ca74..701a101b0f 100755 --- a/Charts/Classes/Utils/ChartViewPortHandler.swift +++ b/Charts/Classes/Utils/ChartViewPortHandler.swift @@ -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) @@ -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 @@ -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. From b670d8cff3cadc0b497bc21cef6cb90243f0b281 Mon Sep 17 00:00:00 2001 From: Adam Nemecek Date: Tue, 28 Jun 2016 19:13:20 -0700 Subject: [PATCH 2/2] * removed superfluous class names from #selector directives --- Charts/Classes/Animation/ChartAnimator.swift | 6 +++--- Charts/Classes/Charts/BarLineChartViewBase.swift | 10 +++++----- Charts/Classes/Charts/PieRadarChartViewBase.swift | 8 ++++---- Charts/Classes/Jobs/AnimatedViewPortJob.swift | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Charts/Classes/Animation/ChartAnimator.swift b/Charts/Classes/Animation/ChartAnimator.swift index 16697a456f..59fd304ff4 100644 --- a/Charts/Classes/Animation/ChartAnimator.swift +++ b/Charts/Classes/Animation/ChartAnimator.swift @@ -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) } } @@ -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) } } @@ -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) } } diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index fbb1e2db73..3cd188283e 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -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 @@ -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 @@ -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) } diff --git a/Charts/Classes/Charts/PieRadarChartViewBase.swift b/Charts/Classes/Charts/PieRadarChartViewBase.swift index f0c13e3a92..563b4d3fd2 100755 --- a/Charts/Classes/Charts/PieRadarChartViewBase.swift +++ b/Charts/Classes/Charts/PieRadarChartViewBase.swift @@ -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 @@ -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) } } @@ -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) } } diff --git a/Charts/Classes/Jobs/AnimatedViewPortJob.swift b/Charts/Classes/Jobs/AnimatedViewPortJob.swift index a1558c4b42..0c03b0cec3 100644 --- a/Charts/Classes/Jobs/AnimatedViewPortJob.swift +++ b/Charts/Classes/Jobs/AnimatedViewPortJob.swift @@ -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) }