From a59df2500ecb9b8f5b3ada973f46d62a151ade28 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 30 Jun 2021 11:27:48 -0400 Subject: [PATCH] Cap cpu chart label values to 2 decimal points Signed-off-by: Sebastian Malton --- .../+cluster/cluster-pie-charts.tsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/renderer/components/+cluster/cluster-pie-charts.tsx b/src/renderer/components/+cluster/cluster-pie-charts.tsx index 609f41d1ad..979a91f0bb 100644 --- a/src/renderer/components/+cluster/cluster-pie-charts.tsx +++ b/src/renderer/components/+cluster/cluster-pie-charts.tsx @@ -33,6 +33,10 @@ import { bytesToUnits } from "../../utils"; import { ThemeStore } from "../../theme.store"; import { getMetricLastPoints } from "../../api/endpoints/metrics.api"; +function createLabels(rawLabelData: [string, number | undefined][]): string[] { + return rawLabelData.map(([key, value]) => `${key}: ${value?.toFixed(2) || "N/A"}`); +} + export const ClusterPieCharts = observer(() => { const renderLimitWarning = () => { return ( @@ -51,7 +55,7 @@ export const ClusterPieCharts = observer(() => { const cpuLimitsOverload = cpuLimits > cpuAllocatableCapacity; const memoryLimitsOverload = memoryLimits > memoryAllocatableCapacity; const defaultColor = ThemeStore.getInstance().activeTheme.colors.pieChartDefaultColor; - + if (!memoryCapacity || !cpuCapacity || !podCapacity || !memoryAllocatableCapacity || !cpuAllocatableCapacity || !podAllocatableCapacity) return null; const cpuData: ChartData = { datasets: [ @@ -92,13 +96,13 @@ export const ClusterPieCharts = observer(() => { label: "Limits" }, ], - labels: [ - `Usage: ${cpuUsage ? cpuUsage.toFixed(2) : "N/A"}`, - `Requests: ${cpuRequests ? cpuRequests.toFixed(2) : "N/A"}`, - `Limits: ${cpuLimits ? cpuLimits.toFixed(2) : "N/A"}`, - `Allocatable Capacity: ${cpuAllocatableCapacity || "N/A"}`, - `Capacity: ${cpuCapacity || "N/A"}` - ] + labels: createLabels([ + ["Usage", cpuUsage], + ["Requests", cpuRequests], + ["Limits", cpuLimits], + ["Allocatable Capacity", cpuAllocatableCapacity], + ["Capacity", cpuCapacity], + ]), }; const memoryData: ChartData = { datasets: [