"use client"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { Chart as ChartJS, ArcElement, Tooltip as ChartTooltip, Legend } from "chart.js"; import ChartDataLabels from "chartjs-plugin-datalabels"; import { BarChart3, PieChart } from "lucide-react"; import React, { useState } from "react"; import { Pie, Bar } from "react-chartjs-2"; ChartJS.register(ArcElement, ChartTooltip, Legend, ChartDataLabels); interface SummaryData { nsapp_count: Record; } interface ApplicationChartProps { data: SummaryData | null; } const ITEMS_PER_PAGE = 20; const CHART_COLORS = [ "#ff6384", "#36a2eb", "#ffce56", "#4bc0c0", "#9966ff", "#ff9f40", "#4dc9f6", "#f67019", "#537bc4", "#acc236", "#166a8f", "#00a950", "#58595b", "#8549ba", ]; export default function ApplicationChart({ data }: ApplicationChartProps) { const [isChartOpen, setIsChartOpen] = useState(false); const [isTableOpen, setIsTableOpen] = useState(false); const [chartStartIndex, setChartStartIndex] = useState(0); const [tableLimit, setTableLimit] = useState(ITEMS_PER_PAGE); if (!data) return null; const sortedApps = Object.entries(data.nsapp_count) .sort(([, a], [, b]) => b - a); const chartApps = sortedApps.slice( chartStartIndex, chartStartIndex + ITEMS_PER_PAGE ); const chartData = { labels: chartApps.map(([name]) => name), datasets: [ { data: chartApps.map(([, count]) => count), backgroundColor: CHART_COLORS, }, ], }; const chartOptions = { plugins: { legend: { display: false }, datalabels: { color: "white", font: { weight: "bold" as const }, formatter: (value: number, context: any) => { const label = context.chart.data.labels?.[context.dataIndex]; return `${label}\n(${value})`; }, }, }, responsive: true, maintainAspectRatio: false, }; return (
Open Chart View Open Table View Applications Distribution
Applications Count
Application Count {sortedApps.slice(0, tableLimit).map(([name, count]) => ( {name} {count} ))}
{tableLimit < sortedApps.length && ( )}
); }