@neo4j-ndl/react-charts 2.1.21 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/LICENSES.txt +0 -295
- package/lib/NOTICE.txt +1383 -1392
- package/lib/{esm/charts/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.js} +13 -5
- package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.js +46 -0
- package/lib/{esm/charts/tests/ChartWrapperWithTooltipFormatter.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.js} +12 -13
- package/lib/{esm/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.js} +13 -2
- package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.js +35 -0
- package/lib/{esm/charts/utils/chart-types.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.js} +10 -2
- package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.js +37 -0
- package/lib/cjs/_virtual/_rolldown/runtime.js +44 -0
- package/lib/cjs/charts/Chart.js +121 -111
- package/lib/cjs/charts/Chart.js.map +1 -1
- package/lib/cjs/charts/ChartContainer.js +67 -62
- package/lib/cjs/charts/ChartContainer.js.map +1 -1
- package/lib/cjs/charts/ChartEmpty.js +45 -30
- package/lib/cjs/charts/ChartEmpty.js.map +1 -1
- package/lib/cjs/charts/ChartRender.js +112 -87
- package/lib/cjs/charts/ChartRender.js.map +1 -1
- package/lib/cjs/charts/ChartTooltip.js +111 -65
- package/lib/cjs/charts/ChartTooltip.js.map +1 -1
- package/lib/cjs/charts/Legend.js +81 -69
- package/lib/cjs/charts/Legend.js.map +1 -1
- package/lib/cjs/charts/LegendItem.js +83 -62
- package/lib/cjs/charts/LegendItem.js.map +1 -1
- package/lib/cjs/charts/LegendLayout.js +330 -348
- package/lib/cjs/charts/LegendLayout.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-instance.js +115 -122
- package/lib/cjs/charts/hooks/use-chart-instance.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-option.js +79 -80
- package/lib/cjs/charts/hooks/use-chart-option.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-refs.js +47 -44
- package/lib/cjs/charts/hooks/use-chart-refs.js.map +1 -1
- package/lib/cjs/charts/hooks/use-chart-zoom.js +102 -127
- package/lib/cjs/charts/hooks/use-chart-zoom.js.map +1 -1
- package/lib/cjs/charts/hooks/use-legend-interactions.js +127 -132
- package/lib/cjs/charts/hooks/use-legend-interactions.js.map +1 -1
- package/lib/cjs/charts/hooks/use-legend-series.js +143 -174
- package/lib/cjs/charts/hooks/use-legend-series.js.map +1 -1
- package/lib/cjs/charts/hooks/use-legend-visibility.js +66 -85
- package/lib/cjs/charts/hooks/use-legend-visibility.js.map +1 -1
- package/lib/cjs/charts/index.js +31 -40
- package/lib/cjs/charts/index.js.map +1 -1
- package/lib/cjs/charts/themes/ndl-echarts-theme.js +136 -168
- package/lib/cjs/charts/themes/ndl-echarts-theme.js.map +1 -1
- package/lib/cjs/charts/utils/aria-description.js +150 -214
- package/lib/cjs/charts/utils/aria-description.js.map +1 -1
- package/lib/cjs/charts/utils/build-chart-option.js +166 -174
- package/lib/cjs/charts/utils/build-chart-option.js.map +1 -1
- package/lib/cjs/charts/utils/chart-tooltip-formatter.js +156 -172
- package/lib/cjs/charts/utils/chart-tooltip-formatter.js.map +1 -1
- package/lib/cjs/charts/utils/chart-types.js +25 -20
- package/lib/cjs/charts/utils/chart-types.js.map +1 -1
- package/lib/cjs/charts/utils/defaults.js +69 -67
- package/lib/cjs/charts/utils/defaults.js.map +1 -1
- package/lib/cjs/charts/utils/format-utils.js +55 -66
- package/lib/cjs/charts/utils/format-utils.js.map +1 -1
- package/lib/cjs/charts/utils/legend-layout.js +54 -53
- package/lib/cjs/charts/utils/legend-layout.js.map +1 -1
- package/lib/cjs/charts/utils/legend-utils.js +82 -121
- package/lib/cjs/charts/utils/legend-utils.js.map +1 -1
- package/lib/cjs/charts/utils/scatter-tooltip-points.js +191 -266
- package/lib/cjs/charts/utils/scatter-tooltip-points.js.map +1 -1
- package/lib/cjs/charts/utils/threshold.js +89 -102
- package/lib/cjs/charts/utils/threshold.js.map +1 -1
- package/lib/cjs/charts/utils/user-option-utils.js +419 -347
- package/lib/cjs/charts/utils/user-option-utils.js.map +1 -1
- package/lib/cjs/index.js +31 -35
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.mjs +11 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs +24 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.mjs +12 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.mjs +11 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.mjs +13 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.mjs +8 -0
- package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.mjs +10 -0
- package/lib/esm/charts/Chart.mjs +123 -0
- package/lib/esm/charts/Chart.mjs.map +1 -0
- package/lib/esm/charts/ChartContainer.mjs +71 -0
- package/lib/esm/charts/ChartContainer.mjs.map +1 -0
- package/lib/esm/charts/ChartEmpty.mjs +46 -0
- package/lib/esm/charts/ChartEmpty.mjs.map +1 -0
- package/lib/esm/charts/ChartRender.mjs +113 -0
- package/lib/esm/charts/ChartRender.mjs.map +1 -0
- package/lib/esm/charts/ChartTooltip.mjs +109 -0
- package/lib/esm/charts/ChartTooltip.mjs.map +1 -0
- package/lib/esm/charts/Legend.mjs +82 -0
- package/lib/esm/charts/Legend.mjs.map +1 -0
- package/lib/esm/charts/LegendItem.mjs +82 -0
- package/lib/esm/charts/LegendItem.mjs.map +1 -0
- package/lib/esm/charts/LegendLayout.mjs +337 -0
- package/lib/esm/charts/LegendLayout.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-instance.mjs +119 -0
- package/lib/esm/charts/hooks/use-chart-instance.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-option.mjs +79 -0
- package/lib/esm/charts/hooks/use-chart-option.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-refs.mjs +49 -0
- package/lib/esm/charts/hooks/use-chart-refs.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-chart-zoom.mjs +102 -0
- package/lib/esm/charts/hooks/use-chart-zoom.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-legend-interactions.mjs +138 -0
- package/lib/esm/charts/hooks/use-legend-interactions.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-legend-series.mjs +151 -0
- package/lib/esm/charts/hooks/use-legend-series.mjs.map +1 -0
- package/lib/esm/charts/hooks/use-legend-visibility.mjs +67 -0
- package/lib/esm/charts/hooks/use-legend-visibility.mjs.map +1 -0
- package/lib/esm/charts/index.mjs +27 -0
- package/lib/esm/charts/index.mjs.map +1 -0
- package/lib/esm/charts/themes/ndl-echarts-theme.mjs +139 -0
- package/lib/esm/charts/themes/ndl-echarts-theme.mjs.map +1 -0
- package/lib/esm/charts/utils/aria-description.mjs +162 -0
- package/lib/esm/charts/utils/aria-description.mjs.map +1 -0
- package/lib/esm/charts/utils/build-chart-option.mjs +184 -0
- package/lib/esm/charts/utils/build-chart-option.mjs.map +1 -0
- package/lib/esm/charts/utils/chart-tooltip-formatter.mjs +159 -0
- package/lib/esm/charts/utils/chart-tooltip-formatter.mjs.map +1 -0
- package/lib/esm/charts/utils/chart-types.mjs +24 -0
- package/lib/esm/charts/utils/chart-types.mjs.map +1 -0
- package/lib/esm/charts/utils/defaults.mjs +73 -0
- package/lib/esm/charts/utils/defaults.mjs.map +1 -0
- package/lib/esm/charts/utils/format-utils.mjs +61 -0
- package/lib/esm/charts/utils/format-utils.mjs.map +1 -0
- package/lib/esm/charts/utils/legend-layout.mjs +57 -0
- package/lib/esm/charts/utils/legend-layout.mjs.map +1 -0
- package/lib/esm/charts/utils/legend-utils.mjs +90 -0
- package/lib/esm/charts/utils/legend-utils.mjs.map +1 -0
- package/lib/esm/charts/utils/scatter-tooltip-points.mjs +215 -0
- package/lib/esm/charts/utils/scatter-tooltip-points.mjs.map +1 -0
- package/lib/esm/charts/utils/threshold.mjs +92 -0
- package/lib/esm/charts/utils/threshold.mjs.map +1 -0
- package/lib/esm/charts/utils/user-option-utils.mjs +445 -0
- package/lib/esm/charts/utils/user-option-utils.mjs.map +1 -0
- package/lib/esm/index.mjs +27 -0
- package/lib/esm/index.mjs.map +1 -0
- package/package.json +12 -16
- package/skills/ndl-react-charts/SKILL.md +2 -2
- package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js +0 -38
- package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
- package/lib/cjs/charts/tests/ChartZoomHarness.js +0 -113
- package/lib/cjs/charts/tests/ChartZoomHarness.js.map +0 -1
- package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js +0 -78
- package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
- package/lib/cjs/charts/tests/PieChartWithRerender.js +0 -46
- package/lib/cjs/charts/tests/PieChartWithRerender.js.map +0 -1
- package/lib/cjs/charts/tests/chart-test-utils.js +0 -527
- package/lib/cjs/charts/tests/chart-test-utils.js.map +0 -1
- package/lib/esm/charts/Chart.js +0 -114
- package/lib/esm/charts/Chart.js.map +0 -1
- package/lib/esm/charts/ChartContainer.js +0 -67
- package/lib/esm/charts/ChartContainer.js.map +0 -1
- package/lib/esm/charts/ChartEmpty.js +0 -33
- package/lib/esm/charts/ChartEmpty.js.map +0 -1
- package/lib/esm/charts/ChartRender.js +0 -89
- package/lib/esm/charts/ChartRender.js.map +0 -1
- package/lib/esm/charts/ChartTooltip.js +0 -64
- package/lib/esm/charts/ChartTooltip.js.map +0 -1
- package/lib/esm/charts/Legend.js +0 -71
- package/lib/esm/charts/Legend.js.map +0 -1
- package/lib/esm/charts/LegendItem.js +0 -61
- package/lib/esm/charts/LegendItem.js.map +0 -1
- package/lib/esm/charts/LegendLayout.js +0 -323
- package/lib/esm/charts/LegendLayout.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-instance.js +0 -128
- package/lib/esm/charts/hooks/use-chart-instance.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-option.js +0 -82
- package/lib/esm/charts/hooks/use-chart-option.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-refs.js +0 -48
- package/lib/esm/charts/hooks/use-chart-refs.js.map +0 -1
- package/lib/esm/charts/hooks/use-chart-zoom.js +0 -129
- package/lib/esm/charts/hooks/use-chart-zoom.js.map +0 -1
- package/lib/esm/charts/hooks/use-legend-interactions.js +0 -145
- package/lib/esm/charts/hooks/use-legend-interactions.js.map +0 -1
- package/lib/esm/charts/hooks/use-legend-series.js +0 -184
- package/lib/esm/charts/hooks/use-legend-series.js.map +0 -1
- package/lib/esm/charts/hooks/use-legend-visibility.js +0 -87
- package/lib/esm/charts/hooks/use-legend-visibility.js.map +0 -1
- package/lib/esm/charts/index.js.map +0 -1
- package/lib/esm/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
- package/lib/esm/charts/tests/ChartZoomHarness.js +0 -109
- package/lib/esm/charts/tests/ChartZoomHarness.js.map +0 -1
- package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js +0 -74
- package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
- package/lib/esm/charts/tests/PieChartWithRerender.js +0 -43
- package/lib/esm/charts/tests/PieChartWithRerender.js.map +0 -1
- package/lib/esm/charts/tests/chart-test-utils.js +0 -500
- package/lib/esm/charts/tests/chart-test-utils.js.map +0 -1
- package/lib/esm/charts/themes/ndl-echarts-theme.js +0 -172
- package/lib/esm/charts/themes/ndl-echarts-theme.js.map +0 -1
- package/lib/esm/charts/utils/aria-description.js +0 -228
- package/lib/esm/charts/utils/aria-description.js.map +0 -1
- package/lib/esm/charts/utils/build-chart-option.js +0 -193
- package/lib/esm/charts/utils/build-chart-option.js.map +0 -1
- package/lib/esm/charts/utils/chart-tooltip-formatter.js +0 -177
- package/lib/esm/charts/utils/chart-tooltip-formatter.js.map +0 -1
- package/lib/esm/charts/utils/chart-types.js.map +0 -1
- package/lib/esm/charts/utils/defaults.js +0 -73
- package/lib/esm/charts/utils/defaults.js.map +0 -1
- package/lib/esm/charts/utils/format-utils.js +0 -74
- package/lib/esm/charts/utils/format-utils.js.map +0 -1
- package/lib/esm/charts/utils/legend-layout.js +0 -59
- package/lib/esm/charts/utils/legend-layout.js.map +0 -1
- package/lib/esm/charts/utils/legend-utils.js +0 -131
- package/lib/esm/charts/utils/legend-utils.js.map +0 -1
- package/lib/esm/charts/utils/scatter-tooltip-points.js +0 -291
- package/lib/esm/charts/utils/scatter-tooltip-points.js.map +0 -1
- package/lib/esm/charts/utils/threshold.js +0 -106
- package/lib/esm/charts/utils/threshold.js.map +0 -1
- package/lib/esm/charts/utils/user-option-utils.js +0 -374
- package/lib/esm/charts/utils/user-option-utils.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { ChartTooltip } from "../ChartTooltip.mjs";
|
|
2
|
+
import { capitalizeFirstLetter, extractValueFromTooltipSeries, formatTimeAxisDate, formatTooltipValue } from "./format-utils.mjs";
|
|
3
|
+
import { encodedDimensionLabel, extraTooltipRefs, findNearbyScatterPoints, getEncodedAxisRefs, getScatterSymbolSize, readEncodedValue } from "./scatter-tooltip-points.mjs";
|
|
4
|
+
import { evaluateThresholdCondition, getThresholdLineDisplayName, isThresholdLine } from "./threshold.mjs";
|
|
5
|
+
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { renderToString } from "react-dom/server";
|
|
8
|
+
// src/charts/utils/chart-tooltip-formatter.tsx
|
|
9
|
+
/*!
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) "Neo4j"
|
|
12
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
13
|
+
*
|
|
14
|
+
* This file is part of Neo4j.
|
|
15
|
+
*
|
|
16
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
17
|
+
* it under the terms of the GNU General Public License as published by
|
|
18
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
19
|
+
* (at your option) any later version.
|
|
20
|
+
*
|
|
21
|
+
* This program is distributed in the hope that it will be useful,
|
|
22
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
23
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
24
|
+
* GNU General Public License for more details.
|
|
25
|
+
*
|
|
26
|
+
* You should have received a copy of the GNU General Public License
|
|
27
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
28
|
+
*/
|
|
29
|
+
function getTooltipValueFormatter(userOption) {
|
|
30
|
+
if (typeof (userOption === null || userOption === void 0 ? void 0 : userOption.tooltip) === "object" && userOption.tooltip !== null && "valueFormatter" in userOption.tooltip) return userOption.tooltip.valueFormatter;
|
|
31
|
+
return formatTooltipValue;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Upper bound on the points one tooltip lists, so a dense cluster cannot grow
|
|
35
|
+
* a tooltip that covers the chart.
|
|
36
|
+
*/
|
|
37
|
+
const MAX_TOOLTIP_POINTS = 5;
|
|
38
|
+
/**
|
|
39
|
+
* Builds the ECharts axis-tooltip formatter used by line-like charts.
|
|
40
|
+
* It renders Needle tooltip markup and augments non-threshold series with
|
|
41
|
+
* threshold notifications when their current value crosses a threshold line.
|
|
42
|
+
*/
|
|
43
|
+
function createAxisTooltipFormatter({ thresholdLines, userOption }) {
|
|
44
|
+
const valueFormatter = getTooltipValueFormatter(userOption);
|
|
45
|
+
return function axisTooltipFormatter(params) {
|
|
46
|
+
var _firstParam$axisValue;
|
|
47
|
+
const paramsArray = Array.isArray(params) ? params : [params];
|
|
48
|
+
const firstParam = paramsArray[0];
|
|
49
|
+
return `${renderToString(/* @__PURE__ */ jsxs("span", {
|
|
50
|
+
className: "ndl-charts-chart-tooltip",
|
|
51
|
+
children: [/* @__PURE__ */ jsx(ChartTooltip.Title, { children: (_firstParam$axisValue = firstParam === null || firstParam === void 0 ? void 0 : firstParam.axisValueLabel) !== null && _firstParam$axisValue !== void 0 ? _firstParam$axisValue : "" }), paramsArray.map((series) => {
|
|
52
|
+
const value = extractValueFromTooltipSeries(series.value, series.encode, series.axisDim);
|
|
53
|
+
const seriesValue = typeof value === "number" ? value : Number(value);
|
|
54
|
+
const isSeriesThresholdLine = isThresholdLine(series.seriesName);
|
|
55
|
+
const notifications = thresholdLines.flatMap((threshold) => {
|
|
56
|
+
if (isSeriesThresholdLine || Number.isNaN(seriesValue)) return [];
|
|
57
|
+
const { notificationType, value: thresholdValue, condition, customConditionText, customCondition } = threshold;
|
|
58
|
+
const conditionEvaluation = customCondition ? {
|
|
59
|
+
conditionText: customConditionText,
|
|
60
|
+
isConditionMet: customCondition(seriesValue, thresholdValue)
|
|
61
|
+
} : evaluateThresholdCondition(seriesValue, condition, thresholdValue);
|
|
62
|
+
if (!conditionEvaluation.isConditionMet) return [];
|
|
63
|
+
return [{
|
|
64
|
+
id: `threshold-${notificationType}`,
|
|
65
|
+
leadingElement: customCondition ? conditionEvaluation.conditionText : `${conditionEvaluation.conditionText} threshold`,
|
|
66
|
+
notificationType,
|
|
67
|
+
trailingElement: valueFormatter(thresholdValue)
|
|
68
|
+
}];
|
|
69
|
+
});
|
|
70
|
+
return /* @__PURE__ */ jsx(ChartTooltip.Content, {
|
|
71
|
+
leadingElement: isSeriesThresholdLine ? `${capitalizeFirstLetter(getThresholdLineDisplayName(series.seriesName))} threshold` : series.seriesName,
|
|
72
|
+
trailingElement: valueFormatter(value),
|
|
73
|
+
indentSquareColor: series.color,
|
|
74
|
+
notifications
|
|
75
|
+
}, series.seriesName);
|
|
76
|
+
})]
|
|
77
|
+
}))}`;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Builds the ECharts item-tooltip formatter used by scatter charts.
|
|
82
|
+
*
|
|
83
|
+
* The title comes from ECharts `encode.tooltip`, then `encode.itemName`, then
|
|
84
|
+
* an extra data dimension, and otherwise the series name. x and y are listed
|
|
85
|
+
* underneath. See https://echarts.apache.org/en/option.html#series-scatter.encode
|
|
86
|
+
*
|
|
87
|
+
* `tooltip.valueFormatter` runs on the x and y values only. Those calls pass
|
|
88
|
+
* `{ axis: 'x' | 'y' }` (`TooltipValueContext`) as the third argument. The
|
|
89
|
+
* title is shown unchanged.
|
|
90
|
+
*
|
|
91
|
+
* Points whose symbols overlap the hovered one are listed in the same tooltip,
|
|
92
|
+
* closest first, so a cluster is readable without zooming in. Each point gets
|
|
93
|
+
* its own block: the series color sits once on the block title, and the rows
|
|
94
|
+
* are labelled with the axis `name` when the consumer set one, falling back to
|
|
95
|
+
* the dataset dimension name.
|
|
96
|
+
*/
|
|
97
|
+
function createScatterTooltipFormatter({ dataset, getChartInstance, getLegendSelected, series, seriesAxisNames, userOption }) {
|
|
98
|
+
const valueFormatter = getTooltipValueFormatter(userOption);
|
|
99
|
+
const radius = getScatterSymbolSize(series);
|
|
100
|
+
const seriesList = Array.isArray(series) ? series : [series];
|
|
101
|
+
const renderPoint = (point, key) => {
|
|
102
|
+
var _point$seriesIndex, _point$seriesIndex2, _axisNames$x, _axisNames$y;
|
|
103
|
+
const seriesOption = seriesList[(_point$seriesIndex = point.seriesIndex) !== null && _point$seriesIndex !== void 0 ? _point$seriesIndex : 0];
|
|
104
|
+
const swatchColor = typeof (seriesOption === null || seriesOption === void 0 ? void 0 : seriesOption.color) === "string" ? seriesOption.color : point.color;
|
|
105
|
+
const seriesEncode = seriesOption === null || seriesOption === void 0 ? void 0 : seriesOption.encode;
|
|
106
|
+
const titleRef = extraTooltipRefs(_objectSpread2(_objectSpread2({}, point), {}, { encode: _objectSpread2(_objectSpread2(_objectSpread2({}, point.encode), (seriesEncode === null || seriesEncode === void 0 ? void 0 : seriesEncode.tooltip) !== void 0 && { tooltip: seriesEncode.tooltip }), (seriesEncode === null || seriesEncode === void 0 ? void 0 : seriesEncode.itemName) !== void 0 && { itemName: seriesEncode.itemName }) }))[0];
|
|
107
|
+
const pointName = point.name !== void 0 && point.name !== "" ? point.name : point.seriesName;
|
|
108
|
+
const titleValue = titleRef !== void 0 ? readEncodedValue(point.value, titleRef, point.dimensionNames) : pointName;
|
|
109
|
+
const titleText = titleValue instanceof Date ? formatTimeAxisDate(titleValue) : typeof titleValue === "string" || typeof titleValue === "number" ? titleValue : void 0;
|
|
110
|
+
const refs = getEncodedAxisRefs(point.encode);
|
|
111
|
+
const xValue = readEncodedValue(point.value, refs.x, point.dimensionNames);
|
|
112
|
+
const yValue = readEncodedValue(point.value, refs.y, point.dimensionNames);
|
|
113
|
+
const axisNames = seriesAxisNames === null || seriesAxisNames === void 0 ? void 0 : seriesAxisNames[(_point$seriesIndex2 = point.seriesIndex) !== null && _point$seriesIndex2 !== void 0 ? _point$seriesIndex2 : 0];
|
|
114
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
115
|
+
className: "ndl-charts-chart-tooltip-point",
|
|
116
|
+
children: [
|
|
117
|
+
titleText !== void 0 && titleText !== "" && /* @__PURE__ */ jsx(ChartTooltip.Title, {
|
|
118
|
+
indentSquareColor: swatchColor,
|
|
119
|
+
children: titleText
|
|
120
|
+
}),
|
|
121
|
+
xValue !== void 0 && /* @__PURE__ */ jsx(ChartTooltip.Content, {
|
|
122
|
+
leadingElement: (_axisNames$x = axisNames === null || axisNames === void 0 ? void 0 : axisNames.x) !== null && _axisNames$x !== void 0 ? _axisNames$x : encodedDimensionLabel(refs.x, point.dimensionNames, "x"),
|
|
123
|
+
trailingElement: valueFormatter(xValue, point.dataIndex, { axis: "x" })
|
|
124
|
+
}),
|
|
125
|
+
yValue !== void 0 && /* @__PURE__ */ jsx(ChartTooltip.Content, {
|
|
126
|
+
leadingElement: (_axisNames$y = axisNames === null || axisNames === void 0 ? void 0 : axisNames.y) !== null && _axisNames$y !== void 0 ? _axisNames$y : encodedDimensionLabel(refs.y, point.dimensionNames, "y"),
|
|
127
|
+
trailingElement: valueFormatter(yValue, point.dataIndex, { axis: "y" })
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
}, key);
|
|
131
|
+
};
|
|
132
|
+
return function scatterTooltipFormatter(params) {
|
|
133
|
+
const hovered = Array.isArray(params) ? params[0] : params;
|
|
134
|
+
let points = [hovered];
|
|
135
|
+
try {
|
|
136
|
+
points = findNearbyScatterPoints({
|
|
137
|
+
chart: getChartInstance === null || getChartInstance === void 0 ? void 0 : getChartInstance(),
|
|
138
|
+
dataset,
|
|
139
|
+
hovered,
|
|
140
|
+
legendSelected: getLegendSelected === null || getLegendSelected === void 0 ? void 0 : getLegendSelected(),
|
|
141
|
+
maxPoints: MAX_TOOLTIP_POINTS,
|
|
142
|
+
radius,
|
|
143
|
+
series
|
|
144
|
+
});
|
|
145
|
+
} catch (_unused) {
|
|
146
|
+
points = [hovered];
|
|
147
|
+
}
|
|
148
|
+
return `${renderToString(/* @__PURE__ */ jsx("span", {
|
|
149
|
+
className: "ndl-charts-chart-tooltip",
|
|
150
|
+
children: points.map((point, index) => {
|
|
151
|
+
var _point$dataIndex;
|
|
152
|
+
return renderPoint(point, `${point.seriesIndex}-${(_point$dataIndex = point.dataIndex) !== null && _point$dataIndex !== void 0 ? _point$dataIndex : index}`);
|
|
153
|
+
})
|
|
154
|
+
}))}`;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export { createAxisTooltipFormatter, createScatterTooltipFormatter, getTooltipValueFormatter };
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=chart-tooltip-formatter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-tooltip-formatter.mjs","names":[],"sources":["../../../../src/charts/utils/chart-tooltip-formatter.tsx"],"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 React from 'react';\nimport { renderToString } from 'react-dom/server';\n\nimport { ChartTooltip } from '../ChartTooltip';\nimport type { ChartProps, EchartsSeries } from './chart-types';\nimport {\n capitalizeFirstLetter,\n extractValueFromTooltipSeries,\n formatTimeAxisDate,\n formatTooltipValue,\n} from './format-utils';\nimport {\n encodedDimensionLabel,\n extraTooltipRefs,\n findNearbyScatterPoints,\n getEncodedAxisRefs,\n getScatterSymbolSize,\n readEncodedValue,\n type ScatterTooltipChart,\n type ScatterTooltipPoint,\n} from './scatter-tooltip-points';\nimport { evaluateThresholdCondition } from './threshold';\nimport {\n getThresholdLineDisplayName,\n isThresholdLine,\n type NormalizedThresholdLine,\n} from './threshold';\n\n/**\n * Where a scatter tooltip value comes from. Passed to `tooltip.valueFormatter`\n * as its third argument for the x and y rows, so one formatter can give them\n * different units. The title is not passed to the formatter.\n */\nexport type TooltipValueContext = {\n axis: 'x' | 'y';\n};\n\ntype TooltipValueFormatter = (\n value: unknown,\n dataIndex?: number,\n context?: TooltipValueContext,\n) => React.ReactNode;\n\nexport function getTooltipValueFormatter(\n userOption: ChartProps['option'],\n): TooltipValueFormatter {\n if (\n typeof userOption?.tooltip === 'object' &&\n userOption.tooltip !== null &&\n 'valueFormatter' in userOption.tooltip\n ) {\n return userOption.tooltip.valueFormatter as TooltipValueFormatter;\n }\n\n return formatTooltipValue as TooltipValueFormatter;\n}\n\n/**\n * `name` of the x and y axes one series is bound to. `seriesAxisNames` holds\n * one entry per series, indexed by series index.\n */\nexport type SeriesAxisNames = {\n // oxlint-disable-next-line id-length\n x?: string;\n // oxlint-disable-next-line id-length\n y?: string;\n};\n\ntype CreateAxisTooltipFormatterParams = {\n thresholdLines: NormalizedThresholdLine[];\n userOption: ChartProps['option'];\n};\n\ntype CreateScatterTooltipFormatterParams = {\n dataset: ChartProps['dataset'];\n getChartInstance?: () => ScatterTooltipChart | undefined;\n getLegendSelected?: () => Record<string, boolean> | undefined;\n series: EchartsSeries;\n seriesAxisNames?: Array<SeriesAxisNames | undefined>;\n userOption: ChartProps['option'];\n};\n\n/**\n * Upper bound on the points one tooltip lists, so a dense cluster cannot grow\n * a tooltip that covers the chart.\n */\nconst MAX_TOOLTIP_POINTS = 5;\n\n/**\n * Builds the ECharts axis-tooltip formatter used by line-like charts.\n * It renders Needle tooltip markup and augments non-threshold series with\n * threshold notifications when their current value crosses a threshold line.\n */\nexport function createAxisTooltipFormatter({\n thresholdLines,\n userOption,\n}: CreateAxisTooltipFormatterParams) {\n const valueFormatter = getTooltipValueFormatter(userOption);\n\n return function axisTooltipFormatter(params: unknown) {\n const paramsArray = Array.isArray(params) ? params : [params];\n const firstParam = paramsArray[0];\n\n return `${renderToString(\n <span className=\"ndl-charts-chart-tooltip\">\n <ChartTooltip.Title>\n {firstParam?.axisValueLabel ?? ''}\n </ChartTooltip.Title>\n {paramsArray.map((series) => {\n const value = extractValueFromTooltipSeries(\n series.value,\n series.encode,\n series.axisDim,\n );\n\n const seriesValue = typeof value === 'number' ? value : Number(value);\n\n const isSeriesThresholdLine = isThresholdLine(series.seriesName);\n\n const notifications = thresholdLines.flatMap((threshold) => {\n if (isSeriesThresholdLine || Number.isNaN(seriesValue)) {\n return [];\n }\n\n const {\n notificationType,\n value: thresholdValue,\n condition,\n customConditionText,\n customCondition,\n } = threshold;\n const conditionEvaluation = customCondition\n ? {\n conditionText: customConditionText,\n isConditionMet: customCondition(seriesValue, thresholdValue),\n }\n : evaluateThresholdCondition(\n seriesValue,\n condition,\n thresholdValue,\n );\n\n if (!conditionEvaluation.isConditionMet) {\n return [];\n }\n\n return [\n {\n id: `threshold-${notificationType}`,\n leadingElement: customCondition\n ? conditionEvaluation.conditionText\n : `${conditionEvaluation.conditionText} threshold`,\n notificationType,\n trailingElement: valueFormatter(thresholdValue),\n },\n ];\n });\n\n return (\n <ChartTooltip.Content\n key={series.seriesName}\n leadingElement={\n isSeriesThresholdLine\n ? `${capitalizeFirstLetter(\n getThresholdLineDisplayName(series.seriesName),\n )} threshold`\n : series.seriesName\n }\n trailingElement={valueFormatter(value)}\n indentSquareColor={series.color}\n notifications={notifications}\n />\n );\n })}\n </span>,\n )}`;\n };\n}\n\n/**\n * Builds the ECharts item-tooltip formatter used by scatter charts.\n *\n * The title comes from ECharts `encode.tooltip`, then `encode.itemName`, then\n * an extra data dimension, and otherwise the series name. x and y are listed\n * underneath. See https://echarts.apache.org/en/option.html#series-scatter.encode\n *\n * `tooltip.valueFormatter` runs on the x and y values only. Those calls pass\n * `{ axis: 'x' | 'y' }` (`TooltipValueContext`) as the third argument. The\n * title is shown unchanged.\n *\n * Points whose symbols overlap the hovered one are listed in the same tooltip,\n * closest first, so a cluster is readable without zooming in. Each point gets\n * its own block: the series color sits once on the block title, and the rows\n * are labelled with the axis `name` when the consumer set one, falling back to\n * the dataset dimension name.\n */\nexport function createScatterTooltipFormatter({\n dataset,\n getChartInstance,\n getLegendSelected,\n series,\n seriesAxisNames,\n userOption,\n}: CreateScatterTooltipFormatterParams) {\n const valueFormatter = getTooltipValueFormatter(userOption);\n const radius = getScatterSymbolSize(series);\n const seriesList = Array.isArray(series) ? series : [series];\n\n const renderPoint = (point: ScatterTooltipPoint, key: string) => {\n // ECharts only copies x/y into the hovered point's `encode`. The dimension\n // the consumer set on `encode.tooltip` (or `itemName`) still lives on the\n // series option, which is what the nearby points are already read from.\n const seriesOption = seriesList[point.seriesIndex ?? 0] as\n | { color?: unknown; encode?: Record<string, unknown> }\n | undefined;\n // The hovered point's own color is its theme-colored interior. The swatch\n // uses the series color, which is the ring.\n const swatchColor =\n typeof seriesOption?.color === 'string'\n ? seriesOption.color\n : point.color;\n const seriesEncode = seriesOption?.encode;\n const titleRef = extraTooltipRefs({\n ...point,\n encode: {\n ...point.encode,\n ...(seriesEncode?.tooltip !== undefined && {\n tooltip: seriesEncode.tooltip,\n }),\n ...(seriesEncode?.itemName !== undefined && {\n itemName: seriesEncode.itemName,\n }),\n },\n })[0];\n // ECharts reports `name` as '' when a point has no name dimension, which\n // would hide the title and the color swatch. The series name fills that in.\n const pointName =\n point.name !== undefined && point.name !== ''\n ? point.name\n : point.seriesName;\n const titleValue =\n titleRef !== undefined\n ? readEncodedValue(point.value, titleRef, point.dimensionNames)\n : pointName;\n // The title identifies the point, so it is not run through\n // `valueFormatter`. Only string and number titles are renderable children,\n // so dates are formatted like the time axis.\n const titleText =\n titleValue instanceof Date\n ? formatTimeAxisDate(titleValue)\n : typeof titleValue === 'string' || typeof titleValue === 'number'\n ? titleValue\n : undefined;\n const refs = getEncodedAxisRefs(point.encode);\n const xValue = readEncodedValue(point.value, refs.x, point.dimensionNames);\n const yValue = readEncodedValue(point.value, refs.y, point.dimensionNames);\n const axisNames = seriesAxisNames?.[point.seriesIndex ?? 0];\n\n return (\n <div className=\"ndl-charts-chart-tooltip-point\" key={key}>\n {titleText !== undefined && titleText !== '' && (\n <ChartTooltip.Title indentSquareColor={swatchColor}>\n {titleText}\n </ChartTooltip.Title>\n )}\n {xValue !== undefined && (\n <ChartTooltip.Content\n leadingElement={\n axisNames?.x ??\n encodedDimensionLabel(refs.x, point.dimensionNames, 'x')\n }\n trailingElement={valueFormatter(xValue, point.dataIndex, {\n axis: 'x',\n })}\n />\n )}\n {yValue !== undefined && (\n <ChartTooltip.Content\n leadingElement={\n axisNames?.y ??\n encodedDimensionLabel(refs.y, point.dimensionNames, 'y')\n }\n trailingElement={valueFormatter(yValue, point.dataIndex, {\n axis: 'y',\n })}\n />\n )}\n </div>\n );\n };\n\n return function scatterTooltipFormatter(params: unknown) {\n const hovered = (\n Array.isArray(params) ? params[0] : params\n ) as ScatterTooltipPoint;\n\n let points = [hovered];\n\n // A tooltip that throws leaves the chart without any tooltip at all, so a\n // failed neighbor lookup falls back to the hovered point.\n try {\n points = findNearbyScatterPoints({\n chart: getChartInstance?.(),\n dataset,\n hovered,\n legendSelected: getLegendSelected?.(),\n maxPoints: MAX_TOOLTIP_POINTS,\n radius,\n series,\n });\n } catch {\n points = [hovered];\n }\n\n return `${renderToString(\n <span className=\"ndl-charts-chart-tooltip\">\n {points.map((point, index) =>\n renderPoint(\n point,\n `${point.seriesIndex}-${point.dataIndex ?? index}`,\n ),\n )}\n </span>,\n )}`;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,yBACd,YACuB;CACvB,IACE,QAAA,eAAA,QAAA,eAAA,KAAA,IAAA,KAAA,IAAO,WAAY,aAAY,YAC/B,WAAW,YAAY,QACvB,oBAAoB,WAAW,SAE/B,OAAO,WAAW,QAAQ;CAG5B,OAAO;AACT;;;;;AA+BA,MAAM,qBAAqB;;;;;;AAO3B,SAAgB,2BAA2B,EACzC,gBACA,cACmC;CACnC,MAAM,iBAAiB,yBAAyB,UAAU;CAE1D,OAAO,SAAS,qBAAqB,QAAiB;;EACpD,MAAM,cAAc,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;EAC5D,MAAM,aAAa,YAAY;EAE/B,OAAO,GAAG,eACR,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACE,oBAAC,aAAa,OAAd,EAAA,W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|
|
1
|
+
// src/charts/utils/chart-types.ts
|
|
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
|
+
export {};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=chart-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-types.mjs","names":[],"sources":["../../../../src/charts/utils/chart-types.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport {\n type EChartsOption,\n type LineSeriesOption,\n type RegisteredSeriesOption,\n type SetOptionOpts,\n} from 'echarts';\n\nexport type HexColor = `#${string}`;\n\nexport type Condition =\n | 'greater'\n | 'greaterOrEqual'\n | 'less'\n | 'lessOrEqual'\n | 'equal'\n | 'notEqual';\n\nexport type Values<T> = T[keyof T];\nexport type SeriesOption = Values<RegisteredSeriesOption>;\n\nexport type EchartsSeries = SeriesOption | SeriesOption[];\n\ntype CustomCondition = (\n lineValue: unknown,\n thresholdLineValue: unknown,\n) => boolean;\n\nexport interface ThresholdLineSeriesOption<\n T extends NotificationType,\n> extends Omit<LineSeriesOption, 'type'> {\n type: 'thresholdLine';\n yAxis: number;\n xAxis: [number, number];\n notificationType: T;\n color?: string;\n condition?: Condition;\n customConditionText?: string;\n customCondition?: CustomCondition;\n}\n\n// Only one threshold line of each type is allowed.\nexport type NeedleSeries =\n | [\n ThresholdLineSeriesOption<'warning'>,\n ThresholdLineSeriesOption<'danger'>,\n ...SeriesOption[],\n ]\n | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]]\n | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]]\n | SeriesOption[];\n\n/** The zoom window of one configured `dataZoom` component, as reported by `onZoom`. */\nexport type ChartZoomEntry = {\n id?: string | number;\n xAxisIndex?: number | number[] | false;\n yAxisIndex?: number | number[] | false;\n /** Percent, 0–100. */\n startPercent: number;\n /** Percent, 0–100. */\n endPercent: number;\n /** Data value; the category index on a category axis. */\n startValue?: number;\n /** Data value; the category index on a category axis. */\n endValue?: number;\n};\n\nexport interface ChartProps {\n /** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */\n dataset: EChartsOption['dataset'];\n /** The series configuration for the chart. Defines what data to display and how to display it. */\n series: NeedleSeries;\n /** X-axis configuration for the chart. */\n xAxis?: EChartsOption['xAxis'];\n /** Y-axis configuration for the chart. */\n yAxis?: EChartsOption['yAxis'];\n /** Legend configuration for the chart. */\n legend?: {\n /** Whether the legend is visible. */\n isVisible?: boolean;\n };\n /** Additional ECharts options to merge with the chart configuration. */\n option?: Omit<\n EChartsOption,\n 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'\n >;\n /** Custom CSS styles to apply to the chart container. */\n style?: React.CSSProperties;\n /**\n * Settings for how ECharts should update the chart. Defaults to replacing the\n * components the chart owns (`series`, `dataset`, axes, and similar) while\n * merging the rest, which drops data that disappeared without discarding the\n * ECharts components behind zoom interactions. Passing `notMerge: true`\n * re-creates those components on every update and breaks drag-to-zoom.\n */\n settings?: SetOptionOpts;\n /** Whether the chart is in a loading state. */\n isLoading?: boolean;\n /** Callback functions for chart interactions. */\n callbacks?: {\n /**\n * Called after every zoom change: slider or inside drag, drag-to-zoom and\n * the double-click reset. Only fires when `dataZoom` is configured; to\n * track drag-to-zoom on its own, add `dataZoom: [{ type: 'inside' }]`.\n *\n * `dataZoom` holds one entry per `dataZoom` component you configured, in\n * config order, so the values can be passed back as\n * `startValue`/`endValue` to restore the zoom. `id` and the axis indices\n * are copied from the config, so they are `undefined` when not set there.\n */\n onZoom?: (params: {\n // TODO v6: remove startValue and endValue\n /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].startValue` instead. */\n startValue: number;\n /** @deprecated Only reflects the first `dataZoom` entry, use `dataZoom[0].endValue` instead. */\n endValue: number;\n dataZoom: ChartZoomEntry[];\n }) => void;\n };\n /** Data zoom configuration for the chart. */\n dataZoom?: EChartsOption['dataZoom'];\n /** Whether the zoom in the chart is disabled */\n isChartZoomDisabled?: boolean;\n /** Custom color palette that overrides the default categorical colors. */\n palette?: HexColor[];\n}\n\nexport interface ChartEmptyProps {\n /** A text displayed to the user when the chart is empty. */\n message?: React.ReactNode;\n /** The type of chart. This is used to render the appropriate icon. */\n type?: 'line' | 'pie' | 'bar';\n /** Optional element (preferably a TextButton) that should provide the user with an action. */\n action?: React.ReactNode;\n}\n\n/**\n * Chart tooltip\n */\n\n/**\n * Client coordinates used to anchor a floating element at a fixed point (e.g.\n * the cursor position), instead of at an anchor element.\n */\ntype AnchorPosition = {\n // oxlint-disable-next-line id-length\n x: number;\n // oxlint-disable-next-line id-length\n y: number;\n};\n\nexport interface ChartTooltipProps {\n children: React.ReactNode;\n className?: string;\n isOpen?: boolean;\n style?: React.CSSProperties;\n anchorPosition?: AnchorPosition;\n ref?: React.Ref<HTMLDivElement>;\n}\n\nexport type NotificationType = 'warning' | 'danger';\n\nexport type Notification = {\n leadingElement: React.ReactNode;\n trailingElement: React.ReactNode;\n notificationType: NotificationType;\n id: string;\n};\n\nexport type ChartTooltipContentProps = {\n leadingElement?: React.ReactNode;\n trailingElement?: React.ReactNode;\n indentSquareColor?: string;\n notifications?: Notification[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\n/**\n * Legend\n */\nexport interface LegendItemProps {\n name: string;\n children: React.ReactNode;\n as?: 'button' | 'div';\n className?: string;\n color?: string;\n isSelected?: boolean;\n isDeselected?: boolean;\n onLegendItemClick?: () => void;\n hasButtons?: boolean;\n onLegendItemMouseEnter?: () => void;\n onLegendItemMouseLeave?: () => void;\n ref?: React.Ref<HTMLButtonElement> & React.Ref<HTMLDivElement>;\n}\n\nexport type LegendProps = {\n series: {\n name: string;\n color: string;\n }[];\n ref?: React.Ref<HTMLDivElement>;\n};\n\nexport type HtmlAttributes<T extends React.ElementType> =\n React.ComponentPropsWithoutRef<T> & {\n [key: `data-${string}`]: string | undefined;\n };\n\ntype BaseProps<T extends React.ElementType> = {\n /**\n * Additional classnames will be applied to the root element.\n */\n className?: string;\n /**\n * Additional css styling. Will be applied to the root element.\n */\n style?: React.CSSProperties;\n\n /**\n * Html attributes to apply to the root element. This will override any default html attributes, use with caution.\n */\n htmlAttributes?: HtmlAttributes<T>;\n\n /**\n * A ref to apply to the root element.\n */\n ref?: React.ComponentPropsWithRef<T>['ref'];\n};\n\nexport type CommonProps<T extends React.ElementType, P> = P & BaseProps<T>;\n"],"mappings":""}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/charts/utils/defaults.ts
|
|
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
|
+
const defaultThresholdLineSeriesOption = { condition: "greater" };
|
|
23
|
+
const tooltipMaxWidth = 400;
|
|
24
|
+
/**
|
|
25
|
+
* ECharts writes `white-space: nowrap` inline on the tooltip container, so a
|
|
26
|
+
* long series name or category label stretches the tooltip across the chart
|
|
27
|
+
* until the max width and normal wrapping override it. `overflow-wrap` is
|
|
28
|
+
* needed on top of that: the tooltip rows are flex items, and only `anywhere`
|
|
29
|
+
* lets their min-content size drop below the longest word.
|
|
30
|
+
*/
|
|
31
|
+
const tooltipExtraCssText = [
|
|
32
|
+
"box-shadow: none",
|
|
33
|
+
"background-color: transparent",
|
|
34
|
+
`max-width: 400px`,
|
|
35
|
+
"white-space: normal",
|
|
36
|
+
"overflow-wrap: anywhere"
|
|
37
|
+
].join("; ");
|
|
38
|
+
/**
|
|
39
|
+
* ECharts component main types that `buildChartOption` always writes in full,
|
|
40
|
+
* so replacing them gives the same "drop what disappeared" behavior as
|
|
41
|
+
* `notMerge`. Every entry has to be a registered component main type, which is
|
|
42
|
+
* only asserted by ECharts in development builds.
|
|
43
|
+
*
|
|
44
|
+
* `toolbox` is deliberately absent: it has to keep its view instance across
|
|
45
|
+
* updates, see `defaultChartSettings`.
|
|
46
|
+
*/
|
|
47
|
+
const needleOwnedComponents = [
|
|
48
|
+
"dataZoom",
|
|
49
|
+
"dataset",
|
|
50
|
+
"grid",
|
|
51
|
+
"legend",
|
|
52
|
+
"series",
|
|
53
|
+
"tooltip",
|
|
54
|
+
"xAxis",
|
|
55
|
+
"yAxis"
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* `notMerge` rebuilds every component view on each `setOption`. That makes
|
|
59
|
+
* ECharts mount a fresh toolbox brush controller while the previous one stays
|
|
60
|
+
* attached to the renderer, because `ToolboxView.dispose` iterates its feature
|
|
61
|
+
* map with `zrUtil.each` and so never disposes anything. Every leftover
|
|
62
|
+
* controller then re-applies the same drag, each time against an axis the
|
|
63
|
+
* previous one already zoomed, which shrinks the selected range.
|
|
64
|
+
*/
|
|
65
|
+
const defaultChartSettings = {
|
|
66
|
+
lazyUpdate: false,
|
|
67
|
+
notMerge: false,
|
|
68
|
+
replaceMerge: needleOwnedComponents,
|
|
69
|
+
silent: false
|
|
70
|
+
};
|
|
71
|
+
export { defaultChartSettings, defaultThresholdLineSeriesOption, needleOwnedComponents, tooltipExtraCssText, tooltipMaxWidth };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=defaults.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.mjs","names":[],"sources":["../../../../src/charts/utils/defaults.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { ChartProps, Condition } from './chart-types';\n\nconst defaultThresholdLineSeriesOption: {\n condition: Condition;\n} = {\n condition: 'greater',\n};\n\nconst tooltipMaxWidth = 400;\n\n/**\n * ECharts writes `white-space: nowrap` inline on the tooltip container, so a\n * long series name or category label stretches the tooltip across the chart\n * until the max width and normal wrapping override it. `overflow-wrap` is\n * needed on top of that: the tooltip rows are flex items, and only `anywhere`\n * lets their min-content size drop below the longest word.\n */\nconst tooltipExtraCssText = [\n 'box-shadow: none',\n 'background-color: transparent',\n `max-width: ${tooltipMaxWidth}px`,\n 'white-space: normal',\n 'overflow-wrap: anywhere',\n].join('; ');\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 tooltipExtraCssText,\n tooltipMaxWidth,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,mCAEF,EACF,WAAW,UACb;AAEA,MAAM,kBAAkB;;;;;;;;AASxB,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWX,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAUA,MAAM,uBAA4D;CAChE,YAAY;CACZ,UAAU;CACV,cAAc;CACd,QAAQ;AACV"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { time } from "echarts";
|
|
2
|
+
// src/charts/utils/format-utils.ts
|
|
3
|
+
/*!
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) "Neo4j"
|
|
6
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Neo4j.
|
|
9
|
+
*
|
|
10
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
*/
|
|
23
|
+
const capitalizeFirstLetter = (str) => {
|
|
24
|
+
if (!str) return str;
|
|
25
|
+
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
26
|
+
};
|
|
27
|
+
const enUSNumberFormatter = new Intl.NumberFormat("en-US");
|
|
28
|
+
/**
|
|
29
|
+
* Formats finite number values with en-US separators and returns all other
|
|
30
|
+
* values unchanged.
|
|
31
|
+
*/
|
|
32
|
+
const formatNumberEnUS = (value) => {
|
|
33
|
+
if (typeof value === "number") return Number.isFinite(value) ? enUSNumberFormatter.format(value) : value;
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Formats a date the way ECharts labels a time axis, so tooltips match it.
|
|
38
|
+
*/
|
|
39
|
+
const formatTimeAxisDate = (date) => time.format(date, "{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}", false);
|
|
40
|
+
/**
|
|
41
|
+
* Default tooltip formatting. Numbers get en-US separators and dates use
|
|
42
|
+
* `formatTimeAxisDate`. Other values are returned unchanged.
|
|
43
|
+
*/
|
|
44
|
+
const formatTooltipValue = (value) => {
|
|
45
|
+
if (value instanceof Date) return formatTimeAxisDate(value);
|
|
46
|
+
return formatNumberEnUS(value);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Extract the tooltip value from the series depending on the axisDim and encode properties
|
|
50
|
+
* If the value is a single value, return it as it is
|
|
51
|
+
* If the encode property does not exist fallback to 1
|
|
52
|
+
*/
|
|
53
|
+
const extractValueFromTooltipSeries = (value, encode, axisDim = "x") => {
|
|
54
|
+
var _encode$x, _value$seriesValueIdx;
|
|
55
|
+
if (!Array.isArray(value)) return value;
|
|
56
|
+
const encodeValueToRead = axisDim === "x" ? encode === null || encode === void 0 ? void 0 : encode.y : (_encode$x = encode === null || encode === void 0 ? void 0 : encode.x) !== null && _encode$x !== void 0 ? _encode$x : 1;
|
|
57
|
+
return (_value$seriesValueIdx = value[Array.isArray(encodeValueToRead) ? encodeValueToRead[0] : encodeValueToRead]) !== null && _value$seriesValueIdx !== void 0 ? _value$seriesValueIdx : value;
|
|
58
|
+
};
|
|
59
|
+
export { capitalizeFirstLetter, extractValueFromTooltipSeries, formatNumberEnUS, formatTimeAxisDate, formatTooltipValue };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=format-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-utils.mjs","names":[],"sources":["../../../../src/charts/utils/format-utils.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { time } from 'echarts';\n\nconst capitalizeFirstLetter = (str: string) => {\n if (!str) {\n return str;\n }\n return str.charAt(0).toUpperCase() + str.substring(1);\n};\n\nconst enUSNumberFormatter = new Intl.NumberFormat('en-US');\n\n/**\n * Formats finite number values with en-US separators and returns all other\n * values unchanged.\n */\nconst formatNumberEnUS = <T>(value: T): string | T => {\n if (typeof value === 'number') {\n return Number.isFinite(value) ? enUSNumberFormatter.format(value) : value;\n }\n\n return value;\n};\n\n/**\n * Formats a date the way ECharts labels a time axis, so tooltips match it.\n */\nconst formatTimeAxisDate = (date: Date) =>\n time.format(date, '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}', false);\n\n/**\n * Default tooltip formatting. Numbers get en-US separators and dates use\n * `formatTimeAxisDate`. Other values are returned unchanged.\n */\nconst formatTooltipValue = <T>(value: T): string | T => {\n if (value instanceof Date) {\n return formatTimeAxisDate(value);\n }\n\n return formatNumberEnUS(value);\n};\n\n/**\n * Extract the tooltip value from the series depending on the axisDim and encode properties\n * If the value is a single value, return it as it is\n * If the encode property does not exist fallback to 1\n */\nconst extractValueFromTooltipSeries = (\n value: string | number | (number | string)[],\n encode: {\n // E-Charts uses encode.x and encode.y - https://echarts.apache.org/en/option.html#series-line.encode\n // oxlint-disable-next-line id-length\n x: number | number[];\n // oxlint-disable-next-line id-length\n y: number | number[];\n },\n // We currently only support x and y axes\n axisDim: 'x' | 'y' | 'angle' | 'radius' | 'single' = 'x',\n) => {\n if (!Array.isArray(value)) {\n return value;\n }\n\n // The axisDim is the axis that the tooltip was triggered on,\n // if it was triggered on the x axis the value should be read from the y axis and vice versa\n const encodeValueToRead = axisDim === 'x' ? encode?.y : (encode?.x ?? 1);\n\n const seriesValueIdx = Array.isArray(encodeValueToRead)\n ? encodeValueToRead[0]\n : encodeValueToRead;\n\n return value[seriesValueIdx] ?? value;\n};\n\nexport {\n capitalizeFirstLetter,\n extractValueFromTooltipSeries,\n formatNumberEnUS,\n formatTimeAxisDate,\n formatTooltipValue,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,yBAAyB,QAAgB;CAC7C,IAAI,CAAC,KACH,OAAO;CAET,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,IAAI,UAAU,CAAC;AACtD;AAEA,MAAM,sBAAsB,IAAI,KAAK,aAAa,OAAO;;;;;AAMzD,MAAM,oBAAuB,UAAyB;CACpD,IAAI,OAAO,UAAU,UACnB,OAAO,OAAO,SAAS,KAAK,IAAI,oBAAoB,OAAO,KAAK,IAAI;CAGtE,OAAO;AACT;;;;AAKA,MAAM,sBAAsB,SAC1B,KAAK,OAAO,MAAM,mCAAmC,KAAK;;;;;AAM5D,MAAM,sBAAyB,UAAyB;CACtD,IAAI,iBAAiB,MACnB,OAAO,mBAAmB,KAAK;CAGjC,OAAO,iBAAiB,KAAK;AAC/B;;;;;;AAOA,MAAM,iCACJ,OACA,QAQA,UAAqD,QAClD;;CACH,IAAI,CAAC,MAAM,QAAQ,KAAK,GACtB,OAAO;CAKT,MAAM,oBAAoB,YAAY,MAAA,WAAA,QAAA,WAAA,KAAA,IAAA,KAAA,IAAM,OAAQ,KAAA,YAAA,WAAA,QAAA,WAAA,KAAA,IAAA,KAAA,IAAK,OAAQ,OAAA,QAAA,cAAA,KAAA,IAAA,YAAK;CAMtE,QAAA,wBAAO,MAJgB,MAAM,QAAQ,iBAAiB,IAClD,kBAAkB,KAClB,wBAAA,QAAA,0BAAA,KAAA,IAAA,wBAE4B;AAClC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/charts/utils/legend-layout.ts
|
|
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
|
+
const COLLAPSED_LEGEND_ROWS = 2;
|
|
23
|
+
const COLLAPSED_LEGEND_MAX_HEIGHT = 64;
|
|
24
|
+
/**
|
|
25
|
+
* Get the computed element width, including both paddings and margins
|
|
26
|
+
*/
|
|
27
|
+
const getComputedElementWidth = (element) => {
|
|
28
|
+
const elementRect = element.getBoundingClientRect();
|
|
29
|
+
const elementComputedStyle = window.getComputedStyle(element);
|
|
30
|
+
const elementMarginLeft = parseFloat(elementComputedStyle.marginLeft);
|
|
31
|
+
const elementMarginRight = parseFloat(elementComputedStyle.marginRight);
|
|
32
|
+
return elementRect.width + elementMarginLeft + elementMarginRight;
|
|
33
|
+
};
|
|
34
|
+
const getItemCountThatFitsRow = (itemWidths, availableWidth, { keepOversizedFirstItem = true } = {}) => {
|
|
35
|
+
let rowWidth = 0;
|
|
36
|
+
let count = 0;
|
|
37
|
+
for (const itemWidth of itemWidths) {
|
|
38
|
+
if (count === 0 && itemWidth > availableWidth) return keepOversizedFirstItem ? 1 : 0;
|
|
39
|
+
if (rowWidth + itemWidth > availableWidth) return count;
|
|
40
|
+
rowWidth += itemWidth;
|
|
41
|
+
count += 1;
|
|
42
|
+
}
|
|
43
|
+
return count;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Calculates how many legend items fit in the two-row collapsed layout.
|
|
47
|
+
*
|
|
48
|
+
* The second row reserves space for the "View more" action so that control
|
|
49
|
+
* remains visible at the end of the collapsed legend.
|
|
50
|
+
*/
|
|
51
|
+
const getCollapsedVisibleItemCount = (itemWidths, availableRowWidth, viewMoreButtonWidth) => {
|
|
52
|
+
const firstRowItemCount = getItemCountThatFitsRow(itemWidths, availableRowWidth);
|
|
53
|
+
return firstRowItemCount + getItemCountThatFitsRow(itemWidths.slice(firstRowItemCount), availableRowWidth - viewMoreButtonWidth, { keepOversizedFirstItem: false });
|
|
54
|
+
};
|
|
55
|
+
export { COLLAPSED_LEGEND_MAX_HEIGHT, COLLAPSED_LEGEND_ROWS, getCollapsedVisibleItemCount, getComputedElementWidth, getItemCountThatFitsRow };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=legend-layout.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend-layout.mjs","names":[],"sources":["../../../../src/charts/utils/legend-layout.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport const COLLAPSED_LEGEND_ROWS = 2;\nexport const COLLAPSED_LEGEND_MAX_HEIGHT = 64;\n\n/**\n * Get the computed element width, including both paddings and margins\n */\nexport const getComputedElementWidth = (element: Element) => {\n const elementRect = element.getBoundingClientRect();\n const elementComputedStyle = window.getComputedStyle(element);\n const elementMarginLeft = parseFloat(elementComputedStyle.marginLeft);\n const elementMarginRight = parseFloat(elementComputedStyle.marginRight);\n\n return elementRect.width + elementMarginLeft + elementMarginRight;\n};\n\nexport const getItemCountThatFitsRow = (\n itemWidths: number[],\n availableWidth: number,\n { keepOversizedFirstItem = true } = {},\n) => {\n let rowWidth = 0;\n let count = 0;\n\n for (const itemWidth of itemWidths) {\n if (count === 0 && itemWidth > availableWidth) {\n return keepOversizedFirstItem ? 1 : 0;\n }\n\n if (rowWidth + itemWidth > availableWidth) {\n return count;\n }\n\n rowWidth += itemWidth;\n count += 1;\n }\n\n return count;\n};\n\n/**\n * Calculates how many legend items fit in the two-row collapsed layout.\n *\n * The second row reserves space for the \"View more\" action so that control\n * remains visible at the end of the collapsed legend.\n */\nexport const getCollapsedVisibleItemCount = (\n itemWidths: number[],\n availableRowWidth: number,\n viewMoreButtonWidth: number,\n) => {\n const firstRowItemCount = getItemCountThatFitsRow(\n itemWidths,\n availableRowWidth,\n );\n const secondRowItemCount = getItemCountThatFitsRow(\n itemWidths.slice(firstRowItemCount),\n availableRowWidth - viewMoreButtonWidth,\n { keepOversizedFirstItem: false },\n );\n\n return firstRowItemCount + secondRowItemCount;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,wBAAwB;AACrC,MAAa,8BAA8B;;;;AAK3C,MAAa,2BAA2B,YAAqB;CAC3D,MAAM,cAAc,QAAQ,sBAAsB;CAClD,MAAM,uBAAuB,OAAO,iBAAiB,OAAO;CAC5D,MAAM,oBAAoB,WAAW,qBAAqB,UAAU;CACpE,MAAM,qBAAqB,WAAW,qBAAqB,WAAW;CAEtE,OAAO,YAAY,QAAQ,oBAAoB;AACjD;AAEA,MAAa,2BACX,YACA,gBACA,EAAE,yBAAyB,SAAS,CAAC,MAClC;CACH,IAAI,WAAW;CACf,IAAI,QAAQ;CAEZ,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,UAAU,KAAK,YAAY,gBAC7B,OAAO,yBAAyB,IAAI;EAGtC,IAAI,WAAW,YAAY,gBACzB,OAAO;EAGT,YAAY;EACZ,SAAS;CACX;CAEA,OAAO;AACT;;;;;;;AAQA,MAAa,gCACX,YACA,mBACA,wBACG;CACH,MAAM,oBAAoB,wBACxB,YACA,iBACF;CAOA,OAAO,oBANoB,wBACzB,WAAW,MAAM,iBAAiB,GAClC,oBAAoB,qBACpB,EAAE,wBAAwB,MAAM,CAGU;AAC9C"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs";
|
|
2
|
+
import { getInstanceByDom } from "echarts";
|
|
3
|
+
// src/charts/utils/legend-utils.ts
|
|
4
|
+
/*!
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) "Neo4j"
|
|
7
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
8
|
+
*
|
|
9
|
+
* This file is part of Neo4j.
|
|
10
|
+
*
|
|
11
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* This program is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU General Public License
|
|
22
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
*/
|
|
24
|
+
const resetAllSeriesHighlight = (chart) => {
|
|
25
|
+
(chart.getOption().series || []).forEach((_series, seriesIndex) => {
|
|
26
|
+
chart.dispatchAction({
|
|
27
|
+
seriesIndex,
|
|
28
|
+
type: "downplay"
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const highlightOrDownplayLineAndBarSeries = (chart, currentSeriesToDispatch, action, currentChartOptions) => {
|
|
33
|
+
var _allChartOptionSeries;
|
|
34
|
+
const isDownplay = action === "downplay";
|
|
35
|
+
const allChartOptionSeries = (currentChartOptions === null || currentChartOptions === void 0 ? void 0 : currentChartOptions.series) || [];
|
|
36
|
+
chart === null || chart === void 0 || chart.setOption({ series: allChartOptionSeries === null || allChartOptionSeries === void 0 ? void 0 : allChartOptionSeries.map((seriesItem) => seriesItem.type === "scatter" ? seriesItem : _objectSpread2(_objectSpread2({}, seriesItem), {}, { emphasis: _objectSpread2(_objectSpread2({}, seriesItem.emphasis), {}, { disabled: isDownplay }) })) });
|
|
37
|
+
const seriesWithSeriesIndex = allChartOptionSeries === null || allChartOptionSeries === void 0 || (_allChartOptionSeries = allChartOptionSeries.map((seriesItem, index) => _objectSpread2(_objectSpread2({}, seriesItem), {}, { seriesIndex: index }))) === null || _allChartOptionSeries === void 0 ? void 0 : _allChartOptionSeries.filter((seriesItem) => currentSeriesToDispatch.some((series) => series.name === seriesItem.name));
|
|
38
|
+
if (!seriesWithSeriesIndex.length) return;
|
|
39
|
+
chart === null || chart === void 0 || chart.dispatchAction({
|
|
40
|
+
seriesIndex: seriesWithSeriesIndex.map((series) => series.seriesIndex),
|
|
41
|
+
type: action
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Highlight or downplay pie chart dataset item
|
|
46
|
+
*/
|
|
47
|
+
const highlightOrDownplayPieSlices = (chart, currentSeriesToDispatch, action, currentChartOptions) => {
|
|
48
|
+
var _datasetArray$;
|
|
49
|
+
const isDownplay = action === "downplay";
|
|
50
|
+
const allChartOptionSeries = (currentChartOptions === null || currentChartOptions === void 0 ? void 0 : currentChartOptions.series) || [];
|
|
51
|
+
chart === null || chart === void 0 || chart.setOption({ series: allChartOptionSeries === null || allChartOptionSeries === void 0 ? void 0 : allChartOptionSeries.map((seriesItem) => _objectSpread2(_objectSpread2({}, seriesItem), {}, { blur: {
|
|
52
|
+
itemStyle: { opacity: isDownplay ? 1 : .3 },
|
|
53
|
+
label: { opacity: isDownplay ? 1 : .3 }
|
|
54
|
+
} })) });
|
|
55
|
+
const chartOptionDataset = currentChartOptions === null || currentChartOptions === void 0 ? void 0 : currentChartOptions.dataset;
|
|
56
|
+
const datasetArray = Array.isArray(chartOptionDataset) ? chartOptionDataset : [chartOptionDataset];
|
|
57
|
+
const sourceArray = datasetArray === null || datasetArray === void 0 || (_datasetArray$ = datasetArray[0]) === null || _datasetArray$ === void 0 ? void 0 : _datasetArray$.source;
|
|
58
|
+
const currentDataSeriesIndexes = currentSeriesToDispatch.map((series) => {
|
|
59
|
+
return (sourceArray === null || sourceArray === void 0 ? void 0 : sourceArray.findIndex((item) => item[0] === series.name)) - 1;
|
|
60
|
+
});
|
|
61
|
+
if (action === "highlight") {
|
|
62
|
+
const otherSeriesIndexes = sourceArray.map((_row, index) => index).filter((dataIndex) => !currentDataSeriesIndexes.includes(dataIndex));
|
|
63
|
+
chart === null || chart === void 0 || chart.dispatchAction({
|
|
64
|
+
dataIndex: otherSeriesIndexes,
|
|
65
|
+
seriesIndex: [0],
|
|
66
|
+
type: "downplay"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
chart === null || chart === void 0 || chart.dispatchAction({
|
|
70
|
+
dataIndex: currentDataSeriesIndexes,
|
|
71
|
+
seriesIndex: [0],
|
|
72
|
+
type: action
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Highlight or downplay the series in the chart to toggle between emphasized and non-emphasized state
|
|
77
|
+
*/
|
|
78
|
+
const highlightOrDownplaySeries = (chartRef, series, currentSelectedSeries, currentSeriesToDispatch, action) => {
|
|
79
|
+
var _ref;
|
|
80
|
+
const hasOnlyOneSeries = series.length === 1;
|
|
81
|
+
if (Object.values(currentSelectedSeries).filter(Boolean).length === 1 || currentSeriesToDispatch.length === 0 || chartRef.current === null || hasOnlyOneSeries) return;
|
|
82
|
+
const chart = getInstanceByDom(chartRef.current);
|
|
83
|
+
if (!chart) return;
|
|
84
|
+
const currentChartOptions = chart.getOption();
|
|
85
|
+
if ((currentChartOptions === null || currentChartOptions === void 0 || (_ref = currentChartOptions.series) === null || _ref === void 0 || (_ref = _ref[0]) === null || _ref === void 0 ? void 0 : _ref.type) === "pie") highlightOrDownplayPieSlices(chart, currentSeriesToDispatch, action, currentChartOptions);
|
|
86
|
+
else highlightOrDownplayLineAndBarSeries(chart, currentSeriesToDispatch, action, currentChartOptions);
|
|
87
|
+
};
|
|
88
|
+
export { highlightOrDownplaySeries, resetAllSeriesHighlight };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=legend-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend-utils.mjs","names":[],"sources":["../../../../src/charts/utils/legend-utils.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport {\n type EChartsOption,\n type EChartsType,\n getInstanceByDom,\n} from 'echarts';\n\nexport const resetAllSeriesHighlight = (chart: EChartsType) => {\n const option = chart.getOption();\n const seriesList = (option.series as unknown[] | undefined) || [];\n\n seriesList.forEach((_series, seriesIndex: number) => {\n chart.dispatchAction({\n seriesIndex,\n type: 'downplay',\n });\n });\n};\n\nconst highlightOrDownplayLineAndBarSeries = (\n chart: EChartsType,\n currentSeriesToDispatch: { name: string; color: string }[],\n action: 'highlight' | 'downplay',\n currentChartOptions: ReturnType<EChartsType['getOption']>,\n) => {\n const isDownplay = action === 'downplay';\n const allChartOptionSeries =\n (currentChartOptions?.series as Record<string, unknown>[] | undefined) ||\n [];\n\n // Change emphasis state to add opacity on the non highlighted items.\n // Scatter keeps emphasis enabled: that state is what fills the circle when\n // a point is hovered, and disabling it on legend mouse-leave would turn the\n // fill off too.\n chart?.setOption({\n series: allChartOptionSeries?.map((seriesItem: Record<string, unknown>) =>\n seriesItem.type === 'scatter'\n ? seriesItem\n : {\n ...seriesItem,\n emphasis: {\n ...(seriesItem.emphasis as Record<string, unknown>),\n disabled: isDownplay,\n },\n },\n ),\n });\n\n const seriesWithSeriesIndex = allChartOptionSeries\n // Since the series index does not exist in the data we extract it from the series index\n ?.map((seriesItem, index) => ({\n ...seriesItem,\n seriesIndex: index,\n }))\n // Select the series that are in the currentSeriesToDispatch array\n ?.filter((seriesItem: Record<string, unknown>) =>\n currentSeriesToDispatch.some((series) => series.name === seriesItem.name),\n );\n\n if (!seriesWithSeriesIndex.length) {\n return;\n }\n\n chart?.dispatchAction({\n seriesIndex: seriesWithSeriesIndex.map((series) => series.seriesIndex),\n type: action,\n });\n};\n\n/**\n * Highlight or downplay pie chart dataset item\n */\nconst highlightOrDownplayPieSlices = (\n chart: EChartsType,\n currentSeriesToDispatch: { name: string; color: string }[],\n action: 'highlight' | 'downplay',\n currentChartOptions: ReturnType<EChartsType['getOption']>,\n) => {\n const isDownplay = action === 'downplay';\n const allChartOptionSeries =\n (currentChartOptions?.series as Record<string, unknown>[] | undefined) ||\n [];\n\n // Change blur state to add opacity on the non highlighted items in the pie chart\n chart?.setOption({\n series: allChartOptionSeries?.map(\n (seriesItem: Record<string, unknown>) => ({\n ...seriesItem,\n blur: {\n itemStyle: {\n opacity: isDownplay ? 1 : 0.3,\n },\n label: {\n opacity: isDownplay ? 1 : 0.3,\n },\n },\n }),\n ),\n });\n\n // The dataIndex that we want to dispatch can be found in the dataset[0] source array, where the first item is the name of the series\n const chartOptionDataset =\n currentChartOptions?.dataset as EChartsOption['dataset'];\n const datasetArray = Array.isArray(chartOptionDataset)\n ? chartOptionDataset\n : [chartOptionDataset];\n const sourceArray = datasetArray?.[0]?.source as unknown[][];\n\n // Find the dataIndexes that we want to dispatch\n const currentDataSeriesIndexes = currentSeriesToDispatch.map((series) => {\n const index = sourceArray?.findIndex((item) => item[0] === series.name) - 1;\n return index;\n });\n\n if (action === 'highlight') {\n // Downplay other data indexes to make sure the other slices are not highlighted\n const otherSeriesIndexes = sourceArray\n .map((_row, index) => index)\n .filter((dataIndex) => !currentDataSeriesIndexes.includes(dataIndex));\n\n chart?.dispatchAction({\n dataIndex: otherSeriesIndexes,\n seriesIndex: [0], // pie charts only has one series so seriesIndex is always 0\n type: 'downplay',\n });\n }\n\n chart?.dispatchAction({\n dataIndex: currentDataSeriesIndexes,\n seriesIndex: [0], // pie charts only has one series so otherSeriesIndexes is always 0\n type: action,\n });\n};\n\n/**\n * Highlight or downplay the series in the chart to toggle between emphasized and non-emphasized state\n */\nconst highlightOrDownplaySeries = (\n chartRef: React.RefObject<HTMLDivElement | null>,\n series: { name: string; color: string }[],\n currentSelectedSeries: Record<string, boolean>,\n currentSeriesToDispatch: { name: string; color: string }[],\n action: 'highlight' | 'downplay',\n) => {\n const hasOnlyOneSeries = series.length === 1;\n\n const isOnlyOneSeriesSelected =\n Object.values(currentSelectedSeries).filter(Boolean).length === 1;\n\n if (\n isOnlyOneSeriesSelected ||\n currentSeriesToDispatch.length === 0 ||\n chartRef.current === null ||\n hasOnlyOneSeries\n ) {\n return;\n }\n\n const chart = getInstanceByDom(chartRef.current);\n\n if (!chart) {\n return;\n }\n const currentChartOptions = chart.getOption();\n\n const seriesType = (\n currentChartOptions?.series as Record<string, unknown>[]\n )?.[0]?.type;\n\n if (seriesType === 'pie') {\n highlightOrDownplayPieSlices(\n chart,\n currentSeriesToDispatch,\n action,\n currentChartOptions,\n );\n } else {\n highlightOrDownplayLineAndBarSeries(\n chart,\n currentSeriesToDispatch,\n action,\n currentChartOptions,\n );\n }\n};\n\nexport { highlightOrDownplaySeries };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,2BAA2B,UAAuB;CAI7D,CAHe,MAAM,UACI,CAAC,CAAC,UAAoC,CAAC,EAAA,CAErD,SAAS,SAAS,gBAAwB;EACnD,MAAM,eAAe;GACnB;GACA,MAAM;EACR,CAAC;CACH,CAAC;AACH;AAEA,MAAM,uCACJ,OACA,yBACA,QACA,wBACG;;CACH,MAAM,aAAa,WAAW;CAC9B,MAAM,wBAAA,wBAAA,QAAA,wBAAA,KAAA,IAAA,KAAA,IACH,oBAAqB,WACtB,CAAC;CAMH,UAAA,QAAA,UAAA,KAAA,KAAA,MAAO,UAAU,EACf,QAAA,yBAAA,QAAA,yBAAA,KAAA,IAAA,KAAA,IAAQ,qBAAsB,KAAK,eACjC,WAAW,SAAS,YAChB,aAAA,eAAA,eAAA,CAAA,GAEK,UAAA,GAAA,CAAA,GAAA,EACH,UAAA,eAAA,eAAA,CAAA,GACM,WAAW,QAAA,GAAA,CAAA,GAAA,EACf,UAAU,WAAA,CACZ,EAAA,CACF,CACN,EACF,CAAC;CAED,MAAM,wBAAA,yBAAA,QAAA,yBAAA,KAAA,MAAA,wBAAwB,qBAE1B,KAAK,YAAY,UAAA,eAAA,eAAA,CAAA,GACd,UAAA,GAAA,CAAA,GAAA,EACH,aAAa,MAAA,CACf,CAAE,OAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAEA,QAAQ,eACR,wBAAwB,MA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