Colorize graph lines red if above "bad" threshold in CPU Card

This commit is contained in:
Hristo Nedelkov 2023-09-27 22:39:40 +03:00
parent 76a279b3dd
commit 102fafa4e2
1 changed files with 12 additions and 9 deletions

View File

@ -19,20 +19,23 @@ type DeviceCPULoadProps = {
load: number[] load: number[]
} }
const DeviceCPULoad: React.FC<DeviceCPULoadProps> = ({ load }) => { const DeviceCPULoad: React.FC<DeviceCPULoadProps> = ({ load }) => {
const dataObj = load.map((yValue, index: number) => ({
x: index + 1,
y: yValue,
}))
const currentLoad =
dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0
const message = currentLoad < 80 ? 'Good' : 'Poor'
const chartData: ChartData[] = [ const chartData: ChartData[] = [
{ {
id: 'cpu', id: 'cpu',
color: '#8DC6BC', color: message === 'Good' ? '#8DC6BC' : '#e95460',
data: load.map((yValue, index: number) => ({ data: dataObj,
x: index + 1,
y: yValue,
})),
}, },
] ]
const currentLoad =
chartData[0].data.length > 0 ? chartData[0].data[chartData[0].data.length - 1].y : 0
const message = currentLoad < 80 ? 'Good' : 'Poor'
return ( return (
<Shadow <Shadow