@neo4j-ndl/react-charts 2.1.22 → 2.2.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/lib/LICENSES.txt +0 -295
- package/lib/NOTICE.txt +1383 -1392
- package/lib/{esm/charts/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.js} +13 -5
- package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.js +46 -0
- package/lib/{esm/charts/tests/ChartWrapperWithTooltipFormatter.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.js} +12 -13
- package/lib/{esm/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.js} +13 -2
- package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.js +35 -0
- package/lib/{esm/charts/utils/chart-types.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.js} +10 -2
- package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.js +37 -0
- package/lib/cjs/_virtual/_rolldown/runtime.js +44 -0
- package/lib/cjs/charts/Chart.js +121 -111
- package/lib/cjs/charts/Chart.js.map +1 -1
- package/lib/cjs/charts/ChartContainer.js +67 -62
- package/lib/cjs/charts/ChartContainer.js.map +1 -1
- package/lib/cjs/charts/ChartEmpty.js +45 -30
- package/lib/cjs/charts/ChartEmpty.js.map +1 -1
- package/lib/cjs/charts/ChartRender.js +112 -87
- package/lib/cjs/charts/ChartRender.js.map +1 -1
- package/lib/cjs/charts/ChartTooltip.js +111 -65
- package/lib/cjs/charts/ChartTooltip.js.map +1 -1
- package/lib/cjs/charts/Legend.js +81 -69
- package/lib/cjs/charts/Legend.js.map +1 -1
- package/lib/cjs/charts/LegendItem.js +83 -62
- package/lib/cjs/charts/LegendItem.js.map +1 -1
- package/lib/cjs/charts/LegendLayout.js +330 -348
- package/lib/cjs/charts/LegendLayout.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-instance.js +115 -122
- package/lib/cjs/charts/hooks/use-chart-instance.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-option.js +79 -80
- package/lib/cjs/charts/hooks/use-chart-option.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-refs.js +47 -44
- package/lib/cjs/charts/hooks/use-chart-refs.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-zoom.js +102 -127
- package/lib/cjs/charts/hooks/use-chart-zoom.js.map +1 -1
- package/lib/cjs/charts/hooks/use-legend-interactions.js +127 -132
- package/lib/cjs/charts/hooks/use-legend-interactions.js.map +1 -1
- package/lib/cjs/charts/hooks/use-legend-series.js +143 -174
- package/lib/cjs/charts/hooks/use-legend-series.js.map +1 -1
- package/lib/cjs/charts/hooks/use-legend-visibility.js +66 -85
- package/lib/cjs/charts/hooks/use-legend-visibility.js.map +1 -1
- package/lib/cjs/charts/index.js +31 -40
- package/lib/cjs/charts/index.js.map +1 -1
- package/lib/cjs/charts/themes/ndl-echarts-theme.js +136 -168
- package/lib/cjs/charts/themes/ndl-echarts-theme.js.map +1 -1
- package/lib/cjs/charts/utils/aria-description.js +150 -214
- package/lib/cjs/charts/utils/aria-description.js.map +1 -1
- package/lib/cjs/charts/utils/build-chart-option.js +166 -174
- package/lib/cjs/charts/utils/build-chart-option.js.map +1 -1
- package/lib/cjs/charts/utils/chart-tooltip-formatter.js +156 -172
- package/lib/cjs/charts/utils/chart-tooltip-formatter.js.map +1 -1
- package/lib/cjs/charts/utils/chart-types.js +25 -20
- package/lib/cjs/charts/utils/chart-types.js.map +1 -1
- package/lib/cjs/charts/utils/defaults.js +69 -67
- package/lib/cjs/charts/utils/defaults.js.map +1 -1
- package/lib/cjs/charts/utils/format-utils.js +55 -66
- package/lib/cjs/charts/utils/format-utils.js.map +1 -1
- package/lib/cjs/charts/utils/legend-layout.js +54 -53
- package/lib/cjs/charts/utils/legend-layout.js.map +1 -1
- package/lib/cjs/charts/utils/legend-utils.js +82 -121
- package/lib/cjs/charts/utils/legend-utils.js.map +1 -1
- package/lib/cjs/charts/utils/scatter-tooltip-points.js +191 -266
- package/lib/cjs/charts/utils/scatter-tooltip-points.js.map +1 -1
- package/lib/cjs/charts/utils/threshold.js +89 -102
- package/lib/cjs/charts/utils/threshold.js.map +1 -1
- package/lib/cjs/charts/utils/user-option-utils.js +419 -347
- package/lib/cjs/charts/utils/user-option-utils.js.map +1 -1
- package/lib/cjs/index.js +31 -35
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.mjs +11 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs +24 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.mjs +12 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.mjs +11 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.mjs +13 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.mjs +8 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.mjs +10 -0
- package/lib/esm/charts/Chart.mjs +123 -0
- package/lib/esm/charts/Chart.mjs.map +1 -0
- package/lib/esm/charts/ChartContainer.mjs +71 -0
- package/lib/esm/charts/ChartContainer.mjs.map +1 -0
- package/lib/esm/charts/ChartEmpty.mjs +46 -0
- package/lib/esm/charts/ChartEmpty.mjs.map +1 -0
- package/lib/esm/charts/ChartRender.mjs +113 -0
- package/lib/esm/charts/ChartRender.mjs.map +1 -0
- package/lib/esm/charts/ChartTooltip.mjs +109 -0
- package/lib/esm/charts/ChartTooltip.mjs.map +1 -0
- package/lib/esm/charts/Legend.mjs +82 -0
- package/lib/esm/charts/Legend.mjs.map +1 -0
- package/lib/esm/charts/LegendItem.mjs +82 -0
- package/lib/esm/charts/LegendItem.mjs.map +1 -0
- package/lib/esm/charts/LegendLayout.mjs +337 -0
- package/lib/esm/charts/LegendLayout.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-instance.mjs +119 -0
- package/lib/esm/charts/hooks/use-chart-instance.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-option.mjs +79 -0
- package/lib/esm/charts/hooks/use-chart-option.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-refs.mjs +49 -0
- package/lib/esm/charts/hooks/use-chart-refs.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-zoom.mjs +102 -0
- package/lib/esm/charts/hooks/use-chart-zoom.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-legend-interactions.mjs +138 -0
- package/lib/esm/charts/hooks/use-legend-interactions.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-legend-series.mjs +151 -0
- package/lib/esm/charts/hooks/use-legend-series.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-legend-visibility.mjs +67 -0
- package/lib/esm/charts/hooks/use-legend-visibility.mjs.map +1 -0
- package/lib/esm/charts/index.mjs +27 -0
- package/lib/esm/charts/index.mjs.map +1 -0
- package/lib/esm/charts/themes/ndl-echarts-theme.mjs +139 -0
- package/lib/esm/charts/themes/ndl-echarts-theme.mjs.map +1 -0
- package/lib/esm/charts/utils/aria-description.mjs +162 -0
- package/lib/esm/charts/utils/aria-description.mjs.map +1 -0
- package/lib/esm/charts/utils/build-chart-option.mjs +184 -0
- package/lib/esm/charts/utils/build-chart-option.mjs.map +1 -0
- package/lib/esm/charts/utils/chart-tooltip-formatter.mjs +159 -0
- package/lib/esm/charts/utils/chart-tooltip-formatter.mjs.map +1 -0
- package/lib/esm/charts/utils/chart-types.mjs +24 -0
- package/lib/esm/charts/utils/chart-types.mjs.map +1 -0
- package/lib/esm/charts/utils/defaults.mjs +73 -0
- package/lib/esm/charts/utils/defaults.mjs.map +1 -0
- package/lib/esm/charts/utils/format-utils.mjs +61 -0
- package/lib/esm/charts/utils/format-utils.mjs.map +1 -0
- package/lib/esm/charts/utils/legend-layout.mjs +57 -0
- package/lib/esm/charts/utils/legend-layout.mjs.map +1 -0
- package/lib/esm/charts/utils/legend-utils.mjs +90 -0
- package/lib/esm/charts/utils/legend-utils.mjs.map +1 -0
- package/lib/esm/charts/utils/scatter-tooltip-points.mjs +215 -0
- package/lib/esm/charts/utils/scatter-tooltip-points.mjs.map +1 -0
- package/lib/esm/charts/utils/threshold.mjs +92 -0
- package/lib/esm/charts/utils/threshold.mjs.map +1 -0
- package/lib/esm/charts/utils/user-option-utils.mjs +445 -0
- package/lib/esm/charts/utils/user-option-utils.mjs.map +1 -0
- package/lib/esm/index.mjs +27 -0
- package/lib/esm/index.mjs.map +1 -0
- package/package.json +12 -16
- package/skills/ndl-react-charts/SKILL.md +2 -2
- package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js +0 -38
- package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
- package/lib/cjs/charts/tests/ChartZoomHarness.js +0 -113
- package/lib/cjs/charts/tests/ChartZoomHarness.js.map +0 -1
- package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js +0 -78
- package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
- package/lib/cjs/charts/tests/PieChartWithRerender.js +0 -46
- package/lib/cjs/charts/tests/PieChartWithRerender.js.map +0 -1
- package/lib/cjs/charts/tests/chart-test-utils.js +0 -527
- package/lib/cjs/charts/tests/chart-test-utils.js.map +0 -1
- package/lib/esm/charts/Chart.js +0 -114
- package/lib/esm/charts/Chart.js.map +0 -1
- package/lib/esm/charts/ChartContainer.js +0 -67
- package/lib/esm/charts/ChartContainer.js.map +0 -1
- package/lib/esm/charts/ChartEmpty.js +0 -33
- package/lib/esm/charts/ChartEmpty.js.map +0 -1
- package/lib/esm/charts/ChartRender.js +0 -89
- package/lib/esm/charts/ChartRender.js.map +0 -1
- package/lib/esm/charts/ChartTooltip.js +0 -64
- package/lib/esm/charts/ChartTooltip.js.map +0 -1
- package/lib/esm/charts/Legend.js +0 -71
- package/lib/esm/charts/Legend.js.map +0 -1
- package/lib/esm/charts/LegendItem.js +0 -61
- package/lib/esm/charts/LegendItem.js.map +0 -1
- package/lib/esm/charts/LegendLayout.js +0 -323
- package/lib/esm/charts/LegendLayout.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-instance.js +0 -128
- package/lib/esm/charts/hooks/use-chart-instance.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-option.js +0 -82
- package/lib/esm/charts/hooks/use-chart-option.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-refs.js +0 -48
- package/lib/esm/charts/hooks/use-chart-refs.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-zoom.js +0 -129
- package/lib/esm/charts/hooks/use-chart-zoom.js.map +0 -1
- package/lib/esm/charts/hooks/use-legend-interactions.js +0 -145
- package/lib/esm/charts/hooks/use-legend-interactions.js.map +0 -1
- package/lib/esm/charts/hooks/use-legend-series.js +0 -184
- package/lib/esm/charts/hooks/use-legend-series.js.map +0 -1
- package/lib/esm/charts/hooks/use-legend-visibility.js +0 -87
- package/lib/esm/charts/hooks/use-legend-visibility.js.map +0 -1
- package/lib/esm/charts/index.js.map +0 -1
- package/lib/esm/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
- package/lib/esm/charts/tests/ChartZoomHarness.js +0 -109
- package/lib/esm/charts/tests/ChartZoomHarness.js.map +0 -1
- package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js +0 -74
- package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
- package/lib/esm/charts/tests/PieChartWithRerender.js +0 -43
- package/lib/esm/charts/tests/PieChartWithRerender.js.map +0 -1
- package/lib/esm/charts/tests/chart-test-utils.js +0 -500
- package/lib/esm/charts/tests/chart-test-utils.js.map +0 -1
- package/lib/esm/charts/themes/ndl-echarts-theme.js +0 -172
- package/lib/esm/charts/themes/ndl-echarts-theme.js.map +0 -1
- package/lib/esm/charts/utils/aria-description.js +0 -228
- package/lib/esm/charts/utils/aria-description.js.map +0 -1
- package/lib/esm/charts/utils/build-chart-option.js +0 -193
- package/lib/esm/charts/utils/build-chart-option.js.map +0 -1
- package/lib/esm/charts/utils/chart-tooltip-formatter.js +0 -177
- package/lib/esm/charts/utils/chart-tooltip-formatter.js.map +0 -1
- package/lib/esm/charts/utils/chart-types.js.map +0 -1
- package/lib/esm/charts/utils/defaults.js +0 -73
- package/lib/esm/charts/utils/defaults.js.map +0 -1
- package/lib/esm/charts/utils/format-utils.js +0 -74
- package/lib/esm/charts/utils/format-utils.js.map +0 -1
- package/lib/esm/charts/utils/legend-layout.js +0 -59
- package/lib/esm/charts/utils/legend-layout.js.map +0 -1
- package/lib/esm/charts/utils/legend-utils.js +0 -131
- package/lib/esm/charts/utils/legend-utils.js.map +0 -1
- package/lib/esm/charts/utils/scatter-tooltip-points.js +0 -291
- package/lib/esm/charts/utils/scatter-tooltip-points.js.map +0 -1
- package/lib/esm/charts/utils/threshold.js +0 -106
- package/lib/esm/charts/utils/threshold.js.map +0 -1
- package/lib/esm/charts/utils/user-option-utils.js +0 -374
- package/lib/esm/charts/utils/user-option-utils.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { tokens } from "@neo4j-ndl/base";
|
|
2
|
+
// src/charts/themes/ndl-echarts-theme.ts
|
|
3
|
+
/*!
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) "Neo4j"
|
|
6
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Neo4j.
|
|
9
|
+
*
|
|
10
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
*/
|
|
23
|
+
const axisCommon = (theme) => ({
|
|
24
|
+
axisLabel: {
|
|
25
|
+
color: tokens.theme[theme].color.neutral.text.weaker,
|
|
26
|
+
fontFamily: tokens.typography["body-small"].fontFamily,
|
|
27
|
+
fontSize: tokens.typography["body-small"].fontSize
|
|
28
|
+
},
|
|
29
|
+
nameGap: 8,
|
|
30
|
+
nameMoveOverlap: true,
|
|
31
|
+
nameTextStyle: {
|
|
32
|
+
color: tokens.theme[theme].color.neutral.text.default,
|
|
33
|
+
fontFamily: tokens.typography["body-medium"].fontFamily,
|
|
34
|
+
fontSize: tokens.typography["body-medium"].fontSize,
|
|
35
|
+
fontWeight: tokens.typography["body-medium"].fontWeight,
|
|
36
|
+
lineHeight: tokens.typography["body-medium"].lineHeight
|
|
37
|
+
},
|
|
38
|
+
axisLine: { lineStyle: {
|
|
39
|
+
cap: "square",
|
|
40
|
+
color: tokens.theme[theme].color.neutral.border.strong,
|
|
41
|
+
width: 2
|
|
42
|
+
} },
|
|
43
|
+
axisTick: {
|
|
44
|
+
length: 8,
|
|
45
|
+
lineStyle: {
|
|
46
|
+
color: tokens.theme[theme].color.neutral.border.strong,
|
|
47
|
+
width: 1
|
|
48
|
+
},
|
|
49
|
+
show: true
|
|
50
|
+
},
|
|
51
|
+
minorSplitLine: { lineStyle: { color: tokens.theme[theme].color.neutral.border.weak } },
|
|
52
|
+
splitArea: { areaStyle: { color: [tokens.theme[theme].color.neutral.hover, "transparent"] } },
|
|
53
|
+
splitLine: { lineStyle: { color: tokens.theme[theme].color.neutral.border.weak } }
|
|
54
|
+
});
|
|
55
|
+
const ndlEchartsTheme = (theme, palette) => {
|
|
56
|
+
return {
|
|
57
|
+
darkMode: theme === "dark",
|
|
58
|
+
color: palette !== null && palette !== void 0 ? palette : Object.values(tokens.categorical),
|
|
59
|
+
backgroundColor: "transparent",
|
|
60
|
+
axisPointer: {
|
|
61
|
+
crossStyle: { color: tokens.theme[theme].color.neutral.border.strong },
|
|
62
|
+
label: { color: tokens.theme[theme].color.neutral.text.weaker },
|
|
63
|
+
lineStyle: { color: tokens.theme[theme].color.neutral.border.strong }
|
|
64
|
+
},
|
|
65
|
+
legend: {},
|
|
66
|
+
textStyle: { color: tokens.theme[theme].color.neutral.text.weaker },
|
|
67
|
+
title: {},
|
|
68
|
+
toolbox: {},
|
|
69
|
+
dataZoom: {
|
|
70
|
+
backgroundColor: "transparent",
|
|
71
|
+
borderColor: tokens.theme[theme].color.neutral.border.weak,
|
|
72
|
+
borderRadius: parseInt(tokens.borderRadius.sm.replace("px", "")),
|
|
73
|
+
dataBackground: {
|
|
74
|
+
areaStyle: {
|
|
75
|
+
color: tokens.theme[theme].color.neutral.bg.default,
|
|
76
|
+
opacity: 1
|
|
77
|
+
},
|
|
78
|
+
lineStyle: {
|
|
79
|
+
color: tokens.theme[theme].color.neutral.border.weak,
|
|
80
|
+
opacity: 1,
|
|
81
|
+
width: 1
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
emphasis: {
|
|
85
|
+
handleLabel: {},
|
|
86
|
+
handleStyle: {
|
|
87
|
+
borderColor: tokens.theme[theme].color.neutral.border.strong,
|
|
88
|
+
color: tokens.theme[theme].color.neutral.bg.strong,
|
|
89
|
+
opacity: 1
|
|
90
|
+
},
|
|
91
|
+
moveHandleStyle: {
|
|
92
|
+
borderColor: tokens.theme[theme].color.neutral.border.strong,
|
|
93
|
+
color: tokens.theme[theme].color.neutral.border.strong,
|
|
94
|
+
opacity: 1
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
fillerColor: `rgb( from ${tokens.theme[theme].color.neutral.hover} r g b / 0.1)`,
|
|
98
|
+
handleIcon: "M2 0.5h4s1.5 0 1.5 1.5v16s0 1.5 -1.5 1.5h-4s-1.5 0 -1.5 -1.5v-16s0 -1.5 1.5 -1.5",
|
|
99
|
+
handleSize: "80%",
|
|
100
|
+
handleStyle: {
|
|
101
|
+
borderColor: tokens.theme[theme].color.neutral.border.strong,
|
|
102
|
+
color: tokens.theme[theme].color.neutral.bg.weak
|
|
103
|
+
},
|
|
104
|
+
moveHandleSize: 6,
|
|
105
|
+
moveHandleStyle: {
|
|
106
|
+
backgroundColor: tokens.theme[theme].color.neutral.bg.strong,
|
|
107
|
+
color: tokens.theme[theme].color.neutral.bg.strong,
|
|
108
|
+
opacity: 1
|
|
109
|
+
},
|
|
110
|
+
selectedDataBackground: {
|
|
111
|
+
areaStyle: {
|
|
112
|
+
color: tokens.theme[theme].color.neutral.bg["on-bg-weak"],
|
|
113
|
+
opacity: 1,
|
|
114
|
+
shadowBlur: 0
|
|
115
|
+
},
|
|
116
|
+
lineStyle: {
|
|
117
|
+
color: tokens.theme[theme].color.neutral.border.strong,
|
|
118
|
+
opacity: 1,
|
|
119
|
+
width: 1
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
textStyle: { color: tokens.theme[theme].color.neutral.text.weaker }
|
|
123
|
+
},
|
|
124
|
+
visualMap: {},
|
|
125
|
+
timeline: {},
|
|
126
|
+
calendar: {},
|
|
127
|
+
timeAxis: axisCommon(theme),
|
|
128
|
+
logAxis: axisCommon(theme),
|
|
129
|
+
valueAxis: axisCommon(theme),
|
|
130
|
+
categoryAxis: axisCommon(theme),
|
|
131
|
+
line: { symbol: "circle" },
|
|
132
|
+
graph: {},
|
|
133
|
+
gauge: {},
|
|
134
|
+
candlestick: {}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export { ndlEchartsTheme };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=ndl-echarts-theme.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ndl-echarts-theme.mjs","names":[],"sources":["../../../../src/charts/themes/ndl-echarts-theme.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n// oxlint-disable sort-keys\nimport { tokens } from '@neo4j-ndl/base';\n\nimport { type HexColor } from '../utils/chart-types';\n\nconst axisCommon = (theme: 'light' | 'dark') => ({\n axisLabel: {\n color: tokens.theme[theme].color.neutral.text.weaker,\n fontFamily: tokens.typography['body-small'].fontFamily,\n fontSize: tokens.typography['body-small'].fontSize,\n },\n nameGap: 8,\n nameMoveOverlap: true,\n nameTextStyle: {\n color: tokens.theme[theme].color.neutral.text.default,\n fontFamily: tokens.typography['body-medium'].fontFamily,\n fontSize: tokens.typography['body-medium'].fontSize,\n fontWeight: tokens.typography['body-medium'].fontWeight,\n lineHeight: tokens.typography['body-medium'].lineHeight,\n },\n axisLine: {\n lineStyle: {\n cap: 'square',\n color: tokens.theme[theme].color.neutral.border.strong,\n width: 2,\n },\n },\n axisTick: {\n length: 8,\n lineStyle: {\n color: tokens.theme[theme].color.neutral.border.strong,\n width: 1,\n },\n show: true,\n },\n minorSplitLine: {\n lineStyle: {\n color: tokens.theme[theme].color.neutral.border.weak,\n },\n },\n splitArea: {\n areaStyle: {\n color: [tokens.theme[theme].color.neutral.hover, 'transparent'],\n },\n },\n splitLine: {\n lineStyle: {\n color: tokens.theme[theme].color.neutral.border.weak,\n },\n },\n});\n\nexport const ndlEchartsTheme = (\n theme: 'light' | 'dark',\n palette?: HexColor[],\n) => {\n return {\n darkMode: theme === 'dark',\n color: palette ?? Object.values(tokens.categorical),\n backgroundColor: 'transparent',\n\n axisPointer: {\n crossStyle: {\n color: tokens.theme[theme].color.neutral.border.strong,\n },\n label: {\n color: tokens.theme[theme].color.neutral.text.weaker,\n },\n lineStyle: {\n color: tokens.theme[theme].color.neutral.border.strong,\n },\n },\n // We use a custom legend so this does not affect anything\n legend: {},\n textStyle: {\n color: tokens.theme[theme].color.neutral.text.weaker,\n },\n // We are not using the echarts title so this does not affect anything\n title: {},\n toolbox: {},\n\n dataZoom: {\n backgroundColor: 'transparent',\n borderColor: tokens.theme[theme].color.neutral.border.weak,\n borderRadius: parseInt(tokens.borderRadius.sm.replace('px', '')),\n dataBackground: {\n areaStyle: {\n color: tokens.theme[theme].color.neutral.bg.default,\n opacity: 1,\n },\n lineStyle: {\n color: tokens.theme[theme].color.neutral.border.weak,\n opacity: 1,\n width: 1,\n },\n },\n emphasis: {\n handleLabel: {},\n handleStyle: {\n borderColor: tokens.theme[theme].color.neutral.border.strong,\n color: tokens.theme[theme].color.neutral.bg.strong,\n opacity: 1,\n },\n moveHandleStyle: {\n borderColor: tokens.theme[theme].color.neutral.border.strong,\n color: tokens.theme[theme].color.neutral.border.strong,\n opacity: 1,\n },\n },\n fillerColor: `rgb( from ${tokens.theme[theme].color.neutral.hover} r g b / 0.1)`,\n handleIcon:\n 'M2 0.5h4s1.5 0 1.5 1.5v16s0 1.5 -1.5 1.5h-4s-1.5 0 -1.5 -1.5v-16s0 -1.5 1.5 -1.5',\n handleSize: '80%',\n handleStyle: {\n borderColor: tokens.theme[theme].color.neutral.border.strong,\n color: tokens.theme[theme].color.neutral.bg.weak,\n\n // borderRadius: 0, // Doesn't work\n },\n moveHandleSize: 6,\n moveHandleStyle: {\n backgroundColor: tokens.theme[theme].color.neutral.bg.strong,\n color: tokens.theme[theme].color.neutral.bg.strong,\n opacity: 1, // 0.3,\n },\n selectedDataBackground: {\n areaStyle: {\n color: tokens.theme[theme].color.neutral.bg['on-bg-weak'],\n opacity: 1,\n shadowBlur: 0,\n },\n lineStyle: {\n color: tokens.theme[theme].color.neutral.border.strong,\n opacity: 1,\n width: 1,\n },\n },\n textStyle: {\n color: tokens.theme[theme].color.neutral.text.weaker,\n },\n },\n // Not implemented\n visualMap: {},\n // Not implemented\n timeline: {},\n // Not implemented\n calendar: {},\n timeAxis: axisCommon(theme),\n logAxis: axisCommon(theme),\n valueAxis: axisCommon(theme),\n categoryAxis: axisCommon(theme),\n line: {\n symbol: 'circle',\n },\n // Not implemented\n graph: {},\n // Not implemented\n gauge: {},\n // Not implemented\n candlestick: {},\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,cAAc,WAA6B;CAC/C,WAAW;EACT,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,KAAK;EAC9C,YAAY,OAAO,WAAW,aAAa,CAAC;EAC5C,UAAU,OAAO,WAAW,aAAa,CAAC;CAC5C;CACA,SAAS;CACT,iBAAiB;CACjB,eAAe;EACb,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,KAAK;EAC9C,YAAY,OAAO,WAAW,cAAc,CAAC;EAC7C,UAAU,OAAO,WAAW,cAAc,CAAC;EAC3C,YAAY,OAAO,WAAW,cAAc,CAAC;EAC7C,YAAY,OAAO,WAAW,cAAc,CAAC;CAC/C;CACA,UAAU,EACR,WAAW;EACT,KAAK;EACL,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,OAAO;EAChD,OAAO;CACT,EACF;CACA,UAAU;EACR,QAAQ;EACR,WAAW;GACT,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,OAAO;GAChD,OAAO;EACT;EACA,MAAM;CACR;CACA,gBAAgB,EACd,WAAW,EACT,OAAO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C5C,SAAS;IACX;IACA,iBAAiB;KACf,aAAa,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,OAAO;KACtD,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,OAAO;KAChD,SAAS;IACX;GACF;GACA,aAAa,aAAa,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,MAAM;GAClE,YACE;GACF,YAAY;GACZ,aAAa;IACX,aAAa,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,OAAO;IACtD,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,GAAG;GAG9C;GACA,gBAAgB;GAChB,iBAAiB;IACf,iBAAiB,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtD,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,GAAG;IAC5C,SAAS;GACX;GACA,wBAAwB;IACtB,WAAW;KACT,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,GAAG;KAC5C,SAAS;KACT,YAAY;IACd;IACA,WAAW;KACT,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,OAAO;KAChD,SAAS;KACT,OAAO;IACT;GACF;GACA,WAAW,EACT,OAAO,OAAO,MAAM,MAAM,CAAC,MAAM,QAAQ,KAAK,OAChD;EACF;EAEA,WAAW,CAAC;EAEZ,UAAU,CAAC;EAEX,UAAU,CAAC;EACX,UAAU,WAAW,KAAK;EAC1B,SAAS,WAAW,KAAK;EACzB,WAAW,WAAW,KAAK;EAC3B,cAAc,WAAW,KAAK;EAC9B,MAAM,EACJ,QAAQ,SACV;EAEA,OAAO,CAAC;EAER,OAAO,CAAC;EAER,aAAa,CAAC;CAChB;AACF"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { defaultThresholdLineSeriesOption } from "./defaults.mjs";
|
|
2
|
+
import { evaluateThresholdCondition, thresholdConditionToText } from "./threshold.mjs";
|
|
3
|
+
// src/charts/utils/aria-description.ts
|
|
4
|
+
/*!
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) "Neo4j"
|
|
7
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
8
|
+
*
|
|
9
|
+
* This file is part of Neo4j.
|
|
10
|
+
*
|
|
11
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* This program is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU General Public License
|
|
22
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Extract numeric y-values from inline series data.
|
|
26
|
+
* Handles formats: [x, y], [x, y, ...], or single number.
|
|
27
|
+
*/
|
|
28
|
+
function extractInlineValues(data, encode) {
|
|
29
|
+
if (!Array.isArray(data)) return [];
|
|
30
|
+
const yIndex = (encode === null || encode === void 0 ? void 0 : encode.y) !== void 0 && typeof encode.y === "number" ? encode.y : 1;
|
|
31
|
+
const values = [];
|
|
32
|
+
for (const point of data) {
|
|
33
|
+
if (point === null || point === void 0) continue;
|
|
34
|
+
if (Array.isArray(point)) {
|
|
35
|
+
const val = point[yIndex];
|
|
36
|
+
if (typeof val === "number" && !isNaN(val)) values.push(val);
|
|
37
|
+
} else if (typeof point === "number" && !isNaN(point)) values.push(point);
|
|
38
|
+
else if (typeof point === "object" && "value" in point) {
|
|
39
|
+
const val = point.value;
|
|
40
|
+
if (typeof val === "number" && !isNaN(val)) values.push(val);
|
|
41
|
+
else if (Array.isArray(val)) {
|
|
42
|
+
const yValue = val[yIndex];
|
|
43
|
+
if (typeof yValue === "number" && !isNaN(yValue)) values.push(yValue);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return values;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Extract numeric y-values from a dataset source for a given series.
|
|
51
|
+
*/
|
|
52
|
+
function extractDatasetValues(dataset, series) {
|
|
53
|
+
if (!dataset) return [];
|
|
54
|
+
const currentDataset = (Array.isArray(dataset) ? dataset : [dataset])["datasetIndex" in series && typeof series.datasetIndex === "number" ? series.datasetIndex : 0];
|
|
55
|
+
if (!currentDataset || !Array.isArray(currentDataset.source)) return [];
|
|
56
|
+
const source = currentDataset.source;
|
|
57
|
+
if (source.length < 1) return [];
|
|
58
|
+
const dimensions = currentDataset.dimensions;
|
|
59
|
+
let columnNames;
|
|
60
|
+
let dataStartIndex;
|
|
61
|
+
if (Array.isArray(dimensions) && dimensions.length > 0) {
|
|
62
|
+
columnNames = dimensions.map((dimension) => typeof dimension === "string" ? dimension : dimension.name);
|
|
63
|
+
dataStartIndex = 0;
|
|
64
|
+
} else {
|
|
65
|
+
const headerRow = source[0];
|
|
66
|
+
if (!Array.isArray(headerRow) || source.length < 2) return [];
|
|
67
|
+
columnNames = headerRow;
|
|
68
|
+
dataStartIndex = 1;
|
|
69
|
+
}
|
|
70
|
+
const encode = "encode" in series ? series.encode : void 0;
|
|
71
|
+
let yColumnIndex = -1;
|
|
72
|
+
if ((encode === null || encode === void 0 ? void 0 : encode.y) !== void 0) {
|
|
73
|
+
if (typeof encode.y === "number") yColumnIndex = encode.y;
|
|
74
|
+
else if (typeof encode.y === "string") yColumnIndex = columnNames.indexOf(encode.y);
|
|
75
|
+
}
|
|
76
|
+
if (yColumnIndex === -1) return [];
|
|
77
|
+
const values = [];
|
|
78
|
+
for (let rowIndex = dataStartIndex; rowIndex < source.length; rowIndex++) {
|
|
79
|
+
const row = source[rowIndex];
|
|
80
|
+
if (!Array.isArray(row)) continue;
|
|
81
|
+
const val = row[yColumnIndex];
|
|
82
|
+
if (typeof val === "number" && !isNaN(val)) values.push(val);
|
|
83
|
+
}
|
|
84
|
+
return values;
|
|
85
|
+
}
|
|
86
|
+
function pluralize(count, singular, plural) {
|
|
87
|
+
return count === 1 ? singular : plural !== null && plural !== void 0 ? plural : `${singular}s`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Resolves y-values for a series from either inline data or a dataset.
|
|
91
|
+
*/
|
|
92
|
+
function resolveSeriesValues(series, dataset) {
|
|
93
|
+
if ("data" in series && series.data) {
|
|
94
|
+
const encode = "encode" in series ? series.encode : void 0;
|
|
95
|
+
return extractInlineValues(series.data, encode);
|
|
96
|
+
}
|
|
97
|
+
return extractDatasetValues(dataset, series);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generates a human-readable aria-label description for the chart
|
|
101
|
+
* that includes meaningful threshold context and data relationships.
|
|
102
|
+
*/
|
|
103
|
+
function generateThresholdAriaDescription(propsSeries, dataset) {
|
|
104
|
+
const seriesArray = Array.isArray(propsSeries) ? propsSeries : [propsSeries];
|
|
105
|
+
const thresholds = [];
|
|
106
|
+
const dataSeries = [];
|
|
107
|
+
for (const series of seriesArray) if (series.type === "thresholdLine") {
|
|
108
|
+
var _threshold$condition;
|
|
109
|
+
const threshold = series;
|
|
110
|
+
thresholds.push({
|
|
111
|
+
condition: (_threshold$condition = threshold.condition) !== null && _threshold$condition !== void 0 ? _threshold$condition : defaultThresholdLineSeriesOption.condition,
|
|
112
|
+
customConditionText: threshold.customConditionText,
|
|
113
|
+
hasCustomCondition: typeof threshold.customCondition === "function",
|
|
114
|
+
notificationType: threshold.notificationType,
|
|
115
|
+
yAxisValue: threshold.yAxis
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
var _echartsSeriesOption$;
|
|
119
|
+
const echartsSeriesOption = series;
|
|
120
|
+
const name = typeof echartsSeriesOption.name === "string" ? echartsSeriesOption.name : `Series ${dataSeries.length + 1}`;
|
|
121
|
+
const values = resolveSeriesValues(echartsSeriesOption, dataset);
|
|
122
|
+
dataSeries.push({
|
|
123
|
+
name,
|
|
124
|
+
type: (_echartsSeriesOption$ = echartsSeriesOption.type) !== null && _echartsSeriesOption$ !== void 0 ? _echartsSeriesOption$ : "line",
|
|
125
|
+
values
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (thresholds.length === 0) return;
|
|
129
|
+
const parts = [];
|
|
130
|
+
const dataSeriesCountText = dataSeries.length === 1 ? "1 data series" : `${dataSeries.length} data series`;
|
|
131
|
+
const thresholdCountText = thresholds.length === 1 ? "1 threshold line" : `${thresholds.length} threshold lines`;
|
|
132
|
+
parts.push(`This chart has ${dataSeriesCountText} and ${thresholdCountText}.`);
|
|
133
|
+
for (const series of dataSeries) {
|
|
134
|
+
const { name, type, values } = series;
|
|
135
|
+
if (values.length > 0) {
|
|
136
|
+
const min = Math.min(...values);
|
|
137
|
+
const max = Math.max(...values);
|
|
138
|
+
parts.push(`${name} is a ${type} chart with ${values.length} ${pluralize(values.length, "data point")} ranging from ${min} to ${max}.`);
|
|
139
|
+
} else parts.push(`${name} is a ${type} chart with no resolved data.`);
|
|
140
|
+
}
|
|
141
|
+
for (const threshold of thresholds) {
|
|
142
|
+
var _threshold$customCond;
|
|
143
|
+
const conditionText = threshold.hasCustomCondition ? (_threshold$customCond = threshold.customConditionText) !== null && _threshold$customCond !== void 0 ? _threshold$customCond : "custom condition" : thresholdConditionToText(threshold.condition);
|
|
144
|
+
parts.push(`${threshold.notificationType === "warning" ? "Warning" : "Danger"} threshold at ${threshold.yAxisValue}: triggers when values are ${conditionText} ${threshold.yAxisValue}.`);
|
|
145
|
+
}
|
|
146
|
+
for (const series of dataSeries) {
|
|
147
|
+
const { name, values } = series;
|
|
148
|
+
if (values.length === 0) continue;
|
|
149
|
+
for (const threshold of thresholds) {
|
|
150
|
+
if (threshold.hasCustomCondition) continue;
|
|
151
|
+
const violatingValues = values.filter((value) => evaluateThresholdCondition(value, threshold.condition, threshold.yAxisValue).isConditionMet);
|
|
152
|
+
if (violatingValues.length > 0) {
|
|
153
|
+
const count = violatingValues.length;
|
|
154
|
+
parts.push(`${name} has ${count} ${pluralize(count, "value")} ${thresholdConditionToText(threshold.condition)} the ${threshold.notificationType} threshold of ${threshold.yAxisValue}.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return parts.join(" ");
|
|
159
|
+
}
|
|
160
|
+
export { generateThresholdAriaDescription };
|
|
161
|
+
|
|
162
|
+
//# sourceMappingURL=aria-description.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aria-description.mjs","names":[],"sources":["../../../../src/charts/utils/aria-description.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { EChartsOption, SeriesOption } from 'echarts';\n\nimport type {\n Condition,\n NeedleSeries,\n NotificationType,\n ThresholdLineSeriesOption,\n} from './chart-types';\nimport { defaultThresholdLineSeriesOption } from './defaults';\nimport {\n evaluateThresholdCondition,\n thresholdConditionToText,\n} from './threshold';\n\ninterface ResolvedDataSeries {\n name: string;\n type: string;\n values: number[];\n}\n\ninterface ResolvedThreshold {\n notificationType: NotificationType;\n yAxisValue: number;\n condition: Condition;\n hasCustomCondition: boolean;\n customConditionText?: string;\n}\n\n/**\n * Extract numeric y-values from inline series data.\n * Handles formats: [x, y], [x, y, ...], or single number.\n */\nfunction extractInlineValues(\n data: SeriesOption['data'],\n encode?: {\n // E-Charts uses encode.x and encode.y - https://echarts.apache.org/en/option.html#series-line.encode\n // oxlint-disable-next-line id-length\n x?: string | number;\n // oxlint-disable-next-line id-length\n y?: string | number;\n },\n): number[] {\n if (!Array.isArray(data)) {\n return [];\n }\n\n const yIndex =\n encode?.y !== undefined && typeof encode.y === 'number' ? encode.y : 1;\n\n const values: number[] = [];\n for (const point of data) {\n if (point === null || point === undefined) {\n continue;\n }\n if (Array.isArray(point)) {\n const val = point[yIndex];\n if (typeof val === 'number' && !isNaN(val)) {\n values.push(val);\n }\n } else if (typeof point === 'number' && !isNaN(point)) {\n values.push(point);\n } else if (typeof point === 'object' && 'value' in point) {\n const val = point.value;\n if (typeof val === 'number' && !isNaN(val)) {\n values.push(val);\n } else if (Array.isArray(val)) {\n const yValue = val[yIndex];\n if (typeof yValue === 'number' && !isNaN(yValue)) {\n values.push(yValue);\n }\n }\n }\n }\n return values;\n}\n\n/**\n * Extract numeric y-values from a dataset source for a given series.\n */\nfunction extractDatasetValues(\n dataset: EChartsOption['dataset'],\n series: SeriesOption,\n): number[] {\n if (!dataset) {\n return [];\n }\n\n const datasets = Array.isArray(dataset) ? dataset : [dataset];\n const datasetIndex =\n 'datasetIndex' in series && typeof series.datasetIndex === 'number'\n ? series.datasetIndex\n : 0;\n const currentDataset = datasets[datasetIndex];\n\n if (!currentDataset || !Array.isArray(currentDataset.source)) {\n return [];\n }\n\n const source = currentDataset.source as (string | number)[][];\n if (source.length < 1) {\n return [];\n }\n\n // Determine column names and data start index.\n // When `dimensions` is provided, column names come from there and all\n // rows in `source` are data. Otherwise the first row is a header.\n const dimensions = currentDataset.dimensions as\n | (string | { name: string })[]\n | undefined;\n let columnNames: (string | number)[];\n let dataStartIndex: number;\n\n if (Array.isArray(dimensions) && dimensions.length > 0) {\n columnNames = dimensions.map((dimension) =>\n typeof dimension === 'string' ? dimension : dimension.name,\n );\n dataStartIndex = 0;\n } else {\n const headerRow = source[0];\n if (!Array.isArray(headerRow) || source.length < 2) {\n return [];\n }\n columnNames = headerRow;\n dataStartIndex = 1;\n }\n\n // Determine which column contains the y-values\n const encode =\n 'encode' in series ? (series.encode as Record<string, unknown>) : undefined;\n let yColumnIndex = -1;\n\n if (encode?.y !== undefined) {\n if (typeof encode.y === 'number') {\n yColumnIndex = encode.y;\n } else if (typeof encode.y === 'string') {\n yColumnIndex = columnNames.indexOf(encode.y);\n }\n }\n\n if (yColumnIndex === -1) {\n // Avoid guessing a data column for aria descriptions.\n // If we cannot resolve a value column explicitly, return no values.\n return [];\n }\n\n const values: number[] = [];\n for (let rowIndex = dataStartIndex; rowIndex < source.length; rowIndex++) {\n const row = source[rowIndex];\n if (!Array.isArray(row)) {\n continue;\n }\n const val = row[yColumnIndex];\n if (typeof val === 'number' && !isNaN(val)) {\n values.push(val);\n }\n }\n\n return values;\n}\n\nfunction pluralize(count: number, singular: string, plural?: string): string {\n return count === 1 ? singular : (plural ?? `${singular}s`);\n}\n\n/**\n * Resolves y-values for a series from either inline data or a dataset.\n */\nfunction resolveSeriesValues(\n series: SeriesOption,\n dataset: EChartsOption['dataset'],\n): number[] {\n if ('data' in series && series.data) {\n const encode =\n 'encode' in series\n ? (series.encode as Record<string, unknown> | undefined)\n : undefined;\n return extractInlineValues(series.data, encode);\n }\n return extractDatasetValues(dataset, series);\n}\n\n/**\n * Generates a human-readable aria-label description for the chart\n * that includes meaningful threshold context and data relationships.\n */\nexport function generateThresholdAriaDescription(\n propsSeries: NeedleSeries,\n dataset: EChartsOption['dataset'],\n): string | undefined {\n const seriesArray = Array.isArray(propsSeries) ? propsSeries : [propsSeries];\n\n // Separate threshold lines from data series\n const thresholds: ResolvedThreshold[] = [];\n const dataSeries: ResolvedDataSeries[] = [];\n\n for (const series of seriesArray) {\n if (series.type === 'thresholdLine') {\n const threshold = series as ThresholdLineSeriesOption<NotificationType>;\n thresholds.push({\n condition:\n threshold.condition ?? defaultThresholdLineSeriesOption.condition,\n customConditionText: threshold.customConditionText,\n hasCustomCondition: typeof threshold.customCondition === 'function',\n notificationType: threshold.notificationType,\n yAxisValue: threshold.yAxis,\n });\n } else {\n const echartsSeriesOption = series as SeriesOption;\n const name =\n typeof echartsSeriesOption.name === 'string'\n ? echartsSeriesOption.name\n : `Series ${dataSeries.length + 1}`;\n\n const values = resolveSeriesValues(echartsSeriesOption, dataset);\n\n dataSeries.push({\n name,\n type: echartsSeriesOption.type ?? 'line',\n values,\n });\n }\n }\n\n if (thresholds.length === 0) {\n return undefined;\n }\n\n const parts: string[] = [];\n\n // 1. Overview\n const dataSeriesCountText =\n dataSeries.length === 1\n ? '1 data series'\n : `${dataSeries.length} data series`;\n const thresholdCountText =\n thresholds.length === 1\n ? '1 threshold line'\n : `${thresholds.length} threshold lines`;\n parts.push(\n `This chart has ${dataSeriesCountText} and ${thresholdCountText}.`,\n );\n\n // 2. Describe each data series\n for (const series of dataSeries) {\n const { name, type, values } = series;\n if (values.length > 0) {\n const min = Math.min(...values);\n const max = Math.max(...values);\n parts.push(\n `${name} is a ${type} chart with ${values.length} ${pluralize(values.length, 'data point')} ranging from ${min} to ${max}.`,\n );\n } else {\n parts.push(`${name} is a ${type} chart with no resolved data.`);\n }\n }\n\n // 3. Describe threshold lines\n for (const threshold of thresholds) {\n const conditionText = threshold.hasCustomCondition\n ? (threshold.customConditionText ?? 'custom condition')\n : thresholdConditionToText(threshold.condition);\n\n parts.push(\n `${threshold.notificationType === 'warning' ? 'Warning' : 'Danger'} threshold at ${threshold.yAxisValue}: triggers when values are ${conditionText} ${threshold.yAxisValue}.`,\n );\n }\n\n // 4. Report threshold violations per data series\n for (const series of dataSeries) {\n const { name, values } = series;\n if (values.length === 0) {\n continue;\n }\n\n for (const threshold of thresholds) {\n // Custom conditions use runtime callbacks that we cannot evaluate\n // at description-generation time, so we skip violation reporting.\n if (threshold.hasCustomCondition) {\n continue;\n }\n\n const violatingValues = values.filter(\n (value) =>\n evaluateThresholdCondition(\n value,\n threshold.condition,\n threshold.yAxisValue,\n ).isConditionMet,\n );\n\n if (violatingValues.length > 0) {\n const count = violatingValues.length;\n parts.push(\n `${name} has ${count} ${pluralize(count, 'value')} ${thresholdConditionToText(threshold.condition)} the ${threshold.notificationType} threshold of ${threshold.yAxisValue}.`,\n );\n }\n }\n }\n\n return parts.join(' ');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAS,oBACP,MACA,QAOU;CACV,IAAI,CAAC,MAAM,QAAQ,IAAI,GACrB,OAAO,CAAC;CAGV,MAAM,UAAA,WAAA,QAAA,WAAA,KAAA,IAAA,KAAA,IACJ,OAAQ,OAAM,KAAA,KAAa,OAAO,OAAO,MAAM,WAAW,OAAO,IAAI;CAEvE,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,SAAS,MAAM;EACxB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC9B;EAEF,IAAI,MAAM,QAAQ,KAAK,GAAG;GACxB,MAAM,MAAM,MAAM;GAClB,IAAI,OAAO,QAAQ,YAAY,CAAC,MAAM,GAAG,GACvC,OAAO,KAAK,GAAG;EAEnB,OAAO,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,KAAK,GAClD,OAAO,KAAK,KAAK;OACZ,IAAI,OAAO,UAAU,YAAY,WAAW,OAAO;GACxD,MAAM,MAAM,MAAM;GAClB,IAAI,OAAO,QAAQ,YAAY,CAAC,MAAM,GAAG,GACvC,OAAO,KAAK,GAAG;QACV,IAAI,MAAM,QAAQ,GAAG,GAAG;IAC7B,MAAM,SAAS,IAAI;IACnB,IAAI,OAAO,WAAW,YAAY,CAAC,MAAM,MAAM,GAC7C,OAAO,KAAK,MAAM;GAEtB;EACF;CACF;CACA,OAAO;AACT;;;;AAKA,SAAS,qBACP,SACA,QACU;CACV,IAAI,CAAC,SACH,OAAO,CAAC;CAQV,MAAM,kBALW,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO,EAAA,CAE1D,kBAAkB,UAAU,OAAO,OAAO,iBAAiB,WACvD,OA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,KAAK,IAAI,GAAG,MAAM;GAC9B,MAAM,KACJ,GAAG,KAAK,QAAQ,KAAK,cAAc,OAAO,OAAO,GAAG,UAAU,OAAO,QAAQ,YAAY,EAAE,gBAAgB,IAAI,MAAM,IAAI,EAC3H;EACF,OACE,MAAM,KAAK,GAAG,KAAK,QAAQ,KAAK,8BAA8B;CAElE;CAGA,KAAK,MAAM,aAAa,YAAY;;EAClC,MAAM,gBAAgB,UAAU,sBAAA,wBAC3B,UAAU,yBAAA,QAAA,0BAAA,KAAA,IAAA,wBAAuB,qBAClC,yBAAyB,UAAU,SAAS;EAEhD,MAAM,KACJ,GAAG,UAAU,qBAAqB,YAAY,YAAY,SAAS,gBAAgB,UAAU,WAAW,6BAA6B,cAAc,GAAG,UAAU,WAAW,EAC7K;CACF;CAGA,KAAK,MAAM,UAAU,YAAY;EAC/B,MAAM,EAAE,MAAM,WAAW;EACzB,IAAI,OAAO,WAAW,GACpB;EAGF,KAAK,MAAM,aAAa,YAAY;GAGlC,IAAI,UAAU,oBACZ;GAGF,MAAM,kBAAkB,OAAO,QAC5B,UACC,2BACE,OACA,UAAU,WACV,UAAU,UACZ,CAAC,CAAC,cACN;GAEA,IAAI,gBAAgB,SAAS,GAAG;IAC9B,MAAM,QAAQ,gBAAgB;IAC9B,MAAM,KACJ,GAAG,KAAK,OAAO,MAAM,GAAG,UAAU,OAAO,OAAO,EAAE,GAAG,yBAAyB,UAAU,SAAS,EAAE,OAAO,UAAU,iBAAiB,gBAAgB,UAAU,WAAW,EAC5K;GACF;EACF;CACF;CAEA,OAAO,MAAM,KAAK,GAAG;AACvB"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { generateThresholdAriaDescription } from "./aria-description.mjs";
|
|
2
|
+
import { createAxisTooltipFormatter, createScatterTooltipFormatter } from "./chart-tooltip-formatter.mjs";
|
|
3
|
+
import { tooltipExtraCssText } from "./defaults.mjs";
|
|
4
|
+
import { isVerticalSlider, mergeToolbox } from "./user-option-utils.mjs";
|
|
5
|
+
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs";
|
|
6
|
+
// src/charts/utils/build-chart-option.ts
|
|
7
|
+
/*!
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) "Neo4j"
|
|
10
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
11
|
+
*
|
|
12
|
+
* This file is part of Neo4j.
|
|
13
|
+
*
|
|
14
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
15
|
+
* it under the terms of the GNU General Public License as published by
|
|
16
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
17
|
+
* (at your option) any later version.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU General Public License
|
|
25
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
const SLIDER_OUTER_BOUND_GAP = 8;
|
|
28
|
+
const SLIDER_OUTER_BOUND_FALLBACK = 60;
|
|
29
|
+
const toDataZoomArray = (dataZoom) => Array.isArray(dataZoom) ? dataZoom : [dataZoom];
|
|
30
|
+
/**
|
|
31
|
+
* Horizontal slider zoom needs extra bottom grid space for ECharts' slider
|
|
32
|
+
* control.
|
|
33
|
+
*/
|
|
34
|
+
function hasHorizontalSliderZoom(dataZoom) {
|
|
35
|
+
return toDataZoomArray(dataZoom).some((dataZoomOption) => (dataZoomOption === null || dataZoomOption === void 0 ? void 0 : dataZoomOption.type) === "slider" && !isVerticalSlider(dataZoomOption));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Vertical slider zoom needs extra right grid space for ECharts' slider
|
|
39
|
+
* control.
|
|
40
|
+
*/
|
|
41
|
+
function hasVerticalSliderZoom(dataZoom) {
|
|
42
|
+
return toDataZoomArray(dataZoom).some((dataZoomOption) => isVerticalSlider(dataZoomOption));
|
|
43
|
+
}
|
|
44
|
+
const getPixelValue = (value) => {
|
|
45
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
46
|
+
if (typeof value !== "string" || !/^-?\d+(?:\.\d+)?px$/.test(value)) return;
|
|
47
|
+
return Number.parseFloat(value);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Reserves the area occupied by bottom-positioned horizontal slider controls.
|
|
51
|
+
*
|
|
52
|
+
* ECharts lays data zoom controls outside the Cartesian grid, so its automatic
|
|
53
|
+
* axis outer bounds do not account for them. Normalized sliders use pixel
|
|
54
|
+
* values; custom percentage-based layouts fall back to the previous 60px
|
|
55
|
+
* reserve because they cannot be resolved without the rendered chart size.
|
|
56
|
+
*/
|
|
57
|
+
function getSliderBottomOuterBound(dataZoom) {
|
|
58
|
+
const sliderOuterBounds = toDataZoomArray(dataZoom).flatMap((option) => {
|
|
59
|
+
const slider = option;
|
|
60
|
+
if ((slider === null || slider === void 0 ? void 0 : slider.type) !== "slider" || isVerticalSlider(slider)) return [];
|
|
61
|
+
const bottom = getPixelValue(slider.bottom);
|
|
62
|
+
const height = getPixelValue(slider.height);
|
|
63
|
+
if (bottom === void 0 || height === void 0) return [SLIDER_OUTER_BOUND_FALLBACK];
|
|
64
|
+
return [bottom + height + SLIDER_OUTER_BOUND_GAP];
|
|
65
|
+
});
|
|
66
|
+
return sliderOuterBounds.length > 0 ? Math.max(...sliderOuterBounds) : void 0;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reserves the area occupied by right-positioned vertical slider controls,
|
|
70
|
+
* mirroring `getSliderBottomOuterBound` for horizontal ones. Normalized
|
|
71
|
+
* sliders use pixel values; custom percentage-based layouts fall back to the
|
|
72
|
+
* 60px reserve because they cannot be resolved without the rendered chart
|
|
73
|
+
* size.
|
|
74
|
+
*/
|
|
75
|
+
function getSliderRightOuterBound(dataZoom) {
|
|
76
|
+
const sliderOuterBounds = toDataZoomArray(dataZoom).flatMap((option) => {
|
|
77
|
+
const slider = option;
|
|
78
|
+
if (!isVerticalSlider(slider)) return [];
|
|
79
|
+
const right = getPixelValue(slider === null || slider === void 0 ? void 0 : slider.right);
|
|
80
|
+
const width = getPixelValue(slider === null || slider === void 0 ? void 0 : slider.width);
|
|
81
|
+
if (right === void 0 || width === void 0) return [SLIDER_OUTER_BOUND_FALLBACK];
|
|
82
|
+
return [right + width + SLIDER_OUTER_BOUND_GAP];
|
|
83
|
+
});
|
|
84
|
+
return sliderOuterBounds.length > 0 ? Math.max(...sliderOuterBounds) : void 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Mark area needs extra top grid space to fit inside the chart.
|
|
88
|
+
*/
|
|
89
|
+
const hasMarkAreaInSeries = (series) => Array.isArray(series) ? series.some((option) => !!option.markArea) : !!series.markArea;
|
|
90
|
+
/**
|
|
91
|
+
* Reads the `name` of the axis at `axisIndex`, which scatter tooltips use to
|
|
92
|
+
* label their x and y rows.
|
|
93
|
+
*/
|
|
94
|
+
function getAxisName(axis, axisIndex = 0) {
|
|
95
|
+
const axisOption = Array.isArray(axis) ? axis[axisIndex] : axisIndex === 0 ? axis : void 0;
|
|
96
|
+
return typeof (axisOption === null || axisOption === void 0 ? void 0 : axisOption.name) === "string" && axisOption.name.length > 0 ? axisOption.name : void 0;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Category x-axes use slightly wider grid padding to avoid clipped labels.
|
|
100
|
+
*/
|
|
101
|
+
function hasCategoryXAxis(xAxis) {
|
|
102
|
+
return Array.isArray(xAxis) ? xAxis.some((axis) => axis.type === "category") : (xAxis === null || xAxis === void 0 ? void 0 : xAxis.type) === "category";
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Builds the ECharts option object from Needle chart props and derived values.
|
|
106
|
+
* Applying the option to an ECharts instance happens in `useChartOption`.
|
|
107
|
+
*/
|
|
108
|
+
function buildChartOption({ dataZoom, dataset, getChartInstance, getLegendSelected, hasCategoryXAxis, legendSelected, propsSeries, series, thresholdLines, toolboxOptions, userOption, xAxis, yAxis, hasMarkArea }) {
|
|
109
|
+
const customAriaDescription = generateThresholdAriaDescription(propsSeries, dataset);
|
|
110
|
+
const sliderBottomOuterBound = getSliderBottomOuterBound(dataZoom);
|
|
111
|
+
const sliderRightOuterBound = getSliderRightOuterBound(dataZoom);
|
|
112
|
+
const hasVerticalSlider = hasVerticalSliderZoom(dataZoom);
|
|
113
|
+
const hasHorizontalSlider = hasHorizontalSliderZoom(dataZoom);
|
|
114
|
+
const gridBottom = hasHorizontalSlider ? 60 : hasVerticalSlider ? 25 : 10;
|
|
115
|
+
const gridHorizontalInset = hasCategoryXAxis ? 15 : 10;
|
|
116
|
+
const gridRight = hasVerticalSlider ? 60 : hasHorizontalSlider ? 45 : gridHorizontalInset;
|
|
117
|
+
const outerBoundsTop = hasMarkArea ? 20 : 10;
|
|
118
|
+
const gridTop = hasVerticalSlider ? 20 : outerBoundsTop;
|
|
119
|
+
const seriesList = Array.isArray(series) ? series : [series];
|
|
120
|
+
const isScatterChart = seriesList.length > 0 && seriesList.every((seriesOption) => seriesOption.type === "scatter");
|
|
121
|
+
const seriesAxisNames = seriesList.map((seriesOption) => {
|
|
122
|
+
const { xAxisIndex, yAxisIndex } = seriesOption;
|
|
123
|
+
return {
|
|
124
|
+
x: getAxisName(xAxis, xAxisIndex),
|
|
125
|
+
y: getAxisName(yAxis, yAxisIndex)
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
return _objectSpread2(_objectSpread2({}, userOption), {}, {
|
|
129
|
+
aria: _objectSpread2(_objectSpread2({
|
|
130
|
+
decal: { show: false },
|
|
131
|
+
enabled: true
|
|
132
|
+
}, customAriaDescription !== void 0 && { label: { description: customAriaDescription } }), userOption === null || userOption === void 0 ? void 0 : userOption.aria),
|
|
133
|
+
dataZoom,
|
|
134
|
+
dataset,
|
|
135
|
+
grid: _objectSpread2({
|
|
136
|
+
bottom: `${gridBottom}px`,
|
|
137
|
+
left: `${gridHorizontalInset}px`,
|
|
138
|
+
outerBounds: {
|
|
139
|
+
bottom: sliderBottomOuterBound !== null && sliderBottomOuterBound !== void 0 ? sliderBottomOuterBound : gridBottom,
|
|
140
|
+
left: gridHorizontalInset,
|
|
141
|
+
right: sliderRightOuterBound !== null && sliderRightOuterBound !== void 0 ? sliderRightOuterBound : gridHorizontalInset,
|
|
142
|
+
top: outerBoundsTop
|
|
143
|
+
},
|
|
144
|
+
outerBoundsContain: "all",
|
|
145
|
+
right: `${gridRight}px`,
|
|
146
|
+
top: `${gridTop}px`,
|
|
147
|
+
type: "solid"
|
|
148
|
+
}, userOption === null || userOption === void 0 ? void 0 : userOption.grid),
|
|
149
|
+
legend: {
|
|
150
|
+
selected: _objectSpread2({}, legendSelected),
|
|
151
|
+
show: false
|
|
152
|
+
},
|
|
153
|
+
series,
|
|
154
|
+
toolbox: mergeToolbox(toolboxOptions, {
|
|
155
|
+
dataZoom,
|
|
156
|
+
xAxis,
|
|
157
|
+
yAxis
|
|
158
|
+
}),
|
|
159
|
+
tooltip: {
|
|
160
|
+
borderRadius: 0,
|
|
161
|
+
borderWidth: 0,
|
|
162
|
+
confine: true,
|
|
163
|
+
extraCssText: tooltipExtraCssText,
|
|
164
|
+
formatter: isScatterChart ? createScatterTooltipFormatter({
|
|
165
|
+
dataset,
|
|
166
|
+
getChartInstance,
|
|
167
|
+
getLegendSelected,
|
|
168
|
+
series,
|
|
169
|
+
seriesAxisNames,
|
|
170
|
+
userOption
|
|
171
|
+
}) : createAxisTooltipFormatter({
|
|
172
|
+
thresholdLines,
|
|
173
|
+
userOption
|
|
174
|
+
}),
|
|
175
|
+
padding: 0,
|
|
176
|
+
trigger: isScatterChart ? "item" : "axis"
|
|
177
|
+
},
|
|
178
|
+
xAxis,
|
|
179
|
+
yAxis
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
export { buildChartOption, getSliderBottomOuterBound, getSliderRightOuterBound, hasCategoryXAxis, hasHorizontalSliderZoom, hasMarkAreaInSeries, hasVerticalSliderZoom };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=build-chart-option.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-chart-option.mjs","names":[],"sources":["../../../../src/charts/utils/build-chart-option.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { DataZoomComponentOption, EChartsOption } from 'echarts';\n\nimport { generateThresholdAriaDescription } from './aria-description';\nimport {\n createAxisTooltipFormatter,\n createScatterTooltipFormatter,\n type SeriesAxisNames,\n} from './chart-tooltip-formatter';\nimport type { ChartProps, EchartsSeries } from './chart-types';\nimport { tooltipExtraCssText } from './defaults';\nimport type { ScatterTooltipChart } from './scatter-tooltip-points';\nimport type { NormalizedThresholdLine } from './threshold';\nimport { isVerticalSlider, mergeToolbox } from './user-option-utils';\n\nconst SLIDER_OUTER_BOUND_GAP = 8;\nconst SLIDER_OUTER_BOUND_FALLBACK = 60;\n\ntype BuildChartOptionParams = {\n dataZoom: EChartsOption['dataZoom'];\n dataset: ChartProps['dataset'];\n getChartInstance?: () => ScatterTooltipChart | undefined;\n getLegendSelected?: () => Record<string, boolean> | undefined;\n hasCategoryXAxis: boolean;\n legendSelected: Record<string, boolean>;\n propsSeries: ChartProps['series'];\n series: EchartsSeries;\n thresholdLines: NormalizedThresholdLine[];\n toolboxOptions: EChartsOption['toolbox'];\n userOption: ChartProps['option'];\n xAxis: EChartsOption['xAxis'];\n yAxis: EChartsOption['yAxis'];\n hasMarkArea: boolean;\n};\n\nconst toDataZoomArray = (dataZoom: EChartsOption['dataZoom']) =>\n Array.isArray(dataZoom) ? dataZoom : [dataZoom];\n\n/**\n * Horizontal slider zoom needs extra bottom grid space for ECharts' slider\n * control.\n */\nexport function hasHorizontalSliderZoom(\n dataZoom: EChartsOption['dataZoom'],\n): boolean {\n return toDataZoomArray(dataZoom).some(\n (dataZoomOption: DataZoomComponentOption | undefined) =>\n dataZoomOption?.type === 'slider' && !isVerticalSlider(dataZoomOption),\n );\n}\n\n/**\n * Vertical slider zoom needs extra right grid space for ECharts' slider\n * control.\n */\nexport function hasVerticalSliderZoom(\n dataZoom: EChartsOption['dataZoom'],\n): boolean {\n return toDataZoomArray(dataZoom).some(\n (dataZoomOption: DataZoomComponentOption | undefined) =>\n isVerticalSlider(dataZoomOption),\n );\n}\n\ntype SliderDataZoomLayout = DataZoomComponentOption & {\n bottom?: number | string;\n height?: number | string;\n orient?: 'horizontal' | 'vertical';\n right?: number | string;\n width?: number | string;\n};\n\nconst getPixelValue = (value: number | string | undefined) => {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n\n if (typeof value !== 'string' || !/^-?\\d+(?:\\.\\d+)?px$/.test(value)) {\n return undefined;\n }\n\n return Number.parseFloat(value);\n};\n\n/**\n * Reserves the area occupied by bottom-positioned horizontal slider controls.\n *\n * ECharts lays data zoom controls outside the Cartesian grid, so its automatic\n * axis outer bounds do not account for them. Normalized sliders use pixel\n * values; custom percentage-based layouts fall back to the previous 60px\n * reserve because they cannot be resolved without the rendered chart size.\n */\nexport function getSliderBottomOuterBound(\n dataZoom: EChartsOption['dataZoom'],\n): number | undefined {\n const sliderOuterBounds = toDataZoomArray(dataZoom).flatMap((option) => {\n const slider = option as SliderDataZoomLayout | undefined;\n if (slider?.type !== 'slider' || isVerticalSlider(slider)) {\n return [];\n }\n\n const bottom = getPixelValue(slider.bottom);\n const height = getPixelValue(slider.height);\n if (bottom === undefined || height === undefined) {\n return [SLIDER_OUTER_BOUND_FALLBACK];\n }\n\n return [bottom + height + SLIDER_OUTER_BOUND_GAP];\n });\n\n return sliderOuterBounds.length > 0\n ? Math.max(...sliderOuterBounds)\n : undefined;\n}\n\n/**\n * Reserves the area occupied by right-positioned vertical slider controls,\n * mirroring `getSliderBottomOuterBound` for horizontal ones. Normalized\n * sliders use pixel values; custom percentage-based layouts fall back to the\n * 60px reserve because they cannot be resolved without the rendered chart\n * size.\n */\nexport function getSliderRightOuterBound(\n dataZoom: EChartsOption['dataZoom'],\n): number | undefined {\n const sliderOuterBounds = toDataZoomArray(dataZoom).flatMap((option) => {\n const slider = option as SliderDataZoomLayout | undefined;\n if (!isVerticalSlider(slider)) {\n return [];\n }\n\n const right = getPixelValue(slider?.right);\n const width = getPixelValue(slider?.width);\n if (right === undefined || width === undefined) {\n return [SLIDER_OUTER_BOUND_FALLBACK];\n }\n\n return [right + width + SLIDER_OUTER_BOUND_GAP];\n });\n\n return sliderOuterBounds.length > 0\n ? Math.max(...sliderOuterBounds)\n : undefined;\n}\n\n/**\n * Mark area needs extra top grid space to fit inside the chart.\n */\nexport const hasMarkAreaInSeries = (series: EchartsSeries) =>\n Array.isArray(series)\n ? series.some((option) => !!option.markArea)\n : !!series.markArea;\n\n/**\n * Reads the `name` of the axis at `axisIndex`, which scatter tooltips use to\n * label their x and y rows.\n */\nfunction getAxisName(\n axis: EChartsOption['xAxis'] | EChartsOption['yAxis'],\n axisIndex = 0,\n): string | undefined {\n const axisOption = (\n Array.isArray(axis) ? axis[axisIndex] : axisIndex === 0 ? axis : undefined\n ) as { name?: unknown } | undefined;\n\n return typeof axisOption?.name === 'string' && axisOption.name.length > 0\n ? axisOption.name\n : undefined;\n}\n\n/**\n * Category x-axes use slightly wider grid padding to avoid clipped labels.\n */\nexport function hasCategoryXAxis(xAxis: EChartsOption['xAxis']): boolean {\n return Array.isArray(xAxis)\n ? xAxis.some((axis) => axis.type === 'category')\n : xAxis?.type === 'category';\n}\n\n/**\n * Builds the ECharts option object from Needle chart props and derived values.\n * Applying the option to an ECharts instance happens in `useChartOption`.\n */\nexport function buildChartOption({\n dataZoom,\n dataset,\n getChartInstance,\n getLegendSelected,\n hasCategoryXAxis,\n legendSelected,\n propsSeries,\n series,\n thresholdLines,\n toolboxOptions,\n userOption,\n xAxis,\n yAxis,\n hasMarkArea,\n}: BuildChartOptionParams): EChartsOption {\n const customAriaDescription = generateThresholdAriaDescription(\n propsSeries,\n dataset,\n );\n const sliderBottomOuterBound = getSliderBottomOuterBound(dataZoom);\n const sliderRightOuterBound = getSliderRightOuterBound(dataZoom);\n const hasVerticalSlider = hasVerticalSliderZoom(dataZoom);\n const hasHorizontalSlider = hasHorizontalSliderZoom(dataZoom);\n const gridBottom = hasHorizontalSlider ? 60 : hasVerticalSlider ? 25 : 10;\n const gridHorizontalInset = hasCategoryXAxis ? 15 : 10;\n const gridRight = hasVerticalSlider\n ? 60\n : hasHorizontalSlider\n ? 45\n : gridHorizontalInset;\n const outerBoundsTop = hasMarkArea ? 20 : 10;\n const gridTop = hasVerticalSlider ? 20 : outerBoundsTop;\n const seriesList = Array.isArray(series) ? series : [series];\n const isScatterChart =\n seriesList.length > 0 &&\n seriesList.every((seriesOption) => seriesOption.type === 'scatter');\n const seriesAxisNames: SeriesAxisNames[] = seriesList.map((seriesOption) => {\n const { xAxisIndex, yAxisIndex } = seriesOption as {\n xAxisIndex?: number;\n yAxisIndex?: number;\n };\n\n return {\n // oxlint-disable-next-line id-length\n x: getAxisName(xAxis, xAxisIndex),\n // oxlint-disable-next-line id-length\n y: getAxisName(yAxis, yAxisIndex),\n };\n });\n\n return {\n ...userOption,\n aria: {\n decal: {\n show: false,\n },\n enabled: true,\n ...(customAriaDescription !== undefined && {\n label: { description: customAriaDescription },\n }),\n ...(userOption?.aria as EChartsOption['aria']),\n },\n dataZoom,\n dataset,\n grid: {\n bottom: `${gridBottom}px`,\n left: `${gridHorizontalInset}px`,\n outerBounds: {\n bottom: sliderBottomOuterBound ?? gridBottom,\n left: gridHorizontalInset,\n right: sliderRightOuterBound ?? gridHorizontalInset,\n top: outerBoundsTop,\n },\n outerBoundsContain: 'all',\n right: `${gridRight}px`,\n top: `${gridTop}px`,\n type: 'solid',\n ...(userOption?.grid as EChartsOption['grid']),\n },\n legend: {\n // ECharts mutates option.legend.selected internally; callers pass a\n // copied object so the React ref remains the source of truth.\n selected: { ...legendSelected },\n show: false,\n },\n series,\n toolbox: mergeToolbox(toolboxOptions, { dataZoom, xAxis, yAxis }),\n tooltip: {\n borderRadius: 0,\n borderWidth: 0,\n confine: true,\n extraCssText: tooltipExtraCssText,\n formatter: isScatterChart\n ? createScatterTooltipFormatter({\n dataset,\n getChartInstance,\n getLegendSelected,\n series,\n seriesAxisNames,\n userOption,\n })\n : createAxisTooltipFormatter({ thresholdLines, userOption }),\n padding: 0,\n // Scatter needs item trigger so the unique per-point `encode.tooltip`\n // value can title the tooltip. Axis trigger would group every point\n // that shares an x (or y) value.\n trigger: isScatterChart ? 'item' : 'axis',\n },\n xAxis,\n yAxis,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,yBAAyB;AAC/B,MAAM,8BAA8B;AAmBpC,MAAM,mBAAmB,aACvB,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;;;;;AAMhD,SAAgB,wBACd,UACS;CACT,OAAO,gBAAgB,QAAQ,CAAC,CAAC,MAC9B,oBAAA,mBAAA,QAAA,mBAAA,KAAA,IAAA,KAAA,IACC,eAAgB,UAAS,YAAY,CAAC,iBAAiB,cAAc,CACzE;AACF;;;;;AAMA,SAAgB,sBACd,UACS;CACT,OAAO,gBAAgB,QAAQ,CAAC,CAAC,MAC9B,mBACC,iBAAiB,cAAc,CACnC;AACF;AAUA,MAAM,iBA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