diff --git a/frontend/src/components/ApplicationChart.tsx b/frontend/src/components/ApplicationChart.tsx index dfef0bda..668b2234 100644 --- a/frontend/src/components/ApplicationChart.tsx +++ b/frontend/src/components/ApplicationChart.tsx @@ -1,6 +1,6 @@ "use client"; -import React from "react"; +import React, { useState } from "react"; import { Pie } from "react-chartjs-2"; import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; @@ -11,35 +11,92 @@ interface ApplicationChartProps { } const ApplicationChart: React.FC = ({ data }) => { - const chartData = () => { - const appCounts: Record = {}; + const [visibleCount, setVisibleCount] = useState(20); // Zeigt zuerst 20 an + const [highlighted, setHighlighted] = useState(null); + const [chartStartIndex, setChartStartIndex] = useState(0); - data.forEach((item) => { - appCounts[item.nsapp] = (appCounts[item.nsapp] || 0) + 1; - }); + const appCounts: Record = {}; + data.forEach((item) => { + appCounts[item.nsapp] = (appCounts[item.nsapp] || 0) + 1; + }); - return { - labels: Object.keys(appCounts), - datasets: [ - { - label: "Applications", - data: Object.values(appCounts), - backgroundColor: [ - "#ff6384", - "#36a2eb", - "#ffce56", - "#4bc0c0", - "#9966ff", - "#ff9f40", - ], - }, - ], - }; + const sortedApps = Object.entries(appCounts) + .sort(([, a], [, b]) => b - a) + .slice(0, visibleCount); + + const chartApps = sortedApps.slice(chartStartIndex, chartStartIndex + 20); + + const chartData = { + labels: chartApps.map(([name]) => name), + datasets: [ + { + label: "Applications", + data: chartApps.map(([, count]) => count), + backgroundColor: [ + "#ff6384", + "#36a2eb", + "#ffce56", + "#4bc0c0", + "#9966ff", + "#ff9f40", + ], + }, + ], }; return ( -
- +
+ + + + + + + + + {sortedApps.map(([name, count]) => ( + setHighlighted(name)} + onMouseLeave={() => setHighlighted(null)} + > + + + + ))} + +
ApplicationCount
{name}{count}
+ + {visibleCount < Object.keys(appCounts).length && ( + + )} + +
+ +
+ +
+ + +
); };