Fix console and charting

This commit is contained in:
Dane Everitt 2020-07-04 22:36:28 -07:00
parent becad7b3c7
commit db7f3e5fc0
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 15 additions and 30 deletions

View file

@ -6,6 +6,7 @@ import { ServerContext } from '@/state/server';
import styled from 'styled-components/macro';
import { usePermissions } from '@/plugins/usePermissions';
import tw from 'twin.macro';
import 'xterm/dist/xterm.css';
const theme = {
background: 'transparent',

View file

@ -7,7 +7,7 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
import { faMemory, faMicrochip } from '@fortawesome/free-solid-svg-icons';
import tw from 'twin.macro';
const chartDefaults: ChartConfiguration = {
const chartDefaults = (ticks?: Chart.TickOptions | undefined): ChartConfiguration => ({
type: 'line',
options: {
legend: {
@ -45,21 +45,17 @@ const chartDefaults: ChartConfiguration = {
zeroLineColor: 'rgba(15, 178, 184, 0.45)',
zeroLineWidth: 3,
},
ticks: {
ticks: merge(ticks || {}, {
fontSize: 10,
fontFamily: '"IBM Plex Mono", monospace',
fontColor: 'rgb(229, 232, 235)',
min: 0,
beginAtZero: true,
maxTicksLimit: 5,
},
}),
} ],
},
},
};
const createDefaultChart = (ctx: CanvasRenderingContext2D, options?: ChartConfiguration): Chart => new Chart(ctx, {
...merge(chartDefaults, options || {}),
data: {
labels: Array(20).fill(''),
datasets: [
@ -84,18 +80,12 @@ export default () => {
return;
}
setMemory(createDefaultChart(node.getContext('2d')!, {
options: {
scales: {
yAxes: [ {
ticks: {
callback: (value) => `${value}Mb `,
suggestedMax: limits.memory,
},
} ],
},
},
}));
setMemory(
new Chart(node.getContext('2d')!, chartDefaults({
callback: (value) => `${value}Mb `,
suggestedMax: limits.memory,
}))
);
}, []);
const cpuRef = useCallback<(node: HTMLCanvasElement | null) => void>(node => {
@ -103,17 +93,11 @@ export default () => {
return;
}
setCpu(createDefaultChart(node.getContext('2d')!, {
options: {
scales: {
yAxes: [ {
ticks: {
callback: (value) => `${value}% `,
},
} ],
},
},
}));
setCpu(
new Chart(node.getContext('2d')!, chartDefaults({
callback: (value) => `${value}%`,
})),
);
}, []);
const statsListener = (data: string) => {