Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

UsageDailyChart.tsx

39 lines1.3 KB

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;
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 {/* column-reverse stacks the bottom-first provider values upward
23 without reversing the array (Hermes lacks Array#toReversed). */}
24 {chartDays.map((day) => (
25 <View key={day.day} className="h-full flex-1 flex-col-reverse overflow-hidden rounded-sm">
26 {day.values.map((entry) => (
27 <View
28 key={entry.provider}
29 style={{
30 height: max === 0 ? 0 : (entry.value / max) * height,
31 backgroundColor: colors[entry.provider],
32 }}
33 />
34 ))}
35 </View>
36 ))}
37 </View>
38 );