Skip to content
Open
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
18 changes: 12 additions & 6 deletions Classes/Drawing/LineDrawingLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ internal class LineDrawingLayer : ScrollableGraphViewDrawingLayer {

private var lineStyle: ScrollableGraphViewLineStyle
private var shouldFill: Bool
private var shouldStartAtZero: Bool
private var shouldEndAtZero: Bool
private var lineCurviness: CGFloat

init(frame: CGRect, lineWidth: CGFloat, lineColor: UIColor, lineStyle: ScrollableGraphViewLineStyle, lineJoin: String, lineCap: String, shouldFill: Bool, lineCurviness: CGFloat) {
init(frame: CGRect, lineWidth: CGFloat, lineColor: UIColor, lineStyle: ScrollableGraphViewLineStyle, lineJoin: String, lineCap: String, shouldFill: Bool, shouldStartAtZero: Bool, shouldEndAtZero: Bool, lineCurviness: CGFloat) {

self.lineStyle = lineStyle
self.shouldFill = shouldFill
self.shouldStartAtZero = shouldStartAtZero
self.shouldEndAtZero = shouldEndAtZero
self.lineCurviness = lineCurviness

super.init(viewportWidth: frame.size.width, viewportHeight: frame.size.height)
Expand Down Expand Up @@ -61,9 +65,10 @@ internal class LineDrawingLayer : ScrollableGraphViewDrawingLayer {
if(shouldFill) {
// Add a line from the base of the graph to the first data point.
let firstDataPoint = owner.graphPoint(forIndex: activePointsInterval.lowerBound)

let viewportLeftZero = CGPoint(x: firstDataPoint.location.x - (pointPadding.leftmostPointPadding), y: zeroYPosition)
let leftFarEdgeTop = CGPoint(x: firstDataPoint.location.x - (pointPadding.leftmostPointPadding + viewportWidth), y: zeroYPosition)
let leftYPosition: CGFloat = shouldStartAtZero ? zeroYPosition : firstDataPoint.y

let viewportLeftZero = CGPoint(x: firstDataPoint.location.x - (pointPadding.leftmostPointPadding), y: leftYPosition)
let leftFarEdgeTop = CGPoint(x: firstDataPoint.location.x - (pointPadding.leftmostPointPadding + viewportWidth), y: leftYPosition)
let leftFarEdgeBottom = CGPoint(x: firstDataPoint.location.x - (pointPadding.leftmostPointPadding + viewportWidth), y: viewportHeight)

currentLinePath.move(to: leftFarEdgeBottom)
Expand All @@ -89,9 +94,10 @@ internal class LineDrawingLayer : ScrollableGraphViewDrawingLayer {
if(shouldFill) {
// Add a line from the last data point to the base of the graph.
let lastDataPoint = owner.graphPoint(forIndex: activePointsInterval.upperBound - 1).location
let rightYPosition: CGFloat = shouldEndAtZero ? zeroYPosition : lastDataPoint.y

let viewportRightZero = CGPoint(x: lastDataPoint.x + (pointPadding.rightmostPointPadding), y: zeroYPosition)
let rightFarEdgeTop = CGPoint(x: lastDataPoint.x + (pointPadding.rightmostPointPadding + viewportWidth), y: zeroYPosition)
let viewportRightZero = CGPoint(x: lastDataPoint.x + (pointPadding.rightmostPointPadding), y: rightYPosition)
let rightFarEdgeTop = CGPoint(x: lastDataPoint.x + (pointPadding.rightmostPointPadding + viewportWidth), y: rightYPosition)
let rightFarEdgeBottom = CGPoint(x: lastDataPoint.x + (pointPadding.rightmostPointPadding + viewportWidth), y: viewportHeight)

pathSegmentAdder(lastDataPoint, viewportRightZero, currentLinePath)
Expand Down
8 changes: 7 additions & 1 deletion Classes/Plots/LinePlot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ open class LinePlot : Plot {

/// Specifies whether or not the plotted graph should be filled with a colour or gradient.
open var shouldFill: Bool = false

/// Specifies whether or not the plotted graph should be started at zero position.
open var shouldStartAtZero: Bool = true

/// Specifies whether or not the plotted graph should be ended at zero position.
open var shouldEndAtZero: Bool = true

var fillType_: Int {
get { return fillType.rawValue }
Expand Down Expand Up @@ -92,7 +98,7 @@ open class LinePlot : Plot {
private func createLayers(viewport: CGRect) {

// Create the line drawing layer.
lineLayer = LineDrawingLayer(frame: viewport, lineWidth: lineWidth, lineColor: lineColor, lineStyle: lineStyle, lineJoin: lineJoin, lineCap: lineCap, shouldFill: shouldFill, lineCurviness: lineCurviness)
lineLayer = LineDrawingLayer(frame: viewport, lineWidth: lineWidth, lineColor: lineColor, lineStyle: lineStyle, lineJoin: lineJoin, lineCap: lineCap, shouldFill: shouldFill, shouldStartAtZero: shouldStartAtZero, shouldEndAtZero: shouldEndAtZero, lineCurviness: lineCurviness)

// Depending on whether we want to fill with solid or gradient, create the layer accordingly.

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ Line plot specific customisation options. These options are available on any `Li
| Property | Description |
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **shouldFill**: Bool | Specifies whether or not the plotted graph should be filled with a colour or gradient. |
| **shouldStartAtZero**: Bool | Specifies whether or not the plotted graph should be started at zero position. |
| **shouldEndAtZero**: Bool | Specifies whether or not the plotted graph should be ended at zero position. |
| **fillType**: ScrollableGraphViewFillType | Specifies whether to fill the graph with a solid colour or gradient. Possible values: <ul><li>`ScrollableGraphViewFillType.solid`</li> <li>`ScrollableGraphViewFillType.gradient`</li></ul> |
| **fillColor**: UIColor | If `fillType` is set to `.solid` then this colour will be used to fill the graph. |
| **fillGradientStartColor**: UIColor | If `fillType` is set to `.gradient` then this will be the starting colour for the gradient. |
Expand Down