@ons/design-system 72.8.0 → 72.9.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.
@@ -22,7 +22,6 @@ class CommonChartOptions {
22
22
  symbolWidth: 20,
23
23
  margin: 50,
24
24
  navigation: {
25
- // ensures that when the legend is long, there is no pagination or scrollbar
26
25
  enabled: false,
27
26
  },
28
27
  itemDistance: 30,
@@ -30,9 +29,8 @@ class CommonChartOptions {
30
29
  color: this.constants.labelColor, // Prevents the text from changing color on hover
31
30
  },
32
31
  itemStyle: {
33
- cursor: 'default', // ensures that it does not change to a hand (pointer) on hover.
34
32
  color: this.constants.labelColor,
35
- fontSize: this.constants.desktopFontSize,
33
+ fontSize: this.constants.defaultFontSize,
36
34
  fontWeight: 'normal',
37
35
  },
38
36
  // Disable click event on legend
@@ -64,7 +62,7 @@ class CommonChartOptions {
64
62
  labels: {
65
63
  style: {
66
64
  color: this.constants.axisLabelColor,
67
- fontSize: this.constants.desktopFontSize,
65
+ fontSize: this.constants.defaultFontSize,
68
66
  },
69
67
  },
70
68
  title: {
@@ -78,7 +76,7 @@ class CommonChartOptions {
78
76
  y: -25,
79
77
  style: {
80
78
  color: this.constants.axisLabelColor,
81
- fontSize: this.constants.desktopFontSize,
79
+ fontSize: this.constants.defaultFontSize,
82
80
  },
83
81
  },
84
82
  lineColor: this.constants.gridLineColor,
@@ -87,7 +85,7 @@ class CommonChartOptions {
87
85
  plotLines: [
88
86
  {
89
87
  color: this.constants.zeroLineColor,
90
- width: 1,
88
+ width: 1.5,
91
89
  value: 0,
92
90
  zIndex: 2,
93
91
  },
@@ -104,14 +102,14 @@ class CommonChartOptions {
104
102
  rotation: 0,
105
103
  style: {
106
104
  color: this.constants.axisLabelColor,
107
- fontSize: this.constants.desktopFontSize,
105
+ fontSize: this.constants.defaultFontSize,
108
106
  },
109
107
  },
110
108
  title: {
111
109
  align: 'high',
112
110
  style: {
113
111
  color: this.constants.axisLabelColor,
114
- fontSize: this.constants.desktopFontSize,
112
+ fontSize: this.constants.defaultFontSize,
115
113
  },
116
114
  },
117
115
  lineColor: this.constants.gridLineColor,
@@ -147,35 +145,10 @@ class CommonChartOptions {
147
145
 
148
146
  getMobileOptions = (xAxisTickInterval, yAxisTickInterval) => {
149
147
  return {
150
- legend: {
151
- itemStyle: {
152
- fontSize: this.constants.mobileFontSize,
153
- },
154
- },
155
148
  xAxis: {
156
- labels: {
157
- style: {
158
- fontSize: this.constants.mobileFontSize,
159
- },
160
- },
161
- title: {
162
- style: {
163
- fontSize: this.constants.mobileFontSize,
164
- },
165
- },
166
149
  tickInterval: xAxisTickInterval,
167
150
  },
168
151
  yAxis: {
169
- labels: {
170
- style: {
171
- fontSize: this.constants.mobileFontSize,
172
- },
173
- },
174
- title: {
175
- style: {
176
- fontSize: this.constants.mobileFontSize,
177
- },
178
- },
179
152
  tickInterval: yAxisTickInterval,
180
153
  },
181
154
  };
@@ -0,0 +1,68 @@
1
+ {% from "components/chart/_macro.njk" import onsChart %}
2
+
3
+ {{
4
+ onsChart({
5
+ "chartType": "area",
6
+ "description": "Area 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
+ "series": [
32
+ {
33
+ "data": [
34
+ 39.2, 47.1, 44.0, 46, 65.3, 53.2, 49.1, 49.3, 50.4, 48.1,
35
+ 43.9, 41.8
36
+ ],
37
+ "name": "Test series 3"
38
+ },
39
+ {
40
+ "data": [
41
+ 28.8, 23.2, 33.0, 25.8, 20.8, 39.8, 37.9, 28.2, 37.6, 46.7,
42
+ 43.9, 41.8
43
+ ],
44
+ "name": "Test series 2"
45
+ },
46
+ {
47
+ "data": [
48
+ 37.8, 41.0, 43.0, 42.9, 41.8, 39.8, 37.9, 38.2, 37.6, 36.7,
49
+ 33.9, 31.8
50
+ ],
51
+ "name": "Test series 1"
52
+ }
53
+ ],
54
+ "xAxis": {
55
+ "categories": [
56
+ "Mar 1901", "Mar 1902", "Mar 1903", "Mar 1904", "Mar 1905", "Mar 1906", "Mar 1907", "Mar 1908", "Mar 1909", "Mar 1910",
57
+ "Mar 1911", "Mar 1912"
58
+ ],
59
+ "title": "Years",
60
+ "type": "linear"
61
+ },
62
+ "yAxis": {
63
+ "title": "Y axis title"
64
+ },
65
+ "percentageHeightDesktop": 50,
66
+ "percentageHeightMobile": 120
67
+ })
68
+ }}
@@ -58,6 +58,8 @@
58
58
  "name": "Another test data source",
59
59
  "type": "line"
60
60
  }
61
- ]
61
+ ],
62
+ "percentageHeightDesktop": 35,
63
+ "percentageHeightMobile": 90
62
64
  })
63
65
  }}
@@ -0,0 +1,138 @@
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": "primary",
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
+ ]
47
+ },
48
+ "yAxis": {
49
+ "title": "Sales",
50
+ "labelFormat": "{value:,.f}"
51
+ },
52
+ "series": [
53
+ {
54
+ "name": 'CPIH',
55
+ "data": [
56
+ 1.3, null, 0.7, 0.5, 0.4, 0.3, 0.3, 0.4, 0.3, 0.5
57
+ ],
58
+ "marker": 'true',
59
+ "connectNulls": 'true'
60
+ },
61
+ {
62
+ "name": 'Goods',
63
+ "data": [
64
+ 0.3, -0.2, -1.0, null, -2.0, -2.1, -1.9, -1.8, -2.0, -1.8
65
+ ],
66
+ "marker": 'true',
67
+ "connectNulls": 'true'
68
+ },
69
+ {
70
+ "name": 'Services',
71
+ "data": [
72
+ 2.2, 2.1, 2.1, 2.1, 2.2, 2.2, 2.0, 2.1, 2.1, 2.2
73
+ ],
74
+ "marker": 'true',
75
+ "connectNulls": 'true'
76
+ },
77
+ {
78
+ "name": 'CPIH excl energy, food, alcohol & tobacco',
79
+ "data": [
80
+ 1.5, 1.3, 1.4, 1.5, 1.4, 1.2, 1.1, 1.2, 1.0, 1.3
81
+ ],
82
+ "marker": 'true',
83
+ "connectNulls": 'true'
84
+ }
85
+ ,
86
+ {
87
+ "name": 'Extra test series 1',
88
+ "data": [
89
+ 3.2, 3.7, 3.8, 3.9, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7
90
+ ],
91
+ "marker": 'true',
92
+ "connectNulls": 'true'
93
+ },
94
+ {
95
+ "name": 'Extra test series 2',
96
+ "data": [
97
+ 4.5, 4.3, 4.4, 4.5, 4.4, 4.2, 4.1, 4.2, 4.0, 4.3
98
+ ],
99
+ "marker": 'true',
100
+ "connectNulls": 'true'
101
+ },
102
+ {
103
+ "name": 'Extra test series 3',
104
+ "data": [
105
+ 5.5, 5.3, 5.4, 5.5, 5.4, 5.2, 5.1, 5.2, 5.0, 5.3
106
+ ],
107
+ "marker": 'true',
108
+ "connectNulls": 'true'
109
+ },
110
+ {
111
+ "name": 'Extra test series 4',
112
+ "data": [
113
+ -3.5, -3.3, -3.4, -3.5, -3.4, -3.2, -3.1, -3.2, -3.0, -3.3
114
+ ],
115
+ "marker": 'true',
116
+ "connectNulls": 'true'
117
+ },
118
+ {
119
+ "name": 'Extra test series 5',
120
+ "data": [
121
+ -4.5, -4.3, -4.4, -4.5, -4.4, -4.2, -4.1, -4.2, -4.0, -4.3
122
+ ],
123
+ "marker": 'true',
124
+ "connectNulls": 'true'
125
+ },
126
+ {
127
+ "name": 'Extra test series 6',
128
+ "data": [
129
+ -5.5, -5.3, -5.4, -5.5, -5.4, -5.2, -5.1, -5.2, -5.0, -5.3
130
+ ],
131
+ "marker": 'true',
132
+ "connectNulls": 'true'
133
+ }
134
+ ],
135
+ "percentageHeightDesktop": 35,
136
+ "percentageHeightMobile": 90
137
+ })
138
+ }}
@@ -0,0 +1,94 @@
1
+ {% from "components/chart/_macro.njk" import onsChart %}
2
+
3
+ {{
4
+ onsChart({
5
+ "chartType": "scatter",
6
+ "description": "Example scatter chart",
7
+ "theme": "alternate",
8
+ "title": "Example scatter chart",
9
+ "subtitle": "Scatter chart subtitle",
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
+ "xAxis": {
31
+ "title": "Height"
32
+ },
33
+ "yAxis": {
34
+ "title": "Weight"
35
+ },
36
+ "legend": 'true',
37
+ "series": [
38
+ {
39
+ "name": "Female",
40
+ "data": [
41
+ [161.2, 51.6], [167.5, 59.0], [159.5, 49.2], [157.0, 63.0],
42
+ [163.8, 54.5], [158.4, 50.8], [165.2, 57.3], [160.7, 52.4],
43
+ [162.3, 55.1], [166.8, 58.7], [159.8, 51.9], [164.5, 56.2],
44
+ [158.9, 50.3], [163.1, 53.8],
45
+ [161.8, 52.1], [167.1, 58.8], [159.2, 49.8], [157.4, 62.7],
46
+ [163.5, 54.9], [158.7, 51.2], [165.5, 57.8], [160.4, 52.7],
47
+ [162.7, 55.4], [166.4, 58.4], [159.4, 51.5], [164.8, 56.5],
48
+ [158.6, 50.6], [163.4, 53.5]
49
+ ],
50
+ "marker": 'true'
51
+ },
52
+ {
53
+ "name": "Male",
54
+ "data": [
55
+ [174.0, 65.6], [175.3, 71.8], [187.5, 80.7], [186.5, 72.6],
56
+ [178.2, 68.4], [182.7, 74.3], [176.8, 67.9], [188.4, 77.2],
57
+ [184.5, 73.8], [179.6, 70.5], [186.2, 79.4], [183.8, 75.1],
58
+ [177.4, 69.2], [185.9, 76.3],
59
+ [174.3, 66.1], [175.8, 71.4], [187.8, 80.2], [186.1, 72.9],
60
+ [178.7, 68.8], [182.2, 74.7], [176.4, 67.5], [188.0, 77.6],
61
+ [184.1, 73.4], [179.2, 70.8], [186.6, 79.8], [183.4, 75.4],
62
+ [177.8, 69.6], [185.5, 76.7]
63
+ ],
64
+ "marker": 'true'
65
+ },
66
+ {
67
+ "name": "Adolescent Male",
68
+ "data": [
69
+ [168.5, 58.2], [171.2, 62.4], [169.8, 59.7], [173.4, 63.8],
70
+ [170.6, 61.2], [172.8, 64.5], [167.9, 57.8], [174.2, 65.1],
71
+ [169.5, 60.3], [171.8, 63.2],
72
+ [168.8, 58.6], [171.5, 62.8], [169.2, 59.4], [173.7, 63.5],
73
+ [170.2, 61.6], [172.4, 64.2], [168.2, 58.1], [173.9, 64.8],
74
+ [169.8, 60.7], [171.4, 63.6]
75
+ ],
76
+ "marker": 'true'
77
+ },
78
+ {
79
+ "name": "Adolescent Female",
80
+ "data": [
81
+ [164.2, 54.8], [166.5, 57.2], [163.8, 53.9], [165.7, 56.4],
82
+ [162.9, 52.8], [167.2, 58.1], [164.8, 55.3], [166.9, 57.8],
83
+ [163.5, 53.4], [165.4, 56.7],
84
+ [164.5, 55.1], [166.2, 57.5], [163.4, 53.6], [165.9, 56.2],
85
+ [162.6, 52.5], [167.5, 58.4], [164.4, 55.6], [166.6, 57.6],
86
+ [163.8, 53.7], [165.2, 56.9]
87
+ ],
88
+ "marker": 'true'
89
+ }
90
+ ],
91
+ "percentageHeightDesktop": 35,
92
+ "percentageHeightMobile": 90
93
+ })
94
+ }}
@@ -1,39 +1,34 @@
1
+ import ChartConstants from './chart-constants';
1
2
  class LineChart {
3
+ constructor() {
4
+ this.chartConstants = ChartConstants.constants();
5
+ this.markerStyles = this.chartConstants.lineMarkerStyles;
6
+ }
7
+
2
8
  getLineChartOptions = () => {
3
9
  return {
4
10
  plotOptions: {
5
11
  line: {
6
12
  lineWidth: 3,
7
13
  linecap: 'round',
8
- // In a later PR we will update the marker styles
9
- marker: {
10
- enabled: false,
11
- radius: 4,
12
- symbol: 'circle',
13
- lineWidth: 0,
14
- },
15
14
  },
16
15
  },
17
16
  };
18
17
  };
19
18
 
20
19
  updateLastPointMarker = (series) => {
21
- series.forEach((series) => {
22
- // If markers are disabled, hide them all but the last point marker
23
- if (series.options.marker.enabled.enabled === undefined) {
24
- const points = series.points;
25
- if (points && points.length > 0) {
26
- // Show only the last point marker
27
- const lastPoint = points[points.length - 1];
28
- lastPoint.update(
29
- {
30
- marker: {
31
- enabled: true,
32
- },
33
- },
34
- false,
35
- );
36
- }
20
+ series.forEach((series, i) => {
21
+ const points = series.points;
22
+ if (points && points.length > 0) {
23
+ // Show only the last point marker
24
+ const lastPoint = points[points.length - 1];
25
+ lastPoint.update({
26
+ marker: {
27
+ enabled: true,
28
+ },
29
+ });
30
+ // Update the marker styles to use for each series
31
+ series.update({ marker: this.markerStyles[i] != undefined ? this.markerStyles[i] : this.markerStyles[0] }, false);
37
32
  }
38
33
  });
39
34
  };
@@ -0,0 +1,34 @@
1
+ import ChartConstants from './chart-constants';
2
+
3
+ class ScatterChart {
4
+ constructor() {
5
+ this.chartConstants = ChartConstants.constants();
6
+ this.markerStyles = this.chartConstants.scatterMarkerStyles;
7
+ }
8
+
9
+ getScatterChartOptions = () => {
10
+ return {
11
+ plotOptions: {
12
+ scatter: {
13
+ // enable tooltips for scatter charts
14
+ enableMouseTracking: true,
15
+ },
16
+ },
17
+ xAxis: {
18
+ gridLineWidth: 1,
19
+ },
20
+ yAxis: {
21
+ gridLineWidth: 1,
22
+ },
23
+ };
24
+ };
25
+
26
+ // Use a different set of marker styles for scatter charts
27
+ updateMarkers = (currentChart) => {
28
+ currentChart.series.forEach((series, i) => {
29
+ series.update({ marker: this.markerStyles[i] != undefined ? this.markerStyles[i] : this.markerStyles[0] }, false);
30
+ });
31
+ };
32
+ }
33
+
34
+ export default ScatterChart;