@ons/design-system 72.9.2 → 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.
Files changed (33) hide show
  1. package/components/chart/_chart.scss +74 -1
  2. package/components/chart/_macro.njk +64 -5
  3. package/components/chart/_macro.spec.js +405 -0
  4. package/components/chart/bar-chart.js +2 -2
  5. package/components/chart/boxplot.js +37 -0
  6. package/components/chart/chart-constants.js +13 -0
  7. package/components/chart/chart.js +86 -46
  8. package/components/chart/columnrange-chart.js +94 -0
  9. package/components/chart/common-chart-options.js +28 -15
  10. package/components/chart/example-bar-chart-with-annotations.njk +1 -1
  11. package/components/chart/example-bar-chart-with-point-range-and-reference-line-annotations.njk +95 -0
  12. package/components/chart/example-bar-with-confidence-levels.njk +71 -0
  13. package/components/chart/example-clustered-column-chart.njk +1 -3
  14. package/components/chart/example-column-chart-with-annotations.njk +1 -1
  15. package/components/chart/example-column-chart-with-range-annotations.njk +64 -0
  16. package/components/chart/example-column-chart-with-reference-line-annotations.njk +64 -0
  17. package/components/chart/example-column-with-confidence-levels.njk +61 -0
  18. package/components/chart/example-line-chart-with-annotations.njk +3 -3
  19. package/components/chart/example-line-chart-with-markers.njk +1 -1
  20. package/components/chart/example-line-chart-with-range-annotations-inside.njk +238 -0
  21. package/components/chart/example-line-chart-with-range-annotations-outside-left-right.njk +240 -0
  22. package/components/chart/example-line-chart-with-range-annotations-outside-top-bottom.njk +239 -0
  23. package/components/chart/example-line-chart-with-reference-line-annotations.njk +236 -0
  24. package/components/chart/example-scatter-chart.njk +1 -1
  25. package/components/chart/range-annotations-options.js +216 -0
  26. package/components/chart/reference-line-annotations-options.js +93 -0
  27. package/components/chart/scatter-chart.js +15 -0
  28. package/components/chart/specific-chart-options.js +1 -1
  29. package/components/chart/utilities.js +96 -0
  30. package/css/main.css +1 -1
  31. package/package.json +1 -1
  32. package/scripts/main.es5.js +1 -1
  33. package/scripts/main.js +1 -1
@@ -0,0 +1,96 @@
1
+ // Utility function to merge two configs together
2
+ export const mergeConfigs = (baseConfig, newConfig) => {
3
+ // If newConfig is null/undefined, return baseConfig
4
+ if (!newConfig) return baseConfig;
5
+
6
+ // Create a new object to store the merged result
7
+ const merged = { ...baseConfig };
8
+
9
+ // Iterate through all keys in newConfig
10
+ Object.keys(newConfig).forEach((key) => {
11
+ // Get values from both configs for this key
12
+ const baseValue = merged[key];
13
+ const newValue = newConfig[key];
14
+
15
+ // If both values are objects (and not null), recursively merge them
16
+ if (
17
+ baseValue &&
18
+ newValue &&
19
+ typeof baseValue === 'object' &&
20
+ typeof newValue === 'object' &&
21
+ !Array.isArray(baseValue) &&
22
+ !Array.isArray(newValue)
23
+ ) {
24
+ merged[key] = mergeConfigs(baseValue, newValue);
25
+ } else {
26
+ // For non-objects and arrays use the new value
27
+ // If the new value is null/undefined, use the base value
28
+ merged[key] = newValue ?? baseValue;
29
+ }
30
+ });
31
+
32
+ return merged;
33
+ };
34
+
35
+ // Helper function to process the range and reference line annotations plus any plot lines config
36
+ // ready to pass to the responsive rules
37
+ export const preparePlotLinesAndBands = (
38
+ annotations = undefined,
39
+ rangeAnnotations = undefined,
40
+ rangeAnnotationsOptions = undefined,
41
+ referenceLineAnnotationsOptions = undefined,
42
+ commonChartOptions,
43
+ chartType,
44
+ ) => {
45
+ const totalPointAndRangeAnnotations = (annotations ? annotations.length : 0) + (rangeAnnotations ? rangeAnnotations.length : 0);
46
+
47
+ // Both range and reference line annotations are added to the axis objects, so we need to correctly combine them before we can pass them to the config.
48
+ let desktopRangeAnnotations = {};
49
+ let mobileRangeAnnotations = {};
50
+ let desktopReferenceLineAnnotations = {};
51
+ let mobileReferenceLineAnnotations = {};
52
+ let desktopAllPlotLines = {};
53
+ let mobileAllPlotLines = {};
54
+ let desktopAllPlotLinesAndBands = {};
55
+ let mobileAllPlotLinesAndBands = {};
56
+
57
+ // get the desktop and mobile range annotations
58
+ if (rangeAnnotationsOptions) {
59
+ desktopRangeAnnotations = rangeAnnotationsOptions.getRangeAnnotationsOptionsDesktop(chartType);
60
+ mobileRangeAnnotations = rangeAnnotationsOptions.getRangeAnnotationsOptionsMobile(annotations ? annotations.length : 0, chartType);
61
+ }
62
+
63
+ // get the desktop and mobile reference line annotations
64
+ if (referenceLineAnnotationsOptions) {
65
+ desktopReferenceLineAnnotations = referenceLineAnnotationsOptions.getReferenceLineAnnotationsOptionsDesktop();
66
+ mobileReferenceLineAnnotations = referenceLineAnnotationsOptions.getReferenceLineAnnotationsOptionsMobile(
67
+ totalPointAndRangeAnnotations,
68
+ chartType,
69
+ );
70
+ }
71
+
72
+ // We also need to combine the zero line (and any future plot lines) with the reference line annotations here, as otherwise
73
+ // it gets overridden by the reference line annotations config
74
+ let plotLineOptions = commonChartOptions.getPlotLines();
75
+
76
+ if (desktopReferenceLineAnnotations.yAxis !== undefined) {
77
+ let desktopMergedPlotLines = desktopReferenceLineAnnotations.yAxis.plotLines.concat(plotLineOptions.yAxis.plotLines);
78
+ let mobileMergedPlotLines = mobileReferenceLineAnnotations.yAxis.plotLines.concat(plotLineOptions.yAxis.plotLines);
79
+ desktopAllPlotLines = { ...desktopReferenceLineAnnotations };
80
+ mobileAllPlotLines = { ...mobileReferenceLineAnnotations };
81
+ desktopAllPlotLines.yAxis.plotLines = desktopMergedPlotLines;
82
+ mobileAllPlotLines.yAxis.plotLines = mobileMergedPlotLines;
83
+ } else {
84
+ desktopAllPlotLines = { ...plotLineOptions };
85
+ mobileAllPlotLines = { ...plotLineOptions };
86
+ }
87
+
88
+ // combine the desktop and mobile range and reference line annotations, along with other plot lines, ready to pass to the config
89
+ desktopAllPlotLinesAndBands = mergeConfigs(desktopRangeAnnotations, desktopAllPlotLines);
90
+ mobileAllPlotLinesAndBands = mergeConfigs(mobileRangeAnnotations, mobileAllPlotLines);
91
+
92
+ return {
93
+ desktopAllPlotLinesAndBands,
94
+ mobileAllPlotLinesAndBands,
95
+ };
96
+ };