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,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AreaChart Widget - Filled area under line
|
|
3
|
-
*/
|
|
4
|
-
import React, { memo, useMemo } from 'react';
|
|
5
|
-
import { View, Text as RNText, StyleSheet } from 'react-native';
|
|
6
|
-
import Svg, { Defs, LinearGradient, Stop, Line as SvgLine } from 'react-native-svg';
|
|
7
|
-
import {
|
|
8
|
-
useWidgetDimensions,
|
|
9
|
-
useWidgetTheme,
|
|
10
|
-
normalize,
|
|
11
|
-
formatTimeLabel,
|
|
12
|
-
reduceLabels,
|
|
13
|
-
} from '../../core';
|
|
14
|
-
import {
|
|
15
|
-
createLinePath,
|
|
16
|
-
createAreaPath,
|
|
17
|
-
AnimatedPath,
|
|
18
|
-
} from '../../renderer-svg';
|
|
19
|
-
import { AreaChartWidgetProps } from './types';
|
|
20
|
-
|
|
21
|
-
export const AreaChart = memo<AreaChartWidgetProps>(({
|
|
22
|
-
data: widgetData,
|
|
23
|
-
width,
|
|
24
|
-
height,
|
|
25
|
-
loading = false,
|
|
26
|
-
theme: themeOverride,
|
|
27
|
-
showXAxis = true,
|
|
28
|
-
showYAxis = true,
|
|
29
|
-
showGrid = true,
|
|
30
|
-
showLegend = true,
|
|
31
|
-
showGradient = true,
|
|
32
|
-
stacked = false,
|
|
33
|
-
curveStyle = 'linear',
|
|
34
|
-
maxXLabels = 6,
|
|
35
|
-
testID,
|
|
36
|
-
}) => {
|
|
37
|
-
const theme = useWidgetTheme(themeOverride);
|
|
38
|
-
const dimensions = useWidgetDimensions(width, height, 350, 250);
|
|
39
|
-
|
|
40
|
-
if (loading) {
|
|
41
|
-
return (
|
|
42
|
-
<View style={[styles.container, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md }]} testID={`${testID}-loading`}>
|
|
43
|
-
<RNText style={[styles.loadingText, { color: theme.colors.textSecondary }]}>Loading...</RNText>
|
|
44
|
-
</View>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!widgetData || !widgetData.series || widgetData.series.length === 0) {
|
|
49
|
-
return (
|
|
50
|
-
<View style={[styles.container, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md }]} testID={`${testID}-empty`}>
|
|
51
|
-
<RNText style={[styles.emptyText, { color: theme.colors.textSecondary }]}>No data</RNText>
|
|
52
|
-
</View>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const { series, title, timeInterval } = widgetData;
|
|
57
|
-
const padding = theme.spacing.md;
|
|
58
|
-
const titleHeight = title ? theme.fontScale.md + theme.spacing.sm : 0;
|
|
59
|
-
const legendHeight = showLegend ? 30 : 0;
|
|
60
|
-
const xAxisHeight = showXAxis ? 30 : 0;
|
|
61
|
-
const yAxisWidth = showYAxis ? 40 : 0;
|
|
62
|
-
|
|
63
|
-
const chartWidth = dimensions.width - padding * 2 - yAxisWidth;
|
|
64
|
-
const chartHeight = dimensions.height - padding * 2 - titleHeight - legendHeight - xAxisHeight;
|
|
65
|
-
|
|
66
|
-
const { globalMinY, globalMaxY, xLabels } = useMemo(() => {
|
|
67
|
-
let minY = Infinity;
|
|
68
|
-
let maxY = -Infinity;
|
|
69
|
-
const allXValues: (number | Date)[] = [];
|
|
70
|
-
|
|
71
|
-
series.forEach(s => {
|
|
72
|
-
s.data.forEach(point => {
|
|
73
|
-
if (point.y < minY) minY = point.y;
|
|
74
|
-
if (point.y > maxY) maxY = point.y;
|
|
75
|
-
allXValues.push(point.x);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const labels = allXValues.map((x, idx) => {
|
|
80
|
-
if (x instanceof Date) {
|
|
81
|
-
return timeInterval ? formatTimeLabel(x, timeInterval) : x.toLocaleDateString();
|
|
82
|
-
}
|
|
83
|
-
return x.toString();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return { globalMinY: minY, globalMaxY: maxY, xLabels: labels };
|
|
87
|
-
}, [series, timeInterval]);
|
|
88
|
-
|
|
89
|
-
const yAxisLabels = useMemo(() => {
|
|
90
|
-
const range = globalMaxY - globalMinY;
|
|
91
|
-
const step = range / 4;
|
|
92
|
-
return Array.from({ length: 5 }, (_, i) => ({
|
|
93
|
-
value: globalMinY + i * step,
|
|
94
|
-
y: chartHeight - (i * chartHeight) / 4,
|
|
95
|
-
}));
|
|
96
|
-
}, [globalMinY, globalMaxY, chartHeight]);
|
|
97
|
-
|
|
98
|
-
const xAxisLabelsReduced = useMemo(() => {
|
|
99
|
-
return reduceLabels(xLabels, maxXLabels);
|
|
100
|
-
}, [xLabels, maxXLabels]);
|
|
101
|
-
|
|
102
|
-
const seriesPaths = useMemo(() => {
|
|
103
|
-
return series.map((s, seriesIndex) => {
|
|
104
|
-
const points = s.data.map((point, index) => {
|
|
105
|
-
const x = (index / (s.data.length - 1 || 1)) * chartWidth;
|
|
106
|
-
const normalizedY = normalize(point.y, globalMinY, globalMaxY);
|
|
107
|
-
const y = chartHeight - normalizedY * chartHeight;
|
|
108
|
-
return { x, y };
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const linePath = createLinePath(points);
|
|
112
|
-
const areaPath = createAreaPath(points, chartHeight);
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
linePath,
|
|
116
|
-
areaPath,
|
|
117
|
-
color: s.color,
|
|
118
|
-
label: s.label,
|
|
119
|
-
gradientId: `gradient-${seriesIndex}`,
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
}, [series, chartWidth, chartHeight, globalMinY, globalMaxY]);
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<View style={[styles.wrapper, { width: dimensions.width, height: dimensions.height, backgroundColor: theme.colors.surface, borderRadius: theme.radius.md, padding }]} testID={testID}>
|
|
126
|
-
{title && (
|
|
127
|
-
<RNText style={[styles.title, { color: theme.colors.text, fontSize: theme.fontScale.md, fontWeight: 'bold', marginBottom: theme.spacing.sm }]}>
|
|
128
|
-
{title}
|
|
129
|
-
</RNText>
|
|
130
|
-
)}
|
|
131
|
-
|
|
132
|
-
<View style={styles.chartRow}>
|
|
133
|
-
{showYAxis && (
|
|
134
|
-
<View style={[styles.yAxis, { width: yAxisWidth }]}>
|
|
135
|
-
{yAxisLabels.map((label, index) => (
|
|
136
|
-
<RNText key={`y-${index}`} style={[styles.yAxisLabel, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs, top: label.y - 6 }]}>
|
|
137
|
-
{label.value.toFixed(0)}
|
|
138
|
-
</RNText>
|
|
139
|
-
))}
|
|
140
|
-
</View>
|
|
141
|
-
)}
|
|
142
|
-
|
|
143
|
-
<View>
|
|
144
|
-
<Svg width={chartWidth} height={chartHeight}>
|
|
145
|
-
{showGradient && (
|
|
146
|
-
<Defs>
|
|
147
|
-
{seriesPaths.map((series, index) => (
|
|
148
|
-
<LinearGradient key={series.gradientId} id={series.gradientId} x1="0" y1="0" x2="0" y2="1">
|
|
149
|
-
<Stop offset="0%" stopColor={series.color} stopOpacity="0.4" />
|
|
150
|
-
<Stop offset="100%" stopColor={series.color} stopOpacity="0.05" />
|
|
151
|
-
</LinearGradient>
|
|
152
|
-
))}
|
|
153
|
-
</Defs>
|
|
154
|
-
)}
|
|
155
|
-
|
|
156
|
-
{showGrid && yAxisLabels.map((label, index) => (
|
|
157
|
-
<SvgLine key={`grid-${index}`} x1={0} y1={label.y} x2={chartWidth} y2={label.y} stroke={theme.colors.borderLight} strokeWidth={1} />
|
|
158
|
-
))}
|
|
159
|
-
|
|
160
|
-
{seriesPaths.map((series, index) => (
|
|
161
|
-
<React.Fragment key={`series-${index}`}>
|
|
162
|
-
<AnimatedPath d={series.areaPath} fill={showGradient ? `url(#${series.gradientId})` : series.color} opacity={showGradient ? 1 : 0.3} />
|
|
163
|
-
<AnimatedPath d={series.linePath} stroke={series.color} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" fill="transparent" />
|
|
164
|
-
</React.Fragment>
|
|
165
|
-
))}
|
|
166
|
-
</Svg>
|
|
167
|
-
|
|
168
|
-
{showXAxis && (
|
|
169
|
-
<View style={[styles.xAxis, { width: chartWidth }]}>
|
|
170
|
-
{xAxisLabelsReduced.map((item, index) => (
|
|
171
|
-
<RNText key={`x-${index}`} style={[styles.xAxisLabel, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs, left: (item.index / (xLabels.length - 1 || 1)) * chartWidth - 20 }]}>
|
|
172
|
-
{item.label}
|
|
173
|
-
</RNText>
|
|
174
|
-
))}
|
|
175
|
-
</View>
|
|
176
|
-
)}
|
|
177
|
-
</View>
|
|
178
|
-
</View>
|
|
179
|
-
|
|
180
|
-
{showLegend && (
|
|
181
|
-
<View style={styles.legend}>
|
|
182
|
-
{seriesPaths.map((series, index) => (
|
|
183
|
-
series.label && (
|
|
184
|
-
<View key={`legend-${index}`} style={styles.legendItem}>
|
|
185
|
-
<View style={[styles.legendColor, { backgroundColor: series.color }]} />
|
|
186
|
-
<RNText style={[styles.legendText, { color: theme.colors.textSecondary, fontSize: theme.fontScale.xs }]}>{series.label}</RNText>
|
|
187
|
-
</View>
|
|
188
|
-
)
|
|
189
|
-
))}
|
|
190
|
-
</View>
|
|
191
|
-
)}
|
|
192
|
-
</View>
|
|
193
|
-
);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
AreaChart.displayName = 'AreaChart';
|
|
197
|
-
|
|
198
|
-
const styles = StyleSheet.create({
|
|
199
|
-
wrapper: { justifyContent: 'flex-start', alignItems: 'flex-start' },
|
|
200
|
-
container: { justifyContent: 'center', alignItems: 'center' },
|
|
201
|
-
loadingText: { fontSize: 16 },
|
|
202
|
-
emptyText: { fontSize: 16 },
|
|
203
|
-
title: { textAlign: 'center', width: '100%' },
|
|
204
|
-
chartRow: { flexDirection: 'row', alignItems: 'flex-start' },
|
|
205
|
-
yAxis: { position: 'relative', marginRight: 8 },
|
|
206
|
-
yAxisLabel: { position: 'absolute', right: 0, textAlign: 'right' },
|
|
207
|
-
xAxis: { position: 'relative', height: 30, marginTop: 4 },
|
|
208
|
-
xAxisLabel: { position: 'absolute', width: 40, textAlign: 'center' },
|
|
209
|
-
legend: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'center', marginTop: 12, gap: 12 },
|
|
210
|
-
legendItem: { flexDirection: 'row', alignItems: 'center', gap: 6 },
|
|
211
|
-
legendColor: { width: 12, height: 12, borderRadius: 2 },
|
|
212
|
-
legendText: { textTransform: 'uppercase', letterSpacing: 0.5 },
|
|
213
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AreaChart Widget types
|
|
3
|
-
*/
|
|
4
|
-
import { BaseWidgetProps, TimeInterval } from '../../core';
|
|
5
|
-
|
|
6
|
-
export interface AreaChartDataPoint {
|
|
7
|
-
x: number | Date;
|
|
8
|
-
y: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface AreaChartSeries {
|
|
12
|
-
data: AreaChartDataPoint[];
|
|
13
|
-
color: string;
|
|
14
|
-
label?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface AreaChartData {
|
|
18
|
-
series: AreaChartSeries[];
|
|
19
|
-
title?: string;
|
|
20
|
-
timeInterval?: TimeInterval;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type AreaChartStyle = 'smooth' | 'linear';
|
|
24
|
-
|
|
25
|
-
export interface AreaChartWidgetProps extends BaseWidgetProps<AreaChartData> {
|
|
26
|
-
showXAxis?: boolean;
|
|
27
|
-
showYAxis?: boolean;
|
|
28
|
-
showGrid?: boolean;
|
|
29
|
-
showLegend?: boolean;
|
|
30
|
-
showGradient?: boolean;
|
|
31
|
-
stacked?: boolean;
|
|
32
|
-
curveStyle?: AreaChartStyle;
|
|
33
|
-
maxXLabels?: number;
|
|
34
|
-
}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BarChart Widget - Flexible bar chart for comparing values
|
|
3
|
-
*/
|
|
4
|
-
import React, { memo, useMemo } from 'react';
|
|
5
|
-
import { View, Text as RNText, StyleSheet } from 'react-native';
|
|
6
|
-
import Svg, { Rect } from 'react-native-svg';
|
|
7
|
-
import {
|
|
8
|
-
useWidgetDimensions,
|
|
9
|
-
useWidgetTheme,
|
|
10
|
-
normalize,
|
|
11
|
-
} from '../../core';
|
|
12
|
-
import { Text } from '../../renderer-svg/primitives';
|
|
13
|
-
import { BarChartWidgetProps } from './types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* BarChart Widget Component
|
|
17
|
-
*/
|
|
18
|
-
export const BarChart = memo<BarChartWidgetProps>(({
|
|
19
|
-
data: widgetData,
|
|
20
|
-
width,
|
|
21
|
-
height,
|
|
22
|
-
loading = false,
|
|
23
|
-
theme: themeOverride,
|
|
24
|
-
orientation = 'vertical',
|
|
25
|
-
barWidth: customBarWidth,
|
|
26
|
-
barSpacing = 8,
|
|
27
|
-
showValues = true,
|
|
28
|
-
showLabels = true,
|
|
29
|
-
minBarHeight = 4,
|
|
30
|
-
maxBars = 20,
|
|
31
|
-
testID,
|
|
32
|
-
}) => {
|
|
33
|
-
const theme = useWidgetTheme(themeOverride);
|
|
34
|
-
const dimensions = useWidgetDimensions(width, height, 300, 200);
|
|
35
|
-
|
|
36
|
-
// Handle states
|
|
37
|
-
if (loading) {
|
|
38
|
-
return (
|
|
39
|
-
<View
|
|
40
|
-
style={[
|
|
41
|
-
styles.container,
|
|
42
|
-
{
|
|
43
|
-
width: dimensions.width,
|
|
44
|
-
height: dimensions.height,
|
|
45
|
-
backgroundColor: theme.colors.surface,
|
|
46
|
-
borderRadius: theme.radius.md,
|
|
47
|
-
},
|
|
48
|
-
]}
|
|
49
|
-
testID={`${testID}-loading`}
|
|
50
|
-
>
|
|
51
|
-
<RNText style={[styles.loadingText, { color: theme.colors.textSecondary }]}>
|
|
52
|
-
Loading...
|
|
53
|
-
</RNText>
|
|
54
|
-
</View>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!widgetData || !widgetData.data || widgetData.data.length === 0) {
|
|
59
|
-
return (
|
|
60
|
-
<View
|
|
61
|
-
style={[
|
|
62
|
-
styles.container,
|
|
63
|
-
{
|
|
64
|
-
width: dimensions.width,
|
|
65
|
-
height: dimensions.height,
|
|
66
|
-
backgroundColor: theme.colors.surface,
|
|
67
|
-
borderRadius: theme.radius.md,
|
|
68
|
-
},
|
|
69
|
-
]}
|
|
70
|
-
testID={`${testID}-empty`}
|
|
71
|
-
>
|
|
72
|
-
<RNText style={[styles.emptyText, { color: theme.colors.textSecondary }]}>
|
|
73
|
-
No data
|
|
74
|
-
</RNText>
|
|
75
|
-
</View>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { data, title } = widgetData;
|
|
80
|
-
|
|
81
|
-
// Limit number of bars
|
|
82
|
-
const displayData = data.slice(0, maxBars);
|
|
83
|
-
|
|
84
|
-
// Calculate dimensions
|
|
85
|
-
const padding = theme.spacing.md;
|
|
86
|
-
const titleHeight = title ? theme.fontScale.md + theme.spacing.sm : 0;
|
|
87
|
-
const labelHeight = showLabels ? theme.fontScale.sm + theme.spacing.xs : 0;
|
|
88
|
-
const valueHeight = showValues ? theme.fontScale.sm + theme.spacing.xs : 0;
|
|
89
|
-
|
|
90
|
-
const chartHeight = dimensions.height - padding * 2 - titleHeight - labelHeight - valueHeight;
|
|
91
|
-
const chartWidth = dimensions.width - padding * 2;
|
|
92
|
-
|
|
93
|
-
// Find max value for scaling
|
|
94
|
-
const maxValue = useMemo(() => Math.max(...displayData.map(d => d.value)), [displayData]);
|
|
95
|
-
|
|
96
|
-
// Calculate bar width
|
|
97
|
-
const calculatedBarWidth = customBarWidth ||
|
|
98
|
-
(chartWidth - (displayData.length - 1) * barSpacing) / displayData.length;
|
|
99
|
-
|
|
100
|
-
// Generate bars
|
|
101
|
-
const bars = useMemo(() => {
|
|
102
|
-
return displayData.map((item, index) => {
|
|
103
|
-
const normalizedValue = normalize(item.value, 0, maxValue);
|
|
104
|
-
const barHeight = Math.max(normalizedValue * chartHeight, minBarHeight);
|
|
105
|
-
const barX = index * (calculatedBarWidth + barSpacing);
|
|
106
|
-
const barY = chartHeight - barHeight;
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
x: barX,
|
|
110
|
-
y: barY,
|
|
111
|
-
width: calculatedBarWidth,
|
|
112
|
-
height: barHeight,
|
|
113
|
-
color: item.color || theme.colors.chartPrimary,
|
|
114
|
-
value: item.value,
|
|
115
|
-
label: item.label,
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
}, [displayData, maxValue, chartHeight, calculatedBarWidth, barSpacing, minBarHeight, theme.colors.chartPrimary]);
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<View
|
|
122
|
-
style={[
|
|
123
|
-
styles.wrapper,
|
|
124
|
-
{
|
|
125
|
-
width: dimensions.width,
|
|
126
|
-
height: dimensions.height,
|
|
127
|
-
backgroundColor: theme.colors.surface,
|
|
128
|
-
borderRadius: theme.radius.md,
|
|
129
|
-
padding,
|
|
130
|
-
},
|
|
131
|
-
]}
|
|
132
|
-
testID={testID}
|
|
133
|
-
>
|
|
134
|
-
{/* Title */}
|
|
135
|
-
{title && (
|
|
136
|
-
<RNText
|
|
137
|
-
style={[
|
|
138
|
-
styles.title,
|
|
139
|
-
{
|
|
140
|
-
color: theme.colors.text,
|
|
141
|
-
fontSize: theme.fontScale.md,
|
|
142
|
-
marginBottom: theme.spacing.sm,
|
|
143
|
-
},
|
|
144
|
-
]}
|
|
145
|
-
>
|
|
146
|
-
{title}
|
|
147
|
-
</RNText>
|
|
148
|
-
)}
|
|
149
|
-
|
|
150
|
-
{/* Chart */}
|
|
151
|
-
<View style={styles.chartContainer}>
|
|
152
|
-
<Svg width={chartWidth} height={chartHeight + valueHeight}>
|
|
153
|
-
{/* Bars */}
|
|
154
|
-
{bars.map((bar, index) => (
|
|
155
|
-
<Rect
|
|
156
|
-
key={`bar-${index}`}
|
|
157
|
-
x={bar.x}
|
|
158
|
-
y={bar.y}
|
|
159
|
-
width={bar.width}
|
|
160
|
-
height={bar.height}
|
|
161
|
-
fill={bar.color}
|
|
162
|
-
rx={theme.radius.sm}
|
|
163
|
-
ry={theme.radius.sm}
|
|
164
|
-
/>
|
|
165
|
-
))}
|
|
166
|
-
|
|
167
|
-
{/* Values */}
|
|
168
|
-
{showValues && bars.map((bar, index) => (
|
|
169
|
-
<Text
|
|
170
|
-
key={`value-${index}`}
|
|
171
|
-
x={bar.x + bar.width / 2}
|
|
172
|
-
y={bar.y - 4}
|
|
173
|
-
text={bar.value.toString()}
|
|
174
|
-
fontSize={theme.fontScale.xs}
|
|
175
|
-
fill={theme.colors.textSecondary}
|
|
176
|
-
textAnchor="middle"
|
|
177
|
-
/>
|
|
178
|
-
))}
|
|
179
|
-
</Svg>
|
|
180
|
-
|
|
181
|
-
{/* Labels */}
|
|
182
|
-
{showLabels && (
|
|
183
|
-
<View style={styles.labelsContainer}>
|
|
184
|
-
{bars.map((bar, index) => (
|
|
185
|
-
<View
|
|
186
|
-
key={`label-${index}`}
|
|
187
|
-
style={[
|
|
188
|
-
styles.labelItem,
|
|
189
|
-
{ width: bar.width + barSpacing },
|
|
190
|
-
]}
|
|
191
|
-
>
|
|
192
|
-
<RNText
|
|
193
|
-
style={[
|
|
194
|
-
styles.labelText,
|
|
195
|
-
{
|
|
196
|
-
color: theme.colors.textSecondary,
|
|
197
|
-
fontSize: theme.fontScale.xs,
|
|
198
|
-
},
|
|
199
|
-
]}
|
|
200
|
-
numberOfLines={1}
|
|
201
|
-
>
|
|
202
|
-
{bar.label}
|
|
203
|
-
</RNText>
|
|
204
|
-
</View>
|
|
205
|
-
))}
|
|
206
|
-
</View>
|
|
207
|
-
)}
|
|
208
|
-
</View>
|
|
209
|
-
</View>
|
|
210
|
-
);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
BarChart.displayName = 'BarChart';
|
|
214
|
-
|
|
215
|
-
const styles = StyleSheet.create({
|
|
216
|
-
wrapper: {
|
|
217
|
-
justifyContent: 'flex-start',
|
|
218
|
-
alignItems: 'flex-start',
|
|
219
|
-
},
|
|
220
|
-
container: {
|
|
221
|
-
justifyContent: 'center',
|
|
222
|
-
alignItems: 'center',
|
|
223
|
-
},
|
|
224
|
-
loadingText: {
|
|
225
|
-
fontSize: 16,
|
|
226
|
-
},
|
|
227
|
-
emptyText: {
|
|
228
|
-
fontSize: 16,
|
|
229
|
-
},
|
|
230
|
-
title: {
|
|
231
|
-
fontWeight: 'bold',
|
|
232
|
-
textAlign: 'center',
|
|
233
|
-
width: '100%',
|
|
234
|
-
},
|
|
235
|
-
chartContainer: {
|
|
236
|
-
flex: 1,
|
|
237
|
-
width: '100%',
|
|
238
|
-
},
|
|
239
|
-
labelsContainer: {
|
|
240
|
-
flexDirection: 'row',
|
|
241
|
-
marginTop: 4,
|
|
242
|
-
},
|
|
243
|
-
labelItem: {
|
|
244
|
-
alignItems: 'center',
|
|
245
|
-
},
|
|
246
|
-
labelText: {
|
|
247
|
-
textAlign: 'center',
|
|
248
|
-
},
|
|
249
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BarChart Widget types
|
|
3
|
-
*/
|
|
4
|
-
import { BaseWidgetProps } from '../../core/types';
|
|
5
|
-
|
|
6
|
-
export interface BarDataPoint {
|
|
7
|
-
value: number;
|
|
8
|
-
label: string;
|
|
9
|
-
color?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface BarChartData {
|
|
13
|
-
data: BarDataPoint[];
|
|
14
|
-
title?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type BarOrientation = 'vertical' | 'horizontal';
|
|
18
|
-
|
|
19
|
-
export interface BarChartWidgetProps extends BaseWidgetProps<BarChartData> {
|
|
20
|
-
orientation?: BarOrientation;
|
|
21
|
-
barWidth?: number;
|
|
22
|
-
barSpacing?: number;
|
|
23
|
-
showValues?: boolean;
|
|
24
|
-
showLabels?: boolean;
|
|
25
|
-
minBarHeight?: number;
|
|
26
|
-
maxBars?: number;
|
|
27
|
-
}
|