"use client" import { useMemo } from "react" import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, PieChart, Pie, Cell, Legend } from "recharts" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" interface Dataset { Name: string Category: string Description: string Task: string Data_Type: string Source: string "Paper link": string Availability: string Contact: string } interface DatasetStatisticsProps { datasets: Dataset[] selectedCategory: string | null selectedDataType: string | null selectedAvailability: string | null onCategoryClick: (category: string) => void onDataTypeClick: (dataType: string) => void onAvailabilityClick: (availability: string) => void } const CATEGORY_COLORS = [ "#6366f1", // indigo "#10b981", // emerald "#f59e0b", // amber "#3b82f6", // blue "#8b5cf6", // violet "#06b6d4", // cyan ] const DATA_TYPE_COLORS = [ "#3b82f6", // blue "#10b981", // emerald "#6366f1", // indigo "#f59e0b", // amber "#8b5cf6", // violet "#06b6d4", // cyan ] const AVAILABILITY_COLORS = { "Open source": "#3b82f6", // blue "Gated": "#10b981", // emerald "Unknown": "#6b7280", // gray } export function DatasetStatistics({ datasets, selectedCategory, selectedDataType, selectedAvailability, onCategoryClick, onDataTypeClick, onAvailabilityClick }: DatasetStatisticsProps) { const categoryData = useMemo(() => { const counts: Record = {} datasets.forEach((dataset) => { if (dataset.Category) { counts[dataset.Category] = (counts[dataset.Category] || 0) + 1 } }) return Object.entries(counts) .map(([name, value]) => ({ name, value })) .sort((a, b) => b.value - a.value) }, [datasets]) const dataTypeData = useMemo(() => { const counts: Record = {} datasets.forEach((dataset) => { if (dataset.Data_Type) { counts[dataset.Data_Type] = (counts[dataset.Data_Type] || 0) + 1 } }) return Object.entries(counts) .map(([name, value]) => ({ name, value })) .sort((a, b) => b.value - a.value) }, [datasets]) const availabilityData = useMemo(() => { const counts: Record = {} datasets.forEach((dataset) => { if (dataset.Availability) { counts[dataset.Availability] = (counts[dataset.Availability] || 0) + 1 } }) return Object.entries(counts).map(([name, value]) => ({ name, value })) }, [datasets]) const CustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { return (

{payload[0].payload.name}

Count: {payload[0].value}

) } return null } const renderCustomBarLabel = (props: any) => { const { x, y, width, height, value } = props return ( {value} ) } return (
{/* Top Row: By Data Type and Availability */}
{/* By Data Type */} By Data Type {selectedDataType && ( (Click to clear filter) )} } /> onDataTypeClick(data.name)} cursor="pointer" > {dataTypeData.map((entry, index) => { const isSelected = selectedDataType === entry.name const shouldGreyscale = selectedDataType && !isSelected const color = shouldGreyscale ? "#94a3b8" : DATA_TYPE_COLORS[index % DATA_TYPE_COLORS.length] return ( ) })} {/* Availability */} Availability {selectedAvailability && ( (Click to clear filter) )} `${name}: ${value}`} outerRadius={80} fill="#8884d8" dataKey="value" onClick={(data) => onAvailabilityClick(data.name)} cursor="pointer" > {availabilityData.map((entry, index) => { const isSelected = selectedAvailability === entry.name const shouldGreyscale = selectedAvailability && !isSelected const originalColor = AVAILABILITY_COLORS[entry.name as keyof typeof AVAILABILITY_COLORS] || "#6b7280" const color = shouldGreyscale ? "#94a3b8" : originalColor return ( ) })} } /> {value}} />
{/* Bottom Row: By Category */}
By Category {selectedCategory && ( (Click to clear filter) )} } /> onCategoryClick(data.name)} cursor="pointer" > {categoryData.map((entry, index) => { const isSelected = selectedCategory === entry.name const shouldGreyscale = selectedCategory && !isSelected const color = shouldGreyscale ? "#94a3b8" : CATEGORY_COLORS[index % CATEGORY_COLORS.length] return ( ) })}
) }