@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
@@ -1,52 +1,55 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ let react = require("react");
7
+ // src/charts/hooks/use-chart-refs.ts
2
8
  /*!
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.ChartRefsProvider = ChartRefsProvider;
24
- exports.useChartRefsContext = useChartRefsContext;
25
- const react_1 = require("react");
26
- const ChartRefsContext = (0, react_1.createContext)(undefined);
9
+ *
10
+ * Copyright (c) "Neo4j"
11
+ * Neo4j Sweden AB [http://neo4j.com]
12
+ *
13
+ * This file is part of Neo4j.
14
+ *
15
+ * Neo4j is free software: you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License as published by
17
+ * the Free Software Foundation, either version 3 of the License, or
18
+ * (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
+ */
28
+ const ChartRefsContext = (0, react.createContext)(void 0);
27
29
  /**
28
- * Creates the mutable refs shared between `ChartRender` and legend components.
29
- *
30
- * `chartEchartRef` points at the ECharts host element, while the legend refs act
31
- * as a bridge for state that ECharts needs synchronously during option rebuilds
32
- * without forcing extra React renders.
33
- */
30
+ * Creates the mutable refs shared between `ChartRender` and legend components.
31
+ *
32
+ * `chartEchartRef` points at the ECharts host element, while the legend refs act
33
+ * as a bridge for state that ECharts needs synchronously during option rebuilds
34
+ * without forcing extra React renders.
35
+ */
34
36
  function ChartRefsProvider({ children }) {
35
- const chartEchartRef = (0, react_1.useRef)(null);
36
- const legendSelectedRef = (0, react_1.useRef)({});
37
- const legendColorCacheRef = (0, react_1.useRef)(new Map());
38
- const refs = (0, react_1.useMemo)(() => ({
39
- chartEchartRef,
40
- legendColorCacheRef,
41
- legendSelectedRef,
42
- }), []);
43
- return (0, react_1.createElement)(ChartRefsContext.Provider, { value: refs }, children);
37
+ const chartEchartRef = (0, react.useRef)(null);
38
+ const legendSelectedRef = (0, react.useRef)({});
39
+ const legendColorCacheRef = (0, react.useRef)(/* @__PURE__ */ new Map());
40
+ const refs = (0, react.useMemo)(() => ({
41
+ chartEchartRef,
42
+ legendColorCacheRef,
43
+ legendSelectedRef
44
+ }), []);
45
+ return (0, react.createElement)(ChartRefsContext.Provider, { value: refs }, children);
44
46
  }
45
47
  function useChartRefsContext() {
46
- const refs = (0, react_1.useContext)(ChartRefsContext);
47
- if (refs === undefined) {
48
- throw new Error('useChartRefsContext must be used within ChartRefsProvider');
49
- }
50
- return refs;
48
+ const refs = (0, react.useContext)(ChartRefsContext);
49
+ if (refs === void 0) throw new Error("useChartRefsContext must be used within ChartRefsProvider");
50
+ return refs;
51
51
  }
52
+ exports.ChartRefsProvider = ChartRefsProvider;
53
+ exports.useChartRefsContext = useChartRefsContext;
54
+
52
55
  //# sourceMappingURL=use-chart-refs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-chart-refs.js","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-refs.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AA0BH,8CAcC;AAED,kDASC;AAjDD,iCAOe;AAQf,MAAM,gBAAgB,GAAG,IAAA,qBAAa,EAAwB,SAAS,CAAC,CAAC;AAEzE;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAA2B;IACrE,MAAM,cAAc,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IACpD,MAAM,iBAAiB,GAAG,IAAA,cAAM,EAA0B,EAAE,CAAC,CAAC;IAC9D,MAAM,mBAAmB,GAAG,IAAA,cAAM,EAAsB,IAAI,GAAG,EAAE,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,IAAA,eAAO,EAClB,GAAG,EAAE,CAAC,CAAC;QACL,cAAc;QACd,mBAAmB;QACnB,iBAAiB;KAClB,CAAC,EACF,EAAE,CACH,CAAC;IAEF,OAAO,IAAA,qBAAa,EAAC,gBAAgB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC7E,CAAC;AAED,SAAgB,mBAAmB;IACjC,MAAM,IAAI,GAAG,IAAA,kBAAU,EAAC,gBAAgB,CAAC,CAAC;IAC1C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","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"]}
1
+ {"version":3,"file":"use-chart-refs.js","names":["createContext","useRef","useMemo","createElement","useContext"],"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,oBAAA,GAAmBA,MAAAA,cAAAA,CAAqC,KAAA,CAAS;;;;;;;;AASvE,SAAgB,kBAAkB,EAAE,YAAqC;CACvE,MAAM,kBAAA,GAAiBC,MAAAA,OAAAA,CAAuB,IAAI;CAClD,MAAM,qBAAA,GAAoBA,MAAAA,OAAAA,CAAgC,CAAC,CAAC;CAC5D,MAAM,uBAAA,GAAsBA,MAAAA,OAAAA,iBAA4B,IAAI,IAAI,CAAC;CACjE,MAAM,QAAA,GAAOC,MAAAA,QAAAA,QACJ;EACL;EACA;EACA;CACF,IACA,CAAC,CACH;CAEA,QAAA,GAAOC,MAAAA,cAAAA,CAAc,iBAAiB,UAAU,EAAE,OAAO,KAAK,GAAG,QAAQ;AAC3E;AAEA,SAAgB,sBAAsB;CACpC,MAAM,QAAA,GAAOC,MAAAA,WAAAA,CAAW,gBAAgB;CACxC,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MACR,2DACF;CAGF,OAAO;AACT"}
@@ -1,132 +1,107 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ const require_charts_hooks_use_chart_refs = require("./use-chart-refs.js");
7
+ let react = require("react");
8
+ let echarts = require("echarts");
9
+ // src/charts/hooks/use-chart-zoom.ts
2
10
  /*!
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.useChartZoom = useChartZoom;
24
- const echarts_1 = require("echarts");
25
- const react_1 = require("react");
26
- const use_chart_refs_1 = require("./use-chart-refs");
11
+ *
12
+ * Copyright (c) "Neo4j"
13
+ * Neo4j Sweden AB [http://neo4j.com]
14
+ *
15
+ * This file is part of Neo4j.
16
+ *
17
+ * Neo4j is free software: you can redistribute it and/or modify
18
+ * it under the terms of the GNU General Public License as published by
19
+ * the Free Software Foundation, either version 3 of the License, or
20
+ * (at your option) any later version.
21
+ *
22
+ * This program is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ * GNU General Public License for more details.
26
+ *
27
+ * You should have received a copy of the GNU General Public License
28
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
+ */
27
30
  /**
28
- * Owns ECharts zoom interactions and forwards zoom changes to consumers.
29
- *
30
- * The hook subscribes to ECharts `datazoom` events, enables drag-to-zoom through
31
- * ECharts' global cursor API, resets zoom on double click, and clears ECharts'
32
- * SVG cursor override after mouse movement so Needle's default cursor styling is
33
- * preserved.
34
- *
35
- * The effect re-runs on every render, so each listener has to be detached again
36
- * on cleanup. Otherwise they pile up and consumers get one `onZoom` call per
37
- * render that has happened so far.
38
- */
39
- function useChartZoom({ callbacks, isChartZoomDisabled, }) {
40
- const { chartEchartRef } = (0, use_chart_refs_1.useChartRefsContext)();
41
- (0, react_1.useEffect)(() => {
42
- var _a;
43
- const chart = chartEchartRef.current === null
44
- ? undefined
45
- : (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
46
- const handleDataZoom = () => {
47
- var _a, _b;
48
- if (chartEchartRef.current === null) {
49
- return;
50
- }
51
- const currentChart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
52
- if (!currentChart) {
53
- return;
54
- }
55
- const chartOption = currentChart.getOption();
56
- const echartsDataZoom = ((_a = chartOption.dataZoom) !== null && _a !== void 0 ? _a : []);
57
- const dataZoom = echartsDataZoom
58
- .filter((entry) => entry !== null)
59
- // map to trim unnecessary values, just keeping the relevant fields
60
- .map(({ end, endValue, id, start, startValue, xAxisIndex, yAxisIndex, }) => ({
61
- endPercent: end,
62
- endValue,
63
- id,
64
- startPercent: start,
65
- startValue,
66
- xAxisIndex,
67
- yAxisIndex,
68
- }));
69
- if (dataZoom.length === 0) {
70
- return;
71
- }
72
- (_b = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _b === void 0 ? void 0 : _b.call(callbacks, {
73
- dataZoom,
74
- endValue: dataZoom[0].endValue,
75
- startValue: dataZoom[0].startValue,
76
- });
77
- };
78
- if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
79
- chart === null || chart === void 0 ? void 0 : chart.on('datazoom', handleDataZoom);
80
- }
81
- const handleMouseMove = () => {
82
- // ECharts updates SVG cursor styles on mouse move, so Needle has to
83
- // reset it after ECharts' internal handler runs.
84
- chart === null || chart === void 0 ? void 0 : chart.getZr().setCursorStyle('default');
85
- };
86
- const chartChild = (_a = chartEchartRef.current) === null || _a === void 0 ? void 0 : _a.children[0];
87
- if (!isChartZoomDisabled) {
88
- chartChild === null || chartChild === void 0 ? void 0 : chartChild.addEventListener('mousemove', handleMouseMove);
89
- }
90
- const handleMouseDown = (params) => {
91
- const event = params.event;
92
- const amountOfMouseClicks = event.detail;
93
- const isDoubleClick = amountOfMouseClicks === 2;
94
- if (isDoubleClick) {
95
- if (chart === undefined) {
96
- return;
97
- }
98
- chart === null || chart === void 0 ? void 0 : chart.dispatchAction({
99
- end: 100,
100
- start: 0,
101
- type: 'dataZoom',
102
- });
103
- }
104
- };
105
- if (!isChartZoomDisabled) {
106
- chart === null || chart === void 0 ? void 0 : chart.getZr().on('mousedown', handleMouseDown);
107
- }
108
- const chartRefCurrentElement = chartEchartRef.current;
109
- const element = chartRefCurrentElement === null || chartRefCurrentElement === void 0 ? void 0 : chartRefCurrentElement.children[0];
110
- return () => {
111
- element === null || element === void 0 ? void 0 : element.removeEventListener('mousemove', handleMouseMove);
112
- if (chartRefCurrentElement) {
113
- const chart = (0, echarts_1.getInstanceByDom)(chartRefCurrentElement);
114
- chart === null || chart === void 0 ? void 0 : chart.off('datazoom', handleDataZoom);
115
- chart === null || chart === void 0 ? void 0 : chart.getZr().off('mousedown', handleMouseDown);
116
- }
117
- };
118
- });
119
- if (chartEchartRef.current !== null && !isChartZoomDisabled) {
120
- const chart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
121
- if (chart) {
122
- // Needs to be re-set on every re-render. Sets the selectable zoom area
123
- // over the chart body, not the slider.
124
- chart.dispatchAction({
125
- dataZoomSelectActive: true,
126
- key: 'dataZoomSelect',
127
- type: 'takeGlobalCursor',
128
- });
129
- }
130
- }
31
+ * Owns ECharts zoom interactions and forwards zoom changes to consumers.
32
+ *
33
+ * The hook subscribes to ECharts `datazoom` events, enables drag-to-zoom through
34
+ * ECharts' global cursor API, resets zoom on double click, and clears ECharts'
35
+ * SVG cursor override after mouse movement so Needle's default cursor styling is
36
+ * preserved.
37
+ *
38
+ * The effect re-runs on every render, so each listener has to be detached again
39
+ * on cleanup. Otherwise they pile up and consumers get one `onZoom` call per
40
+ * render that has happened so far.
41
+ */
42
+ function useChartZoom({ callbacks, isChartZoomDisabled }) {
43
+ const { chartEchartRef } = require_charts_hooks_use_chart_refs.useChartRefsContext();
44
+ (0, react.useEffect)(() => {
45
+ var _chartEchartRef$curre;
46
+ const chart = chartEchartRef.current === null ? void 0 : (0, echarts.getInstanceByDom)(chartEchartRef.current);
47
+ const handleDataZoom = () => {
48
+ var _chartOption$dataZoom, _callbacks$onZoom;
49
+ if (chartEchartRef.current === null) return;
50
+ const currentChart = (0, echarts.getInstanceByDom)(chartEchartRef.current);
51
+ if (!currentChart) return;
52
+ 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 }) => ({
53
+ endPercent: end,
54
+ endValue,
55
+ id,
56
+ startPercent: start,
57
+ startValue,
58
+ xAxisIndex,
59
+ yAxisIndex
60
+ }));
61
+ if (dataZoom.length === 0) return;
62
+ callbacks === null || callbacks === void 0 || (_callbacks$onZoom = callbacks.onZoom) === null || _callbacks$onZoom === void 0 || _callbacks$onZoom.call(callbacks, {
63
+ dataZoom,
64
+ endValue: dataZoom[0].endValue,
65
+ startValue: dataZoom[0].startValue
66
+ });
67
+ };
68
+ if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) chart === null || chart === void 0 || chart.on("datazoom", handleDataZoom);
69
+ const handleMouseMove = () => {
70
+ chart === null || chart === void 0 || chart.getZr().setCursorStyle("default");
71
+ };
72
+ const chartChild = (_chartEchartRef$curre = chartEchartRef.current) === null || _chartEchartRef$curre === void 0 ? void 0 : _chartEchartRef$curre.children[0];
73
+ if (!isChartZoomDisabled) chartChild === null || chartChild === void 0 || chartChild.addEventListener("mousemove", handleMouseMove);
74
+ const handleMouseDown = (params) => {
75
+ if (params.event.detail === 2) {
76
+ if (chart === void 0) return;
77
+ chart === null || chart === void 0 || chart.dispatchAction({
78
+ end: 100,
79
+ start: 0,
80
+ type: "dataZoom"
81
+ });
82
+ }
83
+ };
84
+ if (!isChartZoomDisabled) chart === null || chart === void 0 || chart.getZr().on("mousedown", handleMouseDown);
85
+ const chartRefCurrentElement = chartEchartRef.current;
86
+ const element = chartRefCurrentElement === null || chartRefCurrentElement === void 0 ? void 0 : chartRefCurrentElement.children[0];
87
+ return () => {
88
+ element === null || element === void 0 || element.removeEventListener("mousemove", handleMouseMove);
89
+ if (chartRefCurrentElement) {
90
+ const chart = (0, echarts.getInstanceByDom)(chartRefCurrentElement);
91
+ chart === null || chart === void 0 || chart.off("datazoom", handleDataZoom);
92
+ chart === null || chart === void 0 || chart.getZr().off("mousedown", handleMouseDown);
93
+ }
94
+ };
95
+ });
96
+ if (chartEchartRef.current !== null && !isChartZoomDisabled) {
97
+ const chart = (0, echarts.getInstanceByDom)(chartEchartRef.current);
98
+ if (chart) chart.dispatchAction({
99
+ dataZoomSelectActive: true,
100
+ key: "dataZoomSelect",
101
+ type: "takeGlobalCursor"
102
+ });
103
+ }
131
104
  }
105
+ exports.useChartZoom = useChartZoom;
106
+
132
107
  //# sourceMappingURL=use-chart-zoom.js.map
@@ -1 +1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BAAkB;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC","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"]}
1
+ {"version":3,"file":"use-chart-zoom.js","names":["useChartRefsContext","getInstanceByDom"],"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,mBAAmBA,oCAAAA,oBAAoB;CAE/C,CAAA,GAAA,MAAA,UAAA,OAAgB;;EACd,MAAM,QACJ,eAAe,YAAY,OACvB,KAAA,KAAA,GACAC,QAAAA,iBAAAA,CAAiB,eAAe,OAAO;EAE7C,MAAM,uBAAuB;;GAC3B,IAAI,eAAe,YAAY,MAC7B;GAGF,MAAM,gBAAA,GAAeA,QAAAA,iBAAAA,CAAiB,eAAe,OAAO;GAC5D,IAAI,CAAC,cACH;GAMF,MAAM,aAAA,wBAHc,aAAa,UACE,CAAC,CAAC,cAAA,QAAA,0BAAA,KAAA,IAAA,wBACnC,CAAC,EAAA,CAEA,QAAQ,UAAU,UAAU,IAAI,CAAC,CAEjC,KACE,EACC,KACA,UACA,IACA,OACA,YACA,YACA,kBACK;IACL,YAAY;IACZ;IACA;IACA,cAAc;IACd;IACA;IACA;GACF,EACF;GACF,IAAI,SAAS,WAAW,GACtB;GAGF,cAAA,QAAA,cAAA,KAAA,MAAA,oBAAA,UAAW,YAAA,QAAA,sBAAA,KAAA,KAAA,kBAAA,KAAA,WAAS;IAClB;IACA,UAAU,SAAS,EAAE,CAAC;IACtB,YAAY,SAAS,EAAE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