import React, { useState, useMemo } from "react"; import { type DataPoint } from "@/src/features/widgets/chart-library/chart-props"; import { CardContent } from "@/src/components/ui/card"; import LineChartTimeSeries from "@/src/features/widgets/chart-library/LineChartTimeSeries"; import VerticalBarChartTimeSeries from "@/src/features/widgets/chart-library/VerticalBarChartTimeSeries"; import HorizontalBarChart from "@/src/features/widgets/chart-library/HorizontalBarChart"; import VerticalBarChart from "@/src/features/widgets/chart-library/VerticalBarChart"; import PieChart from "@/src/features/widgets/chart-library/PieChart"; import HistogramChart from "@/src/features/widgets/chart-library/HistogramChart"; import { type DashboardWidgetChartType } from "@langfuse/shared/src/db"; import { Button } from "@/src/components/ui/button"; import { AlertCircle } from "lucide-react"; import { BigNumber } from "@/src/features/widgets/chart-library/BigNumber"; import { PivotTable } from "@/src/features/widgets/chart-library/PivotTable"; import { type OrderByState } from "@langfuse/shared"; export const Chart = ({ chartType, data, rowLimit, chartConfig, sortState, onSortChange, isLoading = false, }: { chartType: DashboardWidgetChartType; data: DataPoint[]; rowLimit: number; chartConfig?: { type: DashboardWidgetChartType; row_limit?: number; bins?: number; dimensions?: string[]; metrics?: string[]; defaultSort?: OrderByState; }; sortState?: OrderByState | null; onSortChange?: (sortState: OrderByState | null) => void; isLoading?: boolean; }) => { const [forceRender, setForceRender] = useState(false); const shouldWarn = data.length > 2000 && !forceRender; const renderedData = useMemo(() => { return data.map((item) => { return { ...item, time_dimension: item.time_dimension ? new Date(item.time_dimension).toLocaleTimeString("en-US", { year: "2-digit", month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit", }) : undefined, }; }); }, [data]); const renderChart = () => { switch (chartType) { case "LINE_TIME_SERIES": return ; case "BAR_TIME_SERIES": return ; case "HORIZONTAL_BAR": return ; case "VERTICAL_BAR": return ; case "PIE": return ; case "HISTOGRAM": return ; case "NUMBER": { return ; } case "PIVOT_TABLE": { // Extract pivot table configuration from chartConfig const pivotConfig = { dimensions: chartConfig?.dimensions ?? [], metrics: chartConfig?.metrics ?? ["metric"], // Use metrics from chartConfig rowLimit: chartConfig?.row_limit ?? rowLimit, defaultSort: chartConfig?.defaultSort, }; return ( ); } default: return ; } }; const renderWarning = () => (

Large Dataset Warning

This chart has more than 2,000 unique data points. Rendering it may be slow or may crash your browser. Try to reduce the number of dimensions by adding more selective filters or choosing a coarser breakdown dimension.

); return ( {shouldWarn ? renderWarning() : renderChart()} ); };