"use client"; import { StatCard } from "@pythnetwork/component-library/StatCard"; import clsx from "clsx"; import dynamic from "next/dynamic"; import { type ElementType, type ComponentProps, type ReactNode, Suspense, useState, useMemo, useCallback, } from "react"; import { ResponsiveContainer, Tooltip, Line, XAxis, YAxis } from "recharts"; import type { CategoricalChartState } from "recharts/types/chart/types"; import styles from "./index.module.scss"; const LineChart = dynamic( () => import("recharts").then((recharts) => recharts.LineChart), { ssr: false, }, ); const CHART_HEIGHT = 36; type OwnProps = { chartClassName?: string | undefined; data: Point[]; }; type Point = { x: T; y: number; displayX?: ReactNode | undefined; displayY?: ReactNode | undefined; }; type Props = Omit< ComponentProps>, keyof OwnProps | "children" > & OwnProps; export const ChartCard = ({ className, chartClassName, data, stat, miniStat, ...props }: Props) => { const [selectedPoint, setSelectedPoint] = useState>( undefined, ); const selectedDate = useMemo( () => selectedPoint ? (selectedPoint.displayX ?? selectedPoint.x) : undefined, [selectedPoint], ); const domain = useMemo( () => [ Math.min(...data.map((point) => point.y)), Math.max(...data.map((point) => point.y)), ], [data], ); const updateSelectedPoint = useCallback( (chart: CategoricalChartState) => { setSelectedPoint( (chart.activePayload as { payload: Point }[] | undefined)?.[0] ?.payload, ); }, [setSelectedPoint], ); return ( } > <>} /> ); };