Add maxMemory argument

This commit is contained in:
Hristo Nedelkov 2023-08-11 14:16:20 +03:00
parent 04b29d9e84
commit caf4469556
3 changed files with 12 additions and 6 deletions

View File

@ -12,20 +12,23 @@ type ChartData = {
id: string
color: string
data: DataPoint[]
maxMemory?: number
}
type DeviceMemoryProps = {
load: number[]
currentMemory: number[]
maxMemory?: number
}
const DeviceMemory: React.FC<DeviceMemoryProps> = ({ load }) => {
const DeviceMemory = ({ currentMemory, maxMemory }: DeviceMemoryProps) => {
const chartData: ChartData[] = [
{
id: 'cpu',
color: '#8DC6BC',
data: load.map((yValue, index: number) => ({
data: currentMemory.map((yValue, index: number) => ({
x: index + 1,
y: yValue,
})),
maxMemory: maxMemory,
},
]
const currentLoad =

View File

@ -96,7 +96,7 @@ function Content() {
Discover Nodes
</button>
</article>
<DeviceMemory load={[12,13,14,14,2,1,3]}></DeviceMemory>
<DeviceMemory currentMemory={[12,32,21,2,3,64]} maxMemory={64}/>
</div>
)
}

View File

@ -7,12 +7,15 @@ interface DataPoint {
interface ChartData {
id: string
data: DataPoint[]
maxMemory?: number
}
interface StandartLineChartProps {
data: ChartData[]
}
const StandartLineChart = ({ data }: StandartLineChartProps) => {
const maxMemory = data[0].maxMemory || 'auto'
return (
<ResponsiveLine
data={data}
@ -20,8 +23,8 @@ const StandartLineChart = ({ data }: StandartLineChartProps) => {
xScale={{ type: 'linear', min: 0, max: data[0].data.length }}
yScale={{
type: 'linear',
min: 'auto',
max: 'auto',
min: 0,
max: maxMemory,
stacked: true,
reverse: false,
}}