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

UsageDailyChart.ios.tsx

42 lines1.2 KB

1import { Chart, Host, type ChartDataPoint } from "@expo/ui/swift-ui";
2import { frame } from "@expo/ui/swift-ui/modifiers";
3import { useMemo } from "react";
4​
5import type { DailyTotals } from "@t3tools/shared/usageMerge";
6​
7import { buildChartDays, type UsageChartMetric } from "./usageChartData";
8import { useProviderColors } from "./usageProviders";
9​
10export interface UsageDailyChartProps {
11 readonly days: readonly string[];
12 readonly daily: readonly DailyTotals[];
13 readonly metric: UsageChartMetric;
14 readonly height: number;
16​
17export function UsageDailyChart({ days, daily, metric, height }: UsageDailyChartProps) {
18 const colors = useProviderColors();
19​
20 const data = useMemo((): ChartDataPoint[] => {
21 return buildChartDays(days, daily, metric).flatMap((day) =>
22 day.values.map((entry) => ({
23 x: day.day,
24 y: entry.value,
25 color: colors[entry.provider],
26 })),
27 );
28 }, [days, daily, metric, colors]);
29​
30 return (
31 <Host style={{ height, width: "100%" }}>
32 <Chart
33 type="bar"
34 data={data}
35 animate
36 showGrid={false}
37 barStyle={{ cornerRadius: 2 }}
38 modifiers={[frame({ height })]}
39 />
40 </Host>
41 );