diff --git a/bun.lockb b/bun.lockb index 51cd29c..2ead69a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index a931d3d..12c70a5 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "react": "^18", "react-day-picker": "9.0.8", "react-dom": "^18", + "recharts": "^2.12.7", "sass": "^1.77.8", "tailwind-merge": "^2.5.2", "tailwindcss-animate": "^1.0.7" diff --git a/src/components/analytics/exif/EXIFDistribution.tsx b/src/components/analytics/exif/EXIFDistribution.tsx new file mode 100644 index 0000000..807b209 --- /dev/null +++ b/src/components/analytics/exif/EXIFDistribution.tsx @@ -0,0 +1,38 @@ +import { Card } from "@/components/ui/card"; +import PieChart, { IPieChartData } from "@/components/ui/pie-chart"; +import { getExifDistribution, ISupportedEXIFColumns } from "@/handlers/api/analytics.handler"; +import React, { useEffect, useState } from "react"; + +export interface IEXIFDistributionProps { + column: ISupportedEXIFColumns; + title: string; + description: string; +} + +export default function EXIFDistribution( + { column, title, description }: IEXIFDistributionProps +) { + const [chartData, setChartData] = useState([]); + const [loading, setLoading] = useState(false); + const [errorMessage, setErrorMessage] = useState(null); + + const fetchData = async () => { + return getExifDistribution(column) + .then(setChartData) + .finally(() => setLoading(false)); + }; + + useEffect(() => { + fetchData(); + }, [column]); + + + return ( + + + + ); +} diff --git a/src/components/ui/card.tsx b/src/components/ui/card.tsx index 77e9fb7..3c9063a 100644 --- a/src/components/ui/card.tsx +++ b/src/components/ui/card.tsx @@ -2,7 +2,7 @@ import * as React from "react" import { cn } from "@/lib/utils" -const Card = React.forwardRef< +const CardRoot = React.forwardRef< HTMLDivElement, React.HTMLAttributes >(({ className, ...props }, ref) => ( @@ -15,7 +15,7 @@ const Card = React.forwardRef< {...props} /> )) -Card.displayName = "Card" +CardRoot.displayName = "CardRoot" const CardHeader = React.forwardRef< HTMLDivElement, @@ -73,4 +73,23 @@ const CardFooter = React.forwardRef< )) CardFooter.displayName = "CardFooter" -export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } +interface CardProps { + title?: string + description?: string + + children: React.ReactNode +} +const Card = ({ children, title, description }: CardProps) => { + return ( + + {!!(title || description) && ( + + {title && {title}} + {description && {description}} + + )} + {children} + + ) +} +export { Card, CardRoot, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } diff --git a/src/components/ui/chart.tsx b/src/components/ui/chart.tsx new file mode 100644 index 0000000..b58b494 --- /dev/null +++ b/src/components/ui/chart.tsx @@ -0,0 +1,368 @@ +import * as React from "react" +import * as RechartsPrimitive from "recharts" +import { + NameType, + Payload, + ValueType, +} from "recharts/types/component/DefaultTooltipContent" + +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 ( +