From 717a4da3167e73bbdd47ebdefc98e5ad68797997 Mon Sep 17 00:00:00 2001 From: Matt Pocock Date: Wed, 4 Dec 2024 16:28:19 +0000 Subject: [PATCH] Added a line chart to show historical improvements --- apps/evalite-ui/app/components/ui/card.tsx | 79 ++++ apps/evalite-ui/app/components/ui/chart.tsx | 363 ++++++++++++++++++ .../app/components/ui/line-chart.tsx | 45 +++ apps/evalite-ui/app/routes/eval.$name.tsx | 12 +- apps/evalite-ui/package.json | 1 + .../example/src/content-generation.eval.ts | 3 + pnpm-lock.yaml | 252 ++++++++++++ 7 files changed, 754 insertions(+), 1 deletion(-) create mode 100644 apps/evalite-ui/app/components/ui/card.tsx create mode 100644 apps/evalite-ui/app/components/ui/chart.tsx create mode 100644 apps/evalite-ui/app/components/ui/line-chart.tsx diff --git a/apps/evalite-ui/app/components/ui/card.tsx b/apps/evalite-ui/app/components/ui/card.tsx new file mode 100644 index 0000000..08e7a15 --- /dev/null +++ b/apps/evalite-ui/app/components/ui/card.tsx @@ -0,0 +1,79 @@ +import * as React from "react" + +import { cn } from "~/lib/utils" + +const Card = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +Card.displayName = "Card" + +const CardHeader = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +CardHeader.displayName = "CardHeader" + +const CardTitle = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +CardTitle.displayName = "CardTitle" + +const CardDescription = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +CardDescription.displayName = "CardDescription" + +const CardContent = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +CardContent.displayName = "CardContent" + +const CardFooter = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +CardFooter.displayName = "CardFooter" + +export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } diff --git a/apps/evalite-ui/app/components/ui/chart.tsx b/apps/evalite-ui/app/components/ui/chart.tsx new file mode 100644 index 0000000..bb3acf6 --- /dev/null +++ b/apps/evalite-ui/app/components/ui/chart.tsx @@ -0,0 +1,363 @@ +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; +} + +const ChartContainer = React.forwardRef< + HTMLDivElement, + React.ComponentProps<"div"> & { + config: ChartConfig; + children: React.ComponentProps< + typeof RechartsPrimitive.ResponsiveContainer + >["children"]; + } +>(({ id, className, children, config, ...props }, ref) => { + const uniqueId = React.useId(); + const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`; + + return ( + +
+ + + {children} + +
+
+ ); +}); +ChartContainer.displayName = "Chart"; + +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 ( +