Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created September 14, 2020 04:18
Show Gist options
  • Save prafullakumar/43cf09a94a2481b0c9b1e8745e884c9d to your computer and use it in GitHub Desktop.
Save prafullakumar/43cf09a94a2481b0c9b1e8745e884c9d to your computer and use it in GitHub Desktop.
struct PieChart: View {
@State private var selectedCell: UUID = UUID()
let dataModel: ChartDataModel
let onTap: (ChartCellModel?) -> ()
var body: some View {
ZStack {
ForEach(dataModel.chartCellModel) { dataSet in
PieChartCell(startAngle: self.dataModel.angle(for: dataSet.value), endAngle: self.dataModel.startingAngle)
.foregroundColor(dataSet.color)
.onTapGesture {
withAnimation {
if self.selectedCell == dataSet.id {
self.onTap(nil)
self.selectedCell = UUID()
} else {
self.selectedCell = dataSet.id
self.onTap(dataSet)
}
}
}.scaleEffect((self.selectedCell == dataSet.id) ? 1.05 : 1.0)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment