From 7e1d26174b7159a925822a6ac38110ab138861db Mon Sep 17 00:00:00 2001 From: andersonid Date: Sat, 4 Oct 2025 11:54:54 -0300 Subject: [PATCH] Restore original Victory.js pie chart with real data - Revert to Victory.VictoryPie component (original format) - Keep real data from /api/v1/namespace-distribution - Maintain hover effects and summary statistics - Fix chart rendering while preserving data accuracy --- app/static/index.html | 123 +++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 31 deletions(-) diff --git a/app/static/index.html b/app/static/index.html index f39be2f..b7fcbf5 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -2138,38 +2138,82 @@ return; } - // Add summary information + // Generate colors for namespaces + const colors = ['#0066CC', '#CC0000', '#00CC66', '#FF8800', '#CC00CC', '#666666', '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7']; + + // Prepare data for Victory chart + const chartData = data.map((item, index) => ({ + x: item.x, + y: item.y, + color: colors[index % colors.length], + podCount: item.podCount || 0, + memoryRequests: item.memoryRequests || 0 + })); + + const chart = React.createElement(Victory.VictoryPie, { + width: container.offsetWidth || 500, + height: 300, + data: chartData, + colorScale: chartData.map(item => item.color), + padding: { top: 20, bottom: 20, left: 20, right: 20 }, + style: { + parent: { + background: '#1A1A1A', + width: '100%', + height: '100%' + }, + labels: { + fill: '#ccc', + fontSize: 11, + fontFamily: 'Red Hat Text, sans-serif' + } + }, + labelComponent: React.createElement(Victory.VictoryLabel, { + style: { + fill: '#ccc', + fontSize: 11, + fontFamily: 'Red Hat Text, sans-serif' + }, + labelPlacement: 'perpendicular', + text: (datum) => { + const cpuCores = datum.y.toFixed(2); + const podCount = datum.podCount; + return `${datum.x}\n${cpuCores} cores\n${podCount} pods`; + } + }), + events: [{ + target: "data", + eventHandlers: { + onMouseOver: () => { + return [{ + target: "labels", + mutation: (props) => { + return { + style: Object.assign({}, props.style, { fill: "#fff", fontSize: 12, fontWeight: "bold" }) + }; + } + }]; + }, + onMouseOut: () => { + return [{ + target: "labels", + mutation: (props) => { + return { + style: Object.assign({}, props.style, { fill: "#ccc", fontSize: 11, fontWeight: "normal" }) + }; + } + }]; + } + } + }] + }); + + // Add summary information below the chart const totalCpu = data.reduce((sum, item) => sum + item.y, 0); const totalPods = data.reduce((sum, item) => sum + (item.podCount || 0), 0); - // Create simple HTML pie chart instead of Victory - const colors = ['#0066CC', '#CC0000', '#00CC66', '#FF8800', '#CC00CC', '#666666', '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7']; - - let pieHtml = '
'; - pieHtml += '
'; - - data.forEach((item, index) => { - const percentage = totalCpu > 0 ? ((item.y / totalCpu) * 100).toFixed(1) : 0; - const color = colors[index % colors.length]; - - pieHtml += ` -
-
-
-
${item.x}
-
- ${item.y.toFixed(2)} cores (${percentage}%) • ${item.podCount} pods -
-
-
- `; - }); - - pieHtml += '
'; - - // Add summary statistics - pieHtml += ` -
+ const summaryHtml = ` +
Total CPU Requests
@@ -2186,10 +2230,27 @@
`; + + // Create a wrapper div to hold both chart and summary + const wrapper = document.createElement('div'); + wrapper.style.width = '100%'; + wrapper.style.height = '100%'; + wrapper.style.display = 'flex'; + wrapper.style.flexDirection = 'column'; - pieHtml += '
'; + const chartDiv = document.createElement('div'); + chartDiv.style.flex = '1'; + chartDiv.style.minHeight = '200px'; - container.innerHTML = pieHtml; + wrapper.appendChild(chartDiv); + wrapper.innerHTML += summaryHtml; + + // Clear container and add wrapper + container.innerHTML = ''; + container.appendChild(wrapper); + + // Render chart in the chart div + ReactDOM.render(chart, chartDiv); } // 3. Issues by Severity Timeline