-
-
Save anupamchugh/19da517f3733108c521ccaef00e81c66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Path { | |
static func lineChart(points:[Double], step:CGPoint) -> Path { | |
var path = Path() | |
if (points.count < 2){ | |
return path | |
} | |
guard let offset = points.min() else { return path } | |
let p1 = CGPoint(x: 0, y: CGFloat(points[0]-offset)*step.y) | |
path.move(to: p1) | |
for pointIndex in 1..<points.count { | |
let p2 = CGPoint(x: step.x * CGFloat(pointIndex), y: step.y*CGFloat(points[pointIndex]-offset)) | |
path.addLine(to: p2) | |
} | |
return path | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment