@wavemaker/react-native-echarts 1.0.0-dev.1 → 1.0.0-dev.11
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 +360 -3
- package/area/area-chart.d.ts +1 -1
- package/area/area-chart.d.ts.map +1 -1
- package/area/area-chart.js +81 -50
- 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 +66 -35
- package/candlestick/candlestick-chart.d.ts.map +1 -1
- package/candlestick/candlestick-chart.js +37 -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 +93 -33
- 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/legend/echarts-legend-layout.d.ts +20 -0
- package/legend/echarts-legend-layout.d.ts.map +1 -0
- package/legend/echarts-legend-layout.js +103 -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 +69 -45
- package/pie/pie-chart.props.d.ts +19 -8
- 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 +50 -13
- package/props/cartesian.d.ts.map +1 -1
- package/props/common.d.ts +2 -0
- package/props/common.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 +59 -12
- package/radar/radar-chart.props.d.ts +20 -2
- 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 +44 -16
- package/radial/radial-chart.props.d.ts +16 -3
- 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 +64 -22
- 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
|
@@ -0,0 +1,39 @@
|
|
|
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 pieCardFromParams(p) {
|
|
5
|
+
const { name, value, percent, color, ringName } = p;
|
|
6
|
+
return (<TooltipPresetCard eyebrow={ringName != null && ringName !== '' ? ringName : undefined} header={{ swatchColor: color, title: name, marginBottom: 6 }}>
|
|
7
|
+
<Text style={{ fontSize: 14, fontWeight: '700', color: '#0f172a' }}>
|
|
8
|
+
{value} <Text style={{ fontWeight: '500', color: '#64748b' }}>({percent.toFixed(1)}%)</Text>
|
|
9
|
+
</Text>
|
|
10
|
+
</TooltipPresetCard>);
|
|
11
|
+
}
|
|
12
|
+
function pieCompactFromParams(p) {
|
|
13
|
+
const { name, value, percent } = p;
|
|
14
|
+
return <TooltipPresetCompact emphasis={name} detail={`${value} (${percent.toFixed(1)}%)`} wrap/>;
|
|
15
|
+
}
|
|
16
|
+
function pieKpiFromParams(p) {
|
|
17
|
+
const { name, value, percent, color } = p;
|
|
18
|
+
return (<TooltipPresetKpi accentColor={color ?? '#3b82f6'} minWidth={140} overline={name} metric={String(value)} caption={`${percent.toFixed(1)}% of total`}/>);
|
|
19
|
+
}
|
|
20
|
+
function pieStripedFromParams(p) {
|
|
21
|
+
const { name, value, percent, color } = p;
|
|
22
|
+
return (<TooltipPresetStriped headerSwatch={{ color: color ?? '#64748b', title: name }} rows={[
|
|
23
|
+
{ key: 'value', leftLabel: 'value', right: String(value) },
|
|
24
|
+
{ key: 'share', leftLabel: 'share', right: `${percent.toFixed(1)}%` },
|
|
25
|
+
]}/>);
|
|
26
|
+
}
|
|
27
|
+
export function createPieTooltipPreset(preset) {
|
|
28
|
+
switch (preset) {
|
|
29
|
+
case 'card':
|
|
30
|
+
return (p) => pieCardFromParams(p);
|
|
31
|
+
case 'compact':
|
|
32
|
+
return (p) => pieCompactFromParams(p);
|
|
33
|
+
case 'kpi':
|
|
34
|
+
return (p) => pieKpiFromParams(p);
|
|
35
|
+
case 'striped':
|
|
36
|
+
return (p) => pieStripedFromParams(p);
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Unknown tooltip preset: ${String(preset)}`);
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Item tooltip payload for pie / donut (ECharts `trigger: 'item'`, `showTip` without `dataByCoordSys`).
|
|
3
|
+
*/
|
|
4
|
+
export interface PieItemTooltipParams {
|
|
5
|
+
pointerX: number;
|
|
6
|
+
pointerY: number;
|
|
7
|
+
seriesIndex: number;
|
|
8
|
+
dataIndex: number;
|
|
9
|
+
/** Slice label */
|
|
10
|
+
name: string;
|
|
11
|
+
value: number;
|
|
12
|
+
/** Share of this pie ring (0–100). */
|
|
13
|
+
percent: number;
|
|
14
|
+
color?: string;
|
|
15
|
+
/** Ring / series display name when concentric or `name` is set on the series. */
|
|
16
|
+
ringName?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface PieItemTooltipContext {
|
|
19
|
+
/** One entry per pie series (single chart has one; concentric has one per ring). */
|
|
20
|
+
normalizedSeries: Array<{
|
|
21
|
+
name?: string;
|
|
22
|
+
data: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
value: number;
|
|
25
|
+
}>;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=pie-item-tooltip.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pie-item-tooltip.types.d.ts","sourceRoot":"","sources":["../../../../../components/chart/pie/tooltip/pie-item-tooltip.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,oFAAoF;IACpF,gBAAgB,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAAC;CAC1F"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PieItemTooltipContext, PieItemTooltipParams } from './pie-item-tooltip.types';
|
|
2
|
+
/**
|
|
3
|
+
* Build pie item tooltip params from an ECharts `showTip` payload and chart instance.
|
|
4
|
+
* Ignores axis-style payloads (`dataByCoordSys`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function pieItemParamsFromShowTip(chart: any, evt: any, ctx: PieItemTooltipContext, themeSeries: Array<{
|
|
7
|
+
color: string;
|
|
8
|
+
}>): PieItemTooltipParams | null;
|
|
9
|
+
//# sourceMappingURL=pie-item-tooltip.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pie-item-tooltip.utils.d.ts","sourceRoot":"","sources":["../../../../../components/chart/pie/tooltip/pie-item-tooltip.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAyE5F;;;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,GACpC,oBAAoB,GAAG,IAAI,CA4D7B"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
function resolveDataIndexInside(data, evt) {
|
|
2
|
+
if (typeof evt?.dataIndexInside === 'number' && !Number.isNaN(evt.dataIndexInside)) {
|
|
3
|
+
return evt.dataIndexInside;
|
|
4
|
+
}
|
|
5
|
+
if (typeof evt?.dataIndex === 'number' && !Number.isNaN(evt.dataIndex)) {
|
|
6
|
+
const mapped = typeof data?.indexOfRawIndex === 'function' ? data.indexOfRawIndex(evt.dataIndex) : evt.dataIndex;
|
|
7
|
+
if (typeof mapped === 'number' && !Number.isNaN(mapped))
|
|
8
|
+
return mapped;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
function pieSectorCenter(data, diInside) {
|
|
13
|
+
const layout = data.getItemLayout?.(diInside);
|
|
14
|
+
if (!layout || !Number.isFinite(layout.cx) || !Number.isFinite(layout.cy))
|
|
15
|
+
return null;
|
|
16
|
+
const cx = Number(layout.cx);
|
|
17
|
+
const cy = Number(layout.cy);
|
|
18
|
+
const r = Number(layout.r);
|
|
19
|
+
const r0 = Number(layout.r0 ?? 0);
|
|
20
|
+
const startAngle = Number(layout.startAngle);
|
|
21
|
+
const endAngle = Number(layout.endAngle);
|
|
22
|
+
if (!Number.isFinite(startAngle) || !Number.isFinite(endAngle))
|
|
23
|
+
return null;
|
|
24
|
+
const mid = (startAngle + endAngle) / 2;
|
|
25
|
+
const avgR = (r0 + r) / 2;
|
|
26
|
+
return {
|
|
27
|
+
x: cx + Math.cos(mid) * avgR,
|
|
28
|
+
y: cy + Math.sin(mid) * avgR,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function pointerFromEventOrSector(chart, evt, seriesModel, data, diInside) {
|
|
32
|
+
const ex = evt?.x;
|
|
33
|
+
const ey = evt?.y;
|
|
34
|
+
if (typeof ex === 'number' && typeof ey === 'number' && !Number.isNaN(ex) && !Number.isNaN(ey)) {
|
|
35
|
+
return { x: ex, y: ey };
|
|
36
|
+
}
|
|
37
|
+
return pieSectorCenter(data, diInside);
|
|
38
|
+
}
|
|
39
|
+
function sliceValueAt(data, diInside) {
|
|
40
|
+
try {
|
|
41
|
+
const dim = typeof data.mapDimension === 'function' ? data.mapDimension('value') : null;
|
|
42
|
+
if (dim != null) {
|
|
43
|
+
const v = data.get(dim, diInside);
|
|
44
|
+
const n = Number(v);
|
|
45
|
+
if (Number.isFinite(n))
|
|
46
|
+
return n;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
/* ignore */
|
|
51
|
+
}
|
|
52
|
+
const v0 = data.get?.(0, diInside);
|
|
53
|
+
const n0 = Number(v0);
|
|
54
|
+
if (Number.isFinite(n0))
|
|
55
|
+
return n0;
|
|
56
|
+
try {
|
|
57
|
+
const n1 = Number(data.get?.('value', diInside));
|
|
58
|
+
if (Number.isFinite(n1))
|
|
59
|
+
return n1;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* ignore */
|
|
63
|
+
}
|
|
64
|
+
return NaN;
|
|
65
|
+
}
|
|
66
|
+
function seriesValueTotal(data) {
|
|
67
|
+
const n = typeof data.count === 'function' ? data.count() : 0;
|
|
68
|
+
let total = 0;
|
|
69
|
+
for (let i = 0; i < n; i++) {
|
|
70
|
+
const v = sliceValueAt(data, i);
|
|
71
|
+
if (Number.isFinite(v))
|
|
72
|
+
total += v;
|
|
73
|
+
}
|
|
74
|
+
return total;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build pie item tooltip params from an ECharts `showTip` payload and chart instance.
|
|
78
|
+
* Ignores axis-style payloads (`dataByCoordSys`).
|
|
79
|
+
*/
|
|
80
|
+
export function pieItemParamsFromShowTip(chart, evt, ctx, themeSeries) {
|
|
81
|
+
if (!chart || !evt)
|
|
82
|
+
return null;
|
|
83
|
+
if (Array.isArray(evt.dataByCoordSys) && evt.dataByCoordSys.length > 0)
|
|
84
|
+
return null;
|
|
85
|
+
const si = evt.seriesIndex;
|
|
86
|
+
if (typeof si !== 'number' || si < 0)
|
|
87
|
+
return null;
|
|
88
|
+
const seriesModel = chart.getModel?.().getSeriesByIndex?.(si);
|
|
89
|
+
const seriesKind = seriesModel?.subType ?? seriesModel?.get?.('type');
|
|
90
|
+
if (!seriesModel || seriesKind !== 'pie')
|
|
91
|
+
return null;
|
|
92
|
+
const data = seriesModel.getData?.();
|
|
93
|
+
if (!data)
|
|
94
|
+
return null;
|
|
95
|
+
const diInside = resolveDataIndexInside(data, evt);
|
|
96
|
+
if (diInside == null || diInside < 0)
|
|
97
|
+
return null;
|
|
98
|
+
const pixel = pointerFromEventOrSector(chart, evt, seriesModel, data, diInside);
|
|
99
|
+
if (!pixel)
|
|
100
|
+
return null;
|
|
101
|
+
const ring = ctx.normalizedSeries[si];
|
|
102
|
+
const row = ring?.data?.[diInside];
|
|
103
|
+
if (!row)
|
|
104
|
+
return null;
|
|
105
|
+
const name = String(data.getName?.(diInside) ?? row.name ?? '');
|
|
106
|
+
const fromModel = sliceValueAt(data, diInside);
|
|
107
|
+
const value = Number.isFinite(fromModel) ? fromModel : Number(row.value);
|
|
108
|
+
const total = seriesValueTotal(data);
|
|
109
|
+
const percent = total > 0 ? (value / total) * 100 : 0;
|
|
110
|
+
let color;
|
|
111
|
+
try {
|
|
112
|
+
const style = data.getItemVisual?.(diInside, 'style');
|
|
113
|
+
const fill = style?.fill;
|
|
114
|
+
if (typeof fill === 'string' && fill !== '')
|
|
115
|
+
color = fill;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* ignore */
|
|
119
|
+
}
|
|
120
|
+
if (color == null) {
|
|
121
|
+
const themeLen = Math.max(themeSeries.length, 1);
|
|
122
|
+
color = themeSeries[diInside % themeLen]?.color;
|
|
123
|
+
}
|
|
124
|
+
const ringNameRaw = seriesModel.get?.('name');
|
|
125
|
+
const ringName = typeof ringNameRaw === 'string' && ringNameRaw !== '' ? ringNameRaw : ring?.name != null && ring.name !== ''
|
|
126
|
+
? String(ring.name)
|
|
127
|
+
: undefined;
|
|
128
|
+
return {
|
|
129
|
+
pointerX: pixel.x,
|
|
130
|
+
pointerY: pixel.y,
|
|
131
|
+
seriesIndex: si,
|
|
132
|
+
dataIndex: diInside,
|
|
133
|
+
name,
|
|
134
|
+
value,
|
|
135
|
+
percent,
|
|
136
|
+
...(typeof color === 'string' ? { color } : {}),
|
|
137
|
+
...(ringName != null ? { ringName } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PieItemTooltipContext, PieItemTooltipParams } from './pie-item-tooltip.types';
|
|
3
|
+
export interface UsePieItemTooltipOptions {
|
|
4
|
+
active: boolean;
|
|
5
|
+
renderTooltip: (params: PieItemTooltipParams) => React.ReactNode;
|
|
6
|
+
contextRef: React.RefObject<PieItemTooltipContext>;
|
|
7
|
+
themeSeriesRef: React.RefObject<Array<{
|
|
8
|
+
color: string;
|
|
9
|
+
}>>;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export interface UsePieItemTooltipResult {
|
|
14
|
+
attachPieItemTooltipListeners: (chart: {
|
|
15
|
+
on: (ev: string, fn: (...args: any[]) => void) => void;
|
|
16
|
+
off: (ev: string, fn: (...args: any[]) => void) => void;
|
|
17
|
+
}) => () => void;
|
|
18
|
+
renderPieTooltipOverlay: () => React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pie / donut item tooltip as React Native UI (`trigger: 'item'`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function usePieItemTooltip(options: UsePieItemTooltipOptions): UsePieItemTooltipResult;
|
|
24
|
+
//# sourceMappingURL=use-pie-item-tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pie-item-tooltip.d.ts","sourceRoot":"","sources":["../../../../../components/chart/pie/tooltip/use-pie-item-tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAG5F,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,KAAK,CAAC,SAAS,CAAC;IACjE,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACnD,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,uBAAuB;IACtC,6BAA6B,EAAE,CAAC,KAAK,EAAE;QACrC,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,uBAAuB,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,uBAAuB,CAiD5F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { ChartPointerTooltipOverlay } from '../../tooltip/chart-pointer-tooltip-overlay';
|
|
3
|
+
import { pieItemParamsFromShowTip } from './pie-item-tooltip.utils';
|
|
4
|
+
/**
|
|
5
|
+
* Pie / donut item tooltip as React Native UI (`trigger: 'item'`).
|
|
6
|
+
*/
|
|
7
|
+
export function usePieItemTooltip(options) {
|
|
8
|
+
const { active, renderTooltip, contextRef, themeSeriesRef, width, height } = options;
|
|
9
|
+
const [params, setParams] = useState(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!active)
|
|
12
|
+
setParams(null);
|
|
13
|
+
}, [active]);
|
|
14
|
+
const attachPieItemTooltipListeners = useCallback((chart) => {
|
|
15
|
+
if (!active)
|
|
16
|
+
return () => { };
|
|
17
|
+
const onShowTip = (evt) => {
|
|
18
|
+
const ctx = contextRef.current;
|
|
19
|
+
if (!ctx?.normalizedSeries?.length) {
|
|
20
|
+
setParams(null);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const next = pieItemParamsFromShowTip(chart, evt, ctx, themeSeriesRef.current ?? []);
|
|
24
|
+
setParams(next);
|
|
25
|
+
};
|
|
26
|
+
const onHideTip = () => setParams(null);
|
|
27
|
+
chart.on('showTip', onShowTip);
|
|
28
|
+
chart.on('hideTip', onHideTip);
|
|
29
|
+
return () => {
|
|
30
|
+
chart.off('showTip', onShowTip);
|
|
31
|
+
chart.off('hideTip', onHideTip);
|
|
32
|
+
};
|
|
33
|
+
}, [active, contextRef, themeSeriesRef]);
|
|
34
|
+
const renderPieTooltipOverlay = useCallback(() => {
|
|
35
|
+
if (!active || params == null)
|
|
36
|
+
return null;
|
|
37
|
+
return (<ChartPointerTooltipOverlay width={width} height={height} pointerX={params.pointerX} pointerY={params.pointerY}>
|
|
38
|
+
{renderTooltip(params)}
|
|
39
|
+
</ChartPointerTooltipOverlay>);
|
|
40
|
+
}, [active, renderTooltip, params, width, height]);
|
|
41
|
+
return {
|
|
42
|
+
attachPieItemTooltipListeners,
|
|
43
|
+
renderPieTooltipOverlay,
|
|
44
|
+
};
|
|
45
|
+
}
|
package/props/cartesian.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { AxisTooltipParams } from '../cartesian/tooltip/axis-tooltip.types';
|
|
3
|
+
import type { ChartTooltipOption } from '../tooltip';
|
|
4
|
+
import type { CommonChartProps, LegendPosition } from './common';
|
|
2
5
|
/**
|
|
3
6
|
* Emitted when the user taps/clicks a series data point on Cartesian-based charts
|
|
4
7
|
* (area, line, column, bar, scatter, bubble, candlestick, etc.).
|
|
@@ -40,23 +43,39 @@ export interface CartesianChartProps extends CommonChartProps {
|
|
|
40
43
|
*/
|
|
41
44
|
boundaryGap?: boolean;
|
|
42
45
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
+
* X-axis minimum when set. Applies to the chart’s **X** axis (category or value, depending on the chart).
|
|
47
|
+
* For horizontal column/bar, the **value** (bar length) scale is on **X** — use `minX` / `maxX` / `intervalX` for that scale.
|
|
48
|
+
* When omitted, the minimum is derived from the data or chosen automatically.
|
|
46
49
|
*/
|
|
47
|
-
|
|
50
|
+
minX?: number;
|
|
48
51
|
/**
|
|
49
|
-
*
|
|
50
|
-
|
|
52
|
+
* X-axis maximum when set. See {@link minX} for layout notes. When omitted, the maximum is derived from the data or chosen automatically.
|
|
53
|
+
*/
|
|
54
|
+
maxX?: number;
|
|
55
|
+
/**
|
|
56
|
+
* X-axis tick interval when set. See {@link minX} for layout notes. When omitted, the tick step is chosen automatically.
|
|
57
|
+
*/
|
|
58
|
+
intervalX?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Y-axis (value scale) minimum when set. Applies to the chart’s **Y** axis.
|
|
61
|
+
* When omitted, the minimum is derived from the data or chosen automatically.
|
|
62
|
+
*/
|
|
63
|
+
minY?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Y-axis (value scale) maximum when set. When omitted, the maximum is derived from the data or chosen automatically.
|
|
66
|
+
*/
|
|
67
|
+
maxY?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Y-axis (value scale) tick interval when set. When omitted, the tick step is chosen automatically.
|
|
51
70
|
*/
|
|
52
|
-
|
|
71
|
+
intervalY?: number;
|
|
53
72
|
/**
|
|
54
73
|
* Whether to show the X-axis line and labels.
|
|
55
74
|
* @default true
|
|
56
75
|
*/
|
|
57
76
|
showXAxis?: boolean;
|
|
58
77
|
/**
|
|
59
|
-
* Whether to show X-axis tick marks.
|
|
78
|
+
* Whether to show X-axis tick marks. Only applies when {@link showXAxis} is true.
|
|
60
79
|
* @default true
|
|
61
80
|
*/
|
|
62
81
|
showXAxisTicks?: boolean;
|
|
@@ -66,7 +85,7 @@ export interface CartesianChartProps extends CommonChartProps {
|
|
|
66
85
|
*/
|
|
67
86
|
showYAxis?: boolean;
|
|
68
87
|
/**
|
|
69
|
-
* Whether to show Y-axis tick marks.
|
|
88
|
+
* Whether to show Y-axis tick marks. Only applies when {@link showYAxis} is true.
|
|
70
89
|
* @default true
|
|
71
90
|
*/
|
|
72
91
|
showYAxisTicks?: boolean;
|
|
@@ -96,14 +115,26 @@ export interface CartesianChartProps extends CommonChartProps {
|
|
|
96
115
|
grid?: CartesianGrid;
|
|
97
116
|
/**
|
|
98
117
|
* Whether to display a legend for named series.
|
|
99
|
-
* @default
|
|
118
|
+
* @default true
|
|
100
119
|
*/
|
|
101
120
|
showLegend?: boolean;
|
|
102
121
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @default
|
|
122
|
+
* Legend position. Top and bottom use a horizontal legend that wraps; left and right use a vertical legend.
|
|
123
|
+
* @default 'bottom'
|
|
124
|
+
*/
|
|
125
|
+
legendPosition?: LegendPosition;
|
|
126
|
+
/**
|
|
127
|
+
* Whether **emphasis** (hover highlight) is applied while the axis pointer / tooltip is near the series.
|
|
128
|
+
* Column and bar charts default this to `false`; area defaults to `true`.
|
|
105
129
|
*/
|
|
106
130
|
showHighlighter?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Built-in axis tooltip preset when `renderTooltip` is omitted (area, line, column, bar). Use `none` to hide the overlay.
|
|
133
|
+
* When `renderTooltip` is set, it replaces the preset body. The overlay is hidden only when `tooltip` is `none` and `renderTooltip` is omitted.
|
|
134
|
+
* Scatter and bubble use the same prop for **item** tooltips.
|
|
135
|
+
* @default 'card'
|
|
136
|
+
*/
|
|
137
|
+
tooltip?: ChartTooltipOption;
|
|
107
138
|
/**
|
|
108
139
|
* Formatter for X-axis tick labels. (value, index?) => string
|
|
109
140
|
*/
|
|
@@ -116,5 +147,11 @@ export interface CartesianChartProps extends CommonChartProps {
|
|
|
116
147
|
* Called when the user selects (taps/clicks) a data point on a series (when supported).
|
|
117
148
|
*/
|
|
118
149
|
onSelect?: (event: CartesianChartSelectEvent) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Overrides the default React Native axis tooltip body for charts that use the axis tooltip overlay (area, line, column, bar).
|
|
152
|
+
* Scatter and bubble charts use item tooltip `renderTooltip` on their own props instead.
|
|
153
|
+
* Takes precedence over {@link tooltip}.
|
|
154
|
+
*/
|
|
155
|
+
renderTooltip?: (params: AxisTooltipParams) => ReactNode;
|
|
119
156
|
}
|
|
120
157
|
//# sourceMappingURL=cartesian.d.ts.map
|
package/props/cartesian.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian.d.ts","sourceRoot":"","sources":["../../../../components/chart/props/cartesian.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"cartesian.d.ts","sourceRoot":"","sources":["../../../../components/chart/props/cartesian.ts"],"names":[],"mappings":"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"}
|
package/props/common.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ChartTheme } from '../chart-theme.context';
|
|
2
|
+
/** Placement of the chart legend (or geo visual map). */
|
|
3
|
+
export type LegendPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
2
4
|
/**
|
|
3
5
|
* Props shared by all chart components (common base).
|
|
4
6
|
* common -> cartesian -> area | bar | scatter -> line (extends area) | bubble (extends scatter)
|
package/props/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../components/chart/props/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../components/chart/props/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,yDAAyD;AACzD,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
package/radar/index.d.ts
CHANGED
package/radar/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/chart/radar/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,eAAe,GAChB,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/chart/radar/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/radar/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radar-chart.d.ts","sourceRoot":"","sources":["../../../../components/chart/radar/radar-chart.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"radar-chart.d.ts","sourceRoot":"","sources":["../../../../components/chart/radar/radar-chart.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,qBAAqB,CAAC;AAe7B,OAAO,KAAqC,MAAM,OAAO,CAAC;AAG1D,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAsQ7B,eAAO,MAAM,UAAU;;;;;;;CAErB,CAAC"}
|
package/radar/radar-chart.js
CHANGED
|
@@ -1,10 +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 { echartsLegendLayoutFragment, radarGeometryForLegend, } from '../legend/echarts-legend-layout';
|
|
5
|
+
import { createRadarTooltipPreset, useRadarItemTooltip } from './tooltip';
|
|
3
6
|
import { SkiaChart, SkiaRenderer } from '@wuba/react-native-echarts';
|
|
4
7
|
import { RadarChart as EChartsRadarChart } from 'echarts/charts';
|
|
5
8
|
import { GridComponent, LegendComponent, TooltipComponent, } from 'echarts/components';
|
|
6
9
|
import * as echarts from 'echarts/core';
|
|
7
10
|
import React, { useEffect, useMemo, useRef } from 'react';
|
|
11
|
+
import { View } from 'react-native';
|
|
8
12
|
echarts.use([
|
|
9
13
|
TooltipComponent,
|
|
10
14
|
GridComponent,
|
|
@@ -27,17 +31,41 @@ function normalizeRadarSeries(data, indicatorCount) {
|
|
|
27
31
|
value: item.value,
|
|
28
32
|
}));
|
|
29
33
|
}
|
|
30
|
-
const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol = 'none', symbolSize, showLegend =
|
|
34
|
+
const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol = 'none', symbolSize, showLegend = true, legendPosition = 'bottom', showHighlighter = true, showIndicatorLabels = true, showSplitLine = true, showAxisLine = true, tooltip = 'card', renderTooltip, onSelect, ...props }) => {
|
|
31
35
|
const { theme } = useChartTheme(props.theme, props.colors);
|
|
32
36
|
const chartRef = useRef(null);
|
|
33
37
|
const onSelectRef = useRef(onSelect);
|
|
34
38
|
onSelectRef.current = onSelect;
|
|
35
|
-
const
|
|
39
|
+
const radarContextRef = useRef({
|
|
40
|
+
indicators: [],
|
|
41
|
+
normalizedSeries: [],
|
|
42
|
+
});
|
|
43
|
+
const themeSeriesRef = useRef(theme.series);
|
|
44
|
+
themeSeriesRef.current = theme.series;
|
|
45
|
+
const tooltipOverlayActive = renderTooltip != null || tooltip !== 'none';
|
|
46
|
+
const renderTooltipFn = useMemo(() => {
|
|
47
|
+
if (renderTooltip != null)
|
|
48
|
+
return renderTooltip;
|
|
49
|
+
if (tooltip === 'none')
|
|
50
|
+
return () => null;
|
|
51
|
+
return createRadarTooltipPreset(tooltip);
|
|
52
|
+
}, [renderTooltip, tooltip]);
|
|
53
|
+
const { attachRadarItemTooltipListeners, renderRadarTooltipOverlay } = useRadarItemTooltip({
|
|
54
|
+
active: tooltipOverlayActive,
|
|
55
|
+
renderTooltip: renderTooltipFn,
|
|
56
|
+
contextRef: radarContextRef,
|
|
57
|
+
themeSeriesRef,
|
|
58
|
+
width,
|
|
59
|
+
height,
|
|
60
|
+
});
|
|
36
61
|
const normalizedSeries = useMemo(() => {
|
|
37
62
|
const count = indicators?.length ?? 0;
|
|
38
63
|
return normalizeRadarSeries(data, count);
|
|
39
64
|
}, [data, indicators?.length]);
|
|
40
|
-
|
|
65
|
+
radarContextRef.current = {
|
|
66
|
+
indicators: (indicators ?? []).map((ind) => ({ name: ind.name })),
|
|
67
|
+
normalizedSeries,
|
|
68
|
+
};
|
|
41
69
|
const indicatorMax = useMemo(() => {
|
|
42
70
|
if (!indicators?.length)
|
|
43
71
|
return [];
|
|
@@ -58,7 +86,9 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
58
86
|
return { series: [] };
|
|
59
87
|
const radarAxis = theme.axis.r;
|
|
60
88
|
const gridStyle = theme.grid.r;
|
|
89
|
+
const hasRadarLegend = showLegend && normalizedSeries.some((s) => s.name);
|
|
61
90
|
const radarConfig = {
|
|
91
|
+
...radarGeometryForLegend(legendPosition, showLegend, hasRadarLegend),
|
|
62
92
|
indicator: indicators.map((ind, i) => ({
|
|
63
93
|
name: ind.name,
|
|
64
94
|
max: indicatorMax[i] ?? ind.max ?? 100,
|
|
@@ -103,14 +133,19 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
103
133
|
lineStyle: { color: seriesColor, width: seriesLineWidth },
|
|
104
134
|
areaStyle: { color: areaColor },
|
|
105
135
|
emphasis: showHighlighter
|
|
106
|
-
? {
|
|
136
|
+
? {
|
|
137
|
+
focus: 'none',
|
|
138
|
+
lineStyle: { width: seriesLineWidth + 1 },
|
|
139
|
+
areaStyle: { opacity: 0.8 },
|
|
140
|
+
}
|
|
107
141
|
: { focus: 'none' },
|
|
108
142
|
};
|
|
109
143
|
}),
|
|
110
144
|
};
|
|
111
|
-
const legendConfig = showLegend && normalizedSeries.some(s => s.name)
|
|
145
|
+
const legendConfig = showLegend && normalizedSeries.some((s) => s.name)
|
|
112
146
|
? {
|
|
113
|
-
data: normalizedSeries.map(s => s.name),
|
|
147
|
+
data: normalizedSeries.map((s) => s.name),
|
|
148
|
+
...echartsLegendLayoutFragment(legendPosition),
|
|
114
149
|
textStyle: {
|
|
115
150
|
color: theme.legend.textColor,
|
|
116
151
|
fontSize: theme.legend.fontSize,
|
|
@@ -118,12 +153,16 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
118
153
|
backgroundColor: theme.legend.backgroundColor,
|
|
119
154
|
}
|
|
120
155
|
: undefined;
|
|
156
|
+
const tooltipConfig = tooltipOverlayActive
|
|
157
|
+
? {
|
|
158
|
+
trigger: 'item',
|
|
159
|
+
...axisTooltipShowContentFlag(true),
|
|
160
|
+
}
|
|
161
|
+
: { show: false };
|
|
121
162
|
const config = {
|
|
122
163
|
radar: radarConfig,
|
|
123
164
|
series: [seriesConfig],
|
|
124
|
-
tooltip:
|
|
125
|
-
trigger: 'item',
|
|
126
|
-
},
|
|
165
|
+
tooltip: tooltipConfig,
|
|
127
166
|
};
|
|
128
167
|
if (legendConfig)
|
|
129
168
|
config.legend = legendConfig;
|
|
@@ -136,13 +175,16 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
136
175
|
symbol,
|
|
137
176
|
symbolSize,
|
|
138
177
|
showLegend,
|
|
178
|
+
legendPosition,
|
|
139
179
|
showHighlighter,
|
|
140
180
|
showIndicatorLabels,
|
|
141
181
|
showSplitLine,
|
|
142
182
|
showAxisLine,
|
|
183
|
+
tooltipOverlayActive,
|
|
143
184
|
]);
|
|
144
185
|
useEffect(() => {
|
|
145
186
|
let chart;
|
|
187
|
+
let detachRadarTooltip = () => { };
|
|
146
188
|
if (chartRef.current) {
|
|
147
189
|
try {
|
|
148
190
|
chart = echarts.init(chartRef.current, 'light', {
|
|
@@ -150,6 +192,7 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
150
192
|
height,
|
|
151
193
|
});
|
|
152
194
|
chart.setOption(option);
|
|
195
|
+
detachRadarTooltip = attachRadarItemTooltipListeners(chart);
|
|
153
196
|
const handleRadarClick = (params) => {
|
|
154
197
|
const cb = onSelectRef.current;
|
|
155
198
|
if (typeof cb !== 'function')
|
|
@@ -161,7 +204,7 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
161
204
|
const dataIndex = params.dataIndex;
|
|
162
205
|
if (typeof dataIndex !== 'number' || dataIndex < 0)
|
|
163
206
|
return;
|
|
164
|
-
const row =
|
|
207
|
+
const row = radarContextRef.current.normalizedSeries[dataIndex];
|
|
165
208
|
if (!row)
|
|
166
209
|
return;
|
|
167
210
|
const event = {
|
|
@@ -179,6 +222,7 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
179
222
|
}
|
|
180
223
|
}
|
|
181
224
|
return () => {
|
|
225
|
+
detachRadarTooltip();
|
|
182
226
|
if (chart) {
|
|
183
227
|
try {
|
|
184
228
|
chart.dispose();
|
|
@@ -188,8 +232,11 @@ const ChartComponent = ({ indicators, data, width = 220, height = 350, symbol =
|
|
|
188
232
|
}
|
|
189
233
|
}
|
|
190
234
|
};
|
|
191
|
-
}, [option, width, height]);
|
|
192
|
-
return <
|
|
235
|
+
}, [option, width, height, attachRadarItemTooltipListeners]);
|
|
236
|
+
return (<View style={{ width, height, position: 'relative' }}>
|
|
237
|
+
<SkiaChart ref={chartRef} useRNGH/>
|
|
238
|
+
{renderRadarTooltipOverlay()}
|
|
239
|
+
</View>);
|
|
193
240
|
};
|
|
194
241
|
const RadarChartComponent = withResponsiveContainer(withChartTheme(ChartComponent));
|
|
195
242
|
export const RadarChart = Object.assign(RadarChartComponent, {
|