diff --git a/src/app/dashboard/chart.tsx b/src/app/dashboard/chart.tsx new file mode 100644 index 0000000..dc59de4 --- /dev/null +++ b/src/app/dashboard/chart.tsx @@ -0,0 +1,109 @@ +"use client" + +import { TrendingUp } from "lucide-react" +import { Area, AreaChart, CartesianGrid, ResponsiveContainer, XAxis, YAxis } from "recharts" + +import { + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card" +import { + ChartConfig, + ChartContainer, + ChartTooltip, + ChartTooltipContent, +} from "@/components/ui/chart" + +const chartConfig = { + cpu: { + label: "CPU", + color: "var(--chart-2)", + }, + ram: { + label: "RAM", + color: "var(--chart-1)", + }, +} satisfies ChartConfig + +export function ChartAreaGradient({chartData}: {chartData: {hour: number, cpu: number, ram: number}[]}) { + return ( + + + CPU & RAM Usage + + Showing the average CPU and RAM usage over the last 24 hours. + + + + + + + + value+"h"} + height={34} + /> + + + } /> + + + + + + + + + + + + + + + + + + ) +} diff --git a/src/components/ui/chart.tsx b/src/components/ui/chart.tsx new file mode 100644 index 0000000..97cc280 --- /dev/null +++ b/src/components/ui/chart.tsx @@ -0,0 +1,353 @@ +"use client" + +import * as React from "react" +import * as RechartsPrimitive from "recharts" + +import { cn } from "@/lib/utils" + +// Format: { THEME_NAME: CSS_SELECTOR } +const THEMES = { light: "", dark: ".dark" } as const + +export type ChartConfig = { + [k in string]: { + label?: React.ReactNode + icon?: React.ComponentType + } & ( + | { color?: string; theme?: never } + | { color?: never; theme: Record } + ) +} + +type ChartContextProps = { + config: ChartConfig +} + +const ChartContext = React.createContext(null) + +function useChart() { + const context = React.useContext(ChartContext) + + if (!context) { + throw new Error("useChart must be used within a ") + } + + return context +} + +function ChartContainer({ + id, + className, + children, + config, + ...props +}: React.ComponentProps<"div"> & { + config: ChartConfig + children: React.ComponentProps< + typeof RechartsPrimitive.ResponsiveContainer + >["children"] +}) { + const uniqueId = React.useId() + const chartId = `chart-${id || uniqueId.replace(/:/g, "")}` + + return ( + +
+ + + {children} + +
+
+ ) +} + +const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => { + const colorConfig = Object.entries(config).filter( + ([, config]) => config.theme || config.color + ) + + if (!colorConfig.length) { + return null + } + + return ( +