@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
package/column/column-chart.js
CHANGED
|
@@ -5,7 +5,9 @@ import { BarChart as EChartsBarChart } 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 {
|
|
8
|
+
import { View } from 'react-native';
|
|
9
|
+
import { getAxis, valueAxisBoundsFromProps, xAxisBoundsFromProps } from '../axis';
|
|
10
|
+
import { createAxisTooltipPreset, useAxisTooltip } from '../cartesian/tooltip';
|
|
9
11
|
echarts.use([
|
|
10
12
|
TooltipComponent,
|
|
11
13
|
GridComponent,
|
|
@@ -13,12 +15,44 @@ echarts.use([
|
|
|
13
15
|
SkiaRenderer,
|
|
14
16
|
EChartsBarChart,
|
|
15
17
|
]);
|
|
16
|
-
|
|
18
|
+
/** Stable identity for default `cornerRadius` (inline `[4,4,0,0]` in params is a new array every render). */
|
|
19
|
+
const DEFAULT_COLUMN_CORNER_RADIUS = [4, 4, 0, 0];
|
|
20
|
+
function columnCornerRadiusDep(value) {
|
|
21
|
+
if (typeof value === 'number')
|
|
22
|
+
return value;
|
|
23
|
+
if (Array.isArray(value))
|
|
24
|
+
return value.join(',');
|
|
25
|
+
return '4,4,0,0';
|
|
26
|
+
}
|
|
27
|
+
const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, cornerRadius = DEFAULT_COLUMN_CORNER_RADIUS, horizontal = false, stack, stackNormalize = false, activeIndex, activeColor, barInsideLabelPosition = 'start', barInsideLabelFormatter, barOutsideLabelPosition = 'start', barOutsideLabelFormatter, itemStyle, showXAxis = true, showXAxisTicks = true, showYAxis = true, showYAxisTicks = true, showXAxisSplitLines = true, showYAxisSplitLines = true, grid, showLegend = false, showHighlighter = false, tooltip = 'card', xAxisTickLabelFormatter, yAxisTickLabelFormatter, xAxisLabel, yAxisLabel, minX, maxX, intervalX, minY, maxY, intervalY, onSelect, renderTooltip, ...props }) => {
|
|
17
28
|
const { theme } = useChartTheme(props.theme, props.colors);
|
|
18
29
|
const chartRef = useRef(null);
|
|
19
30
|
const onSelectRef = useRef(onSelect);
|
|
20
31
|
onSelectRef.current = onSelect;
|
|
21
|
-
const selectContextRef = useRef({
|
|
32
|
+
const selectContextRef = useRef({
|
|
33
|
+
displaySeries: [],
|
|
34
|
+
categoryAxisData: [],
|
|
35
|
+
labelOverlayDuplicate: false,
|
|
36
|
+
categoryAxisIsY: false,
|
|
37
|
+
});
|
|
38
|
+
const themeSeriesRef = useRef(theme.series);
|
|
39
|
+
themeSeriesRef.current = theme.series;
|
|
40
|
+
const tooltipOverlayActive = renderTooltip != null || tooltip !== 'none';
|
|
41
|
+
const renderTooltipFn = useMemo(() => {
|
|
42
|
+
if (renderTooltip != null)
|
|
43
|
+
return renderTooltip;
|
|
44
|
+
if (tooltip === 'none')
|
|
45
|
+
return () => null;
|
|
46
|
+
return createAxisTooltipPreset(tooltip);
|
|
47
|
+
}, [renderTooltip, tooltip]);
|
|
48
|
+
const { attachAxisTooltipListeners, renderAxisTooltipOverlay } = useAxisTooltip({
|
|
49
|
+
active: tooltipOverlayActive,
|
|
50
|
+
renderTooltip: renderTooltipFn,
|
|
51
|
+
contextRef: selectContextRef,
|
|
52
|
+
themeSeriesRef,
|
|
53
|
+
width,
|
|
54
|
+
height,
|
|
55
|
+
});
|
|
22
56
|
const normalizedSeries = useMemo(() => {
|
|
23
57
|
let normalizedData = [];
|
|
24
58
|
if (!Array.isArray(data) || data.length === 0)
|
|
@@ -82,34 +116,31 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
82
116
|
};
|
|
83
117
|
});
|
|
84
118
|
}, [normalizedSeries, stackNormalize]);
|
|
119
|
+
const valueAxisBounds = useMemo(() => valueAxisBoundsFromProps({ minY, maxY, intervalY }), [minY, maxY, intervalY]);
|
|
120
|
+
const xAxisBounds = useMemo(() => xAxisBoundsFromProps({ minX, maxX, intervalX }), [minX, maxX, intervalX]);
|
|
85
121
|
const showLabelInside = barInsideLabelFormatter != null;
|
|
86
122
|
const showLabelOutside = barOutsideLabelFormatter != null;
|
|
87
123
|
const isSingleSeries = displaySeries.length === 1;
|
|
88
124
|
const labelOverlayDuplicate = showLabelInside && showLabelOutside && isSingleSeries;
|
|
89
|
-
|
|
90
|
-
const option = useMemo(() => {
|
|
125
|
+
const categoryAxisData = useMemo(() => {
|
|
91
126
|
const categories = (displaySeries[0]?.data ?? []).map((item) => String(item[0]));
|
|
92
127
|
const dataPoints = displaySeries.flatMap((s) => s.data.map((d) => d[1]));
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
color: 'rgba(0,0,0,0.08)',
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
: { trigger: 'axis' };
|
|
128
|
+
return categories.length > 0 ? categories : getAxis(dataPoints).map(String);
|
|
129
|
+
}, [displaySeries]);
|
|
130
|
+
selectContextRef.current = {
|
|
131
|
+
displaySeries,
|
|
132
|
+
categoryAxisData,
|
|
133
|
+
labelOverlayDuplicate,
|
|
134
|
+
categoryAxisIsY: horizontal,
|
|
135
|
+
};
|
|
136
|
+
const option = useMemo(() => {
|
|
137
|
+
const categories = (displaySeries[0]?.data ?? []).map((item) => String(item[0]));
|
|
138
|
+
const xAxisData = categoryAxisData;
|
|
109
139
|
const categoryAxisConfig = {
|
|
110
140
|
type: 'category',
|
|
111
141
|
data: xAxisData,
|
|
112
142
|
boundaryGap,
|
|
143
|
+
...(!horizontal ? (xAxisBounds ?? {}) : {}),
|
|
113
144
|
...((horizontal ? yAxisLabel : xAxisLabel) != null && (horizontal ? yAxisLabel : xAxisLabel) !== '' && {
|
|
114
145
|
name: horizontal ? yAxisLabel : xAxisLabel,
|
|
115
146
|
nameLocation: 'middle',
|
|
@@ -145,13 +176,15 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
145
176
|
},
|
|
146
177
|
},
|
|
147
178
|
};
|
|
179
|
+
const stackPct = stackNormalize && displaySeries.length > 1;
|
|
180
|
+
const valueAxisNumericExtras = stackPct
|
|
181
|
+
? { min: 0, max: 100 }
|
|
182
|
+
: horizontal
|
|
183
|
+
? { ...(valueAxisBounds ?? {}), ...(xAxisBounds ?? {}) }
|
|
184
|
+
: (valueAxisBounds ?? {});
|
|
148
185
|
const valueAxisConfig = {
|
|
149
186
|
type: 'value',
|
|
150
|
-
...
|
|
151
|
-
displaySeries.length > 1 && {
|
|
152
|
-
min: 0,
|
|
153
|
-
max: 100,
|
|
154
|
-
}),
|
|
187
|
+
...valueAxisNumericExtras,
|
|
155
188
|
...((horizontal ? xAxisLabel : yAxisLabel) != null && (horizontal ? xAxisLabel : yAxisLabel) !== '' && {
|
|
156
189
|
name: horizontal ? xAxisLabel : yAxisLabel,
|
|
157
190
|
nameLocation: 'middle',
|
|
@@ -368,10 +401,23 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
368
401
|
seriesConfig.push(labelOnlySeries);
|
|
369
402
|
}
|
|
370
403
|
const config = {
|
|
371
|
-
tooltip: tooltipConfig,
|
|
372
404
|
xAxis: xAxisConfig,
|
|
373
405
|
yAxis: yAxisConfig,
|
|
374
406
|
series: seriesConfig,
|
|
407
|
+
axisPointer: {
|
|
408
|
+
show: true,
|
|
409
|
+
type: 'line',
|
|
410
|
+
snap: true,
|
|
411
|
+
lineStyle: {
|
|
412
|
+
type: 'solid',
|
|
413
|
+
width: 1,
|
|
414
|
+
color: '#00000000',
|
|
415
|
+
show: false,
|
|
416
|
+
},
|
|
417
|
+
label: {
|
|
418
|
+
show: false,
|
|
419
|
+
},
|
|
420
|
+
},
|
|
375
421
|
};
|
|
376
422
|
if (legendConfig)
|
|
377
423
|
config.legend = legendConfig;
|
|
@@ -383,7 +429,7 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
383
429
|
normalizedSeries,
|
|
384
430
|
displaySeries,
|
|
385
431
|
boundaryGap,
|
|
386
|
-
cornerRadius,
|
|
432
|
+
columnCornerRadiusDep(cornerRadius),
|
|
387
433
|
horizontal,
|
|
388
434
|
stack,
|
|
389
435
|
stackNormalize,
|
|
@@ -404,18 +450,23 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
404
450
|
showLegend,
|
|
405
451
|
hasNamedSeries,
|
|
406
452
|
showHighlighter,
|
|
453
|
+
tooltipOverlayActive,
|
|
407
454
|
xAxisTickLabelFormatter,
|
|
408
455
|
yAxisTickLabelFormatter,
|
|
409
|
-
xAxisTicks,
|
|
410
456
|
xAxisLabel,
|
|
411
457
|
yAxisLabel,
|
|
458
|
+
categoryAxisData,
|
|
459
|
+
valueAxisBounds,
|
|
460
|
+
xAxisBounds,
|
|
412
461
|
]);
|
|
413
462
|
useEffect(() => {
|
|
414
463
|
let chart;
|
|
464
|
+
let detachAxisTooltip = () => { };
|
|
415
465
|
if (chartRef.current) {
|
|
416
466
|
try {
|
|
417
467
|
chart = echarts.init(chartRef.current, 'light', { width, height });
|
|
418
468
|
chart.setOption(option);
|
|
469
|
+
detachAxisTooltip = attachAxisTooltipListeners(chart);
|
|
419
470
|
const handleSeriesClick = (params) => {
|
|
420
471
|
const cb = onSelectRef.current;
|
|
421
472
|
if (typeof cb !== 'function')
|
|
@@ -463,6 +514,7 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
463
514
|
}
|
|
464
515
|
}
|
|
465
516
|
return () => {
|
|
517
|
+
detachAxisTooltip();
|
|
466
518
|
if (chart) {
|
|
467
519
|
try {
|
|
468
520
|
chart.dispose();
|
|
@@ -472,8 +524,11 @@ const ChartComponent = ({ data, width = 220, height = 350, boundaryGap = true, c
|
|
|
472
524
|
}
|
|
473
525
|
}
|
|
474
526
|
};
|
|
475
|
-
}, [option, width, height]);
|
|
476
|
-
return <
|
|
527
|
+
}, [option, width, height, attachAxisTooltipListeners]);
|
|
528
|
+
return (<View style={{ width, height, position: 'relative' }}>
|
|
529
|
+
<SkiaChart ref={chartRef} useRNGH/>
|
|
530
|
+
{renderAxisTooltipOverlay()}
|
|
531
|
+
</View>);
|
|
477
532
|
};
|
|
478
533
|
const ColumnChartComponent = withResponsiveContainer(withChartTheme(ChartComponent));
|
|
479
534
|
export const ColumnChart = Object.assign(ColumnChartComponent, {
|
package/geo/geo-chart.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo-chart.d.ts","sourceRoot":"","sources":["../../../../components/chart/geo/geo-chart.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geo-chart.d.ts","sourceRoot":"","sources":["../../../../components/chart/geo/geo-chart.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAoC,MAAM,mBAAmB,CAAC;AAOzF,OAAO,KAAgE,MAAM,OAAO,CAAC;AAGrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAErG,2GAA2G;AAC3G,eAAO,MAAM,iBAAiB,kCAAyC,CAAC;AA0PxE,eAAO,MAAM,QAAQ;;;;;;;CAEnB,CAAC"}
|
package/geo/geo-chart.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { withResponsiveContainer } from '../chart-container';
|
|
2
2
|
import { useChartTheme, withChartTheme } from '../chart-theme.context';
|
|
3
|
+
import { axisTooltipShowContentFlag } from '../cartesian/tooltip';
|
|
4
|
+
import { createGeoTooltipPreset, useGeoItemTooltip } from './tooltip';
|
|
3
5
|
import { SkiaChart, SkiaRenderer } from '@wuba/react-native-echarts';
|
|
4
6
|
import { MapChart } from 'echarts/charts';
|
|
5
7
|
import { TooltipComponent, VisualMapComponent } from 'echarts/components';
|
|
6
8
|
import * as echarts from 'echarts/core';
|
|
7
9
|
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
|
|
8
|
-
import
|
|
10
|
+
import { View } from 'react-native';
|
|
11
|
+
import worldJson from './world.json';
|
|
9
12
|
/** Optional context to provide mapJson without passing as prop (avoids Storybook serialization issues). */
|
|
10
13
|
export const GeoMapJsonContext = createContext(null);
|
|
11
14
|
echarts.use([
|
|
@@ -15,13 +18,41 @@ echarts.use([
|
|
|
15
18
|
MapChart,
|
|
16
19
|
]);
|
|
17
20
|
const DEFAULT_MAP_NAME = 'world';
|
|
18
|
-
const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME, width = 400, height = 300, showLegend = true, showHighlighter = true,
|
|
21
|
+
const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME, width = 400, height = 300, showLegend = true, showHighlighter = true, tooltip = 'card', renderTooltip, visualMapMin, visualMapMax, visualMapMode = 'continuous', piecewisePieces, onSelect, ...props }) => {
|
|
19
22
|
const { theme } = useChartTheme(props.theme, props.colors);
|
|
20
23
|
const chartRef = useRef(null);
|
|
21
24
|
const onSelectRef = useRef(onSelect);
|
|
22
25
|
onSelectRef.current = onSelect;
|
|
26
|
+
const geoContextRef = useRef({ regions: [] });
|
|
27
|
+
const themeSeriesRef = useRef(theme.series);
|
|
28
|
+
themeSeriesRef.current = theme.series;
|
|
23
29
|
const contextMapJson = useContext(GeoMapJsonContext);
|
|
24
30
|
const mapJson = mapJsonProp ?? contextMapJson ?? worldJson;
|
|
31
|
+
const tooltipOverlayActive = renderTooltip != null || tooltip !== 'none';
|
|
32
|
+
const renderTooltipFn = useMemo(() => {
|
|
33
|
+
if (renderTooltip != null)
|
|
34
|
+
return renderTooltip;
|
|
35
|
+
if (tooltip === 'none')
|
|
36
|
+
return () => null;
|
|
37
|
+
return createGeoTooltipPreset(tooltip);
|
|
38
|
+
}, [renderTooltip, tooltip]);
|
|
39
|
+
const { attachGeoItemTooltipListeners, renderGeoTooltipOverlay } = useGeoItemTooltip({
|
|
40
|
+
active: tooltipOverlayActive,
|
|
41
|
+
renderTooltip: renderTooltipFn,
|
|
42
|
+
contextRef: geoContextRef,
|
|
43
|
+
themeSeriesRef,
|
|
44
|
+
width,
|
|
45
|
+
height,
|
|
46
|
+
});
|
|
47
|
+
const tooltipRegions = useMemo(() => {
|
|
48
|
+
if (!Array.isArray(data) || data.length === 0)
|
|
49
|
+
return [];
|
|
50
|
+
return data.map((d) => ({
|
|
51
|
+
name: String(d.name),
|
|
52
|
+
value: Number(d.value),
|
|
53
|
+
}));
|
|
54
|
+
}, [data]);
|
|
55
|
+
geoContextRef.current = { regions: tooltipRegions };
|
|
25
56
|
useEffect(() => {
|
|
26
57
|
if (mapJson?.type === 'FeatureCollection' && mapJson.features?.length) {
|
|
27
58
|
try {
|
|
@@ -47,20 +78,12 @@ const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME
|
|
|
47
78
|
return { series: [{ type: 'map', map: mapName, data: [] }] };
|
|
48
79
|
}
|
|
49
80
|
const seriesColor = theme.series[0]?.color ?? '#3b82f6';
|
|
50
|
-
const tooltipConfig =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
: undefined,
|
|
58
|
-
backgroundColor: theme.tooltip.backgroundColor,
|
|
59
|
-
borderColor: theme.tooltip.borderColor,
|
|
60
|
-
borderWidth: theme.tooltip.borderWidth,
|
|
61
|
-
borderRadius: theme.tooltip.borderRadius,
|
|
62
|
-
padding: theme.tooltip.padding,
|
|
63
|
-
};
|
|
81
|
+
const tooltipConfig = tooltipOverlayActive
|
|
82
|
+
? {
|
|
83
|
+
trigger: 'item',
|
|
84
|
+
...axisTooltipShowContentFlag(true),
|
|
85
|
+
}
|
|
86
|
+
: { show: false };
|
|
64
87
|
const visualMapConfig = showLegend
|
|
65
88
|
? visualMapMode === 'piecewise' && piecewisePieces?.length
|
|
66
89
|
? {
|
|
@@ -112,15 +135,18 @@ const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME
|
|
|
112
135
|
},
|
|
113
136
|
emphasis: showHighlighter
|
|
114
137
|
? {
|
|
138
|
+
focus: 'none',
|
|
115
139
|
itemStyle: {
|
|
116
|
-
areaColor: seriesColor,
|
|
117
140
|
borderColor: '#333',
|
|
118
141
|
borderWidth: 1,
|
|
119
142
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
143
|
+
// Avoid duplicating the region name when the RN tooltip is active.
|
|
144
|
+
label: tooltipOverlayActive
|
|
145
|
+
? { show: false }
|
|
146
|
+
: {
|
|
147
|
+
show: true,
|
|
148
|
+
color: theme.legend.textColor,
|
|
149
|
+
},
|
|
124
150
|
}
|
|
125
151
|
: { disabled: true },
|
|
126
152
|
};
|
|
@@ -138,12 +164,13 @@ const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME
|
|
|
138
164
|
valueRange,
|
|
139
165
|
showLegend,
|
|
140
166
|
showHighlighter,
|
|
141
|
-
|
|
167
|
+
tooltipOverlayActive,
|
|
142
168
|
visualMapMode,
|
|
143
169
|
piecewisePieces,
|
|
144
170
|
]);
|
|
145
171
|
useEffect(() => {
|
|
146
172
|
let chart;
|
|
173
|
+
let detachGeoTooltip = () => { };
|
|
147
174
|
if (chartRef.current) {
|
|
148
175
|
try {
|
|
149
176
|
chart = echarts.init(chartRef.current, 'light', {
|
|
@@ -151,6 +178,7 @@ const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME
|
|
|
151
178
|
height,
|
|
152
179
|
});
|
|
153
180
|
chart.setOption(option);
|
|
181
|
+
detachGeoTooltip = attachGeoItemTooltipListeners(chart);
|
|
154
182
|
const handleMapClick = (params) => {
|
|
155
183
|
const cb = onSelectRef.current;
|
|
156
184
|
if (typeof cb !== 'function')
|
|
@@ -182,6 +210,7 @@ const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME
|
|
|
182
210
|
}
|
|
183
211
|
}
|
|
184
212
|
return () => {
|
|
213
|
+
detachGeoTooltip();
|
|
185
214
|
if (chart) {
|
|
186
215
|
try {
|
|
187
216
|
chart.dispose();
|
|
@@ -191,8 +220,11 @@ const ChartComponent = ({ data, mapJson: mapJsonProp, mapName = DEFAULT_MAP_NAME
|
|
|
191
220
|
}
|
|
192
221
|
}
|
|
193
222
|
};
|
|
194
|
-
}, [option, width, height]);
|
|
195
|
-
return <
|
|
223
|
+
}, [option, width, height, attachGeoItemTooltipListeners]);
|
|
224
|
+
return (<View style={{ width, height, position: 'relative' }}>
|
|
225
|
+
<SkiaChart ref={chartRef} useRNGH/>
|
|
226
|
+
{renderGeoTooltipOverlay()}
|
|
227
|
+
</View>);
|
|
196
228
|
};
|
|
197
229
|
const GeoChartComponent = withResponsiveContainer(withChartTheme(ChartComponent));
|
|
198
230
|
export const GeoChart = Object.assign(GeoChartComponent, {
|
package/geo/geo-chart.props.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { CommonChartProps } from '../props/common';
|
|
2
|
+
import type { ChartTooltipOption } from '../tooltip';
|
|
3
|
+
import type { GeoItemTooltipParams } from './tooltip/geo-item-tooltip.types';
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
2
5
|
/** Emitted when the user taps/clicks a map region. */
|
|
3
6
|
export interface GeoChartSelectEvent {
|
|
4
7
|
name: string;
|
|
@@ -59,12 +62,15 @@ export interface GeoChartProps extends CommonChartProps {
|
|
|
59
62
|
*/
|
|
60
63
|
showHighlighter?: boolean;
|
|
61
64
|
/**
|
|
62
|
-
*
|
|
65
|
+
* Built-in region tooltip preset when `renderTooltip` is omitted. Use `none` to hide the overlay.
|
|
66
|
+
* @default 'card'
|
|
63
67
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
tooltip?: ChartTooltipOption;
|
|
69
|
+
/**
|
|
70
|
+
* Overrides the default React Native item tooltip body (see {@link GeoItemTooltipParams}).
|
|
71
|
+
* Takes precedence over {@link tooltip}.
|
|
72
|
+
*/
|
|
73
|
+
renderTooltip?: (params: GeoItemTooltipParams) => ReactNode;
|
|
68
74
|
/**
|
|
69
75
|
* Minimum value for the visual map scale. Auto-derived from data if not set.
|
|
70
76
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo-chart.props.d.ts","sourceRoot":"","sources":["../../../../components/chart/geo/geo-chart.props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"geo-chart.props.d.ts","sourceRoot":"","sources":["../../../../components/chart/geo/geo-chart.props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,sDAAsD;AACtD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,OAAO,CAAA;SAAE,CAAC;QACjD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACtC,CAAC,CAAC;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD;;;OAGG;IACH,IAAI,EAAE,WAAW,EAAE,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,SAAS,CAAC;IAC5D;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAC3C;;;OAGG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpF;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACjD"}
|
package/geo/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { GeoChart, GeoMapJsonContext } from './geo-chart';
|
|
|
2
2
|
export { USChart } from './us-chart';
|
|
3
3
|
export { WorldChart } from './world-chart';
|
|
4
4
|
export type { GeoChartProps, GeoChartSelectEvent, GeoDataItem, GeoJSONMap, } from './geo-chart.props';
|
|
5
|
+
export * from './tooltip';
|
|
5
6
|
export type { USChartProps } from './us-chart';
|
|
6
7
|
export type { WorldChartProps } from './world-chart';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/geo/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/chart/geo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/chart/geo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
package/geo/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartTheme } from '../../chart-theme.context';
|
|
3
|
+
import type { GeoItemTooltipParams } from './geo-item-tooltip.types';
|
|
4
|
+
/** Themed default geo / map item tooltip (React Native). */
|
|
5
|
+
export declare function createDefaultGeoTooltip(theme: Pick<ChartTheme, 'tooltip'>): (params: GeoItemTooltipParams) => React.ReactElement;
|
|
6
|
+
//# sourceMappingURL=default-geo-tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-geo-tooltip.d.ts","sourceRoot":"","sources":["../../../../../components/chart/geo/tooltip/default-geo-tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,4DAA4D;AAC5D,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GACjC,CAAC,MAAM,EAAE,oBAAoB,KAAK,KAAK,CAAC,YAAY,CA6BtD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
/** Themed default geo / map item tooltip (React Native). */
|
|
4
|
+
export function createDefaultGeoTooltip(theme) {
|
|
5
|
+
const t = theme.tooltip;
|
|
6
|
+
return function DefaultGeoTooltip(params) {
|
|
7
|
+
const { name, value, color } = params;
|
|
8
|
+
return (<View style={{
|
|
9
|
+
backgroundColor: t.backgroundColor,
|
|
10
|
+
borderColor: t.borderColor,
|
|
11
|
+
borderWidth: t.borderWidth,
|
|
12
|
+
borderRadius: t.borderRadius,
|
|
13
|
+
padding: t.padding,
|
|
14
|
+
}}>
|
|
15
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 4 }}>
|
|
16
|
+
{color != null && color !== '' ? (<View style={[styles.swatch, { backgroundColor: color }]}/>) : (<View style={styles.swatchPlaceholder}/>)}
|
|
17
|
+
<Text style={[styles.title, { color: t.labelColor }]}>{name}</Text>
|
|
18
|
+
</View>
|
|
19
|
+
<Text style={[styles.line, { color: t.valueColor }]}>
|
|
20
|
+
<Text style={{ color: t.labelColor }}>value: </Text>
|
|
21
|
+
{String(value)}
|
|
22
|
+
</Text>
|
|
23
|
+
</View>);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const styles = StyleSheet.create({
|
|
27
|
+
title: {
|
|
28
|
+
fontWeight: '600',
|
|
29
|
+
fontSize: 13,
|
|
30
|
+
flex: 1,
|
|
31
|
+
},
|
|
32
|
+
line: {
|
|
33
|
+
fontSize: 12,
|
|
34
|
+
marginTop: 2,
|
|
35
|
+
},
|
|
36
|
+
swatch: {
|
|
37
|
+
width: 8,
|
|
38
|
+
height: 8,
|
|
39
|
+
borderRadius: 4,
|
|
40
|
+
marginRight: 6,
|
|
41
|
+
},
|
|
42
|
+
swatchPlaceholder: {
|
|
43
|
+
width: 8,
|
|
44
|
+
height: 8,
|
|
45
|
+
marginRight: 6,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartTooltipPreset } from '../../tooltip';
|
|
3
|
+
import type { GeoItemTooltipParams } from './geo-item-tooltip.types';
|
|
4
|
+
export declare function createGeoTooltipPreset(preset: ChartTooltipPreset): (params: GeoItemTooltipParams) => React.ReactElement;
|
|
5
|
+
//# sourceMappingURL=geo-item-tooltip-presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo-item-tooltip-presets.d.ts","sourceRoot":"","sources":["../../../../../components/chart/geo/tooltip/geo-item-tooltip-presets.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAOxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AA2CrE,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,kBAAkB,GACzB,CAAC,MAAM,EAAE,oBAAoB,KAAK,KAAK,CAAC,YAAY,CAYtD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
import { TooltipPresetCard, TooltipPresetCompact, TooltipPresetKpi, TooltipPresetStriped, } from '../../tooltip/chart-tooltip-preset-shells';
|
|
4
|
+
function geoCardFromParams(p) {
|
|
5
|
+
const { name, value, color } = p;
|
|
6
|
+
return (<TooltipPresetCard minWidth={140} header={{ swatchColor: color, title: name, titleVariant: 'emphasis', marginBottom: 6 }}>
|
|
7
|
+
<Text style={{ fontSize: 20, fontWeight: '800', color: '#0f172a' }}>{String(value)}</Text>
|
|
8
|
+
<Text style={{ fontSize: 11, color: '#64748b', marginTop: 4 }}>Value</Text>
|
|
9
|
+
</TooltipPresetCard>);
|
|
10
|
+
}
|
|
11
|
+
function geoCompactFromParams(p) {
|
|
12
|
+
const { name, value } = p;
|
|
13
|
+
return <TooltipPresetCompact emphasis={name} detail={String(value)} wrap={false}/>;
|
|
14
|
+
}
|
|
15
|
+
function geoKpiFromParams(p) {
|
|
16
|
+
const { name, value, color } = p;
|
|
17
|
+
return (<TooltipPresetKpi accentColor={color ?? '#3b82f6'} minWidth={140} overline={name} metric={String(value)} caption="Region value"/>);
|
|
18
|
+
}
|
|
19
|
+
function geoStripedFromParams(p) {
|
|
20
|
+
const { name, value, color } = p;
|
|
21
|
+
return (<TooltipPresetStriped headerSwatch={{ color: color ?? '#64748b', title: name }} rows={[{ key: 'value', leftLabel: 'value', right: String(value) }]}/>);
|
|
22
|
+
}
|
|
23
|
+
export function createGeoTooltipPreset(preset) {
|
|
24
|
+
switch (preset) {
|
|
25
|
+
case 'card':
|
|
26
|
+
return (p) => geoCardFromParams(p);
|
|
27
|
+
case 'compact':
|
|
28
|
+
return (p) => geoCompactFromParams(p);
|
|
29
|
+
case 'kpi':
|
|
30
|
+
return (p) => geoKpiFromParams(p);
|
|
31
|
+
case 'striped':
|
|
32
|
+
return (p) => geoStripedFromParams(p);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Unknown tooltip preset: ${String(preset)}`);
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Item tooltip for map / geo (`trigger: 'item'`, `series.type` === `map`).
|
|
3
|
+
*/
|
|
4
|
+
export interface GeoItemTooltipParams {
|
|
5
|
+
pointerX: number;
|
|
6
|
+
pointerY: number;
|
|
7
|
+
/** Region name (matches map feature / data `name`). */
|
|
8
|
+
name: string;
|
|
9
|
+
value: number;
|
|
10
|
+
color?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface GeoItemTooltipContext {
|
|
13
|
+
/** Normalized `{ name, value }` rows from chart `data` (for lookup when the event omits value). */
|
|
14
|
+
regions: Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
value: number;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=geo-item-tooltip.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo-item-tooltip.types.d.ts","sourceRoot":"","sources":["../../../../../components/chart/geo/tooltip/geo-item-tooltip.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,mGAAmG;IACnG,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GeoItemTooltipContext, GeoItemTooltipParams } from './geo-item-tooltip.types';
|
|
2
|
+
/**
|
|
3
|
+
* Build geo map item tooltip params from an ECharts `showTip` payload.
|
|
4
|
+
* Ignores axis-style payloads (`dataByCoordSys`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function geoItemParamsFromShowTip(chart: any, evt: any, ctx: GeoItemTooltipContext, themeSeries: Array<{
|
|
7
|
+
color: string;
|
|
8
|
+
}>,
|
|
9
|
+
/** Prefer over region centroid: matches the pointer that drove hover / emphasis. */
|
|
10
|
+
lastZrPointer?: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
} | null): GeoItemTooltipParams | null;
|
|
14
|
+
//# sourceMappingURL=geo-item-tooltip.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo-item-tooltip.utils.d.ts","sourceRoot":"","sources":["../../../../../components/chart/geo/tooltip/geo-item-tooltip.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AA0I5F;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,GAAG,EACV,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,qBAAqB,EAC1B,WAAW,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACrC,oFAAoF;AACpF,aAAa,CAAC,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAC9C,oBAAoB,GAAG,IAAI,CAqE7B"}
|