Skip to content

Instantly share code, notes, and snippets.

@ilamanov
Created April 25, 2021 04:38
Show Gist options
  • Save ilamanov/8f63a6501f0735f6567df7052b93225d to your computer and use it in GitHub Desktop.
Save ilamanov/8f63a6501f0735f6567df7052b93225d to your computer and use it in GitHub Desktop.
Creating SwiftPieChart: PieSliceView
struct PieSliceView: View {
var pieSliceData: PieSliceData
var body: some View {
GeometryReader { geometry in
Path { path in
let width: CGFloat = min(geometry.size.width, geometry.size.height)
let height = width
let center = CGPoint(x: width * 0.5, y: height * 0.5)
path.move(to: center)
path.addArc(
center: center,
radius: width * 0.5,
startAngle: Angle(degrees: -90.0) + pieSliceData.startAngle,
endAngle: Angle(degrees: -90.0) + pieSliceData.endAngle,
clockwise: false)
}
.fill(pieSliceData.color)
}
.aspectRatio(1, contentMode: .fit)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment