Skip to content

Commit d6ef575

Browse files
authored
Merge pull request #8 from ar-rahimi/feature/add-label-to-piechart-slices
added prefix postfix
2 parents 26d6a64 + 68aaf5f commit d6ef575

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Sources/SwiftUICharts/PieChart/PieChartView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public struct PieChartView : View {
1616
public var formSize:CGSize
1717
public var dropShadow: Bool
1818
public var valueSpecifier:String
19-
public var showPercentage:Bool
19+
public var prefix:String
20+
public var postfix: String
2021

2122
@State private var showValue = false
2223
@State private var currentValue: PieChartData = PieChartData(value: 0) {
@@ -27,7 +28,7 @@ public struct PieChartView : View {
2728
}
2829
}
2930

30-
public init(data: [PieChartData], title: String, legend: String? = nil, style: ChartStyle = Styles.pieChartStyleOne, form: CGSize? = ChartForm.medium, dropShadow: Bool? = true, valueSpecifier: String? = "%.1f", showPercentage: Bool? = false){
31+
public init(data: [PieChartData], title: String, legend: String? = nil, style: ChartStyle = Styles.pieChartStyleOne, form: CGSize? = ChartForm.medium, dropShadow: Bool? = true, valueSpecifier: String? = "%.1f", prefix: String? = "", postfix: String? = ""){
3132
self.data = data
3233
self.title = title
3334
self.legend = legend
@@ -39,6 +40,8 @@ public struct PieChartView : View {
3940
self.dropShadow = dropShadow!
4041
self.valueSpecifier = valueSpecifier!
4142
self.showPercentage = showPercentage!
43+
self.prefix = prefix!
44+
self.postfix = postfix!
4245
}
4346

4447
public var body: some View {
@@ -54,7 +57,7 @@ public struct PieChartView : View {
5457
.font(.headline)
5558
.foregroundColor(self.style.textColor)
5659
}else{
57-
Text("\(self.currentValue.label) \(self.currentValue.value, specifier: self.valueSpecifier)\(self.showPercentage ? "%" : "")")
60+
Text("\(self.currentValue.label) \(self.prefix)\(self.currentValue.value, specifier: self.valueSpecifier)\(self.postfix)")
5861
.font(.headline)
5962
.foregroundColor(self.style.textColor)
6063
}

0 commit comments

Comments
 (0)