@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.
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
@@ -1,187 +1,156 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ const require_charts_utils_threshold = require("../utils/threshold.js");
7
+ const require_charts_hooks_use_chart_refs = require("./use-chart-refs.js");
8
+ let react = require("react");
9
+ let echarts = require("echarts");
10
+ // src/charts/hooks/use-legend-series.ts
2
11
  /*!
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
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.useLegendSeries = useLegendSeries;
24
- const echarts_1 = require("echarts");
25
- const react_1 = require("react");
26
- const threshold_1 = require("../utils/threshold");
27
- const use_chart_refs_1 = require("./use-chart-refs");
28
- const isThresholdLineSeries = (series) => series.type === 'line' &&
29
- typeof series.name === 'string' &&
30
- (0, threshold_1.isThresholdLine)(series.name);
12
+ *
13
+ * Copyright (c) "Neo4j"
14
+ * Neo4j Sweden AB [http://neo4j.com]
15
+ *
16
+ * This file is part of Neo4j.
17
+ *
18
+ * Neo4j is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU General Public License as published by
20
+ * the Free Software Foundation, either version 3 of the License, or
21
+ * (at your option) any later version.
22
+ *
23
+ * This program is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU General Public License
29
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+ */
31
+ const isThresholdLineSeries = (series) => series.type === "line" && typeof series.name === "string" && require_charts_utils_threshold.isThresholdLine(series.name);
31
32
  const getDatasetForSeries = (optionDataset, series) => {
32
- const datasetList = Array.isArray(optionDataset)
33
- ? optionDataset
34
- : [optionDataset];
35
- if (series.datasetId && Array.isArray(optionDataset)) {
36
- return datasetList.find((dataset) => (dataset === null || dataset === void 0 ? void 0 : dataset.id) === series.datasetId);
37
- }
38
- if (series.datasetIndex !== undefined) {
39
- return datasetList[series.datasetIndex];
40
- }
41
- return datasetList[0];
33
+ const datasetList = Array.isArray(optionDataset) ? optionDataset : [optionDataset];
34
+ if (series.datasetId && Array.isArray(optionDataset)) return datasetList.find((dataset) => (dataset === null || dataset === void 0 ? void 0 : dataset.id) === series.datasetId);
35
+ if (series.datasetIndex !== void 0) return datasetList[series.datasetIndex];
36
+ return datasetList[0];
42
37
  };
43
- const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
44
- const getCachedLegendColor = ({ chart, isAllVisible, legendColorCacheRef, name, seriesIndex, dataIndexInside, }) => {
45
- var _a;
46
- const freshColor = chart === null || chart === void 0 ? void 0 : chart.getVisual({ dataIndexInside, seriesIndex }, 'color');
47
- if (isAllVisible && typeof freshColor === 'string') {
48
- legendColorCacheRef.current.set(name, freshColor);
49
- }
50
- return ((_a = legendColorCacheRef.current.get(name)) !== null && _a !== void 0 ? _a : (typeof freshColor === 'string' ? freshColor : '#000000'));
38
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
39
+ const getCachedLegendColor = ({ chart, isAllVisible, legendColorCacheRef, name, seriesIndex, dataIndexInside }) => {
40
+ var _legendColorCacheRef$;
41
+ const freshColor = chart === null || chart === void 0 ? void 0 : chart.getVisual({
42
+ dataIndexInside,
43
+ seriesIndex
44
+ }, "color");
45
+ if (isAllVisible && typeof freshColor === "string") legendColorCacheRef.current.set(name, freshColor);
46
+ return (_legendColorCacheRef$ = legendColorCacheRef.current.get(name)) !== null && _legendColorCacheRef$ !== void 0 ? _legendColorCacheRef$ : typeof freshColor === "string" ? freshColor : "#000000";
51
47
  };
52
- const createPieLegendSeriesItem = ({ chart, dataIndexInside, isAllVisible, legendColorCacheRef, name, seriesIndex, }) => ({
53
- color: getCachedLegendColor({
54
- chart,
55
- dataIndexInside,
56
- isAllVisible,
57
- legendColorCacheRef,
58
- name,
59
- seriesIndex,
60
- }),
61
- name,
48
+ const createPieLegendSeriesItem = ({ chart, dataIndexInside, isAllVisible, legendColorCacheRef, name, seriesIndex }) => ({
49
+ color: getCachedLegendColor({
50
+ chart,
51
+ dataIndexInside,
52
+ isAllVisible,
53
+ legendColorCacheRef,
54
+ name,
55
+ seriesIndex
56
+ }),
57
+ name
62
58
  });
63
- const getPieLegendSeriesFromArrayRows = ({ chart, dataset, encodedItemName, isAllVisible, legendColorCacheRef, seriesIndex, }) => {
64
- const source = dataset === null || dataset === void 0 ? void 0 : dataset.source;
65
- if (!Array.isArray(source) || !Array.isArray(source[0])) {
66
- return [];
67
- }
68
- const itemNameIndex = source[0].findIndex((item) => item === encodedItemName);
69
- if (itemNameIndex === -1) {
70
- return [];
71
- }
72
- return source.slice(1).flatMap((row, rowIndex) => {
73
- if (!Array.isArray(row)) {
74
- return [];
75
- }
76
- return createPieLegendSeriesItem({
77
- chart,
78
- dataIndexInside: rowIndex,
79
- isAllVisible,
80
- legendColorCacheRef,
81
- name: String(row[itemNameIndex]),
82
- seriesIndex,
83
- });
84
- });
59
+ const getPieLegendSeriesFromArrayRows = ({ chart, dataset, encodedItemName, isAllVisible, legendColorCacheRef, seriesIndex }) => {
60
+ const source = dataset === null || dataset === void 0 ? void 0 : dataset.source;
61
+ if (!Array.isArray(source) || !Array.isArray(source[0])) return [];
62
+ const itemNameIndex = source[0].findIndex((item) => item === encodedItemName);
63
+ if (itemNameIndex === -1) return [];
64
+ return source.slice(1).flatMap((row, rowIndex) => {
65
+ if (!Array.isArray(row)) return [];
66
+ return createPieLegendSeriesItem({
67
+ chart,
68
+ dataIndexInside: rowIndex,
69
+ isAllVisible,
70
+ legendColorCacheRef,
71
+ name: String(row[itemNameIndex]),
72
+ seriesIndex
73
+ });
74
+ });
85
75
  };
86
- const getPieLegendSeriesFromObjectRows = ({ chart, dataset, encodedItemName, isAllVisible, legendColorCacheRef, seriesIndex, }) => {
87
- const source = dataset === null || dataset === void 0 ? void 0 : dataset.source;
88
- if (!Array.isArray(source) || typeof encodedItemName !== 'string') {
89
- return [];
90
- }
91
- return source.flatMap((row, rowIndex) => {
92
- if (!isRecord(row) || !(encodedItemName in row)) {
93
- return [];
94
- }
95
- return createPieLegendSeriesItem({
96
- chart,
97
- dataIndexInside: rowIndex,
98
- isAllVisible,
99
- legendColorCacheRef,
100
- name: String(row[encodedItemName]),
101
- seriesIndex,
102
- });
103
- });
76
+ const getPieLegendSeriesFromObjectRows = ({ chart, dataset, encodedItemName, isAllVisible, legendColorCacheRef, seriesIndex }) => {
77
+ const source = dataset === null || dataset === void 0 ? void 0 : dataset.source;
78
+ if (!Array.isArray(source) || typeof encodedItemName !== "string") return [];
79
+ return source.flatMap((row, rowIndex) => {
80
+ if (!isRecord(row) || !(encodedItemName in row)) return [];
81
+ return createPieLegendSeriesItem({
82
+ chart,
83
+ dataIndexInside: rowIndex,
84
+ isAllVisible,
85
+ legendColorCacheRef,
86
+ name: String(row[encodedItemName]),
87
+ seriesIndex
88
+ });
89
+ });
104
90
  };
105
91
  const getPieLegendSeries = (params) => {
106
- var _a;
107
- const source = (_a = params.dataset) === null || _a === void 0 ? void 0 : _a.source;
108
- if (!Array.isArray(source) || source.length === 0) {
109
- return [];
110
- }
111
- return Array.isArray(source[0])
112
- ? getPieLegendSeriesFromArrayRows(params)
113
- : getPieLegendSeriesFromObjectRows(params);
92
+ var _params$dataset;
93
+ const source = (_params$dataset = params.dataset) === null || _params$dataset === void 0 ? void 0 : _params$dataset.source;
94
+ if (!Array.isArray(source) || source.length === 0) return [];
95
+ return Array.isArray(source[0]) ? getPieLegendSeriesFromArrayRows(params) : getPieLegendSeriesFromObjectRows(params);
114
96
  };
115
97
  /**
116
- * Derives Needle legend rows from ECharts' normalized option and visual state.
117
- *
118
- * Standard series map one-to-one with legend items. Pie charts instead create a
119
- * legend item for each data row, so the hook reads the encoded item-name column
120
- * from the dataset and asks ECharts for each slice color. Fresh colors are
121
- * cached while all slices are visible because ECharts reports dimmed colors for
122
- * deselected slices.
123
- *
124
- * The hook waits until the first chart resize has completed so color lookups run
125
- * against an initialized ECharts instance.
126
- */
127
- function useLegendSeries({ chartOption, isWaitingForFirstResize, }) {
128
- const { chartEchartRef, legendColorCacheRef, legendSelectedRef } = (0, use_chart_refs_1.useChartRefsContext)();
129
- return (0, react_1.useMemo)(() => {
130
- var _a;
131
- if (chartEchartRef.current === null || isWaitingForFirstResize) {
132
- return;
133
- }
134
- const chart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
135
- const optionSeries = (_a = chartOption === null || chartOption === void 0 ? void 0 : chartOption.series) !== null && _a !== void 0 ? _a : [];
136
- const optionDataset = chartOption === null || chartOption === void 0 ? void 0 : chartOption.dataset;
137
- const isAllLegendSeriesVisible = Object.values(legendSelectedRef.current).every((isVisible) => isVisible);
138
- const legendSeries = [];
139
- if (Array.isArray(optionSeries)) {
140
- optionSeries.forEach((currentSeries, index) => {
141
- var _a;
142
- if (currentSeries === null) {
143
- return;
144
- }
145
- else if (isThresholdLineSeries(currentSeries)) {
146
- return;
147
- }
148
- else if (currentSeries.type === 'pie') {
149
- legendSeries.push(...getPieLegendSeries({
150
- chart,
151
- dataset: getDatasetForSeries(optionDataset, currentSeries),
152
- encodedItemName: (_a = currentSeries.encode) === null || _a === void 0 ? void 0 : _a.itemName,
153
- isAllVisible: isAllLegendSeriesVisible,
154
- legendColorCacheRef,
155
- seriesIndex: index,
156
- }));
157
- return;
158
- }
159
- else {
160
- const name = currentSeries.name;
161
- if (name === undefined) {
162
- return;
163
- }
164
- // A scatter point's fill is the theme surface color, so the visual
165
- // color is not the series color. The series color is the ring.
166
- const visualColor = chart === null || chart === void 0 ? void 0 : chart.getVisual({ seriesIndex: index }, 'color');
167
- const seriesColor = currentSeries.color;
168
- const color = currentSeries.type === 'scatter' && typeof seriesColor === 'string'
169
- ? seriesColor
170
- : visualColor;
171
- legendSeries.push({
172
- color: typeof color === 'string' ? color : '#000000',
173
- name: String(name),
174
- });
175
- }
176
- });
177
- }
178
- return legendSeries;
179
- }, [
180
- chartEchartRef,
181
- chartOption,
182
- isWaitingForFirstResize,
183
- legendColorCacheRef,
184
- legendSelectedRef,
185
- ]);
98
+ * Derives Needle legend rows from ECharts' normalized option and visual state.
99
+ *
100
+ * Standard series map one-to-one with legend items. Pie charts instead create a
101
+ * legend item for each data row, so the hook reads the encoded item-name column
102
+ * from the dataset and asks ECharts for each slice color. Fresh colors are
103
+ * cached while all slices are visible because ECharts reports dimmed colors for
104
+ * deselected slices.
105
+ *
106
+ * The hook waits until the first chart resize has completed so color lookups run
107
+ * against an initialized ECharts instance.
108
+ */
109
+ function useLegendSeries({ chartOption, isWaitingForFirstResize }) {
110
+ const { chartEchartRef, legendColorCacheRef, legendSelectedRef } = require_charts_hooks_use_chart_refs.useChartRefsContext();
111
+ return (0, react.useMemo)(() => {
112
+ var _ref;
113
+ if (chartEchartRef.current === null || isWaitingForFirstResize) return;
114
+ const chart = (0, echarts.getInstanceByDom)(chartEchartRef.current);
115
+ const optionSeries = (_ref = chartOption === null || chartOption === void 0 ? void 0 : chartOption.series) !== null && _ref !== void 0 ? _ref : [];
116
+ const optionDataset = chartOption === null || chartOption === void 0 ? void 0 : chartOption.dataset;
117
+ const isAllLegendSeriesVisible = Object.values(legendSelectedRef.current).every((isVisible) => isVisible);
118
+ const legendSeries = [];
119
+ if (Array.isArray(optionSeries)) optionSeries.forEach((currentSeries, index) => {
120
+ if (currentSeries === null) return;
121
+ else if (isThresholdLineSeries(currentSeries)) return;
122
+ else if (currentSeries.type === "pie") {
123
+ var _currentSeries$encode;
124
+ legendSeries.push(...getPieLegendSeries({
125
+ chart,
126
+ dataset: getDatasetForSeries(optionDataset, currentSeries),
127
+ encodedItemName: (_currentSeries$encode = currentSeries.encode) === null || _currentSeries$encode === void 0 ? void 0 : _currentSeries$encode.itemName,
128
+ isAllVisible: isAllLegendSeriesVisible,
129
+ legendColorCacheRef,
130
+ seriesIndex: index
131
+ }));
132
+ return;
133
+ } else {
134
+ const name = currentSeries.name;
135
+ if (name === void 0) return;
136
+ const visualColor = chart === null || chart === void 0 ? void 0 : chart.getVisual({ seriesIndex: index }, "color");
137
+ const seriesColor = currentSeries.color;
138
+ const color = currentSeries.type === "scatter" && typeof seriesColor === "string" ? seriesColor : visualColor;
139
+ legendSeries.push({
140
+ color: typeof color === "string" ? color : "#000000",
141
+ name: String(name)
142
+ });
143
+ }
144
+ });
145
+ return legendSeries;
146
+ }, [
147
+ chartEchartRef,
148
+ chartOption,
149
+ isWaitingForFirstResize,
150
+ legendColorCacheRef,
151
+ legendSelectedRef
152
+ ]);
186
153
  }
154
+ exports.useLegendSeries = useLegendSeries;
155
+
187
156
  //# sourceMappingURL=use-legend-series.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-legend-series.js","sourceRoot":"","sources":["../../../../src/charts/hooks/use-legend-series.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AA2MH,0CAuEC;AA3QD,qCAA2C;AAC3C,iCAAgC;AAOhC,kDAAqD;AACrD,qDAAuE;AAgCvE,MAAM,qBAAqB,GAAG,CAAC,MAAwB,EAAE,EAAE,CACzD,MAAM,CAAC,IAAI,KAAK,MAAM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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 DatasetComponentOption,\n EChartsOption,\n EChartsType,\n} from 'echarts';\nimport { getInstanceByDom } from 'echarts';\nimport { useMemo } from 'react';\n\nimport type {\n LegendProps,\n NeedleSeries,\n SeriesOption,\n} from '../utils/chart-types';\nimport { isThresholdLine } from '../utils/threshold';\nimport { type ChartRefs, useChartRefsContext } from './use-chart-refs';\n\ntype UseLegendSeriesParams = {\n chartOption: EChartsOption | undefined;\n isWaitingForFirstResize: boolean;\n};\n\ntype LegendSeries = LegendProps['series'];\ntype NeedleSeriesItem = NeedleSeries[number];\ntype SeriesWithDataset = SeriesOption & {\n datasetId?: string;\n datasetIndex?: number;\n};\n\ntype PieLegendSeriesParams = {\n chart: EChartsType | undefined;\n dataset: DatasetComponentOption | undefined;\n encodedItemName: unknown;\n isAllVisible: boolean;\n legendColorCacheRef: ChartRefs['legendColorCacheRef'];\n seriesIndex: number;\n};\n\ntype GetCachedLegendColorParams = {\n chart: EChartsType | undefined;\n dataIndexInside: number;\n isAllVisible: boolean;\n legendColorCacheRef: ChartRefs['legendColorCacheRef'];\n name: string;\n seriesIndex: number;\n};\n\nconst isThresholdLineSeries = (series: NeedleSeriesItem) =>\n series.type === 'line' &&\n typeof series.name === 'string' &&\n isThresholdLine(series.name);\n\nconst getDatasetForSeries = (\n optionDataset: EChartsOption['dataset'],\n series: SeriesWithDataset,\n) => {\n const datasetList = Array.isArray(optionDataset)\n ? optionDataset\n : [optionDataset];\n\n if (series.datasetId && Array.isArray(optionDataset)) {\n return datasetList.find((dataset) => dataset?.id === series.datasetId);\n }\n\n if (series.datasetIndex !== undefined) {\n return datasetList[series.datasetIndex];\n }\n\n return datasetList[0];\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst getCachedLegendColor = ({\n chart,\n isAllVisible,\n legendColorCacheRef,\n name,\n seriesIndex,\n dataIndexInside,\n}: GetCachedLegendColorParams) => {\n const freshColor = chart?.getVisual(\n { dataIndexInside, seriesIndex },\n 'color',\n );\n\n if (isAllVisible && typeof freshColor === 'string') {\n legendColorCacheRef.current.set(name, freshColor);\n }\n\n return (\n legendColorCacheRef.current.get(name) ??\n (typeof freshColor === 'string' ? freshColor : '#000000')\n );\n};\n\nconst createPieLegendSeriesItem = ({\n chart,\n dataIndexInside,\n isAllVisible,\n legendColorCacheRef,\n name,\n seriesIndex,\n}: GetCachedLegendColorParams) => ({\n color: getCachedLegendColor({\n chart,\n dataIndexInside,\n isAllVisible,\n legendColorCacheRef,\n name,\n seriesIndex,\n }),\n name,\n});\n\nconst getPieLegendSeriesFromArrayRows = ({\n chart,\n dataset,\n encodedItemName,\n isAllVisible,\n legendColorCacheRef,\n seriesIndex,\n}: PieLegendSeriesParams): LegendSeries => {\n const source = dataset?.source;\n if (!Array.isArray(source) || !Array.isArray(source[0])) {\n return [];\n }\n\n const itemNameIndex = source[0].findIndex((item) => item === encodedItemName);\n if (itemNameIndex === -1) {\n return [];\n }\n\n return source.slice(1).flatMap((row, rowIndex) => {\n if (!Array.isArray(row)) {\n return [];\n }\n\n return createPieLegendSeriesItem({\n chart,\n dataIndexInside: rowIndex,\n isAllVisible,\n legendColorCacheRef,\n name: String(row[itemNameIndex]),\n seriesIndex,\n });\n });\n};\n\nconst getPieLegendSeriesFromObjectRows = ({\n chart,\n dataset,\n encodedItemName,\n isAllVisible,\n legendColorCacheRef,\n seriesIndex,\n}: PieLegendSeriesParams): LegendSeries => {\n const source = dataset?.source;\n if (!Array.isArray(source) || typeof encodedItemName !== 'string') {\n return [];\n }\n\n return source.flatMap((row, rowIndex) => {\n if (!isRecord(row) || !(encodedItemName in row)) {\n return [];\n }\n\n return createPieLegendSeriesItem({\n chart,\n dataIndexInside: rowIndex,\n isAllVisible,\n legendColorCacheRef,\n name: String(row[encodedItemName]),\n seriesIndex,\n });\n });\n};\n\nconst getPieLegendSeries = (params: PieLegendSeriesParams): LegendSeries => {\n const source = params.dataset?.source;\n if (!Array.isArray(source) || source.length === 0) {\n return [];\n }\n\n return Array.isArray(source[0])\n ? getPieLegendSeriesFromArrayRows(params)\n : getPieLegendSeriesFromObjectRows(params);\n};\n\n/**\n * Derives Needle legend rows from ECharts' normalized option and visual state.\n *\n * Standard series map one-to-one with legend items. Pie charts instead create a\n * legend item for each data row, so the hook reads the encoded item-name column\n * from the dataset and asks ECharts for each slice color. Fresh colors are\n * cached while all slices are visible because ECharts reports dimmed colors for\n * deselected slices.\n *\n * The hook waits until the first chart resize has completed so color lookups run\n * against an initialized ECharts instance.\n */\nexport function useLegendSeries({\n chartOption,\n isWaitingForFirstResize,\n}: UseLegendSeriesParams): LegendSeries | undefined {\n const { chartEchartRef, legendColorCacheRef, legendSelectedRef } =\n useChartRefsContext();\n\n return useMemo(() => {\n if (chartEchartRef.current === null || isWaitingForFirstResize) {\n return;\n }\n\n const chart = getInstanceByDom(chartEchartRef.current);\n const optionSeries = (chartOption?.series as NeedleSeries) ?? [];\n const optionDataset = chartOption?.dataset;\n const isAllLegendSeriesVisible = Object.values(\n legendSelectedRef.current,\n ).every((isVisible) => isVisible);\n\n const legendSeries: LegendSeries = [];\n if (Array.isArray(optionSeries)) {\n optionSeries.forEach((currentSeries, index) => {\n if (currentSeries === null) {\n return;\n } else if (isThresholdLineSeries(currentSeries)) {\n return;\n } else if (currentSeries.type === 'pie') {\n legendSeries.push(\n ...getPieLegendSeries({\n chart,\n dataset: getDatasetForSeries(\n optionDataset,\n currentSeries as SeriesWithDataset,\n ),\n encodedItemName: currentSeries.encode?.itemName,\n isAllVisible: isAllLegendSeriesVisible,\n legendColorCacheRef,\n seriesIndex: index,\n }),\n );\n return;\n } else {\n const name = currentSeries.name;\n\n if (name === undefined) {\n return;\n }\n\n // A scatter point's fill is the theme surface color, so the visual\n // color is not the series color. The series color is the ring.\n const visualColor = chart?.getVisual({ seriesIndex: index }, 'color');\n const seriesColor = currentSeries.color;\n const color =\n currentSeries.type === 'scatter' && typeof seriesColor === 'string'\n ? seriesColor\n : visualColor;\n legendSeries.push({\n color: typeof color === 'string' ? color : '#000000',\n name: String(name),\n });\n }\n });\n }\n return legendSeries;\n }, [\n chartEchartRef,\n chartOption,\n isWaitingForFirstResize,\n legendColorCacheRef,\n legendSelectedRef,\n ]);\n}\n"]}
1
+ {"version":3,"file":"use-legend-series.js","names":["isThresholdLine","useChartRefsContext","useMemo","getInstanceByDom"],"sources":["../../../../src/charts/hooks/use-legend-series.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 DatasetComponentOption,\n EChartsOption,\n EChartsType,\n} from 'echarts';\nimport { getInstanceByDom } from 'echarts';\nimport { useMemo } from 'react';\n\nimport type {\n LegendProps,\n NeedleSeries,\n SeriesOption,\n} from '../utils/chart-types';\nimport { isThresholdLine } from '../utils/threshold';\nimport { type ChartRefs, useChartRefsContext } from './use-chart-refs';\n\ntype UseLegendSeriesParams = {\n chartOption: EChartsOption | undefined;\n isWaitingForFirstResize: boolean;\n};\n\ntype LegendSeries = LegendProps['series'];\ntype NeedleSeriesItem = NeedleSeries[number];\ntype SeriesWithDataset = SeriesOption & {\n datasetId?: string;\n datasetIndex?: number;\n};\n\ntype PieLegendSeriesParams = {\n chart: EChartsType | undefined;\n dataset: DatasetComponentOption | undefined;\n encodedItemName: unknown;\n isAllVisible: boolean;\n legendColorCacheRef: ChartRefs['legendColorCacheRef'];\n seriesIndex: number;\n};\n\ntype GetCachedLegendColorParams = {\n chart: EChartsType | undefined;\n dataIndexInside: number;\n isAllVisible: boolean;\n legendColorCacheRef: ChartRefs['legendColorCacheRef'];\n name: string;\n seriesIndex: number;\n};\n\nconst isThresholdLineSeries = (series: NeedleSeriesItem) =>\n series.type === 'line' &&\n typeof series.name === 'string' &&\n isThresholdLine(series.name);\n\nconst getDatasetForSeries = (\n optionDataset: EChartsOption['dataset'],\n series: SeriesWithDataset,\n) => {\n const datasetList = Array.isArray(optionDataset)\n ? optionDataset\n : [optionDataset];\n\n if (series.datasetId && Array.isArray(optionDataset)) {\n return datasetList.find((dataset) => dataset?.id === series.datasetId);\n }\n\n if (series.datasetIndex !== undefined) {\n return datasetList[series.datasetIndex];\n }\n\n return datasetList[0];\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst getCachedLegendColor = ({\n chart,\n isAllVisible,\n legendColorCacheRef,\n name,\n seriesIndex,\n dataIndexInside,\n}: GetCachedLegendColorParams) => {\n const freshColor = chart?.getVisual(\n { dataIndexInside, seriesIndex },\n 'color',\n );\n\n if (isAllVisible && typeof freshColor === 'string') {\n legendColorCacheRef.current.set(name, freshColor);\n }\n\n return (\n legendColorCacheRef.current.get(name) ??\n (typeof freshColor === 'string' ? freshColor : '#000000')\n );\n};\n\nconst createPieLegendSeriesItem = ({\n chart,\n dataIndexInside,\n isAllVisible,\n legendColorCacheRef,\n name,\n seriesIndex,\n}: GetCachedLegendColorParams) => ({\n color: getCachedLegendColor({\n chart,\n dataIndexInside,\n isAllVisible,\n legendColorCacheRef,\n name,\n seriesIndex,\n }),\n name,\n});\n\nconst getPieLegendSeriesFromArrayRows = ({\n chart,\n dataset,\n encodedItemName,\n isAllVisible,\n legendColorCacheRef,\n seriesIndex,\n}: PieLegendSeriesParams): LegendSeries => {\n const source = dataset?.source;\n if (!Array.isArray(source) || !Array.isArray(source[0])) {\n return [];\n }\n\n const itemNameIndex = source[0].findIndex((item) => item === encodedItemName);\n if (itemNameIndex === -1) {\n return [];\n }\n\n return source.slice(1).flatMap((row, rowIndex) => {\n if (!Array.isArray(row)) {\n return [];\n }\n\n return createPieLegendSeriesItem({\n chart,\n dataIndexInside: rowIndex,\n isAllVisible,\n legendColorCacheRef,\n name: String(row[itemNameIndex]),\n seriesIndex,\n });\n });\n};\n\nconst getPieLegendSeriesFromObjectRows = ({\n chart,\n dataset,\n encodedItemName,\n isAllVisible,\n legendColorCacheRef,\n seriesIndex,\n}: PieLegendSeriesParams): LegendSeries => {\n const source = dataset?.source;\n if (!Array.isArray(source) || typeof encodedItemName !== 'string') {\n return [];\n }\n\n return source.flatMap((row, rowIndex) => {\n if (!isRecord(row) || !(encodedItemName in row)) {\n return [];\n }\n\n return createPieLegendSeriesItem({\n chart,\n dataIndexInside: rowIndex,\n isAllVisible,\n legendColorCacheRef,\n name: String(row[encodedItemName]),\n seriesIndex,\n });\n });\n};\n\nconst getPieLegendSeries = (params: PieLegendSeriesParams): LegendSeries => {\n const source = params.dataset?.source;\n if (!Array.isArray(source) || source.length === 0) {\n return [];\n }\n\n return Array.isArray(source[0])\n ? getPieLegendSeriesFromArrayRows(params)\n : getPieLegendSeriesFromObjectRows(params);\n};\n\n/**\n * Derives Needle legend rows from ECharts' normalized option and visual state.\n *\n * Standard series map one-to-one with legend items. Pie charts instead create a\n * legend item for each data row, so the hook reads the encoded item-name column\n * from the dataset and asks ECharts for each slice color. Fresh colors are\n * cached while all slices are visible because ECharts reports dimmed colors for\n * deselected slices.\n *\n * The hook waits until the first chart resize has completed so color lookups run\n * against an initialized ECharts instance.\n */\nexport function useLegendSeries({\n chartOption,\n isWaitingForFirstResize,\n}: UseLegendSeriesParams): LegendSeries | undefined {\n const { chartEchartRef, legendColorCacheRef, legendSelectedRef } =\n useChartRefsContext();\n\n return useMemo(() => {\n if (chartEchartRef.current === null || isWaitingForFirstResize) {\n return;\n }\n\n const chart = getInstanceByDom(chartEchartRef.current);\n const optionSeries = (chartOption?.series as NeedleSeries) ?? [];\n const optionDataset = chartOption?.dataset;\n const isAllLegendSeriesVisible = Object.values(\n legendSelectedRef.current,\n ).every((isVisible) => isVisible);\n\n const legendSeries: LegendSeries = [];\n if (Array.isArray(optionSeries)) {\n optionSeries.forEach((currentSeries, index) => {\n if (currentSeries === null) {\n return;\n } else if (isThresholdLineSeries(currentSeries)) {\n return;\n } else if (currentSeries.type === 'pie') {\n legendSeries.push(\n ...getPieLegendSeries({\n chart,\n dataset: getDatasetForSeries(\n optionDataset,\n currentSeries as SeriesWithDataset,\n ),\n encodedItemName: currentSeries.encode?.itemName,\n isAllVisible: isAllLegendSeriesVisible,\n legendColorCacheRef,\n seriesIndex: index,\n }),\n );\n return;\n } else {\n const name = currentSeries.name;\n\n if (name === undefined) {\n return;\n }\n\n // A scatter point's fill is the theme surface color, so the visual\n // color is not the series color. The series color is the ring.\n const visualColor = chart?.getVisual({ seriesIndex: index }, 'color');\n const seriesColor = currentSeries.color;\n const color =\n currentSeries.type === 'scatter' && typeof seriesColor === 'string'\n ? seriesColor\n : visualColor;\n legendSeries.push({\n color: typeof color === 'string' ? color : '#000000',\n name: String(name),\n });\n }\n });\n }\n return legendSeries;\n }, [\n chartEchartRef,\n chartOption,\n isWaitingForFirstResize,\n legendColorCacheRef,\n legendSelectedRef,\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAM,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AAe,OAAO;EACrD,MAAM,gBAAA,OAAA,gBAAA,QAAA,gBAAA,KAAA,IAAA,KAAA,IAAgB,YAAa,YAAA,QAAA,SAAA,KAAA,IAAA,OAA2B,CAAC;EAC/D,MAAM,gBAAA,gBAAA,QAAA,gBAAA,KAAA,IAAA,KAAA,IAAgB,YAAa;EACnC,MAAM,2BAA2B,OAAO,OACtC,kBAAkB,OACpB,CAAC,CAAC,OAAO,cAAc,SAAS;EAEhC,MAAM,eAA6B,CAAC;EACpC,IAAI,MAAM,QAAQ,YAAY,GAC5B,aAAa,SAAS,eAAe,UAAU;GAC7C,IAAI,kBAAkB,MACpB;QACK,IAAI,sBAAsB,aAAa,GAC5C;QACK,IAAI,cAAc,SAAS,OAAO;;IACvC,aAAa,KACX,GAAG,mBAAmB;KACpB;KACA,SAAS,oBACP,eACA,aACF;KACA,kBAAA,wBAAiB,cAAc,YAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAQ;KACvC,cAAc;KACd;KACA,aAAa;IACf,CAAC,CACH;IACA;GACF,OAAO;IACL,MAAM,OAAO,cAAc;IAE3B,IAAI,SAAS,KAAA,GACX;IAKF,MAAM,cAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAc,MAAO,UAAU,EAAE,aAAa,MAAM,GAAG,OAAO;IACpE,MAAM,cAAc,cAAc;IAClC,MAAM,QACJ,cAAc,SAAS,aAAa,OAAO,gBAAgB,WACvD,cACA;IACN,aAAa,KAAK;KAChB,OAAO,OAAO,UAAU,WAAW,QAAQ;KAC3C,MAAM,OAAO,IAAI;IACnB,CAAC;GACH;EACF,CAAC;EAEH,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;CACF,CAAC;AACH"}
@@ -1,91 +1,72 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ const require_charts_utils_threshold = require("../utils/threshold.js");
7
+ const require_charts_hooks_use_chart_refs = require("./use-chart-refs.js");
8
+ let react = require("react");
9
+ let echarts = require("echarts");
10
+ // src/charts/hooks/use-legend-visibility.ts
2
11
  /*!
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
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.useLegendVisibility = void 0;
24
- const echarts_1 = require("echarts");
25
- const react_1 = require("react");
26
- const threshold_1 = require("../utils/threshold");
27
- const use_chart_refs_1 = require("./use-chart-refs");
12
+ *
13
+ * Copyright (c) "Neo4j"
14
+ * Neo4j Sweden AB [http://neo4j.com]
15
+ *
16
+ * This file is part of Neo4j.
17
+ *
18
+ * Neo4j is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU General Public License as published by
20
+ * the Free Software Foundation, either version 3 of the License, or
21
+ * (at your option) any later version.
22
+ *
23
+ * This program is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU General Public License
29
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+ */
28
31
  const useLegendVisibility = (selectedSeries) => {
29
- const { chartEchartRef } = (0, use_chart_refs_1.useChartRefsContext)();
30
- const setOnlyVisible = (0, react_1.useCallback)((name) => {
31
- if (chartEchartRef.current === null) {
32
- return;
33
- }
34
- const chart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
35
- chart === null || chart === void 0 ? void 0 : chart.dispatchAction({
36
- name: name,
37
- type: 'legendSelect',
38
- });
39
- const otherNames = Object.keys(selectedSeries).filter((seriesName) => seriesName !== name);
40
- otherNames.forEach((name) => {
41
- if ((0, threshold_1.isThresholdLine)(name)) {
42
- return;
43
- }
44
- chart === null || chart === void 0 ? void 0 : chart.dispatchAction({
45
- name: name,
46
- type: 'legendUnSelect',
47
- });
48
- });
49
- }, [chartEchartRef, selectedSeries]);
50
- const setAllVisible = (0, react_1.useCallback)(() => {
51
- if (chartEchartRef.current === null) {
52
- return;
53
- }
54
- const chart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
55
- chart === null || chart === void 0 ? void 0 : chart.dispatchAction({
56
- type: 'legendAllSelect',
57
- });
58
- }, [chartEchartRef]);
59
- /**
60
- * Toggle the visibility of a legend series
61
- *
62
- * The toggle logic depends on the current state of the series:
63
- * - If only the legend series that was selected is visible: show all series
64
- * - If all series are visible: hide all except the series that was selected
65
- * - Otherwise: toggle the legend series
66
- *
67
- * The isOnlyVisible and isAllSeriesSelected states can't be calculated in this
68
- * function since different legend types require different logic.
69
- */
70
- const toggleLegendVisibility = (0, react_1.useCallback)((name, isAllSeriesSelected, isOnlyVisible) => {
71
- if (chartEchartRef.current === null || name === undefined) {
72
- return;
73
- }
74
- if (isOnlyVisible) {
75
- setAllVisible();
76
- }
77
- else if (isAllSeriesSelected) {
78
- setOnlyVisible(name);
79
- }
80
- else {
81
- const chart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
82
- chart === null || chart === void 0 ? void 0 : chart.dispatchAction({
83
- name: name,
84
- type: 'legendToggleSelect',
85
- });
86
- }
87
- }, [chartEchartRef, setOnlyVisible, setAllVisible]);
88
- return { toggleLegendVisibility };
32
+ const { chartEchartRef } = require_charts_hooks_use_chart_refs.useChartRefsContext();
33
+ const setOnlyVisible = (0, react.useCallback)((name) => {
34
+ if (chartEchartRef.current === null) return;
35
+ const chart = (0, echarts.getInstanceByDom)(chartEchartRef.current);
36
+ chart === null || chart === void 0 || chart.dispatchAction({
37
+ name,
38
+ type: "legendSelect"
39
+ });
40
+ Object.keys(selectedSeries).filter((seriesName) => seriesName !== name).forEach((name) => {
41
+ if (require_charts_utils_threshold.isThresholdLine(name)) return;
42
+ chart === null || chart === void 0 || chart.dispatchAction({
43
+ name,
44
+ type: "legendUnSelect"
45
+ });
46
+ });
47
+ }, [chartEchartRef, selectedSeries]);
48
+ const setAllVisible = (0, react.useCallback)(() => {
49
+ if (chartEchartRef.current === null) return;
50
+ const chart = (0, echarts.getInstanceByDom)(chartEchartRef.current);
51
+ chart === null || chart === void 0 || chart.dispatchAction({ type: "legendAllSelect" });
52
+ }, [chartEchartRef]);
53
+ return { toggleLegendVisibility: (0, react.useCallback)((name, isAllSeriesSelected, isOnlyVisible) => {
54
+ if (chartEchartRef.current === null || name === void 0) return;
55
+ if (isOnlyVisible) setAllVisible();
56
+ else if (isAllSeriesSelected) setOnlyVisible(name);
57
+ else {
58
+ const chart = (0, echarts.getInstanceByDom)(chartEchartRef.current);
59
+ chart === null || chart === void 0 || chart.dispatchAction({
60
+ name,
61
+ type: "legendToggleSelect"
62
+ });
63
+ }
64
+ }, [
65
+ chartEchartRef,
66
+ setOnlyVisible,
67
+ setAllVisible
68
+ ]) };
89
69
  };
90
70
  exports.useLegendVisibility = useLegendVisibility;
71
+
91
72
  //# sourceMappingURL=use-legend-visibility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-legend-visibility.js","sourceRoot":"","sources":["../../../../src/charts/hooks/use-legend-visibility.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,qCAA2C;AAC3C,iCAAoC;AAEpC,kDAAqD;AACrD,qDAAuD;AAEhD,MAAM,mBAAmB,GAAG,CACjC,cAAuC,EACvC,EAAE;IACF,MAAM,EAAE,cAAc,EAAE,GAA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AAM,sBAAsB,GAAG,IAAA,mBAAW,EACxC,CACE,IAAwB,EACxB,mBAA4B,EAC5B,aAAsB,EACtB,EAAE;QACF,IAAI,cAAc,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YAC1D,OAAO;QACT,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,EAAE,CAAC;QAClB,CAAC;aAAM,IAAI,mBAAmB,EAAE,CAAC;YAC/B,cAAc,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,IAAA,0BAAgB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAEvD,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,CAAC;gBACpB,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,oBAAoB;aAC3B,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EACD,CAAC,cAAc,EAAE,cAAc,EAAE,aAAa,CAAC,CAChD,CAAC;IAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC;AACpC,CAAC,CAAC;AApFW,QAAA,mBAAmB,uBAoF9B","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 { getInstanceByDom } from 'echarts';\nimport { useCallback } from 'react';\n\nimport { isThresholdLine } from '../utils/threshold';\nimport { useChartRefsContext } from './use-chart-refs';\n\nexport const useLegendVisibility = (\n selectedSeries: Record<string, boolean>,\n) => {\n const { chartEchartRef } = useChartRefsContext();\n\n const setOnlyVisible = useCallback(\n (name: string | undefined) => {\n if (chartEchartRef.current === null) {\n return;\n }\n const chart = getInstanceByDom(chartEchartRef.current);\n\n chart?.dispatchAction({\n name: name,\n type: 'legendSelect',\n });\n\n const otherNames = Object.keys(selectedSeries).filter(\n (seriesName) => seriesName !== name,\n );\n otherNames.forEach((name) => {\n if (isThresholdLine(name)) {\n return;\n }\n\n chart?.dispatchAction({\n name: name,\n type: 'legendUnSelect',\n });\n });\n },\n [chartEchartRef, selectedSeries],\n );\n\n const setAllVisible = useCallback(() => {\n if (chartEchartRef.current === null) {\n return;\n }\n\n const chart = getInstanceByDom(chartEchartRef.current);\n\n chart?.dispatchAction({\n type: 'legendAllSelect',\n });\n }, [chartEchartRef]);\n\n /**\n * Toggle the visibility of a legend series\n *\n * The toggle logic depends on the current state of the series:\n * - If only the legend series that was selected is visible: show all series\n * - If all series are visible: hide all except the series that was selected\n * - Otherwise: toggle the legend series\n *\n * The isOnlyVisible and isAllSeriesSelected states can't be calculated in this\n * function since different legend types require different logic.\n */\n const toggleLegendVisibility = useCallback(\n (\n name: string | undefined,\n isAllSeriesSelected: boolean,\n isOnlyVisible: boolean,\n ) => {\n if (chartEchartRef.current === null || name === undefined) {\n return;\n }\n\n if (isOnlyVisible) {\n setAllVisible();\n } else if (isAllSeriesSelected) {\n setOnlyVisible(name);\n } else {\n const chart = getInstanceByDom(chartEchartRef.current);\n\n chart?.dispatchAction({\n name: name,\n type: 'legendToggleSelect',\n });\n }\n },\n [chartEchartRef, setOnlyVisible, setAllVisible],\n );\n\n return { toggleLegendVisibility };\n};\n"]}
1
+ {"version":3,"file":"use-legend-visibility.js","names":["useChartRefsContext","useCallback","getInstanceByDom","isThresholdLine"],"sources":["../../../../src/charts/hooks/use-legend-visibility.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 { getInstanceByDom } from 'echarts';\nimport { useCallback } from 'react';\n\nimport { isThresholdLine } from '../utils/threshold';\nimport { useChartRefsContext } from './use-chart-refs';\n\nexport const useLegendVisibility = (\n selectedSeries: Record<string, boolean>,\n) => {\n const { chartEchartRef } = useChartRefsContext();\n\n const setOnlyVisible = useCallback(\n (name: string | undefined) => {\n if (chartEchartRef.current === null) {\n return;\n }\n const chart = getInstanceByDom(chartEchartRef.current);\n\n chart?.dispatchAction({\n name: name,\n type: 'legendSelect',\n });\n\n const otherNames = Object.keys(selectedSeries).filter(\n (seriesName) => seriesName !== name,\n );\n otherNames.forEach((name) => {\n if (isThresholdLine(name)) {\n return;\n }\n\n chart?.dispatchAction({\n name: name,\n type: 'legendUnSelect',\n });\n });\n },\n [chartEchartRef, selectedSeries],\n );\n\n const setAllVisible = useCallback(() => {\n if (chartEchartRef.current === null) {\n return;\n }\n\n const chart = getInstanceByDom(chartEchartRef.current);\n\n chart?.dispatchAction({\n type: 'legendAllSelect',\n });\n }, [chartEchartRef]);\n\n /**\n * Toggle the visibility of a legend series\n *\n * The toggle logic depends on the current state of the series:\n * - If only the legend series that was selected is visible: show all series\n * - If all series are visible: hide all except the series that was selected\n * - Otherwise: toggle the legend series\n *\n * The isOnlyVisible and isAllSeriesSelected states can't be calculated in this\n * function since different legend types require different logic.\n */\n const toggleLegendVisibility = useCallback(\n (\n name: string | undefined,\n isAllSeriesSelected: boolean,\n isOnlyVisible: boolean,\n ) => {\n if (chartEchartRef.current === null || name === undefined) {\n return;\n }\n\n if (isOnlyVisible) {\n setAllVisible();\n } else if (isAllSeriesSelected) {\n setOnlyVisible(name);\n } else {\n const chart = getInstanceByDom(chartEchartRef.current);\n\n chart?.dispatchAction({\n name: name,\n type: 'legendToggleSelect',\n });\n }\n },\n [chartEchartRef, setOnlyVisible, setAllVisible],\n );\n\n return { toggleLegendVisibility };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,uBACX,mBACG;CACH,MAAM,EAAE,mBAAmBA,oCAAAA,oBAAoB;CAE/C,MAAM,kBAAA,GAAiBC,MAAAA,YAAAA,EACpB,SAA6B;EAC5B,IAAI,eAAe,YAAY,MAC7B;EAEF,MAAM,SAAA,GAAQC,QAAAA,iBAAAA,CAAiB,eAAe,OAAO;EAErD,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,eAAe;GACd;GACN,MAAM;EACR,CAAC;EAKD,OAH0B,KAAK,cAAc,CAAC,CAAC,QAC5C,eAAe,eAAe,IAExB,CAAC,CAAC,SAAS,SAAS;GAC3B,IAAIC,+BAAAA,gBAAgB,IAAI,GACtB;GAGF,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,eAAe;IACd;IACN,MAAM;GACR,CAAC;EACH,CAAC;CACH,GACA,CAAC,gBAAgB,cAAc,CACjC;CAEA,MAAM,iBAAA,GAAgBF,MAAAA,YAAAA,OAAkB;EACtC,IAAI,eAAe,YAAY,MAC7B;EAGF,MAAM,SAAA,GAAQC,QAAAA,iBAAAA,CAAiB,eAAe,OAAO;EAErD,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,eAAe,EACpB,MAAM,kBACR,CAAC;CACH,GAAG,CAAC,cAAc,CAAC;CAuCnB,OAAO,EAAE,yBAAA,GA1BsBD,MAAAA,YAAAA,EAE3B,MACA,qBACA,kBACG;EACH,IAAI,eAAe,YAAY,QAAQ,SAAS,KAAA,GAC9C;EAGF,IAAI,eACF,cAAc;OACT,IAAI,qBACT,eAA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