Skip to content

Commit

Permalink
Minor refactoring (Closes #1187)
Browse files Browse the repository at this point in the history
Sorry, un-mergable to `master`...
  • Loading branch information
danielgindi committed Aug 15, 2016
1 parent ee4de2b commit cbd7bf7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 65 deletions.
6 changes: 3 additions & 3 deletions Charts/Classes/Animation/Animator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public class Animator: NSObject

if (_enabledX || _enabledY)
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(Animator.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ public class Animator: NSObject
{
if _displayLink === nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(Animator.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down Expand Up @@ -304,7 +304,7 @@ public class Animator: NSObject
{
if _displayLink === nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(Animator.animationLoop))
_displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop))
_displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,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 Down
4 changes: 2 additions & 2 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,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
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: ViewPortJob

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
70 changes: 14 additions & 56 deletions Charts/Classes/Utils/ViewPortHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,60 +407,39 @@ public class ViewPortHandler: 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 + 1.0 ? true : false
return _contentRect.origin.x <= x + 1.0
}

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

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 = floor(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 @@ -514,40 +493,19 @@ public class ViewPortHandler: 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 _scaleY > _minScaleY || _minScaleY > 1.0
}

/// - 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 _scaleX > _minScaleX || _minScaleX > 1.0
}

/// Set an offset in pixels that allows the user to drag the chart over it's bounds on the x-axis.
Expand All @@ -571,24 +529,24 @@ public class ViewPortHandler: NSObject
/// - returns: `true` if the chart is not yet fully zoomed out on the x-axis
public var canZoomOutMoreX: Bool
{
return (_scaleX > _minScaleX)
return _scaleX > _minScaleX
}

/// - returns: `true` if the chart is not yet fully zoomed in on the x-axis
public var canZoomInMoreX: Bool
{
return (_scaleX < _maxScaleX)
return _scaleX < _maxScaleX
}

/// - returns: `true` if the chart is not yet fully zoomed out on the y-axis
public var canZoomOutMoreY: Bool
{
return (_scaleY > _minScaleY)
return _scaleY > _minScaleY
}

/// - returns: `true` if the chart is not yet fully zoomed in on the y-axis
public var canZoomInMoreY: Bool
{
return (_scaleY < _maxScaleY)
return _scaleY < _maxScaleY
}
}

0 comments on commit cbd7bf7

Please sign in to comment.