@ons/design-system 72.9.1 → 72.10.0
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/button/_button.scss +10 -0
- package/components/card/_macro.njk +3 -3
- package/components/card/_macro.spec.js +109 -252
- package/components/card/_test_examples.js +56 -0
- package/components/chart/_chart.scss +74 -1
- package/components/chart/_macro.njk +64 -5
- package/components/chart/_macro.spec.js +405 -0
- package/components/chart/bar-chart.js +2 -2
- package/components/chart/boxplot.js +37 -0
- package/components/chart/chart-constants.js +13 -0
- package/components/chart/chart.js +98 -50
- package/components/chart/columnrange-chart.js +94 -0
- package/components/chart/common-chart-options.js +28 -19
- package/components/chart/example-bar-chart-with-annotations.njk +1 -1
- package/components/chart/example-bar-chart-with-point-range-and-reference-line-annotations.njk +95 -0
- package/components/chart/example-bar-with-confidence-levels.njk +71 -0
- package/components/chart/example-clustered-column-chart.njk +1 -3
- package/components/chart/example-column-chart-with-annotations.njk +1 -1
- package/components/chart/example-column-chart-with-range-annotations.njk +64 -0
- package/components/chart/example-column-chart-with-reference-line-annotations.njk +64 -0
- package/components/chart/example-column-with-confidence-levels.njk +61 -0
- package/components/chart/example-line-chart-with-annotations.njk +3 -3
- package/components/chart/example-line-chart-with-markers.njk +1 -1
- package/components/chart/example-line-chart-with-range-annotations-inside.njk +238 -0
- package/components/chart/example-line-chart-with-range-annotations-outside-left-right.njk +240 -0
- package/components/chart/example-line-chart-with-range-annotations-outside-top-bottom.njk +239 -0
- package/components/chart/example-line-chart-with-reference-line-annotations.njk +236 -0
- package/components/chart/example-scatter-chart.njk +1 -1
- package/components/chart/range-annotations-options.js +216 -0
- package/components/chart/reference-line-annotations-options.js +93 -0
- package/components/chart/scatter-chart.js +15 -0
- package/components/chart/specific-chart-options.js +1 -1
- package/components/chart/utilities.js +96 -0
- package/components/details-panel/_macro.njk +5 -1
- package/components/details-panel/_macro.spec.js +22 -0
- package/components/document-list/_document-list.scss +5 -13
- package/components/document-list/_macro.njk +14 -17
- package/components/document-list/_macro.spec.js +3 -3
- package/components/fieldset/_macro.spec.js +200 -120
- package/components/fieldset/_test_examples.js +15 -0
- package/components/header/_header.scss +11 -0
- package/components/header/_macro.njk +11 -6
- package/components/header/_macro.spec.js +113 -3
- package/components/hero/_macro.spec.js +1 -1
- package/components/icon/_macro.njk +14 -24
- package/components/language-selector/_macro.njk +6 -3
- package/components/navigation/navigation.js +57 -58
- package/components/navigation/navigation.spec.js +6 -10
- package/components/summary/_macro.njk +4 -1
- package/components/table-of-contents/_macro.njk +1 -1
- package/components/table-of-contents/_macro.spec.js +7 -0
- package/components/table-of-contents/table-of-contents.js +43 -26
- package/css/main.css +1 -1
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
{% from "components/chart/_macro.njk" import onsChart %}
|
|
2
|
+
|
|
3
|
+
{{
|
|
4
|
+
onsChart({
|
|
5
|
+
"chartType": "line",
|
|
6
|
+
"description": "Line chart showing the annual rate of inflation for the Consumer Prices Index including owner occupiers’ housing costs (CPIH) and its components.",
|
|
7
|
+
"theme": "alternate",
|
|
8
|
+
"title": "Sales volumes and values saw moderate growth in July 2024",
|
|
9
|
+
"subtitle": "Figure 6: Upward contribution from housing and household services (including energy) saw the annual CPIH inflation rate rise",
|
|
10
|
+
"id": "id",
|
|
11
|
+
"headingLevel": 4,
|
|
12
|
+
"caption": "Source: Monthly Business Survey, Retails Sales Inquiry from the Office for National Statistics",
|
|
13
|
+
"download": {
|
|
14
|
+
'title': 'Download Figure 1 data',
|
|
15
|
+
'itemsList': [
|
|
16
|
+
{
|
|
17
|
+
"text": "Excel spreadsheet (XLSX format, 18KB)",
|
|
18
|
+
"url": "#"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"text": "Simple text file (CSV format, 25KB)",
|
|
22
|
+
"url": "#"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
|
|
26
|
+
"text": "Image (PNG format, 25KB)",
|
|
27
|
+
"url": "#"
|
|
28
|
+
}
|
|
29
|
+
]},
|
|
30
|
+
"legend": true,
|
|
31
|
+
"xAxis": {
|
|
32
|
+
"title": "Year",
|
|
33
|
+
"type": "linear",
|
|
34
|
+
"labelFormat": "{value:,.f}",
|
|
35
|
+
"categories": [
|
|
36
|
+
'Oct 2014',
|
|
37
|
+
'Nov 2014',
|
|
38
|
+
'Dec 2014',
|
|
39
|
+
'Jan 2015',
|
|
40
|
+
'Feb 2015',
|
|
41
|
+
'Mar 2015',
|
|
42
|
+
'Apr 2015',
|
|
43
|
+
'May 2015',
|
|
44
|
+
'Jun 2015',
|
|
45
|
+
'Jul 2015',
|
|
46
|
+
'Aug 2015',
|
|
47
|
+
'Sep 2015',
|
|
48
|
+
'Oct 2015',
|
|
49
|
+
'Nov 2015',
|
|
50
|
+
'Dec 2015',
|
|
51
|
+
'Jan 2016',
|
|
52
|
+
'Feb 2016',
|
|
53
|
+
'Mar 2016',
|
|
54
|
+
'Apr 2016',
|
|
55
|
+
'May 2016',
|
|
56
|
+
'Jun 2016',
|
|
57
|
+
'Jul 2016',
|
|
58
|
+
'Aug 2016',
|
|
59
|
+
'Sep 2016',
|
|
60
|
+
'Oct 2016',
|
|
61
|
+
'Nov 2016',
|
|
62
|
+
'Dec 2016',
|
|
63
|
+
'Jan 2017',
|
|
64
|
+
'Feb 2017',
|
|
65
|
+
'Mar 2017',
|
|
66
|
+
'Apr 2017',
|
|
67
|
+
'May 2017',
|
|
68
|
+
'Jun 2017',
|
|
69
|
+
'Jul 2017',
|
|
70
|
+
'Aug 2017',
|
|
71
|
+
'Sep 2017',
|
|
72
|
+
'Oct 2017',
|
|
73
|
+
'Nov 2017',
|
|
74
|
+
'Dec 2017',
|
|
75
|
+
'Jan 2018',
|
|
76
|
+
'Feb 2018',
|
|
77
|
+
'Mar 2018',
|
|
78
|
+
'Apr 2018',
|
|
79
|
+
'May 2018',
|
|
80
|
+
'Jun 2018',
|
|
81
|
+
'Jul 2018',
|
|
82
|
+
'Aug 2018',
|
|
83
|
+
'Sep 2018',
|
|
84
|
+
'Oct 2018',
|
|
85
|
+
'Nov 2018',
|
|
86
|
+
'Dec 2018',
|
|
87
|
+
'Jan 2019',
|
|
88
|
+
'Feb 2019',
|
|
89
|
+
'Mar 2019',
|
|
90
|
+
'Apr 2019',
|
|
91
|
+
'May 2019',
|
|
92
|
+
'Jun 2019',
|
|
93
|
+
'Jul 2019',
|
|
94
|
+
'Aug 2019',
|
|
95
|
+
'Sep 2019',
|
|
96
|
+
'Oct 2019',
|
|
97
|
+
'Nov 2019',
|
|
98
|
+
'Dec 2019',
|
|
99
|
+
'Jan 2020',
|
|
100
|
+
'Feb 2020',
|
|
101
|
+
'Mar 2020',
|
|
102
|
+
'Apr 2020',
|
|
103
|
+
'May 2020',
|
|
104
|
+
'Jun 2020',
|
|
105
|
+
'Jul 2020',
|
|
106
|
+
'Aug 2020',
|
|
107
|
+
'Sep 2020',
|
|
108
|
+
'Oct 2020',
|
|
109
|
+
'Nov 2020',
|
|
110
|
+
'Dec 2020',
|
|
111
|
+
'Jan 2021',
|
|
112
|
+
'Feb 2021',
|
|
113
|
+
'Mar 2021',
|
|
114
|
+
'Apr 2021',
|
|
115
|
+
'May 2021',
|
|
116
|
+
'Jun 2021',
|
|
117
|
+
'Jul 2021',
|
|
118
|
+
'Aug 2021',
|
|
119
|
+
'Sep 2021',
|
|
120
|
+
'Oct 2021',
|
|
121
|
+
'Nov 2021',
|
|
122
|
+
'Dec 2021',
|
|
123
|
+
'Jan 2022',
|
|
124
|
+
'Feb 2022',
|
|
125
|
+
'Mar 2022',
|
|
126
|
+
'Apr 2022',
|
|
127
|
+
'May 2022',
|
|
128
|
+
'Jun 2022',
|
|
129
|
+
'Jul 2022',
|
|
130
|
+
'Aug 2022',
|
|
131
|
+
'Sep 2022',
|
|
132
|
+
'Oct 2022',
|
|
133
|
+
'Nov 2022',
|
|
134
|
+
'Dec 2022',
|
|
135
|
+
'Jan 2023',
|
|
136
|
+
'Feb 2023',
|
|
137
|
+
'Mar 2023',
|
|
138
|
+
'Apr 2023',
|
|
139
|
+
'May 2023',
|
|
140
|
+
'Jun 2023',
|
|
141
|
+
'Jul 2023',
|
|
142
|
+
'Aug 2023',
|
|
143
|
+
'Sep 2023',
|
|
144
|
+
'Oct 2023',
|
|
145
|
+
'Nov 2023',
|
|
146
|
+
'Dec 2023',
|
|
147
|
+
'Jan 2024',
|
|
148
|
+
'Feb 2024',
|
|
149
|
+
'Mar 2024',
|
|
150
|
+
'Apr 2024',
|
|
151
|
+
'May 2024',
|
|
152
|
+
'Jun 2024',
|
|
153
|
+
'Jul 2024',
|
|
154
|
+
'Aug 2024',
|
|
155
|
+
'Sep 2024',
|
|
156
|
+
'Oct 2024'
|
|
157
|
+
],
|
|
158
|
+
"tickIntervalDesktop": 15,
|
|
159
|
+
"tickIntervalMobile": 30
|
|
160
|
+
},
|
|
161
|
+
"yAxis": {
|
|
162
|
+
"title": "Sales",
|
|
163
|
+
"labelFormat": "{value:,.f}"
|
|
164
|
+
},
|
|
165
|
+
"percentageHeightDesktop": 35,
|
|
166
|
+
"percentageHeightMobile": 90,
|
|
167
|
+
"series": [
|
|
168
|
+
{
|
|
169
|
+
"name": 'CPIH',
|
|
170
|
+
"data": [
|
|
171
|
+
1.3, 1.1, 0.7, 0.5, 0.4, 0.3, 0.3, 0.4, 0.3, 0.5, 0.4, 0.2, 0.2, 0.4, 0.5, 0.6,
|
|
172
|
+
0.6, 0.8, 0.7, 0.7, 0.8, 0.9, 1.0, 1.3, 1.3, 1.5, 1.8, 1.9, 2.3, 2.3, 2.6, 2.7,
|
|
173
|
+
2.6, 2.6, 2.7, 2.8, 2.8, 2.8, 2.7, 2.7, 2.5, 2.3, 2.2, 2.3, 2.3, 2.3, 2.4, 2.2,
|
|
174
|
+
2.2, 2.2, 2.0, 1.8, 1.8, 1.8, 2.0, 1.9, 1.9, 2.0, 1.7, 1.7, 1.5, 1.5, 1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1.6, 1.5, 1.5, 1.6, 1.6, 1.5, 1.7, 1.6, 1.7, 1.8, 1.8, 2.1, 1.9, 2.4, 2.5,
|
|
213
|
+
2.4, 2.4, 2.6, 2.5, 2.5, 2.5, 2.3, 2.4, 2.2, 2.1, 2.0, 2.0, 1.8, 1.8, 1.9, 1.8,
|
|
214
|
+
1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.7, 1.7, 1.7, 1.9, 1.5, 1.6, 1.7, 1.7, 1.4, 1.6,
|
|
215
|
+
1.7, 1.6, 1.5, 1.3, 1.5, 1.8, 1.0, 1.4, 1.5, 1.2, 1.5, 1.5, 1.1, 1.3, 1.5, 2.0,
|
|
216
|
+
2.3, 1.9, 2.9, 2.7, 3.1, 3.6, 3.8, 4.0, 4.6, 5.1, 5.4, 5.2, 5.2, 5.5, 5.6, 5.8,
|
|
217
|
+
5.8, 5.7, 5.8, 5.3, 5.7, 5.7, 6.2, 6.5, 6.4, 6.4, 5.9, 5.9, 5.6, 5.2, 5.2, 5.1,
|
|
218
|
+
4.8, 4.7, 4.4, 4.2, 4.2, 4.1, 4.3, 4.0, 4.1
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"referenceLineAnnotations": [
|
|
223
|
+
{
|
|
224
|
+
"text": "A test x axis reference line annotation",
|
|
225
|
+
"value": 34,
|
|
226
|
+
"axis": "x"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"text": "A test y axis reference line annotation",
|
|
230
|
+
"value": 12,
|
|
231
|
+
"axis": "y",
|
|
232
|
+
"labelWidth": 100
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
})
|
|
236
|
+
}}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import ChartConstants from './chart-constants';
|
|
2
|
+
|
|
3
|
+
class RangeAnnotationsOptions {
|
|
4
|
+
constructor(rangeAnnotations) {
|
|
5
|
+
this.constants = ChartConstants.constants();
|
|
6
|
+
this.rangeAnnotations = rangeAnnotations;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getRangeAnnotationsOptionsDesktop = (chartType) => {
|
|
10
|
+
let xAxisPlotBands = [];
|
|
11
|
+
let yAxisPlotBands = [];
|
|
12
|
+
this.rangeAnnotations.forEach((rangeAnnotation) => {
|
|
13
|
+
let adjustedRangeValues = this.adjustRangeForCategoryAxis(rangeAnnotation, chartType);
|
|
14
|
+
let rangeConfig = {
|
|
15
|
+
from: adjustedRangeValues.axisValue1,
|
|
16
|
+
to: adjustedRangeValues.axisValue2,
|
|
17
|
+
label: {
|
|
18
|
+
text: rangeAnnotation.text,
|
|
19
|
+
useHTML: true,
|
|
20
|
+
className: rangeAnnotation.labelInside
|
|
21
|
+
? `ons-chart__range-annotation-label ons-chart__range-annotation-label--${rangeAnnotation.axis}`
|
|
22
|
+
: 'ons-chart__range-annotation-label--outside',
|
|
23
|
+
allowOverlap: true,
|
|
24
|
+
style: {
|
|
25
|
+
color: this.constants.labelColor,
|
|
26
|
+
fontSize: this.constants.defaultFontSize,
|
|
27
|
+
width: rangeAnnotation.labelWidth ? rangeAnnotation.labelWidth : 150,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
color: this.constants.shadingColor,
|
|
31
|
+
};
|
|
32
|
+
if (!rangeAnnotation.labelInside && rangeAnnotation.labelOffsetX) {
|
|
33
|
+
rangeConfig.label.x = rangeAnnotation.labelOffsetX;
|
|
34
|
+
}
|
|
35
|
+
if (!rangeAnnotation.labelInside && rangeAnnotation.labelOffsetY) {
|
|
36
|
+
rangeConfig.label.y = rangeAnnotation.labelOffsetY;
|
|
37
|
+
}
|
|
38
|
+
if (rangeAnnotation.axis === 'x') {
|
|
39
|
+
xAxisPlotBands.push(rangeConfig);
|
|
40
|
+
} else if (rangeAnnotation.axis === 'y') {
|
|
41
|
+
yAxisPlotBands.push(rangeConfig);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
xAxis: xAxisPlotBands.length > 0 ? { plotBands: xAxisPlotBands } : undefined,
|
|
46
|
+
yAxis: yAxisPlotBands.length > 0 ? { plotBands: yAxisPlotBands } : undefined,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
getRangeAnnotationsOptionsMobile = (annotationsLength, chartType) => {
|
|
51
|
+
let xAxisPlotBands = [];
|
|
52
|
+
let yAxisPlotBands = [];
|
|
53
|
+
this.rangeAnnotations.forEach((rangeAnnotation, index) => {
|
|
54
|
+
let adjustedRangeValues = this.adjustRangeForCategoryAxis(rangeAnnotation, chartType);
|
|
55
|
+
let rangeConfig = {
|
|
56
|
+
from: adjustedRangeValues.axisValue1,
|
|
57
|
+
to: adjustedRangeValues.axisValue2,
|
|
58
|
+
label: {
|
|
59
|
+
// Add the number of point annotations to the current range annotation loop
|
|
60
|
+
// So that if we have both types of annotations, the numbers will be sequential
|
|
61
|
+
text: `${annotationsLength + index + 1}`,
|
|
62
|
+
useHTML: true,
|
|
63
|
+
className: 'ons-chart__footnote-number',
|
|
64
|
+
allowOverlap: true,
|
|
65
|
+
style: {
|
|
66
|
+
color: this.constants.labelColor,
|
|
67
|
+
fontSize: this.constants.defaultFontSize,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
color: this.constants.shadingColor,
|
|
71
|
+
};
|
|
72
|
+
if (rangeAnnotation.axis === 'x') {
|
|
73
|
+
xAxisPlotBands.push(rangeConfig);
|
|
74
|
+
} else if (rangeAnnotation.axis === 'y') {
|
|
75
|
+
yAxisPlotBands.push(rangeConfig);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
xAxis: xAxisPlotBands.length > 0 ? { plotBands: xAxisPlotBands } : undefined,
|
|
80
|
+
yAxis: yAxisPlotBands.length > 0 ? { plotBands: yAxisPlotBands } : undefined,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Returns the position of the label relative to the plotBand
|
|
85
|
+
getLabelPosition = (chartType, labelRect, plotBandRect, isXaxis) => {
|
|
86
|
+
let isToLeft = false;
|
|
87
|
+
let isToRight = false;
|
|
88
|
+
let isToTop = false;
|
|
89
|
+
let isToBottom = false;
|
|
90
|
+
let isVertical = chartType === 'bar' ? !isXaxis : isXaxis;
|
|
91
|
+
if (isVertical) {
|
|
92
|
+
// vertical plotBand
|
|
93
|
+
if (labelRect.right < plotBandRect.left) {
|
|
94
|
+
isToLeft = true;
|
|
95
|
+
}
|
|
96
|
+
if (labelRect.left > plotBandRect.right) {
|
|
97
|
+
isToRight = true;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
// horizontal plotBand
|
|
101
|
+
if (labelRect.bottom < plotBandRect.top) {
|
|
102
|
+
isToTop = true;
|
|
103
|
+
}
|
|
104
|
+
if (labelRect.top > plotBandRect.bottom) {
|
|
105
|
+
isToBottom = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { isToLeft, isToRight, isToTop, isToBottom };
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Draws the line connecting the label to the plotBand
|
|
112
|
+
// Also adds a custom class to the label based on its position
|
|
113
|
+
addLine = (currentChart) => {
|
|
114
|
+
// If there is already a line in the chart, remove it before redrawing it
|
|
115
|
+
const lines = currentChart.container.querySelectorAll('[data-range-annotation-line]');
|
|
116
|
+
if (lines.length > 0) {
|
|
117
|
+
lines.forEach((line) => {
|
|
118
|
+
line.remove();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Get all plotBands from both axes
|
|
123
|
+
// The filter ensures that plotLines are not included as they will have a `value` property rather than `from` and `to` properties
|
|
124
|
+
const xAxisPlotBands = currentChart.xAxis[0].plotLinesAndBands.filter((band) => band.options.from !== undefined);
|
|
125
|
+
const yAxisPlotBands = currentChart.yAxis[0].plotLinesAndBands.filter((band) => band.options.from !== undefined);
|
|
126
|
+
|
|
127
|
+
// Combine all plotBands
|
|
128
|
+
const allPlotBands = [...xAxisPlotBands, ...yAxisPlotBands];
|
|
129
|
+
|
|
130
|
+
allPlotBands.forEach((plotBand) => {
|
|
131
|
+
// If the label is set to be inside the plotBand, exit early and don't draw a line
|
|
132
|
+
if (plotBand.options.label.x === undefined && plotBand.options.label.y === undefined) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Get the plotBand element
|
|
137
|
+
const plotBandElement = plotBand.svgElem.element;
|
|
138
|
+
const plotBandRect = plotBandElement.getBoundingClientRect();
|
|
139
|
+
|
|
140
|
+
// Get the label element
|
|
141
|
+
const labelElement = plotBand.label.element;
|
|
142
|
+
const labelRect = labelElement.getBoundingClientRect();
|
|
143
|
+
|
|
144
|
+
// Get the label position relative to the plotBand (left, right, top or bottom)
|
|
145
|
+
const labelPosition = this.getLabelPosition(
|
|
146
|
+
currentChart.userOptions.chart.type,
|
|
147
|
+
labelRect,
|
|
148
|
+
plotBandRect,
|
|
149
|
+
plotBand.axis.isXAxis,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// Only draw a line in the label doesn't overlap the plot band
|
|
153
|
+
if (!(labelPosition.isToLeft || labelPosition.isToRight || labelPosition.isToTop || labelPosition.isToBottom)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Create and add the connecting line
|
|
158
|
+
const line = document.createElement('div');
|
|
159
|
+
line.classList.add('ons-chart__connector-line');
|
|
160
|
+
line.setAttribute('data-range-annotation-line', true);
|
|
161
|
+
labelElement.appendChild(line);
|
|
162
|
+
|
|
163
|
+
// Draw the line based on the label position
|
|
164
|
+
if (labelPosition.isToRight) {
|
|
165
|
+
let divWidth = labelRect.left - plotBandRect.right;
|
|
166
|
+
line.style.width = `${divWidth}px`;
|
|
167
|
+
line.style.height = '1px';
|
|
168
|
+
line.style.top = `${labelRect.height / 2}px`;
|
|
169
|
+
line.style.left = `-${divWidth}px`;
|
|
170
|
+
labelElement.classList.add('ons-chart__range-annotation-label--right');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (labelPosition.isToLeft) {
|
|
174
|
+
let divWidth = plotBandRect.left - labelRect.right;
|
|
175
|
+
line.style.width = `${divWidth}px`;
|
|
176
|
+
line.style.height = '1px';
|
|
177
|
+
line.style.top = `${labelRect.height / 2}px`;
|
|
178
|
+
line.style.right = `-${divWidth}px`;
|
|
179
|
+
labelElement.classList.add('ons-chart__range-annotation-label--left');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (labelPosition.isToTop) {
|
|
183
|
+
let divHeight = plotBandRect.top - labelRect.bottom;
|
|
184
|
+
line.style.height = `${divHeight}px`;
|
|
185
|
+
line.style.width = '1px';
|
|
186
|
+
line.style.top = `${labelRect.height}px`;
|
|
187
|
+
line.style.left = `${labelRect.width / 2}px`;
|
|
188
|
+
labelElement.classList.add('ons-chart__range-annotation-label--top');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (labelPosition.isToBottom) {
|
|
192
|
+
let divHeight = labelRect.top - plotBandRect.bottom;
|
|
193
|
+
line.style.height = `${divHeight}px`;
|
|
194
|
+
line.style.width = '1px';
|
|
195
|
+
line.style.top = `-${divHeight}px`;
|
|
196
|
+
line.style.left = `${labelRect.width / 2}px`;
|
|
197
|
+
labelElement.classList.add('ons-chart__range-annotation-label--bottom');
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// For bar and column charts, we want the range to
|
|
203
|
+
// start and end flush with the edges of the columns / bars,
|
|
204
|
+
// not halfway through as is the Highcharts default.
|
|
205
|
+
adjustRangeForCategoryAxis = (rangeAnnotation, chartType) => {
|
|
206
|
+
let axisValue1 = rangeAnnotation.range.axisValue1;
|
|
207
|
+
let axisValue2 = rangeAnnotation.range.axisValue2;
|
|
208
|
+
if ((chartType === 'bar' && rangeAnnotation.axis === 'x') || (chartType === 'column' && rangeAnnotation.axis === 'x')) {
|
|
209
|
+
axisValue1 = rangeAnnotation.range.axisValue1 - 0.5;
|
|
210
|
+
axisValue2 = rangeAnnotation.range.axisValue2 - 0.5;
|
|
211
|
+
}
|
|
212
|
+
return { axisValue1, axisValue2 };
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export default RangeAnnotationsOptions;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import ChartConstants from './chart-constants';
|
|
2
|
+
|
|
3
|
+
class ReferenceLineAnnotationsOptions {
|
|
4
|
+
constructor(referenceLineAnnotations) {
|
|
5
|
+
this.constants = ChartConstants.constants();
|
|
6
|
+
this.referenceLineAnnotations = referenceLineAnnotations;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getReferenceLineAnnotationsOptionsDesktop = () => {
|
|
10
|
+
let xAxisPlotLines = [];
|
|
11
|
+
let yAxisPlotLines = [];
|
|
12
|
+
this.referenceLineAnnotations.forEach((referenceLineAnnotation) => {
|
|
13
|
+
let referenceLineConfig = {
|
|
14
|
+
label: {
|
|
15
|
+
text: referenceLineAnnotation.text,
|
|
16
|
+
style: {
|
|
17
|
+
color: this.constants.labelColor,
|
|
18
|
+
fontSize: this.constants.defaultFontSize,
|
|
19
|
+
width: referenceLineAnnotation.labelWidth ? referenceLineAnnotation.labelWidth : 150,
|
|
20
|
+
},
|
|
21
|
+
x: referenceLineAnnotation.labelOffsetX ? referenceLineAnnotation.labelOffsetX : 10,
|
|
22
|
+
y: referenceLineAnnotation.labelOffsetY ? referenceLineAnnotation.labelOffsetY : 20,
|
|
23
|
+
rotation: 0,
|
|
24
|
+
align: 'left',
|
|
25
|
+
textAlign: 'left',
|
|
26
|
+
},
|
|
27
|
+
color: this.constants.zeroLineColor,
|
|
28
|
+
// note this works to give a dashed line with 4px and a 4px gap, but
|
|
29
|
+
// this way of styling it is undocumented
|
|
30
|
+
dashStyle: '2 2',
|
|
31
|
+
width: 2,
|
|
32
|
+
value: referenceLineAnnotation.value,
|
|
33
|
+
zIndex: 3,
|
|
34
|
+
};
|
|
35
|
+
if (referenceLineAnnotation.axis === 'x') {
|
|
36
|
+
xAxisPlotLines.push(referenceLineConfig);
|
|
37
|
+
} else if (referenceLineAnnotation.axis === 'y') {
|
|
38
|
+
yAxisPlotLines.push(referenceLineConfig);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
xAxis: xAxisPlotLines.length > 0 ? { plotLines: xAxisPlotLines } : undefined,
|
|
43
|
+
yAxis: yAxisPlotLines.length > 0 ? { plotLines: yAxisPlotLines } : undefined,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
getReferenceLineAnnotationsOptionsMobile = (annotationsLength, chartType) => {
|
|
48
|
+
let xAxisPlotLines = [];
|
|
49
|
+
let yAxisPlotLines = [];
|
|
50
|
+
this.referenceLineAnnotations.forEach((referenceLineAnnotation, index) => {
|
|
51
|
+
let isVertical = referenceLineAnnotation.axis === 'x' ? true : false;
|
|
52
|
+
if (chartType === 'bar') {
|
|
53
|
+
isVertical = !isVertical;
|
|
54
|
+
}
|
|
55
|
+
let referenceLineConfig = {
|
|
56
|
+
label: {
|
|
57
|
+
// Add the number of point and range annotations to the current reference line annotation loop
|
|
58
|
+
// So that if we have more than one type of annotations, the numbers will be sequential
|
|
59
|
+
text: `${annotationsLength + index + 1}`,
|
|
60
|
+
useHTML: true,
|
|
61
|
+
className: 'ons-chart__footnote-number',
|
|
62
|
+
allowOverlap: true,
|
|
63
|
+
style: {
|
|
64
|
+
color: this.constants.labelColor,
|
|
65
|
+
fontSize: this.constants.defaultFontSize,
|
|
66
|
+
},
|
|
67
|
+
x: isVertical ? 7 : 0,
|
|
68
|
+
y: isVertical ? 13 : -10, // 13 works with the height of the styled number
|
|
69
|
+
rotation: 0,
|
|
70
|
+
zIndex: 3,
|
|
71
|
+
},
|
|
72
|
+
color: this.constants.zeroLineColor,
|
|
73
|
+
// note this works to give a dashed line with 4px and a 4px gap, but
|
|
74
|
+
// this way of styling it is undocumented
|
|
75
|
+
dashStyle: '2 2',
|
|
76
|
+
width: 2,
|
|
77
|
+
value: referenceLineAnnotation.value,
|
|
78
|
+
zIndex: 3,
|
|
79
|
+
};
|
|
80
|
+
if (referenceLineAnnotation.axis === 'x') {
|
|
81
|
+
xAxisPlotLines.push(referenceLineConfig);
|
|
82
|
+
} else if (referenceLineAnnotation.axis === 'y') {
|
|
83
|
+
yAxisPlotLines.push(referenceLineConfig);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
xAxis: xAxisPlotLines.length > 0 ? { plotLines: xAxisPlotLines } : undefined,
|
|
88
|
+
yAxis: yAxisPlotLines.length > 0 ? { plotLines: yAxisPlotLines } : undefined,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default ReferenceLineAnnotationsOptions;
|
|
@@ -4,6 +4,7 @@ class ScatterChart {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this.chartConstants = ChartConstants.constants();
|
|
6
6
|
this.markerStyles = this.chartConstants.scatterMarkerStyles;
|
|
7
|
+
this.confidenceLevelMarkerStyles = this.chartConstants.confidenceLevelMarkerStyles;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
getScatterChartOptions = () => {
|
|
@@ -29,6 +30,20 @@ class ScatterChart {
|
|
|
29
30
|
series.update({ marker: this.markerStyles[i] != undefined ? this.markerStyles[i] : this.markerStyles[0] }, false);
|
|
30
31
|
});
|
|
31
32
|
};
|
|
33
|
+
|
|
34
|
+
updateMarkersForConfidenceLevels = (series) => {
|
|
35
|
+
series.forEach((series, i) => {
|
|
36
|
+
series.update(
|
|
37
|
+
{
|
|
38
|
+
marker:
|
|
39
|
+
this.confidenceLevelMarkerStyles[i] != undefined
|
|
40
|
+
? this.confidenceLevelMarkerStyles[i]
|
|
41
|
+
: this.confidenceLevelMarkerStyles[0],
|
|
42
|
+
},
|
|
43
|
+
false,
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
32
47
|
}
|
|
33
48
|
|
|
34
49
|
export default ScatterChart;
|
|
@@ -11,7 +11,7 @@ class SpecificChartOptions {
|
|
|
11
11
|
colors: this.theme === 'alternate' ? this.constants.alternateTheme : this.constants.primaryTheme,
|
|
12
12
|
chart: {
|
|
13
13
|
type: type,
|
|
14
|
-
marginTop: this.config.legend.enabled ? undefined : 50,
|
|
14
|
+
marginTop: this.config.legend.enabled ? (type === 'boxplot' ? 50 : undefined) : 50,
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
17
|
}
|