@wavemaker/react-native-echarts 1.0.0-dev.1 → 1.0.0-dev.10
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,409 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
import { DARK_THEME, useChartTheme } from '../chart-theme.context';
|
|
4
|
+
function isLightBackground(color) {
|
|
5
|
+
const hex = color.trim().replace(/^#/, '');
|
|
6
|
+
if (!/^[0-9a-f]{3}$|^[0-9a-f]{6}$/i.test(hex))
|
|
7
|
+
return true;
|
|
8
|
+
const h = hex.length === 3 ? hex.split('').map((c) => c + c).join('') : hex;
|
|
9
|
+
const r = parseInt(h.slice(0, 2), 16) / 255;
|
|
10
|
+
const g = parseInt(h.slice(2, 4), 16) / 255;
|
|
11
|
+
const b = parseInt(h.slice(4, 6), 16) / 255;
|
|
12
|
+
const lum = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
13
|
+
return lum > 0.65;
|
|
14
|
+
}
|
|
15
|
+
function hexToRgba(hex, alpha) {
|
|
16
|
+
const h = hex.trim().replace(/^#/, '');
|
|
17
|
+
const full = h.length === 3 ? h.split('').map((c) => c + c).join('') : h;
|
|
18
|
+
if (full.length !== 6)
|
|
19
|
+
return `rgba(15,23,42,${alpha})`;
|
|
20
|
+
const r = parseInt(full.slice(0, 2), 16);
|
|
21
|
+
const g = parseInt(full.slice(2, 4), 16);
|
|
22
|
+
const b = parseInt(full.slice(4, 6), 16);
|
|
23
|
+
return `rgba(${r},${g},${b},${alpha})`;
|
|
24
|
+
}
|
|
25
|
+
function parseHexRgb(hex) {
|
|
26
|
+
const raw = hex.trim().replace(/^#/, '');
|
|
27
|
+
if (!/^[0-9a-f]{3}$|^[0-9a-f]{6}$/i.test(raw))
|
|
28
|
+
return null;
|
|
29
|
+
const full = raw.length === 3 ? raw.split('').map((c) => c + c).join('') : raw;
|
|
30
|
+
if (full.length !== 6)
|
|
31
|
+
return null;
|
|
32
|
+
return {
|
|
33
|
+
r: parseInt(full.slice(0, 2), 16),
|
|
34
|
+
g: parseInt(full.slice(2, 4), 16),
|
|
35
|
+
b: parseInt(full.slice(4, 6), 16),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function rgbToHex(r, g, b) {
|
|
39
|
+
const c = (n) => Math.max(0, Math.min(255, Math.round(n)))
|
|
40
|
+
.toString(16)
|
|
41
|
+
.padStart(2, '0');
|
|
42
|
+
return `#${c(r)}${c(g)}${c(b)}`;
|
|
43
|
+
}
|
|
44
|
+
function rgbMaxChannelDelta(a, b) {
|
|
45
|
+
return Math.max(Math.abs(a.r - b.r), Math.abs(a.g - b.g), Math.abs(a.b - b.b));
|
|
46
|
+
}
|
|
47
|
+
function useTooltipPresetTokens() {
|
|
48
|
+
const { theme } = useChartTheme();
|
|
49
|
+
return useMemo(() => {
|
|
50
|
+
const t = theme.tooltip;
|
|
51
|
+
const ax = theme.axis.x;
|
|
52
|
+
const lightTooltipBg = isLightBackground(t.backgroundColor);
|
|
53
|
+
const dt = DARK_THEME.tooltip;
|
|
54
|
+
const padH = Math.max(12, t.padding * 5);
|
|
55
|
+
const padV = Math.max(10, t.padding * 5);
|
|
56
|
+
const radius = Math.max(8, t.borderRadius);
|
|
57
|
+
const card = {
|
|
58
|
+
shell: {
|
|
59
|
+
alignSelf: 'flex-start',
|
|
60
|
+
paddingHorizontal: padH,
|
|
61
|
+
paddingVertical: padV,
|
|
62
|
+
borderRadius: radius,
|
|
63
|
+
backgroundColor: t.backgroundColor,
|
|
64
|
+
borderWidth: t.borderWidth,
|
|
65
|
+
borderColor: t.borderColor,
|
|
66
|
+
shadowColor: '#000',
|
|
67
|
+
shadowOffset: { width: 0, height: 4 },
|
|
68
|
+
shadowOpacity: 0.12,
|
|
69
|
+
shadowRadius: 8,
|
|
70
|
+
elevation: 4,
|
|
71
|
+
},
|
|
72
|
+
eyebrow: { fontSize: 11, fontWeight: '700', color: t.labelColor, marginBottom: 6 },
|
|
73
|
+
axisCategoryTitle: {
|
|
74
|
+
fontSize: 12,
|
|
75
|
+
fontWeight: '700',
|
|
76
|
+
color: t.labelColor,
|
|
77
|
+
marginBottom: 6,
|
|
78
|
+
},
|
|
79
|
+
cardHeaderTitleSm: { fontSize: 12, fontWeight: '700', color: t.labelColor },
|
|
80
|
+
cardHeaderTitleMd: { fontSize: 13, fontWeight: '700', color: t.valueColor },
|
|
81
|
+
cardSeriesLabel: { fontSize: 14, color: t.labelColor },
|
|
82
|
+
cardSeriesValue: {
|
|
83
|
+
fontSize: 14,
|
|
84
|
+
fontWeight: '700',
|
|
85
|
+
color: t.valueColor,
|
|
86
|
+
flexShrink: 0,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
const kpi = {
|
|
90
|
+
shell: {
|
|
91
|
+
alignSelf: 'flex-start',
|
|
92
|
+
padding: padV,
|
|
93
|
+
borderRadius: radius,
|
|
94
|
+
backgroundColor: t.backgroundColor,
|
|
95
|
+
borderLeftWidth: 4,
|
|
96
|
+
},
|
|
97
|
+
overline: { fontSize: 11, color: t.labelColor, textTransform: 'uppercase' },
|
|
98
|
+
metric: { fontSize: 28, fontWeight: '800', color: t.valueColor, marginTop: 4 },
|
|
99
|
+
caption: { fontSize: 11, color: t.labelColor, marginTop: 2 },
|
|
100
|
+
footerRule: {
|
|
101
|
+
marginTop: 10,
|
|
102
|
+
paddingTop: 10,
|
|
103
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
104
|
+
borderTopColor: t.borderColor,
|
|
105
|
+
},
|
|
106
|
+
footerLeft: { fontSize: 12, color: t.labelColor },
|
|
107
|
+
footerRight: {
|
|
108
|
+
fontSize: 12,
|
|
109
|
+
fontWeight: '600',
|
|
110
|
+
color: t.valueColor,
|
|
111
|
+
flexShrink: 0,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
const compactBg = lightTooltipBg
|
|
115
|
+
? hexToRgba(dt.backgroundColor, 0.92)
|
|
116
|
+
: hexToRgba(t.backgroundColor, 0.95);
|
|
117
|
+
const compactEmph = lightTooltipBg ? dt.valueColor : t.valueColor;
|
|
118
|
+
const compactDetail = lightTooltipBg ? dt.labelColor : t.labelColor;
|
|
119
|
+
const compact = {
|
|
120
|
+
shell: {
|
|
121
|
+
alignSelf: 'flex-start',
|
|
122
|
+
flexDirection: 'row',
|
|
123
|
+
alignItems: 'center',
|
|
124
|
+
paddingVertical: 6,
|
|
125
|
+
paddingHorizontal: 10,
|
|
126
|
+
borderRadius: Math.max(16, radius + 8),
|
|
127
|
+
backgroundColor: compactBg,
|
|
128
|
+
minWidth: 0,
|
|
129
|
+
},
|
|
130
|
+
emphasis: {
|
|
131
|
+
fontSize: 12,
|
|
132
|
+
fontWeight: '700',
|
|
133
|
+
color: compactEmph,
|
|
134
|
+
marginRight: 8,
|
|
135
|
+
flexShrink: 0,
|
|
136
|
+
},
|
|
137
|
+
detail: { fontSize: 12, color: compactDetail },
|
|
138
|
+
};
|
|
139
|
+
const striped = {
|
|
140
|
+
outer: {
|
|
141
|
+
alignSelf: 'flex-start',
|
|
142
|
+
alignItems: 'flex-start',
|
|
143
|
+
borderRadius: Math.max(6, t.borderRadius - 1),
|
|
144
|
+
overflow: 'hidden',
|
|
145
|
+
borderWidth: t.borderWidth,
|
|
146
|
+
borderColor: t.borderColor,
|
|
147
|
+
},
|
|
148
|
+
headerBand: {
|
|
149
|
+
paddingHorizontal: 10,
|
|
150
|
+
paddingVertical: 8,
|
|
151
|
+
backgroundColor: ax.splitLineColor,
|
|
152
|
+
},
|
|
153
|
+
headerTitle: { fontSize: 13, fontWeight: '700', color: t.valueColor },
|
|
154
|
+
rowRight: { fontSize: 13, fontWeight: '600', color: t.valueColor, flexShrink: 0 },
|
|
155
|
+
rowLeftText: { fontSize: 13, color: t.labelColor },
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
t,
|
|
159
|
+
card,
|
|
160
|
+
kpi,
|
|
161
|
+
compact,
|
|
162
|
+
striped,
|
|
163
|
+
};
|
|
164
|
+
}, [theme]);
|
|
165
|
+
}
|
|
166
|
+
/** White card + shadow (axis category + series, or item header + body). */
|
|
167
|
+
export function TooltipPresetCard({ minWidth, eyebrow, categoryTitle, header, seriesRows, keyValueRows, children, }) {
|
|
168
|
+
const { card, t } = useTooltipPresetTokens();
|
|
169
|
+
return (<View style={[card.shell, minWidth != null && { minWidth }]}>
|
|
170
|
+
{eyebrow != null && eyebrow !== '' ? <Text style={card.eyebrow}>{eyebrow}</Text> : null}
|
|
171
|
+
{categoryTitle != null && categoryTitle !== '' ? (<Text style={card.axisCategoryTitle}>{String(categoryTitle)}</Text>) : null}
|
|
172
|
+
{header != null ? (<View style={[styles.cardHeaderRow, { marginBottom: header.marginBottom ?? 8 }]}>
|
|
173
|
+
{header.swatchColor != null && header.swatchColor !== '' ? (<View style={[styles.swatchRound, { backgroundColor: header.swatchColor }]}/>) : null}
|
|
174
|
+
<View style={styles.cardHeaderTitleCell}>
|
|
175
|
+
<Text style={header.titleVariant === 'emphasis' ? card.cardHeaderTitleMd : card.cardHeaderTitleSm}>
|
|
176
|
+
{header.title}
|
|
177
|
+
</Text>
|
|
178
|
+
</View>
|
|
179
|
+
</View>) : null}
|
|
180
|
+
{seriesRows?.map((r) => (<View key={String(r.key)} style={styles.cardSeriesRow}>
|
|
181
|
+
<View style={[styles.swatchRound, { backgroundColor: r.swatchColor }]}/>
|
|
182
|
+
<View style={styles.cardSeriesLabelCell}>
|
|
183
|
+
<Text style={card.cardSeriesLabel}>{r.label}</Text>
|
|
184
|
+
</View>
|
|
185
|
+
<Text style={card.cardSeriesValue}>{r.value}</Text>
|
|
186
|
+
</View>))}
|
|
187
|
+
{keyValueRows?.map((r) => (<View key={r.key} style={styles.kvRow}>
|
|
188
|
+
<View style={styles.kvRowLeftCell}>
|
|
189
|
+
<Text style={[styles.kvRowText, { color: t.labelColor }]}>{r.left}</Text>
|
|
190
|
+
</View>
|
|
191
|
+
<Text style={[styles.kvRowText, { color: t.valueColor, fontWeight: '700', flexShrink: 0 }]}>
|
|
192
|
+
{r.right}
|
|
193
|
+
</Text>
|
|
194
|
+
</View>))}
|
|
195
|
+
{children}
|
|
196
|
+
</View>);
|
|
197
|
+
}
|
|
198
|
+
/** Pill chip on dark glass. */
|
|
199
|
+
export function TooltipPresetCompact({ emphasis, detail, wrap = true, }) {
|
|
200
|
+
const { compact } = useTooltipPresetTokens();
|
|
201
|
+
return (<View style={[compact.shell, wrap && styles.compactShellWrap]}>
|
|
202
|
+
<Text style={compact.emphasis}>{emphasis}</Text>
|
|
203
|
+
<View style={styles.compactDetailCell}>
|
|
204
|
+
<Text style={compact.detail}>{detail}</Text>
|
|
205
|
+
</View>
|
|
206
|
+
</View>);
|
|
207
|
+
}
|
|
208
|
+
/** KPI strip with optional footer metric rows. */
|
|
209
|
+
export function TooltipPresetKpi({ accentColor, minWidth = 140, overline, metric, caption, footerRows, }) {
|
|
210
|
+
const { kpi } = useTooltipPresetTokens();
|
|
211
|
+
return (<View style={[kpi.shell, { borderLeftColor: accentColor, minWidth }]}>
|
|
212
|
+
<Text style={kpi.overline}>{overline}</Text>
|
|
213
|
+
{typeof metric === 'string' || typeof metric === 'number' ? (<Text style={kpi.metric}>{String(metric)}</Text>) : (metric)}
|
|
214
|
+
{caption != null && caption !== '' ? <Text style={kpi.caption}>{caption}</Text> : null}
|
|
215
|
+
{footerRows != null && footerRows.length > 0 ? (<View style={kpi.footerRule}>
|
|
216
|
+
{footerRows.map((r) => (<View key={String(r.key)} style={styles.kpiFooterRow}>
|
|
217
|
+
<View style={styles.kpiFooterLeftCell}>
|
|
218
|
+
<Text style={kpi.footerLeft}>{r.left}</Text>
|
|
219
|
+
</View>
|
|
220
|
+
<Text style={kpi.footerRight}>{r.right}</Text>
|
|
221
|
+
</View>))}
|
|
222
|
+
</View>) : null}
|
|
223
|
+
</View>);
|
|
224
|
+
}
|
|
225
|
+
/** Banded header + zebra rows. */
|
|
226
|
+
export function TooltipPresetStriped({ header, headerTitle, headerSwatch, rows, }) {
|
|
227
|
+
const { striped, t } = useTooltipPresetTokens();
|
|
228
|
+
let headerNode;
|
|
229
|
+
if (header != null) {
|
|
230
|
+
headerNode = header;
|
|
231
|
+
}
|
|
232
|
+
else if (headerSwatch != null) {
|
|
233
|
+
headerNode = (<View style={styles.stripedHeaderInner}>
|
|
234
|
+
<View style={[styles.swatchSmall, { backgroundColor: headerSwatch.color }]}/>
|
|
235
|
+
<View style={styles.stripedHeaderTitleCell}>
|
|
236
|
+
<Text style={striped.headerTitle}>{headerSwatch.title}</Text>
|
|
237
|
+
</View>
|
|
238
|
+
</View>);
|
|
239
|
+
}
|
|
240
|
+
else if (headerTitle != null) {
|
|
241
|
+
headerNode = <Text style={striped.headerTitle}>{headerTitle}</Text>;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
headerNode = null;
|
|
245
|
+
}
|
|
246
|
+
return (<View style={striped.outer}>
|
|
247
|
+
<View style={styles.stripedInner}>
|
|
248
|
+
<View style={striped.headerBand}>{headerNode}</View>
|
|
249
|
+
{rows.map((r, i) => (<View key={r.key} style={[
|
|
250
|
+
styles.stripedRow,
|
|
251
|
+
{
|
|
252
|
+
backgroundColor: i % 2 === 0 ? t.backgroundColor : stripedAltRowBg(t.backgroundColor, t.borderColor),
|
|
253
|
+
},
|
|
254
|
+
]}>
|
|
255
|
+
<View style={styles.stripedRowLeft}>
|
|
256
|
+
{r.left != null ? (r.left) : (<>
|
|
257
|
+
{r.leftSwatchColor != null ? (<View style={[styles.swatchSmall, { backgroundColor: r.leftSwatchColor }]}/>) : null}
|
|
258
|
+
<View style={styles.stripedRowLeftLabelCell}>
|
|
259
|
+
<Text style={striped.rowLeftText}>{r.leftLabel ?? ''}</Text>
|
|
260
|
+
</View>
|
|
261
|
+
</>)}
|
|
262
|
+
</View>
|
|
263
|
+
<Text style={striped.rowRight}>{String(r.right)}</Text>
|
|
264
|
+
</View>))}
|
|
265
|
+
</View>
|
|
266
|
+
</View>);
|
|
267
|
+
}
|
|
268
|
+
/** Between slate-300 and slate-400: zebra when border ≈ bg without overpowering the base row. */
|
|
269
|
+
const STRIPE_NEUTRAL_LIGHT = { r: 176, g: 188, b: 205 };
|
|
270
|
+
/**
|
|
271
|
+
* Alternate striped row fill: opaque blend of tooltip bg toward border.
|
|
272
|
+
* Light themes often use #fff + light gray border; a weak blend matches the base row—use a
|
|
273
|
+
* stronger mix and fall back to a neutral gray when border is missing or too close to bg.
|
|
274
|
+
*/
|
|
275
|
+
function stripedAltRowBg(bg, border) {
|
|
276
|
+
const base = parseHexRgb(bg);
|
|
277
|
+
if (base == null) {
|
|
278
|
+
return isLightBackground(bg) ? '#f1f5f9' : '#1e293b';
|
|
279
|
+
}
|
|
280
|
+
const light = isLightBackground(bg);
|
|
281
|
+
const edge = parseHexRgb(border);
|
|
282
|
+
const sameAsBase = edge != null && rgbMaxChannelDelta(base, edge) < 4;
|
|
283
|
+
let mix = edge != null && !sameAsBase ? edge : light ? STRIPE_NEUTRAL_LIGHT : { r: 255, g: 255, b: 255 };
|
|
284
|
+
let t = light ? 0.5 : 0.32;
|
|
285
|
+
let r = base.r * (1 - t) + mix.r * t;
|
|
286
|
+
let g = base.g * (1 - t) + mix.g * t;
|
|
287
|
+
let b = base.b * (1 - t) + mix.b * t;
|
|
288
|
+
if (rgbMaxChannelDelta(base, { r, g, b }) < 14) {
|
|
289
|
+
t = light ? 0.66 : 0.46;
|
|
290
|
+
r = base.r * (1 - t) + mix.r * t;
|
|
291
|
+
g = base.g * (1 - t) + mix.g * t;
|
|
292
|
+
b = base.b * (1 - t) + mix.b * t;
|
|
293
|
+
}
|
|
294
|
+
if (rgbMaxChannelDelta(base, { r, g, b }) < 10) {
|
|
295
|
+
mix = light ? STRIPE_NEUTRAL_LIGHT : { r: 255, g: 255, b: 255 };
|
|
296
|
+
t = light ? 0.28 : 0.3;
|
|
297
|
+
r = base.r * (1 - t) + mix.r * t;
|
|
298
|
+
g = base.g * (1 - t) + mix.g * t;
|
|
299
|
+
b = base.b * (1 - t) + mix.b * t;
|
|
300
|
+
}
|
|
301
|
+
return rgbToHex(r, g, b);
|
|
302
|
+
}
|
|
303
|
+
const styles = StyleSheet.create({
|
|
304
|
+
swatchRound: {
|
|
305
|
+
width: 10,
|
|
306
|
+
height: 10,
|
|
307
|
+
borderRadius: 5,
|
|
308
|
+
marginRight: 10,
|
|
309
|
+
},
|
|
310
|
+
swatchSmall: {
|
|
311
|
+
width: 8,
|
|
312
|
+
height: 8,
|
|
313
|
+
borderRadius: 2,
|
|
314
|
+
marginRight: 8,
|
|
315
|
+
},
|
|
316
|
+
cardHeaderRow: {
|
|
317
|
+
flexDirection: 'row',
|
|
318
|
+
alignItems: 'center',
|
|
319
|
+
minWidth: 0,
|
|
320
|
+
},
|
|
321
|
+
cardHeaderTitleCell: {
|
|
322
|
+
flexGrow: 1,
|
|
323
|
+
flexShrink: 1,
|
|
324
|
+
minWidth: 0,
|
|
325
|
+
},
|
|
326
|
+
cardSeriesRow: {
|
|
327
|
+
flexDirection: 'row',
|
|
328
|
+
alignItems: 'center',
|
|
329
|
+
marginTop: 6,
|
|
330
|
+
minWidth: 0,
|
|
331
|
+
},
|
|
332
|
+
cardSeriesLabelCell: {
|
|
333
|
+
flexGrow: 1,
|
|
334
|
+
flexShrink: 1,
|
|
335
|
+
minWidth: 0,
|
|
336
|
+
marginRight: 8,
|
|
337
|
+
},
|
|
338
|
+
kvRow: {
|
|
339
|
+
flexDirection: 'row',
|
|
340
|
+
justifyContent: 'space-between',
|
|
341
|
+
alignItems: 'center',
|
|
342
|
+
marginTop: 4,
|
|
343
|
+
minWidth: 0,
|
|
344
|
+
},
|
|
345
|
+
kvRowLeftCell: {
|
|
346
|
+
flexGrow: 1,
|
|
347
|
+
flexShrink: 1,
|
|
348
|
+
minWidth: 0,
|
|
349
|
+
marginRight: 8,
|
|
350
|
+
},
|
|
351
|
+
kvRowText: {
|
|
352
|
+
fontSize: 13,
|
|
353
|
+
},
|
|
354
|
+
compactShellWrap: {
|
|
355
|
+
flexWrap: 'wrap',
|
|
356
|
+
},
|
|
357
|
+
compactDetailCell: {
|
|
358
|
+
flexGrow: 1,
|
|
359
|
+
flexShrink: 1,
|
|
360
|
+
minWidth: 0,
|
|
361
|
+
},
|
|
362
|
+
kpiFooterRow: {
|
|
363
|
+
flexDirection: 'row',
|
|
364
|
+
justifyContent: 'space-between',
|
|
365
|
+
alignItems: 'center',
|
|
366
|
+
marginTop: 4,
|
|
367
|
+
minWidth: 0,
|
|
368
|
+
},
|
|
369
|
+
kpiFooterLeftCell: {
|
|
370
|
+
flexGrow: 1,
|
|
371
|
+
flexShrink: 1,
|
|
372
|
+
minWidth: 0,
|
|
373
|
+
marginRight: 8,
|
|
374
|
+
},
|
|
375
|
+
stripedInner: {
|
|
376
|
+
alignItems: 'stretch',
|
|
377
|
+
minWidth: 0,
|
|
378
|
+
},
|
|
379
|
+
stripedHeaderInner: {
|
|
380
|
+
flexDirection: 'row',
|
|
381
|
+
alignItems: 'center',
|
|
382
|
+
minWidth: 0,
|
|
383
|
+
},
|
|
384
|
+
stripedHeaderTitleCell: {
|
|
385
|
+
flexGrow: 1,
|
|
386
|
+
flexShrink: 1,
|
|
387
|
+
minWidth: 0,
|
|
388
|
+
},
|
|
389
|
+
stripedRow: {
|
|
390
|
+
flexDirection: 'row',
|
|
391
|
+
justifyContent: 'space-between',
|
|
392
|
+
alignItems: 'center',
|
|
393
|
+
paddingHorizontal: 10,
|
|
394
|
+
paddingVertical: 6,
|
|
395
|
+
minWidth: 0,
|
|
396
|
+
},
|
|
397
|
+
stripedRowLeft: {
|
|
398
|
+
flexDirection: 'row',
|
|
399
|
+
alignItems: 'center',
|
|
400
|
+
flexGrow: 1,
|
|
401
|
+
flexShrink: 1,
|
|
402
|
+
minWidth: 0,
|
|
403
|
+
marginRight: 8,
|
|
404
|
+
},
|
|
405
|
+
stripedRowLeftLabelCell: {
|
|
406
|
+
flexShrink: 1,
|
|
407
|
+
minWidth: 0,
|
|
408
|
+
},
|
|
409
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ChartPointerTooltipOverlay, } from './chart-pointer-tooltip-overlay';
|
|
2
|
+
export type { ChartPointerTooltipOverlayProps } from './chart-pointer-tooltip-overlay';
|
|
3
|
+
/** Built-in tooltip layout when `renderTooltip` is not provided. */
|
|
4
|
+
export type ChartTooltipPreset = 'card' | 'compact' | 'kpi' | 'striped';
|
|
5
|
+
/** Tooltip preset or `none` to hide the React Native tooltip overlay. */
|
|
6
|
+
export type ChartTooltipOption = ChartTooltipPreset | 'none';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/chart/tooltip/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AACvF,oEAAoE;AACpE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;AAExE,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,GAAG,MAAM,CAAC"}
|
package/tooltip/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChartPointerTooltipOverlay, } from './chart-pointer-tooltip-overlay';
|