Skip to content

Commit

Permalink
Minor changes to logic in ViewPortJob subclasses. (#2992)
Browse files Browse the repository at this point in the history
* Minor changes to logic in `ViewPortJob` subclasses.

* Removed TODOs
  • Loading branch information
jjatie authored and liuxuan30 committed Nov 23, 2017
1 parent 3b6eda1 commit bc40b16
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 48 deletions.
16 changes: 8 additions & 8 deletions Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
}
else
{
let _ = viewPortHandler.refresh(newMatrix: viewPortHandler.touchMatrix, chart: self, invalidate: true)
viewPortHandler.refresh(newMatrix: viewPortHandler.touchMatrix, chart: self, invalidate: true)
}
}

Expand Down Expand Up @@ -648,7 +648,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

matrix = _viewPortHandler.touchMatrix.concatenating(matrix)

let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)

if delegate !== nil
{
Expand Down Expand Up @@ -971,7 +971,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
let center = _viewPortHandler.contentCenter

let matrix = _viewPortHandler.zoomIn(x: center.x, y: -center.y)
let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)

// Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets.
calculateOffsets()
Expand All @@ -984,7 +984,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
let center = _viewPortHandler.contentCenter

let matrix = _viewPortHandler.zoomOut(x: center.x, y: -center.y)
let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)

// Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets.
calculateOffsets()
Expand All @@ -995,7 +995,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
@objc open func resetZoom()
{
let matrix = _viewPortHandler.resetZoom()
let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)

// Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets.
calculateOffsets()
Expand All @@ -1016,7 +1016,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
y: CGFloat)
{
let matrix = _viewPortHandler.zoom(scaleX: scaleX, scaleY: scaleY, x: x, y: -y)
let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)

// Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets.
calculateOffsets()
Expand Down Expand Up @@ -1067,7 +1067,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
scaleY: scaleY,
x: center.x,
y: -center.y)
let _ = viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
}

/// Zooms by the specified scale factor to the specified values on the specified axis.
Expand Down Expand Up @@ -1157,7 +1157,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
@objc open func fitScreen()
{
let matrix = _viewPortHandler.fitScreen()
let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false)

calculateOffsets()
setNeedsDisplay()
Expand Down
29 changes: 13 additions & 16 deletions Source/Charts/Jobs/AnimatedViewPortJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,20 @@ open class AnimatedViewPortJob: ViewPortJob

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

if finish
{
_displayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes)
_displayLink = nil

if finish
if phase != 1.0
{
if phase != 1.0
{
phase = 1.0
phase = 1.0

animationUpdate()
}

animationEnd()
phase = 1.0

animationUpdate()
}

animationEnd()
}
}

Expand Down Expand Up @@ -132,11 +129,11 @@ open class AnimatedViewPortJob: ViewPortJob

@objc internal func animationUpdate()
{
// Override this
fatalError("`animationUpdate()` must be overriden by subclasses")
}

@objc internal func animationEnd()
{
// Override this
fatalError("`animationEnd()` must be overriden by subclasses")
}
}
4 changes: 2 additions & 2 deletions Source/Charts/Jobs/AnimatedZoomViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ open class AnimatedZoomViewJob: AnimatedViewPortJob
let scaleY = yOrigin + (self.scaleY - yOrigin) * phase

var matrix = viewPortHandler.setZoom(scaleX: scaleX, scaleY: scaleY)
let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false)
viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false)

let valsInView = CGFloat(yAxis?.axisRange ?? 0.0) / viewPortHandler.scaleY
let xsInView = CGFloat(xAxisRange) / viewPortHandler.scaleX
Expand All @@ -85,7 +85,7 @@ open class AnimatedZoomViewJob: AnimatedViewPortJob
transformer.pointValueToPixel(&pt)

matrix = viewPortHandler.translate(pt: pt)
let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: true)
viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: true)
}

internal override func animationEnd()
Expand Down
17 changes: 1 addition & 16 deletions Source/Charts/Jobs/MoveViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,7 @@ import CoreGraphics

@objc(MoveChartViewJob)
open class MoveViewJob: ViewPortJob
{
public override init(
viewPortHandler: ViewPortHandler,
xValue: Double,
yValue: Double,
transformer: Transformer,
view: ChartViewBase)
{
super.init(
viewPortHandler: viewPortHandler,
xValue: xValue,
yValue: yValue,
transformer: transformer,
view: view)
}

{
open override func doJob()
{
guard
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Jobs/ViewPortJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ open class ViewPortJob: NSObject

@objc open func doJob()
{
// Override this
fatalError("`doJob()` must be overridden by subclasses")
}
}
4 changes: 2 additions & 2 deletions Source/Charts/Jobs/ZoomViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class ZoomViewJob: ViewPortJob
else { return }

var matrix = viewPortHandler.setZoom(scaleX: scaleX, scaleY: scaleY)
let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false)
viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false)

let yValsInView = (view as! BarLineChartViewBase).getAxis(axisDependency).axisRange / Double(viewPortHandler.scaleY)
let xValsInView = (view as! BarLineChartViewBase).xAxis.axisRange / Double(viewPortHandler.scaleX)
Expand All @@ -67,7 +67,7 @@ open class ZoomViewJob: ViewPortJob
transformer.pointValueToPixel(&pt)

matrix = viewPortHandler.translate(pt: pt)
let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false)
viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false)

(view as! BarLineChartViewBase).calculateOffsets()
view.setNeedsDisplay()
Expand Down
5 changes: 2 additions & 3 deletions Source/Charts/Utils/ViewPortHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,11 @@ open class ViewPortHandler: NSObject
let translateY = pt.y - offsetTop

let matrix = _touchMatrix.concatenating(CGAffineTransform(translationX: -translateX, y: -translateY))

let _ = refresh(newMatrix: matrix, chart: chart, invalidate: true)
refresh(newMatrix: matrix, chart: chart, invalidate: true)
}

/// call this method to refresh the graph with a given matrix
@objc open func refresh(newMatrix: CGAffineTransform, chart: ChartViewBase, invalidate: Bool) -> CGAffineTransform
@objc @discardableResult open func refresh(newMatrix: CGAffineTransform, chart: ChartViewBase, invalidate: Bool) -> CGAffineTransform
{
_touchMatrix = newMatrix

Expand Down

0 comments on commit bc40b16

Please sign in to comment.