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 styled from 'styled-components/macro';
import { usePermissions } from '@/plugins/usePermissions'; import { usePermissions } from '@/plugins/usePermissions';
import tw from 'twin.macro'; import tw from 'twin.macro';
import 'xterm/dist/xterm.css';
const theme = { const theme = {
background: 'transparent', background: 'transparent',

View file

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