@wavemaker/react-native-echarts 1.0.0-dev.4 → 1.0.0-dev.8
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/README.md +211 -39
- package/area/area-chart.d.ts +1 -1
- package/area/area-chart.d.ts.map +1 -1
- package/area/area-chart.js +48 -23
- package/area/area-chart.props.d.ts +4 -0
- package/area/area-chart.props.d.ts.map +1 -1
- package/area/index.d.ts +1 -1
- package/area/index.d.ts.map +1 -1
- package/bubble/bubble-chart.d.ts.map +1 -1
- package/bubble/bubble-chart.js +50 -31
- package/cartesian/tooltip/axis-tooltip-presets.d.ts +5 -0
- package/cartesian/tooltip/axis-tooltip-presets.d.ts.map +1 -0
- package/cartesian/tooltip/axis-tooltip-presets.js +46 -0
- package/cartesian/tooltip/axis-tooltip.types.d.ts +38 -0
- package/cartesian/tooltip/axis-tooltip.types.d.ts.map +1 -0
- package/cartesian/tooltip/axis-tooltip.types.js +4 -0
- package/cartesian/tooltip/axis-tooltip.utils.d.ts +10 -0
- package/cartesian/tooltip/axis-tooltip.utils.d.ts.map +1 -0
- package/cartesian/tooltip/axis-tooltip.utils.js +121 -0
- package/cartesian/tooltip/default-axis-tooltip.d.ts +9 -0
- package/cartesian/tooltip/default-axis-tooltip.d.ts.map +1 -0
- package/cartesian/tooltip/default-axis-tooltip.js +53 -0
- package/cartesian/tooltip/index.d.ts +7 -0
- package/cartesian/tooltip/index.d.ts.map +1 -0
- package/cartesian/tooltip/index.js +4 -0
- package/cartesian/tooltip/use-axis-tooltip.d.ts +38 -0
- package/cartesian/tooltip/use-axis-tooltip.d.ts.map +1 -0
- package/cartesian/tooltip/use-axis-tooltip.js +54 -0
- package/column/column-chart.d.ts.map +1 -1
- package/column/column-chart.js +73 -20
- package/geo/geo-chart.d.ts.map +1 -1
- package/geo/geo-chart.js +56 -24
- package/geo/geo-chart.props.d.ts +11 -5
- package/geo/geo-chart.props.d.ts.map +1 -1
- package/geo/index.d.ts +1 -0
- package/geo/index.d.ts.map +1 -1
- package/geo/index.js +1 -0
- package/geo/tooltip/default-geo-tooltip.d.ts +6 -0
- package/geo/tooltip/default-geo-tooltip.d.ts.map +1 -0
- package/geo/tooltip/default-geo-tooltip.js +47 -0
- package/geo/tooltip/geo-item-tooltip-presets.d.ts +5 -0
- package/geo/tooltip/geo-item-tooltip-presets.d.ts.map +1 -0
- package/geo/tooltip/geo-item-tooltip-presets.js +35 -0
- package/geo/tooltip/geo-item-tooltip.types.d.ts +19 -0
- package/geo/tooltip/geo-item-tooltip.types.d.ts.map +1 -0
- package/geo/tooltip/geo-item-tooltip.types.js +3 -0
- package/geo/tooltip/geo-item-tooltip.utils.d.ts +14 -0
- package/geo/tooltip/geo-item-tooltip.utils.d.ts.map +1 -0
- package/geo/tooltip/geo-item-tooltip.utils.js +220 -0
- package/geo/tooltip/index.d.ts +7 -0
- package/geo/tooltip/index.d.ts.map +1 -0
- package/geo/tooltip/index.js +4 -0
- package/geo/tooltip/use-geo-item-tooltip.d.ts +26 -0
- package/geo/tooltip/use-geo-item-tooltip.d.ts.map +1 -0
- package/geo/tooltip/use-geo-item-tooltip.js +59 -0
- package/geo/us-chart.js +1 -1
- package/geo/us-states.json +54 -0
- package/geo/world.json +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/line/index.d.ts +1 -1
- package/line/index.d.ts.map +1 -1
- package/line/line-chart.d.ts +1 -1
- package/line/line-chart.d.ts.map +1 -1
- package/line/line-chart.props.d.ts +5 -0
- package/line/line-chart.props.d.ts.map +1 -1
- package/package.json +7 -4
- package/pie/index.d.ts +1 -0
- package/pie/index.d.ts.map +1 -1
- package/pie/index.js +1 -0
- package/pie/pie-chart.d.ts.map +1 -1
- package/pie/pie-chart.js +59 -36
- package/pie/pie-chart.props.d.ts +12 -6
- package/pie/pie-chart.props.d.ts.map +1 -1
- package/pie/tooltip/default-pie-tooltip.d.ts +5 -0
- package/pie/tooltip/default-pie-tooltip.d.ts.map +1 -0
- package/pie/tooltip/default-pie-tooltip.js +57 -0
- package/pie/tooltip/index.d.ts +7 -0
- package/pie/tooltip/index.d.ts.map +1 -0
- package/pie/tooltip/index.js +4 -0
- package/pie/tooltip/pie-item-tooltip-presets.d.ts +5 -0
- package/pie/tooltip/pie-item-tooltip-presets.d.ts.map +1 -0
- package/pie/tooltip/pie-item-tooltip-presets.js +39 -0
- package/pie/tooltip/pie-item-tooltip.types.d.ts +28 -0
- package/pie/tooltip/pie-item-tooltip.types.d.ts.map +1 -0
- package/pie/tooltip/pie-item-tooltip.types.js +3 -0
- package/pie/tooltip/pie-item-tooltip.utils.d.ts +9 -0
- package/pie/tooltip/pie-item-tooltip.utils.d.ts.map +1 -0
- package/pie/tooltip/pie-item-tooltip.utils.js +139 -0
- package/pie/tooltip/use-pie-item-tooltip.d.ts +24 -0
- package/pie/tooltip/use-pie-item-tooltip.d.ts.map +1 -0
- package/pie/tooltip/use-pie-item-tooltip.js +45 -0
- package/props/cartesian.d.ts +18 -2
- package/props/cartesian.d.ts.map +1 -1
- package/radar/index.d.ts +1 -0
- package/radar/index.d.ts.map +1 -1
- package/radar/index.js +1 -0
- package/radar/radar-chart.d.ts.map +1 -1
- package/radar/radar-chart.js +52 -10
- package/radar/radar-chart.props.d.ts +13 -0
- package/radar/radar-chart.props.d.ts.map +1 -1
- package/radar/tooltip/default-radar-tooltip.d.ts +6 -0
- package/radar/tooltip/default-radar-tooltip.d.ts.map +1 -0
- package/radar/tooltip/default-radar-tooltip.js +47 -0
- package/radar/tooltip/index.d.ts +7 -0
- package/radar/tooltip/index.d.ts.map +1 -0
- package/radar/tooltip/index.js +4 -0
- package/radar/tooltip/radar-item-tooltip-presets.d.ts +5 -0
- package/radar/tooltip/radar-item-tooltip-presets.d.ts.map +1 -0
- package/radar/tooltip/radar-item-tooltip-presets.js +50 -0
- package/radar/tooltip/radar-item-tooltip.types.d.ts +28 -0
- package/radar/tooltip/radar-item-tooltip.types.d.ts.map +1 -0
- package/radar/tooltip/radar-item-tooltip.types.js +3 -0
- package/radar/tooltip/radar-item-tooltip.utils.d.ts +9 -0
- package/radar/tooltip/radar-item-tooltip.utils.d.ts.map +1 -0
- package/radar/tooltip/radar-item-tooltip.utils.js +77 -0
- package/radar/tooltip/use-radar-item-tooltip.d.ts +22 -0
- package/radar/tooltip/use-radar-item-tooltip.d.ts.map +1 -0
- package/radar/tooltip/use-radar-item-tooltip.js +43 -0
- package/radial/index.d.ts +1 -0
- package/radial/index.d.ts.map +1 -1
- package/radial/index.js +1 -0
- package/radial/radial-chart.d.ts.map +1 -1
- package/radial/radial-chart.js +42 -10
- package/radial/radial-chart.props.d.ts +14 -1
- package/radial/radial-chart.props.d.ts.map +1 -1
- package/radial/tooltip/default-radial-tooltip.d.ts +6 -0
- package/radial/tooltip/default-radial-tooltip.d.ts.map +1 -0
- package/radial/tooltip/default-radial-tooltip.js +52 -0
- package/radial/tooltip/index.d.ts +7 -0
- package/radial/tooltip/index.d.ts.map +1 -0
- package/radial/tooltip/index.js +4 -0
- package/radial/tooltip/radial-item-tooltip-presets.d.ts +5 -0
- package/radial/tooltip/radial-item-tooltip-presets.d.ts.map +1 -0
- package/radial/tooltip/radial-item-tooltip-presets.js +43 -0
- package/radial/tooltip/radial-item-tooltip.types.d.ts +23 -0
- package/radial/tooltip/radial-item-tooltip.types.d.ts.map +1 -0
- package/radial/tooltip/radial-item-tooltip.types.js +3 -0
- package/radial/tooltip/radial-item-tooltip.utils.d.ts +9 -0
- package/radial/tooltip/radial-item-tooltip.utils.d.ts.map +1 -0
- package/radial/tooltip/radial-item-tooltip.utils.js +122 -0
- package/radial/tooltip/use-radial-item-tooltip.d.ts +22 -0
- package/radial/tooltip/use-radial-item-tooltip.d.ts.map +1 -0
- package/radial/tooltip/use-radial-item-tooltip.js +43 -0
- package/scatter/index.d.ts +1 -0
- package/scatter/index.d.ts.map +1 -1
- package/scatter/index.js +1 -0
- package/scatter/scatter-chart.d.ts.map +1 -1
- package/scatter/scatter-chart.js +46 -12
- package/scatter/scatter-chart.props.d.ts +7 -1
- package/scatter/scatter-chart.props.d.ts.map +1 -1
- package/scatter/tooltip/default-scatter-tooltip.d.ts +8 -0
- package/scatter/tooltip/default-scatter-tooltip.d.ts.map +1 -0
- package/scatter/tooltip/default-scatter-tooltip.js +57 -0
- package/scatter/tooltip/index.d.ts +7 -0
- package/scatter/tooltip/index.d.ts.map +1 -0
- package/scatter/tooltip/index.js +4 -0
- package/scatter/tooltip/scatter-item-tooltip-presets.d.ts +5 -0
- package/scatter/tooltip/scatter-item-tooltip-presets.d.ts.map +1 -0
- package/scatter/tooltip/scatter-item-tooltip-presets.js +49 -0
- package/scatter/tooltip/scatter-item-tooltip.types.d.ts +22 -0
- package/scatter/tooltip/scatter-item-tooltip.types.d.ts.map +1 -0
- package/scatter/tooltip/scatter-item-tooltip.types.js +3 -0
- package/scatter/tooltip/scatter-item-tooltip.utils.d.ts +9 -0
- package/scatter/tooltip/scatter-item-tooltip.utils.d.ts.map +1 -0
- package/scatter/tooltip/scatter-item-tooltip.utils.js +83 -0
- package/scatter/tooltip/use-scatter-item-tooltip.d.ts +25 -0
- package/scatter/tooltip/use-scatter-item-tooltip.d.ts.map +1 -0
- package/scatter/tooltip/use-scatter-item-tooltip.js +46 -0
- package/tooltip/chart-pointer-tooltip-overlay.d.ts +11 -0
- package/tooltip/chart-pointer-tooltip-overlay.d.ts.map +1 -0
- package/tooltip/chart-pointer-tooltip-overlay.js +88 -0
- package/tooltip/chart-tooltip-preset-shells.d.ts +66 -0
- package/tooltip/chart-tooltip-preset-shells.d.ts.map +1 -0
- package/tooltip/chart-tooltip-preset-shells.js +409 -0
- package/tooltip/index.d.ts +7 -0
- package/tooltip/index.d.ts.map +1 -0
- package/tooltip/index.js +1 -0
package/bubble/bubble-chart.js
CHANGED
|
@@ -5,6 +5,9 @@ import { ScatterChart as EChartsScatterChart } from 'echarts/charts';
|
|
|
5
5
|
import { GridComponent, LegendComponent, TooltipComponent, } from 'echarts/components';
|
|
6
6
|
import * as echarts from 'echarts/core';
|
|
7
7
|
import React, { useEffect, useMemo, useRef } from 'react';
|
|
8
|
+
import { View } from 'react-native';
|
|
9
|
+
import { axisTooltipShowContentFlag } from '../cartesian/tooltip';
|
|
10
|
+
import { createScatterTooltipPreset, useScatterItemTooltip } from '../scatter/tooltip';
|
|
8
11
|
echarts.use([
|
|
9
12
|
TooltipComponent,
|
|
10
13
|
GridComponent,
|
|
@@ -18,12 +21,31 @@ function scaleSize(value, dataMin, dataMax, outMin, outMax) {
|
|
|
18
21
|
const t = (value - dataMin) / (dataMax - dataMin);
|
|
19
22
|
return outMin + t * (outMax - outMin);
|
|
20
23
|
}
|
|
21
|
-
const
|
|
24
|
+
const DEFAULT_SIZE_RANGE = [8, 50];
|
|
25
|
+
const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', sizeRange = DEFAULT_SIZE_RANGE, showXAxis = true, showXAxisTicks = true, showYAxis = true, showYAxisTicks = true, showXAxisSplitLines = true, showYAxisSplitLines = true, boundaryGap = false, grid, showLegend = false, showHighlighter = true, tooltip = 'card', xAxisTickLabelFormatter, yAxisTickLabelFormatter, xAxisLabel, yAxisLabel, onSelect, renderTooltip, ...props }) => {
|
|
22
26
|
const { theme } = useChartTheme(props.theme, props.colors);
|
|
23
27
|
const chartRef = useRef(null);
|
|
24
28
|
const onSelectRef = useRef(onSelect);
|
|
25
29
|
onSelectRef.current = onSelect;
|
|
26
30
|
const selectContextRef = useRef({ normalizedSeries: [] });
|
|
31
|
+
const themeSeriesRef = useRef(theme.series);
|
|
32
|
+
themeSeriesRef.current = theme.series;
|
|
33
|
+
const tooltipOverlayActive = renderTooltip != null || tooltip !== 'none';
|
|
34
|
+
const renderTooltipFn = useMemo(() => {
|
|
35
|
+
if (renderTooltip != null)
|
|
36
|
+
return renderTooltip;
|
|
37
|
+
if (tooltip === 'none')
|
|
38
|
+
return () => null;
|
|
39
|
+
return createScatterTooltipPreset(tooltip);
|
|
40
|
+
}, [renderTooltip, tooltip]);
|
|
41
|
+
const { attachScatterItemTooltipListeners, renderScatterTooltipOverlay } = useScatterItemTooltip({
|
|
42
|
+
active: tooltipOverlayActive,
|
|
43
|
+
renderTooltip: renderTooltipFn,
|
|
44
|
+
contextRef: selectContextRef,
|
|
45
|
+
themeSeriesRef,
|
|
46
|
+
width,
|
|
47
|
+
height,
|
|
48
|
+
});
|
|
27
49
|
const normalizedSeries = useMemo(() => {
|
|
28
50
|
if (!Array.isArray(data) || data.length === 0)
|
|
29
51
|
return [];
|
|
@@ -52,39 +74,29 @@ const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', si
|
|
|
52
74
|
return [];
|
|
53
75
|
}, [data]);
|
|
54
76
|
const hasNamedSeries = useMemo(() => normalizedSeries.some((s) => 'name' in s && s.name), [normalizedSeries]);
|
|
55
|
-
selectContextRef.current = {
|
|
77
|
+
selectContextRef.current = {
|
|
78
|
+
normalizedSeries: normalizedSeries,
|
|
79
|
+
};
|
|
56
80
|
const option = useMemo(() => {
|
|
57
|
-
const tooltipConfig =
|
|
81
|
+
const tooltipConfig = tooltipOverlayActive
|
|
58
82
|
? {
|
|
59
83
|
trigger: 'item',
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
84
|
+
...axisTooltipShowContentFlag(true),
|
|
85
|
+
...(showHighlighter && {
|
|
86
|
+
axisPointer: {
|
|
63
87
|
type: 'line',
|
|
64
|
-
|
|
65
|
-
|
|
88
|
+
lineStyle: {
|
|
89
|
+
type: 'line',
|
|
90
|
+
width: 1,
|
|
91
|
+
color: '#00000000',
|
|
92
|
+
},
|
|
93
|
+
label: {
|
|
94
|
+
show: false,
|
|
95
|
+
},
|
|
66
96
|
},
|
|
67
|
-
},
|
|
68
|
-
formatter: (params) => {
|
|
69
|
-
const p = Array.isArray(params) ? params[0] : params;
|
|
70
|
-
const d = p?.data;
|
|
71
|
-
if (!d || !Array.isArray(d))
|
|
72
|
-
return '';
|
|
73
|
-
const name = p.seriesName ? `${p.seriesName}<br/>` : '';
|
|
74
|
-
return `${name}x: ${d[0]}, y: ${d[1]}${d[2] != null ? `, size: ${d[2]}` : ''}`;
|
|
75
|
-
},
|
|
97
|
+
}),
|
|
76
98
|
}
|
|
77
|
-
: {
|
|
78
|
-
trigger: 'item',
|
|
79
|
-
formatter: (params) => {
|
|
80
|
-
const p = Array.isArray(params) ? params[0] : params;
|
|
81
|
-
const d = p?.data;
|
|
82
|
-
if (!d || !Array.isArray(d))
|
|
83
|
-
return '';
|
|
84
|
-
const name = p.seriesName ? `${p.seriesName}<br/>` : '';
|
|
85
|
-
return `${name}x: ${d[0]}, y: ${d[1]}${d[2] != null ? `, size: ${d[2]}` : ''}`;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
99
|
+
: { show: false };
|
|
88
100
|
const xAxisConfig = {
|
|
89
101
|
type: 'value',
|
|
90
102
|
boundaryGap,
|
|
@@ -193,7 +205,7 @@ const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', si
|
|
|
193
205
|
itemStyle: { color: seriesColor },
|
|
194
206
|
emphasis: showHighlighter
|
|
195
207
|
? {
|
|
196
|
-
focus: '
|
|
208
|
+
focus: 'none',
|
|
197
209
|
scale: true,
|
|
198
210
|
itemStyle: {
|
|
199
211
|
color: seriesColor,
|
|
@@ -234,6 +246,7 @@ const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', si
|
|
|
234
246
|
showLegend,
|
|
235
247
|
hasNamedSeries,
|
|
236
248
|
showHighlighter,
|
|
249
|
+
tooltipOverlayActive,
|
|
237
250
|
xAxisTickLabelFormatter,
|
|
238
251
|
yAxisTickLabelFormatter,
|
|
239
252
|
xAxisLabel,
|
|
@@ -241,10 +254,12 @@ const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', si
|
|
|
241
254
|
]);
|
|
242
255
|
useEffect(() => {
|
|
243
256
|
let chart;
|
|
257
|
+
let detachScatterTooltip = () => { };
|
|
244
258
|
if (chartRef.current) {
|
|
245
259
|
try {
|
|
246
260
|
chart = echarts.init(chartRef.current, 'light', { width, height });
|
|
247
261
|
chart.setOption(option);
|
|
262
|
+
detachScatterTooltip = attachScatterItemTooltipListeners(chart);
|
|
248
263
|
const handleSeriesClick = (params) => {
|
|
249
264
|
const cb = onSelectRef.current;
|
|
250
265
|
if (typeof cb !== 'function')
|
|
@@ -287,6 +302,7 @@ const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', si
|
|
|
287
302
|
}
|
|
288
303
|
}
|
|
289
304
|
return () => {
|
|
305
|
+
detachScatterTooltip();
|
|
290
306
|
if (chart) {
|
|
291
307
|
try {
|
|
292
308
|
chart.dispose();
|
|
@@ -296,8 +312,11 @@ const ChartComponent = ({ data, width = 220, height = 350, symbol = 'circle', si
|
|
|
296
312
|
}
|
|
297
313
|
}
|
|
298
314
|
};
|
|
299
|
-
}, [option, width, height]);
|
|
300
|
-
return <
|
|
315
|
+
}, [option, width, height, attachScatterItemTooltipListeners]);
|
|
316
|
+
return (<View style={{ width, height, position: 'relative' }}>
|
|
317
|
+
<SkiaChart ref={chartRef} useRNGH/>
|
|
318
|
+
{renderScatterTooltipOverlay()}
|
|
319
|
+
</View>);
|
|
301
320
|
};
|
|
302
321
|
const BubbleChartComponent = withResponsiveContainer(withChartTheme(ChartComponent));
|
|
303
322
|
export const BubbleChart = Object.assign(BubbleChartComponent, {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartTooltipPreset } from '../../tooltip';
|
|
3
|
+
import type { AxisTooltipParams } from './axis-tooltip.types';
|
|
4
|
+
export declare function createAxisTooltipPreset(preset: ChartTooltipPreset): (params: AxisTooltipParams) => React.ReactElement;
|
|
5
|
+
//# sourceMappingURL=axis-tooltip-presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axis-tooltip-presets.d.ts","sourceRoot":"","sources":["../../../../../components/chart/cartesian/tooltip/axis-tooltip-presets.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAOxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA0D9D,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,kBAAkB,GACzB,CAAC,MAAM,EAAE,iBAAiB,KAAK,KAAK,CAAC,YAAY,CAYnD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TooltipPresetCard, TooltipPresetCompact, TooltipPresetKpi, TooltipPresetStriped, } from '../../tooltip/chart-tooltip-preset-shells';
|
|
3
|
+
function axisCardFromParams({ axisValue, series }) {
|
|
4
|
+
return (<TooltipPresetCard categoryTitle={String(axisValue)} seriesRows={series.map((s) => ({
|
|
5
|
+
key: s.seriesIndex,
|
|
6
|
+
swatchColor: s.color ?? '#94a3b8',
|
|
7
|
+
label: s.seriesName,
|
|
8
|
+
value: s.value,
|
|
9
|
+
}))}/>);
|
|
10
|
+
}
|
|
11
|
+
function axisCompactFromParams({ axisValue, series }) {
|
|
12
|
+
const detail = series.map((s) => `${s.seriesName} ${s.value}`).join(' · ');
|
|
13
|
+
return <TooltipPresetCompact emphasis={String(axisValue)} detail={detail} wrap/>;
|
|
14
|
+
}
|
|
15
|
+
function axisKpiFromParams({ axisValue, series }) {
|
|
16
|
+
const primary = series[0];
|
|
17
|
+
const rest = series.slice(1);
|
|
18
|
+
return (<TooltipPresetKpi accentColor={primary?.color ?? '#3b82f6'} minWidth={160} overline={String(axisValue)} metric={primary?.value ?? ''} caption={primary?.seriesName} footerRows={rest.length > 0
|
|
19
|
+
? rest.map((s) => ({
|
|
20
|
+
key: s.seriesIndex,
|
|
21
|
+
left: s.seriesName,
|
|
22
|
+
right: s.value,
|
|
23
|
+
}))
|
|
24
|
+
: undefined}/>);
|
|
25
|
+
}
|
|
26
|
+
function axisStripedFromParams({ axisValue, series }) {
|
|
27
|
+
return (<TooltipPresetStriped headerTitle={String(axisValue)} rows={series.map((s) => ({
|
|
28
|
+
key: `s-${s.seriesIndex}`,
|
|
29
|
+
leftLabel: s.seriesName,
|
|
30
|
+
leftSwatchColor: s.color ?? '#64748b',
|
|
31
|
+
right: s.value,
|
|
32
|
+
}))}/>);
|
|
33
|
+
}
|
|
34
|
+
export function createAxisTooltipPreset(preset) {
|
|
35
|
+
switch (preset) {
|
|
36
|
+
case 'card':
|
|
37
|
+
return (p) => axisCardFromParams(p);
|
|
38
|
+
case 'compact':
|
|
39
|
+
return (p) => axisCompactFromParams(p);
|
|
40
|
+
case 'kpi':
|
|
41
|
+
return (p) => axisKpiFromParams(p);
|
|
42
|
+
case 'striped':
|
|
43
|
+
return (p) => axisStripedFromParams(p);
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Unknown tooltip preset: ${String(preset)}`);
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for axis-triggered tooltips (category axis + one value per series).
|
|
3
|
+
* Used by area, line, column, and bar charts.
|
|
4
|
+
*/
|
|
5
|
+
/** One series row at the hovered category index. */
|
|
6
|
+
export interface AxisTooltipSeriesItem {
|
|
7
|
+
seriesName: string;
|
|
8
|
+
value: number;
|
|
9
|
+
seriesIndex: number;
|
|
10
|
+
color?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Axis tooltip fields without pointer position. */
|
|
13
|
+
export interface AxisTooltipContentParams {
|
|
14
|
+
axisValue: string | number;
|
|
15
|
+
dataIndex: number;
|
|
16
|
+
series: AxisTooltipSeriesItem[];
|
|
17
|
+
}
|
|
18
|
+
/** Payload for `renderTooltip` (includes pointer in chart pixel space). */
|
|
19
|
+
export interface AxisTooltipParams extends AxisTooltipContentParams {
|
|
20
|
+
pointerX: number;
|
|
21
|
+
pointerY: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Ref snapshot read when `showTip` fires. Keep `categoryAxisData` in sync with the chart’s category axis `data`.
|
|
25
|
+
*/
|
|
26
|
+
export interface AxisTooltipContext {
|
|
27
|
+
displaySeries: Array<{
|
|
28
|
+
name?: string;
|
|
29
|
+
data: [string | number, number][] | number[];
|
|
30
|
+
}>;
|
|
31
|
+
categoryAxisData: (string | number)[];
|
|
32
|
+
/**
|
|
33
|
+
* Set when the category axis is Y (horizontal column/bar). `showTip` lists that axis in `dataByAxis`;
|
|
34
|
+
* reading `[0]` would be the value axis and yields a stuck `dataIndex`.
|
|
35
|
+
*/
|
|
36
|
+
categoryAxisIsY?: boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=axis-tooltip.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axis-tooltip.types.d.ts","sourceRoot":"","sources":["../../../../../components/chart/cartesian/tooltip/axis-tooltip.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oDAAoD;AACpD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oDAAoD;AACpD,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,qBAAqB,EAAE,CAAC;CACjC;AAED,2EAA2E;AAC3E,MAAM,WAAW,iBAAkB,SAAQ,wBAAwB;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACtF,gBAAgB,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACtC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AxisTooltipContext, AxisTooltipParams } from './axis-tooltip.types';
|
|
2
|
+
/** Build axis tooltip params from an ECharts `showTip` dispatch payload. */
|
|
3
|
+
export declare function axisTooltipParamsFromShowTipEvent(evt: any, ctx: AxisTooltipContext, seriesTheme: Array<{
|
|
4
|
+
color: string;
|
|
5
|
+
}>): AxisTooltipParams | null;
|
|
6
|
+
/** Spread onto ECharts `tooltip` when using an RN overlay (`showTip` / `hideTip` still fire). */
|
|
7
|
+
export declare function axisTooltipShowContentFlag(useCustomTooltipOverlay: boolean): {
|
|
8
|
+
showContent: boolean;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=axis-tooltip.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axis-tooltip.utils.d.ts","sourceRoot":"","sources":["../../../../../components/chart/cartesian/tooltip/axis-tooltip.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAyB,MAAM,sBAAsB,CAAC;AAsEzG,4EAA4E;AAC5E,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EACvB,WAAW,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GACpC,iBAAiB,GAAG,IAAI,CAsD1B;AAED,iGAAiG;AACjG,wBAAgB,0BAA0B,CACxC,uBAAuB,EAAE,OAAO,GAC/B;IAAE,WAAW,EAAE,OAAO,CAAA;CAAE,CAE1B"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
function isCategoryAxisEntry(a) {
|
|
2
|
+
return String(a?.axisType ?? '').toLowerCase() === 'category';
|
|
3
|
+
}
|
|
4
|
+
function hasSeriesIndices(a) {
|
|
5
|
+
return Array.isArray(a?.seriesDataIndices) && a.seriesDataIndices.length > 0;
|
|
6
|
+
}
|
|
7
|
+
/** First numeric `dataIndex` carried on the axis tooltip batch (the authoritative index for that axis). */
|
|
8
|
+
function dataIndexFromSeriesDataIndices(indices) {
|
|
9
|
+
if (!Array.isArray(indices))
|
|
10
|
+
return undefined;
|
|
11
|
+
for (const item of indices) {
|
|
12
|
+
const d = item?.dataIndex;
|
|
13
|
+
if (typeof d === 'number' && !Number.isNaN(d))
|
|
14
|
+
return d;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
function seriesDataIndicesFromShowTipEvt(evt, categoryAxisIsY) {
|
|
19
|
+
const axes = evt?.dataByCoordSys?.[0]?.dataByAxis;
|
|
20
|
+
if (!Array.isArray(axes) || axes.length === 0)
|
|
21
|
+
return null;
|
|
22
|
+
const categoryAxes = axes.filter(isCategoryAxisEntry);
|
|
23
|
+
if (categoryAxes.length === 1) {
|
|
24
|
+
const axisEntry = categoryAxes[0];
|
|
25
|
+
return {
|
|
26
|
+
indices: Array.isArray(axisEntry.seriesDataIndices) ? axisEntry.seriesDataIndices : [],
|
|
27
|
+
axisEntry,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (categoryAxes.length > 1 && categoryAxisIsY != null) {
|
|
31
|
+
const dim = categoryAxisIsY ? 'y' : 'x';
|
|
32
|
+
const axisEntry = categoryAxes.find((a) => a?.axisDim === dim && hasSeriesIndices(a)) ??
|
|
33
|
+
categoryAxes.find((a) => a?.axisDim === dim) ??
|
|
34
|
+
categoryAxes[0];
|
|
35
|
+
return {
|
|
36
|
+
indices: Array.isArray(axisEntry.seriesDataIndices) ? axisEntry.seriesDataIndices : [],
|
|
37
|
+
axisEntry,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (categoryAxisIsY === true) {
|
|
41
|
+
const yWith = axes.find((a) => a?.axisDim === 'y' && hasSeriesIndices(a));
|
|
42
|
+
if (yWith)
|
|
43
|
+
return { indices: yWith.seriesDataIndices, axisEntry: yWith };
|
|
44
|
+
const yAxis = axes.find((a) => a?.axisDim === 'y');
|
|
45
|
+
if (yAxis)
|
|
46
|
+
return { indices: Array.isArray(yAxis.seriesDataIndices) ? yAxis.seriesDataIndices : [], axisEntry: yAxis };
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (categoryAxisIsY === false) {
|
|
50
|
+
const xWith = axes.find((a) => a?.axisDim === 'x' && hasSeriesIndices(a));
|
|
51
|
+
if (xWith)
|
|
52
|
+
return { indices: xWith.seriesDataIndices, axisEntry: xWith };
|
|
53
|
+
const xAxis = axes.find((a) => a?.axisDim === 'x');
|
|
54
|
+
if (xAxis)
|
|
55
|
+
return { indices: Array.isArray(xAxis.seriesDataIndices) ? xAxis.seriesDataIndices : [], axisEntry: xAxis };
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const preferred = axes.find((a) => a?.axisDim === 'x' && hasSeriesIndices(a));
|
|
59
|
+
const fallback = axes.find((a) => hasSeriesIndices(a));
|
|
60
|
+
const axisEntry = preferred ?? fallback ?? axes[0];
|
|
61
|
+
const indices = axisEntry?.seriesDataIndices;
|
|
62
|
+
if (!Array.isArray(indices) || indices.length === 0)
|
|
63
|
+
return null;
|
|
64
|
+
return { indices, axisEntry };
|
|
65
|
+
}
|
|
66
|
+
/** Build axis tooltip params from an ECharts `showTip` dispatch payload. */
|
|
67
|
+
export function axisTooltipParamsFromShowTipEvent(evt, ctx, seriesTheme) {
|
|
68
|
+
const pointerX = evt?.x;
|
|
69
|
+
const pointerY = evt?.y;
|
|
70
|
+
if (typeof pointerX !== 'number' || typeof pointerY !== 'number')
|
|
71
|
+
return null;
|
|
72
|
+
if (Number.isNaN(pointerX) || Number.isNaN(pointerY))
|
|
73
|
+
return null;
|
|
74
|
+
const picked = seriesDataIndicesFromShowTipEvt(evt, ctx.categoryAxisIsY);
|
|
75
|
+
if (picked == null)
|
|
76
|
+
return null;
|
|
77
|
+
const { indices, axisEntry } = picked;
|
|
78
|
+
const dataIndexRaw = dataIndexFromSeriesDataIndices(indices) ??
|
|
79
|
+
(typeof axisEntry?.dataIndex === 'number' && !Number.isNaN(axisEntry.dataIndex)
|
|
80
|
+
? axisEntry.dataIndex
|
|
81
|
+
: undefined) ??
|
|
82
|
+
(typeof evt?.dataIndex === 'number' && !Number.isNaN(evt.dataIndex) ? evt.dataIndex : undefined) ??
|
|
83
|
+
0;
|
|
84
|
+
const { displaySeries: ds, categoryAxisData: cats } = ctx;
|
|
85
|
+
if (!ds?.length || dataIndexRaw < 0)
|
|
86
|
+
return null;
|
|
87
|
+
const indicesForSeries = Array.isArray(indices) && indices.length > 0
|
|
88
|
+
? indices
|
|
89
|
+
: ds.map((_, seriesIndex) => ({ seriesIndex, dataIndex: dataIndexRaw }));
|
|
90
|
+
const axisValue = cats[dataIndexRaw] ?? dataIndexRaw;
|
|
91
|
+
const themeLen = Math.max(seriesTheme.length, 1);
|
|
92
|
+
const series = indicesForSeries.map((item) => {
|
|
93
|
+
const seriesIndex = typeof item.seriesIndex === 'number' ? item.seriesIndex : 0;
|
|
94
|
+
const s = ds[seriesIndex];
|
|
95
|
+
const seriesName = s?.name != null && s.name !== '' ? String(s.name) : `Series ${seriesIndex + 1}`;
|
|
96
|
+
let value = 0;
|
|
97
|
+
const pt = s?.data?.[dataIndexRaw];
|
|
98
|
+
if (typeof pt === 'number')
|
|
99
|
+
value = pt;
|
|
100
|
+
else if (Array.isArray(pt) && pt.length >= 2)
|
|
101
|
+
value = Number(pt[1]);
|
|
102
|
+
const color = seriesTheme[seriesIndex % themeLen]?.color;
|
|
103
|
+
return {
|
|
104
|
+
seriesName,
|
|
105
|
+
value,
|
|
106
|
+
seriesIndex,
|
|
107
|
+
...(typeof color === 'string' ? { color } : {}),
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
axisValue,
|
|
112
|
+
dataIndex: dataIndexRaw,
|
|
113
|
+
series,
|
|
114
|
+
pointerX,
|
|
115
|
+
pointerY,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Spread onto ECharts `tooltip` when using an RN overlay (`showTip` / `hideTip` still fire). */
|
|
119
|
+
export function axisTooltipShowContentFlag(useCustomTooltipOverlay) {
|
|
120
|
+
return { showContent: !useCustomTooltipOverlay };
|
|
121
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartTheme } from '../../chart-theme.context';
|
|
3
|
+
import type { AxisTooltipParams } from './axis-tooltip.types';
|
|
4
|
+
/**
|
|
5
|
+
* Themed default axis tooltip as React Native (mirrors the former ECharts tooltip styling).
|
|
6
|
+
* Pass the result of this factory to {@link useAxisTooltip} when the consumer does not pass `renderTooltip`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createDefaultAxisTooltip(theme: Pick<ChartTheme, 'tooltip'>): (params: AxisTooltipParams) => React.ReactElement;
|
|
9
|
+
//# sourceMappingURL=default-axis-tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-axis-tooltip.d.ts","sourceRoot":"","sources":["../../../../../components/chart/cartesian/tooltip/default-axis-tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GACjC,CAAC,MAAM,EAAE,iBAAiB,KAAK,KAAK,CAAC,YAAY,CA8BnD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
/**
|
|
4
|
+
* Themed default axis tooltip as React Native (mirrors the former ECharts tooltip styling).
|
|
5
|
+
* Pass the result of this factory to {@link useAxisTooltip} when the consumer does not pass `renderTooltip`.
|
|
6
|
+
*/
|
|
7
|
+
export function createDefaultAxisTooltip(theme) {
|
|
8
|
+
const t = theme.tooltip;
|
|
9
|
+
return function DefaultAxisTooltip(params) {
|
|
10
|
+
return (<View style={{
|
|
11
|
+
backgroundColor: t.backgroundColor,
|
|
12
|
+
borderColor: t.borderColor,
|
|
13
|
+
borderWidth: t.borderWidth,
|
|
14
|
+
borderRadius: t.borderRadius,
|
|
15
|
+
padding: t.padding,
|
|
16
|
+
}}>
|
|
17
|
+
<Text style={[styles.axisTitle, { color: t.labelColor }]}>{String(params.axisValue)}</Text>
|
|
18
|
+
{params.series.map((item) => (<View key={item.seriesIndex} style={styles.row}>
|
|
19
|
+
{item.color != null && item.color !== '' ? (<View style={[styles.swatch, { backgroundColor: item.color }]}/>) : (<View style={styles.swatchPlaceholder}/>)}
|
|
20
|
+
<Text style={[styles.valueLine, { color: t.valueColor }]}>
|
|
21
|
+
<Text style={{ color: t.labelColor }}>{item.seriesName}: </Text>
|
|
22
|
+
{String(item.value)}
|
|
23
|
+
</Text>
|
|
24
|
+
</View>))}
|
|
25
|
+
</View>);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const styles = StyleSheet.create({
|
|
29
|
+
axisTitle: {
|
|
30
|
+
fontWeight: '600',
|
|
31
|
+
marginBottom: 4,
|
|
32
|
+
},
|
|
33
|
+
row: {
|
|
34
|
+
flexDirection: 'row',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
marginTop: 2,
|
|
37
|
+
},
|
|
38
|
+
swatch: {
|
|
39
|
+
width: 8,
|
|
40
|
+
height: 8,
|
|
41
|
+
borderRadius: 4,
|
|
42
|
+
marginRight: 6,
|
|
43
|
+
},
|
|
44
|
+
swatchPlaceholder: {
|
|
45
|
+
width: 8,
|
|
46
|
+
height: 8,
|
|
47
|
+
marginRight: 6,
|
|
48
|
+
},
|
|
49
|
+
valueLine: {
|
|
50
|
+
fontSize: 12,
|
|
51
|
+
flex: 1,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createDefaultAxisTooltip } from './default-axis-tooltip';
|
|
2
|
+
export { createAxisTooltipPreset } from './axis-tooltip-presets';
|
|
3
|
+
export type { AxisTooltipContentParams, AxisTooltipContext, AxisTooltipParams, AxisTooltipSeriesItem, } from './axis-tooltip.types';
|
|
4
|
+
export { axisTooltipShowContentFlag, axisTooltipParamsFromShowTipEvent } from './axis-tooltip.utils';
|
|
5
|
+
export { AxisTooltipOverlay, useAxisTooltip } from './use-axis-tooltip';
|
|
6
|
+
export type { AxisTooltipOverlayProps, UseAxisTooltipOptions, UseAxisTooltipResult } from './use-axis-tooltip';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../components/chart/cartesian/tooltip/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,YAAY,EACV,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACxE,YAAY,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createDefaultAxisTooltip } from './default-axis-tooltip';
|
|
2
|
+
export { createAxisTooltipPreset } from './axis-tooltip-presets';
|
|
3
|
+
export { axisTooltipShowContentFlag, axisTooltipParamsFromShowTipEvent } from './axis-tooltip.utils';
|
|
4
|
+
export { AxisTooltipOverlay, useAxisTooltip } from './use-axis-tooltip';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AxisTooltipContext, AxisTooltipParams } from './axis-tooltip.types';
|
|
3
|
+
export interface AxisTooltipOverlayProps {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
params: AxisTooltipParams | null;
|
|
7
|
+
children: (params: AxisTooltipParams) => React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/** Presentational overlay; use with your own state if you do not use the hook. */
|
|
10
|
+
export declare function AxisTooltipOverlay({ width, height, params, children }: AxisTooltipOverlayProps): React.JSX.Element | null;
|
|
11
|
+
export interface UseAxisTooltipOptions {
|
|
12
|
+
/**
|
|
13
|
+
* When true, registers `showTip` / `hideTip` listeners and drives the overlay.
|
|
14
|
+
* Typically matches whether the chart shows the RN tooltip overlay (see chart `tooltip` / `renderTooltip`).
|
|
15
|
+
*/
|
|
16
|
+
active: boolean;
|
|
17
|
+
/** Resolved renderer (include {@link createDefaultAxisTooltip} when the consumer does not pass one). */
|
|
18
|
+
renderTooltip: (params: AxisTooltipParams) => React.ReactNode;
|
|
19
|
+
contextRef: React.RefObject<AxisTooltipContext>;
|
|
20
|
+
themeSeriesRef: React.RefObject<Array<{
|
|
21
|
+
color: string;
|
|
22
|
+
}>>;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}
|
|
26
|
+
export interface UseAxisTooltipResult {
|
|
27
|
+
attachAxisTooltipListeners: (chart: {
|
|
28
|
+
on: (ev: string, fn: (...args: any[]) => void) => void;
|
|
29
|
+
off: (ev: string, fn: (...args: any[]) => void) => void;
|
|
30
|
+
}) => () => void;
|
|
31
|
+
renderAxisTooltipOverlay: () => React.ReactNode;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Axis tooltip as React Native UI: listens to ECharts `showTip` / `hideTip`, maps payload with
|
|
35
|
+
* {@link axisTooltipParamsFromShowTipEvent}, and positions an overlay near the pointer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useAxisTooltip(options: UseAxisTooltipOptions): UseAxisTooltipResult;
|
|
38
|
+
//# sourceMappingURL=use-axis-tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-axis-tooltip.d.ts","sourceRoot":"","sources":["../../../../../components/chart/cartesian/tooltip/use-axis-tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGlF,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,KAAK,CAAC,SAAS,CAAC;CAC1D;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,uBAAuB,4BAY9F;AAED,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB,wGAAwG;IACxG,aAAa,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,KAAK,CAAC,SAAS,CAAC;IAC9D,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAChD,cAAc,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB;IACnC,0BAA0B,EAAE,CAAC,KAAK,EAAE;QAClC,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;QACvD,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;KACzD,KAAK,MAAM,IAAI,CAAC;IACjB,wBAAwB,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC;CACjD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CA4CnF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { ChartPointerTooltipOverlay } from '../../tooltip/chart-pointer-tooltip-overlay';
|
|
3
|
+
import { axisTooltipParamsFromShowTipEvent } from './axis-tooltip.utils';
|
|
4
|
+
/** Presentational overlay; use with your own state if you do not use the hook. */
|
|
5
|
+
export function AxisTooltipOverlay({ width, height, params, children }) {
|
|
6
|
+
if (params == null)
|
|
7
|
+
return null;
|
|
8
|
+
return (<ChartPointerTooltipOverlay width={width} height={height} pointerX={params.pointerX} pointerY={params.pointerY}>
|
|
9
|
+
{children(params)}
|
|
10
|
+
</ChartPointerTooltipOverlay>);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Axis tooltip as React Native UI: listens to ECharts `showTip` / `hideTip`, maps payload with
|
|
14
|
+
* {@link axisTooltipParamsFromShowTipEvent}, and positions an overlay near the pointer.
|
|
15
|
+
*/
|
|
16
|
+
export function useAxisTooltip(options) {
|
|
17
|
+
const { active, renderTooltip, contextRef, themeSeriesRef, width, height } = options;
|
|
18
|
+
const [tooltipParams, setTooltipParams] = useState(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!active)
|
|
21
|
+
setTooltipParams(null);
|
|
22
|
+
}, [active]);
|
|
23
|
+
const attachAxisTooltipListeners = useCallback((chart) => {
|
|
24
|
+
if (!active)
|
|
25
|
+
return () => { };
|
|
26
|
+
const onShowTip = (evt) => {
|
|
27
|
+
const ctx = contextRef.current;
|
|
28
|
+
if (!ctx?.displaySeries?.length) {
|
|
29
|
+
setTooltipParams(null);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const params = axisTooltipParamsFromShowTipEvent(evt, ctx, themeSeriesRef.current ?? []);
|
|
33
|
+
setTooltipParams(params);
|
|
34
|
+
};
|
|
35
|
+
const onHideTip = () => setTooltipParams(null);
|
|
36
|
+
chart.on('showTip', onShowTip);
|
|
37
|
+
chart.on('hideTip', onHideTip);
|
|
38
|
+
return () => {
|
|
39
|
+
chart.off('showTip', onShowTip);
|
|
40
|
+
chart.off('hideTip', onHideTip);
|
|
41
|
+
};
|
|
42
|
+
}, [active, contextRef, themeSeriesRef]);
|
|
43
|
+
const renderAxisTooltipOverlay = useCallback(() => {
|
|
44
|
+
if (!active || tooltipParams == null)
|
|
45
|
+
return null;
|
|
46
|
+
return (<AxisTooltipOverlay width={width} height={height} params={tooltipParams}>
|
|
47
|
+
{renderTooltip}
|
|
48
|
+
</AxisTooltipOverlay>);
|
|
49
|
+
}, [active, renderTooltip, tooltipParams, width, height]);
|
|
50
|
+
return {
|
|
51
|
+
attachAxisTooltipListeners,
|
|
52
|
+
renderAxisTooltipOverlay,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-chart.d.ts","sourceRoot":"","sources":["../../../../components/chart/column/column-chart.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAS7D,OAAO,KAAqC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"column-chart.d.ts","sourceRoot":"","sources":["../../../../components/chart/column/column-chart.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAS7D,OAAO,KAAqC,MAAM,OAAO,CAAC;AAO1D,oCAAoC;AACpC,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAqnB7D,eAAO,MAAM,WAAW;;;;;;;CAEtB,CAAC"}
|