@neo4j-ndl/react-charts 2.1.0 → 2.1.2

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.
@@ -44,7 +44,7 @@ function useChartZoom({ callbacks, isChartZoomDisabled, }) {
44
44
  ? undefined
45
45
  : (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
46
46
  const handleDataZoom = () => {
47
- var _a;
47
+ var _a, _b;
48
48
  if (chartEchartRef.current === null) {
49
49
  return;
50
50
  }
@@ -52,15 +52,28 @@ function useChartZoom({ callbacks, isChartZoomDisabled, }) {
52
52
  if (!currentChart) {
53
53
  return;
54
54
  }
55
- const option = currentChart.getOption();
56
- if (!option || !option.dataZoom) {
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) {
57
70
  return;
58
71
  }
59
- const dataZoom = Array.isArray(option.dataZoom)
60
- ? option.dataZoom[0]
61
- : option.dataZoom;
62
- const { startValue, endValue } = dataZoom;
63
- (_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _a === void 0 ? void 0 : _a.call(callbacks, { endValue, startValue });
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
+ });
64
77
  };
65
78
  if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
66
79
  chart === null || chart === void 0 ? void 0 : chart.on('datazoom', handleDataZoom);
@@ -75,7 +88,6 @@ function useChartZoom({ callbacks, isChartZoomDisabled, }) {
75
88
  chartChild === null || chartChild === void 0 ? void 0 : chartChild.addEventListener('mousemove', handleMouseMove);
76
89
  }
77
90
  const handleMouseDown = (params) => {
78
- var _a;
79
91
  const event = params.event;
80
92
  const amountOfMouseClicks = event.detail;
81
93
  const isDoubleClick = amountOfMouseClicks === 2;
@@ -88,9 +100,6 @@ function useChartZoom({ callbacks, isChartZoomDisabled, }) {
88
100
  start: 0,
89
101
  type: 'dataZoom',
90
102
  });
91
- if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
92
- (_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _a === void 0 ? void 0 : _a.call(callbacks, { endValue: 100, startValue: 0 });
93
- }
94
103
  }
95
104
  };
96
105
  if (!isChartZoomDisabled) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-chart-zoom.js","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AAyBH,oCAqGC;AA5HD,qCAA2C;AAC3C,iCAAkC;AAGlC,qDAAuD;AAOvD;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,mBAAmB,GACA;IACnB,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,oCAAmB,GAAE,CAAC;IAEjD,IAAA,iBAAS,EAAC,GAAG,EAAE;;QACb,MAAM,KAAK,GACT,cAAc,CAAC,OAAO,KAAK,IAAI;YAC7B,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAA,0BAAgB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE/C,MAAM,cAAc,GAAG,GAAG,EAAE;;YAC1B,IAAI,cAAc,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBACpC,OAAO;YACT,CAAC;YAED,MAAM,YAAY,GAAG,IAAA,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K,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;YACnD,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAI,cAAc,CAAC,OAAO,KAAK,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC5D,MAAM,KAAK,GAAG,IAAA,0BAAgB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,KAAK,EAAE,CAAC;YACV,uEAAuE;YACvE,uCAAuC;YACvC,KAAK,CAAC,cAAc,CAAC;gBACnB,oBAAoB,EAAE,IAAI;gBAC1B,GAAG,EAAE,gBAAgB;gBACrB,IAAI,EAAE,kBAAkB;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 } from '../utils/chart-types';\nimport { useChartRefsContext } from './use-chart-refs';\n\ntype UseChartZoomParams = {\n callbacks: ChartProps['callbacks'];\n isChartZoomDisabled: boolean;\n};\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 option = currentChart.getOption();\n if (!option || !option.dataZoom) {\n return;\n }\n\n const dataZoom = Array.isArray(option.dataZoom)\n ? option.dataZoom[0]\n : option.dataZoom;\n const { startValue, endValue } = dataZoom as {\n startValue: number;\n endValue: number;\n };\n\n callbacks?.onZoom?.({ endValue, startValue });\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 if (callbacks?.onZoom) {\n callbacks?.onZoom?.({ endValue: 100, startValue: 0 });\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","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AAgCH,oCAsHC;AApJD,qCAA2C;AAC3C,iCAAkC;AAGlC,qDAAuD;AAcvD;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,mBAAmB,GACA;IACnB,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,oCAAmB,GAAE,CAAC;IAEjD,IAAA,iBAAS,EAAC,GAAG,EAAE;;QACb,MAAM,KAAK,GACT,cAAc,CAAC,OAAO,KAAK,IAAI;YAC7B,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAA,0BAAgB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE/C,MAAM,cAAc,GAAG,GAAG,EAAE;;YAC1B,IAAI,cAAc,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBACpC,OAAO;YACT,CAAC;YAED,MAAM,YAAY,GAAG,IAAA,0BAAgB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAC9D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,MAAM,WAAW,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC;YAC7C,MAAM,eAAe,GAAG,CAAC,MAAA,WAAW,CAAC,QAAQ,mCAC3C,EAAE,CAAoC,CAAC;YACzC,MAAM,QAAQ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I,cAAc,CAAC,OAAO,KAAK,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC5D,MAAM,KAAK,GAAG,IAAA,0BAAgB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,KAAK,EAAE,CAAC;YACV,uEAAuE;YACvE,uCAAuC;YACvC,KAAK,CAAC,cAAc,CAAC;gBACnB,oBAAoB,EAAE,IAAI;gBAC1B,GAAG,EAAE,gBAAgB;gBACrB,IAAI,EAAE,kBAAkB;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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/charts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,+CAA6B;AAC7B,2IAA2I;AAC3I,6CAAoE;AAA3D,4HAAA,gCAAgC,OAAA","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 ThresholdLineSeriesOption,\n type Values,\n type SeriesOption,\n type EchartsSeries,\n type NeedleSeries,\n} from './utils/chart-types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/charts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,+CAA6B;AAC7B,2IAA2I;AAC3I,6CAAoE;AAA3D,4HAAA,gCAAgC,OAAA","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"]}
@@ -33,12 +33,31 @@ const zoomHarnessDataset = [
33
33
  Number((40 + Math.sin(index / 6) * 12).toFixed(2)),
34
34
  ]),
35
35
  ];
36
+ const defaultOption = {
37
+ dataZoom: [
38
+ {
39
+ filterMode: 'none',
40
+ type: 'inside',
41
+ zoomOnMouseWheel: false,
42
+ },
43
+ ],
44
+ toolbox: {
45
+ feature: {
46
+ dataZoom: {
47
+ yAxisIndex: false,
48
+ },
49
+ },
50
+ },
51
+ };
36
52
  /**
37
53
  * Reproduces the consumer setup from the metrics UI: a chart with toolbox
38
54
  * brush-zoom whose parent re-renders while the chart stays mounted, passing a
39
55
  * freshly built `option` object on every render.
56
+ *
57
+ * `option` and `seriesType` swap in other zoom setups, such as a scatter
58
+ * chart with one slider per axis.
40
59
  */
41
- const ChartZoomHarness = ({ settings, }) => {
60
+ const ChartZoomHarness = ({ option = defaultOption, seriesType = 'line', settings, }) => {
42
61
  const containerRef = (0, react_1.useRef)(null);
43
62
  const zoomCallsRef = (0, react_1.useRef)([]);
44
63
  const [, setRerenderCount] = (0, react_1.useState)(0);
@@ -58,7 +77,7 @@ const ChartZoomHarness = ({ settings, }) => {
58
77
  var _a, _b;
59
78
  const dataZoom = (_b = (_a = getChart()) === null || _a === void 0 ? void 0 : _a.getOption()) === null || _b === void 0 ? void 0 : _b.dataZoom;
60
79
  return (dataZoom !== null && dataZoom !== void 0 ? dataZoom : [])
61
- .filter((item) => item.startValue !== undefined && item.endValue !== undefined)
80
+ .filter((item) => (item === null || item === void 0 ? void 0 : item.startValue) !== undefined && item.endValue !== undefined)
62
81
  .map((item) => ({
63
82
  endValue: item.endValue,
64
83
  startValue: item.startValue,
@@ -69,6 +88,15 @@ const ChartZoomHarness = ({ settings, }) => {
69
88
  resetZoomCalls: () => {
70
89
  zoomCallsRef.current = [];
71
90
  },
91
+ zoomTo: (dataZoomId, start, end) => {
92
+ var _a;
93
+ (_a = getChart()) === null || _a === void 0 ? void 0 : _a.dispatchAction({
94
+ dataZoomId,
95
+ end,
96
+ start,
97
+ type: 'dataZoom',
98
+ });
99
+ },
72
100
  };
73
101
  }, []);
74
102
  return ((0, jsx_runtime_1.jsxs)("div", { ref: containerRef, style: { height: '420px', width: '900px' }, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", "data-testid": "force-rerender", onClick: () => setRerenderCount((count) => count + 1), children: "Re-render" }), (0, jsx_runtime_1.jsx)("div", { className: "ndl-chart", style: { height: '380px', width: '100%' }, children: (0, jsx_runtime_1.jsx)(react_charts_1.Chart, { callbacks: { onZoom: handleZoom }, dataset: [{ source: zoomHarnessDataset }], series: [
@@ -77,24 +105,9 @@ const ChartZoomHarness = ({ settings, }) => {
77
105
  // oxlint-disable-next-line id-length
78
106
  encode: { x: 'time', y: 'value' },
79
107
  name: 'Value',
80
- type: 'line',
81
- },
82
- ], settings: settings, xAxis: { type: 'value' }, yAxis: { type: 'value' }, option: {
83
- dataZoom: [
84
- {
85
- filterMode: 'none',
86
- type: 'inside',
87
- zoomOnMouseWheel: false,
88
- },
89
- ],
90
- toolbox: {
91
- feature: {
92
- dataZoom: {
93
- yAxisIndex: false,
94
- },
95
- },
108
+ type: seriesType,
96
109
  },
97
- } }) })] }));
110
+ ], settings: settings, xAxis: { type: 'value' }, yAxis: { type: 'value' }, option: structuredClone(option) }) })] }));
98
111
  };
99
112
  exports.ChartZoomHarness = ChartZoomHarness;
100
113
  //# sourceMappingURL=ChartZoomHarness.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChartZoomHarness.js","sourceRoot":"","sources":["../../../../src/charts/tests/ChartZoomHarness.tsx"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0DAAgD;AAChD,qCAA2C;AAC3C,iCAMe;AAkBf,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,kBAAkB,GAAG;IACzB,CAAC,MAAM,EAAE,OAAO,CAAC;IACjB,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,KAAK;QACL,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACnD,CAAC;CACH,CAAC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AAE;wBACN,QAAQ,EAAE;4BACR;gCACE,UAAU,EAAE,MAAM;gCAClB,IAAI,EAAE,QAAQ;gCACd,gBAAgB,EAAE,KAAK;6BACxB;yBACF;wBACD,OAAO,EAAE;4BACP,OAAO,EAAE;gCACP,QAAQ,EAAE;oCACR,UAAU,EAAE,KAAK;iCAClB;6BACF;yBACF;qBACF,GACD,GACE,IACF,CACP,CAAC;AACJ,CAAC,CAAC;AA9FW,QAAA,gBAAgB,oBA8F3B","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 { Chart } from '@neo4j-ndl/react-charts';\nimport { getInstanceByDom } from 'echarts';\nimport {\n type ComponentProps,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\ntype ChartSettings = ComponentProps<typeof Chart>['settings'];\n\nexport type ZoomCall = { endValue: number; startValue: number };\n\nexport type ZoomHarnessApi = {\n /** Applied zoom windows, in data values, as ECharts currently has them. */\n getAppliedZoomWindows: () => ZoomCall[];\n /** Every `callbacks.onZoom` invocation the consumer received. */\n getZoomCalls: () => ZoomCall[];\n /** Data value at a pixel offset inside the chart element. */\n pixelToValue: (pixelX: number) => number;\n resetZoomCalls: () => void;\n};\n\ntype HarnessWindow = Window & { chartZoomHarness?: ZoomHarnessApi };\n\nconst POINT_COUNT = 180;\n\nconst zoomHarnessDataset = [\n ['time', 'value'],\n ...Array.from({ length: POINT_COUNT }, (_unused, index) => [\n index,\n Number((40 + Math.sin(index / 6) * 12).toFixed(2)),\n ]),\n];\n\n/**\n * Reproduces the consumer setup from the metrics UI: a chart with toolbox\n * brush-zoom whose parent re-renders while the chart stays mounted, passing a\n * freshly built `option` object on every render.\n */\nexport const ChartZoomHarness = ({\n settings,\n}: {\n settings?: ChartSettings;\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const zoomCallsRef = useRef<ZoomCall[]>([]);\n const [, setRerenderCount] = useState(0);\n\n const handleZoom = useCallback((zoom: ZoomCall) => {\n zoomCallsRef.current = [...zoomCallsRef.current, zoom];\n }, []);\n\n useEffect(() => {\n const getChart = () => {\n const echartElement =\n containerRef.current?.querySelector('.ndl-chart-echart');\n return echartElement instanceof HTMLElement\n ? getInstanceByDom(echartElement)\n : undefined;\n };\n\n (window as HarnessWindow).chartZoomHarness = {\n getAppliedZoomWindows: () => {\n const dataZoom = (\n getChart()?.getOption() as\n | { dataZoom?: { endValue?: number; startValue?: number }[] }\n | undefined\n )?.dataZoom;\n\n return (dataZoom ?? [])\n .filter(\n (item) =>\n item.startValue !== undefined && item.endValue !== undefined,\n )\n .map((item) => ({\n endValue: item.endValue as number,\n startValue: item.startValue as number,\n }));\n },\n getZoomCalls: () => zoomCallsRef.current,\n pixelToValue: (pixelX: number) =>\n getChart()?.convertFromPixel({ xAxisIndex: 0 }, pixelX) as number,\n resetZoomCalls: () => {\n zoomCallsRef.current = [];\n },\n };\n }, []);\n\n return (\n <div ref={containerRef} style={{ height: '420px', width: '900px' }}>\n <button\n type=\"button\"\n data-testid=\"force-rerender\"\n onClick={() => setRerenderCount((count) => count + 1)}\n >\n Re-render\n </button>\n <div className=\"ndl-chart\" style={{ height: '380px', width: '100%' }}>\n <Chart\n callbacks={{ onZoom: handleZoom }}\n dataset={[{ source: zoomHarnessDataset }]}\n series={[\n {\n // E-Charts uses encode.x and encode.y - https://echarts.apache.org/en/option.html#series-line.encode\n // oxlint-disable-next-line id-length\n encode: { x: 'time', y: 'value' },\n name: 'Value',\n type: 'line',\n },\n ]}\n settings={settings}\n xAxis={{ type: 'value' }}\n yAxis={{ type: 'value' }}\n option={{\n dataZoom: [\n {\n filterMode: 'none',\n type: 'inside',\n zoomOnMouseWheel: false,\n },\n ],\n toolbox: {\n feature: {\n dataZoom: {\n yAxisIndex: false,\n },\n },\n },\n }}\n />\n </div>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"ChartZoomHarness.js","sourceRoot":"","sources":["../../../../src/charts/tests/ChartZoomHarness.tsx"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0DAAgD;AAChD,qCAA2C;AAC3C,iCAMe;AA8Bf,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,kBAAkB,GAAG;IACzB,CAAC,MAAM,EAAE,OAAO,CAAC;IACjB,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,KAAK;QACL,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACnD,CAAC;CACH,CAAC;AAEF,MAAM,aAAa,GAAgB;IACjC,QAAQ,EAAE;QACR;YACE,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,QAAQ;YACd,gBAAgB,EAAE,KAAK;SACxB;KACF;IACD,OAAO,EAAE;QACP,OAAO,EAAE;YACP,QAAQ,EAAE;gBACR,UAAU,EAAE,KAAK;aAClB;SACF;KACF;CACF,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAAC,EAC/B,MAAM,GAAG,aAAa,EACtB,UAAU,GAAG,MAAM,EACnB,QAAQ,GAKT,EAAE,EAAE;IACH,MAAM,YAAY,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,YAAY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AAI,EAAE,OAAO,EAAE,EACxB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACxB,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAC/B,GACE,IACF,CACP,CAAC;AACJ,CAAC,CAAC;AAhGW,QAAA,gBAAgB,oBAgG3B","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 { Chart } from '@neo4j-ndl/react-charts';\nimport { getInstanceByDom } from 'echarts';\nimport {\n type ComponentProps,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport type { ChartZoomEntry } from '../utils/chart-types';\n\ntype ChartComponentProps = ComponentProps<typeof Chart>;\ntype ChartSettings = ChartComponentProps['settings'];\nexport type ChartOption = ChartComponentProps['option'];\n\nexport type ZoomCall = {\n dataZoom: ChartZoomEntry[];\n endValue: number;\n startValue: number;\n};\n\nexport type ZoomWindow = { endValue: number; startValue: number };\n\nexport type ZoomHarnessApi = {\n /** Applied zoom windows, in data values, as ECharts currently has them. */\n getAppliedZoomWindows: () => ZoomWindow[];\n /** Every `callbacks.onZoom` invocation the consumer received. */\n getZoomCalls: () => ZoomCall[];\n /** Data value at a pixel offset inside the chart element. */\n pixelToValue: (pixelX: number) => number;\n resetZoomCalls: () => void;\n /** Applies a zoom window, in percent, to one `dataZoom` entry by its `id`. */\n zoomTo: (dataZoomId: string, start: number, end: number) => void;\n};\n\ntype HarnessWindow = Window & { chartZoomHarness?: ZoomHarnessApi };\n\nconst POINT_COUNT = 180;\n\nconst zoomHarnessDataset = [\n ['time', 'value'],\n ...Array.from({ length: POINT_COUNT }, (_unused, index) => [\n index,\n Number((40 + Math.sin(index / 6) * 12).toFixed(2)),\n ]),\n];\n\nconst defaultOption: ChartOption = {\n dataZoom: [\n {\n filterMode: 'none',\n type: 'inside',\n zoomOnMouseWheel: false,\n },\n ],\n toolbox: {\n feature: {\n dataZoom: {\n yAxisIndex: false,\n },\n },\n },\n};\n\n/**\n * Reproduces the consumer setup from the metrics UI: a chart with toolbox\n * brush-zoom whose parent re-renders while the chart stays mounted, passing a\n * freshly built `option` object on every render.\n *\n * `option` and `seriesType` swap in other zoom setups, such as a scatter\n * chart with one slider per axis.\n */\nexport const ChartZoomHarness = ({\n option = defaultOption,\n seriesType = 'line',\n settings,\n}: {\n option?: ChartOption;\n seriesType?: 'line' | 'scatter';\n settings?: ChartSettings;\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const zoomCallsRef = useRef<ZoomCall[]>([]);\n const [, setRerenderCount] = useState(0);\n\n const handleZoom = useCallback((zoom: ZoomCall) => {\n zoomCallsRef.current = [...zoomCallsRef.current, zoom];\n }, []);\n\n useEffect(() => {\n const getChart = () => {\n const echartElement =\n containerRef.current?.querySelector('.ndl-chart-echart');\n return echartElement instanceof HTMLElement\n ? getInstanceByDom(echartElement)\n : undefined;\n };\n\n (window as HarnessWindow).chartZoomHarness = {\n getAppliedZoomWindows: () => {\n const dataZoom = (\n getChart()?.getOption() as\n | {\n dataZoom?: ({\n endValue?: number;\n startValue?: number;\n } | null)[];\n }\n | undefined\n )?.dataZoom;\n\n return (dataZoom ?? [])\n .filter(\n (item): item is ZoomWindow =>\n item?.startValue !== undefined && item.endValue !== undefined,\n )\n .map((item) => ({\n endValue: item.endValue as number,\n startValue: item.startValue as number,\n }));\n },\n getZoomCalls: () => zoomCallsRef.current,\n pixelToValue: (pixelX: number) =>\n getChart()?.convertFromPixel({ xAxisIndex: 0 }, pixelX) as number,\n resetZoomCalls: () => {\n zoomCallsRef.current = [];\n },\n zoomTo: (dataZoomId: string, start: number, end: number) => {\n getChart()?.dispatchAction({\n dataZoomId,\n end,\n start,\n type: 'dataZoom',\n });\n },\n };\n }, []);\n\n return (\n <div ref={containerRef} style={{ height: '420px', width: '900px' }}>\n <button\n type=\"button\"\n data-testid=\"force-rerender\"\n onClick={() => setRerenderCount((count) => count + 1)}\n >\n Re-render\n </button>\n <div className=\"ndl-chart\" style={{ height: '380px', width: '100%' }}>\n <Chart\n callbacks={{ onZoom: handleZoom }}\n dataset={[{ source: zoomHarnessDataset }]}\n series={[\n {\n // E-Charts uses encode.x and encode.y - https://echarts.apache.org/en/option.html#series-line.encode\n // oxlint-disable-next-line id-length\n encode: { x: 'time', y: 'value' },\n name: 'Value',\n type: seriesType,\n },\n ]}\n settings={settings}\n xAxis={{ type: 'value' }}\n yAxis={{ type: 'value' }}\n option={structuredClone(option)}\n />\n </div>\n </div>\n );\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"chart-types.js","sourceRoot":"","sources":["../../../../src/charts/utils/chart-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG","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 type EChartsOption,\n type LineSeriesOption,\n type RegisteredSeriesOption,\n type SetOptionOpts,\n} from 'echarts';\n\nexport type HexColor = `#${string}`;\n\nexport type Condition =\n | 'greater'\n | 'greaterOrEqual'\n | 'less'\n | 'lessOrEqual'\n | 'equal'\n | 'notEqual';\n\nexport type Values<T> = T[keyof T];\nexport type SeriesOption = Values<RegisteredSeriesOption>;\n\nexport type EchartsSeries = SeriesOption | SeriesOption[];\n\ntype CustomCondition = (\n lineValue: unknown,\n thresholdLineValue: unknown,\n) => boolean;\n\nexport interface ThresholdLineSeriesOption<\n T extends NotificationType,\n> extends Omit<LineSeriesOption, 'type'> {\n type: 'thresholdLine';\n yAxis: number;\n xAxis: [number, number];\n notificationType: T;\n color?: string;\n condition?: Condition;\n customConditionText?: string;\n customCondition?: CustomCondition;\n}\n\n// Only one threshold line of each type is allowed.\nexport type NeedleSeries =\n | [\n ThresholdLineSeriesOption<'warning'>,\n ThresholdLineSeriesOption<'danger'>,\n ...SeriesOption[],\n ]\n | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]]\n | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]]\n | SeriesOption[];\n\nexport interface ChartProps {\n /** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */\n dataset: EChartsOption['dataset'];\n /** The series configuration for the chart. Defines what data to display and how to display it. */\n series: NeedleSeries;\n /** X-axis configuration for the chart. */\n xAxis?: EChartsOption['xAxis'];\n /** Y-axis configuration for the chart. */\n yAxis?: EChartsOption['yAxis'];\n /** Legend configuration for the chart. */\n legend?: {\n /** Whether the legend is visible. */\n isVisible?: boolean;\n };\n /** Additional ECharts options to merge with the chart configuration. */\n option?: Omit<\n EChartsOption,\n 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'\n >;\n /** Custom CSS styles to apply to the chart container. */\n style?: React.CSSProperties;\n /**\n * Settings for how ECharts should update the chart. Defaults to replacing the\n * components the chart owns (`series`, `dataset`, axes, and similar) while\n * merging the rest, which drops data that disappeared without discarding the\n * ECharts components behind zoom interactions. Passing `notMerge: true`\n * re-creates those components on every update and breaks drag-to-zoom.\n */\n settings?: SetOptionOpts;\n /** Whether the chart is in a loading state. */\n isLoading?: boolean;\n /** Callback functions for chart interactions. */\n callbacks?: {\n onZoom?: (params: { startValue: number; endValue: number }) => void;\n };\n /** Data zoom configuration for the chart. */\n dataZoom?: EChartsOption['dataZoom'];\n /** Whether the zoom in the chart is disabled */\n isChartZoomDisabled?: boolean;\n /** Custom color palette that overrides the default categorical colors. */\n palette?: HexColor[];\n}\n\nexport interface ChartEmptyProps {\n /** A text displayed to the user when the chart is empty. */\n message?: React.ReactNode;\n /** The type of chart. This is used to render the appropriate icon. */\n type?: 'line' | 'pie' | 'bar';\n /** Optional element (preferably a TextButton) that should provide the user with an action. */\n action?: React.ReactNode;\n}\n\n/**\n * Chart tooltip\n */\n\n/**\n * Client coordinates used to anchor a floating element at a fixed point (e.g.\n * the cursor position), instead of at an anchor element.\n */\ntype AnchorPosition = {\n // oxlint-disable-next-line id-length\n x: number;\n // oxlint-disable-next-line id-length\n y: number;\n};\n\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: AnchorPosition;\n ref?: React.Ref<HTMLDivElement>;\n}\n\nexport type NotificationType = 'warning' | 'danger';\n\nexport type Notification = {\n leadingElement: React.ReactNode;\n trailingElement: React.ReactNode;\n notificationType: NotificationType;\n id: string;\n};\n\nexport type ChartTooltipContentProps = {\n leadingElement?: React.ReactNode;\n trailingElement?: React.ReactNode;\n indentSquareColor?: string;\n notifications?: Notification[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\n/**\n * Legend\n */\nexport interface LegendItemProps {\n name: string;\n children: React.ReactNode;\n as?: 'button' | 'div';\n className?: string;\n color?: string;\n isSelected?: boolean;\n isDeselected?: boolean;\n onLegendItemClick?: () => void;\n hasButtons?: boolean;\n onLegendItemMouseEnter?: () => void;\n onLegendItemMouseLeave?: () => void;\n ref?: React.Ref<HTMLButtonElement> & React.Ref<HTMLDivElement>;\n}\n\nexport type LegendProps = {\n series: {\n name: string;\n color: string;\n }[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\nexport type HtmlAttributes<T extends React.ElementType> =\n React.ComponentPropsWithoutRef<T> & {\n [key: `data-${string}`]: string | undefined;\n };\n\ntype BaseProps<T extends React.ElementType> = {\n /**\n * Additional classnames will be applied to the root element.\n */\n className?: string;\n /**\n * Additional css styling. Will be applied to the root element.\n */\n style?: React.CSSProperties;\n\n /**\n * Html attributes to apply to the root element. This will override any default html attributes, use with caution.\n */\n htmlAttributes?: HtmlAttributes<T>;\n\n /**\n * A ref to apply to the root element.\n */\n ref?: React.ComponentPropsWithRef<T>['ref'];\n};\n\nexport type CommonProps<T extends React.ElementType, P> = P & BaseProps<T>;\n"]}
1
+ {"version":3,"file":"chart-types.js","sourceRoot":"","sources":["../../../../src/charts/utils/chart-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG","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 type EChartsOption,\n type LineSeriesOption,\n type RegisteredSeriesOption,\n type SetOptionOpts,\n} from 'echarts';\n\nexport type HexColor = `#${string}`;\n\nexport type Condition =\n | 'greater'\n | 'greaterOrEqual'\n | 'less'\n | 'lessOrEqual'\n | 'equal'\n | 'notEqual';\n\nexport type Values<T> = T[keyof T];\nexport type SeriesOption = Values<RegisteredSeriesOption>;\n\nexport type EchartsSeries = SeriesOption | SeriesOption[];\n\ntype CustomCondition = (\n lineValue: unknown,\n thresholdLineValue: unknown,\n) => boolean;\n\nexport interface ThresholdLineSeriesOption<\n T extends NotificationType,\n> extends Omit<LineSeriesOption, 'type'> {\n type: 'thresholdLine';\n yAxis: number;\n xAxis: [number, number];\n notificationType: T;\n color?: string;\n condition?: Condition;\n customConditionText?: string;\n customCondition?: CustomCondition;\n}\n\n// Only one threshold line of each type is allowed.\nexport type NeedleSeries =\n | [\n ThresholdLineSeriesOption<'warning'>,\n ThresholdLineSeriesOption<'danger'>,\n ...SeriesOption[],\n ]\n | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]]\n | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]]\n | SeriesOption[];\n\n/** The zoom window of one configured `dataZoom` component, as reported by `onZoom`. */\nexport type ChartZoomEntry = {\n id?: string | number;\n xAxisIndex?: number | number[] | false;\n yAxisIndex?: number | number[] | false;\n /** Percent, 0–100. */\n startPercent: number;\n /** Percent, 0–100. */\n endPercent: number;\n /** Data value; the category index on a category axis. */\n startValue?: number;\n /** Data value; the category index on a category axis. */\n endValue?: number;\n};\n\nexport interface ChartProps {\n /** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */\n dataset: EChartsOption['dataset'];\n /** The series configuration for the chart. Defines what data to display and how to display it. */\n series: NeedleSeries;\n /** X-axis configuration for the chart. */\n xAxis?: EChartsOption['xAxis'];\n /** Y-axis configuration for the chart. */\n yAxis?: EChartsOption['yAxis'];\n /** Legend configuration for the chart. */\n legend?: {\n /** Whether the legend is visible. */\n isVisible?: boolean;\n };\n /** Additional ECharts options to merge with the chart configuration. */\n option?: Omit<\n EChartsOption,\n 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'\n >;\n /** Custom CSS styles to apply to the chart container. */\n style?: React.CSSProperties;\n /**\n * Settings for how ECharts should update the chart. Defaults to replacing the\n * components the chart owns (`series`, `dataset`, axes, and similar) while\n * merging the rest, which drops data that disappeared without discarding the\n * ECharts components behind zoom interactions. Passing `notMerge: true`\n * re-creates those components on every update and breaks drag-to-zoom.\n */\n settings?: SetOptionOpts;\n /** Whether the chart is in a loading state. */\n isLoading?: boolean;\n /** Callback functions for chart interactions. */\n callbacks?: {\n /**\n * Called after every zoom change: slider or inside drag, drag-to-zoom and\n * the double-click reset. Only fires when `dataZoom` is configured; to\n * track drag-to-zoom on its own, add `dataZoom: [{ type: 'inside' }]`.\n *\n * `dataZoom` holds one entry per `dataZoom` component you configured, in\n * config order, so the values can be passed back as\n * `startValue`/`endValue` to restore the zoom. `id` and the axis indices\n * are copied from the config, so they are `undefined` when not set there.\n */\n onZoom?: (params: {\n // TODO v6: remove startValue and endValue\n /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].startValue` instead. */\n startValue: number;\n /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].endValue` instead. */\n endValue: number;\n dataZoom: ChartZoomEntry[];\n }) => void;\n };\n /** Data zoom configuration for the chart. */\n dataZoom?: EChartsOption['dataZoom'];\n /** Whether the zoom in the chart is disabled */\n isChartZoomDisabled?: boolean;\n /** Custom color palette that overrides the default categorical colors. */\n palette?: HexColor[];\n}\n\nexport interface ChartEmptyProps {\n /** A text displayed to the user when the chart is empty. */\n message?: React.ReactNode;\n /** The type of chart. This is used to render the appropriate icon. */\n type?: 'line' | 'pie' | 'bar';\n /** Optional element (preferably a TextButton) that should provide the user with an action. */\n action?: React.ReactNode;\n}\n\n/**\n * Chart tooltip\n */\n\n/**\n * Client coordinates used to anchor a floating element at a fixed point (e.g.\n * the cursor position), instead of at an anchor element.\n */\ntype AnchorPosition = {\n // oxlint-disable-next-line id-length\n x: number;\n // oxlint-disable-next-line id-length\n y: number;\n};\n\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: AnchorPosition;\n ref?: React.Ref<HTMLDivElement>;\n}\n\nexport type NotificationType = 'warning' | 'danger';\n\nexport type Notification = {\n leadingElement: React.ReactNode;\n trailingElement: React.ReactNode;\n notificationType: NotificationType;\n id: string;\n};\n\nexport type ChartTooltipContentProps = {\n leadingElement?: React.ReactNode;\n trailingElement?: React.ReactNode;\n indentSquareColor?: string;\n notifications?: Notification[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\n/**\n * Legend\n */\nexport interface LegendItemProps {\n name: string;\n children: React.ReactNode;\n as?: 'button' | 'div';\n className?: string;\n color?: string;\n isSelected?: boolean;\n isDeselected?: boolean;\n onLegendItemClick?: () => void;\n hasButtons?: boolean;\n onLegendItemMouseEnter?: () => void;\n onLegendItemMouseLeave?: () => void;\n ref?: React.Ref<HTMLButtonElement> & React.Ref<HTMLDivElement>;\n}\n\nexport type LegendProps = {\n series: {\n name: string;\n color: string;\n }[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\nexport type HtmlAttributes<T extends React.ElementType> =\n React.ComponentPropsWithoutRef<T> & {\n [key: `data-${string}`]: string | undefined;\n };\n\ntype BaseProps<T extends React.ElementType> = {\n /**\n * Additional classnames will be applied to the root element.\n */\n className?: string;\n /**\n * Additional css styling. Will be applied to the root element.\n */\n style?: React.CSSProperties;\n\n /**\n * Html attributes to apply to the root element. This will override any default html attributes, use with caution.\n */\n htmlAttributes?: HtmlAttributes<T>;\n\n /**\n * A ref to apply to the root element.\n */\n ref?: React.ComponentPropsWithRef<T>['ref'];\n};\n\nexport type CommonProps<T extends React.ElementType, P> = P & BaseProps<T>;\n"]}
@@ -41,7 +41,7 @@ export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
41
41
  ? undefined
42
42
  : getInstanceByDom(chartEchartRef.current);
43
43
  const handleDataZoom = () => {
44
- var _a;
44
+ var _a, _b;
45
45
  if (chartEchartRef.current === null) {
46
46
  return;
47
47
  }
@@ -49,15 +49,28 @@ export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
49
49
  if (!currentChart) {
50
50
  return;
51
51
  }
52
- const option = currentChart.getOption();
53
- if (!option || !option.dataZoom) {
52
+ const chartOption = currentChart.getOption();
53
+ const echartsDataZoom = ((_a = chartOption.dataZoom) !== null && _a !== void 0 ? _a : []);
54
+ const dataZoom = echartsDataZoom
55
+ .filter((entry) => entry !== null)
56
+ // map to trim unnecessary values, just keeping the relevant fields
57
+ .map(({ end, endValue, id, start, startValue, xAxisIndex, yAxisIndex, }) => ({
58
+ endPercent: end,
59
+ endValue,
60
+ id,
61
+ startPercent: start,
62
+ startValue,
63
+ xAxisIndex,
64
+ yAxisIndex,
65
+ }));
66
+ if (dataZoom.length === 0) {
54
67
  return;
55
68
  }
56
- const dataZoom = Array.isArray(option.dataZoom)
57
- ? option.dataZoom[0]
58
- : option.dataZoom;
59
- const { startValue, endValue } = dataZoom;
60
- (_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _a === void 0 ? void 0 : _a.call(callbacks, { endValue, startValue });
69
+ (_b = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _b === void 0 ? void 0 : _b.call(callbacks, {
70
+ dataZoom,
71
+ endValue: dataZoom[0].endValue,
72
+ startValue: dataZoom[0].startValue,
73
+ });
61
74
  };
62
75
  if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
63
76
  chart === null || chart === void 0 ? void 0 : chart.on('datazoom', handleDataZoom);
@@ -72,7 +85,6 @@ export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
72
85
  chartChild === null || chartChild === void 0 ? void 0 : chartChild.addEventListener('mousemove', handleMouseMove);
73
86
  }
74
87
  const handleMouseDown = (params) => {
75
- var _a;
76
88
  const event = params.event;
77
89
  const amountOfMouseClicks = event.detail;
78
90
  const isDoubleClick = amountOfMouseClicks === 2;
@@ -85,9 +97,6 @@ export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
85
97
  start: 0,
86
98
  type: 'dataZoom',
87
99
  });
88
- if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
89
- (_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _a === void 0 ? void 0 : _a.call(callbacks, { endValue: 100, startValue: 0 });
90
- }
91
100
  }
92
101
  };
93
102
  if (!isChartZoomDisabled) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-chart-zoom.js","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOvD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,mBAAmB,GACA;IACnB,MAAM,EAAE,cAAc,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAEjD,SAAS,CAAC,GAAG,EAAE;;QACb,MAAM,KAAK,GACT,cAAc,CAAC,OAAO,KAAK,IAAI;YAC7B,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,gBAAgB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE/C,MAAM,cAAc,GAAG,GAAG,EAAE;;YAC1B,IAAI,cAAc,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBACpC,OAAO;YACT,CAAC;YAED,MAAM,YAAY,GAAG,gBAAgB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAC9D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAChC,OAAO;YACT,CAAC;YAED,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAC7C,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACpB,CAAC,CAAC,MAAM,CAA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AAE,gBAAgB;gBACrB,IAAI,EAAE,kBAAkB;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 } from '../utils/chart-types';\nimport { useChartRefsContext } from './use-chart-refs';\n\ntype UseChartZoomParams = {\n callbacks: ChartProps['callbacks'];\n isChartZoomDisabled: boolean;\n};\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 option = currentChart.getOption();\n if (!option || !option.dataZoom) {\n return;\n }\n\n const dataZoom = Array.isArray(option.dataZoom)\n ? option.dataZoom[0]\n : option.dataZoom;\n const { startValue, endValue } = dataZoom as {\n startValue: number;\n endValue: number;\n };\n\n callbacks?.onZoom?.({ endValue, startValue });\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 if (callbacks?.onZoom) {\n callbacks?.onZoom?.({ endValue: 100, startValue: 0 });\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","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;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sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { 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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/charts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,2IAA2I;AAC3I,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,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\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 ThresholdLineSeriesOption,\n type Values,\n type SeriesOption,\n type EchartsSeries,\n type NeedleSeries,\n} from './utils/chart-types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/charts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,2IAA2I;AAC3I,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,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\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"]}
@@ -30,12 +30,31 @@ const zoomHarnessDataset = [
30
30
  Number((40 + Math.sin(index / 6) * 12).toFixed(2)),
31
31
  ]),
32
32
  ];
33
+ const defaultOption = {
34
+ dataZoom: [
35
+ {
36
+ filterMode: 'none',
37
+ type: 'inside',
38
+ zoomOnMouseWheel: false,
39
+ },
40
+ ],
41
+ toolbox: {
42
+ feature: {
43
+ dataZoom: {
44
+ yAxisIndex: false,
45
+ },
46
+ },
47
+ },
48
+ };
33
49
  /**
34
50
  * Reproduces the consumer setup from the metrics UI: a chart with toolbox
35
51
  * brush-zoom whose parent re-renders while the chart stays mounted, passing a
36
52
  * freshly built `option` object on every render.
53
+ *
54
+ * `option` and `seriesType` swap in other zoom setups, such as a scatter
55
+ * chart with one slider per axis.
37
56
  */
38
- export const ChartZoomHarness = ({ settings, }) => {
57
+ export const ChartZoomHarness = ({ option = defaultOption, seriesType = 'line', settings, }) => {
39
58
  const containerRef = useRef(null);
40
59
  const zoomCallsRef = useRef([]);
41
60
  const [, setRerenderCount] = useState(0);
@@ -55,7 +74,7 @@ export const ChartZoomHarness = ({ settings, }) => {
55
74
  var _a, _b;
56
75
  const dataZoom = (_b = (_a = getChart()) === null || _a === void 0 ? void 0 : _a.getOption()) === null || _b === void 0 ? void 0 : _b.dataZoom;
57
76
  return (dataZoom !== null && dataZoom !== void 0 ? dataZoom : [])
58
- .filter((item) => item.startValue !== undefined && item.endValue !== undefined)
77
+ .filter((item) => (item === null || item === void 0 ? void 0 : item.startValue) !== undefined && item.endValue !== undefined)
59
78
  .map((item) => ({
60
79
  endValue: item.endValue,
61
80
  startValue: item.startValue,
@@ -66,6 +85,15 @@ export const ChartZoomHarness = ({ settings, }) => {
66
85
  resetZoomCalls: () => {
67
86
  zoomCallsRef.current = [];
68
87
  },
88
+ zoomTo: (dataZoomId, start, end) => {
89
+ var _a;
90
+ (_a = getChart()) === null || _a === void 0 ? void 0 : _a.dispatchAction({
91
+ dataZoomId,
92
+ end,
93
+ start,
94
+ type: 'dataZoom',
95
+ });
96
+ },
69
97
  };
70
98
  }, []);
71
99
  return (_jsxs("div", { ref: containerRef, style: { height: '420px', width: '900px' }, children: [_jsx("button", { type: "button", "data-testid": "force-rerender", onClick: () => setRerenderCount((count) => count + 1), children: "Re-render" }), _jsx("div", { className: "ndl-chart", style: { height: '380px', width: '100%' }, children: _jsx(Chart, { callbacks: { onZoom: handleZoom }, dataset: [{ source: zoomHarnessDataset }], series: [
@@ -74,23 +102,8 @@ export const ChartZoomHarness = ({ settings, }) => {
74
102
  // oxlint-disable-next-line id-length
75
103
  encode: { x: 'time', y: 'value' },
76
104
  name: 'Value',
77
- type: 'line',
78
- },
79
- ], settings: settings, xAxis: { type: 'value' }, yAxis: { type: 'value' }, option: {
80
- dataZoom: [
81
- {
82
- filterMode: 'none',
83
- type: 'inside',
84
- zoomOnMouseWheel: false,
85
- },
86
- ],
87
- toolbox: {
88
- feature: {
89
- dataZoom: {
90
- yAxisIndex: false,
91
- },
92
- },
105
+ type: seriesType,
93
106
  },
94
- } }) })] }));
107
+ ], settings: settings, xAxis: { type: 'value' }, yAxis: { type: 'value' }, option: structuredClone(option) }) })] }));
95
108
  };
96
109
  //# sourceMappingURL=ChartZoomHarness.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChartZoomHarness.js","sourceRoot":"","sources":["../../../../src/charts/tests/ChartZoomHarness.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAEL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAkBf,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,kBAAkB,GAAG;IACzB,CAAC,MAAM,EAAE,OAAO,CAAC;IACjB,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,KAAK;QACL,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACnD,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,QAAQ,GAGT,EAAE,EAAE;IACH,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,MAAM,CAAa,EAAE,CAAC,CAAC;IAC5C,MAAM,CAAC,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEzC,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,IAAc,EAAE,EAA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j 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 { Chart } from '@neo4j-ndl/react-charts';\nimport { getInstanceByDom } from 'echarts';\nimport {\n type ComponentProps,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\ntype ChartSettings = ComponentProps<typeof Chart>['settings'];\n\nexport type ZoomCall = { endValue: number; startValue: number };\n\nexport type ZoomHarnessApi = {\n /** Applied zoom windows, in data values, as ECharts currently has them. */\n getAppliedZoomWindows: () => ZoomCall[];\n /** Every `callbacks.onZoom` invocation the consumer received. */\n getZoomCalls: () => ZoomCall[];\n /** Data value at a pixel offset inside the chart element. */\n pixelToValue: (pixelX: number) => number;\n resetZoomCalls: () => void;\n};\n\ntype HarnessWindow = Window & { chartZoomHarness?: ZoomHarnessApi };\n\nconst POINT_COUNT = 180;\n\nconst zoomHarnessDataset = [\n ['time', 'value'],\n ...Array.from({ length: POINT_COUNT }, (_unused, index) => [\n index,\n Number((40 + Math.sin(index / 6) * 12).toFixed(2)),\n ]),\n];\n\n/**\n * Reproduces the consumer setup from the metrics UI: a chart with toolbox\n * brush-zoom whose parent re-renders while the chart stays mounted, passing a\n * freshly built `option` object on every render.\n */\nexport const ChartZoomHarness = ({\n settings,\n}: {\n settings?: ChartSettings;\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const zoomCallsRef = useRef<ZoomCall[]>([]);\n const [, setRerenderCount] = useState(0);\n\n const handleZoom = useCallback((zoom: ZoomCall) => {\n zoomCallsRef.current = [...zoomCallsRef.current, zoom];\n }, []);\n\n useEffect(() => {\n const getChart = () => {\n const echartElement =\n containerRef.current?.querySelector('.ndl-chart-echart');\n return echartElement instanceof HTMLElement\n ? getInstanceByDom(echartElement)\n : undefined;\n };\n\n (window as HarnessWindow).chartZoomHarness = {\n getAppliedZoomWindows: () => {\n const dataZoom = (\n getChart()?.getOption() as\n | { dataZoom?: { endValue?: number; startValue?: number }[] }\n | undefined\n )?.dataZoom;\n\n return (dataZoom ?? [])\n .filter(\n (item) =>\n item.startValue !== undefined && item.endValue !== undefined,\n )\n .map((item) => ({\n endValue: item.endValue as number,\n startValue: item.startValue as number,\n }));\n },\n getZoomCalls: () => zoomCallsRef.current,\n pixelToValue: (pixelX: number) =>\n getChart()?.convertFromPixel({ xAxisIndex: 0 }, pixelX) as number,\n resetZoomCalls: () => {\n zoomCallsRef.current = [];\n },\n };\n }, []);\n\n return (\n <div ref={containerRef} style={{ height: '420px', width: '900px' }}>\n <button\n type=\"button\"\n data-testid=\"force-rerender\"\n onClick={() => setRerenderCount((count) => count + 1)}\n >\n Re-render\n </button>\n <div className=\"ndl-chart\" style={{ height: '380px', width: '100%' }}>\n <Chart\n callbacks={{ onZoom: handleZoom }}\n dataset={[{ source: zoomHarnessDataset }]}\n series={[\n {\n // E-Charts uses encode.x and encode.y - https://echarts.apache.org/en/option.html#series-line.encode\n // oxlint-disable-next-line id-length\n encode: { x: 'time', y: 'value' },\n name: 'Value',\n type: 'line',\n },\n ]}\n settings={settings}\n xAxis={{ type: 'value' }}\n yAxis={{ type: 'value' }}\n option={{\n dataZoom: [\n {\n filterMode: 'none',\n type: 'inside',\n zoomOnMouseWheel: false,\n },\n ],\n toolbox: {\n feature: {\n dataZoom: {\n yAxisIndex: false,\n },\n },\n },\n }}\n />\n </div>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"ChartZoomHarness.js","sourceRoot":"","sources":["../../../../src/charts/tests/ChartZoomHarness.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CA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EAAE;;gBACzD,MAAA,QAAQ,EAAE,0CAAE,cAAc,CAAC;oBACzB,UAAU;oBACV,GAAG;oBACH,KAAK;oBACL,IAAI,EAAE,UAAU;iBACjB,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,eAAK,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,aAChE,iBACE,IAAI,EAAC,QAAQ,iBACD,gBAAgB,EAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,0BAG9C,EACT,cAAK,SAAS,EAAC,WAAW,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAClE,KAAC,KAAK,IACJ,SAAS,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EACjC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,EACzC,MAAM,EAAE;wBACN;4BACE,qGAAqG;4BACrG,qCAAqC;4BACrC,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE;4BACjC,IAAI,EAAE,OAAO;4BACb,IAAI,EAAE,UAAU;yBACjB;qBACF,EACD,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACxB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACxB,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAC/B,GACE,IACF,CACP,CAAC;AACJ,CAAC,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 { Chart } from '@neo4j-ndl/react-charts';\nimport { getInstanceByDom } from 'echarts';\nimport {\n type ComponentProps,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport type { ChartZoomEntry } from '../utils/chart-types';\n\ntype ChartComponentProps = ComponentProps<typeof Chart>;\ntype ChartSettings = ChartComponentProps['settings'];\nexport type ChartOption = ChartComponentProps['option'];\n\nexport type ZoomCall = {\n dataZoom: ChartZoomEntry[];\n endValue: number;\n startValue: number;\n};\n\nexport type ZoomWindow = { endValue: number; startValue: number };\n\nexport type ZoomHarnessApi = {\n /** Applied zoom windows, in data values, as ECharts currently has them. */\n getAppliedZoomWindows: () => ZoomWindow[];\n /** Every `callbacks.onZoom` invocation the consumer received. */\n getZoomCalls: () => ZoomCall[];\n /** Data value at a pixel offset inside the chart element. */\n pixelToValue: (pixelX: number) => number;\n resetZoomCalls: () => void;\n /** Applies a zoom window, in percent, to one `dataZoom` entry by its `id`. */\n zoomTo: (dataZoomId: string, start: number, end: number) => void;\n};\n\ntype HarnessWindow = Window & { chartZoomHarness?: ZoomHarnessApi };\n\nconst POINT_COUNT = 180;\n\nconst zoomHarnessDataset = [\n ['time', 'value'],\n ...Array.from({ length: POINT_COUNT }, (_unused, index) => [\n index,\n Number((40 + Math.sin(index / 6) * 12).toFixed(2)),\n ]),\n];\n\nconst defaultOption: ChartOption = {\n dataZoom: [\n {\n filterMode: 'none',\n type: 'inside',\n zoomOnMouseWheel: false,\n },\n ],\n toolbox: {\n feature: {\n dataZoom: {\n yAxisIndex: false,\n },\n },\n },\n};\n\n/**\n * Reproduces the consumer setup from the metrics UI: a chart with toolbox\n * brush-zoom whose parent re-renders while the chart stays mounted, passing a\n * freshly built `option` object on every render.\n *\n * `option` and `seriesType` swap in other zoom setups, such as a scatter\n * chart with one slider per axis.\n */\nexport const ChartZoomHarness = ({\n option = defaultOption,\n seriesType = 'line',\n settings,\n}: {\n option?: ChartOption;\n seriesType?: 'line' | 'scatter';\n settings?: ChartSettings;\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const zoomCallsRef = useRef<ZoomCall[]>([]);\n const [, setRerenderCount] = useState(0);\n\n const handleZoom = useCallback((zoom: ZoomCall) => {\n zoomCallsRef.current = [...zoomCallsRef.current, zoom];\n }, []);\n\n useEffect(() => {\n const getChart = () => {\n const echartElement =\n containerRef.current?.querySelector('.ndl-chart-echart');\n return echartElement instanceof HTMLElement\n ? getInstanceByDom(echartElement)\n : undefined;\n };\n\n (window as HarnessWindow).chartZoomHarness = {\n getAppliedZoomWindows: () => {\n const dataZoom = (\n getChart()?.getOption() as\n | {\n dataZoom?: ({\n endValue?: number;\n startValue?: number;\n } | null)[];\n }\n | undefined\n )?.dataZoom;\n\n return (dataZoom ?? [])\n .filter(\n (item): item is ZoomWindow =>\n item?.startValue !== undefined && item.endValue !== undefined,\n )\n .map((item) => ({\n endValue: item.endValue as number,\n startValue: item.startValue as number,\n }));\n },\n getZoomCalls: () => zoomCallsRef.current,\n pixelToValue: (pixelX: number) =>\n getChart()?.convertFromPixel({ xAxisIndex: 0 }, pixelX) as number,\n resetZoomCalls: () => {\n zoomCallsRef.current = [];\n },\n zoomTo: (dataZoomId: string, start: number, end: number) => {\n getChart()?.dispatchAction({\n dataZoomId,\n end,\n start,\n type: 'dataZoom',\n });\n },\n };\n }, []);\n\n return (\n <div ref={containerRef} style={{ height: '420px', width: '900px' }}>\n <button\n type=\"button\"\n data-testid=\"force-rerender\"\n onClick={() => setRerenderCount((count) => count + 1)}\n >\n Re-render\n </button>\n <div className=\"ndl-chart\" style={{ height: '380px', width: '100%' }}>\n <Chart\n callbacks={{ onZoom: handleZoom }}\n dataset={[{ source: zoomHarnessDataset }]}\n series={[\n {\n // E-Charts uses encode.x and encode.y - https://echarts.apache.org/en/option.html#series-line.encode\n // oxlint-disable-next-line id-length\n encode: { x: 'time', y: 'value' },\n name: 'Value',\n type: seriesType,\n },\n ]}\n settings={settings}\n xAxis={{ type: 'value' }}\n yAxis={{ type: 'value' }}\n option={structuredClone(option)}\n />\n </div>\n </div>\n );\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"chart-types.js","sourceRoot":"","sources":["../../../../src/charts/utils/chart-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG","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 type EChartsOption,\n type LineSeriesOption,\n type RegisteredSeriesOption,\n type SetOptionOpts,\n} from 'echarts';\n\nexport type HexColor = `#${string}`;\n\nexport type Condition =\n | 'greater'\n | 'greaterOrEqual'\n | 'less'\n | 'lessOrEqual'\n | 'equal'\n | 'notEqual';\n\nexport type Values<T> = T[keyof T];\nexport type SeriesOption = Values<RegisteredSeriesOption>;\n\nexport type EchartsSeries = SeriesOption | SeriesOption[];\n\ntype CustomCondition = (\n lineValue: unknown,\n thresholdLineValue: unknown,\n) => boolean;\n\nexport interface ThresholdLineSeriesOption<\n T extends NotificationType,\n> extends Omit<LineSeriesOption, 'type'> {\n type: 'thresholdLine';\n yAxis: number;\n xAxis: [number, number];\n notificationType: T;\n color?: string;\n condition?: Condition;\n customConditionText?: string;\n customCondition?: CustomCondition;\n}\n\n// Only one threshold line of each type is allowed.\nexport type NeedleSeries =\n | [\n ThresholdLineSeriesOption<'warning'>,\n ThresholdLineSeriesOption<'danger'>,\n ...SeriesOption[],\n ]\n | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]]\n | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]]\n | SeriesOption[];\n\nexport interface ChartProps {\n /** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */\n dataset: EChartsOption['dataset'];\n /** The series configuration for the chart. Defines what data to display and how to display it. */\n series: NeedleSeries;\n /** X-axis configuration for the chart. */\n xAxis?: EChartsOption['xAxis'];\n /** Y-axis configuration for the chart. */\n yAxis?: EChartsOption['yAxis'];\n /** Legend configuration for the chart. */\n legend?: {\n /** Whether the legend is visible. */\n isVisible?: boolean;\n };\n /** Additional ECharts options to merge with the chart configuration. */\n option?: Omit<\n EChartsOption,\n 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'\n >;\n /** Custom CSS styles to apply to the chart container. */\n style?: React.CSSProperties;\n /**\n * Settings for how ECharts should update the chart. Defaults to replacing the\n * components the chart owns (`series`, `dataset`, axes, and similar) while\n * merging the rest, which drops data that disappeared without discarding the\n * ECharts components behind zoom interactions. Passing `notMerge: true`\n * re-creates those components on every update and breaks drag-to-zoom.\n */\n settings?: SetOptionOpts;\n /** Whether the chart is in a loading state. */\n isLoading?: boolean;\n /** Callback functions for chart interactions. */\n callbacks?: {\n onZoom?: (params: { startValue: number; endValue: number }) => void;\n };\n /** Data zoom configuration for the chart. */\n dataZoom?: EChartsOption['dataZoom'];\n /** Whether the zoom in the chart is disabled */\n isChartZoomDisabled?: boolean;\n /** Custom color palette that overrides the default categorical colors. */\n palette?: HexColor[];\n}\n\nexport interface ChartEmptyProps {\n /** A text displayed to the user when the chart is empty. */\n message?: React.ReactNode;\n /** The type of chart. This is used to render the appropriate icon. */\n type?: 'line' | 'pie' | 'bar';\n /** Optional element (preferably a TextButton) that should provide the user with an action. */\n action?: React.ReactNode;\n}\n\n/**\n * Chart tooltip\n */\n\n/**\n * Client coordinates used to anchor a floating element at a fixed point (e.g.\n * the cursor position), instead of at an anchor element.\n */\ntype AnchorPosition = {\n // oxlint-disable-next-line id-length\n x: number;\n // oxlint-disable-next-line id-length\n y: number;\n};\n\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: AnchorPosition;\n ref?: React.Ref<HTMLDivElement>;\n}\n\nexport type NotificationType = 'warning' | 'danger';\n\nexport type Notification = {\n leadingElement: React.ReactNode;\n trailingElement: React.ReactNode;\n notificationType: NotificationType;\n id: string;\n};\n\nexport type ChartTooltipContentProps = {\n leadingElement?: React.ReactNode;\n trailingElement?: React.ReactNode;\n indentSquareColor?: string;\n notifications?: Notification[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\n/**\n * Legend\n */\nexport interface LegendItemProps {\n name: string;\n children: React.ReactNode;\n as?: 'button' | 'div';\n className?: string;\n color?: string;\n isSelected?: boolean;\n isDeselected?: boolean;\n onLegendItemClick?: () => void;\n hasButtons?: boolean;\n onLegendItemMouseEnter?: () => void;\n onLegendItemMouseLeave?: () => void;\n ref?: React.Ref<HTMLButtonElement> & React.Ref<HTMLDivElement>;\n}\n\nexport type LegendProps = {\n series: {\n name: string;\n color: string;\n }[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\nexport type HtmlAttributes<T extends React.ElementType> =\n React.ComponentPropsWithoutRef<T> & {\n [key: `data-${string}`]: string | undefined;\n };\n\ntype BaseProps<T extends React.ElementType> = {\n /**\n * Additional classnames will be applied to the root element.\n */\n className?: string;\n /**\n * Additional css styling. Will be applied to the root element.\n */\n style?: React.CSSProperties;\n\n /**\n * Html attributes to apply to the root element. This will override any default html attributes, use with caution.\n */\n htmlAttributes?: HtmlAttributes<T>;\n\n /**\n * A ref to apply to the root element.\n */\n ref?: React.ComponentPropsWithRef<T>['ref'];\n};\n\nexport type CommonProps<T extends React.ElementType, P> = P & BaseProps<T>;\n"]}
1
+ {"version":3,"file":"chart-types.js","sourceRoot":"","sources":["../../../../src/charts/utils/chart-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG","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 type EChartsOption,\n type LineSeriesOption,\n type RegisteredSeriesOption,\n type SetOptionOpts,\n} from 'echarts';\n\nexport type HexColor = `#${string}`;\n\nexport type Condition =\n | 'greater'\n | 'greaterOrEqual'\n | 'less'\n | 'lessOrEqual'\n | 'equal'\n | 'notEqual';\n\nexport type Values<T> = T[keyof T];\nexport type SeriesOption = Values<RegisteredSeriesOption>;\n\nexport type EchartsSeries = SeriesOption | SeriesOption[];\n\ntype CustomCondition = (\n lineValue: unknown,\n thresholdLineValue: unknown,\n) => boolean;\n\nexport interface ThresholdLineSeriesOption<\n T extends NotificationType,\n> extends Omit<LineSeriesOption, 'type'> {\n type: 'thresholdLine';\n yAxis: number;\n xAxis: [number, number];\n notificationType: T;\n color?: string;\n condition?: Condition;\n customConditionText?: string;\n customCondition?: CustomCondition;\n}\n\n// Only one threshold line of each type is allowed.\nexport type NeedleSeries =\n | [\n ThresholdLineSeriesOption<'warning'>,\n ThresholdLineSeriesOption<'danger'>,\n ...SeriesOption[],\n ]\n | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]]\n | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]]\n | SeriesOption[];\n\n/** The zoom window of one configured `dataZoom` component, as reported by `onZoom`. */\nexport type ChartZoomEntry = {\n id?: string | number;\n xAxisIndex?: number | number[] | false;\n yAxisIndex?: number | number[] | false;\n /** Percent, 0–100. */\n startPercent: number;\n /** Percent, 0–100. */\n endPercent: number;\n /** Data value; the category index on a category axis. */\n startValue?: number;\n /** Data value; the category index on a category axis. */\n endValue?: number;\n};\n\nexport interface ChartProps {\n /** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */\n dataset: EChartsOption['dataset'];\n /** The series configuration for the chart. Defines what data to display and how to display it. */\n series: NeedleSeries;\n /** X-axis configuration for the chart. */\n xAxis?: EChartsOption['xAxis'];\n /** Y-axis configuration for the chart. */\n yAxis?: EChartsOption['yAxis'];\n /** Legend configuration for the chart. */\n legend?: {\n /** Whether the legend is visible. */\n isVisible?: boolean;\n };\n /** Additional ECharts options to merge with the chart configuration. */\n option?: Omit<\n EChartsOption,\n 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'\n >;\n /** Custom CSS styles to apply to the chart container. */\n style?: React.CSSProperties;\n /**\n * Settings for how ECharts should update the chart. Defaults to replacing the\n * components the chart owns (`series`, `dataset`, axes, and similar) while\n * merging the rest, which drops data that disappeared without discarding the\n * ECharts components behind zoom interactions. Passing `notMerge: true`\n * re-creates those components on every update and breaks drag-to-zoom.\n */\n settings?: SetOptionOpts;\n /** Whether the chart is in a loading state. */\n isLoading?: boolean;\n /** Callback functions for chart interactions. */\n callbacks?: {\n /**\n * Called after every zoom change: slider or inside drag, drag-to-zoom and\n * the double-click reset. Only fires when `dataZoom` is configured; to\n * track drag-to-zoom on its own, add `dataZoom: [{ type: 'inside' }]`.\n *\n * `dataZoom` holds one entry per `dataZoom` component you configured, in\n * config order, so the values can be passed back as\n * `startValue`/`endValue` to restore the zoom. `id` and the axis indices\n * are copied from the config, so they are `undefined` when not set there.\n */\n onZoom?: (params: {\n // TODO v6: remove startValue and endValue\n /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].startValue` instead. */\n startValue: number;\n /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].endValue` instead. */\n endValue: number;\n dataZoom: ChartZoomEntry[];\n }) => void;\n };\n /** Data zoom configuration for the chart. */\n dataZoom?: EChartsOption['dataZoom'];\n /** Whether the zoom in the chart is disabled */\n isChartZoomDisabled?: boolean;\n /** Custom color palette that overrides the default categorical colors. */\n palette?: HexColor[];\n}\n\nexport interface ChartEmptyProps {\n /** A text displayed to the user when the chart is empty. */\n message?: React.ReactNode;\n /** The type of chart. This is used to render the appropriate icon. */\n type?: 'line' | 'pie' | 'bar';\n /** Optional element (preferably a TextButton) that should provide the user with an action. */\n action?: React.ReactNode;\n}\n\n/**\n * Chart tooltip\n */\n\n/**\n * Client coordinates used to anchor a floating element at a fixed point (e.g.\n * the cursor position), instead of at an anchor element.\n */\ntype AnchorPosition = {\n // oxlint-disable-next-line id-length\n x: number;\n // oxlint-disable-next-line id-length\n y: number;\n};\n\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: AnchorPosition;\n ref?: React.Ref<HTMLDivElement>;\n}\n\nexport type NotificationType = 'warning' | 'danger';\n\nexport type Notification = {\n leadingElement: React.ReactNode;\n trailingElement: React.ReactNode;\n notificationType: NotificationType;\n id: string;\n};\n\nexport type ChartTooltipContentProps = {\n leadingElement?: React.ReactNode;\n trailingElement?: React.ReactNode;\n indentSquareColor?: string;\n notifications?: Notification[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\n/**\n * Legend\n */\nexport interface LegendItemProps {\n name: string;\n children: React.ReactNode;\n as?: 'button' | 'div';\n className?: string;\n color?: string;\n isSelected?: boolean;\n isDeselected?: boolean;\n onLegendItemClick?: () => void;\n hasButtons?: boolean;\n onLegendItemMouseEnter?: () => void;\n onLegendItemMouseLeave?: () => void;\n ref?: React.Ref<HTMLButtonElement> & React.Ref<HTMLDivElement>;\n}\n\nexport type LegendProps = {\n series: {\n name: string;\n color: string;\n }[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\nexport type HtmlAttributes<T extends React.ElementType> =\n React.ComponentPropsWithoutRef<T> & {\n [key: `data-${string}`]: string | undefined;\n };\n\ntype BaseProps<T extends React.ElementType> = {\n /**\n * Additional classnames will be applied to the root element.\n */\n className?: string;\n /**\n * Additional css styling. Will be applied to the root element.\n */\n style?: React.CSSProperties;\n\n /**\n * Html attributes to apply to the root element. This will override any default html attributes, use with caution.\n */\n htmlAttributes?: HtmlAttributes<T>;\n\n /**\n * A ref to apply to the root element.\n */\n ref?: React.ComponentPropsWithRef<T>['ref'];\n};\n\nexport type CommonProps<T extends React.ElementType, P> = P & BaseProps<T>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-chart-zoom.d.ts","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACnC,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,mBAAmB,GACpB,EAAE,kBAAkB,QAkGpB"}
1
+ {"version":3,"file":"use-chart-zoom.d.ts","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,sBAAsB,CAAC;AAGvE,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACnC,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AASF;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,mBAAmB,GACpB,EAAE,kBAAkB,QAmHpB"}
@@ -22,5 +22,5 @@ export * from './Chart';
22
22
  export * from './ChartEmpty';
23
23
  export { defaultThresholdLineSeriesOption } from './utils/defaults';
24
24
  export { type TooltipValueContext } from './utils/chart-tooltip-formatter';
25
- export { type ChartEmptyProps, type ThresholdLineSeriesOption, type Values, type SeriesOption, type EchartsSeries, type NeedleSeries, } from './utils/chart-types';
25
+ export { type ChartEmptyProps, type ChartZoomEntry, type ThresholdLineSeriesOption, type Values, type SeriesOption, type EchartsSeries, type NeedleSeries, } from './utils/chart-types';
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/charts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/charts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,qBAAqB,CAAC"}
@@ -20,26 +20,41 @@
20
20
  */
21
21
  import { Chart } from '@neo4j-ndl/react-charts';
22
22
  import { type ComponentProps } from 'react';
23
- type ChartSettings = ComponentProps<typeof Chart>['settings'];
23
+ import type { ChartZoomEntry } from '../utils/chart-types';
24
+ type ChartComponentProps = ComponentProps<typeof Chart>;
25
+ type ChartSettings = ChartComponentProps['settings'];
26
+ export type ChartOption = ChartComponentProps['option'];
24
27
  export type ZoomCall = {
28
+ dataZoom: ChartZoomEntry[];
29
+ endValue: number;
30
+ startValue: number;
31
+ };
32
+ export type ZoomWindow = {
25
33
  endValue: number;
26
34
  startValue: number;
27
35
  };
28
36
  export type ZoomHarnessApi = {
29
37
  /** Applied zoom windows, in data values, as ECharts currently has them. */
30
- getAppliedZoomWindows: () => ZoomCall[];
38
+ getAppliedZoomWindows: () => ZoomWindow[];
31
39
  /** Every `callbacks.onZoom` invocation the consumer received. */
32
40
  getZoomCalls: () => ZoomCall[];
33
41
  /** Data value at a pixel offset inside the chart element. */
34
42
  pixelToValue: (pixelX: number) => number;
35
43
  resetZoomCalls: () => void;
44
+ /** Applies a zoom window, in percent, to one `dataZoom` entry by its `id`. */
45
+ zoomTo: (dataZoomId: string, start: number, end: number) => void;
36
46
  };
37
47
  /**
38
48
  * Reproduces the consumer setup from the metrics UI: a chart with toolbox
39
49
  * brush-zoom whose parent re-renders while the chart stays mounted, passing a
40
50
  * freshly built `option` object on every render.
51
+ *
52
+ * `option` and `seriesType` swap in other zoom setups, such as a scatter
53
+ * chart with one slider per axis.
41
54
  */
42
- export declare const ChartZoomHarness: ({ settings, }: {
55
+ export declare const ChartZoomHarness: ({ option, seriesType, settings, }: {
56
+ option?: ChartOption;
57
+ seriesType?: "line" | "scatter";
43
58
  settings?: ChartSettings;
44
59
  }) => import("react/jsx-runtime").JSX.Element;
45
60
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"ChartZoomHarness.d.ts","sourceRoot":"","sources":["../../../../src/charts/tests/ChartZoomHarness.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EACL,KAAK,cAAc,EAKpB,MAAM,OAAO,CAAC;AAEf,KAAK,aAAa,GAAG,cAAc,CAAC,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,cAAc,GAAG;IAC3B,2EAA2E;IAC3E,qBAAqB,EAAE,MAAM,QAAQ,EAAE,CAAC;IACxC,iEAAiE;IACjE,YAAY,EAAE,MAAM,QAAQ,EAAE,CAAC;IAC/B,6DAA6D;IAC7D,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B,CAAC;AAcF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,eAE9B;IACD,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,4CA0FA,CAAC"}
1
+ {"version":3,"file":"ChartZoomHarness.d.ts","sourceRoot":"","sources":["../../../../src/charts/tests/ChartZoomHarness.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EACL,KAAK,cAAc,EAKpB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,KAAK,mBAAmB,GAAG,cAAc,CAAC,OAAO,KAAK,CAAC,CAAC;AACxD,KAAK,aAAa,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAExD,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG;IAC3B,2EAA2E;IAC3E,qBAAqB,EAAE,MAAM,UAAU,EAAE,CAAC;IAC1C,iEAAiE;IACjE,YAAY,EAAE,MAAM,QAAQ,EAAE,CAAC;IAC/B,6DAA6D;IAC7D,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,8EAA8E;IAC9E,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAClE,CAAC;AA+BF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,mCAI9B;IACD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,4CAwFA,CAAC"}
@@ -40,6 +40,20 @@ export type NeedleSeries = [
40
40
  ThresholdLineSeriesOption<'danger'>,
41
41
  ...SeriesOption[]
42
42
  ] | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]] | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]] | SeriesOption[];
43
+ /** The zoom window of one configured `dataZoom` component, as reported by `onZoom`. */
44
+ export type ChartZoomEntry = {
45
+ id?: string | number;
46
+ xAxisIndex?: number | number[] | false;
47
+ yAxisIndex?: number | number[] | false;
48
+ /** Percent, 0–100. */
49
+ startPercent: number;
50
+ /** Percent, 0–100. */
51
+ endPercent: number;
52
+ /** Data value; the category index on a category axis. */
53
+ startValue?: number;
54
+ /** Data value; the category index on a category axis. */
55
+ endValue?: number;
56
+ };
43
57
  export interface ChartProps {
44
58
  /** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */
45
59
  dataset: EChartsOption['dataset'];
@@ -70,9 +84,22 @@ export interface ChartProps {
70
84
  isLoading?: boolean;
71
85
  /** Callback functions for chart interactions. */
72
86
  callbacks?: {
87
+ /**
88
+ * Called after every zoom change: slider or inside drag, drag-to-zoom and
89
+ * the double-click reset. Only fires when `dataZoom` is configured; to
90
+ * track drag-to-zoom on its own, add `dataZoom: [{ type: 'inside' }]`.
91
+ *
92
+ * `dataZoom` holds one entry per `dataZoom` component you configured, in
93
+ * config order, so the values can be passed back as
94
+ * `startValue`/`endValue` to restore the zoom. `id` and the axis indices
95
+ * are copied from the config, so they are `undefined` when not set there.
96
+ */
73
97
  onZoom?: (params: {
98
+ /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].startValue` instead. */
74
99
  startValue: number;
100
+ /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].endValue` instead. */
75
101
  endValue: number;
102
+ dataZoom: ChartZoomEntry[];
76
103
  }) => void;
77
104
  };
78
105
  /** Data zoom configuration for the chart. */
@@ -1 +1 @@
1
- {"version":3,"file":"chart-types.d.ts","sourceRoot":"","sources":["../../../../src/charts/utils/chart-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;AAEpC,MAAM,MAAM,SAA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CAAC;CAC7C,CAAC;AAEJ,KAAK,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,IAAI;IAC5C;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAEnC;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-ndl/react-charts",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "sideEffects": false,
5
5
  "description": "React implementation of charts from Neo4j Design System",
6
6
  "keywords": [
@@ -57,7 +57,7 @@
57
57
  "peerDependencies": {
58
58
  "react": ">=19.0.0",
59
59
  "react-dom": ">=19.0.0",
60
- "@neo4j-ndl/react": "^5.1.0",
60
+ "@neo4j-ndl/react": "^5.1.1",
61
61
  "@neo4j-ndl/base": "^5.1.0"
62
62
  },
63
63
  "dependencies": {
@@ -2,7 +2,7 @@
2
2
  name: ndl-react-charts
3
3
  metadata:
4
4
  package: '@neo4j-ndl/react-charts'
5
- version: '2.1.0'
5
+ version: '2.1.2'
6
6
  description: >-
7
7
  Build data visualizations with the Neo4j Needle React Charts library
8
8
  (@neo4j-ndl/react-charts), an Apache ECharts-based charting layer. Use when
@@ -15,7 +15,7 @@ description: >-
15
15
 
16
16
  # Neo4j Needle React Charts (@neo4j-ndl/react-charts)
17
17
 
18
- > 📌 Shipped with `@neo4j-ndl/react-charts` v2.1.0. Once installed into your repo (e.g. via
18
+ > 📌 Shipped with `@neo4j-ndl/react-charts` v2.1.2. Once installed into your repo (e.g. via
19
19
  > `npx skills add`) this folder is detached from the package — the installed
20
20
  > package (TypeScript types in `node_modules/@neo4j-ndl/react-charts`) is the source of
21
21
  > truth.
@@ -10,7 +10,7 @@ Import: `import { Chart } from '@neo4j-ndl/react-charts'`
10
10
 
11
11
  | Prop | Type | Required | Default | Description |
12
12
  |------|------|----------|---------|-------------|
13
- | `callbacks` | `{ onZoom?: ((params: { startValue: number; endValue: number; }) => void); }` | | | Callback functions for chart interactions. |
13
+ | `callbacks` | `{ onZoom?: ((params: { startValue: number; endValue: number; dataZoom: ChartZoomEntry[]; }) => void); }` | | | Callback functions for chart interactions. |
14
14
  | `dataset` | `DatasetOption \| DatasetOption[] \| undefined` | ✅ | | The dataset configuration for the chart. Can be a single dataset or an array of datasets. |
15
15
  | `dataZoom` | `DataZoomComponentOption \| DataZoomComponentOption[]` | | | Data zoom configuration for the chart. |
16
16
  | `isChartZoomDisabled` | `boolean` | | | Whether the zoom in the chart is disabled |