@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.
- 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 +86 -46
- package/components/chart/columnrange-chart.js +94 -0
- package/components/chart/common-chart-options.js +28 -15
- 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/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,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
|
+
};
|