diff --git a/src/components/charts/Tooltip.tsx b/src/components/charts/Tooltip.tsx new file mode 100644 index 0000000..e360e7d --- /dev/null +++ b/src/components/charts/Tooltip.tsx @@ -0,0 +1,155 @@ +/* + * Custom Recharts tooltip component. + * Used in Rechart charts +* +* Code obtained from `tremor.so` +* https://github.com/tremorlabs/tremor/blob/main/src/components/chart-elements/common/ChartTooltip.tsx +*/ + +import { cn } from "@/lib/utils"; + +export const ChartTooltipFrame = ({ children }: { children: React.ReactNode }) => ( +
+ {children} +
+); + +export interface ChartTooltipRowProps { + value: string; + name: string; + color: string; +} + +export const ChartTooltipRow = ({ value, name, color }: ChartTooltipRowProps) => { + return ( +
+
+ +

+ {name} +

+
+

+ {value} +

+
+) }; + +export interface ChartTooltipProps { + active: boolean | undefined; + payload: any; + label: string; + // categoryColors: Map; + valueFormatter: { + (value: number): string; + } + labelFormatter?: { + (payload:any ) : string; + } +} + +const ChartTooltip = ({ + active, + payload, + label, + // categoryColors, + valueFormatter, + labelFormatter +}: ChartTooltipProps) => { + if (active && payload) { + const filteredPayload: any[] = payload.filter((item: any) => item.type !== "none"); + + return ( + +
+

+ {labelFormatter ? labelFormatter(payload) : label} +

+
+ +
+ {filteredPayload.map(({ value, name, payload }: { value: number; name: string, payload: any }, idx: number) => ( + + ))} +
+
+ ); + } + return null; +}; + +export default ChartTooltip;