Skip to content

Commit cc06d1f

Browse files
authored
Fixes rounding when 0.001% or less on CPU usage. (pterodactyl#4207)
1 parent ccea09c commit cc06d1f

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

resources/scripts/components/server/console/StatGraphs.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default () => {
1616
const limits = ServerContext.useStoreState((state) => state.server.data!.limits);
1717
const previous = useRef<Record<'tx' | 'rx', number>>({ tx: -1, rx: -1 });
1818

19-
const cpu = useChartTickLabel('CPU', limits.cpu, '%');
19+
const cpu = useChartTickLabel('CPU', limits.cpu, '%', 2);
2020
const memory = useChartTickLabel('Memory', limits.memory, 'MB');
2121
const network = useChart('Network', {
2222
sets: 2,
@@ -56,8 +56,7 @@ export default () => {
5656
} catch (e) {
5757
return;
5858
}
59-
60-
cpu.push(values.cpu_absolute.toFixed(2));
59+
cpu.push(values.cpu_absolute);
6160
memory.push(Math.floor(values.memory_bytes / 1024 / 1024));
6261
network.push([
6362
previous.current.tx < 0 ? 0 : Math.max(0, values.network.tx_bytes - previous.current.tx),

resources/scripts/components/server/console/chart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function useChart(label: string, opts?: UseChartOptions) {
139139
return { props: { data, options }, push, clear };
140140
}
141141

142-
function useChartTickLabel(label: string, max: number, tickLabel: string) {
142+
function useChartTickLabel(label: string, max: number, tickLabel: string, roundTo?: number) {
143143
return useChart(label, {
144144
sets: 1,
145145
options: {
@@ -148,7 +148,7 @@ function useChartTickLabel(label: string, max: number, tickLabel: string) {
148148
suggestedMax: max,
149149
ticks: {
150150
callback(value) {
151-
return `${value}${tickLabel}`;
151+
return `${roundTo ? Number(value).toFixed(roundTo) : value}${tickLabel}`;
152152
},
153153
},
154154
},

0 commit comments

Comments
 (0)