Created
September 14, 2020 04:18
-
-
Save prafullakumar/43cf09a94a2481b0c9b1e8745e884c9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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