@fluentui/react-charting 5.19.2 → 5.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +31 -1
- package/CHANGELOG.md +11 -2
- package/dist/react-charting.js +1 -1
- package/dist/react-charting.min.js +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/lib-amd/version.js +1 -1
- package/lib-amd/version.js.map +1 -1
- package/lib-commonjs/version.js +1 -1
- package/lib-commonjs/version.js.map +1 -1
- package/package.json +4 -4
- package/docs/TechnicalDetails.md +0 -88
- package/docs/TestPlans/AreaChart/ComponentTests.md +0 -61
- package/docs/TestPlans/BasicDonutChart.png +0 -0
- package/docs/TestPlans/DonutChart/ComponentTests.md +0 -35
- package/docs/TestPlans/GaugeChart/ComponentTests.md +0 -31
- package/docs/TestPlans/GroupedVerticalBarChart/ComponentTests.md +0 -62
- package/docs/TestPlans/HorizontalBarChart/ComponentTests.md +0 -51
- package/docs/TestPlans/LineChart/ComponentTests.md +0 -63
- package/docs/TestPlans/MultiStackedBarChart/componentTests.md +0 -56
- package/docs/TestPlans/StackedBarChart/ComponentTests.md +0 -64
- package/docs/TestPlans/TestingGuide.md +0 -13
- package/docs/TestPlans/Utilities/UnitTests.md +0 -16
- package/docs/TestPlans/VerticalBarChart/ComponentTests.md +0 -65
- package/docs/TestPlans/VerticalStackedBarChart/ComponentTests.md +0 -73
- package/docs/colors.md +0 -149
- package/docs/implementing-2-to-1-spacing.md +0 -215
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
# Implementing 2:1 spacing
|
|
2
|
-
|
|
3
|
-
## Discrete Axis
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
As per design specs, there should be a minimum space of 8px before the first bar and after the last bar of a vertical bar chart. Let’s call this space `MIN_DOMAIN_MARGIN`.
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
const MIN_DOMAIN_MARGIN = 8;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
The total space available to render the bars:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
const totalWidth = containerWidth - (this.margins.left! + MIN_DOMAIN_MARGIN) - (this.margins.right! + MIN_DOMAIN_MARGIN);
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
where\
|
|
20
|
-
`containerWidth` is the total width of the SVG,\
|
|
21
|
-
`margins` define the space from the SVG edges that must be excluded before rendering the bars. It helps to prevent the bars from overlapping with the axis labels.
|
|
22
|
-
|
|
23
|
-
Construct a scale to define the geometry of the bars:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
const xBarScale = d3ScaleBand()
|
|
27
|
-
.domain(this._xAxisLabels)
|
|
28
|
-
.range([this.margins.left! + MIN_DOMAIN_MARGIN, containerWidth - this.margins.right! - MIN_DOMAIN_MARGIN])
|
|
29
|
-
.paddingInner(2 / 3);
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
where\
|
|
33
|
-
`_xAxisLabels` is an array of labels in the x-axis,\
|
|
34
|
-
`paddingInner` is the ratio of the range that is reserved for blank space between bands (bars).
|
|
35
|
-
|
|
36
|
-
$$
|
|
37
|
-
paddingInner = {spaceBetweenBars \over spaceBetweenBars + barWidth}
|
|
38
|
-
$$
|
|
39
|
-
|
|
40
|
-
$$
|
|
41
|
-
spaceBetweenBars = 2 * barWidth
|
|
42
|
-
$$
|
|
43
|
-
|
|
44
|
-
$$
|
|
45
|
-
\implies paddingInner = {2 \over 3}
|
|
46
|
-
$$
|
|
47
|
-
|
|
48
|
-

|
|
49
|
-
|
|
50
|
-
### Problem
|
|
51
|
-
|
|
52
|
-
The bandwidth generated by the scale can be different from the bar width provided by the user.
|
|
53
|
-
|
|
54
|
-
### Solution
|
|
55
|
-
|
|
56
|
-
As per design specs, the default bar width is 16px. Users can adjust it with values ranging from 1px to 24px.
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
let barWidth = Math.min(this.props.barWidth || 16, 24);
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
The total space required to render the bars of provided width with 2:1 spacing:
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
const reqWidth = this._xAxisLabels.length * barWidth + (this._xAxisLabels.length - 1) * barWidth * 2;
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
where\
|
|
69
|
-
`_xAxisLabels.length` is equal to the maximum number of bars.
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
this._domainMargin = MIN_DOMAIN_MARGIN;
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
where\
|
|
76
|
-
`_domainMargin` keeps track of the blank space before the first bar and after the last bar.
|
|
77
|
-
|
|
78
|
-
If more space is available after rendering the bars, center align the chart.
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
if (totalWidth >= reqWidth) {
|
|
82
|
-
this._domainMargin += (totalWidth - reqWidth) / 2;
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
If more space is required to render the bars of provided width, decrease the bar width to maintain 2:1 spacing.
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
else {
|
|
90
|
-
const maxBandwidth = totalWidth / (this._xAxisLabels.length + (this._xAxisLabels.length - 1) * 2);
|
|
91
|
-
barWidth = maxBandwidth;
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
where\
|
|
96
|
-
`maxBandwidth` is the maximum possible bar width such that the bars can be rendered within the total available space with 2:1 spacing. Derived from the formula for `reqWidth`.
|
|
97
|
-
|
|
98
|
-
Make the adjusted bar width available to use everywhere inside the component:
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
this._barWidth = barWidth;
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Update the scale range to take the extra space into account by replacing `MIN_DOMAIN_MARGIN` with `_domainMargin`:
|
|
105
|
-
|
|
106
|
-
```
|
|
107
|
-
const xBarScale = d3ScaleBand()
|
|
108
|
-
.domain(this._xAxisLabels)
|
|
109
|
-
.range([this.margins.left! + this._domainMargin, containerWidth - this.margins.right! - this._domainMargin])
|
|
110
|
-
.paddingInner(2 / 3);
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-

|
|
114
|
-
|
|
115
|
-
### Problem
|
|
116
|
-
|
|
117
|
-
The domain (x-axis labels) doesn’t sync with the bars.
|
|
118
|
-
|
|
119
|
-
### Solution
|
|
120
|
-
|
|
121
|
-
Create a function to generate margins for the domain, taking the extra space into account:
|
|
122
|
-
|
|
123
|
-

|
|
124
|
-
_VerticalStackedBarChart.base.tsx_
|
|
125
|
-
|
|
126
|
-
Pass the function and the same inner padding to the `CartesianChart` common component where the axes are created:
|
|
127
|
-
|
|
128
|
-

|
|
129
|
-
_VerticalStackedBarChart.base.tsx_
|
|
130
|
-
|
|
131
|
-
Update parameters of the function that creates the axis:
|
|
132
|
-
|
|
133
|
-

|
|
134
|
-
_CartesianChart.base.tsx_
|
|
135
|
-
|
|
136
|
-
Set the inner padding while constructing the scale for the axis:
|
|
137
|
-
|
|
138
|
-

|
|
139
|
-
_utilities.ts_
|
|
140
|
-
|
|
141
|
-

|
|
142
|
-
|
|
143
|
-
### Special Case: GroupedVerticalBarChart
|
|
144
|
-
|
|
145
|
-

|
|
146
|
-
|
|
147
|
-
Construct a scale to define the geometry of the bars in a group:
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
const X1_INNER_PADDING = 0.1;
|
|
151
|
-
|
|
152
|
-
const xScale1 = d3ScaleBand()
|
|
153
|
-
.domain(this._keys)
|
|
154
|
-
.range([0, xScale0.bandwidth()])
|
|
155
|
-
.paddingInner(X1_INNER_PADDING);
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
where\
|
|
159
|
-
`_keys` is an array of strings that identify the bars in a group.
|
|
160
|
-
|
|
161
|
-
$$
|
|
162
|
-
x1InnerPadding = {spaceBetweenBars \over spaceBetweenBars + barWidth}
|
|
163
|
-
$$
|
|
164
|
-
|
|
165
|
-
$$
|
|
166
|
-
\implies spaceBetweenBars = {x1InnerPadding \over 1 - x1InnerPadding} * barWidth
|
|
167
|
-
$$
|
|
168
|
-
|
|
169
|
-
```
|
|
170
|
-
const BAR_GAP_RATE = X1_INNER_PADDING / (1 - X1_INNER_PADDING);
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
$$
|
|
174
|
-
\implies spaceBetweenBars = barGapRate * barWidth
|
|
175
|
-
$$
|
|
176
|
-
|
|
177
|
-
Construct a scale to define the geometry of the groups:
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
const xScale0 = d3ScaleBand()
|
|
181
|
-
.domain(this._xAxisLabels)
|
|
182
|
-
.range([this.margins.left! + this._domainMargin, containerWidth! - this.margins.right! - this._domainMargin])
|
|
183
|
-
.paddingInner(2 / (2 + this._keys.length + (this._keys.length - 1) * BAR_GAP_RATE));
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
where\
|
|
187
|
-
`_keys.length` is equal to the number of bars in a group.
|
|
188
|
-
|
|
189
|
-
$$
|
|
190
|
-
x0InnerPadding = {spaceBetweenGroups \over spaceBetweenGroups + groupWidth}
|
|
191
|
-
$$
|
|
192
|
-
|
|
193
|
-
$$
|
|
194
|
-
spaceBetweenGroups = 2 * barWidth
|
|
195
|
-
$$
|
|
196
|
-
|
|
197
|
-
$$
|
|
198
|
-
groupWidth = numBarsInGroup * barWidth + (numBarsInGroup - 1) * spaceBetweenBars
|
|
199
|
-
$$
|
|
200
|
-
|
|
201
|
-
$$
|
|
202
|
-
\implies x0InnerPadding = {2 \over 2 + numBarsInGroup + (numBarsInGroup - 1) * barGapRate}
|
|
203
|
-
$$
|
|
204
|
-
|
|
205
|
-
Create a function to generate margins for the domain, taking the extra space into account:
|
|
206
|
-
|
|
207
|
-

|
|
208
|
-
_GroupedVerticalBarChart.base.tsx_
|
|
209
|
-
|
|
210
|
-
Pass the function and the same inner padding to the `CartesianChart` common component where the axes are created:
|
|
211
|
-
|
|
212
|
-

|
|
213
|
-
_GroupedVerticalBarChart.base.tsx_
|
|
214
|
-
|
|
215
|
-
**Note:** The bars and the x-axis use separate scales for rendering, and code changes are done to sync these scales. A better solution would be to share the same scale with both, but doing so will need a lot of refactoring in the shared/common code.
|