Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created March 5, 2020 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupamchugh/19da517f3733108c521ccaef00e81c66 to your computer and use it in GitHub Desktop.
Save anupamchugh/19da517f3733108c521ccaef00e81c66 to your computer and use it in GitHub Desktop.
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