@@ -104,6 +104,7 @@ import UIKit
104104
105105 // Graph Line
106106 private var currentLinePath = UIBezierPath ( )
107+ private var zeroYPosition : CGFloat = 0
107108
108109 // Labels
109110 private var labelsView = UIView ( )
@@ -659,13 +660,13 @@ import UIKit
659660
660661 let pathSegmentAdder = lineStyle == . Straight ? addStraightLineSegment : addCurvedLineSegment
661662
663+ zeroYPosition = calculatePosition ( 0 , value: self . range. min) . y
664+
662665 // Connect the line to the starting edge if we are filling it.
663666 if ( shouldFill) {
664667 // Add a line from the base of the graph to the first data point.
665668 let firstDataPoint = graphPoints [ activePointsInterval. startIndex]
666669
667- let zeroYPosition = calculatePosition ( 0 , value: self . range. min) . y
668-
669670 let viewportLeftZero = CGPoint ( x: firstDataPoint. x - ( leftmostPointPadding) , y: zeroYPosition)
670671 let leftFarEdgeTop = CGPoint ( x: firstDataPoint. x - ( leftmostPointPadding + viewportWidth) , y: zeroYPosition)
671672 let leftFarEdgeBottom = CGPoint ( x: firstDataPoint. x - ( leftmostPointPadding + viewportWidth) , y: viewportHeight)
@@ -694,8 +695,6 @@ import UIKit
694695 // Add a line from the last data point to the base of the graph.
695696 let lastDataPoint = graphPoints [ activePointsInterval. endIndex]
696697
697- let zeroYPosition = calculatePosition ( 0 , value: self . range. min) . y
698-
699698 let viewportRightZero = CGPoint ( x: lastDataPoint. x + ( rightmostPointPadding) , y: zeroYPosition)
700699 let rightFarEdgeTop = CGPoint ( x: lastDataPoint. x + ( rightmostPointPadding + viewportWidth) , y: zeroYPosition)
701700 let rightFarEdgeBottom = CGPoint ( x: lastDataPoint. x + ( rightmostPointPadding + viewportWidth) , y: viewportHeight)
@@ -773,11 +772,16 @@ import UIKit
773772
774773 // Update any paths with the new path based on visible data points.
775774 private func updatePaths( ) {
775+
776776 createLinePath ( )
777777
778778 if let drawingLayers = drawingView. layer. sublayers {
779779 for layer in drawingLayers {
780780 if let layer = layer as? ScrollableGraphViewDrawingLayer {
781+ // Need to make sure this is set in createLinePath
782+ assert ( layer. zeroYPosition > 0 ) ;
783+ // The bar layer needs the zero Y position to set the bottom of the bar
784+ layer. zeroYPosition = zeroYPosition
781785 layer. updatePath ( )
782786 }
783787 }
@@ -1084,6 +1088,7 @@ private class ScrollableGraphViewDrawingLayer : CAShapeLayer {
10841088
10851089 var viewportWidth : CGFloat = 0
10861090 var viewportHeight : CGFloat = 0
1091+ var zeroYPosition : CGFloat = 0
10871092
10881093 var graphViewDrawingDelegate : ScrollableGraphViewDrawingDelegate ? = nil
10891094
0 commit comments