react-native-metrify 0.1.0-alpha.1 → 0.1.0-alpha.3
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 +111 -51
- package/package.json +1 -2
- package/src/core/animation/index.ts +0 -113
- package/src/core/animation/index.web.ts +0 -112
- package/src/core/hooks/index.ts +0 -66
- package/src/core/index.ts +0 -26
- package/src/core/layout/index.ts +0 -101
- package/src/core/math/index.ts +0 -72
- package/src/core/package.json +0 -13
- package/src/core/theme/ThemeProvider.tsx +0 -36
- package/src/core/theme/index.ts +0 -5
- package/src/core/theme/themes.ts +0 -132
- package/src/core/types/index.ts +0 -164
- package/src/core/utils/responsive.ts +0 -203
- package/src/core/utils/time.ts +0 -100
- package/src/index.ts +0 -13
- package/src/renderer-svg/adapters/index.ts +0 -84
- package/src/renderer-svg/index.ts +0 -8
- package/src/renderer-svg/package.json +0 -17
- package/src/renderer-svg/paths/arc.ts +0 -93
- package/src/renderer-svg/paths/index.ts +0 -6
- package/src/renderer-svg/paths/line.ts +0 -83
- package/src/renderer-svg/paths/rect.ts +0 -80
- package/src/renderer-svg/primitives/AnimatedCircle.tsx +0 -48
- package/src/renderer-svg/primitives/AnimatedPath.tsx +0 -48
- package/src/renderer-svg/primitives/Text.tsx +0 -73
- package/src/renderer-svg/primitives/index.ts +0 -6
- package/src/widgets/AreaChart/AreaChart.tsx +0 -213
- package/src/widgets/AreaChart/index.ts +0 -2
- package/src/widgets/AreaChart/types.ts +0 -34
- package/src/widgets/BarChart/BarChart.tsx +0 -249
- package/src/widgets/BarChart/index.ts +0 -10
- package/src/widgets/BarChart/types.ts +0 -27
- package/src/widgets/BoxPlot/BoxPlot.tsx +0 -252
- package/src/widgets/BoxPlot/index.ts +0 -2
- package/src/widgets/BoxPlot/types.ts +0 -27
- package/src/widgets/BubbleChart/BubbleChart.tsx +0 -175
- package/src/widgets/BubbleChart/index.ts +0 -2
- package/src/widgets/BubbleChart/types.ts +0 -33
- package/src/widgets/CandlestickChart/CandlestickChart.tsx +0 -204
- package/src/widgets/CandlestickChart/index.ts +0 -2
- package/src/widgets/CandlestickChart/types.ts +0 -29
- package/src/widgets/FunnelChart/FunnelChart.tsx +0 -172
- package/src/widgets/FunnelChart/index.ts +0 -2
- package/src/widgets/FunnelChart/types.ts +0 -22
- package/src/widgets/Gauge/Gauge.tsx +0 -235
- package/src/widgets/Gauge/index.ts +0 -5
- package/src/widgets/Gauge/types.ts +0 -19
- package/src/widgets/GroupedBarChart/GroupedBarChart.tsx +0 -190
- package/src/widgets/GroupedBarChart/index.ts +0 -2
- package/src/widgets/GroupedBarChart/types.ts +0 -30
- package/src/widgets/Heatmap/Heatmap.tsx +0 -216
- package/src/widgets/Heatmap/index.ts +0 -2
- package/src/widgets/Heatmap/types.ts +0 -27
- package/src/widgets/Histogram/Histogram.tsx +0 -173
- package/src/widgets/Histogram/index.ts +0 -2
- package/src/widgets/Histogram/types.ts +0 -18
- package/src/widgets/HorizontalBarChart/HorizontalBarChart.tsx +0 -125
- package/src/widgets/HorizontalBarChart/index.ts +0 -2
- package/src/widgets/HorizontalBarChart/types.ts +0 -23
- package/src/widgets/KPI/KPI.tsx +0 -222
- package/src/widgets/KPI/index.ts +0 -5
- package/src/widgets/KPI/types.ts +0 -19
- package/src/widgets/LineChart/LineChart.tsx +0 -364
- package/src/widgets/LineChart/index.ts +0 -10
- package/src/widgets/LineChart/types.ts +0 -34
- package/src/widgets/MultiLineSparkline/MultiLineSparkline.tsx +0 -234
- package/src/widgets/MultiLineSparkline/index.ts +0 -10
- package/src/widgets/MultiLineSparkline/types.ts +0 -25
- package/src/widgets/PieChart/PieChart.tsx +0 -275
- package/src/widgets/PieChart/index.ts +0 -10
- package/src/widgets/PieChart/types.ts +0 -26
- package/src/widgets/Progress/Progress.tsx +0 -201
- package/src/widgets/Progress/index.ts +0 -5
- package/src/widgets/Progress/types.ts +0 -19
- package/src/widgets/RadarChart/RadarChart.tsx +0 -213
- package/src/widgets/RadarChart/index.ts +0 -2
- package/src/widgets/RadarChart/types.ts +0 -29
- package/src/widgets/SankeyDiagram/SankeyDiagram.tsx +0 -272
- package/src/widgets/SankeyDiagram/index.ts +0 -2
- package/src/widgets/SankeyDiagram/types.ts +0 -29
- package/src/widgets/ScatterPlot/ScatterPlot.tsx +0 -167
- package/src/widgets/ScatterPlot/index.ts +0 -2
- package/src/widgets/ScatterPlot/types.ts +0 -32
- package/src/widgets/Sparkline/Sparkline.tsx +0 -203
- package/src/widgets/Sparkline/index.ts +0 -5
- package/src/widgets/Sparkline/types.ts +0 -18
- package/src/widgets/StackedBarChart/StackedBarChart.tsx +0 -181
- package/src/widgets/StackedBarChart/index.ts +0 -2
- package/src/widgets/StackedBarChart/types.ts +0 -29
- package/src/widgets/SunburstChart/SunburstChart.tsx +0 -176
- package/src/widgets/SunburstChart/index.ts +0 -2
- package/src/widgets/SunburstChart/types.ts +0 -22
- package/src/widgets/Treemap/Treemap.tsx +0 -191
- package/src/widgets/Treemap/index.ts +0 -2
- package/src/widgets/Treemap/types.ts +0 -23
- package/src/widgets/WaterfallChart/WaterfallChart.tsx +0 -226
- package/src/widgets/WaterfallChart/index.ts +0 -2
- package/src/widgets/WaterfallChart/types.ts +0 -26
- package/src/widgets/index.ts +0 -40
- package/src/widgets/package.json +0 -18
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BoxPlot Widget - Shows statistical distribution with quartiles
|
|
3
|
-
*/
|
|
4
|
-
import React, { memo, useMemo } from 'react';
|
|
5
|
-
import { View, Text as RNText, StyleSheet } from 'react-native';
|
|
6
|
-
import Svg, { Rect, Line as SvgLine, Circle } from 'react-native-svg';
|
|
7
|
-
import { useWidgetDimensions, useWidgetTheme, normalize } from '../../core';
|
|
8
|
-
import { BoxPlotWidgetProps } from './types';
|
|
9
|
-
|
|
10
|
-
export const BoxPlot = memo<BoxPlotWidgetProps>(({
|
|
11
|
-
data: widgetData,
|
|
12
|
-
width,
|
|
13
|
-
height,
|
|
14
|
-
loading = false,
|
|
15
|
-
theme: themeOverride,
|
|
16
|
-
showLabels = true,
|
|
17
|
-
showOutliers = true,
|
|
18
|
-
boxWidth = 50,
|
|
19
|
-
boxSpacing = 30,
|
|
20
|
-
color,
|
|
21
|
-
testID,
|
|
22
|
-
}) => {
|
|
23
|
-
const theme = useWidgetTheme(themeOverride);
|
|
24
|
-
const dimensions = useWidgetDimensions(width, height, 350, 300);
|
|
25
|
-
|
|
26
|
-
if (loading) {
|
|
27
|
-
return (
|
|
28
|
-
<View style={[styles.container, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md }]} testID={`${testID}-loading`}>
|
|
29
|
-
<RNText style={[styles.loadingText, { color: theme.colors.textSecondary }]}>Loading...</RNText>
|
|
30
|
-
</View>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!widgetData || !widgetData.data || widgetData.data.length === 0) {
|
|
35
|
-
return (
|
|
36
|
-
<View style={[styles.container, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md }]} testID={`${testID}-empty`}>
|
|
37
|
-
<RNText style={[styles.emptyText, { color: theme.colors.textSecondary }]}>No data</RNText>
|
|
38
|
-
</View>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const { data, title } = widgetData;
|
|
43
|
-
const padding = theme.spacing.md;
|
|
44
|
-
const titleHeight = title ? theme.fontScale.md + theme.spacing.sm : 0;
|
|
45
|
-
const labelHeight = showLabels ? 30 : 0;
|
|
46
|
-
const yAxisWidth = 40;
|
|
47
|
-
|
|
48
|
-
const chartHeight = dimensions.height - padding * 2 - titleHeight - labelHeight;
|
|
49
|
-
const chartWidth = dimensions.width - padding * 2 - yAxisWidth;
|
|
50
|
-
|
|
51
|
-
const boxColor = color || theme.colors.chartPrimary;
|
|
52
|
-
|
|
53
|
-
// Find global min/max for Y-axis
|
|
54
|
-
const { globalMin, globalMax } = useMemo(() => {
|
|
55
|
-
let min = Infinity;
|
|
56
|
-
let max = -Infinity;
|
|
57
|
-
|
|
58
|
-
data.forEach(point => {
|
|
59
|
-
if (point.min < min) min = point.min;
|
|
60
|
-
if (point.max > max) max = point.max;
|
|
61
|
-
if (point.outliers) {
|
|
62
|
-
point.outliers.forEach(val => {
|
|
63
|
-
if (val < min) min = val;
|
|
64
|
-
if (val > max) max = val;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return { globalMin: min, globalMax: max };
|
|
70
|
-
}, [data]);
|
|
71
|
-
|
|
72
|
-
const yAxisLabels = useMemo(() => {
|
|
73
|
-
const range = globalMax - globalMin;
|
|
74
|
-
const step = range / 4;
|
|
75
|
-
return Array.from({ length: 5 }, (_, i) => ({
|
|
76
|
-
value: globalMin + i * step,
|
|
77
|
-
y: chartHeight - (i * chartHeight) / 4,
|
|
78
|
-
}));
|
|
79
|
-
}, [globalMin, globalMax, chartHeight]);
|
|
80
|
-
|
|
81
|
-
const boxes = useMemo(() => {
|
|
82
|
-
return data.map((point, index) => {
|
|
83
|
-
const centerX = index * (boxWidth + boxSpacing) + boxWidth / 2;
|
|
84
|
-
|
|
85
|
-
// Normalize values to chart height
|
|
86
|
-
const minY = chartHeight - normalize(point.min, globalMin, globalMax) * chartHeight;
|
|
87
|
-
const maxY = chartHeight - normalize(point.max, globalMin, globalMax) * chartHeight;
|
|
88
|
-
const q1Y = chartHeight - normalize(point.q1, globalMin, globalMax) * chartHeight;
|
|
89
|
-
const q3Y = chartHeight - normalize(point.q3, globalMin, globalMax) * chartHeight;
|
|
90
|
-
const medianY = chartHeight - normalize(point.median, globalMin, globalMax) * chartHeight;
|
|
91
|
-
|
|
92
|
-
const outlierPoints = point.outliers?.map(val => ({
|
|
93
|
-
x: centerX,
|
|
94
|
-
y: chartHeight - normalize(val, globalMin, globalMax) * chartHeight,
|
|
95
|
-
})) || [];
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
label: point.label,
|
|
99
|
-
centerX,
|
|
100
|
-
boxX: centerX - boxWidth / 2,
|
|
101
|
-
boxWidth,
|
|
102
|
-
// Whiskers
|
|
103
|
-
minY,
|
|
104
|
-
maxY,
|
|
105
|
-
// Box (IQR)
|
|
106
|
-
q1Y,
|
|
107
|
-
q3Y,
|
|
108
|
-
boxHeight: Math.abs(q3Y - q1Y),
|
|
109
|
-
boxY: Math.min(q1Y, q3Y),
|
|
110
|
-
// Median line
|
|
111
|
-
medianY,
|
|
112
|
-
// Outliers
|
|
113
|
-
outliers: outlierPoints,
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
}, [data, chartHeight, globalMin, globalMax, boxWidth, boxSpacing]);
|
|
117
|
-
|
|
118
|
-
return (
|
|
119
|
-
<View style={[styles.wrapper, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md, padding }]} testID={testID}>
|
|
120
|
-
{title && (
|
|
121
|
-
<RNText style={[styles.title, { color: theme.colors.text, fontSize: theme.fontScale.md, fontWeight: 'bold', marginBottom: theme.spacing.sm }]}>
|
|
122
|
-
{title}
|
|
123
|
-
</RNText>
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
<View style={styles.chartRow}>
|
|
127
|
-
{/* Y-Axis */}
|
|
128
|
-
<View style={[styles.yAxis, { width: yAxisWidth }]}>
|
|
129
|
-
{yAxisLabels.map((label, index) => (
|
|
130
|
-
<RNText key={`y-${index}`} style={[styles.yAxisLabel, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs, top: label.y - 6 }]}>
|
|
131
|
-
{label.value.toFixed(0)}
|
|
132
|
-
</RNText>
|
|
133
|
-
))}
|
|
134
|
-
</View>
|
|
135
|
-
|
|
136
|
-
<View>
|
|
137
|
-
<Svg width={chartWidth} height={chartHeight}>
|
|
138
|
-
{boxes.map((box, index) => (
|
|
139
|
-
<React.Fragment key={`box-${index}`}>
|
|
140
|
-
{/* Whisker lines (min to Q1, Q3 to max) */}
|
|
141
|
-
<SvgLine
|
|
142
|
-
x1={box.centerX}
|
|
143
|
-
y1={box.minY}
|
|
144
|
-
x2={box.centerX}
|
|
145
|
-
y2={box.q1Y}
|
|
146
|
-
stroke={boxColor}
|
|
147
|
-
strokeWidth={1}
|
|
148
|
-
/>
|
|
149
|
-
<SvgLine
|
|
150
|
-
x1={box.centerX}
|
|
151
|
-
y1={box.q3Y}
|
|
152
|
-
x2={box.centerX}
|
|
153
|
-
y2={box.maxY}
|
|
154
|
-
stroke={boxColor}
|
|
155
|
-
strokeWidth={1}
|
|
156
|
-
/>
|
|
157
|
-
|
|
158
|
-
{/* Min/Max caps */}
|
|
159
|
-
<SvgLine
|
|
160
|
-
x1={box.centerX - boxWidth / 4}
|
|
161
|
-
y1={box.minY}
|
|
162
|
-
x2={box.centerX + boxWidth / 4}
|
|
163
|
-
y2={box.minY}
|
|
164
|
-
stroke={boxColor}
|
|
165
|
-
strokeWidth={2}
|
|
166
|
-
/>
|
|
167
|
-
<SvgLine
|
|
168
|
-
x1={box.centerX - boxWidth / 4}
|
|
169
|
-
y1={box.maxY}
|
|
170
|
-
x2={box.centerX + boxWidth / 4}
|
|
171
|
-
y2={box.maxY}
|
|
172
|
-
stroke={boxColor}
|
|
173
|
-
strokeWidth={2}
|
|
174
|
-
/>
|
|
175
|
-
|
|
176
|
-
{/* IQR Box (Q1 to Q3) */}
|
|
177
|
-
<Rect
|
|
178
|
-
x={box.boxX}
|
|
179
|
-
y={box.boxY}
|
|
180
|
-
width={box.boxWidth}
|
|
181
|
-
height={box.boxHeight}
|
|
182
|
-
fill={boxColor}
|
|
183
|
-
fillOpacity={0.3}
|
|
184
|
-
stroke={boxColor}
|
|
185
|
-
strokeWidth={2}
|
|
186
|
-
rx={theme.radius.sm}
|
|
187
|
-
ry={theme.radius.sm}
|
|
188
|
-
/>
|
|
189
|
-
|
|
190
|
-
{/* Median line */}
|
|
191
|
-
<SvgLine
|
|
192
|
-
x1={box.boxX}
|
|
193
|
-
y1={box.medianY}
|
|
194
|
-
x2={box.boxX + box.boxWidth}
|
|
195
|
-
y2={box.medianY}
|
|
196
|
-
stroke={boxColor}
|
|
197
|
-
strokeWidth={3}
|
|
198
|
-
/>
|
|
199
|
-
|
|
200
|
-
{/* Outliers */}
|
|
201
|
-
{showOutliers && box.outliers.map((outlier, oIndex) => (
|
|
202
|
-
<Circle
|
|
203
|
-
key={`outlier-${index}-${oIndex}`}
|
|
204
|
-
cx={outlier.x}
|
|
205
|
-
cy={outlier.y}
|
|
206
|
-
r={3}
|
|
207
|
-
fill={theme.colors.chartNegative}
|
|
208
|
-
opacity={0.8}
|
|
209
|
-
/>
|
|
210
|
-
))}
|
|
211
|
-
</React.Fragment>
|
|
212
|
-
))}
|
|
213
|
-
</Svg>
|
|
214
|
-
|
|
215
|
-
{showLabels && (
|
|
216
|
-
<View style={styles.labelsContainer}>
|
|
217
|
-
{boxes.map((box, index) => (
|
|
218
|
-
<View
|
|
219
|
-
key={`label-${index}`}
|
|
220
|
-
style={[styles.labelItem, { left: box.boxX, width: box.boxWidth }]}
|
|
221
|
-
>
|
|
222
|
-
<RNText
|
|
223
|
-
style={[styles.labelText, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs }]}
|
|
224
|
-
numberOfLines={1}
|
|
225
|
-
>
|
|
226
|
-
{box.label}
|
|
227
|
-
</RNText>
|
|
228
|
-
</View>
|
|
229
|
-
))}
|
|
230
|
-
</View>
|
|
231
|
-
)}
|
|
232
|
-
</View>
|
|
233
|
-
</View>
|
|
234
|
-
</View>
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
BoxPlot.displayName = 'BoxPlot';
|
|
239
|
-
|
|
240
|
-
const styles = StyleSheet.create({
|
|
241
|
-
wrapper: { justifyContent: 'flex-start', alignItems: 'flex-start' },
|
|
242
|
-
container: { justifyContent: 'center', alignItems: 'center' },
|
|
243
|
-
loadingText: { fontSize: 16 },
|
|
244
|
-
emptyText: { fontSize: 16 },
|
|
245
|
-
title: { textAlign: 'center', width: '100%' },
|
|
246
|
-
chartRow: { flexDirection: 'row', alignItems: 'flex-start' },
|
|
247
|
-
yAxis: { position: 'relative', marginRight: 8 },
|
|
248
|
-
yAxisLabel: { position: 'absolute', right: 0, textAlign: 'right' },
|
|
249
|
-
labelsContainer: { position: 'relative', height: 30, marginTop: 4 },
|
|
250
|
-
labelItem: { position: 'absolute', alignItems: 'center' },
|
|
251
|
-
labelText: { textAlign: 'center' },
|
|
252
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BoxPlot Widget types - Statistical distribution (quartiles, outliers)
|
|
3
|
-
*/
|
|
4
|
-
import { BaseWidgetProps } from '../../core';
|
|
5
|
-
|
|
6
|
-
export interface BoxPlotDataPoint {
|
|
7
|
-
label: string;
|
|
8
|
-
min: number;
|
|
9
|
-
q1: number;
|
|
10
|
-
median: number;
|
|
11
|
-
q3: number;
|
|
12
|
-
max: number;
|
|
13
|
-
outliers?: number[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface BoxPlotData {
|
|
17
|
-
data: BoxPlotDataPoint[];
|
|
18
|
-
title?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface BoxPlotWidgetProps extends BaseWidgetProps<BoxPlotData> {
|
|
22
|
-
showLabels?: boolean;
|
|
23
|
-
showOutliers?: boolean;
|
|
24
|
-
boxWidth?: number;
|
|
25
|
-
boxSpacing?: number;
|
|
26
|
-
color?: string;
|
|
27
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BubbleChart Widget - Scatter plot with size dimension (3D data)
|
|
3
|
-
*/
|
|
4
|
-
import React, { memo, useMemo } from 'react';
|
|
5
|
-
import { View, Text as RNText, StyleSheet } from 'react-native';
|
|
6
|
-
import Svg, { Circle, Line as SvgLine } from 'react-native-svg';
|
|
7
|
-
import { useWidgetDimensions, useWidgetTheme, normalize } from '../../core';
|
|
8
|
-
import { BubbleChartWidgetProps } from './types';
|
|
9
|
-
|
|
10
|
-
export const BubbleChart = memo<BubbleChartWidgetProps>(({
|
|
11
|
-
data: widgetData,
|
|
12
|
-
width,
|
|
13
|
-
height,
|
|
14
|
-
loading = false,
|
|
15
|
-
theme: themeOverride,
|
|
16
|
-
showXAxis = true,
|
|
17
|
-
showYAxis = true,
|
|
18
|
-
showGrid = true,
|
|
19
|
-
showLegend = true,
|
|
20
|
-
minBubbleSize = 5,
|
|
21
|
-
maxBubbleSize = 30,
|
|
22
|
-
testID,
|
|
23
|
-
}) => {
|
|
24
|
-
const theme = useWidgetTheme(themeOverride);
|
|
25
|
-
const dimensions = useWidgetDimensions(width, height, 350, 300);
|
|
26
|
-
|
|
27
|
-
if (loading) {
|
|
28
|
-
return (
|
|
29
|
-
<View style={[styles.container, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md }]} testID={`${testID}-loading`}>
|
|
30
|
-
<RNText style={[styles.loadingText, { color: theme.colors.textSecondary }]}>Loading...</RNText>
|
|
31
|
-
</View>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!widgetData || !widgetData.series || widgetData.series.length === 0) {
|
|
36
|
-
return (
|
|
37
|
-
<View style={[styles.container, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md }]} testID={`${testID}-empty`}>
|
|
38
|
-
<RNText style={[styles.emptyText, { color: theme.colors.textSecondary }]}>No data</RNText>
|
|
39
|
-
</View>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const { series, title } = widgetData;
|
|
44
|
-
const padding = theme.spacing.md;
|
|
45
|
-
const titleHeight = title ? theme.fontScale.md + theme.spacing.sm : 0;
|
|
46
|
-
const legendHeight = showLegend ? 30 : 0;
|
|
47
|
-
const xAxisHeight = showXAxis ? 30 : 0;
|
|
48
|
-
const yAxisWidth = showYAxis ? 40 : 0;
|
|
49
|
-
|
|
50
|
-
const chartWidth = dimensions.width - padding * 2 - yAxisWidth;
|
|
51
|
-
const chartHeight = dimensions.height - padding * 2 - titleHeight - legendHeight - xAxisHeight;
|
|
52
|
-
|
|
53
|
-
const { globalMinX, globalMaxX, globalMinY, globalMaxY, globalMinSize, globalMaxSize } = useMemo(() => {
|
|
54
|
-
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity, minS = Infinity, maxS = -Infinity;
|
|
55
|
-
series.forEach(s => {
|
|
56
|
-
s.data.forEach(point => {
|
|
57
|
-
if (point.x < minX) minX = point.x;
|
|
58
|
-
if (point.x > maxX) maxX = point.x;
|
|
59
|
-
if (point.y < minY) minY = point.y;
|
|
60
|
-
if (point.y > maxY) maxY = point.y;
|
|
61
|
-
if (point.size < minS) minS = point.size;
|
|
62
|
-
if (point.size > maxS) maxS = point.size;
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
return { globalMinX: minX, globalMaxX: maxX, globalMinY: minY, globalMaxY: maxY, globalMinSize: minS, globalMaxSize: maxS };
|
|
66
|
-
}, [series]);
|
|
67
|
-
|
|
68
|
-
const yAxisLabels = useMemo(() => {
|
|
69
|
-
const range = globalMaxY - globalMinY;
|
|
70
|
-
const step = range / 4;
|
|
71
|
-
return Array.from({ length: 5 }, (_, i) => ({
|
|
72
|
-
value: globalMinY + i * step,
|
|
73
|
-
y: chartHeight - (i * chartHeight) / 4,
|
|
74
|
-
}));
|
|
75
|
-
}, [globalMinY, globalMaxY, chartHeight]);
|
|
76
|
-
|
|
77
|
-
const seriesBubbles = useMemo(() => {
|
|
78
|
-
return series.map(s => {
|
|
79
|
-
const bubbles = s.data.map(point => {
|
|
80
|
-
const normalizedX = normalize(point.x, globalMinX, globalMaxX);
|
|
81
|
-
const normalizedY = normalize(point.y, globalMinY, globalMaxY);
|
|
82
|
-
const normalizedSize = normalize(point.size, globalMinSize, globalMaxSize);
|
|
83
|
-
const radius = minBubbleSize + normalizedSize * (maxBubbleSize - minBubbleSize);
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
cx: normalizedX * chartWidth,
|
|
87
|
-
cy: chartHeight - normalizedY * chartHeight,
|
|
88
|
-
r: radius,
|
|
89
|
-
label: point.label,
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
bubbles,
|
|
95
|
-
color: s.color,
|
|
96
|
-
label: s.label,
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
}, [series, chartWidth, chartHeight, globalMinX, globalMaxX, globalMinY, globalMaxY, globalMinSize, globalMaxSize, minBubbleSize, maxBubbleSize]);
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<View style={[styles.wrapper, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md, padding }]} testID={testID}>
|
|
103
|
-
{title && (
|
|
104
|
-
<RNText style={[styles.title, { color: theme.colors.text, fontSize: theme.fontScale.md, fontWeight: 'bold', marginBottom: theme.spacing.sm }]}>
|
|
105
|
-
{title}
|
|
106
|
-
</RNText>
|
|
107
|
-
)}
|
|
108
|
-
|
|
109
|
-
<View style={styles.chartRow}>
|
|
110
|
-
{showYAxis && (
|
|
111
|
-
<View style={[styles.yAxis, { width: yAxisWidth }]}>
|
|
112
|
-
{yAxisLabels.map((label, index) => (
|
|
113
|
-
<RNText key={`y-${index}`} style={[styles.yAxisLabel, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs, top: label.y - 6 }]}>
|
|
114
|
-
{label.value.toFixed(0)}
|
|
115
|
-
</RNText>
|
|
116
|
-
))}
|
|
117
|
-
</View>
|
|
118
|
-
)}
|
|
119
|
-
|
|
120
|
-
<View>
|
|
121
|
-
<Svg width={chartWidth} height={chartHeight}>
|
|
122
|
-
{showGrid && yAxisLabels.map((label, index) => (
|
|
123
|
-
<SvgLine key={`grid-${index}`} x1={0} y1={label.y} x2={chartWidth} y2={label.y} stroke={theme.colors.borderLight} strokeWidth={1} />
|
|
124
|
-
))}
|
|
125
|
-
|
|
126
|
-
{seriesBubbles.map((series, seriesIndex) => (
|
|
127
|
-
series.bubbles.map((bubble, bubbleIndex) => (
|
|
128
|
-
<Circle
|
|
129
|
-
key={`series-${seriesIndex}-bubble-${bubbleIndex}`}
|
|
130
|
-
cx={bubble.cx}
|
|
131
|
-
cy={bubble.cy}
|
|
132
|
-
r={bubble.r}
|
|
133
|
-
fill={series.color}
|
|
134
|
-
opacity={0.6}
|
|
135
|
-
stroke={series.color}
|
|
136
|
-
strokeWidth={2}
|
|
137
|
-
/>
|
|
138
|
-
))
|
|
139
|
-
))}
|
|
140
|
-
</Svg>
|
|
141
|
-
</View>
|
|
142
|
-
</View>
|
|
143
|
-
|
|
144
|
-
{showLegend && (
|
|
145
|
-
<View style={styles.legend}>
|
|
146
|
-
{seriesBubbles.map((series, index) => (
|
|
147
|
-
series.label && (
|
|
148
|
-
<View key={`legend-${index}`} style={styles.legendItem}>
|
|
149
|
-
<View style={[styles.legendColor, { backgroundColor: series.color }]} />
|
|
150
|
-
<RNText style={[styles.legendText, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs }]}>{series.label}</RNText>
|
|
151
|
-
</View>
|
|
152
|
-
)
|
|
153
|
-
))}
|
|
154
|
-
</View>
|
|
155
|
-
)}
|
|
156
|
-
</View>
|
|
157
|
-
);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
BubbleChart.displayName = 'BubbleChart';
|
|
161
|
-
|
|
162
|
-
const styles = StyleSheet.create({
|
|
163
|
-
wrapper: { justifyContent: 'flex-start', alignItems: 'flex-start' },
|
|
164
|
-
container: { justifyContent: 'center', alignItems: 'center' },
|
|
165
|
-
loadingText: { fontSize: 16 },
|
|
166
|
-
emptyText: { fontSize: 16 },
|
|
167
|
-
title: { textAlign: 'center', width: '100%' },
|
|
168
|
-
chartRow: { flexDirection: 'row', alignItems: 'flex-start' },
|
|
169
|
-
yAxis: { position: 'relative', marginRight: 8 },
|
|
170
|
-
yAxisLabel: { position: 'absolute', right: 0, textAlign: 'right' },
|
|
171
|
-
legend: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'center', marginTop: 12, gap: 12 },
|
|
172
|
-
legendItem: { flexDirection: 'row', alignItems: 'center', gap: 6 },
|
|
173
|
-
legendColor: { width: 12, height: 12, borderRadius: 6 },
|
|
174
|
-
legendText: { textTransform: 'uppercase', letterSpacing: 0.5 },
|
|
175
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BubbleChart Widget types - 3D scatter plot with size dimension
|
|
3
|
-
*/
|
|
4
|
-
import { BaseWidgetProps } from '../../core';
|
|
5
|
-
|
|
6
|
-
export interface BubbleDataPoint {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
size: number;
|
|
10
|
-
label?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface BubbleSeries {
|
|
14
|
-
data: BubbleDataPoint[];
|
|
15
|
-
color: string;
|
|
16
|
-
label?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface BubbleChartData {
|
|
20
|
-
series: BubbleSeries[];
|
|
21
|
-
title?: string;
|
|
22
|
-
xAxisLabel?: string;
|
|
23
|
-
yAxisLabel?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface BubbleChartWidgetProps extends BaseWidgetProps<BubbleChartData> {
|
|
27
|
-
showXAxis?: boolean;
|
|
28
|
-
showYAxis?: boolean;
|
|
29
|
-
showGrid?: boolean;
|
|
30
|
-
showLegend?: boolean;
|
|
31
|
-
minBubbleSize?: number;
|
|
32
|
-
maxBubbleSize?: number;
|
|
33
|
-
}
|