@@ -11,69 +11,6 @@ import SwiftUI
11
11
Data model for drawing and styling a Grouped Bar Chart.
12
12
13
13
The grouping data informs the model as to how the datapoints are linked.
14
-
15
- # Example
16
- ```
17
- static func makeData() -> GroupedBarChartData {
18
-
19
- enum Group {
20
- case one
21
- case two
22
- case three
23
- case four
24
-
25
- var data : GroupingData {
26
- switch self {
27
- case .one:
28
- return GroupingData(title: "One" , colour: .blue)
29
- case .two:
30
- return GroupingData(title: "Two" , colour: .red)
31
- case .three:
32
- return GroupingData(title: "Three", colour: .yellow)
33
- case .four:
34
- return GroupingData(title: "Four" , colour: .green)
35
- }
36
- }
37
- }
38
-
39
- let groups : [GroupingData] = [Group.one.data, Group.two.data, Group.three.data, Group.four.data]
40
-
41
- let data = MultiBarDataSets(dataSets: [
42
- MultiBarDataSet(dataPoints: [
43
- MultiBarChartDataPoint(value: 10, xAxisLabel: "1.1", pointLabel: "One One" , group: Group.one.data),
44
- MultiBarChartDataPoint(value: 50, xAxisLabel: "1.2", pointLabel: "One Two" , group: Group.two.data),
45
- MultiBarChartDataPoint(value: 30, xAxisLabel: "1.3", pointLabel: "One Three" , group: Group.three.data),
46
- MultiBarChartDataPoint(value: 40, xAxisLabel: "1.4", pointLabel: "One Four" , group: Group.four.data)
47
- ]),
48
-
49
- MultiBarDataSet(dataPoints: [
50
- MultiBarChartDataPoint(value: 20, xAxisLabel: "2.1", pointLabel: "Two One" , group: Group.one.data),
51
- MultiBarChartDataPoint(value: 60, xAxisLabel: "2.2", pointLabel: "Two Two" , group: Group.two.data),
52
- MultiBarChartDataPoint(value: 40, xAxisLabel: "2.3", pointLabel: "Two Three" , group: Group.three.data),
53
- MultiBarChartDataPoint(value: 60, xAxisLabel: "2.3", pointLabel: "Two Four" , group: Group.four.data)
54
- ]),
55
-
56
- MultiBarDataSet(dataPoints: [
57
- MultiBarChartDataPoint(value: 30, xAxisLabel: "3.1", pointLabel: "Three One" , group: Group.one.data),
58
- MultiBarChartDataPoint(value: 70, xAxisLabel: "3.2", pointLabel: "Three Two" , group: Group.two.data),
59
- MultiBarChartDataPoint(value: 30, xAxisLabel: "3.3", pointLabel: "Three Three", group: Group.three.data),
60
- MultiBarChartDataPoint(value: 90, xAxisLabel: "3.4", pointLabel: "Three Four" , group: Group.four.data)
61
- ]),
62
-
63
- MultiBarDataSet(dataPoints: [
64
- MultiBarChartDataPoint(value: 40, xAxisLabel: "4.1", pointLabel: "Four One" , group: Group.one.data),
65
- MultiBarChartDataPoint(value: 80, xAxisLabel: "4.2", pointLabel: "Four Two" , group: Group.two.data),
66
- MultiBarChartDataPoint(value: 20, xAxisLabel: "4.3", pointLabel: "Four Three" , group: Group.three.data),
67
- MultiBarChartDataPoint(value: 50, xAxisLabel: "4.3", pointLabel: "Four Four" , group: Group.four.data)
68
- ])
69
- ])
70
-
71
- return GroupedBarChartData(dataSets : data,
72
- groups : groups,
73
- metadata : ChartMetadata(title: "Hello", subtitle: "Bob"),
74
- chartStyle : BarChartStyle(infoBoxPlacement: .floating,
75
- xAxisLabelsFrom : .dataPoint))
76
- }
77
14
```
78
15
*/
79
16
public final class GroupedBarChartData : CTMultiBarChartDataProtocol {
@@ -130,22 +67,19 @@ public final class GroupedBarChartData: CTMultiBarChartDataProtocol {
130
67
131
68
// MARK: Labels
132
69
public final func getXAxisLabels( ) -> some View {
133
- Group {
70
+ VStack {
134
71
switch self . chartStyle. xAxisLabelsFrom {
135
- case . dataPoint:
72
+ case . dataPoint( let angle ) :
136
73
HStack ( spacing: self . groupSpacing) {
137
74
ForEach ( dataSets. dataSets) { dataSet in
138
75
HStack ( spacing: 0 ) {
139
76
ForEach ( dataSet. dataPoints) { data in
140
77
Spacer ( )
141
78
. frame ( minWidth: 0 , maxWidth: 500 )
142
- Text ( data. wrappedXAxisLabel)
143
- . font ( . caption)
79
+ YAxisDataPointCell ( chartData: self , label: data. group. title, rotationAngle: angle)
144
80
. foregroundColor ( self . chartStyle. xAxisLabelColour)
145
- . lineLimit ( 1 )
146
- . minimumScaleFactor ( 0.5 )
147
- . accessibilityLabel ( Text ( " XAxisLabel " ) )
148
- . accessibilityValue ( Text ( " \( data. wrappedXAxisLabel) " ) )
81
+ . accessibilityLabel ( Text ( " X Axis Label " ) )
82
+ . accessibilityValue ( Text ( " \( data. group. title) " ) )
149
83
Spacer ( )
150
84
. frame ( minWidth: 0 , maxWidth: 500 )
151
85
}
@@ -165,17 +99,32 @@ public final class GroupedBarChartData: CTMultiBarChartDataProtocol {
165
99
. font ( . caption)
166
100
. foregroundColor ( self . chartStyle. xAxisLabelColour)
167
101
. lineLimit ( 1 )
168
- . minimumScaleFactor ( 0.5 )
169
- . accessibilityLabel ( Text ( " XAxisLabel " ) )
102
+ . accessibilityLabel ( Text ( " X Axis Label " ) )
170
103
. accessibilityValue ( Text ( " \( data) " ) )
171
104
Spacer ( )
172
105
. frame ( minWidth: 0 , maxWidth: 500 )
173
106
}
174
107
}
175
108
}
176
109
}
110
+ HStack ( spacing: self . groupSpacing) {
111
+ ForEach ( dataSets. dataSets) { dataSet in
112
+ HStack ( spacing: 0 ) {
113
+ Spacer ( )
114
+ . frame ( minWidth: 0 , maxWidth: 500 )
115
+ YAxisDataPointCell ( chartData: self , label: dataSet. setTitle, rotationAngle: . degrees( 0 ) )
116
+ . foregroundColor ( self . chartStyle. xAxisLabelColour)
117
+ . accessibilityLabel ( Text ( " X Axis Label " ) )
118
+ . accessibilityValue ( Text ( " \( dataSet. setTitle) " ) )
119
+ Spacer ( )
120
+ . frame ( minWidth: 0 , maxWidth: 500 )
121
+ }
122
+ }
123
+ }
124
+ . padding ( . horizontal, - 4 )
177
125
}
178
126
}
127
+
179
128
// MARK: Touch
180
129
public final func getTouchInteraction( touchLocation: CGPoint , chartSize: CGRect ) -> some View {
181
130
self . markerSubView ( )
0 commit comments