@wavemaker/react-native-echarts 1.0.0-dev.5 → 1.0.0-dev.9
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 +29 -3
- package/area/area-chart.d.ts +1 -1
- package/area/area-chart.d.ts.map +1 -1
- package/area/area-chart.js +63 -37
- 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/axis.d.ts +26 -0
- package/axis.d.ts.map +1 -1
- package/axis.js +35 -0
- package/bubble/bubble-chart.d.ts.map +1 -1
- package/bubble/bubble-chart.js +59 -33
- package/candlestick/candlestick-chart.d.ts.map +1 -1
- package/candlestick/candlestick-chart.js +15 -8
- 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 +86 -31
- 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 +1 -1
- 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 +43 -11
- 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 +57 -20
- 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
|
@@ -5,6 +5,7 @@ import { BarChart, CandlestickChart as EChartsCandlestickChart, LineChart } from
|
|
|
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 { valueAxisBoundsFromProps, xAxisBoundsFromProps } from '../axis';
|
|
8
9
|
echarts.use([
|
|
9
10
|
TooltipComponent,
|
|
10
11
|
GridComponent,
|
|
@@ -14,25 +15,25 @@ echarts.use([
|
|
|
14
15
|
BarChart,
|
|
15
16
|
LineChart,
|
|
16
17
|
]);
|
|
17
|
-
const ChartComponent = ({ data, xAxisData, volumeData, ma5, ma10, ma20, width = 220, height = 350, boundaryGap = true, showXAxis = true, showXAxisTicks = true, showYAxis = true, showYAxisTicks = true, showXAxisSplitLines = true, showYAxisSplitLines = true, grid, showLegend = false, showHighlighter = true, positiveColor = '#008000', negativeColor = '#FF2C2C', xAxisTickLabelFormatter, yAxisTickLabelFormatter,
|
|
18
|
+
const ChartComponent = ({ data, xAxisData, volumeData, ma5, ma10, ma20, width = 220, height = 350, boundaryGap = true, showXAxis = true, showXAxisTicks = true, showYAxis = true, showYAxisTicks = true, showXAxisSplitLines = true, showYAxisSplitLines = true, grid, showLegend = false, showHighlighter = true, positiveColor = '#008000', negativeColor = '#FF2C2C', xAxisTickLabelFormatter, yAxisTickLabelFormatter, xAxisLabel, yAxisLabel, minX, maxX, intervalX, minY, maxY, intervalY, onSelect, ...props }) => {
|
|
18
19
|
const { theme } = useChartTheme(props.theme, undefined);
|
|
19
20
|
const chartRef = useRef(null);
|
|
20
21
|
const onSelectRef = useRef(onSelect);
|
|
21
22
|
onSelectRef.current = onSelect;
|
|
22
23
|
const selectContextRef = useRef({ categories: [], ohlcData: [] });
|
|
23
24
|
const categories = useMemo(() => {
|
|
24
|
-
if (xAxisTicks != null && xAxisTicks.length > 0)
|
|
25
|
-
return xAxisTicks;
|
|
26
25
|
if (xAxisData?.length)
|
|
27
26
|
return xAxisData.map(String);
|
|
28
27
|
return data.map((_, i) => String(i));
|
|
29
|
-
}, [
|
|
28
|
+
}, [xAxisData, data]);
|
|
30
29
|
const hasVolume = volumeData != null && volumeData.length > 0;
|
|
31
30
|
const hasMA = (ma5?.length ?? 0) > 0 || (ma10?.length ?? 0) > 0 || (ma20?.length ?? 0) > 0;
|
|
32
31
|
selectContextRef.current = { categories, ohlcData: data };
|
|
33
32
|
const option = useMemo(() => {
|
|
34
33
|
if (!data?.length)
|
|
35
34
|
return { series: [] };
|
|
35
|
+
const valueAxisBounds = valueAxisBoundsFromProps({ minY, maxY, intervalY });
|
|
36
|
+
const xAxisBounds = xAxisBoundsFromProps({ minX, maxX, intervalX });
|
|
36
37
|
const tooltipConfig = showHighlighter
|
|
37
38
|
? {
|
|
38
39
|
trigger: 'axis',
|
|
@@ -66,13 +67,14 @@ const ChartComponent = ({ data, xAxisData, volumeData, ma5, ma10, ma20, width =
|
|
|
66
67
|
? { show: true, lineStyle: { color: theme.axis.x.lineColor, width: theme.axis.x.lineWidth } }
|
|
67
68
|
: { show: false },
|
|
68
69
|
axisTick: {
|
|
69
|
-
show: showXAxisTicks,
|
|
70
|
+
show: showXAxis && showXAxisTicks,
|
|
70
71
|
lineStyle: { color: theme.axis.x.tickColor, width: theme.axis.x.tickWidth },
|
|
71
72
|
},
|
|
72
73
|
splitLine: {
|
|
73
74
|
show: showXAxisSplitLines,
|
|
74
75
|
lineStyle: { color: theme.axis.x.splitLineColor, width: theme.axis.x.splitLineWidth },
|
|
75
76
|
},
|
|
77
|
+
...(xAxisBounds ?? {}),
|
|
76
78
|
};
|
|
77
79
|
if (hasVolume) {
|
|
78
80
|
xAxisMain.gridIndex = 0;
|
|
@@ -80,7 +82,7 @@ const ChartComponent = ({ data, xAxisData, volumeData, ma5, ma10, ma20, width =
|
|
|
80
82
|
}
|
|
81
83
|
const yAxisMain = {
|
|
82
84
|
type: 'value',
|
|
83
|
-
scale: true,
|
|
85
|
+
...(valueAxisBounds ?? { scale: true }),
|
|
84
86
|
...(yAxisLabel != null && yAxisLabel !== '' && {
|
|
85
87
|
name: yAxisLabel,
|
|
86
88
|
nameLocation: 'middle',
|
|
@@ -96,7 +98,7 @@ const ChartComponent = ({ data, xAxisData, volumeData, ma5, ma10, ma20, width =
|
|
|
96
98
|
? { show: true, lineStyle: { color: theme.axis.y.lineColor, width: theme.axis.y.lineWidth } }
|
|
97
99
|
: { show: false },
|
|
98
100
|
axisTick: {
|
|
99
|
-
show: showYAxisTicks,
|
|
101
|
+
show: showYAxis && showYAxisTicks,
|
|
100
102
|
lineStyle: { color: theme.axis.y.tickColor, width: theme.axis.y.tickWidth },
|
|
101
103
|
},
|
|
102
104
|
splitLine: {
|
|
@@ -230,9 +232,14 @@ const ChartComponent = ({ data, xAxisData, volumeData, ma5, ma10, ma20, width =
|
|
|
230
232
|
negativeColor,
|
|
231
233
|
xAxisTickLabelFormatter,
|
|
232
234
|
yAxisTickLabelFormatter,
|
|
233
|
-
xAxisTicks,
|
|
234
235
|
xAxisLabel,
|
|
235
236
|
yAxisLabel,
|
|
237
|
+
minX,
|
|
238
|
+
maxX,
|
|
239
|
+
intervalX,
|
|
240
|
+
minY,
|
|
241
|
+
maxY,
|
|
242
|
+
intervalY,
|
|
236
243
|
]);
|
|
237
244
|
useEffect(() => {
|
|
238
245
|
let chart;
|
|
@@ -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;AAqoB7D,eAAO,MAAM,WAAW;;;;;;;CAEtB,CAAC"}
|