@ons/design-system 72.10.2 → 72.10.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/components/chart/bar-chart.js +0 -2
- package/components/chart/chart.js +11 -10
- package/components/chart/common-chart-options.js +0 -115
- package/components/chart/specific-chart-options.js +117 -0
- package/css/main.css +1 -1
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/objects/_page.scss +1 -1
|
@@ -79,6 +79,8 @@ class HighchartsBaseChart {
|
|
|
79
79
|
this.boxplot = new Boxplot();
|
|
80
80
|
this.extraLines = this.checkForExtraLines();
|
|
81
81
|
this.extraScatter = this.checkForExtraScatter();
|
|
82
|
+
// This code only needs to run once per request as it sets
|
|
83
|
+
// options that are used for all charts
|
|
82
84
|
if (window.isCommonChartOptionsDefined === undefined) {
|
|
83
85
|
this.setCommonChartOptions();
|
|
84
86
|
window.isCommonChartOptionsDefined = true;
|
|
@@ -175,7 +177,7 @@ class HighchartsBaseChart {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
// Disable the legend for single series charts
|
|
178
|
-
this.
|
|
180
|
+
this.specificChartOptions.disableLegendForSingleSeries(this.config);
|
|
179
181
|
};
|
|
180
182
|
|
|
181
183
|
// Check if the data labels should be hidden
|
|
@@ -188,7 +190,7 @@ class HighchartsBaseChart {
|
|
|
188
190
|
// Note this is not the same as the viewport width
|
|
189
191
|
// All responsive rules should be defined here to avoid overriding existing rules
|
|
190
192
|
setResponsiveOptions = () => {
|
|
191
|
-
let mobileChartOptions = this.
|
|
193
|
+
let mobileChartOptions = this.specificChartOptions.getMobileOptions(this.xAxisTickIntervalMobile, this.yAxisTickIntervalMobile);
|
|
192
194
|
if (this.chartType === 'column' || this.chartType === 'boxplot') {
|
|
193
195
|
const mobileColumnChartOptions = this.columnChart.getColumnChartMobileOptions(
|
|
194
196
|
this.config,
|
|
@@ -282,9 +284,6 @@ class HighchartsBaseChart {
|
|
|
282
284
|
this.scatterChart.updateMarkersForConfidenceLevels(scatterSeries);
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
|
-
if (this.chartType != 'bar') {
|
|
286
|
-
this.commonChartOptions.adjustChartHeight(currentChart, this.percentageHeightDesktop, this.percentageHeightMobile);
|
|
287
|
-
}
|
|
288
287
|
|
|
289
288
|
// If the chart has an extra line or lines, hide the data labels for
|
|
290
289
|
// that series, update the last point marker
|
|
@@ -295,8 +294,6 @@ class HighchartsBaseChart {
|
|
|
295
294
|
}
|
|
296
295
|
});
|
|
297
296
|
}
|
|
298
|
-
// Update the legend items for all charts
|
|
299
|
-
this.commonChartOptions.updateLegendSymbols(currentChart);
|
|
300
297
|
currentChart.redraw(false);
|
|
301
298
|
};
|
|
302
299
|
};
|
|
@@ -310,6 +307,11 @@ class HighchartsBaseChart {
|
|
|
310
307
|
if (this.rangeAnnotationsOptions) {
|
|
311
308
|
this.rangeAnnotationsOptions.addLine(currentChart);
|
|
312
309
|
}
|
|
310
|
+
if (this.chartType != 'bar') {
|
|
311
|
+
this.specificChartOptions.adjustChartHeight(currentChart, this.percentageHeightDesktop, this.percentageHeightMobile);
|
|
312
|
+
}
|
|
313
|
+
// Update the legend symbols on render to maintain them during resize
|
|
314
|
+
this.specificChartOptions.updateLegendSymbols(currentChart);
|
|
313
315
|
};
|
|
314
316
|
};
|
|
315
317
|
|
|
@@ -324,9 +326,8 @@ class HighchartsBaseChart {
|
|
|
324
326
|
// Update the data labels when the window is resized
|
|
325
327
|
if (this.chartType === 'bar' && !this.hideDataLabels) {
|
|
326
328
|
this.barChart.postLoadDataLabels(currentChart);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.commonChartOptions.adjustChartHeight(currentChart, this.percentageHeightDesktop, this.percentageHeightMobile);
|
|
329
|
+
// Force a single redraw after all updates
|
|
330
|
+
currentChart.redraw(false);
|
|
330
331
|
}
|
|
331
332
|
}, 50);
|
|
332
333
|
});
|
|
@@ -135,20 +135,6 @@ class CommonChartOptions {
|
|
|
135
135
|
|
|
136
136
|
getOptions = () => this.options;
|
|
137
137
|
|
|
138
|
-
getMobileOptions = (xAxisTickInterval, yAxisTickInterval) => {
|
|
139
|
-
return {
|
|
140
|
-
tooltip: {
|
|
141
|
-
enabled: false,
|
|
142
|
-
},
|
|
143
|
-
xAxis: {
|
|
144
|
-
tickInterval: xAxisTickInterval,
|
|
145
|
-
},
|
|
146
|
-
yAxis: {
|
|
147
|
-
tickInterval: yAxisTickInterval,
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
|
|
152
138
|
hideDataLabels = (series) => {
|
|
153
139
|
series.forEach((series) => {
|
|
154
140
|
series.update({
|
|
@@ -158,107 +144,6 @@ class CommonChartOptions {
|
|
|
158
144
|
});
|
|
159
145
|
});
|
|
160
146
|
};
|
|
161
|
-
|
|
162
|
-
disableLegendForSingleSeries = (config) => {
|
|
163
|
-
if (config.chart.type != 'boxplot' && config.series.length === 1) {
|
|
164
|
-
config.legend = {
|
|
165
|
-
enabled: false,
|
|
166
|
-
};
|
|
167
|
-
config.chart.marginTop = 50;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
updateLegendSymbols = (chart) => {
|
|
172
|
-
if (chart.legend.options.enabled) {
|
|
173
|
-
chart.legend.allItems.forEach((item, index) => {
|
|
174
|
-
const { legendItem, userOptions } = item;
|
|
175
|
-
const seriesType = userOptions?.type;
|
|
176
|
-
const { label, symbol, line } = legendItem || {};
|
|
177
|
-
|
|
178
|
-
if (seriesType === 'line') {
|
|
179
|
-
// This is the case for the column plus line chart - the series type is
|
|
180
|
-
// line, but the chart type is column. In this case we show a simple
|
|
181
|
-
// line symbol in the legend, but we need to move the label to the right
|
|
182
|
-
// to account for the longer line symbol
|
|
183
|
-
if (chart.userOptions.chart.type !== 'line') {
|
|
184
|
-
label?.attr({
|
|
185
|
-
x: 30, // Adjust label position to account for longer line
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// This is the scenario for a line chart with markers disabled
|
|
190
|
-
// We have custom code in line-chart.js to update the last point to
|
|
191
|
-
// display as a symbol. This code checks if there is no symbol in the legend
|
|
192
|
-
// (which means it is a line chart with markers disabled)
|
|
193
|
-
// and if so, it updates the legend to display as a symbol rather than as a line
|
|
194
|
-
// We only to this for chart types that are explicitly line charts - i.e. not column with line
|
|
195
|
-
if (!symbol && label && label.element && chart.userOptions.chart.type === 'line') {
|
|
196
|
-
// Hide the line in the legend
|
|
197
|
-
if (line) {
|
|
198
|
-
line.hide();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Create a custom symbol for the legend using the line marker symbol options
|
|
202
|
-
const renderer = chart.renderer;
|
|
203
|
-
const bbox = label.element.getBBox();
|
|
204
|
-
const markerStyle = this.constants.lineMarkerStyles[index % this.constants.lineMarkerStyles.length];
|
|
205
|
-
|
|
206
|
-
const legendSymbol = renderer
|
|
207
|
-
.symbol(markerStyle.symbol, bbox.x - 30, bbox.y + 4, 12, markerStyle.radius, markerStyle.radius)
|
|
208
|
-
.attr({
|
|
209
|
-
fill: item.color,
|
|
210
|
-
stroke: item.color,
|
|
211
|
-
'stroke-width': 1,
|
|
212
|
-
width: 12,
|
|
213
|
-
height: 12,
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
legendSymbol.add(label.parentGroup);
|
|
217
|
-
label?.attr({
|
|
218
|
-
x: 15, // Adjust label position to account for shorter space that the symbol takes up
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
} else if (seriesType === 'columnrange') {
|
|
222
|
-
symbol.attr({
|
|
223
|
-
width: 14,
|
|
224
|
-
height: 14,
|
|
225
|
-
y: 8,
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
if (!symbol) return;
|
|
229
|
-
// Update the symbol width and height
|
|
230
|
-
// For column, bar and other chart types
|
|
231
|
-
else {
|
|
232
|
-
symbol.attr({
|
|
233
|
-
width: 12,
|
|
234
|
-
height: 12,
|
|
235
|
-
y: 8,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
adjustChartHeight = (currentChart, percentageHeightDesktop, percentageHeightMobile) => {
|
|
244
|
-
// get height and width of the plot area
|
|
245
|
-
const plotHeight = currentChart.plotHeight;
|
|
246
|
-
const plotWidth = currentChart.plotWidth;
|
|
247
|
-
// calculate the new plot height based on the percentage height
|
|
248
|
-
// default to the current height
|
|
249
|
-
let newPlotHeight = plotHeight;
|
|
250
|
-
if (plotWidth > 400) {
|
|
251
|
-
newPlotHeight = plotWidth * (percentageHeightDesktop / 100);
|
|
252
|
-
} else {
|
|
253
|
-
newPlotHeight = plotWidth * (percentageHeightMobile / 100);
|
|
254
|
-
}
|
|
255
|
-
const totalHeight = currentChart.plotTop + newPlotHeight + currentChart.marginBottom;
|
|
256
|
-
|
|
257
|
-
// set the new size of the chart
|
|
258
|
-
if (totalHeight !== currentChart.chartHeight) {
|
|
259
|
-
currentChart.setSize(null, totalHeight, false);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
147
|
}
|
|
263
148
|
|
|
264
149
|
export default CommonChartOptions;
|
|
@@ -18,6 +18,49 @@ class SpecificChartOptions {
|
|
|
18
18
|
|
|
19
19
|
getOptions = () => this.options;
|
|
20
20
|
|
|
21
|
+
getMobileOptions = (xAxisTickInterval, yAxisTickInterval) => {
|
|
22
|
+
return {
|
|
23
|
+
tooltip: {
|
|
24
|
+
enabled: false,
|
|
25
|
+
},
|
|
26
|
+
xAxis: {
|
|
27
|
+
tickInterval: xAxisTickInterval,
|
|
28
|
+
},
|
|
29
|
+
yAxis: {
|
|
30
|
+
tickInterval: yAxisTickInterval,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
disableLegendForSingleSeries = (config) => {
|
|
36
|
+
if (config.chart.type != 'boxplot' && config.series.length === 1) {
|
|
37
|
+
config.legend = {
|
|
38
|
+
enabled: false,
|
|
39
|
+
};
|
|
40
|
+
config.chart.marginTop = 50;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
adjustChartHeight = (currentChart, percentageHeightDesktop, percentageHeightMobile) => {
|
|
45
|
+
// get height and width of the plot area
|
|
46
|
+
const plotHeight = currentChart.plotHeight;
|
|
47
|
+
const plotWidth = currentChart.plotWidth;
|
|
48
|
+
// calculate the new plot height based on the percentage height
|
|
49
|
+
// default to the current height
|
|
50
|
+
let newPlotHeight = plotHeight;
|
|
51
|
+
if (plotWidth > 400) {
|
|
52
|
+
newPlotHeight = Math.round(plotWidth * (percentageHeightDesktop / 100));
|
|
53
|
+
} else {
|
|
54
|
+
newPlotHeight = Math.round(plotWidth * (percentageHeightMobile / 100));
|
|
55
|
+
}
|
|
56
|
+
const totalHeight = currentChart.plotTop + newPlotHeight + currentChart.marginBottom;
|
|
57
|
+
|
|
58
|
+
// set the new size of the chart
|
|
59
|
+
if (totalHeight !== currentChart.chartHeight) {
|
|
60
|
+
currentChart.setSize(null, totalHeight, false);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
21
64
|
// Add zero line or custom reference line (but only for column or line charts)
|
|
22
65
|
getReferenceLine = (customReferenceLineValue, chartType) => {
|
|
23
66
|
let lineValue = 0;
|
|
@@ -38,6 +81,80 @@ class SpecificChartOptions {
|
|
|
38
81
|
},
|
|
39
82
|
};
|
|
40
83
|
};
|
|
84
|
+
|
|
85
|
+
updateLegendSymbols = (chart) => {
|
|
86
|
+
if (chart.legend.options.enabled) {
|
|
87
|
+
chart.legend.allItems.forEach((item, index) => {
|
|
88
|
+
const { legendItem, userOptions } = item;
|
|
89
|
+
const seriesType = userOptions?.type;
|
|
90
|
+
const { label, symbol, line } = legendItem || {};
|
|
91
|
+
|
|
92
|
+
if (seriesType === 'line') {
|
|
93
|
+
// This is the case for the column plus line chart - the series type is
|
|
94
|
+
// line, but the chart type is column. In this case we show a simple
|
|
95
|
+
// line symbol in the legend, but we need to move the label to the right
|
|
96
|
+
// to account for the longer line symbol
|
|
97
|
+
if (chart.userOptions.chart.type !== 'line') {
|
|
98
|
+
label?.attr({
|
|
99
|
+
x: 30, // Adjust label position to account for longer line
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// This is the scenario for a line chart with markers disabled
|
|
104
|
+
// We have custom code in line-chart.js to update the last point to
|
|
105
|
+
// display as a symbol. This code checks if there is no symbol in the legend
|
|
106
|
+
// (which means it is a line chart with markers disabled)
|
|
107
|
+
// and if so, it updates the legend to display as a symbol rather than as a line
|
|
108
|
+
// We only to this for chart types that are explicitly line charts - i.e. not column with line
|
|
109
|
+
if (!symbol && label && label.element && chart.userOptions.chart.type === 'line') {
|
|
110
|
+
// Hide the line in the legend
|
|
111
|
+
if (line) {
|
|
112
|
+
line.hide();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Remove any existing custom symbols for this legend item
|
|
116
|
+
const existingSymbols = label.parentGroup.element.querySelectorAll('[data-custom-legend-symbol]');
|
|
117
|
+
existingSymbols.forEach((symbol) => symbol.remove());
|
|
118
|
+
|
|
119
|
+
// Create a custom symbol for the legend using the line marker symbol options
|
|
120
|
+
const renderer = chart.renderer;
|
|
121
|
+
const bbox = label.element.getBBox();
|
|
122
|
+
const markerStyle = this.constants.lineMarkerStyles[index % this.constants.lineMarkerStyles.length];
|
|
123
|
+
|
|
124
|
+
const legendSymbol = renderer
|
|
125
|
+
.symbol(markerStyle.symbol, bbox.x - 22, bbox.y + 4, 12, markerStyle.radius, markerStyle.radius)
|
|
126
|
+
.attr({
|
|
127
|
+
fill: item.color,
|
|
128
|
+
stroke: item.color,
|
|
129
|
+
'stroke-width': 1,
|
|
130
|
+
width: 12,
|
|
131
|
+
height: 12,
|
|
132
|
+
'data-custom-legend-symbol': true,
|
|
133
|
+
});
|
|
134
|
+
legendSymbol.add(label.parentGroup);
|
|
135
|
+
label?.attr({
|
|
136
|
+
x: 15, // Adjust label position to account for shorter space that the symbol takes up
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
} else if (seriesType === 'columnrange') {
|
|
140
|
+
symbol.attr({
|
|
141
|
+
width: 14,
|
|
142
|
+
height: 14,
|
|
143
|
+
y: 8,
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
if (!symbol) return;
|
|
147
|
+
// Update the symbol width and height
|
|
148
|
+
// For column, bar and other chart types
|
|
149
|
+
symbol.attr({
|
|
150
|
+
width: 12,
|
|
151
|
+
height: 12,
|
|
152
|
+
y: 8,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
41
158
|
}
|
|
42
159
|
|
|
43
160
|
export default SpecificChartOptions;
|