Skip to content

Commit 1767ec5

Browse files
Merge pull request #91 from NessieCanCode/convert-pie-chart-to-kpi-tile
Add KPI tile for top PIs
2 parents 8cba418 + 109b549 commit 1767ec5

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/slurmcostmanager.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ nav button:hover {
148148
flex: 0 0 200px;
149149
position: relative;
150150
width: 200px;
151-
height: 120px;
151+
min-height: 120px;
152152

153153
}
154154
.kpi-label {

src/slurmcostmanager.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ function KpiTile({ label, value, renderChart }) {
165165
'div',
166166
{ className: 'kpi-tile' },
167167
React.createElement('div', { className: 'kpi-label' }, label),
168-
React.createElement('div', { className: 'kpi-value' }, value),
168+
value !== undefined && value !== null &&
169+
React.createElement('div', { className: 'kpi-value' }, value),
169170
renderChart && renderChart()
170171
);
171172
}
@@ -279,7 +280,7 @@ function HistoricalUsageChart({ monthly }) {
279280
return React.createElement('div', { className: 'chart-container' }, React.createElement('canvas', { ref: canvasRef, width: 600, height: 300 }));
280281
}
281282

282-
function PiConsumptionChart({ details }) {
283+
function PiConsumptionChart({ details, width = 300, height = 300, legend = true }) {
283284
const canvasRef = useRef(null);
284285
useEffect(() => {
285286
if (!canvasRef.current) return;
@@ -323,18 +324,18 @@ function PiConsumptionChart({ details }) {
323324
responsive: false,
324325
maintainAspectRatio: false,
325326
plugins: {
326-
legend: { position: 'right' }
327+
legend: legend ? { position: 'right' } : { display: false }
327328
}
328329
}
329330
});
330331

331332
return () => chart.destroy();
332-
}, [details]);
333+
}, [details, width, height, legend]);
333334

334335
return React.createElement(
335336
'div',
336-
{ className: 'chart-container', style: { width: '300px', height: '300px' } },
337-
React.createElement('canvas', { ref: canvasRef, width: 300, height: 300 })
337+
{ className: 'chart-container', style: { width: `${width}px`, height: `${height}px` } },
338+
React.createElement('canvas', { ref: canvasRef, width, height })
338339
);
339340
}
340341

@@ -501,6 +502,17 @@ function Summary({ summary, details, daily, monthly }) {
501502
actual: summary.total,
502503
target: targetRevenue
503504
})
505+
}),
506+
React.createElement(KpiTile, {
507+
label: 'Top 10 PIs',
508+
value: null,
509+
renderChart: () =>
510+
React.createElement(PiConsumptionChart, {
511+
details,
512+
width: 120,
513+
height: 120,
514+
legend: false
515+
})
504516
})
505517
),
506518
React.createElement('h3', null, 'Top 10 PIs by consumption'),

0 commit comments

Comments
 (0)