Skip to content

Commit db7f3e5

Browse files
committed
Fix console and charting
1 parent becad7b commit db7f3e5

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

resources/scripts/components/server/Console.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ServerContext } from '@/state/server';
66
import styled from 'styled-components/macro';
77
import { usePermissions } from '@/plugins/usePermissions';
88
import tw from 'twin.macro';
9+
import 'xterm/dist/xterm.css';
910

1011
const theme = {
1112
background: 'transparent',

resources/scripts/components/server/StatGraphs.tsx

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
77
import { faMemory, faMicrochip } from '@fortawesome/free-solid-svg-icons';
88
import tw from 'twin.macro';
99

10-
const chartDefaults: ChartConfiguration = {
10+
const chartDefaults = (ticks?: Chart.TickOptions | undefined): ChartConfiguration => ({
1111
type: 'line',
1212
options: {
1313
legend: {
@@ -45,21 +45,17 @@ const chartDefaults: ChartConfiguration = {
4545
zeroLineColor: 'rgba(15, 178, 184, 0.45)',
4646
zeroLineWidth: 3,
4747
},
48-
ticks: {
48+
ticks: merge(ticks || {}, {
4949
fontSize: 10,
5050
fontFamily: '"IBM Plex Mono", monospace',
5151
fontColor: 'rgb(229, 232, 235)',
5252
min: 0,
5353
beginAtZero: true,
5454
maxTicksLimit: 5,
55-
},
55+
}),
5656
} ],
5757
},
5858
},
59-
};
60-
61-
const createDefaultChart = (ctx: CanvasRenderingContext2D, options?: ChartConfiguration): Chart => new Chart(ctx, {
62-
...merge(chartDefaults, options || {}),
6359
data: {
6460
labels: Array(20).fill(''),
6561
datasets: [
@@ -84,36 +80,24 @@ export default () => {
8480
return;
8581
}
8682

87-
setMemory(createDefaultChart(node.getContext('2d')!, {
88-
options: {
89-
scales: {
90-
yAxes: [ {
91-
ticks: {
92-
callback: (value) => `${value}Mb `,
93-
suggestedMax: limits.memory,
94-
},
95-
} ],
96-
},
97-
},
98-
}));
83+
setMemory(
84+
new Chart(node.getContext('2d')!, chartDefaults({
85+
callback: (value) => `${value}Mb `,
86+
suggestedMax: limits.memory,
87+
}))
88+
);
9989
}, []);
10090

10191
const cpuRef = useCallback<(node: HTMLCanvasElement | null) => void>(node => {
10292
if (!node) {
10393
return;
10494
}
10595

106-
setCpu(createDefaultChart(node.getContext('2d')!, {
107-
options: {
108-
scales: {
109-
yAxes: [ {
110-
ticks: {
111-
callback: (value) => `${value}% `,
112-
},
113-
} ],
114-
},
115-
},
116-
}));
96+
setCpu(
97+
new Chart(node.getContext('2d')!, chartDefaults({
98+
callback: (value) => `${value}%`,
99+
})),
100+
);
117101
}, []);
118102

119103
const statsListener = (data: string) => {

0 commit comments

Comments
 (0)