@ons/design-system 72.9.0 → 72.9.1
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/_macro.njk +15 -2
- package/components/card/example-card-set-with-headline-figures.njk +1 -4
- package/components/chart/_macro.njk +2 -1
- package/components/chart/_macro.spec.js +17 -121
- package/components/chart/area-chart.js +1 -0
- package/components/chart/bar-chart.js +2 -2
- package/components/chart/chart.js +1 -4
- package/components/table-of-contents/_macro.njk +1 -11
- package/components/table-of-contents/example-table-of-contents-related-links-with-button.njk +1 -2
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/components/chart/example-bar-with-line-chart.njk +0 -64
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
{% set placeholderSrcset = (params.image.placeholderUrl if params.image.placeholderUrl else "") + "/img/small/placeholder-card.png 1x, " + (params.image.placeholderUrl if params.image.placeholderUrl else "") + "/img/large/placeholder-card.png 2x" %}
|
|
6
6
|
|
|
7
7
|
<div class="ons-card {% if params.variant == "feature" %}ons-card--feature ons-u-flex-grow{% endif %}">
|
|
8
|
-
|
|
8
|
+
{% set imageBlock %}
|
|
9
9
|
{%- if params.image -%}
|
|
10
10
|
{% if params.image.smallSrc %}
|
|
11
11
|
<img
|
|
@@ -29,10 +29,23 @@
|
|
|
29
29
|
/>
|
|
30
30
|
{% endif %}
|
|
31
31
|
{%- endif -%}
|
|
32
|
+
{% endset %}
|
|
33
|
+
|
|
34
|
+
{% set titleBlock %}
|
|
32
35
|
{{ openingHeadingTag | safe }}
|
|
33
36
|
class="ons-card__title {{ params.title.classes | default('ons-u-fs-m') }}" id="{{ params.title.id }}"> {{ params.title.text }}
|
|
34
37
|
{{ closingHeadingTag | safe }}
|
|
35
|
-
|
|
38
|
+
{% endset %}
|
|
39
|
+
|
|
40
|
+
{% if params.title.url %}
|
|
41
|
+
<a href="{{ params.title.url }}" class="ons-card__link {% if params.title.subtitle %}ons-u-mb-xs{% endif %}">
|
|
42
|
+
{{ imageBlock | safe }}
|
|
43
|
+
{{ titleBlock | safe }}
|
|
44
|
+
</a>
|
|
45
|
+
{% else %}
|
|
46
|
+
{{ imageBlock | safe }}
|
|
47
|
+
{{ titleBlock | safe }}
|
|
48
|
+
{% endif %}
|
|
36
49
|
|
|
37
50
|
{% if params.title.subtitle %}
|
|
38
51
|
<p class="ons-card__subtitle ons-u-fs-s">{{ params.title.subtitle }}</p>
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"title": {
|
|
10
10
|
"id": 'card-set-1',
|
|
11
11
|
"text": 'Deaths registered annually',
|
|
12
|
-
"url": '#0',
|
|
13
12
|
"subtitle": 'England and Wales'
|
|
14
13
|
},
|
|
15
14
|
"body":{
|
|
@@ -28,7 +27,6 @@
|
|
|
28
27
|
"title": {
|
|
29
28
|
"id": 'card-set-2',
|
|
30
29
|
"text": 'Alcohol-specific deaths',
|
|
31
|
-
"url": '#0',
|
|
32
30
|
"subtitle": 'UK'
|
|
33
31
|
},
|
|
34
32
|
"body":{
|
|
@@ -47,8 +45,7 @@
|
|
|
47
45
|
"title": {
|
|
48
46
|
"id": 'card-set-3',
|
|
49
47
|
"text": 'Suicides registered',
|
|
50
|
-
"subtitle": 'England and Wales'
|
|
51
|
-
"url": '#0'
|
|
48
|
+
"subtitle": 'England and Wales'
|
|
52
49
|
},
|
|
53
50
|
"body":{
|
|
54
51
|
"id": 'text3',
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
{% macro onsChart(params) %}
|
|
4
4
|
{% set supportedChartTypes = ['line', 'bar', 'column', 'scatter', 'area'] %}
|
|
5
|
+
{% set supportedChartTypesWithLine = ['column'] %}
|
|
5
6
|
|
|
6
7
|
{% if params.headingLevel and params.headingLevel >= 1 and params.headingLevel <= 4 %}
|
|
7
8
|
{% set headingLevel = params.headingLevel %}
|
|
@@ -94,7 +95,7 @@
|
|
|
94
95
|
"enabled": item.dataLabels if item.dataLabels else false
|
|
95
96
|
},
|
|
96
97
|
"connectNulls": item.connectNulls if item.connectNulls else false,
|
|
97
|
-
"type": item.type if item.type and item.type == 'line' else params.chartType
|
|
98
|
+
"type": item.type if item.type and item.type == 'line' and params.chartType in supportedChartTypesWithLine else params.chartType
|
|
98
99
|
}
|
|
99
100
|
%}
|
|
100
101
|
{# Use `set` tag to avoid printing the return value of extend #}
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
EXAMPLE_LINE_CHART_WITH_ANNOTATIONS_PARAMS,
|
|
14
14
|
EXAMPLE_BAR_CHART_WITH_ANNOTATIONS_PARAMS,
|
|
15
15
|
EXAMPLE_COLUMN_CHART_WITH_ANNOTATIONS_PARAMS,
|
|
16
|
-
EXAMPLE_BAR_WITH_LINE_CHART_PARAMS,
|
|
17
16
|
EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
|
|
18
17
|
EXAMPLE_SCATTER_CHART_PARAMS,
|
|
19
18
|
EXAMPLE_AREA_CHART_PARAMS,
|
|
@@ -625,126 +624,6 @@ describe('Macro: Chart', () => {
|
|
|
625
624
|
});
|
|
626
625
|
});
|
|
627
626
|
|
|
628
|
-
describe('FOR: Bar Chart with Line', () => {
|
|
629
|
-
describe('GIVEN: Params: required', () => {
|
|
630
|
-
describe('WHEN: required params are provided', () => {
|
|
631
|
-
const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_WITH_LINE_CHART_PARAMS));
|
|
632
|
-
const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
|
|
633
|
-
|
|
634
|
-
test('THEN: it passes jest-axe checks', async () => {
|
|
635
|
-
const results = await axe($.html());
|
|
636
|
-
expect(results).toHaveNoViolations();
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
test('THEN: it includes one series of type "bar" and another of type "line"', () => {
|
|
640
|
-
expect(configScript).toContain('"type":"bar"');
|
|
641
|
-
expect(configScript).toContain('"type":"line"');
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
test('THEN: it renders the chart container with correct data attributes', () => {
|
|
645
|
-
expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('bar');
|
|
646
|
-
expect($('[data-highcharts-base-chart]').attr('data-highcharts-theme')).toBe('alternate');
|
|
647
|
-
expect($('[data-highcharts-base-chart]').attr('data-highcharts-title')).toBe('Example Bar Chart');
|
|
648
|
-
expect($('[data-highcharts-base-chart]').attr('data-highcharts-id')).toBe('bar-chart-123');
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
test('THEN: it includes the Highcharts JSON config', () => {
|
|
652
|
-
expect(configScript).toContain('"text":"X Axis Title"');
|
|
653
|
-
expect(configScript).toContain('"text":"Y Axis Title"');
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
describe('GIVEN: Params: Legend', () => {
|
|
659
|
-
describe('WHEN: legend is enabled', () => {
|
|
660
|
-
const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_BAR_WITH_LINE_CHART_PARAMS, legend: false }));
|
|
661
|
-
|
|
662
|
-
test('THEN: it renders the legend', () => {
|
|
663
|
-
const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
|
|
664
|
-
expect(configScript).toContain('"enabled":false');
|
|
665
|
-
});
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
describe('GIVEN: Params: Caption', () => {
|
|
670
|
-
describe('WHEN: caption is provided', () => {
|
|
671
|
-
const $ = cheerio.load(
|
|
672
|
-
renderComponent('chart', {
|
|
673
|
-
...EXAMPLE_BAR_WITH_LINE_CHART_PARAMS,
|
|
674
|
-
caption: 'This is an example caption for the chart.',
|
|
675
|
-
}),
|
|
676
|
-
);
|
|
677
|
-
|
|
678
|
-
test('THEN: it renders the caption when provided', () => {
|
|
679
|
-
expect($('figcaption').text()).toBe('This is an example caption for the chart.');
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
describe('GIVEN: Params: Description', () => {
|
|
685
|
-
describe('WHEN: description is provided', () => {
|
|
686
|
-
const $ = cheerio.load(
|
|
687
|
-
renderComponent('chart', {
|
|
688
|
-
...EXAMPLE_BAR_WITH_LINE_CHART_PARAMS,
|
|
689
|
-
description: 'An accessible description for screen readers.',
|
|
690
|
-
}),
|
|
691
|
-
);
|
|
692
|
-
|
|
693
|
-
test('THEN: it renders the description for accessibility', () => {
|
|
694
|
-
expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.');
|
|
695
|
-
});
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
describe('GIVEN: Params: Series: Type', () => {
|
|
700
|
-
describe('WHEN: a series has an invalid type', () => {
|
|
701
|
-
const invalidTypeParams = {
|
|
702
|
-
...EXAMPLE_BAR_WITH_LINE_CHART_PARAMS,
|
|
703
|
-
series: [
|
|
704
|
-
{ name: 'Invalid Series', data: [5, 15, 25], type: 'scatter' },
|
|
705
|
-
{ name: 'Valid Line Series', data: [10, 20, 30], type: 'line' },
|
|
706
|
-
],
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
const $ = cheerio.load(renderComponent('chart', invalidTypeParams));
|
|
710
|
-
const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
|
|
711
|
-
|
|
712
|
-
test('THEN: it defaults non-line series type to the chartType', () => {
|
|
713
|
-
expect(configScript).not.toContain('"type":"scatter"');
|
|
714
|
-
expect(configScript).toContain('"type":"bar"');
|
|
715
|
-
expect(configScript).toContain('"type":"line"');
|
|
716
|
-
});
|
|
717
|
-
});
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
describe('GIVEN: Params: Download', () => {
|
|
721
|
-
describe('WHEN: download object are provided', () => {
|
|
722
|
-
const $ = cheerio.load(
|
|
723
|
-
renderComponent('chart', {
|
|
724
|
-
...EXAMPLE_BAR_WITH_LINE_CHART_PARAMS,
|
|
725
|
-
download: {
|
|
726
|
-
title: 'Download Chart Data',
|
|
727
|
-
itemsList: [
|
|
728
|
-
{ text: 'Download as PNG', url: 'https://example.com/chart.png' },
|
|
729
|
-
{ text: 'Download as CSV', url: 'https://example.com/chart.csv' },
|
|
730
|
-
],
|
|
731
|
-
},
|
|
732
|
-
}),
|
|
733
|
-
);
|
|
734
|
-
|
|
735
|
-
test('THEN: it renders the download section correctly', () => {
|
|
736
|
-
expect($('.ons-chart__download-title').text()).toBe('Download Chart Data');
|
|
737
|
-
|
|
738
|
-
const downloadLinks = $('.ons-chart__download-title').next().find('li a');
|
|
739
|
-
expect(downloadLinks.eq(0).text()).toBe('Download as PNG');
|
|
740
|
-
expect(downloadLinks.eq(0).attr('href')).toBe('https://example.com/chart.png');
|
|
741
|
-
expect(downloadLinks.eq(1).text()).toBe('Download as CSV');
|
|
742
|
-
expect(downloadLinks.eq(1).attr('href')).toBe('https://example.com/chart.csv');
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
|
|
748
627
|
describe('FOR: Column Chart with Line', () => {
|
|
749
628
|
describe('GIVEN: Params: required', () => {
|
|
750
629
|
describe('WHEN: required params are provided', () => {
|
|
@@ -863,6 +742,23 @@ describe('Macro: Chart', () => {
|
|
|
863
742
|
});
|
|
864
743
|
});
|
|
865
744
|
});
|
|
745
|
+
|
|
746
|
+
describe('GIVEN: Params: ChartType', () => {
|
|
747
|
+
describe('WHEN: chartType is not compatible with line series', () => {
|
|
748
|
+
const params = {
|
|
749
|
+
...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
|
|
750
|
+
chartType: 'bar',
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
const $ = cheerio.load(renderComponent('chart', params));
|
|
754
|
+
const configScript = $('script[data-highcharts-config--column-chart-123]').html();
|
|
755
|
+
|
|
756
|
+
test('THEN: it falls back to chartType and does not include "line" series', () => {
|
|
757
|
+
expect(configScript).not.toContain('"type":"line"');
|
|
758
|
+
expect(configScript).toContain('"type":"bar"');
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
});
|
|
866
762
|
});
|
|
867
763
|
|
|
868
764
|
describe('FOR: Scatter chart', () => {
|
|
@@ -125,9 +125,9 @@ class BarChart {
|
|
|
125
125
|
|
|
126
126
|
// This updates the height of the vertical axis and overall chart to fit the number of categories
|
|
127
127
|
// Note that the vertical axis on a bar chart is the x axis
|
|
128
|
-
updateBarChartHeight = (config, currentChart, useStackedLayout
|
|
128
|
+
updateBarChartHeight = (config, currentChart, useStackedLayout) => {
|
|
129
129
|
const numberOfCategories = config.xAxis.categories.length;
|
|
130
|
-
const numberOfSeries = currentChart.series.length
|
|
130
|
+
const numberOfSeries = currentChart.series.length; // Get number of bar series
|
|
131
131
|
let barHeight = 30; // Height of each individual bar - set in bar-chart-plot-options
|
|
132
132
|
let groupSpacing = 0; // Space we want between category groups, or between series groups for cluster charts
|
|
133
133
|
let categoriesTotalHeight = 0;
|
|
@@ -141,9 +141,6 @@ class HighchartsBaseChart {
|
|
|
141
141
|
if (this.chartType === 'column') {
|
|
142
142
|
this.config = this.mergeConfigs(this.config, columnChartOptions);
|
|
143
143
|
}
|
|
144
|
-
if (this.chartType === 'bar') {
|
|
145
|
-
this.config = this.mergeConfigs(this.config, barChartOptions);
|
|
146
|
-
}
|
|
147
144
|
}
|
|
148
145
|
|
|
149
146
|
// Disable the legend for single series charts
|
|
@@ -220,7 +217,7 @@ class HighchartsBaseChart {
|
|
|
220
217
|
this.commonChartOptions.hideDataLabels(currentChart.series);
|
|
221
218
|
}
|
|
222
219
|
if (this.chartType === 'bar') {
|
|
223
|
-
this.barChart.updateBarChartHeight(this.config, currentChart, this.useStackedLayout
|
|
220
|
+
this.barChart.updateBarChartHeight(this.config, currentChart, this.useStackedLayout);
|
|
224
221
|
if (!this.hideDataLabels) {
|
|
225
222
|
this.barChart.postLoadDataLabels(currentChart);
|
|
226
223
|
} else {
|
|
@@ -61,17 +61,7 @@
|
|
|
61
61
|
|
|
62
62
|
{% if params.button %}
|
|
63
63
|
<div class="ons-table-of-contents__button ons-u-pt-l">
|
|
64
|
-
{% set allVariants = ['small', 'secondary'] %}
|
|
65
|
-
|
|
66
|
-
{% if params.button.variants %}
|
|
67
|
-
{% if params.button.variants is string %}
|
|
68
|
-
{% set allVariants = (allVariants.push(params.button.variants), allVariants) %}
|
|
69
|
-
{% else %}
|
|
70
|
-
{% for variant in params.button.variants %}
|
|
71
|
-
{% set allVariants = (allVariants.push(variant), allVariants) %}
|
|
72
|
-
{% endfor %}
|
|
73
|
-
{% endif %}
|
|
74
|
-
{% endif %}
|
|
64
|
+
{% set allVariants = ['small', 'secondary', 'print'] %}
|
|
75
65
|
|
|
76
66
|
{{
|
|
77
67
|
onsButton({
|