@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 @@
1
+ {"version":3,"file":"use-chart-refs.mjs","names":[],"sources":["../../../../src/charts/hooks/use-chart-refs.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 {\n createContext,\n createElement,\n type ReactNode,\n useContext,\n useMemo,\n useRef,\n} from 'react';\n\nexport type ChartRefs = {\n chartEchartRef: React.RefObject<HTMLDivElement | null>;\n legendColorCacheRef: React.RefObject<Map<string, string>>;\n legendSelectedRef: React.RefObject<Record<string, boolean>>;\n};\n\nconst ChartRefsContext = createContext<ChartRefs | undefined>(undefined);\n\n/**\n * Creates the mutable refs shared between `ChartRender` and legend components.\n *\n * `chartEchartRef` points at the ECharts host element, while the legend refs act\n * as a bridge for state that ECharts needs synchronously during option rebuilds\n * without forcing extra React renders.\n */\nexport function ChartRefsProvider({ children }: { children: ReactNode }) {\n const chartEchartRef = useRef<HTMLDivElement>(null);\n const legendSelectedRef = useRef<Record<string, boolean>>({});\n const legendColorCacheRef = useRef<Map<string, string>>(new Map());\n const refs = useMemo(\n () => ({\n chartEchartRef,\n legendColorCacheRef,\n legendSelectedRef,\n }),\n [],\n );\n\n return createElement(ChartRefsContext.Provider, { value: refs }, children);\n}\n\nexport function useChartRefsContext() {\n const refs = useContext(ChartRefsContext);\n if (refs === undefined) {\n throw new Error(\n 'useChartRefsContext must be used within ChartRefsProvider',\n );\n }\n\n return refs;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,mBAAmB,cAAqC,KAAA,CAAS;;;;;;;;AASvE,SAAgB,kBAAkB,EAAE,YAAqC;CACvE,MAAM,iBAAiB,OAAuB,IAAI;CAClD,MAAM,oBAAoB,OAAgC,CAAC,CAAC;CAC5D,MAAM,sBAAsB,uBAA4B,IAAI,IAAI,CAAC;CACjE,MAAM,OAAO,eACJ;EACL;EACA;EACA;CACF,IACA,CAAC,CACH;CAEA,OAAO,cAAc,iBAAiB,UAAU,EAAE,OAAO,KAAK,GAAG,QAAQ;AAC3E;AAEA,SAAgB,sBAAsB;CACpC,MAAM,OAAO,WAAW,gBAAgB;CACxC,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MACR,2DACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,102 @@
1
+ import { useChartRefsContext } from "./use-chart-refs.mjs";
2
+ import { useEffect } from "react";
3
+ import { getInstanceByDom } from "echarts";
4
+ // src/charts/hooks/use-chart-zoom.ts
5
+ /*!
6
+ *
7
+ * Copyright (c) "Neo4j"
8
+ * Neo4j Sweden AB [http://neo4j.com]
9
+ *
10
+ * This file is part of Neo4j.
11
+ *
12
+ * Neo4j is free software: you can redistribute it and/or modify
13
+ * it under the terms of the GNU General Public License as published by
14
+ * the Free Software Foundation, either version 3 of the License, or
15
+ * (at your option) any later version.
16
+ *
17
+ * This program is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
+ */
25
+ /**
26
+ * Owns ECharts zoom interactions and forwards zoom changes to consumers.
27
+ *
28
+ * The hook subscribes to ECharts `datazoom` events, enables drag-to-zoom through
29
+ * ECharts' global cursor API, resets zoom on double click, and clears ECharts'
30
+ * SVG cursor override after mouse movement so Needle's default cursor styling is
31
+ * preserved.
32
+ *
33
+ * The effect re-runs on every render, so each listener has to be detached again
34
+ * on cleanup. Otherwise they pile up and consumers get one `onZoom` call per
35
+ * render that has happened so far.
36
+ */
37
+ function useChartZoom({ callbacks, isChartZoomDisabled }) {
38
+ const { chartEchartRef } = useChartRefsContext();
39
+ useEffect(() => {
40
+ var _chartEchartRef$curre;
41
+ const chart = chartEchartRef.current === null ? void 0 : getInstanceByDom(chartEchartRef.current);
42
+ const handleDataZoom = () => {
43
+ var _chartOption$dataZoom, _callbacks$onZoom;
44
+ if (chartEchartRef.current === null) return;
45
+ const currentChart = getInstanceByDom(chartEchartRef.current);
46
+ if (!currentChart) return;
47
+ const dataZoom = ((_chartOption$dataZoom = currentChart.getOption().dataZoom) !== null && _chartOption$dataZoom !== void 0 ? _chartOption$dataZoom : []).filter((entry) => entry !== null).map(({ end, endValue, id, start, startValue, xAxisIndex, yAxisIndex }) => ({
48
+ endPercent: end,
49
+ endValue,
50
+ id,
51
+ startPercent: start,
52
+ startValue,
53
+ xAxisIndex,
54
+ yAxisIndex
55
+ }));
56
+ if (dataZoom.length === 0) return;
57
+ callbacks === null || callbacks === void 0 || (_callbacks$onZoom = callbacks.onZoom) === null || _callbacks$onZoom === void 0 || _callbacks$onZoom.call(callbacks, {
58
+ dataZoom,
59
+ endValue: dataZoom[0].endValue,
60
+ startValue: dataZoom[0].startValue
61
+ });
62
+ };
63
+ if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) chart === null || chart === void 0 || chart.on("datazoom", handleDataZoom);
64
+ const handleMouseMove = () => {
65
+ chart === null || chart === void 0 || chart.getZr().setCursorStyle("default");
66
+ };
67
+ const chartChild = (_chartEchartRef$curre = chartEchartRef.current) === null || _chartEchartRef$curre === void 0 ? void 0 : _chartEchartRef$curre.children[0];
68
+ if (!isChartZoomDisabled) chartChild === null || chartChild === void 0 || chartChild.addEventListener("mousemove", handleMouseMove);
69
+ const handleMouseDown = (params) => {
70
+ if (params.event.detail === 2) {
71
+ if (chart === void 0) return;
72
+ chart === null || chart === void 0 || chart.dispatchAction({
73
+ end: 100,
74
+ start: 0,
75
+ type: "dataZoom"
76
+ });
77
+ }
78
+ };
79
+ if (!isChartZoomDisabled) chart === null || chart === void 0 || chart.getZr().on("mousedown", handleMouseDown);
80
+ const chartRefCurrentElement = chartEchartRef.current;
81
+ const element = chartRefCurrentElement === null || chartRefCurrentElement === void 0 ? void 0 : chartRefCurrentElement.children[0];
82
+ return () => {
83
+ element === null || element === void 0 || element.removeEventListener("mousemove", handleMouseMove);
84
+ if (chartRefCurrentElement) {
85
+ const chart = getInstanceByDom(chartRefCurrentElement);
86
+ chart === null || chart === void 0 || chart.off("datazoom", handleDataZoom);
87
+ chart === null || chart === void 0 || chart.getZr().off("mousedown", handleMouseDown);
88
+ }
89
+ };
90
+ });
91
+ if (chartEchartRef.current !== null && !isChartZoomDisabled) {
92
+ const chart = getInstanceByDom(chartEchartRef.current);
93
+ if (chart) chart.dispatchAction({
94
+ dataZoomSelectActive: true,
95
+ key: "dataZoomSelect",
96
+ type: "takeGlobalCursor"
97
+ });
98
+ }
99
+ }
100
+ export { useChartZoom };
101
+
102
+ //# sourceMappingURL=use-chart-zoom.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-chart-zoom.mjs","names":[],"sources":["../../../../src/charts/hooks/use-chart-zoom.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 { useEffect } from 'react';\n\nimport type { ChartProps, ChartZoomEntry } from '../utils/chart-types';\nimport { useChartRefsContext } from './use-chart-refs';\n\ntype UseChartZoomParams = {\n callbacks: ChartProps['callbacks'];\n isChartZoomDisabled: boolean;\n};\n\n// Besides the zoom fields, each entry carries every option ECharts merged in,\n// such as the slider styling from the theme.\ntype EchartsDataZoomEntry = Omit<\n ChartZoomEntry,\n 'startPercent' | 'endPercent'\n> & { start: number; end: number } & Record<string, unknown>;\n\n/**\n * Owns ECharts zoom interactions and forwards zoom changes to consumers.\n *\n * The hook subscribes to ECharts `datazoom` events, enables drag-to-zoom through\n * ECharts' global cursor API, resets zoom on double click, and clears ECharts'\n * SVG cursor override after mouse movement so Needle's default cursor styling is\n * preserved.\n *\n * The effect re-runs on every render, so each listener has to be detached again\n * on cleanup. Otherwise they pile up and consumers get one `onZoom` call per\n * render that has happened so far.\n */\nexport function useChartZoom({\n callbacks,\n isChartZoomDisabled,\n}: UseChartZoomParams) {\n const { chartEchartRef } = useChartRefsContext();\n\n useEffect(() => {\n const chart =\n chartEchartRef.current === null\n ? undefined\n : getInstanceByDom(chartEchartRef.current);\n\n const handleDataZoom = () => {\n if (chartEchartRef.current === null) {\n return;\n }\n\n const currentChart = getInstanceByDom(chartEchartRef.current);\n if (!currentChart) {\n return;\n }\n\n const chartOption = currentChart.getOption();\n const echartsDataZoom = (chartOption.dataZoom ??\n []) as (EchartsDataZoomEntry | null)[];\n const dataZoom: ChartZoomEntry[] = echartsDataZoom\n .filter((entry) => entry !== null)\n // map to trim unnecessary values, just keeping the relevant fields\n .map(\n ({\n end,\n endValue,\n id,\n start,\n startValue,\n xAxisIndex,\n yAxisIndex,\n }) => ({\n endPercent: end,\n endValue,\n id,\n startPercent: start,\n startValue,\n xAxisIndex,\n yAxisIndex,\n }),\n );\n if (dataZoom.length === 0) {\n return;\n }\n\n callbacks?.onZoom?.({\n dataZoom,\n endValue: dataZoom[0].endValue as number,\n startValue: dataZoom[0].startValue as number,\n });\n };\n\n if (callbacks?.onZoom) {\n chart?.on('datazoom', handleDataZoom);\n }\n\n const handleMouseMove = () => {\n // ECharts updates SVG cursor styles on mouse move, so Needle has to\n // reset it after ECharts' internal handler runs.\n chart?.getZr().setCursorStyle('default');\n };\n const chartChild = chartEchartRef.current?.children[0] as\n | HTMLElement\n | undefined;\n if (!isChartZoomDisabled) {\n chartChild?.addEventListener('mousemove', handleMouseMove);\n }\n\n const handleMouseDown = (params: { event: MouseEvent }) => {\n const event = params.event;\n const amountOfMouseClicks = event.detail;\n const isDoubleClick = amountOfMouseClicks === 2;\n if (isDoubleClick) {\n if (chart === undefined) {\n return;\n }\n chart?.dispatchAction({\n end: 100,\n start: 0,\n type: 'dataZoom',\n });\n }\n };\n if (!isChartZoomDisabled) {\n chart?.getZr().on('mousedown', handleMouseDown);\n }\n\n const chartRefCurrentElement = chartEchartRef.current;\n const element = chartRefCurrentElement?.children[0];\n return () => {\n element?.removeEventListener('mousemove', handleMouseMove);\n\n if (chartRefCurrentElement) {\n const chart = getInstanceByDom(chartRefCurrentElement);\n chart?.off('datazoom', handleDataZoom);\n chart?.getZr().off('mousedown', handleMouseDown);\n }\n };\n });\n\n if (chartEchartRef.current !== null && !isChartZoomDisabled) {\n const chart = getInstanceByDom(chartEchartRef.current);\n if (chart) {\n // Needs to be re-set on every re-render. Sets the selectable zoom area\n // over the chart body, not the slider.\n chart.dispatchAction({\n dataZoomSelectActive: true,\n key: 'dataZoomSelect',\n type: 'takeGlobalCursor',\n });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,aAAa,EAC3B,WACA,uBACqB;CACrB,MAAM,EAAE,mBAAmB,oBAAoB;CAE/C,gB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;EACA,IAAI,CAAC,qBACH,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,MAAM,CAAC,CAAC,GAAG,aAAa,eAAe;EAGhD,MAAM,yBAAyB,eAAe;EAC9C,MAAM,UAAA,2BAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAU,uBAAwB,SAAS;EACjD,aAAa;GACX,YAAA,QAAA,YAAA,KAAA,KAAA,QAAS,oBAAoB,aAAa,eAAe;GAEzD,IAAI,wBAAwB;IAC1B,MAAM,QAAQ,iBAAiB,sBAAsB;IACrD,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,IAAI,YAAY,cAAc;IACrC,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,MAAM,CAAC,CAAC,IAAI,aAAa,eAAe;GACjD;EACF;CACF,CAAC;CAED,IAAI,eAAe,YAAY,QAAQ,CAAC,qBAAqB;EAC3D,MAAM,QAAQ,iBAAiB,eAAe,OAAO;EACrD,IAAI,OAGF,MAAM,eAAe;GACnB,sBAAsB;GACtB,KAAK;GACL,MAAM;EACR,CAAC;CAEL;AACF"}
@@ -0,0 +1,138 @@
1
+ import { highlightOrDownplaySeries, resetAllSeriesHighlight } from "../utils/legend-utils.mjs";
2
+ import { isThresholdLine } from "../utils/threshold.mjs";
3
+ import { useChartRefsContext } from "./use-chart-refs.mjs";
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { getInstanceByDom } from "echarts";
6
+ // src/charts/hooks/use-legend-interactions.ts
7
+ /*!
8
+ *
9
+ * Copyright (c) "Neo4j"
10
+ * Neo4j Sweden AB [http://neo4j.com]
11
+ *
12
+ * This file is part of Neo4j.
13
+ *
14
+ * Neo4j is free software: you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation, either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
26
+ */
27
+ const LEGEND_HOVER_HIGHLIGHT_DELAY_MS = 80;
28
+ const LEGEND_SELECTION_EVENT_TYPES = [
29
+ "legendselectchanged",
30
+ "legendselectall",
31
+ "legendselected",
32
+ "legendunselected"
33
+ ];
34
+ const getAllSeriesSelected = (series) => Object.fromEntries(series.map((seriesItem) => {
35
+ var _seriesItem$name;
36
+ return [(_seriesItem$name = seriesItem.name) !== null && _seriesItem$name !== void 0 ? _seriesItem$name : "", true];
37
+ }));
38
+ const hasSelectionForCurrentSeries = (selection, series) => {
39
+ return Object.keys(selection).length === series.length && series.every((seriesItem) => {
40
+ var _seriesItem$name2;
41
+ return Object.prototype.hasOwnProperty.call(selection, (_seriesItem$name2 = seriesItem.name) !== null && _seriesItem$name2 !== void 0 ? _seriesItem$name2 : "");
42
+ });
43
+ };
44
+ const filterThresholdLineSelection = (selected) => Object.fromEntries(Object.entries(selected).filter(([key]) => {
45
+ var _isThresholdLine;
46
+ return !((_isThresholdLine = isThresholdLine(key)) !== null && _isThresholdLine !== void 0 ? _isThresholdLine : false);
47
+ }));
48
+ const clearTimeoutRef = (timeoutRef) => {
49
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
50
+ };
51
+ const createLegendSelectionEventHandler = (chart, eventType, setSelectedSeries) => (params) => {
52
+ var _selected;
53
+ if (typeof params !== "object" || params === null || !("selected" in params) || params.selected === null) return;
54
+ if (eventType === "legendselectchanged") resetAllSeriesHighlight(chart);
55
+ setSelectedSeries(filterThresholdLineSelection((_selected = params.selected) !== null && _selected !== void 0 ? _selected : {}));
56
+ };
57
+ /**
58
+ * Owns React legend selection and keeps it synchronized with ECharts.
59
+ *
60
+ * Current series changes preserve existing selection by name, new series default
61
+ * to visible, removed series are dropped, and ECharts legend events update the
62
+ * React state used to render legend items.
63
+ */
64
+ function useLegendSelection({ series }) {
65
+ const { chartEchartRef, legendSelectedRef } = useChartRefsContext();
66
+ const initialSelected = useMemo(() => getAllSeriesSelected(series), [series]);
67
+ const [selectedSeries, setSelectedSeries] = useState(initialSelected);
68
+ const renderedSelectedSeries = hasSelectionForCurrentSeries(selectedSeries, series) ? selectedSeries : initialSelected;
69
+ useEffect(() => {
70
+ var _legendSelectedRef$cu;
71
+ const prev = (_legendSelectedRef$cu = legendSelectedRef.current) !== null && _legendSelectedRef$cu !== void 0 ? _legendSelectedRef$cu : {};
72
+ const next = {};
73
+ for (const seriesItem of series) {
74
+ var _seriesItem$name3, _prev$name;
75
+ const name = (_seriesItem$name3 = seriesItem.name) !== null && _seriesItem$name3 !== void 0 ? _seriesItem$name3 : "";
76
+ next[name] = (_prev$name = prev[name]) !== null && _prev$name !== void 0 ? _prev$name : true;
77
+ }
78
+ setSelectedSeries(next);
79
+ }, [legendSelectedRef, series]);
80
+ useEffect(() => {
81
+ legendSelectedRef.current = selectedSeries;
82
+ }, [legendSelectedRef, selectedSeries]);
83
+ useEffect(() => {
84
+ if (chartEchartRef.current === null) return;
85
+ const chart = getInstanceByDom(chartEchartRef.current);
86
+ if (!chart) return;
87
+ const eventHandlers = LEGEND_SELECTION_EVENT_TYPES.map((eventType) => {
88
+ const handler = createLegendSelectionEventHandler(chart, eventType, setSelectedSeries);
89
+ chart.on(eventType, handler);
90
+ return {
91
+ eventType,
92
+ handler
93
+ };
94
+ });
95
+ return () => {
96
+ eventHandlers.forEach(({ eventType, handler }) => {
97
+ chart.off(eventType, handler);
98
+ });
99
+ };
100
+ }, [chartEchartRef]);
101
+ return { renderedSelectedSeries };
102
+ }
103
+ /**
104
+ * Creates a delayed ECharts highlighter for legend item hover state.
105
+ *
106
+ * Legend hover moves often happen as a quick leave/enter pair between adjacent
107
+ * items. Keeping separate highlight and downplay timers lets the next hover
108
+ * cancel the previous opposite action, preventing the chart from flickering
109
+ * between emphasized and reset states. Deselected legend items are ignored so
110
+ * hidden series do not get emphasized through hover.
111
+ */
112
+ function useLegendHoverHighlight({ selectedSeries, series }) {
113
+ const { chartEchartRef } = useChartRefsContext();
114
+ const highlightTimeOut = useRef(null);
115
+ const downplayTimeOut = useRef(null);
116
+ useEffect(() => {
117
+ return () => {
118
+ clearTimeoutRef(highlightTimeOut);
119
+ clearTimeoutRef(downplayTimeOut);
120
+ };
121
+ }, []);
122
+ return { toggleHighlight: useCallback((seriesToUpdate, shouldHighlight) => {
123
+ if (seriesToUpdate.name === void 0 ? false : !selectedSeries[seriesToUpdate.name]) return;
124
+ const timeoutToClear = shouldHighlight ? downplayTimeOut : highlightTimeOut;
125
+ const timeoutToSet = shouldHighlight ? highlightTimeOut : downplayTimeOut;
126
+ if (timeoutToClear.current) clearTimeout(timeoutToClear.current);
127
+ timeoutToSet.current = setTimeout(() => {
128
+ highlightOrDownplaySeries(chartEchartRef, series, selectedSeries, [seriesToUpdate], shouldHighlight ? "highlight" : "downplay");
129
+ }, LEGEND_HOVER_HIGHLIGHT_DELAY_MS);
130
+ }, [
131
+ chartEchartRef,
132
+ selectedSeries,
133
+ series
134
+ ]) };
135
+ }
136
+ export { useLegendHoverHighlight, useLegendSelection };
137
+
138
+ //# sourceMappingURL=use-legend-interactions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-legend-interactions.mjs","names":[],"sources":["../../../../src/charts/hooks/use-legend-interactions.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 EChartsType, getInstanceByDom } from 'echarts';\nimport {\n type Dispatch,\n type MutableRefObject,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport type { LegendProps } from '../utils/chart-types';\nimport {\n highlightOrDownplaySeries,\n resetAllSeriesHighlight,\n} from '../utils/legend-utils';\nimport { isThresholdLine } from '../utils/threshold';\nimport { useChartRefsContext } from './use-chart-refs';\n\nconst LEGEND_HOVER_HIGHLIGHT_DELAY_MS = 80;\nconst LEGEND_SELECTION_EVENT_TYPES = [\n 'legendselectchanged',\n 'legendselectall',\n 'legendselected',\n 'legendunselected',\n] as const;\n\ntype LegendSeries = LegendProps['series'];\ntype LegendSelectionEventType = (typeof LEGEND_SELECTION_EVENT_TYPES)[number];\n\ntype LegendSelectionEventParams = {\n selected?: Record<string, boolean> | null;\n};\n\ntype UseLegendHoverHighlightParams = {\n selectedSeries: Record<string, boolean>;\n series: LegendSeries;\n};\n\ntype UseLegendSelectionParams = {\n series: LegendProps['series'];\n};\n\nconst getAllSeriesSelected = (series: LegendProps['series']) =>\n Object.fromEntries(series.map((seriesItem) => [seriesItem.name ?? '', true]));\n\nconst hasSelectionForCurrentSeries = (\n selection: Record<string, boolean>,\n series: LegendProps['series'],\n) => {\n const selectedNames = Object.keys(selection);\n\n return (\n selectedNames.length === series.length &&\n series.every((seriesItem) =>\n Object.prototype.hasOwnProperty.call(selection, seriesItem.name ?? ''),\n )\n );\n};\n\nconst filterThresholdLineSelection = (selected: Record<string, boolean>) =>\n Object.fromEntries(\n Object.entries(selected).filter(\n ([key]) => !(isThresholdLine(key) ?? false),\n ),\n );\n\nconst clearTimeoutRef = (\n timeoutRef: MutableRefObject<ReturnType<typeof setTimeout> | null>,\n) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n};\n\nconst createLegendSelectionEventHandler =\n (\n chart: EChartsType,\n eventType: LegendSelectionEventType,\n setSelectedSeries: Dispatch<SetStateAction<Record<string, boolean>>>,\n ) =>\n (params: unknown) => {\n if (\n typeof params !== 'object' ||\n params === null ||\n !('selected' in params) ||\n params.selected === null\n ) {\n return;\n }\n\n if (eventType === 'legendselectchanged') {\n resetAllSeriesHighlight(chart);\n }\n\n setSelectedSeries(\n filterThresholdLineSelection(\n (params as LegendSelectionEventParams).selected ?? {},\n ),\n );\n };\n\n/**\n * Owns React legend selection and keeps it synchronized with ECharts.\n *\n * Current series changes preserve existing selection by name, new series default\n * to visible, removed series are dropped, and ECharts legend events update the\n * React state used to render legend items.\n */\nexport function useLegendSelection({ series }: UseLegendSelectionParams) {\n const { chartEchartRef, legendSelectedRef } = useChartRefsContext();\n const initialSelected = useMemo(() => getAllSeriesSelected(series), [series]);\n const [selectedSeries, setSelectedSeries] =\n useState<Record<string, boolean>>(initialSelected);\n\n const renderedSelectedSeries = hasSelectionForCurrentSeries(\n selectedSeries,\n series,\n )\n ? selectedSeries\n : initialSelected;\n\n useEffect(() => {\n const prev = legendSelectedRef.current ?? {};\n const next: Record<string, boolean> = {};\n\n for (const seriesItem of series) {\n const name = seriesItem.name ?? '';\n next[name] = prev[name] ?? true;\n }\n\n setSelectedSeries(next);\n }, [legendSelectedRef, series]);\n\n useEffect(() => {\n legendSelectedRef.current = selectedSeries;\n }, [legendSelectedRef, selectedSeries]);\n\n useEffect(() => {\n if (chartEchartRef.current === null) {\n return;\n }\n\n const chart = getInstanceByDom(chartEchartRef.current);\n if (!chart) {\n return;\n }\n\n const eventHandlers = LEGEND_SELECTION_EVENT_TYPES.map((eventType) => {\n const handler = createLegendSelectionEventHandler(\n chart,\n eventType,\n setSelectedSeries,\n );\n chart.on(eventType, handler);\n\n return { eventType, handler };\n });\n\n return () => {\n eventHandlers.forEach(({ eventType, handler }) => {\n chart.off(eventType, handler);\n });\n };\n }, [chartEchartRef]);\n\n return { renderedSelectedSeries };\n}\n\n/**\n * Creates a delayed ECharts highlighter for legend item hover state.\n *\n * Legend hover moves often happen as a quick leave/enter pair between adjacent\n * items. Keeping separate highlight and downplay timers lets the next hover\n * cancel the previous opposite action, preventing the chart from flickering\n * between emphasized and reset states. Deselected legend items are ignored so\n * hidden series do not get emphasized through hover.\n */\nexport function useLegendHoverHighlight({\n selectedSeries,\n series,\n}: UseLegendHoverHighlightParams) {\n const { chartEchartRef } = useChartRefsContext();\n const highlightTimeOut = useRef<ReturnType<typeof setTimeout> | null>(null);\n const downplayTimeOut = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(() => {\n return () => {\n clearTimeoutRef(highlightTimeOut);\n clearTimeoutRef(downplayTimeOut);\n };\n }, []);\n\n const toggleHighlight = useCallback(\n (\n seriesToUpdate: { name: string; color: string },\n shouldHighlight: boolean,\n ) => {\n const isDeselected =\n seriesToUpdate.name === undefined\n ? false\n : !selectedSeries[seriesToUpdate.name];\n\n if (isDeselected) {\n return;\n }\n\n const timeoutToClear = shouldHighlight\n ? downplayTimeOut\n : highlightTimeOut;\n const timeoutToSet = shouldHighlight ? highlightTimeOut : downplayTimeOut;\n\n if (timeoutToClear.current) {\n clearTimeout(timeoutToClear.current);\n }\n\n timeoutToSet.current = setTimeout(() => {\n highlightOrDownplaySeries(\n chartEchartRef,\n series,\n selectedSeries,\n [seriesToUpdate],\n shouldHighlight ? 'highlight' : 'downplay',\n );\n }, LEGEND_HOVER_HIGHLIGHT_DELAY_MS);\n },\n [chartEchartRef, selectedSeries, series],\n );\n\n return { toggleHighlight };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,kCAAkC;AACxC,MAAM,+BAA+B;CACnC;CACA;CACA;CACA;AACF;AAkBA,MAAM,wBAAwB,WAC5B,OAAO,YAAY,OAAO,KAAK,eAAe;;CAAC,OAAA,EAAA,mBAAA,WAAW,UAAA,QAAA,qBAAA,KAAA,IAAA,mBAAQ,IAAI,IAAI;AAAC,CAAA,CAAC;AAE9E,MAAM,gCACJ,WACA,WACG;CAGH,OAFsB,OAAO,KAAK,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isThresholdLine } from "../utils/threshold.mjs";
2
+ import { useChartRefsContext } from "./use-chart-refs.mjs";
3
+ import { useMemo } from "react";
4
+ import { getInstanceByDom } from "echarts";
5
+ // src/charts/hooks/use-legend-series.ts
6
+ /*!
7
+ *
8
+ * Copyright (c) "Neo4j"
9
+ * Neo4j Sweden AB [http://neo4j.com]
10
+ *
11
+ * This file is part of Neo4j.
12
+ *
13
+ * Neo4j is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
+ */
26
+ const isThresholdLineSeries = (series) => series.type === "line" && typeof series.name === "string" && isThresholdLine(series.name);
27
+ const getDatasetForSeries = (optionDataset, series) => {
28
+ const datasetList = Array.isArray(optionDataset) ? optionDataset : [optionDataset];
29
+ if (series.datasetId && Array.isArray(optionDataset)) return datasetList.find((dataset) => (dataset === null || dataset === void 0 ? void 0 : dataset.id) === series.datasetId);
30
+ if (series.datasetIndex !== void 0) return datasetList[series.datasetIndex];
31
+ return datasetList[0];
32
+ };
33
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
34
+ const getCachedLegendColor = ({ chart, isAllVisible, legendColorCacheRef, name, seriesIndex, dataIndexInside }) => {
35
+ var _legendColorCacheRef$;
36
+ const freshColor = chart === null || chart === void 0 ? void 0 : chart.getVisual({
37
+ dataIndexInside,
38
+ seriesIndex
39
+ }, "color");
40
+ if (isAllVisible && typeof freshColor === "string") legendColorCacheRef.current.set(name, freshColor);
41
+ return (_legendColorCacheRef$ = legendColorCacheRef.current.get(name)) !== null && _legendColorCacheRef$ !== void 0 ? _legendColorCacheRef$ : typeof freshColor === "string" ? freshColor : "#000000";
42
+ };
43
+ const createPieLegendSeriesItem = ({ chart, dataIndexInside, isAllVisible, legendColorCacheRef, name, seriesIndex }) => ({
44
+ color: getCachedLegendColor({
45
+ chart,
46
+ dataIndexInside,
47
+ isAllVisible,
48
+ legendColorCacheRef,
49
+ name,
50
+ seriesIndex
51
+ }),
52
+ name
53
+ });
54
+ const getPieLegendSeriesFromArrayRows = ({ chart, dataset, encodedItemName, isAllVisible, legendColorCacheRef, seriesIndex }) => {
55
+ const source = dataset === null || dataset === void 0 ? void 0 : dataset.source;
56
+ if (!Array.isArray(source) || !Array.isArray(source[0])) return [];
57
+ const itemNameIndex = source[0].findIndex((item) => item === encodedItemName);
58
+ if (itemNameIndex === -1) return [];
59
+ return source.slice(1).flatMap((row, rowIndex) => {
60
+ if (!Array.isArray(row)) return [];
61
+ return createPieLegendSeriesItem({
62
+ chart,
63
+ dataIndexInside: rowIndex,
64
+ isAllVisible,
65
+ legendColorCacheRef,
66
+ name: String(row[itemNameIndex]),
67
+ seriesIndex
68
+ });
69
+ });
70
+ };
71
+ const getPieLegendSeriesFromObjectRows = ({ chart, dataset, encodedItemName, isAllVisible, legendColorCacheRef, seriesIndex }) => {
72
+ const source = dataset === null || dataset === void 0 ? void 0 : dataset.source;
73
+ if (!Array.isArray(source) || typeof encodedItemName !== "string") return [];
74
+ return source.flatMap((row, rowIndex) => {
75
+ if (!isRecord(row) || !(encodedItemName in row)) return [];
76
+ return createPieLegendSeriesItem({
77
+ chart,
78
+ dataIndexInside: rowIndex,
79
+ isAllVisible,
80
+ legendColorCacheRef,
81
+ name: String(row[encodedItemName]),
82
+ seriesIndex
83
+ });
84
+ });
85
+ };
86
+ const getPieLegendSeries = (params) => {
87
+ var _params$dataset;
88
+ const source = (_params$dataset = params.dataset) === null || _params$dataset === void 0 ? void 0 : _params$dataset.source;
89
+ if (!Array.isArray(source) || source.length === 0) return [];
90
+ return Array.isArray(source[0]) ? getPieLegendSeriesFromArrayRows(params) : getPieLegendSeriesFromObjectRows(params);
91
+ };
92
+ /**
93
+ * Derives Needle legend rows from ECharts' normalized option and visual state.
94
+ *
95
+ * Standard series map one-to-one with legend items. Pie charts instead create a
96
+ * legend item for each data row, so the hook reads the encoded item-name column
97
+ * from the dataset and asks ECharts for each slice color. Fresh colors are
98
+ * cached while all slices are visible because ECharts reports dimmed colors for
99
+ * deselected slices.
100
+ *
101
+ * The hook waits until the first chart resize has completed so color lookups run
102
+ * against an initialized ECharts instance.
103
+ */
104
+ function useLegendSeries({ chartOption, isWaitingForFirstResize }) {
105
+ const { chartEchartRef, legendColorCacheRef, legendSelectedRef } = useChartRefsContext();
106
+ return useMemo(() => {
107
+ var _ref;
108
+ if (chartEchartRef.current === null || isWaitingForFirstResize) return;
109
+ const chart = getInstanceByDom(chartEchartRef.current);
110
+ const optionSeries = (_ref = chartOption === null || chartOption === void 0 ? void 0 : chartOption.series) !== null && _ref !== void 0 ? _ref : [];
111
+ const optionDataset = chartOption === null || chartOption === void 0 ? void 0 : chartOption.dataset;
112
+ const isAllLegendSeriesVisible = Object.values(legendSelectedRef.current).every((isVisible) => isVisible);
113
+ const legendSeries = [];
114
+ if (Array.isArray(optionSeries)) optionSeries.forEach((currentSeries, index) => {
115
+ if (currentSeries === null) return;
116
+ else if (isThresholdLineSeries(currentSeries)) return;
117
+ else if (currentSeries.type === "pie") {
118
+ var _currentSeries$encode;
119
+ legendSeries.push(...getPieLegendSeries({
120
+ chart,
121
+ dataset: getDatasetForSeries(optionDataset, currentSeries),
122
+ encodedItemName: (_currentSeries$encode = currentSeries.encode) === null || _currentSeries$encode === void 0 ? void 0 : _currentSeries$encode.itemName,
123
+ isAllVisible: isAllLegendSeriesVisible,
124
+ legendColorCacheRef,
125
+ seriesIndex: index
126
+ }));
127
+ return;
128
+ } else {
129
+ const name = currentSeries.name;
130
+ if (name === void 0) return;
131
+ const visualColor = chart === null || chart === void 0 ? void 0 : chart.getVisual({ seriesIndex: index }, "color");
132
+ const seriesColor = currentSeries.color;
133
+ const color = currentSeries.type === "scatter" && typeof seriesColor === "string" ? seriesColor : visualColor;
134
+ legendSeries.push({
135
+ color: typeof color === "string" ? color : "#000000",
136
+ name: String(name)
137
+ });
138
+ }
139
+ });
140
+ return legendSeries;
141
+ }, [
142
+ chartEchartRef,
143
+ chartOption,
144
+ isWaitingForFirstResize,
145
+ legendColorCacheRef,
146
+ legendSelectedRef
147
+ ]);
148
+ }
149
+ export { useLegendSeries };
150
+
151
+ //# sourceMappingURL=use-legend-series.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-legend-series.mjs","names":[],"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,yBAAyB,WAC7B,OAAO,SAAS,UAChB,OAAO,OAAO,SAAS,YACvB,gBAAgB,OAAO,IAAI;AAE7B,MAAM,uBACJ,eACA,WACG;CACH,MAAM,cAAc,MAAM,QAAQ,aAAa,IAC3C,gBACA,CAAC,aAAa;CAElB,IAAI,OAAO,aAAa,MAAM,QAAQ,aAAa,GAC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AS;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"}
@@ -0,0 +1,67 @@
1
+ import { isThresholdLine } from "../utils/threshold.mjs";
2
+ import { useChartRefsContext } from "./use-chart-refs.mjs";
3
+ import { useCallback } from "react";
4
+ import { getInstanceByDom } from "echarts";
5
+ // src/charts/hooks/use-legend-visibility.ts
6
+ /*!
7
+ *
8
+ * Copyright (c) "Neo4j"
9
+ * Neo4j Sweden AB [http://neo4j.com]
10
+ *
11
+ * This file is part of Neo4j.
12
+ *
13
+ * Neo4j is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
+ */
26
+ const useLegendVisibility = (selectedSeries) => {
27
+ const { chartEchartRef } = useChartRefsContext();
28
+ const setOnlyVisible = useCallback((name) => {
29
+ if (chartEchartRef.current === null) return;
30
+ const chart = getInstanceByDom(chartEchartRef.current);
31
+ chart === null || chart === void 0 || chart.dispatchAction({
32
+ name,
33
+ type: "legendSelect"
34
+ });
35
+ Object.keys(selectedSeries).filter((seriesName) => seriesName !== name).forEach((name) => {
36
+ if (isThresholdLine(name)) return;
37
+ chart === null || chart === void 0 || chart.dispatchAction({
38
+ name,
39
+ type: "legendUnSelect"
40
+ });
41
+ });
42
+ }, [chartEchartRef, selectedSeries]);
43
+ const setAllVisible = useCallback(() => {
44
+ if (chartEchartRef.current === null) return;
45
+ const chart = getInstanceByDom(chartEchartRef.current);
46
+ chart === null || chart === void 0 || chart.dispatchAction({ type: "legendAllSelect" });
47
+ }, [chartEchartRef]);
48
+ return { toggleLegendVisibility: useCallback((name, isAllSeriesSelected, isOnlyVisible) => {
49
+ if (chartEchartRef.current === null || name === void 0) return;
50
+ if (isOnlyVisible) setAllVisible();
51
+ else if (isAllSeriesSelected) setOnlyVisible(name);
52
+ else {
53
+ const chart = getInstanceByDom(chartEchartRef.current);
54
+ chart === null || chart === void 0 || chart.dispatchAction({
55
+ name,
56
+ type: "legendToggleSelect"
57
+ });
58
+ }
59
+ }, [
60
+ chartEchartRef,
61
+ setOnlyVisible,
62
+ setAllVisible
63
+ ]) };
64
+ };
65
+ export { useLegendVisibility };
66
+
67
+ //# sourceMappingURL=use-legend-visibility.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-legend-visibility.mjs","names":[],"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,mBAAmB,oBAAoB;CAE/C,MAAM,iBAAiB,aACpB,SAA6B;EAC5B,IAAI,eAAe,YAAY,MAC7B;EAEF,MAAM,QAAQ,iBAAiB,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,IAAI,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,gBAAgB,kBAAkB;EACtC,IAAI,eAAe,YAAY,MAC7B;EAGF,MAAM,QAAQ,iBAAiB,eAAe,OAAO;EAErD,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,eAAe,EACpB,MAAM,kBACR,CAAC;CACH,GAAG,CAAC,cAAc,CAAC;CAuCnB,OAAO,EAAE,wBA1BsB,aAE3B,MACA,qBACA,kBACG;EACH,IAAI,eAAe,YAAY,QAAQ,SAAS,KAAA,GAC9C;EAGF,IAAI,eACF,cAAc;OACT,IAAI,qBACT,eAAe,IAAI;OACd;GACL,MAAM,QAAQ,iBAAiB,eAAe,OAAO;GAErD,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,eAAe;IACd;IACN,MAAM;GACR,CAAC;EACH;CACF,GACA;EAAC;EAAgB;EAAgB;CAAa,CAGlB,EAAE;AAClC"}
@@ -0,0 +1,27 @@
1
+ import { Chart } from "./Chart.mjs";
2
+ import { ChartEmpty } from "./ChartEmpty.mjs";
3
+ import { defaultThresholdLineSeriesOption } from "./utils/defaults.mjs";
4
+ // src/charts/index.ts
5
+ /*!
6
+ *
7
+ * Copyright (c) "Neo4j"
8
+ * Neo4j Sweden AB [http://neo4j.com]
9
+ *
10
+ * This file is part of Neo4j.
11
+ *
12
+ * Neo4j is free software: you can redistribute it and/or modify
13
+ * it under the terms of the GNU General Public License as published by
14
+ * the Free Software Foundation, either version 3 of the License, or
15
+ * (at your option) any later version.
16
+ *
17
+ * This program is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
+ */
25
+ export { Chart, ChartEmpty, defaultThresholdLineSeriesOption };
26
+
27
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/charts/index.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\nexport * from './Chart';\nexport * from './ChartEmpty';\n// Export utils and types that were previously exported from Chart.tsx. Not sure that they are needed, but keeping them to not be breaking.\nexport { defaultThresholdLineSeriesOption } from './utils/defaults';\nexport { type TooltipValueContext } from './utils/chart-tooltip-formatter';\nexport {\n type ChartEmptyProps,\n type ChartZoomEntry,\n type ThresholdLineSeriesOption,\n type Values,\n type SeriesOption,\n type EchartsSeries,\n type NeedleSeries,\n} from './utils/chart-types';\n"],"mappings":""}