@ons/design-system 72.10.2 → 72.10.4
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/card/_card.scss +1 -0
- package/components/card/example-card-set-with-headline-figures.njk +4 -4
- package/components/chart/_macro.njk +34 -34
- package/components/chart/_macro.spec.js +0 -49
- package/components/chart/bar-chart.js +0 -2
- package/components/chart/chart.js +28 -17
- package/components/chart/columnrange-chart.js +3 -0
- package/components/chart/common-chart-options.js +1 -128
- package/components/chart/example-bar-with-confidence-levels.njk +0 -5
- package/components/chart/example-column-with-confidence-levels.njk +1 -4
- package/components/chart/example-scatter-chart.njk +4 -8
- package/components/chart/specific-chart-options.js +141 -1
- package/components/description-list/_description-list.scss +7 -6
- package/components/description-list/_macro.njk +1 -1
- package/components/details-panel/_details-panel.scss +40 -20
- package/components/details-panel/_macro.njk +18 -12
- package/components/details-panel/example-details-panel.njk +1 -0
- package/components/featured-article/_macro.njk +76 -0
- package/components/featured-article/example-featured-article-with-chart.njk +223 -0
- package/components/featured-article/example-featured-article-with-image.njk +24 -0
- package/components/featured-article/featured-article.scss +33 -0
- package/components/featured-article/macro.spec.js +173 -0
- package/components/header/_header.scss +34 -1
- package/components/header/_macro.njk +140 -132
- package/components/hero/_hero.scss +5 -0
- package/components/hero/_macro.njk +8 -4
- package/components/hero/example-hero-grey.njk +2 -17
- package/css/main.css +1 -1
- package/css/print.css +1 -1
- package/js/details.js +39 -0
- package/js/main.js +1 -0
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -0
- package/scss/objects/_page.scss +1 -1
- package/scss/print.scss +6 -1
- package/scss/utilities/_grid.scss +46 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{% from "components/card/_macro.njk" import onsCard %}
|
|
2
2
|
|
|
3
3
|
<div class="ons-container">
|
|
4
|
-
<div class="ons-grid ons-grid-flex ons-grid-flex--vertical-top">
|
|
5
|
-
<div class="ons-grid__col ons-grid__col--flex-col ons-grid__col--stretch
|
|
4
|
+
<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--s ons-grid-flex--vertical-top">
|
|
5
|
+
<div class="ons-grid__col ons-grid__col--flex-col ons-grid__col--stretch">
|
|
6
6
|
{{
|
|
7
7
|
onsCard({
|
|
8
8
|
"variant": 'feature',
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
}}
|
|
21
21
|
</div>
|
|
22
22
|
|
|
23
|
-
<div class="ons-grid__col ons-grid__col--flex-col ons-grid__col--stretch
|
|
23
|
+
<div class="ons-grid__col ons-grid__col--flex-col ons-grid__col--stretch">
|
|
24
24
|
{{
|
|
25
25
|
onsCard({
|
|
26
26
|
"variant": 'feature',
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
}}
|
|
39
39
|
</div>
|
|
40
40
|
|
|
41
|
-
<div class="ons-grid__col ons-grid__col--flex-col ons-grid__col--stretch
|
|
41
|
+
<div class="ons-grid__col ons-grid__col--flex-col ons-grid__col--stretch">
|
|
42
42
|
{{
|
|
43
43
|
onsCard({
|
|
44
44
|
"variant": 'feature',
|
|
@@ -2,14 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
{% macro onsChart(params) %}
|
|
4
4
|
{% set supportedChartTypes = ['line', 'bar', 'column', 'scatter', 'area', 'columnrange', 'boxplot'] %}
|
|
5
|
-
{% set supportedChartTypesWithLine = ['column'
|
|
5
|
+
{% set supportedChartTypesWithLine = ['column'] %}
|
|
6
6
|
{% set supportedChartTypesWithScatter = ['columnrange'] %}
|
|
7
|
-
|
|
8
|
-
{% if params.headingLevel and params.headingLevel >= 1 and params.headingLevel <= 4 %}
|
|
9
|
-
{% set headingLevel = params.headingLevel %}
|
|
10
|
-
{% else %}
|
|
11
|
-
{% set headingLevel = 2 %}
|
|
12
|
-
{% endif %}
|
|
7
|
+
{% set headingLevel = params.headingLevel | default(2) %}
|
|
13
8
|
{% set openingTitleTag = "<h" ~ headingLevel %}
|
|
14
9
|
{% set closingTitleTag = "</h" ~ headingLevel ~ ">" %}
|
|
15
10
|
{% set openingSubtitleTag = "<h" ~ (headingLevel + 1) %}
|
|
@@ -53,8 +48,11 @@
|
|
|
53
48
|
>
|
|
54
49
|
<figure class="ons-chart">
|
|
55
50
|
{{ openingTitleTag | safe }} class="ons-chart__title">{{ params.title }}{{ closingTitleTag | safe }}
|
|
56
|
-
{
|
|
57
|
-
|
|
51
|
+
{% if params.subtitle %}
|
|
52
|
+
{{ openingSubtitleTag | safe }}
|
|
53
|
+
class="ons-chart__subtitle">{{ params.subtitle }}{{ closingSubtitleTag | safe }}
|
|
54
|
+
{% endif %}
|
|
55
|
+
|
|
58
56
|
{% if params.description %}
|
|
59
57
|
<p class="ons-u-vh">{{ params.description }}</p>
|
|
60
58
|
{% endif %}
|
|
@@ -83,28 +81,31 @@
|
|
|
83
81
|
Footnotes for the annotations at mobile
|
|
84
82
|
Hidden from screen readers because the full text will be read out where they appear in the chart
|
|
85
83
|
#}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
84
|
+
{% if params.annotations or params.rangeAnnotations or params.referenceLineAnnotations %}
|
|
85
|
+
<ul class="ons-chart__footnotes" aria-hidden="true">
|
|
86
|
+
{% for annotation in params.annotations %}
|
|
87
|
+
<li class="ons-chart__footnote_item">
|
|
88
|
+
<span class="ons-chart__footnote-number">{{ loop.index }}</span>
|
|
89
|
+
{{ annotation.text }}
|
|
90
|
+
</li>
|
|
91
|
+
{% endfor %}
|
|
92
|
+
{% for rangeAnnotation in params.rangeAnnotations %}
|
|
93
|
+
<li class="ons-chart__footnote_item">
|
|
94
|
+
<span class="ons-chart__footnote-number">{{ loop.index + params.annotations | length }}</span>
|
|
95
|
+
{{ rangeAnnotation.text }}
|
|
96
|
+
</li>
|
|
97
|
+
{% endfor %}
|
|
98
|
+
{% for referenceLineAnnotation in params.referenceLineAnnotations %}
|
|
99
|
+
<li class="ons-chart__footnote_item">
|
|
100
|
+
<span class="ons-chart__footnote-number"
|
|
101
|
+
>{{ loop.index + params.annotations | length + params.rangeAnnotations | length }}</span
|
|
102
|
+
>
|
|
103
|
+
{{ referenceLineAnnotation.text }}
|
|
104
|
+
</li>
|
|
105
|
+
{% endfor %}
|
|
106
|
+
</ul>
|
|
107
|
+
{% endif %}
|
|
108
|
+
|
|
108
109
|
{% if params.caption %}
|
|
109
110
|
<figcaption class="ons-chart__caption">{{ params.caption }}</figcaption>
|
|
110
111
|
{% endif %}
|
|
@@ -132,7 +133,7 @@
|
|
|
132
133
|
"name": item.name if item.name else '',
|
|
133
134
|
"data": item.data if item.data else [],
|
|
134
135
|
"marker": {
|
|
135
|
-
"enabled": item.
|
|
136
|
+
"enabled": true if (item.type == 'scatter' or params.chartType == 'scatter' or item.marker == true) else false
|
|
136
137
|
},
|
|
137
138
|
"dataLabels": {
|
|
138
139
|
"enabled": item.dataLabels if item.dataLabels else false
|
|
@@ -160,8 +161,7 @@
|
|
|
160
161
|
{%
|
|
161
162
|
set config = {
|
|
162
163
|
"chart": {
|
|
163
|
-
"type": params.chartType
|
|
164
|
-
"inverted": params.isChartInverted if params.isChartInverted == true else false
|
|
164
|
+
"type": params.chartType
|
|
165
165
|
},
|
|
166
166
|
"legend": {
|
|
167
167
|
"enabled" : legendValue
|
|
@@ -1132,55 +1132,6 @@ describe('Macro: Chart', () => {
|
|
|
1132
1132
|
expect(configScript).toContain('"type":"columnrange"');
|
|
1133
1133
|
expect(configScript).toContain('"type":"scatter"');
|
|
1134
1134
|
});
|
|
1135
|
-
|
|
1136
|
-
describe('GIVEN: Params: isChartInverted', () => {
|
|
1137
|
-
describe('WHEN: isChartInverted parameter is provided and set to true', () => {
|
|
1138
|
-
const $ = cheerio.load(
|
|
1139
|
-
renderComponent('chart', {
|
|
1140
|
-
...EXAMPLE_COLUMN_RANGE_CHART_PARAMS,
|
|
1141
|
-
isChartInverted: true,
|
|
1142
|
-
}),
|
|
1143
|
-
);
|
|
1144
|
-
test('THEN: it sets isChartInverted to true', () => {
|
|
1145
|
-
const configScript = $(`script[data-highcharts-config--uuid]`).html();
|
|
1146
|
-
expect(configScript).toContain('"chart":{"type":"columnrange","inverted":true}');
|
|
1147
|
-
});
|
|
1148
|
-
});
|
|
1149
|
-
|
|
1150
|
-
describe('WHEN: isChartInverted parameter is provided and set to false', () => {
|
|
1151
|
-
const $ = cheerio.load(
|
|
1152
|
-
renderComponent('chart', {
|
|
1153
|
-
...EXAMPLE_COLUMN_RANGE_CHART_PARAMS,
|
|
1154
|
-
isChartInverted: false,
|
|
1155
|
-
}),
|
|
1156
|
-
);
|
|
1157
|
-
test('THEN: it sets isChartInverted to false', () => {
|
|
1158
|
-
const configScript = $(`script[data-highcharts-config--uuid]`).html();
|
|
1159
|
-
expect(configScript).toContain('"chart":{"type":"columnrange","inverted":false}');
|
|
1160
|
-
});
|
|
1161
|
-
});
|
|
1162
|
-
|
|
1163
|
-
describe('WHEN: isChartInverted parameter is not provided', () => {
|
|
1164
|
-
const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_RANGE_CHART_PARAMS));
|
|
1165
|
-
test('THEN: it sets isChartInverted to false', () => {
|
|
1166
|
-
const configScript = $(`script[data-highcharts-config--uuid]`).html();
|
|
1167
|
-
expect(configScript).toContain('"chart":{"type":"columnrange","inverted":false}');
|
|
1168
|
-
});
|
|
1169
|
-
});
|
|
1170
|
-
|
|
1171
|
-
describe('WHEN: isChartInverted parameter is provided but is not a boolean', () => {
|
|
1172
|
-
const $ = cheerio.load(
|
|
1173
|
-
renderComponent('chart', {
|
|
1174
|
-
...EXAMPLE_COLUMN_RANGE_CHART_PARAMS,
|
|
1175
|
-
isChartInverted: 'false',
|
|
1176
|
-
}),
|
|
1177
|
-
);
|
|
1178
|
-
test('THEN: it sets isChartInverted to false', () => {
|
|
1179
|
-
const configScript = $(`script[data-highcharts-config--uuid]`).html();
|
|
1180
|
-
expect(configScript).toContain('"chart":{"type":"columnrange","inverted":false}');
|
|
1181
|
-
});
|
|
1182
|
-
});
|
|
1183
|
-
});
|
|
1184
1135
|
});
|
|
1185
1136
|
});
|
|
1186
1137
|
});
|
|
@@ -62,14 +62,20 @@ class HighchartsBaseChart {
|
|
|
62
62
|
this.yAxisTickIntervalDesktop = this.node.dataset.highchartsYAxisTickIntervalDesktop
|
|
63
63
|
? parseInt(this.node.dataset.highchartsYAxisTickIntervalDesktop)
|
|
64
64
|
: undefined;
|
|
65
|
-
this.commonChartOptions = new CommonChartOptions(
|
|
65
|
+
this.commonChartOptions = new CommonChartOptions();
|
|
66
66
|
this.estimateLineLabel = this.node.dataset.highchartsEstimateLineLabel;
|
|
67
67
|
this.uncertainyRangeLabel = this.node.dataset.highchartsUncertaintyRangeLabel;
|
|
68
68
|
this.customReferenceLineValue = this.node.dataset.highchartsCustomReferenceLineValue
|
|
69
69
|
? parseFloat(this.node.dataset.highchartsCustomReferenceLineValue)
|
|
70
70
|
: undefined;
|
|
71
71
|
|
|
72
|
-
this.specificChartOptions = new SpecificChartOptions(
|
|
72
|
+
this.specificChartOptions = new SpecificChartOptions(
|
|
73
|
+
this.theme,
|
|
74
|
+
this.chartType,
|
|
75
|
+
this.config,
|
|
76
|
+
this.xAxisTickIntervalDesktop,
|
|
77
|
+
this.yAxisTickIntervalDesktop,
|
|
78
|
+
);
|
|
73
79
|
this.lineChart = new LineChart();
|
|
74
80
|
this.barChart = new BarChart();
|
|
75
81
|
this.columnChart = new ColumnChart();
|
|
@@ -79,6 +85,8 @@ class HighchartsBaseChart {
|
|
|
79
85
|
this.boxplot = new Boxplot();
|
|
80
86
|
this.extraLines = this.checkForExtraLines();
|
|
81
87
|
this.extraScatter = this.checkForExtraScatter();
|
|
88
|
+
// This code only needs to run once per request as it sets
|
|
89
|
+
// options that are used for all charts
|
|
82
90
|
if (window.isCommonChartOptionsDefined === undefined) {
|
|
83
91
|
this.setCommonChartOptions();
|
|
84
92
|
window.isCommonChartOptionsDefined = true;
|
|
@@ -175,7 +183,7 @@ class HighchartsBaseChart {
|
|
|
175
183
|
}
|
|
176
184
|
|
|
177
185
|
// Disable the legend for single series charts
|
|
178
|
-
this.
|
|
186
|
+
this.specificChartOptions.disableLegendForSingleSeries(this.config);
|
|
179
187
|
};
|
|
180
188
|
|
|
181
189
|
// Check if the data labels should be hidden
|
|
@@ -188,7 +196,7 @@ class HighchartsBaseChart {
|
|
|
188
196
|
// Note this is not the same as the viewport width
|
|
189
197
|
// All responsive rules should be defined here to avoid overriding existing rules
|
|
190
198
|
setResponsiveOptions = () => {
|
|
191
|
-
let mobileChartOptions = this.
|
|
199
|
+
let mobileChartOptions = this.specificChartOptions.getMobileOptions(this.xAxisTickIntervalMobile, this.yAxisTickIntervalMobile);
|
|
192
200
|
if (this.chartType === 'column' || this.chartType === 'boxplot') {
|
|
193
201
|
const mobileColumnChartOptions = this.columnChart.getColumnChartMobileOptions(
|
|
194
202
|
this.config,
|
|
@@ -257,46 +265,45 @@ class HighchartsBaseChart {
|
|
|
257
265
|
const currentChart = event.target;
|
|
258
266
|
if (this.chartType === 'line') {
|
|
259
267
|
this.lineChart.updateLastPointMarker(currentChart.series);
|
|
260
|
-
this.
|
|
268
|
+
this.specificChartOptions.hideDataLabels(currentChart.series);
|
|
261
269
|
}
|
|
262
270
|
if (this.chartType === 'bar') {
|
|
263
271
|
this.barChart.updateBarChartHeight(this.config, currentChart, this.useStackedLayout);
|
|
264
272
|
if (!this.hideDataLabels) {
|
|
265
273
|
this.barChart.postLoadDataLabels(currentChart);
|
|
266
274
|
} else {
|
|
267
|
-
this.
|
|
275
|
+
this.specificChartOptions.hideDataLabels(currentChart.series);
|
|
268
276
|
}
|
|
269
277
|
}
|
|
270
278
|
if (this.chartType === 'column') {
|
|
271
|
-
this.
|
|
279
|
+
this.specificChartOptions.hideDataLabels(currentChart.series);
|
|
272
280
|
}
|
|
273
281
|
if (this.chartType === 'scatter') {
|
|
274
282
|
this.scatterChart.updateMarkers(currentChart);
|
|
283
|
+
this.specificChartOptions.hideDataLabels(currentChart.series);
|
|
284
|
+
}
|
|
285
|
+
if (this.chartType === 'boxplot') {
|
|
286
|
+
this.specificChartOptions.hideDataLabels(currentChart.series);
|
|
275
287
|
}
|
|
276
288
|
if (this.chartType === 'columnrange') {
|
|
277
289
|
this.columnRangeChart.updateColumnRangeChartHeight(this.config, currentChart);
|
|
278
|
-
this.
|
|
290
|
+
this.specificChartOptions.hideDataLabels(currentChart.series);
|
|
279
291
|
|
|
280
292
|
if (this.extraScatter > 0) {
|
|
281
293
|
const scatterSeries = currentChart.series.filter((series) => series.type === 'scatter');
|
|
282
294
|
this.scatterChart.updateMarkersForConfidenceLevels(scatterSeries);
|
|
283
295
|
}
|
|
284
296
|
}
|
|
285
|
-
if (this.chartType != 'bar') {
|
|
286
|
-
this.commonChartOptions.adjustChartHeight(currentChart, this.percentageHeightDesktop, this.percentageHeightMobile);
|
|
287
|
-
}
|
|
288
297
|
|
|
289
298
|
// If the chart has an extra line or lines, hide the data labels for
|
|
290
299
|
// that series, update the last point marker
|
|
291
300
|
if (this.extraLines > 0) {
|
|
292
301
|
currentChart.series.forEach((series) => {
|
|
293
302
|
if (series.type === 'line') {
|
|
294
|
-
this.
|
|
303
|
+
this.specificChartOptions.hideDataLabels([series]);
|
|
295
304
|
}
|
|
296
305
|
});
|
|
297
306
|
}
|
|
298
|
-
// Update the legend items for all charts
|
|
299
|
-
this.commonChartOptions.updateLegendSymbols(currentChart);
|
|
300
307
|
currentChart.redraw(false);
|
|
301
308
|
};
|
|
302
309
|
};
|
|
@@ -310,6 +317,11 @@ class HighchartsBaseChart {
|
|
|
310
317
|
if (this.rangeAnnotationsOptions) {
|
|
311
318
|
this.rangeAnnotationsOptions.addLine(currentChart);
|
|
312
319
|
}
|
|
320
|
+
if (this.chartType != 'bar' && this.chartType != 'columnrange') {
|
|
321
|
+
this.specificChartOptions.adjustChartHeight(currentChart, this.percentageHeightDesktop, this.percentageHeightMobile);
|
|
322
|
+
}
|
|
323
|
+
// Update the legend symbols on render to maintain them during resize
|
|
324
|
+
this.specificChartOptions.updateLegendSymbols(currentChart);
|
|
313
325
|
};
|
|
314
326
|
};
|
|
315
327
|
|
|
@@ -324,9 +336,8 @@ class HighchartsBaseChart {
|
|
|
324
336
|
// Update the data labels when the window is resized
|
|
325
337
|
if (this.chartType === 'bar' && !this.hideDataLabels) {
|
|
326
338
|
this.barChart.postLoadDataLabels(currentChart);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.commonChartOptions.adjustChartHeight(currentChart, this.percentageHeightDesktop, this.percentageHeightMobile);
|
|
339
|
+
// Force a single redraw after all updates
|
|
340
|
+
currentChart.redraw(false);
|
|
330
341
|
}
|
|
331
342
|
}, 50);
|
|
332
343
|
});
|
|
@@ -2,7 +2,7 @@ import ChartConstants from './chart-constants';
|
|
|
2
2
|
|
|
3
3
|
// Options that are common to all chart types - these are set once in the Highcharts.setOptions() method
|
|
4
4
|
class CommonChartOptions {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor() {
|
|
6
6
|
this.constants = ChartConstants.constants();
|
|
7
7
|
|
|
8
8
|
this.options = {
|
|
@@ -85,7 +85,6 @@ class CommonChartOptions {
|
|
|
85
85
|
tickWidth: 1,
|
|
86
86
|
tickLength: 6,
|
|
87
87
|
tickColor: this.constants.gridLineColor,
|
|
88
|
-
tickInterval: yAxisTickInterval,
|
|
89
88
|
},
|
|
90
89
|
xAxis: {
|
|
91
90
|
labels: {
|
|
@@ -109,7 +108,6 @@ class CommonChartOptions {
|
|
|
109
108
|
tickWidth: 1,
|
|
110
109
|
tickLength: 6,
|
|
111
110
|
tickColor: this.constants.gridLineColor,
|
|
112
|
-
tickInterval: xAxisTickInterval,
|
|
113
111
|
},
|
|
114
112
|
plotOptions: {
|
|
115
113
|
series: {
|
|
@@ -134,131 +132,6 @@ class CommonChartOptions {
|
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
getOptions = () => this.options;
|
|
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
|
-
hideDataLabels = (series) => {
|
|
153
|
-
series.forEach((series) => {
|
|
154
|
-
series.update({
|
|
155
|
-
dataLabels: {
|
|
156
|
-
enabled: false,
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
};
|
|
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
135
|
}
|
|
263
136
|
|
|
264
137
|
export default CommonChartOptions;
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
{{
|
|
4
4
|
onsChart({
|
|
5
5
|
"chartType": "columnrange",
|
|
6
|
-
"isChartInverted": true,
|
|
7
6
|
"description": "Volume sales, seasonally adjusted, Great Britain, January 2022 to January 2025",
|
|
8
|
-
"theme": "primary",
|
|
9
7
|
"title": "Food stores showed a strong rise on the month, while non-food stores fell",
|
|
10
8
|
"subtitle": "Figure 6: Upward contribution from housing and household services (including energy) saw the annual CPIH inflation rate rise",
|
|
11
9
|
"id": "uuid",
|
|
@@ -56,13 +54,10 @@
|
|
|
56
54
|
[-10.5, 12.0],
|
|
57
55
|
[-12.1, 18.5]
|
|
58
56
|
],
|
|
59
|
-
"dataLabels": true,
|
|
60
57
|
"name": "Values"
|
|
61
58
|
},
|
|
62
59
|
{
|
|
63
60
|
"data": [1,2,3,4,5,6,7,8,9,10,3,11,12],
|
|
64
|
-
"marker": true,
|
|
65
|
-
"dataLabels": false,
|
|
66
61
|
"name": "Another test data source",
|
|
67
62
|
"type": "scatter"
|
|
68
63
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
onsChart({
|
|
5
5
|
"chartType": "boxplot",
|
|
6
6
|
"description": "Public sector net debt excluding public sector banks, percentage of gross domestic product (GDP), UK, financial year ending (FYE) 1901 to October 2024",
|
|
7
|
-
"theme": "primary",
|
|
8
7
|
"title": "Figure 6: Net debt as a percentage of GDP remains at levels last seen in the early 1960s",
|
|
9
8
|
"subtitle": "Public sector net debt excluding public sector banks, percentage of gross domestic product (GDP), UK, financial year ending (FYE) 1901 to October 2024",
|
|
10
9
|
"id": "uuid",
|
|
@@ -39,9 +38,7 @@
|
|
|
39
38
|
[817, 817, 817, 817, 817],
|
|
40
39
|
[806, 806, 806, 806, 806],
|
|
41
40
|
[864, 864, 864, 864, 864]
|
|
42
|
-
]
|
|
43
|
-
"dataLabels": false,
|
|
44
|
-
"name": "Net debt"
|
|
41
|
+
]
|
|
45
42
|
}
|
|
46
43
|
],
|
|
47
44
|
'estimateLineLabel': 'Data line',
|
|
@@ -46,8 +46,7 @@
|
|
|
46
46
|
[163.5, 54.9], [158.7, 51.2], [165.5, 57.8], [160.4, 52.7],
|
|
47
47
|
[162.7, 55.4], [166.4, 58.4], [159.4, 51.5], [164.8, 56.5],
|
|
48
48
|
[158.6, 50.6], [163.4, 53.5]
|
|
49
|
-
]
|
|
50
|
-
"marker": true
|
|
49
|
+
]
|
|
51
50
|
},
|
|
52
51
|
{
|
|
53
52
|
"name": "Male",
|
|
@@ -60,8 +59,7 @@
|
|
|
60
59
|
[178.7, 68.8], [182.2, 74.7], [176.4, 67.5], [188.0, 77.6],
|
|
61
60
|
[184.1, 73.4], [179.2, 70.8], [186.6, 79.8], [183.4, 75.4],
|
|
62
61
|
[177.8, 69.6], [185.5, 76.7]
|
|
63
|
-
]
|
|
64
|
-
"marker": true
|
|
62
|
+
]
|
|
65
63
|
},
|
|
66
64
|
{
|
|
67
65
|
"name": "Adolescent Male",
|
|
@@ -72,8 +70,7 @@
|
|
|
72
70
|
[168.8, 58.6], [171.5, 62.8], [169.2, 59.4], [173.7, 63.5],
|
|
73
71
|
[170.2, 61.6], [172.4, 64.2], [168.2, 58.1], [173.9, 64.8],
|
|
74
72
|
[169.8, 60.7], [171.4, 63.6]
|
|
75
|
-
]
|
|
76
|
-
"marker": true
|
|
73
|
+
]
|
|
77
74
|
},
|
|
78
75
|
{
|
|
79
76
|
"name": "Adolescent Female",
|
|
@@ -84,8 +81,7 @@
|
|
|
84
81
|
[164.5, 55.1], [166.2, 57.5], [163.4, 53.6], [165.9, 56.2],
|
|
85
82
|
[162.6, 52.5], [167.5, 58.4], [164.4, 55.6], [166.6, 57.6],
|
|
86
83
|
[163.8, 53.7], [165.2, 56.9]
|
|
87
|
-
]
|
|
88
|
-
"marker": true
|
|
84
|
+
]
|
|
89
85
|
}
|
|
90
86
|
],
|
|
91
87
|
"percentageHeightDesktop": 35,
|