Open History to see the last commit
1import { View } from "react-native";
2
3import type { DailyTotals } from "@t3tools/shared/usageMerge";
4
5import { buildChartDays, type UsageChartMetric } from "./usageChartData";
6import { useProviderColors } from "./usageProviders";
7
8export interface UsageDailyChartProps {
9 readonly days: readonly string[];
10 readonly daily: readonly DailyTotals[];
11 readonly metric: UsageChartMetric;
12 readonly height: number;
13}
14
15export function UsageDailyChart({ days, daily, metric, height }: UsageDailyChartProps) {
16 const colors = useProviderColors();
17 const chartDays = buildChartDays(days, daily, metric);
18 const max = chartDays.reduce((peak, day) => Math.max(peak, day.total), 0);
19
20 return (
21 <View style={{ height }} className="flex-row items-end gap-px">
22 {/* Use column-reverse: provider values are bottom-first and Hermes lacks toReversed. */}
23 {chartDays.map((day) => (
24 <View key={day.day} className="h-full flex-1 flex-col-reverse overflow-hidden rounded-sm">
25 {day.values.map((entry) => (
26 <View
27 key={entry.provider}
28 style={{
29 height: max === 0 ? 0 : (entry.value / max) * height,
30 backgroundColor: colors[entry.provider],
31 }}
32 />
33 ))}
34 </View>
35 ))}
36 </View>
37 );
38}