diff --git a/AppImage/components/node-metrics-charts.tsx b/AppImage/components/node-metrics-charts.tsx index 7068307..3813381 100644 --- a/AppImage/components/node-metrics-charts.tsx +++ b/AppImage/components/node-metrics-charts.tsx @@ -24,12 +24,57 @@ interface NodeMetricsData { memoryZfsArc: number } +const CustomCpuTooltip = ({ active, payload, label }: any) => { + if (active && payload && payload.length) { + return ( +
+

{label}

+
+ {payload.map((entry: any, index: number) => ( +
+
+ {entry.name}: + {entry.value} +
+ ))} +
+
+ ) + } + return null +} + +const CustomMemoryTooltip = ({ active, payload, label }: any) => { + if (active && payload && payload.length) { + return ( +
+

{label}

+
+ {payload.map((entry: any, index: number) => ( +
+
+ {entry.name}: + {entry.value} GB +
+ ))} +
+
+ ) + } + return null +} + export function NodeMetricsCharts() { const [timeframe, setTimeframe] = useState("day") const [data, setData] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const [visibleLines, setVisibleLines] = useState({ + cpu: { cpu: true, load: true }, + memory: { memoryTotal: true, memoryUsed: true, memoryZfsArc: true, memoryFree: true }, + }) + useEffect(() => { console.log("[v0] NodeMetricsCharts component mounted") fetchMetrics() @@ -146,6 +191,39 @@ export function NodeMetricsCharts() { const tickInterval = Math.ceil(data.length / 8) + const handleLegendClick = (chartType: "cpu" | "memory", dataKey: string) => { + setVisibleLines((prev) => ({ + ...prev, + [chartType]: { + ...prev[chartType], + [dataKey as keyof (typeof prev)[typeof chartType]]: + !prev[chartType][dataKey as keyof (typeof prev)[typeof chartType]], + }, + })) + } + + const renderLegend = (chartType: "cpu" | "memory") => (props: any) => { + const { payload } = props + return ( +
+ {payload.map((entry: any, index: number) => { + const isVisible = visibleLines[chartType][entry.dataKey as keyof (typeof visibleLines)[typeof chartType]] + return ( +
handleLegendClick(chartType, entry.dataKey)} + style={{ opacity: isVisible ? 1 : 0.4 }} + > +
+ {entry.value} +
+ ) + })} +
+ ) + } + console.log("[v0] Render state - loading:", loading, "error:", error, "data length:", data.length) if (loading) { @@ -277,14 +355,8 @@ export function NodeMetricsCharts() { label={{ value: "Load", angle: 90, position: "insideRight", fill: "currentColor" }} domain={[0, "dataMax"]} /> - - + } /> + @@ -339,14 +413,8 @@ export function NodeMetricsCharts() { label={{ value: "GB", angle: -90, position: "insideLeft", fill: "currentColor" }} domain={[0, "dataMax"]} /> - - + } /> +