@neo4j-ndl/react-charts 1.1.20 → 1.1.22
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.
- package/lib/cjs/charts/ChartRender.js +2 -6
- package/lib/cjs/charts/ChartRender.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-zoom.js +25 -19
- package/lib/cjs/charts/hooks/use-chart-zoom.js.map +1 -1
- package/lib/cjs/charts/tests/ChartZoomHarness.js +98 -0
- package/lib/cjs/charts/tests/ChartZoomHarness.js.map +1 -0
- package/lib/cjs/charts/utils/chart-types.js.map +1 -1
- package/lib/cjs/charts/utils/defaults.js +36 -1
- package/lib/cjs/charts/utils/defaults.js.map +1 -1
- package/lib/esm/charts/ChartRender.js +2 -6
- package/lib/esm/charts/ChartRender.js.map +1 -1
- package/lib/esm/charts/hooks/use-chart-zoom.js +25 -19
- package/lib/esm/charts/hooks/use-chart-zoom.js.map +1 -1
- package/lib/esm/charts/tests/ChartZoomHarness.js +94 -0
- package/lib/esm/charts/tests/ChartZoomHarness.js.map +1 -0
- package/lib/esm/charts/utils/chart-types.js.map +1 -1
- package/lib/esm/charts/utils/defaults.js +34 -1
- package/lib/esm/charts/utils/defaults.js.map +1 -1
- package/lib/types/charts/ChartRender.d.ts.map +1 -1
- package/lib/types/charts/hooks/use-chart-zoom.d.ts +4 -0
- package/lib/types/charts/hooks/use-chart-zoom.d.ts.map +1 -1
- package/lib/types/charts/tests/ChartZoomHarness.d.ts +46 -0
- package/lib/types/charts/tests/ChartZoomHarness.d.ts.map +1 -0
- package/lib/types/charts/utils/chart-types.d.ts +7 -1
- package/lib/types/charts/utils/chart-types.d.ts.map +1 -1
- package/lib/types/charts/utils/defaults.d.ts +21 -2
- package/lib/types/charts/utils/defaults.d.ts.map +1 -1
- package/package.json +3 -3
- package/skills/ndl-react-charts/components/charts.md +1 -1
|
@@ -29,13 +29,9 @@ const use_chart_option_1 = require("./hooks/use-chart-option");
|
|
|
29
29
|
const use_chart_refs_1 = require("./hooks/use-chart-refs");
|
|
30
30
|
const use_chart_zoom_1 = require("./hooks/use-chart-zoom");
|
|
31
31
|
const build_chart_option_1 = require("./utils/build-chart-option");
|
|
32
|
+
const defaults_1 = require("./utils/defaults");
|
|
32
33
|
const threshold_1 = require("./utils/threshold");
|
|
33
34
|
const user_option_utils_1 = require("./utils/user-option-utils");
|
|
34
|
-
const DEFAULT_CHART_SETTINGS = {
|
|
35
|
-
lazyUpdate: false,
|
|
36
|
-
notMerge: true,
|
|
37
|
-
silent: false,
|
|
38
|
-
};
|
|
39
35
|
/**
|
|
40
36
|
* Owns the ECharts instance element and coordinates chart-specific hooks.
|
|
41
37
|
*
|
|
@@ -43,7 +39,7 @@ const DEFAULT_CHART_SETTINGS = {
|
|
|
43
39
|
* initializes/resizes the chart instance, applies loading and zoom behavior, and
|
|
44
40
|
* reports derived chart state back to `Chart` for legend rendering.
|
|
45
41
|
*/
|
|
46
|
-
const ChartRender = ({ callbacks, dataset, isChartZoomDisabled = false, isLoading, onChartOptionChange, onFirstResizeChange, option: userOption, palette, series: propsSeries, settings =
|
|
42
|
+
const ChartRender = ({ callbacks, dataset, isChartZoomDisabled = false, isLoading, onChartOptionChange, onFirstResizeChange, option: userOption, palette, series: propsSeries, settings = defaults_1.defaultChartSettings, xAxis: propXAxis, yAxis: propYAxis, }) => {
|
|
47
43
|
const { chartEchartRef } = (0, use_chart_refs_1.useChartRefsContext)();
|
|
48
44
|
const dataZoomOptions = userOption === null || userOption === void 0 ? void 0 : userOption.dataZoom;
|
|
49
45
|
const toolboxOptions = userOption === null || userOption === void 0 ? void 0 : userOption.toolbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartRender.js","sourceRoot":"","sources":["../../../src/charts/ChartRender.tsx"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4CAAkD;AAElD,iCAA2C;AAE3C,mEAIoC;AACpC,+DAA0D;AAC1D,2DAA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AAE,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEnD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEvC,OAAO,gCAAK,GAAG,EAAE,cAAc,EAAE,SAAS,EAAC,kBAAkB,GAAG,CAAC;AACnE,CAAC,CAAC;AA9EW,QAAA,WAAW,eA8EtB","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 { useNeedleTheme } from '@neo4j-ndl/react';\nimport type { EChartsOption } from 'echarts';\nimport { useEffect, useMemo } from 'react';\n\nimport {\n useChartLifecycle,\n useChartLoading,\n useChartResize,\n} from './hooks/use-chart-instance';\nimport { useChartOption } from './hooks/use-chart-option';\nimport { useChartRefsContext } from './hooks/use-chart-refs';\nimport { useChartZoom } from './hooks/use-chart-zoom';\nimport {\n hasCategoryXAxis as getHasCategoryXAxis,\n hasMarkAreaInSeries,\n hasSliderDataZoom,\n} from './utils/build-chart-option';\nimport type { ChartProps } from './utils/chart-types';\nimport { defaultChartSettings } from './utils/defaults';\nimport { normalizeThresholdLines } from './utils/threshold';\nimport {\n mergeDataZoom,\n mergeSeries,\n mergeXAxis,\n mergeYAxis,\n} from './utils/user-option-utils';\n\ntype ChartRenderProps = Omit<ChartProps, 'legend' | 'style'> & {\n onChartOptionChange: (chartOption: EChartsOption | undefined) => void;\n onFirstResizeChange: (isWaitingForFirstResize: boolean) => void;\n};\n\n/**\n * Owns the ECharts instance element and coordinates chart-specific hooks.\n *\n * The component normalizes user props into Needle-themed ECharts options,\n * initializes/resizes the chart instance, applies loading and zoom behavior, and\n * reports derived chart state back to `Chart` for legend rendering.\n */\nexport const ChartRender = ({\n callbacks,\n dataset,\n isChartZoomDisabled = false,\n isLoading,\n onChartOptionChange,\n onFirstResizeChange,\n option: userOption,\n palette,\n series: propsSeries,\n settings = defaultChartSettings,\n xAxis: propXAxis,\n yAxis: propYAxis,\n}: ChartRenderProps) => {\n const { chartEchartRef } = useChartRefsContext();\n const dataZoomOptions = (userOption as EChartsOption)?.dataZoom;\n const toolboxOptions = (userOption as EChartsOption)?.toolbox;\n const { theme } = useNeedleTheme();\n\n const hasSliderZoom = hasSliderDataZoom(dataZoomOptions);\n const thresholdLines = useMemo(\n () => normalizeThresholdLines(propsSeries),\n [propsSeries],\n );\n const dataZoom = useMemo(\n () => mergeDataZoom(dataZoomOptions),\n [dataZoomOptions],\n );\n const series = useMemo(\n () => mergeSeries(propsSeries, theme, userOption, palette),\n [palette, propsSeries, theme, userOption],\n );\n const xAxis = useMemo(() => mergeXAxis(propXAxis, theme), [propXAxis, theme]);\n const yAxis = useMemo(() => mergeYAxis(propYAxis, theme), [propYAxis, theme]);\n const hasCategoryXAxis = getHasCategoryXAxis(xAxis);\n const hasMarkArea = hasMarkAreaInSeries(series);\n\n /**\n * Hook responsibilities:\n * - `useChartLifecycle` creates/disposes the ECharts instance and updates theme data.\n * - `useChartResize` keeps the canvas sized to its container before first render.\n * - `useChartOption` builds and applies the merged ECharts option.\n * - `useChartZoom` attaches consumer zoom callbacks.\n * - `useChartLoading` synchronizes the loading overlay with chart readiness.\n */\n useChartLifecycle({ palette, theme });\n const { isWaitingForFirstResize } = useChartResize();\n const chartOption = useChartOption({\n dataZoom,\n dataset,\n hasCategoryXAxis,\n hasMarkArea,\n hasSliderZoom,\n propsSeries,\n series,\n settings,\n thresholdLines,\n toolboxOptions,\n userOption,\n xAxis,\n yAxis,\n });\n useChartZoom({ callbacks, isChartZoomDisabled });\n useChartLoading({\n isLoading,\n isWaitingForFirstResize,\n theme,\n });\n\n useEffect(() => {\n onFirstResizeChange(isWaitingForFirstResize);\n }, [isWaitingForFirstResize, onFirstResizeChange]);\n\n useEffect(() => {\n onChartOptionChange(chartOption);\n }, [chartOption, onChartOptionChange]);\n\n return <div ref={chartEchartRef} className=\"ndl-chart-echart\" />;\n};\n"]}
|
|
@@ -31,6 +31,10 @@ const use_chart_refs_1 = require("./use-chart-refs");
|
|
|
31
31
|
* ECharts' global cursor API, resets zoom on double click, and clears ECharts'
|
|
32
32
|
* SVG cursor override after mouse movement so Needle's default cursor styling is
|
|
33
33
|
* preserved.
|
|
34
|
+
*
|
|
35
|
+
* The effect re-runs on every render, so each listener has to be detached again
|
|
36
|
+
* on cleanup. Otherwise they pile up and consumers get one `onZoom` call per
|
|
37
|
+
* render that has happened so far.
|
|
34
38
|
*/
|
|
35
39
|
function useChartZoom({ callbacks, isChartZoomDisabled, }) {
|
|
36
40
|
const { chartEchartRef } = (0, use_chart_refs_1.useChartRefsContext)();
|
|
@@ -39,26 +43,27 @@ function useChartZoom({ callbacks, isChartZoomDisabled, }) {
|
|
|
39
43
|
const chart = chartEchartRef.current === null
|
|
40
44
|
? undefined
|
|
41
45
|
: (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
|
|
46
|
+
const handleDataZoom = () => {
|
|
47
|
+
var _a;
|
|
48
|
+
if (chartEchartRef.current === null) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const currentChart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
|
|
52
|
+
if (!currentChart) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const option = currentChart.getOption();
|
|
56
|
+
if (!option || !option.dataZoom) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
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 });
|
|
64
|
+
};
|
|
42
65
|
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
|
|
43
|
-
chart === null || chart === void 0 ? void 0 : chart.on('datazoom',
|
|
44
|
-
var _a;
|
|
45
|
-
if (chartEchartRef.current === null) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const currentChart = (0, echarts_1.getInstanceByDom)(chartEchartRef.current);
|
|
49
|
-
if (!currentChart) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const option = currentChart.getOption();
|
|
53
|
-
if (!option || !option.dataZoom) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
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 });
|
|
61
|
-
});
|
|
66
|
+
chart === null || chart === void 0 ? void 0 : chart.on('datazoom', handleDataZoom);
|
|
62
67
|
}
|
|
63
68
|
const handleMouseMove = () => {
|
|
64
69
|
// ECharts updates SVG cursor styles on mouse move, so Needle has to
|
|
@@ -97,6 +102,7 @@ function useChartZoom({ callbacks, isChartZoomDisabled, }) {
|
|
|
97
102
|
element === null || element === void 0 ? void 0 : element.removeEventListener('mousemove', handleMouseMove);
|
|
98
103
|
if (chartRefCurrentElement) {
|
|
99
104
|
const chart = (0, echarts_1.getInstanceByDom)(chartRefCurrentElement);
|
|
105
|
+
chart === null || chart === void 0 ? void 0 : chart.off('datazoom', handleDataZoom);
|
|
100
106
|
chart === null || chart === void 0 ? void 0 : chart.getZr().off('mousedown', handleMouseDown);
|
|
101
107
|
}
|
|
102
108
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-chart-zoom.js","sourceRoot":"","sources":["../../../../src/charts/hooks/use-chart-zoom.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;
|
|
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,0BAAgB,EAAC,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,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ACvD,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"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChartZoomHarness = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) "Neo4j"
|
|
8
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Neo4j.
|
|
11
|
+
*
|
|
12
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
13
|
+
* it under the terms of the GNU General Public License as published by
|
|
14
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
* (at your option) any later version.
|
|
16
|
+
*
|
|
17
|
+
* This program is distributed in the hope that it will be useful,
|
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
* GNU General Public License for more details.
|
|
21
|
+
*
|
|
22
|
+
* You should have received a copy of the GNU General Public License
|
|
23
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
+
*/
|
|
25
|
+
const react_charts_1 = require("@neo4j-ndl/react-charts");
|
|
26
|
+
const echarts_1 = require("echarts");
|
|
27
|
+
const react_1 = require("react");
|
|
28
|
+
const POINT_COUNT = 180;
|
|
29
|
+
const zoomHarnessDataset = [
|
|
30
|
+
['time', 'value'],
|
|
31
|
+
...Array.from({ length: POINT_COUNT }, (_, index) => [
|
|
32
|
+
index,
|
|
33
|
+
Number((40 + Math.sin(index / 6) * 12).toFixed(2)),
|
|
34
|
+
]),
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Reproduces the consumer setup from the metrics UI: a chart with toolbox
|
|
38
|
+
* brush-zoom whose parent re-renders while the chart stays mounted, passing a
|
|
39
|
+
* freshly built `option` object on every render.
|
|
40
|
+
*/
|
|
41
|
+
const ChartZoomHarness = ({ settings, }) => {
|
|
42
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
43
|
+
const zoomCallsRef = (0, react_1.useRef)([]);
|
|
44
|
+
const [, setRerenderCount] = (0, react_1.useState)(0);
|
|
45
|
+
const handleZoom = (0, react_1.useCallback)((zoom) => {
|
|
46
|
+
zoomCallsRef.current = [...zoomCallsRef.current, zoom];
|
|
47
|
+
}, []);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
const getChart = () => {
|
|
50
|
+
var _a;
|
|
51
|
+
const echartElement = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.ndl-chart-echart');
|
|
52
|
+
return echartElement instanceof HTMLElement
|
|
53
|
+
? (0, echarts_1.getInstanceByDom)(echartElement)
|
|
54
|
+
: undefined;
|
|
55
|
+
};
|
|
56
|
+
window.chartZoomHarness = {
|
|
57
|
+
getAppliedZoomWindows: () => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const dataZoom = (_b = (_a = getChart()) === null || _a === void 0 ? void 0 : _a.getOption()) === null || _b === void 0 ? void 0 : _b.dataZoom;
|
|
60
|
+
return (dataZoom !== null && dataZoom !== void 0 ? dataZoom : [])
|
|
61
|
+
.filter((item) => item.startValue !== undefined && item.endValue !== undefined)
|
|
62
|
+
.map((item) => ({
|
|
63
|
+
endValue: item.endValue,
|
|
64
|
+
startValue: item.startValue,
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
getZoomCalls: () => zoomCallsRef.current,
|
|
68
|
+
pixelToValue: (pixelX) => { var _a; return (_a = getChart()) === null || _a === void 0 ? void 0 : _a.convertFromPixel({ xAxisIndex: 0 }, pixelX); },
|
|
69
|
+
resetZoomCalls: () => {
|
|
70
|
+
zoomCallsRef.current = [];
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
74
|
+
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: [
|
|
75
|
+
{
|
|
76
|
+
encode: { x: 'time', y: 'value' },
|
|
77
|
+
name: 'Value',
|
|
78
|
+
type: 'line',
|
|
79
|
+
},
|
|
80
|
+
], settings: settings, xAxis: { type: 'value' }, yAxis: { type: 'value' }, option: {
|
|
81
|
+
dataZoom: [
|
|
82
|
+
{
|
|
83
|
+
filterMode: 'none',
|
|
84
|
+
type: 'inside',
|
|
85
|
+
zoomOnMouseWheel: false,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
toolbox: {
|
|
89
|
+
feature: {
|
|
90
|
+
dataZoom: {
|
|
91
|
+
yAxisIndex: false,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
} }) })] }));
|
|
96
|
+
};
|
|
97
|
+
exports.ChartZoomHarness = ChartZoomHarness;
|
|
98
|
+
//# sourceMappingURL=ChartZoomHarness.js.map
|
|
@@ -0,0 +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,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,KAAK;QACL,MA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AE,QAAQ,EAClB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACxB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACxB,MAAM,EAAE;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;AA5FW,QAAA,gBAAgB,oBA4F3B","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 }, (_, 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 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 +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 // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n show?: boolean;\n // TODO v5: remove this prop\n /** @deprecated No longer has any effect since wrapping is now automatic, will be removed in v 5 */\n wrappingType?: 'wrapping' | 'truncation' | 'overflow';\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
|
|
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 // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n show?: boolean;\n // TODO v5: remove this prop\n /** @deprecated No longer has any effect since wrapping is now automatic, will be removed in v 5 */\n wrappingType?: 'wrapping' | 'truncation' | 'overflow';\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\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: {\n x: number;\n y: number;\n };\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 // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n selected?: boolean;\n // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n deSelected?: 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"]}
|
|
@@ -20,9 +20,44 @@
|
|
|
20
20
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.defaultThresholdLineSeriesOption = void 0;
|
|
23
|
+
exports.needleOwnedComponents = exports.defaultThresholdLineSeriesOption = exports.defaultChartSettings = void 0;
|
|
24
24
|
const defaultThresholdLineSeriesOption = {
|
|
25
25
|
condition: 'greater',
|
|
26
26
|
};
|
|
27
27
|
exports.defaultThresholdLineSeriesOption = defaultThresholdLineSeriesOption;
|
|
28
|
+
/**
|
|
29
|
+
* ECharts component main types that `buildChartOption` always writes in full,
|
|
30
|
+
* so replacing them gives the same "drop what disappeared" behavior as
|
|
31
|
+
* `notMerge`. Every entry has to be a registered component main type, which is
|
|
32
|
+
* only asserted by ECharts in development builds.
|
|
33
|
+
*
|
|
34
|
+
* `toolbox` is deliberately absent: it has to keep its view instance across
|
|
35
|
+
* updates, see `defaultChartSettings`.
|
|
36
|
+
*/
|
|
37
|
+
const needleOwnedComponents = [
|
|
38
|
+
'dataZoom',
|
|
39
|
+
'dataset',
|
|
40
|
+
'grid',
|
|
41
|
+
'legend',
|
|
42
|
+
'series',
|
|
43
|
+
'tooltip',
|
|
44
|
+
'xAxis',
|
|
45
|
+
'yAxis',
|
|
46
|
+
];
|
|
47
|
+
exports.needleOwnedComponents = needleOwnedComponents;
|
|
48
|
+
/**
|
|
49
|
+
* `notMerge` rebuilds every component view on each `setOption`. That makes
|
|
50
|
+
* ECharts mount a fresh toolbox brush controller while the previous one stays
|
|
51
|
+
* attached to the renderer, because `ToolboxView.dispose` iterates its feature
|
|
52
|
+
* map with `zrUtil.each` and so never disposes anything. Every leftover
|
|
53
|
+
* controller then re-applies the same drag, each time against an axis the
|
|
54
|
+
* previous one already zoomed, which shrinks the selected range.
|
|
55
|
+
*/
|
|
56
|
+
const defaultChartSettings = {
|
|
57
|
+
lazyUpdate: false,
|
|
58
|
+
notMerge: false,
|
|
59
|
+
replaceMerge: needleOwnedComponents,
|
|
60
|
+
silent: false,
|
|
61
|
+
};
|
|
62
|
+
exports.defaultChartSettings = defaultChartSettings;
|
|
28
63
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../../src/charts/utils/defaults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAIH,MAAM,gCAAgC,GAElC;IACF,SAAS,EAAE,SAAS;CACrB,CAAC;
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../../src/charts/utils/defaults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAIH,MAAM,gCAAgC,GAElC;IACF,SAAS,EAAE,SAAS;CACrB,CAAC;AAuCA,4EAAgC;AArClC;;;;;;;;GAQG;AACH,MAAM,qBAAqB,GAAG;IAC5B,UAAU;IACV,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;CACR,CAAC;AAoBA,sDAAqB;AAlBvB;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAwC;IAChE,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,YAAY,EAAE,qBAAqB;IACnC,MAAM,EAAE,KAAK;CACd,CAAC;AAGA,oDAAoB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { ChartProps, Condition } from './chart-types';\n\nconst defaultThresholdLineSeriesOption: {\n condition: Condition;\n} = {\n condition: 'greater',\n};\n\n/**\n * ECharts component main types that `buildChartOption` always writes in full,\n * so replacing them gives the same \"drop what disappeared\" behavior as\n * `notMerge`. Every entry has to be a registered component main type, which is\n * only asserted by ECharts in development builds.\n *\n * `toolbox` is deliberately absent: it has to keep its view instance across\n * updates, see `defaultChartSettings`.\n */\nconst needleOwnedComponents = [\n 'dataZoom',\n 'dataset',\n 'grid',\n 'legend',\n 'series',\n 'tooltip',\n 'xAxis',\n 'yAxis',\n];\n\n/**\n * `notMerge` rebuilds every component view on each `setOption`. That makes\n * ECharts mount a fresh toolbox brush controller while the previous one stays\n * attached to the renderer, because `ToolboxView.dispose` iterates its feature\n * map with `zrUtil.each` and so never disposes anything. Every leftover\n * controller then re-applies the same drag, each time against an axis the\n * previous one already zoomed, which shrinks the selected range.\n */\nconst defaultChartSettings: NonNullable<ChartProps['settings']> = {\n lazyUpdate: false,\n notMerge: false,\n replaceMerge: needleOwnedComponents,\n silent: false,\n};\n\nexport {\n defaultChartSettings,\n defaultThresholdLineSeriesOption,\n needleOwnedComponents,\n};\n"]}
|
|
@@ -26,13 +26,9 @@ import { useChartOption } from './hooks/use-chart-option';
|
|
|
26
26
|
import { useChartRefsContext } from './hooks/use-chart-refs';
|
|
27
27
|
import { useChartZoom } from './hooks/use-chart-zoom';
|
|
28
28
|
import { hasCategoryXAxis as getHasCategoryXAxis, hasMarkAreaInSeries, hasSliderDataZoom, } from './utils/build-chart-option';
|
|
29
|
+
import { defaultChartSettings } from './utils/defaults';
|
|
29
30
|
import { normalizeThresholdLines } from './utils/threshold';
|
|
30
31
|
import { mergeDataZoom, mergeSeries, mergeXAxis, mergeYAxis, } from './utils/user-option-utils';
|
|
31
|
-
const DEFAULT_CHART_SETTINGS = {
|
|
32
|
-
lazyUpdate: false,
|
|
33
|
-
notMerge: true,
|
|
34
|
-
silent: false,
|
|
35
|
-
};
|
|
36
32
|
/**
|
|
37
33
|
* Owns the ECharts instance element and coordinates chart-specific hooks.
|
|
38
34
|
*
|
|
@@ -40,7 +36,7 @@ const DEFAULT_CHART_SETTINGS = {
|
|
|
40
36
|
* initializes/resizes the chart instance, applies loading and zoom behavior, and
|
|
41
37
|
* reports derived chart state back to `Chart` for legend rendering.
|
|
42
38
|
*/
|
|
43
|
-
export const ChartRender = ({ callbacks, dataset, isChartZoomDisabled = false, isLoading, onChartOptionChange, onFirstResizeChange, option: userOption, palette, series: propsSeries, settings =
|
|
39
|
+
export const ChartRender = ({ callbacks, dataset, isChartZoomDisabled = false, isLoading, onChartOptionChange, onFirstResizeChange, option: userOption, palette, series: propsSeries, settings = defaultChartSettings, xAxis: propXAxis, yAxis: propYAxis, }) => {
|
|
44
40
|
const { chartEchartRef } = useChartRefsContext();
|
|
45
41
|
const dataZoomOptions = userOption === null || userOption === void 0 ? void 0 : userOption.dataZoom;
|
|
46
42
|
const toolboxOptions = userOption === null || userOption === void 0 ? void 0 : userOption.toolbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartRender.js","sourceRoot":"","sources":["../../../src/charts/ChartRender.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,gBAAgB,IAAI,mBAAmB,EACvC,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,UAAU,GACX,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"ChartRender.js","sourceRoot":"","sources":["../../../src/charts/ChartRender.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,E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CAAC,CAAC;IAEnD,SAAS,CAAC,GAAG,EAAE;QACb,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEvC,OAAO,cAAK,GAAG,EAAE,cAAc,EAAE,SAAS,EAAC,kBAAkB,GAAG,CAAC;AACnE,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 { useNeedleTheme } from '@neo4j-ndl/react';\nimport type { EChartsOption } from 'echarts';\nimport { useEffect, useMemo } from 'react';\n\nimport {\n useChartLifecycle,\n useChartLoading,\n useChartResize,\n} from './hooks/use-chart-instance';\nimport { useChartOption } from './hooks/use-chart-option';\nimport { useChartRefsContext } from './hooks/use-chart-refs';\nimport { useChartZoom } from './hooks/use-chart-zoom';\nimport {\n hasCategoryXAxis as getHasCategoryXAxis,\n hasMarkAreaInSeries,\n hasSliderDataZoom,\n} from './utils/build-chart-option';\nimport type { ChartProps } from './utils/chart-types';\nimport { defaultChartSettings } from './utils/defaults';\nimport { normalizeThresholdLines } from './utils/threshold';\nimport {\n mergeDataZoom,\n mergeSeries,\n mergeXAxis,\n mergeYAxis,\n} from './utils/user-option-utils';\n\ntype ChartRenderProps = Omit<ChartProps, 'legend' | 'style'> & {\n onChartOptionChange: (chartOption: EChartsOption | undefined) => void;\n onFirstResizeChange: (isWaitingForFirstResize: boolean) => void;\n};\n\n/**\n * Owns the ECharts instance element and coordinates chart-specific hooks.\n *\n * The component normalizes user props into Needle-themed ECharts options,\n * initializes/resizes the chart instance, applies loading and zoom behavior, and\n * reports derived chart state back to `Chart` for legend rendering.\n */\nexport const ChartRender = ({\n callbacks,\n dataset,\n isChartZoomDisabled = false,\n isLoading,\n onChartOptionChange,\n onFirstResizeChange,\n option: userOption,\n palette,\n series: propsSeries,\n settings = defaultChartSettings,\n xAxis: propXAxis,\n yAxis: propYAxis,\n}: ChartRenderProps) => {\n const { chartEchartRef } = useChartRefsContext();\n const dataZoomOptions = (userOption as EChartsOption)?.dataZoom;\n const toolboxOptions = (userOption as EChartsOption)?.toolbox;\n const { theme } = useNeedleTheme();\n\n const hasSliderZoom = hasSliderDataZoom(dataZoomOptions);\n const thresholdLines = useMemo(\n () => normalizeThresholdLines(propsSeries),\n [propsSeries],\n );\n const dataZoom = useMemo(\n () => mergeDataZoom(dataZoomOptions),\n [dataZoomOptions],\n );\n const series = useMemo(\n () => mergeSeries(propsSeries, theme, userOption, palette),\n [palette, propsSeries, theme, userOption],\n );\n const xAxis = useMemo(() => mergeXAxis(propXAxis, theme), [propXAxis, theme]);\n const yAxis = useMemo(() => mergeYAxis(propYAxis, theme), [propYAxis, theme]);\n const hasCategoryXAxis = getHasCategoryXAxis(xAxis);\n const hasMarkArea = hasMarkAreaInSeries(series);\n\n /**\n * Hook responsibilities:\n * - `useChartLifecycle` creates/disposes the ECharts instance and updates theme data.\n * - `useChartResize` keeps the canvas sized to its container before first render.\n * - `useChartOption` builds and applies the merged ECharts option.\n * - `useChartZoom` attaches consumer zoom callbacks.\n * - `useChartLoading` synchronizes the loading overlay with chart readiness.\n */\n useChartLifecycle({ palette, theme });\n const { isWaitingForFirstResize } = useChartResize();\n const chartOption = useChartOption({\n dataZoom,\n dataset,\n hasCategoryXAxis,\n hasMarkArea,\n hasSliderZoom,\n propsSeries,\n series,\n settings,\n thresholdLines,\n toolboxOptions,\n userOption,\n xAxis,\n yAxis,\n });\n useChartZoom({ callbacks, isChartZoomDisabled });\n useChartLoading({\n isLoading,\n isWaitingForFirstResize,\n theme,\n });\n\n useEffect(() => {\n onFirstResizeChange(isWaitingForFirstResize);\n }, [isWaitingForFirstResize, onFirstResizeChange]);\n\n useEffect(() => {\n onChartOptionChange(chartOption);\n }, [chartOption, onChartOptionChange]);\n\n return <div ref={chartEchartRef} className=\"ndl-chart-echart\" />;\n};\n"]}
|
|
@@ -28,6 +28,10 @@ import { useChartRefsContext } from './use-chart-refs';
|
|
|
28
28
|
* ECharts' global cursor API, resets zoom on double click, and clears ECharts'
|
|
29
29
|
* SVG cursor override after mouse movement so Needle's default cursor styling is
|
|
30
30
|
* preserved.
|
|
31
|
+
*
|
|
32
|
+
* The effect re-runs on every render, so each listener has to be detached again
|
|
33
|
+
* on cleanup. Otherwise they pile up and consumers get one `onZoom` call per
|
|
34
|
+
* render that has happened so far.
|
|
31
35
|
*/
|
|
32
36
|
export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
|
|
33
37
|
const { chartEchartRef } = useChartRefsContext();
|
|
@@ -36,26 +40,27 @@ export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
|
|
|
36
40
|
const chart = chartEchartRef.current === null
|
|
37
41
|
? undefined
|
|
38
42
|
: getInstanceByDom(chartEchartRef.current);
|
|
43
|
+
const handleDataZoom = () => {
|
|
44
|
+
var _a;
|
|
45
|
+
if (chartEchartRef.current === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const currentChart = getInstanceByDom(chartEchartRef.current);
|
|
49
|
+
if (!currentChart) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const option = currentChart.getOption();
|
|
53
|
+
if (!option || !option.dataZoom) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
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 });
|
|
61
|
+
};
|
|
39
62
|
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) {
|
|
40
|
-
chart === null || chart === void 0 ? void 0 : chart.on('datazoom',
|
|
41
|
-
var _a;
|
|
42
|
-
if (chartEchartRef.current === null) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const currentChart = getInstanceByDom(chartEchartRef.current);
|
|
46
|
-
if (!currentChart) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const option = currentChart.getOption();
|
|
50
|
-
if (!option || !option.dataZoom) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const dataZoom = Array.isArray(option.dataZoom)
|
|
54
|
-
? option.dataZoom[0]
|
|
55
|
-
: option.dataZoom;
|
|
56
|
-
const { startValue, endValue } = dataZoom;
|
|
57
|
-
(_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onZoom) === null || _a === void 0 ? void 0 : _a.call(callbacks, { endValue, startValue });
|
|
58
|
-
});
|
|
63
|
+
chart === null || chart === void 0 ? void 0 : chart.on('datazoom', handleDataZoom);
|
|
59
64
|
}
|
|
60
65
|
const handleMouseMove = () => {
|
|
61
66
|
// ECharts updates SVG cursor styles on mouse move, so Needle has to
|
|
@@ -94,6 +99,7 @@ export function useChartZoom({ callbacks, isChartZoomDisabled, }) {
|
|
|
94
99
|
element === null || element === void 0 ? void 0 : element.removeEventListener('mousemove', handleMouseMove);
|
|
95
100
|
if (chartRefCurrentElement) {
|
|
96
101
|
const chart = getInstanceByDom(chartRefCurrentElement);
|
|
102
|
+
chart === null || chart === void 0 ? void 0 : chart.off('datazoom', handleDataZoom);
|
|
97
103
|
chart === null || chart === void 0 ? void 0 : chart.getZr().off('mousedown', handleMouseDown);
|
|
98
104
|
}
|
|
99
105
|
};
|
|
@@ -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
|
|
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,CA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CAAC;QAC5D,MAAM,KAAK,GAAG,gBAAgB,CAAC,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"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) "Neo4j"
|
|
5
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
6
|
+
*
|
|
7
|
+
* This file is part of Neo4j.
|
|
8
|
+
*
|
|
9
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* This program is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU General Public License
|
|
20
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
+
*/
|
|
22
|
+
import { Chart } from '@neo4j-ndl/react-charts';
|
|
23
|
+
import { getInstanceByDom } from 'echarts';
|
|
24
|
+
import { useCallback, useEffect, useRef, useState, } from 'react';
|
|
25
|
+
const POINT_COUNT = 180;
|
|
26
|
+
const zoomHarnessDataset = [
|
|
27
|
+
['time', 'value'],
|
|
28
|
+
...Array.from({ length: POINT_COUNT }, (_, index) => [
|
|
29
|
+
index,
|
|
30
|
+
Number((40 + Math.sin(index / 6) * 12).toFixed(2)),
|
|
31
|
+
]),
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Reproduces the consumer setup from the metrics UI: a chart with toolbox
|
|
35
|
+
* brush-zoom whose parent re-renders while the chart stays mounted, passing a
|
|
36
|
+
* freshly built `option` object on every render.
|
|
37
|
+
*/
|
|
38
|
+
export const ChartZoomHarness = ({ settings, }) => {
|
|
39
|
+
const containerRef = useRef(null);
|
|
40
|
+
const zoomCallsRef = useRef([]);
|
|
41
|
+
const [, setRerenderCount] = useState(0);
|
|
42
|
+
const handleZoom = useCallback((zoom) => {
|
|
43
|
+
zoomCallsRef.current = [...zoomCallsRef.current, zoom];
|
|
44
|
+
}, []);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const getChart = () => {
|
|
47
|
+
var _a;
|
|
48
|
+
const echartElement = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.ndl-chart-echart');
|
|
49
|
+
return echartElement instanceof HTMLElement
|
|
50
|
+
? getInstanceByDom(echartElement)
|
|
51
|
+
: undefined;
|
|
52
|
+
};
|
|
53
|
+
window.chartZoomHarness = {
|
|
54
|
+
getAppliedZoomWindows: () => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const dataZoom = (_b = (_a = getChart()) === null || _a === void 0 ? void 0 : _a.getOption()) === null || _b === void 0 ? void 0 : _b.dataZoom;
|
|
57
|
+
return (dataZoom !== null && dataZoom !== void 0 ? dataZoom : [])
|
|
58
|
+
.filter((item) => item.startValue !== undefined && item.endValue !== undefined)
|
|
59
|
+
.map((item) => ({
|
|
60
|
+
endValue: item.endValue,
|
|
61
|
+
startValue: item.startValue,
|
|
62
|
+
}));
|
|
63
|
+
},
|
|
64
|
+
getZoomCalls: () => zoomCallsRef.current,
|
|
65
|
+
pixelToValue: (pixelX) => { var _a; return (_a = getChart()) === null || _a === void 0 ? void 0 : _a.convertFromPixel({ xAxisIndex: 0 }, pixelX); },
|
|
66
|
+
resetZoomCalls: () => {
|
|
67
|
+
zoomCallsRef.current = [];
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
71
|
+
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: [
|
|
72
|
+
{
|
|
73
|
+
encode: { x: 'time', y: 'value' },
|
|
74
|
+
name: 'Value',
|
|
75
|
+
type: 'line',
|
|
76
|
+
},
|
|
77
|
+
], settings: settings, xAxis: { type: 'value' }, yAxis: { type: 'value' }, option: {
|
|
78
|
+
dataZoom: [
|
|
79
|
+
{
|
|
80
|
+
filterMode: 'none',
|
|
81
|
+
type: 'inside',
|
|
82
|
+
zoomOnMouseWheel: false,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
toolbox: {
|
|
86
|
+
feature: {
|
|
87
|
+
dataZoom: {
|
|
88
|
+
yAxisIndex: false,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
} }) })] }));
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=ChartZoomHarness.js.map
|
|
@@ -0,0 +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,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,KAAK;QACL,MAAM,CAAC,CAAC,EAAE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EAAE,EACxB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACxB,MAAM,EAAE;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","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 }, (_, 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 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 +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 // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n show?: boolean;\n // TODO v5: remove this prop\n /** @deprecated No longer has any effect since wrapping is now automatic, will be removed in v 5 */\n wrappingType?: 'wrapping' | 'truncation' | 'overflow';\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
|
|
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 // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n show?: boolean;\n // TODO v5: remove this prop\n /** @deprecated No longer has any effect since wrapping is now automatic, will be removed in v 5 */\n wrappingType?: 'wrapping' | 'truncation' | 'overflow';\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\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: {\n x: number;\n y: number;\n };\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 // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n selected?: boolean;\n // TODO v5: fix boolean naming convention\n // eslint-disable-next-line @typescript-eslint/naming-convention\n deSelected?: 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"]}
|
|
@@ -21,5 +21,38 @@
|
|
|
21
21
|
const defaultThresholdLineSeriesOption = {
|
|
22
22
|
condition: 'greater',
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* ECharts component main types that `buildChartOption` always writes in full,
|
|
26
|
+
* so replacing them gives the same "drop what disappeared" behavior as
|
|
27
|
+
* `notMerge`. Every entry has to be a registered component main type, which is
|
|
28
|
+
* only asserted by ECharts in development builds.
|
|
29
|
+
*
|
|
30
|
+
* `toolbox` is deliberately absent: it has to keep its view instance across
|
|
31
|
+
* updates, see `defaultChartSettings`.
|
|
32
|
+
*/
|
|
33
|
+
const needleOwnedComponents = [
|
|
34
|
+
'dataZoom',
|
|
35
|
+
'dataset',
|
|
36
|
+
'grid',
|
|
37
|
+
'legend',
|
|
38
|
+
'series',
|
|
39
|
+
'tooltip',
|
|
40
|
+
'xAxis',
|
|
41
|
+
'yAxis',
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* `notMerge` rebuilds every component view on each `setOption`. That makes
|
|
45
|
+
* ECharts mount a fresh toolbox brush controller while the previous one stays
|
|
46
|
+
* attached to the renderer, because `ToolboxView.dispose` iterates its feature
|
|
47
|
+
* map with `zrUtil.each` and so never disposes anything. Every leftover
|
|
48
|
+
* controller then re-applies the same drag, each time against an axis the
|
|
49
|
+
* previous one already zoomed, which shrinks the selected range.
|
|
50
|
+
*/
|
|
51
|
+
const defaultChartSettings = {
|
|
52
|
+
lazyUpdate: false,
|
|
53
|
+
notMerge: false,
|
|
54
|
+
replaceMerge: needleOwnedComponents,
|
|
55
|
+
silent: false,
|
|
56
|
+
};
|
|
57
|
+
export { defaultChartSettings, defaultThresholdLineSeriesOption, needleOwnedComponents, };
|
|
25
58
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../../src/charts/utils/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,gCAAgC,GAElC;IACF,SAAS,EAAE,SAAS;CACrB,CAAC;AAEF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../../src/charts/utils/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,gCAAgC,GAElC;IACF,SAAS,EAAE,SAAS;CACrB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,qBAAqB,GAAG;IAC5B,UAAU;IACV,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;CACR,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAwC;IAChE,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,YAAY,EAAE,qBAAqB;IACnC,MAAM,EAAE,KAAK;CACd,CAAC;AAEF,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAChC,qBAAqB,GACtB,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 type { ChartProps, Condition } from './chart-types';\n\nconst defaultThresholdLineSeriesOption: {\n condition: Condition;\n} = {\n condition: 'greater',\n};\n\n/**\n * ECharts component main types that `buildChartOption` always writes in full,\n * so replacing them gives the same \"drop what disappeared\" behavior as\n * `notMerge`. Every entry has to be a registered component main type, which is\n * only asserted by ECharts in development builds.\n *\n * `toolbox` is deliberately absent: it has to keep its view instance across\n * updates, see `defaultChartSettings`.\n */\nconst needleOwnedComponents = [\n 'dataZoom',\n 'dataset',\n 'grid',\n 'legend',\n 'series',\n 'tooltip',\n 'xAxis',\n 'yAxis',\n];\n\n/**\n * `notMerge` rebuilds every component view on each `setOption`. That makes\n * ECharts mount a fresh toolbox brush controller while the previous one stays\n * attached to the renderer, because `ToolboxView.dispose` iterates its feature\n * map with `zrUtil.each` and so never disposes anything. Every leftover\n * controller then re-applies the same drag, each time against an axis the\n * previous one already zoomed, which shrinks the selected range.\n */\nconst defaultChartSettings: NonNullable<ChartProps['settings']> = {\n lazyUpdate: false,\n notMerge: false,\n replaceMerge: needleOwnedComponents,\n silent: false,\n};\n\nexport {\n defaultChartSettings,\n defaultThresholdLineSeriesOption,\n needleOwnedComponents,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartRender.d.ts","sourceRoot":"","sources":["../../../src/charts/ChartRender.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ChartRender.d.ts","sourceRoot":"","sources":["../../../src/charts/ChartRender.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAUtD,KAAK,gBAAgB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG;IAC7D,mBAAmB,EAAE,CAAC,WAAW,EAAE,aAAa,GAAG,SAAS,KAAK,IAAI,CAAC;IACtE,mBAAmB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,IAAI,CAAC;CACjE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,mMAazB,gBAAgB,4CAiElB,CAAC"}
|
|
@@ -30,6 +30,10 @@ type UseChartZoomParams = {
|
|
|
30
30
|
* ECharts' global cursor API, resets zoom on double click, and clears ECharts'
|
|
31
31
|
* SVG cursor override after mouse movement so Needle's default cursor styling is
|
|
32
32
|
* preserved.
|
|
33
|
+
*
|
|
34
|
+
* The effect re-runs on every render, so each listener has to be detached again
|
|
35
|
+
* on cleanup. Otherwise they pile up and consumers get one `onZoom` call per
|
|
36
|
+
* render that has happened so far.
|
|
33
37
|
*/
|
|
34
38
|
export declare function useChartZoom({ callbacks, isChartZoomDisabled, }: UseChartZoomParams): void;
|
|
35
39
|
export {};
|
|
@@ -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
|
|
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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Neo4j.
|
|
7
|
+
*
|
|
8
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
import { Chart } from '@neo4j-ndl/react-charts';
|
|
22
|
+
import { type ComponentProps } from 'react';
|
|
23
|
+
type ChartSettings = ComponentProps<typeof Chart>['settings'];
|
|
24
|
+
export type ZoomCall = {
|
|
25
|
+
endValue: number;
|
|
26
|
+
startValue: number;
|
|
27
|
+
};
|
|
28
|
+
export type ZoomHarnessApi = {
|
|
29
|
+
/** Applied zoom windows, in data values, as ECharts currently has them. */
|
|
30
|
+
getAppliedZoomWindows: () => ZoomCall[];
|
|
31
|
+
/** Every `callbacks.onZoom` invocation the consumer received. */
|
|
32
|
+
getZoomCalls: () => ZoomCall[];
|
|
33
|
+
/** Data value at a pixel offset inside the chart element. */
|
|
34
|
+
pixelToValue: (pixelX: number) => number;
|
|
35
|
+
resetZoomCalls: () => void;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Reproduces the consumer setup from the metrics UI: a chart with toolbox
|
|
39
|
+
* brush-zoom whose parent re-renders while the chart stays mounted, passing a
|
|
40
|
+
* freshly built `option` object on every render.
|
|
41
|
+
*/
|
|
42
|
+
export declare const ChartZoomHarness: ({ settings, }: {
|
|
43
|
+
settings?: ChartSettings;
|
|
44
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=ChartZoomHarness.d.ts.map
|
|
@@ -0,0 +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,4CAwFA,CAAC"}
|
|
@@ -59,7 +59,13 @@ export interface ChartProps {
|
|
|
59
59
|
option?: Omit<EChartsOption, 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'>;
|
|
60
60
|
/** Custom CSS styles to apply to the chart container. */
|
|
61
61
|
style?: React.CSSProperties;
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Settings for how ECharts should update the chart. Defaults to replacing the
|
|
64
|
+
* components the chart owns (`series`, `dataset`, axes, and similar) while
|
|
65
|
+
* merging the rest, which drops data that disappeared without discarding the
|
|
66
|
+
* ECharts components behind zoom interactions. Passing `notMerge: true`
|
|
67
|
+
* re-creates those components on every update and breaks drag-to-zoom.
|
|
68
|
+
*/
|
|
63
69
|
settings?: SetOptionOpts;
|
|
64
70
|
/** Whether the chart is in a loading state. */
|
|
65
71
|
isLoading?: boolean;
|
|
@@ -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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ACf,EAAE,CAAC;IACJ,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,IACpD,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,GAAG;IAClC,CAAC,GAAG,EAAE,QAAQ,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,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"}
|
|
@@ -18,9 +18,28 @@
|
|
|
18
18
|
* You should have received a copy of the GNU General Public License
|
|
19
19
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
import type { Condition } from './chart-types';
|
|
21
|
+
import type { ChartProps, Condition } from './chart-types';
|
|
22
22
|
declare const defaultThresholdLineSeriesOption: {
|
|
23
23
|
condition: Condition;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* ECharts component main types that `buildChartOption` always writes in full,
|
|
27
|
+
* so replacing them gives the same "drop what disappeared" behavior as
|
|
28
|
+
* `notMerge`. Every entry has to be a registered component main type, which is
|
|
29
|
+
* only asserted by ECharts in development builds.
|
|
30
|
+
*
|
|
31
|
+
* `toolbox` is deliberately absent: it has to keep its view instance across
|
|
32
|
+
* updates, see `defaultChartSettings`.
|
|
33
|
+
*/
|
|
34
|
+
declare const needleOwnedComponents: string[];
|
|
35
|
+
/**
|
|
36
|
+
* `notMerge` rebuilds every component view on each `setOption`. That makes
|
|
37
|
+
* ECharts mount a fresh toolbox brush controller while the previous one stays
|
|
38
|
+
* attached to the renderer, because `ToolboxView.dispose` iterates its feature
|
|
39
|
+
* map with `zrUtil.each` and so never disposes anything. Every leftover
|
|
40
|
+
* controller then re-applies the same drag, each time against an axis the
|
|
41
|
+
* previous one already zoomed, which shrinks the selected range.
|
|
42
|
+
*/
|
|
43
|
+
declare const defaultChartSettings: NonNullable<ChartProps['settings']>;
|
|
44
|
+
export { defaultChartSettings, defaultThresholdLineSeriesOption, needleOwnedComponents, };
|
|
26
45
|
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/charts/utils/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/charts/utils/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3D,QAAA,MAAM,gCAAgC,EAAE;IACtC,SAAS,EAAE,SAAS,CAAC;CAGtB,CAAC;AAEF;;;;;;;;GAQG;AACH,QAAA,MAAM,qBAAqB,UAS1B,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,EAAE,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAK7D,CAAC;AAEF,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAChC,qBAAqB,GACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-ndl/react-charts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.22",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React implementation of charts from Neo4j Design System",
|
|
6
6
|
"keywords": [
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": ">=19.0.0",
|
|
58
58
|
"react-dom": ">=19.0.0",
|
|
59
|
-
"@neo4j-ndl/base": "^4.17.
|
|
60
|
-
"@neo4j-ndl/react": "^4.18.
|
|
59
|
+
"@neo4j-ndl/base": "^4.17.2",
|
|
60
|
+
"@neo4j-ndl/react": "^4.18.1"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"classnames": "2.5.1",
|
|
@@ -17,7 +17,7 @@ Import: `import { Chart } from '@neo4j-ndl/react-charts'`
|
|
|
17
17
|
| `option` | `Omit<EChartsOption, "legend" \| "dataset" \| "series" \| "xAxis" \| "yAxis">` | | | Additional ECharts options to merge with the chart configuration. |
|
|
18
18
|
| `palette` | `` `#${string}`[] `` | | | Custom color palette that overrides the default categorical colors. |
|
|
19
19
|
| `series` | `NeedleSeries` | ✅ | | The series configuration for the chart. Defines what data to display and how to display it. |
|
|
20
|
-
| `settings` | `SetOptionOpts` | | | Settings for how ECharts should update the chart. |
|
|
20
|
+
| `settings` | `SetOptionOpts` | | | Settings for how ECharts should update the chart. Defaults to replacing the components the chart owns (`series`, `dataset`, axes, and similar) while merging the rest, which drops data that disappeared without discarding the ECharts components behind zoom interactions. Passing `notMerge: true` re-creates those components on every update and breaks drag-to-zoom. |
|
|
21
21
|
| `xAxis` | `XAXisOption \| XAXisOption[]` | | | X-axis configuration for the chart. |
|
|
22
22
|
| `yAxis` | `YAXisOption \| YAXisOption[]` | | | Y-axis configuration for the chart. |
|
|
23
23
|
|