Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created September 14, 2020 04:19
Show Gist options
  • Save prafullakumar/19a1f9b886304c31792a27603cf00693 to your computer and use it in GitHub Desktop.
Save prafullakumar/19a1f9b886304c31792a27603cf00693 to your computer and use it in GitHub Desktop.
struct InnerCircle: Shape {
let ratio: CGFloat
func path(in rect: CGRect) -> Path {
let center = CGPoint.init(x: (rect.origin.x + rect.width)/2, y: (rect.origin.y + rect.height)/2)
let radii = min(center.x, center.y) * ratio
let path = Path { p in
p.addArc(center: center,
radius: radii,
startAngle: Angle(degrees: 0),
endAngle: Angle(degrees: 360),
clockwise: true)
p.addLine(to: center)
}
return path
}
}
struct DonutChart: View {
@State private var selectedCell: UUID = UUID()
let dataModel: ChartDataModel
let onTap: (ChartCellModel?) -> ()
var body: some View {
ZStack {
PieChart(dataModel: dataModel, onTap: onTap)
InnerCircle(ratio: 1/3).foregroundColor(.white)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment