Skip to content

Instantly share code, notes, and snippets.

@ilamanov
Created April 25, 2021 22:48
Show Gist options
  • Save ilamanov/d7308524ab4b40c96e7d62348dc9fa03 to your computer and use it in GitHub Desktop.
Save ilamanov/d7308524ab4b40c96e7d62348dc9fa03 to your computer and use it in GitHub Desktop.
Creating SwiftPieChart: render rows
var body: some View {
GeometryReader { geometry in
VStack{
ZStack{
ForEach(0..<self.values.count){ i in
PieSliceView(pieSliceData: self.slices[i])
}
.frame(width: geometry.size.width, height: geometry.size.width)
Circle()
.fill(self.backgroundColor)
.frame(width: geometry.size.width * innerRadiusFraction, height: geometry.size.width * innerRadiusFraction)
VStack {
Text("Total")
.font(.title)
.foregroundColor(Color.gray)
Text(String(values.reduce(0, +)))
.font(.title)
}
}
PieChartRows(colors: self.colors, names: self.names, values: self.values.map { String($0) }, percents: self.values.map { String(format: "%.0f%%", $0 * 100 / self.values.reduce(0, +)) })
}
.background(self.backgroundColor)
.foregroundColor(Color.white)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment