@neo4j-ndl/react-charts 2.1.21 → 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.
Files changed (209) hide show
  1. package/lib/LICENSES.txt +0 -295
  2. package/lib/NOTICE.txt +1383 -1392
  3. package/lib/{esm/charts/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.js} +13 -5
  4. package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.js +46 -0
  5. package/lib/{esm/charts/tests/ChartWrapperWithTooltipFormatter.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.js} +12 -13
  6. package/lib/{esm/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.js} +13 -2
  7. package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.js +35 -0
  8. package/lib/{esm/charts/utils/chart-types.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.js} +10 -2
  9. package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.js +37 -0
  10. package/lib/cjs/_virtual/_rolldown/runtime.js +44 -0
  11. package/lib/cjs/charts/Chart.js +121 -111
  12. package/lib/cjs/charts/Chart.js.map +1 -1
  13. package/lib/cjs/charts/ChartContainer.js +67 -62
  14. package/lib/cjs/charts/ChartContainer.js.map +1 -1
  15. package/lib/cjs/charts/ChartEmpty.js +45 -30
  16. package/lib/cjs/charts/ChartEmpty.js.map +1 -1
  17. package/lib/cjs/charts/ChartRender.js +112 -87
  18. package/lib/cjs/charts/ChartRender.js.map +1 -1
  19. package/lib/cjs/charts/ChartTooltip.js +111 -65
  20. package/lib/cjs/charts/ChartTooltip.js.map +1 -1
  21. package/lib/cjs/charts/Legend.js +81 -69
  22. package/lib/cjs/charts/Legend.js.map +1 -1
  23. package/lib/cjs/charts/LegendItem.js +83 -62
  24. package/lib/cjs/charts/LegendItem.js.map +1 -1
  25. package/lib/cjs/charts/LegendLayout.js +330 -348
  26. package/lib/cjs/charts/LegendLayout.js.map +1 -1
  27. package/lib/cjs/charts/hooks/use-chart-instance.js +115 -122
  28. package/lib/cjs/charts/hooks/use-chart-instance.js.map +1 -1
  29. package/lib/cjs/charts/hooks/use-chart-option.js +79 -80
  30. package/lib/cjs/charts/hooks/use-chart-option.js.map +1 -1
  31. package/lib/cjs/charts/hooks/use-chart-refs.js +47 -44
  32. package/lib/cjs/charts/hooks/use-chart-refs.js.map +1 -1
  33. package/lib/cjs/charts/hooks/use-chart-zoom.js +102 -127
  34. package/lib/cjs/charts/hooks/use-chart-zoom.js.map +1 -1
  35. package/lib/cjs/charts/hooks/use-legend-interactions.js +127 -132
  36. package/lib/cjs/charts/hooks/use-legend-interactions.js.map +1 -1
  37. package/lib/cjs/charts/hooks/use-legend-series.js +143 -174
  38. package/lib/cjs/charts/hooks/use-legend-series.js.map +1 -1
  39. package/lib/cjs/charts/hooks/use-legend-visibility.js +66 -85
  40. package/lib/cjs/charts/hooks/use-legend-visibility.js.map +1 -1
  41. package/lib/cjs/charts/index.js +31 -40
  42. package/lib/cjs/charts/index.js.map +1 -1
  43. package/lib/cjs/charts/themes/ndl-echarts-theme.js +136 -168
  44. package/lib/cjs/charts/themes/ndl-echarts-theme.js.map +1 -1
  45. package/lib/cjs/charts/utils/aria-description.js +150 -214
  46. package/lib/cjs/charts/utils/aria-description.js.map +1 -1
  47. package/lib/cjs/charts/utils/build-chart-option.js +166 -174
  48. package/lib/cjs/charts/utils/build-chart-option.js.map +1 -1
  49. package/lib/cjs/charts/utils/chart-tooltip-formatter.js +156 -172
  50. package/lib/cjs/charts/utils/chart-tooltip-formatter.js.map +1 -1
  51. package/lib/cjs/charts/utils/chart-types.js +25 -20
  52. package/lib/cjs/charts/utils/chart-types.js.map +1 -1
  53. package/lib/cjs/charts/utils/defaults.js +69 -67
  54. package/lib/cjs/charts/utils/defaults.js.map +1 -1
  55. package/lib/cjs/charts/utils/format-utils.js +55 -66
  56. package/lib/cjs/charts/utils/format-utils.js.map +1 -1
  57. package/lib/cjs/charts/utils/legend-layout.js +54 -53
  58. package/lib/cjs/charts/utils/legend-layout.js.map +1 -1
  59. package/lib/cjs/charts/utils/legend-utils.js +82 -121
  60. package/lib/cjs/charts/utils/legend-utils.js.map +1 -1
  61. package/lib/cjs/charts/utils/scatter-tooltip-points.js +191 -266
  62. package/lib/cjs/charts/utils/scatter-tooltip-points.js.map +1 -1
  63. package/lib/cjs/charts/utils/threshold.js +89 -102
  64. package/lib/cjs/charts/utils/threshold.js.map +1 -1
  65. package/lib/cjs/charts/utils/user-option-utils.js +419 -347
  66. package/lib/cjs/charts/utils/user-option-utils.js.map +1 -1
  67. package/lib/cjs/index.js +31 -35
  68. package/lib/cjs/index.js.map +1 -1
  69. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.mjs +11 -0
  70. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs +24 -0
  71. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.mjs +12 -0
  72. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.mjs +11 -0
  73. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.mjs +13 -0
  74. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.mjs +8 -0
  75. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.mjs +10 -0
  76. package/lib/esm/charts/Chart.mjs +123 -0
  77. package/lib/esm/charts/Chart.mjs.map +1 -0
  78. package/lib/esm/charts/ChartContainer.mjs +71 -0
  79. package/lib/esm/charts/ChartContainer.mjs.map +1 -0
  80. package/lib/esm/charts/ChartEmpty.mjs +46 -0
  81. package/lib/esm/charts/ChartEmpty.mjs.map +1 -0
  82. package/lib/esm/charts/ChartRender.mjs +113 -0
  83. package/lib/esm/charts/ChartRender.mjs.map +1 -0
  84. package/lib/esm/charts/ChartTooltip.mjs +109 -0
  85. package/lib/esm/charts/ChartTooltip.mjs.map +1 -0
  86. package/lib/esm/charts/Legend.mjs +82 -0
  87. package/lib/esm/charts/Legend.mjs.map +1 -0
  88. package/lib/esm/charts/LegendItem.mjs +82 -0
  89. package/lib/esm/charts/LegendItem.mjs.map +1 -0
  90. package/lib/esm/charts/LegendLayout.mjs +337 -0
  91. package/lib/esm/charts/LegendLayout.mjs.map +1 -0
  92. package/lib/esm/charts/hooks/use-chart-instance.mjs +119 -0
  93. package/lib/esm/charts/hooks/use-chart-instance.mjs.map +1 -0
  94. package/lib/esm/charts/hooks/use-chart-option.mjs +79 -0
  95. package/lib/esm/charts/hooks/use-chart-option.mjs.map +1 -0
  96. package/lib/esm/charts/hooks/use-chart-refs.mjs +49 -0
  97. package/lib/esm/charts/hooks/use-chart-refs.mjs.map +1 -0
  98. package/lib/esm/charts/hooks/use-chart-zoom.mjs +102 -0
  99. package/lib/esm/charts/hooks/use-chart-zoom.mjs.map +1 -0
  100. package/lib/esm/charts/hooks/use-legend-interactions.mjs +138 -0
  101. package/lib/esm/charts/hooks/use-legend-interactions.mjs.map +1 -0
  102. package/lib/esm/charts/hooks/use-legend-series.mjs +151 -0
  103. package/lib/esm/charts/hooks/use-legend-series.mjs.map +1 -0
  104. package/lib/esm/charts/hooks/use-legend-visibility.mjs +67 -0
  105. package/lib/esm/charts/hooks/use-legend-visibility.mjs.map +1 -0
  106. package/lib/esm/charts/index.mjs +27 -0
  107. package/lib/esm/charts/index.mjs.map +1 -0
  108. package/lib/esm/charts/themes/ndl-echarts-theme.mjs +139 -0
  109. package/lib/esm/charts/themes/ndl-echarts-theme.mjs.map +1 -0
  110. package/lib/esm/charts/utils/aria-description.mjs +162 -0
  111. package/lib/esm/charts/utils/aria-description.mjs.map +1 -0
  112. package/lib/esm/charts/utils/build-chart-option.mjs +184 -0
  113. package/lib/esm/charts/utils/build-chart-option.mjs.map +1 -0
  114. package/lib/esm/charts/utils/chart-tooltip-formatter.mjs +159 -0
  115. package/lib/esm/charts/utils/chart-tooltip-formatter.mjs.map +1 -0
  116. package/lib/esm/charts/utils/chart-types.mjs +24 -0
  117. package/lib/esm/charts/utils/chart-types.mjs.map +1 -0
  118. package/lib/esm/charts/utils/defaults.mjs +73 -0
  119. package/lib/esm/charts/utils/defaults.mjs.map +1 -0
  120. package/lib/esm/charts/utils/format-utils.mjs +61 -0
  121. package/lib/esm/charts/utils/format-utils.mjs.map +1 -0
  122. package/lib/esm/charts/utils/legend-layout.mjs +57 -0
  123. package/lib/esm/charts/utils/legend-layout.mjs.map +1 -0
  124. package/lib/esm/charts/utils/legend-utils.mjs +90 -0
  125. package/lib/esm/charts/utils/legend-utils.mjs.map +1 -0
  126. package/lib/esm/charts/utils/scatter-tooltip-points.mjs +215 -0
  127. package/lib/esm/charts/utils/scatter-tooltip-points.mjs.map +1 -0
  128. package/lib/esm/charts/utils/threshold.mjs +92 -0
  129. package/lib/esm/charts/utils/threshold.mjs.map +1 -0
  130. package/lib/esm/charts/utils/user-option-utils.mjs +445 -0
  131. package/lib/esm/charts/utils/user-option-utils.mjs.map +1 -0
  132. package/lib/esm/index.mjs +27 -0
  133. package/lib/esm/index.mjs.map +1 -0
  134. package/package.json +12 -16
  135. package/skills/ndl-react-charts/SKILL.md +2 -2
  136. package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js +0 -38
  137. package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
  138. package/lib/cjs/charts/tests/ChartZoomHarness.js +0 -113
  139. package/lib/cjs/charts/tests/ChartZoomHarness.js.map +0 -1
  140. package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js +0 -78
  141. package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
  142. package/lib/cjs/charts/tests/PieChartWithRerender.js +0 -46
  143. package/lib/cjs/charts/tests/PieChartWithRerender.js.map +0 -1
  144. package/lib/cjs/charts/tests/chart-test-utils.js +0 -527
  145. package/lib/cjs/charts/tests/chart-test-utils.js.map +0 -1
  146. package/lib/esm/charts/Chart.js +0 -114
  147. package/lib/esm/charts/Chart.js.map +0 -1
  148. package/lib/esm/charts/ChartContainer.js +0 -67
  149. package/lib/esm/charts/ChartContainer.js.map +0 -1
  150. package/lib/esm/charts/ChartEmpty.js +0 -33
  151. package/lib/esm/charts/ChartEmpty.js.map +0 -1
  152. package/lib/esm/charts/ChartRender.js +0 -89
  153. package/lib/esm/charts/ChartRender.js.map +0 -1
  154. package/lib/esm/charts/ChartTooltip.js +0 -64
  155. package/lib/esm/charts/ChartTooltip.js.map +0 -1
  156. package/lib/esm/charts/Legend.js +0 -71
  157. package/lib/esm/charts/Legend.js.map +0 -1
  158. package/lib/esm/charts/LegendItem.js +0 -61
  159. package/lib/esm/charts/LegendItem.js.map +0 -1
  160. package/lib/esm/charts/LegendLayout.js +0 -323
  161. package/lib/esm/charts/LegendLayout.js.map +0 -1
  162. package/lib/esm/charts/hooks/use-chart-instance.js +0 -128
  163. package/lib/esm/charts/hooks/use-chart-instance.js.map +0 -1
  164. package/lib/esm/charts/hooks/use-chart-option.js +0 -82
  165. package/lib/esm/charts/hooks/use-chart-option.js.map +0 -1
  166. package/lib/esm/charts/hooks/use-chart-refs.js +0 -48
  167. package/lib/esm/charts/hooks/use-chart-refs.js.map +0 -1
  168. package/lib/esm/charts/hooks/use-chart-zoom.js +0 -129
  169. package/lib/esm/charts/hooks/use-chart-zoom.js.map +0 -1
  170. package/lib/esm/charts/hooks/use-legend-interactions.js +0 -145
  171. package/lib/esm/charts/hooks/use-legend-interactions.js.map +0 -1
  172. package/lib/esm/charts/hooks/use-legend-series.js +0 -184
  173. package/lib/esm/charts/hooks/use-legend-series.js.map +0 -1
  174. package/lib/esm/charts/hooks/use-legend-visibility.js +0 -87
  175. package/lib/esm/charts/hooks/use-legend-visibility.js.map +0 -1
  176. package/lib/esm/charts/index.js.map +0 -1
  177. package/lib/esm/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
  178. package/lib/esm/charts/tests/ChartZoomHarness.js +0 -109
  179. package/lib/esm/charts/tests/ChartZoomHarness.js.map +0 -1
  180. package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js +0 -74
  181. package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
  182. package/lib/esm/charts/tests/PieChartWithRerender.js +0 -43
  183. package/lib/esm/charts/tests/PieChartWithRerender.js.map +0 -1
  184. package/lib/esm/charts/tests/chart-test-utils.js +0 -500
  185. package/lib/esm/charts/tests/chart-test-utils.js.map +0 -1
  186. package/lib/esm/charts/themes/ndl-echarts-theme.js +0 -172
  187. package/lib/esm/charts/themes/ndl-echarts-theme.js.map +0 -1
  188. package/lib/esm/charts/utils/aria-description.js +0 -228
  189. package/lib/esm/charts/utils/aria-description.js.map +0 -1
  190. package/lib/esm/charts/utils/build-chart-option.js +0 -193
  191. package/lib/esm/charts/utils/build-chart-option.js.map +0 -1
  192. package/lib/esm/charts/utils/chart-tooltip-formatter.js +0 -177
  193. package/lib/esm/charts/utils/chart-tooltip-formatter.js.map +0 -1
  194. package/lib/esm/charts/utils/chart-types.js.map +0 -1
  195. package/lib/esm/charts/utils/defaults.js +0 -73
  196. package/lib/esm/charts/utils/defaults.js.map +0 -1
  197. package/lib/esm/charts/utils/format-utils.js +0 -74
  198. package/lib/esm/charts/utils/format-utils.js.map +0 -1
  199. package/lib/esm/charts/utils/legend-layout.js +0 -59
  200. package/lib/esm/charts/utils/legend-layout.js.map +0 -1
  201. package/lib/esm/charts/utils/legend-utils.js +0 -131
  202. package/lib/esm/charts/utils/legend-utils.js.map +0 -1
  203. package/lib/esm/charts/utils/scatter-tooltip-points.js +0 -291
  204. package/lib/esm/charts/utils/scatter-tooltip-points.js.map +0 -1
  205. package/lib/esm/charts/utils/threshold.js +0 -106
  206. package/lib/esm/charts/utils/threshold.js.map +0 -1
  207. package/lib/esm/charts/utils/user-option-utils.js +0 -374
  208. package/lib/esm/charts/utils/user-option-utils.js.map +0 -1
  209. package/lib/esm/index.js.map +0 -1
@@ -0,0 +1,215 @@
1
+ // src/charts/utils/scatter-tooltip-points.ts
2
+ /*!
3
+ *
4
+ * Copyright (c) "Neo4j"
5
+ * Neo4j Sweden AB [http://neo4j.com]
6
+ *
7
+ * This file is part of Neo4j.
8
+ *
9
+ * Neo4j is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ */
22
+ /**
23
+ * Scanning stops past this many points so a dense chart cannot turn every hover
24
+ * into a long walk over the dataset.
25
+ */
26
+ const MAX_SCANNED_POINTS = 2e4;
27
+ /** Symbol width ECharts falls back to when a series sets no numeric size. */
28
+ const DEFAULT_SYMBOL_SIZE = 10;
29
+ const toArray = (value) => {
30
+ if (value === void 0) return [];
31
+ return Array.isArray(value) ? value : [value];
32
+ };
33
+ const encodeRefs = (encode, key) => {
34
+ if (encode === void 0) return [];
35
+ const raw = encode[key];
36
+ return (Array.isArray(raw) ? raw : [raw]).filter((ref) => typeof ref === "number" || typeof ref === "string");
37
+ };
38
+ const readEncodedValue = (value, ref, dimensionNames) => {
39
+ if (Array.isArray(value)) {
40
+ if (typeof ref === "number") return value[ref];
41
+ const dimensionIndex = dimensionNames === null || dimensionNames === void 0 ? void 0 : dimensionNames.indexOf(ref);
42
+ return dimensionIndex !== void 0 && dimensionIndex >= 0 ? value[dimensionIndex] : void 0;
43
+ }
44
+ if (value !== null && typeof value === "object") {
45
+ const record = value;
46
+ if (typeof ref === "string" && ref in record) return record[ref];
47
+ if (typeof ref === "number") {
48
+ const dimensionName = dimensionNames === null || dimensionNames === void 0 ? void 0 : dimensionNames[ref];
49
+ if (dimensionName !== void 0 && dimensionName in record) return record[dimensionName];
50
+ }
51
+ }
52
+ };
53
+ const encodedDimensionLabel = (ref, dimensionNames, fallback) => {
54
+ if (typeof ref === "string") return ref;
55
+ const dimensionName = dimensionNames === null || dimensionNames === void 0 ? void 0 : dimensionNames[ref];
56
+ if (typeof dimensionName === "string" && dimensionName.length > 0) return dimensionName;
57
+ return fallback;
58
+ };
59
+ /**
60
+ * Dimensions holding the unique per-point value: `encode.tooltip` first, then
61
+ * `encode.itemName`, and finally any dimension the axes do not already use.
62
+ */
63
+ const extraTooltipRefs = (point) => {
64
+ const xRefs = encodeRefs(point.encode, "x");
65
+ const yRefs = encodeRefs(point.encode, "y");
66
+ const isAxisRef = (ref) => xRefs.includes(ref) || yRefs.includes(ref);
67
+ const tooltipRefs = encodeRefs(point.encode, "tooltip").filter((ref) => !isAxisRef(ref));
68
+ if (tooltipRefs.length > 0) return tooltipRefs;
69
+ const itemNameRefs = encodeRefs(point.encode, "itemName");
70
+ if (itemNameRefs.length > 0) return itemNameRefs;
71
+ if (Array.isArray(point.value) && point.value.length > 2) {
72
+ const usedIndices = new Set([...xRefs, ...yRefs].filter((ref) => typeof ref === "number"));
73
+ if (usedIndices.size === 0) {
74
+ usedIndices.add(0);
75
+ usedIndices.add(1);
76
+ }
77
+ return point.value.flatMap((_value, index) => usedIndices.has(index) ? [] : [index]);
78
+ }
79
+ return [];
80
+ };
81
+ const getEncodedAxisRefs = (encode) => {
82
+ var _encodeRefs$, _encodeRefs$2;
83
+ return {
84
+ x: (_encodeRefs$ = encodeRefs(encode, "x")[0]) !== null && _encodeRefs$ !== void 0 ? _encodeRefs$ : 0,
85
+ y: (_encodeRefs$2 = encodeRefs(encode, "y")[0]) !== null && _encodeRefs$2 !== void 0 ? _encodeRefs$2 : 1
86
+ };
87
+ };
88
+ const toStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string") ? value : void 0;
89
+ const isHeaderRow = (row) => Array.isArray(row) && row.length > 0 && row.every((cell) => typeof cell === "string");
90
+ /**
91
+ * Resolves the rows a series draws, together with the dimension names its
92
+ * `encode` refers to. Rows are aligned with ECharts' data indices, so a sniffed
93
+ * header row is dropped the way ECharts drops it.
94
+ */
95
+ const resolveSeriesSource = (series, datasets) => {
96
+ var _series$datasetIndex, _series$dimensions;
97
+ const inlineData = Array.isArray(series.data) ? series.data : void 0;
98
+ const dataset = inlineData === void 0 ? datasets[(_series$datasetIndex = series.datasetIndex) !== null && _series$datasetIndex !== void 0 ? _series$datasetIndex : 0] : void 0;
99
+ const rows = inlineData !== null && inlineData !== void 0 ? inlineData : Array.isArray(dataset === null || dataset === void 0 ? void 0 : dataset.source) ? dataset.source : void 0;
100
+ if (rows === void 0) return;
101
+ const declaredDimensions = toStringArray((_series$dimensions = series.dimensions) !== null && _series$dimensions !== void 0 ? _series$dimensions : dataset === null || dataset === void 0 ? void 0 : dataset.dimensions);
102
+ if (declaredDimensions !== void 0) return {
103
+ dimensionNames: declaredDimensions,
104
+ rows
105
+ };
106
+ if (isHeaderRow(rows[0]) && !isHeaderRow(rows[1])) return {
107
+ dimensionNames: rows[0],
108
+ rows: rows.slice(1)
109
+ };
110
+ return { rows };
111
+ };
112
+ const toNumericValue = (value) => {
113
+ if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
114
+ if (value instanceof Date) return value.getTime();
115
+ if (typeof value === "string") {
116
+ const numeric = Number(value);
117
+ if (Number.isFinite(numeric)) return numeric;
118
+ const time = Date.parse(value);
119
+ return Number.isFinite(time) ? time : void 0;
120
+ }
121
+ };
122
+ /**
123
+ * Distance from the hovered value along one axis, as a share of the tolerance.
124
+ * Values that cannot be compared numerically, such as category labels, only
125
+ * count as near when they are identical.
126
+ */
127
+ const axisDistance = (value, hoveredValue, tolerance) => {
128
+ const numeric = toNumericValue(value);
129
+ const hoveredNumeric = toNumericValue(hoveredValue);
130
+ if (numeric === void 0 || hoveredNumeric === void 0) return value === hoveredValue ? 0 : void 0;
131
+ if (tolerance <= 0) return numeric === hoveredNumeric ? 0 : void 0;
132
+ return (numeric - hoveredNumeric) / tolerance;
133
+ };
134
+ const isCoordinatePair = (value) => Array.isArray(value) && value.length >= 2 && Number.isFinite(value[0]) && Number.isFinite(value[1]);
135
+ /**
136
+ * Converts a pixel radius around the hovered point into a distance on each
137
+ * axis, so points can be compared in data space instead of converting every
138
+ * one of them to pixels.
139
+ */
140
+ const getAxisTolerances = (chart, seriesIndex, hoveredValue, radius) => {
141
+ const finder = { seriesIndex };
142
+ const pixel = chart.convertToPixel(finder, hoveredValue);
143
+ if (!isCoordinatePair(pixel)) return;
144
+ const origin = chart.convertFromPixel(finder, [pixel[0], pixel[1]]);
145
+ const offset = chart.convertFromPixel(finder, [pixel[0] + radius, pixel[1] + radius]);
146
+ if (!isCoordinatePair(origin) || !isCoordinatePair(offset)) return;
147
+ return {
148
+ x: Math.abs(offset[0] - origin[0]),
149
+ y: Math.abs(offset[1] - origin[1])
150
+ };
151
+ };
152
+ /**
153
+ * Widest scatter symbol in the chart, which doubles as the radius in which
154
+ * points are considered to overlap the hovered one.
155
+ */
156
+ function getScatterSymbolSize(series) {
157
+ const sizes = toArray(series).filter((seriesOption) => (seriesOption === null || seriesOption === void 0 ? void 0 : seriesOption.type) === "scatter").map((seriesOption) => typeof seriesOption.symbolSize === "number" && Number.isFinite(seriesOption.symbolSize) ? seriesOption.symbolSize : DEFAULT_SYMBOL_SIZE);
158
+ return sizes.length > 0 ? Math.max(...sizes) : DEFAULT_SYMBOL_SIZE;
159
+ }
160
+ /**
161
+ * Collects the points whose symbols overlap the hovered one, closest first,
162
+ * with the hovered point always leading.
163
+ *
164
+ * Distances are measured in data space against a tolerance derived from the
165
+ * pixel radius (ECharts `convertToPixel` / `convertFromPixel`), which keeps the
166
+ * scan to plain arithmetic per point and works on value, time, and log axes
167
+ * alike.
168
+ */
169
+ function findNearbyScatterPoints({ chart, dataset, hovered, legendSelected, maxPoints, radius, series }) {
170
+ const hoveredSeriesIndex = hovered.seriesIndex;
171
+ if (chart === void 0 || hoveredSeriesIndex === void 0) return [hovered];
172
+ const hoveredRefs = getEncodedAxisRefs(hovered.encode);
173
+ const hoveredX = readEncodedValue(hovered.value, hoveredRefs.x, hovered.dimensionNames);
174
+ const hoveredY = readEncodedValue(hovered.value, hoveredRefs.y, hovered.dimensionNames);
175
+ const tolerances = getAxisTolerances(chart, hoveredSeriesIndex, [hoveredX, hoveredY], radius);
176
+ if (tolerances === void 0) return [hovered];
177
+ const seriesList = toArray(series);
178
+ const datasets = toArray(dataset);
179
+ const neighbors = [];
180
+ let scannedPoints = 0;
181
+ for (const [seriesIndex, seriesOption] of seriesList.entries()) {
182
+ var _seriesOption$name;
183
+ if ((seriesOption === null || seriesOption === void 0 ? void 0 : seriesOption.type) !== "scatter" || (legendSelected === null || legendSelected === void 0 ? void 0 : legendSelected[(_seriesOption$name = seriesOption.name) !== null && _seriesOption$name !== void 0 ? _seriesOption$name : ""]) === false) continue;
184
+ const source = resolveSeriesSource(seriesOption, datasets);
185
+ if (source === void 0) continue;
186
+ const refs = getEncodedAxisRefs(seriesOption.encode);
187
+ for (const [dataIndex, row] of source.rows.entries()) {
188
+ if (scannedPoints >= MAX_SCANNED_POINTS) break;
189
+ scannedPoints += 1;
190
+ if (seriesIndex === hoveredSeriesIndex && dataIndex === hovered.dataIndex) continue;
191
+ const xDistance = axisDistance(readEncodedValue(row, refs.x, source.dimensionNames), hoveredX, tolerances.x);
192
+ const yDistance = axisDistance(readEncodedValue(row, refs.y, source.dimensionNames), hoveredY, tolerances.y);
193
+ if (xDistance === void 0 || yDistance === void 0) continue;
194
+ const distance = Math.hypot(xDistance, yDistance);
195
+ if (distance > 1) continue;
196
+ neighbors.push({
197
+ distance,
198
+ point: {
199
+ color: typeof seriesOption.color === "string" ? seriesOption.color : void 0,
200
+ dataIndex,
201
+ dimensionNames: source.dimensionNames,
202
+ encode: seriesOption.encode,
203
+ seriesIndex,
204
+ seriesName: seriesOption.name,
205
+ value: row
206
+ }
207
+ });
208
+ }
209
+ }
210
+ neighbors.sort((first, second) => first.distance - second.distance);
211
+ return [hovered, ...neighbors.slice(0, Math.max(maxPoints - 1, 0)).map(({ point }) => point)];
212
+ }
213
+ export { encodeRefs, encodedDimensionLabel, extraTooltipRefs, findNearbyScatterPoints, getEncodedAxisRefs, getScatterSymbolSize, readEncodedValue };
214
+
215
+ //# sourceMappingURL=scatter-tooltip-points.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scatter-tooltip-points.mjs","names":[],"sources":["../../../../src/charts/utils/scatter-tooltip-points.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 { ChartProps, EchartsSeries } from './chart-types';\n\ntype TooltipEncode = Record<string, unknown> | undefined;\n\n/**\n * A scatter point as the tooltip needs it. ECharts tooltip params already have\n * this shape, so the hovered point and the points found around it are\n * interchangeable.\n */\nexport type ScatterTooltipPoint = {\n color?: string;\n dataIndex?: number;\n dimensionNames?: string[];\n encode?: TooltipEncode;\n name?: string;\n seriesIndex?: number;\n seriesName?: string;\n value?: unknown;\n};\n\n/** The part of the ECharts instance the scatter tooltip reads. */\nexport type ScatterTooltipChart = {\n convertFromPixel(\n finder: { seriesIndex: number },\n value: number[],\n ): number | number[];\n convertToPixel(\n finder: { seriesIndex: number },\n value: unknown[],\n ): number | number[];\n};\n\ntype ScatterSeriesLike = {\n color?: unknown;\n data?: unknown;\n datasetIndex?: number;\n dimensions?: unknown;\n encode?: TooltipEncode;\n name?: string;\n symbolSize?: unknown;\n type?: string;\n};\n\ntype DatasetLike = {\n dimensions?: unknown;\n source?: unknown;\n};\n\n/**\n * Scanning stops past this many points so a dense chart cannot turn every hover\n * into a long walk over the dataset.\n */\nconst MAX_SCANNED_POINTS = 20000;\n\n/** Symbol width ECharts falls back to when a series sets no numeric size. */\nconst DEFAULT_SYMBOL_SIZE = 10;\n\nconst toArray = <T>(value: T | T[] | undefined): T[] => {\n if (value === undefined) {\n return [];\n }\n\n return Array.isArray(value) ? value : [value];\n};\n\nexport const encodeRefs = (\n encode: TooltipEncode,\n key: string,\n): Array<number | string> => {\n if (encode === undefined) {\n return [];\n }\n\n const raw = encode[key];\n const refs = Array.isArray(raw) ? raw : [raw];\n\n return refs.filter(\n (ref): ref is number | string =>\n typeof ref === 'number' || typeof ref === 'string',\n );\n};\n\nexport const readEncodedValue = (\n value: unknown,\n ref: number | string,\n dimensionNames?: string[],\n): unknown => {\n if (Array.isArray(value)) {\n if (typeof ref === 'number') {\n return value[ref];\n }\n\n const dimensionIndex = dimensionNames?.indexOf(ref);\n\n return dimensionIndex !== undefined && dimensionIndex >= 0\n ? value[dimensionIndex]\n : undefined;\n }\n\n if (value !== null && typeof value === 'object') {\n const record = value as Record<string, unknown>;\n\n if (typeof ref === 'string' && ref in record) {\n return record[ref];\n }\n\n if (typeof ref === 'number') {\n const dimensionName = dimensionNames?.[ref];\n\n if (dimensionName !== undefined && dimensionName in record) {\n return record[dimensionName];\n }\n }\n }\n\n return undefined;\n};\n\nexport const encodedDimensionLabel = (\n ref: number | string,\n dimensionNames: string[] | undefined,\n fallback: string,\n): string => {\n if (typeof ref === 'string') {\n return ref;\n }\n\n const dimensionName = dimensionNames?.[ref];\n\n if (typeof dimensionName === 'string' && dimensionName.length > 0) {\n return dimensionName;\n }\n\n return fallback;\n};\n\n/**\n * Dimensions holding the unique per-point value: `encode.tooltip` first, then\n * `encode.itemName`, and finally any dimension the axes do not already use.\n */\nexport const extraTooltipRefs = (\n point: ScatterTooltipPoint,\n): Array<number | string> => {\n const xRefs = encodeRefs(point.encode, 'x');\n const yRefs = encodeRefs(point.encode, 'y');\n const isAxisRef = (ref: number | string) =>\n xRefs.includes(ref) || yRefs.includes(ref);\n\n const tooltipRefs = encodeRefs(point.encode, 'tooltip').filter(\n (ref) => !isAxisRef(ref),\n );\n\n if (tooltipRefs.length > 0) {\n return tooltipRefs;\n }\n\n const itemNameRefs = encodeRefs(point.encode, 'itemName');\n\n if (itemNameRefs.length > 0) {\n return itemNameRefs;\n }\n\n if (Array.isArray(point.value) && point.value.length > 2) {\n const usedIndices = new Set(\n [...xRefs, ...yRefs].filter(\n (ref): ref is number => typeof ref === 'number',\n ),\n );\n\n if (usedIndices.size === 0) {\n usedIndices.add(0);\n usedIndices.add(1);\n }\n\n return point.value.flatMap((_value, index) =>\n usedIndices.has(index) ? [] : [index],\n );\n }\n\n return [];\n};\n\nexport const getEncodedAxisRefs = (encode: TooltipEncode) => ({\n // oxlint-disable-next-line id-length\n x: encodeRefs(encode, 'x')[0] ?? 0,\n // oxlint-disable-next-line id-length\n y: encodeRefs(encode, 'y')[0] ?? 1,\n});\n\nconst toStringArray = (value: unknown): string[] | undefined =>\n Array.isArray(value) && value.every((entry) => typeof entry === 'string')\n ? value\n : undefined;\n\nconst isHeaderRow = (row: unknown): boolean =>\n Array.isArray(row) &&\n row.length > 0 &&\n row.every((cell) => typeof cell === 'string');\n\ntype ScatterSource = {\n dimensionNames?: string[];\n rows: unknown[];\n};\n\n/**\n * Resolves the rows a series draws, together with the dimension names its\n * `encode` refers to. Rows are aligned with ECharts' data indices, so a sniffed\n * header row is dropped the way ECharts drops it.\n */\nconst resolveSeriesSource = (\n series: ScatterSeriesLike,\n datasets: DatasetLike[],\n): ScatterSource | undefined => {\n const inlineData = Array.isArray(series.data) ? series.data : undefined;\n const dataset =\n inlineData === undefined ? datasets[series.datasetIndex ?? 0] : undefined;\n const rows =\n inlineData ?? (Array.isArray(dataset?.source) ? dataset.source : undefined);\n\n if (rows === undefined) {\n return undefined;\n }\n\n const declaredDimensions = toStringArray(\n series.dimensions ?? dataset?.dimensions,\n );\n\n if (declaredDimensions !== undefined) {\n return { dimensionNames: declaredDimensions, rows };\n }\n\n if (isHeaderRow(rows[0]) && !isHeaderRow(rows[1])) {\n return { dimensionNames: rows[0] as string[], rows: rows.slice(1) };\n }\n\n return { rows };\n};\n\nconst toNumericValue = (value: unknown): number | undefined => {\n if (typeof value === 'number') {\n return Number.isFinite(value) ? value : undefined;\n }\n\n if (value instanceof Date) {\n return value.getTime();\n }\n\n if (typeof value === 'string') {\n const numeric = Number(value);\n\n if (Number.isFinite(numeric)) {\n return numeric;\n }\n\n const time = Date.parse(value);\n\n return Number.isFinite(time) ? time : undefined;\n }\n\n return undefined;\n};\n\n/**\n * Distance from the hovered value along one axis, as a share of the tolerance.\n * Values that cannot be compared numerically, such as category labels, only\n * count as near when they are identical.\n */\nconst axisDistance = (\n value: unknown,\n hoveredValue: unknown,\n tolerance: number,\n): number | undefined => {\n const numeric = toNumericValue(value);\n const hoveredNumeric = toNumericValue(hoveredValue);\n\n if (numeric === undefined || hoveredNumeric === undefined) {\n return value === hoveredValue ? 0 : undefined;\n }\n\n if (tolerance <= 0) {\n return numeric === hoveredNumeric ? 0 : undefined;\n }\n\n return (numeric - hoveredNumeric) / tolerance;\n};\n\nconst isCoordinatePair = (value: number | number[]): value is number[] =>\n Array.isArray(value) &&\n value.length >= 2 &&\n Number.isFinite(value[0]) &&\n Number.isFinite(value[1]);\n\n/**\n * Converts a pixel radius around the hovered point into a distance on each\n * axis, so points can be compared in data space instead of converting every\n * one of them to pixels.\n */\nconst getAxisTolerances = (\n chart: ScatterTooltipChart,\n seriesIndex: number,\n hoveredValue: unknown[],\n radius: number,\n) => {\n const finder = { seriesIndex };\n const pixel = chart.convertToPixel(finder, hoveredValue);\n\n if (!isCoordinatePair(pixel)) {\n return undefined;\n }\n\n const origin = chart.convertFromPixel(finder, [pixel[0], pixel[1]]);\n const offset = chart.convertFromPixel(finder, [\n pixel[0] + radius,\n pixel[1] + radius,\n ]);\n\n if (!isCoordinatePair(origin) || !isCoordinatePair(offset)) {\n return undefined;\n }\n\n return {\n // oxlint-disable-next-line id-length\n x: Math.abs(offset[0] - origin[0]),\n // oxlint-disable-next-line id-length\n y: Math.abs(offset[1] - origin[1]),\n };\n};\n\n/**\n * Widest scatter symbol in the chart, which doubles as the radius in which\n * points are considered to overlap the hovered one.\n */\nexport function getScatterSymbolSize(series: EchartsSeries): number {\n const sizes = toArray(series as ScatterSeriesLike | ScatterSeriesLike[])\n .filter((seriesOption) => seriesOption?.type === 'scatter')\n .map((seriesOption) =>\n typeof seriesOption.symbolSize === 'number' &&\n Number.isFinite(seriesOption.symbolSize)\n ? seriesOption.symbolSize\n : DEFAULT_SYMBOL_SIZE,\n );\n\n return sizes.length > 0 ? Math.max(...sizes) : DEFAULT_SYMBOL_SIZE;\n}\n\ntype FindNearbyScatterPointsParams = {\n chart: ScatterTooltipChart | undefined;\n dataset: ChartProps['dataset'];\n hovered: ScatterTooltipPoint;\n legendSelected?: Record<string, boolean>;\n maxPoints: number;\n radius: number;\n series: EchartsSeries;\n};\n\n/**\n * Collects the points whose symbols overlap the hovered one, closest first,\n * with the hovered point always leading.\n *\n * Distances are measured in data space against a tolerance derived from the\n * pixel radius (ECharts `convertToPixel` / `convertFromPixel`), which keeps the\n * scan to plain arithmetic per point and works on value, time, and log axes\n * alike.\n */\nexport function findNearbyScatterPoints({\n chart,\n dataset,\n hovered,\n legendSelected,\n maxPoints,\n radius,\n series,\n}: FindNearbyScatterPointsParams): ScatterTooltipPoint[] {\n const hoveredSeriesIndex = hovered.seriesIndex;\n\n if (chart === undefined || hoveredSeriesIndex === undefined) {\n return [hovered];\n }\n\n const hoveredRefs = getEncodedAxisRefs(hovered.encode);\n const hoveredX = readEncodedValue(\n hovered.value,\n hoveredRefs.x,\n hovered.dimensionNames,\n );\n const hoveredY = readEncodedValue(\n hovered.value,\n hoveredRefs.y,\n hovered.dimensionNames,\n );\n const tolerances = getAxisTolerances(\n chart,\n hoveredSeriesIndex,\n [hoveredX, hoveredY],\n radius,\n );\n\n if (tolerances === undefined) {\n return [hovered];\n }\n\n const seriesList = toArray(series) as ScatterSeriesLike[];\n const datasets = toArray(dataset) as DatasetLike[];\n const neighbors: Array<{ distance: number; point: ScatterTooltipPoint }> = [];\n let scannedPoints = 0;\n\n for (const [seriesIndex, seriesOption] of seriesList.entries()) {\n if (\n seriesOption?.type !== 'scatter' ||\n legendSelected?.[seriesOption.name ?? ''] === false\n ) {\n continue;\n }\n\n const source = resolveSeriesSource(seriesOption, datasets);\n\n if (source === undefined) {\n continue;\n }\n\n const refs = getEncodedAxisRefs(seriesOption.encode);\n\n for (const [dataIndex, row] of source.rows.entries()) {\n if (scannedPoints >= MAX_SCANNED_POINTS) {\n break;\n }\n\n scannedPoints += 1;\n\n if (\n seriesIndex === hoveredSeriesIndex &&\n dataIndex === hovered.dataIndex\n ) {\n continue;\n }\n\n const xDistance = axisDistance(\n readEncodedValue(row, refs.x, source.dimensionNames),\n hoveredX,\n tolerances.x,\n );\n const yDistance = axisDistance(\n readEncodedValue(row, refs.y, source.dimensionNames),\n hoveredY,\n tolerances.y,\n );\n\n if (xDistance === undefined || yDistance === undefined) {\n continue;\n }\n\n const distance = Math.hypot(xDistance, yDistance);\n\n if (distance > 1) {\n continue;\n }\n\n neighbors.push({\n distance,\n point: {\n color:\n typeof seriesOption.color === 'string'\n ? seriesOption.color\n : undefined,\n dataIndex,\n dimensionNames: source.dimensionNames,\n encode: seriesOption.encode,\n seriesIndex,\n seriesName: seriesOption.name,\n value: row,\n },\n });\n }\n }\n\n neighbors.sort((first, second) => first.distance - second.distance);\n\n return [\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WAAW,SAAS;GAEhD,IAAI,WAAW,GACb;GAGF,UAAU,KAAK;IACb;IACA,OAAO;KACL,OACE,OAAO,aAAa,UAAU,WAC1B,aAAa,QACb,KAAA;KACN;KACA,gBAAgB,OAAO;KACvB,QAAQ,aAAa;KACrB;KACA,YAAY,aAAa;KACzB,OAAO;IACT;GACF,CAAC;EACH;CACF;CAEA,UAAU,MAAM,OAAO,WAAW,MAAM,WAAW,OAAO,QAAQ;CAElE,OAAO,CACL,SACA,GAAG,UAAU,MAAM,GAAG,KAAK,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,CAC5E;AACF"}
@@ -0,0 +1,92 @@
1
+ import { defaultThresholdLineSeriesOption } from "./defaults.mjs";
2
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs";
3
+ // src/charts/utils/threshold.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
+ const isThresholdLine = (name) => name === null || name === void 0 ? void 0 : name.startsWith("thresholdLine");
25
+ const getThresholdLineDisplayName = (name) => name.replace("thresholdLine-", "");
26
+ /**
27
+ * Extracts threshold-line series and resolves defaults needed by tooltips.
28
+ */
29
+ function normalizeThresholdLines(propsSeries) {
30
+ return (Array.isArray(propsSeries) ? propsSeries : [propsSeries]).filter((currentSeries) => {
31
+ return currentSeries.type === "thresholdLine";
32
+ }).map((currentThresholdLineSeriesOption) => {
33
+ var _currentThresholdLine;
34
+ return _objectSpread2(_objectSpread2({}, currentThresholdLineSeriesOption), {}, {
35
+ condition: (_currentThresholdLine = currentThresholdLineSeriesOption.condition) !== null && _currentThresholdLine !== void 0 ? _currentThresholdLine : defaultThresholdLineSeriesOption.condition,
36
+ value: currentThresholdLineSeriesOption.yAxis
37
+ });
38
+ });
39
+ }
40
+ /**
41
+ * Evaluates a threshold condition and returns the short label used by
42
+ * chart tooltip notifications.
43
+ */
44
+ function evaluateThresholdCondition(value, condition, threshold) {
45
+ switch (condition) {
46
+ case "greater": return {
47
+ conditionText: "Above",
48
+ isConditionMet: value > threshold
49
+ };
50
+ case "greaterOrEqual": return {
51
+ conditionText: value > threshold ? "Above" : value === threshold ? "Equal" : void 0,
52
+ isConditionMet: value >= threshold
53
+ };
54
+ case "less": return {
55
+ conditionText: "Below",
56
+ isConditionMet: value < threshold
57
+ };
58
+ case "lessOrEqual": return {
59
+ conditionText: value < threshold ? "Below" : value === threshold ? "Equal" : void 0,
60
+ isConditionMet: value <= threshold
61
+ };
62
+ case "equal": return {
63
+ conditionText: "Equal",
64
+ isConditionMet: value === threshold
65
+ };
66
+ case "notEqual": return {
67
+ conditionText: "Not equal",
68
+ isConditionMet: value !== threshold
69
+ };
70
+ default: return {
71
+ conditionText: void 0,
72
+ isConditionMet: false
73
+ };
74
+ }
75
+ }
76
+ /**
77
+ * Returns the longer condition phrase used in chart aria descriptions.
78
+ */
79
+ function thresholdConditionToText(condition) {
80
+ switch (condition) {
81
+ case "greater": return "greater than";
82
+ case "greaterOrEqual": return "greater than or equal to";
83
+ case "less": return "less than";
84
+ case "lessOrEqual": return "less than or equal to";
85
+ case "equal": return "equal to";
86
+ case "notEqual": return "not equal to";
87
+ default: return "compared to";
88
+ }
89
+ }
90
+ export { evaluateThresholdCondition, getThresholdLineDisplayName, isThresholdLine, normalizeThresholdLines, thresholdConditionToText };
91
+
92
+ //# sourceMappingURL=threshold.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threshold.mjs","names":[],"sources":["../../../../src/charts/utils/threshold.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 {\n Condition,\n NeedleSeries,\n NotificationType,\n ThresholdLineSeriesOption,\n} from './chart-types';\nimport { defaultThresholdLineSeriesOption } from './defaults';\n\nexport type NormalizedThresholdLine =\n ThresholdLineSeriesOption<NotificationType> & {\n condition: NonNullable<\n ThresholdLineSeriesOption<NotificationType>['condition']\n >;\n value: number;\n };\n\nexport type ThresholdConditionEvaluation = {\n isConditionMet: boolean;\n conditionText: string | undefined;\n};\n\nexport const isThresholdLine = (name?: string) =>\n name?.startsWith('thresholdLine');\n\nexport const getThresholdLineDisplayName = (name: string) =>\n name.replace('thresholdLine-', '');\n\n/**\n * Extracts threshold-line series and resolves defaults needed by tooltips.\n */\nexport function normalizeThresholdLines(\n propsSeries: NeedleSeries,\n): NormalizedThresholdLine[] {\n const seriesArray = Array.isArray(propsSeries) ? propsSeries : [propsSeries];\n\n const thresholdLineSeries = seriesArray.filter((currentSeries) => {\n return currentSeries.type === 'thresholdLine';\n }) as ThresholdLineSeriesOption<NotificationType>[];\n\n return thresholdLineSeries.map((currentThresholdLineSeriesOption) => {\n return {\n ...currentThresholdLineSeriesOption,\n condition:\n currentThresholdLineSeriesOption.condition ??\n defaultThresholdLineSeriesOption.condition,\n value: currentThresholdLineSeriesOption.yAxis,\n };\n });\n}\n\n/**\n * Evaluates a threshold condition and returns the short label used by\n * chart tooltip notifications.\n */\nexport function evaluateThresholdCondition(\n value: number,\n condition: Condition,\n threshold: number,\n): ThresholdConditionEvaluation {\n switch (condition) {\n case 'greater':\n return {\n conditionText: 'Above',\n isConditionMet: value > threshold,\n };\n case 'greaterOrEqual':\n return {\n conditionText:\n value > threshold\n ? 'Above'\n : value === threshold\n ? 'Equal'\n : undefined,\n isConditionMet: value >= threshold,\n };\n case 'less':\n return {\n conditionText: 'Below',\n isConditionMet: value < threshold,\n };\n case 'lessOrEqual':\n return {\n conditionText:\n value < threshold\n ? 'Below'\n : value === threshold\n ? 'Equal'\n : undefined,\n isConditionMet: value <= threshold,\n };\n case 'equal':\n return {\n conditionText: 'Equal',\n isConditionMet: value === threshold,\n };\n case 'notEqual':\n return {\n conditionText: 'Not equal',\n isConditionMet: value !== threshold,\n };\n default:\n return { conditionText: undefined, isConditionMet: false };\n }\n}\n\n/**\n * Returns the longer condition phrase used in chart aria descriptions.\n */\nexport function thresholdConditionToText(condition: Condition): string {\n switch (condition) {\n case 'greater':\n return 'greater than';\n case 'greaterOrEqual':\n return 'greater than or equal to';\n case 'less':\n return 'less than';\n case 'lessOrEqual':\n return 'less than or equal to';\n case 'equal':\n return 'equal to';\n case 'notEqual':\n return 'not equal to';\n default:\n return 'compared to';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,mBAAmB,SAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAC9B,KAAM,WAAW,eAAe;AAElC,MAAa,+BAA+B,SAC1C,KAAK,QAAQ,kBAAkB,EAAE;;;;AAKnC,SAAgB,wBACd,aAC2B;CAO3B,QANoB,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW,EAAA,CAEnC,QAAQ,kBAAkB;EAChE,OAAO,cAAc,SAAS;CAChC,CAEyB,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