mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
fix: better init detail chart
This commit is contained in:
parent
250d0baff8
commit
3413c73889
@ -102,7 +102,12 @@ function CpuChart({ data }: { data: NezhaAPISafe }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const timestamp = Date.now().toString();
|
const timestamp = Date.now().toString();
|
||||||
const newData = [...cpuChartData, { timeStamp: timestamp, cpu: cpu }];
|
let newData = [] as cpuChartData[];
|
||||||
|
if (cpuChartData.length === 0) {
|
||||||
|
newData = [{ timeStamp: timestamp, cpu: cpu }, { timeStamp: timestamp, cpu: cpu }];
|
||||||
|
} else {
|
||||||
|
newData = [...cpuChartData, { timeStamp: timestamp, cpu: cpu }];
|
||||||
|
}
|
||||||
if (newData.length > 30) {
|
if (newData.length > 30) {
|
||||||
newData.shift();
|
newData.shift();
|
||||||
}
|
}
|
||||||
@ -194,10 +199,12 @@ function ProcessChart({ data }: { data: NezhaAPISafe }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const timestamp = Date.now().toString();
|
const timestamp = Date.now().toString();
|
||||||
const newData = [
|
let newData = [] as processChartData[];
|
||||||
...processChartData,
|
if (processChartData.length === 0) {
|
||||||
{ timeStamp: timestamp, process: process },
|
newData = [{ timeStamp: timestamp, process: process }, { timeStamp: timestamp, process: process }];
|
||||||
];
|
} else {
|
||||||
|
newData = [...processChartData, { timeStamp: timestamp, process: process }];
|
||||||
|
}
|
||||||
if (newData.length > 30) {
|
if (newData.length > 30) {
|
||||||
newData.shift();
|
newData.shift();
|
||||||
}
|
}
|
||||||
@ -276,10 +283,12 @@ function MemChart({ data }: { data: NezhaAPISafe }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const timestamp = Date.now().toString();
|
const timestamp = Date.now().toString();
|
||||||
const newData = [
|
let newData = [] as memChartData[];
|
||||||
...memChartData,
|
if (memChartData.length === 0) {
|
||||||
{ timeStamp: timestamp, mem: mem, swap: swap },
|
newData = [{ timeStamp: timestamp, mem: mem, swap: swap }, { timeStamp: timestamp, mem: mem, swap: swap }];
|
||||||
];
|
} else {
|
||||||
|
newData = [...memChartData, { timeStamp: timestamp, mem: mem, swap: swap }];
|
||||||
|
}
|
||||||
if (newData.length > 30) {
|
if (newData.length > 30) {
|
||||||
newData.shift();
|
newData.shift();
|
||||||
}
|
}
|
||||||
@ -395,7 +404,12 @@ function DiskChart({ data }: { data: NezhaAPISafe }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const timestamp = Date.now().toString();
|
const timestamp = Date.now().toString();
|
||||||
const newData = [...diskChartData, { timeStamp: timestamp, disk: disk }];
|
let newData = [] as diskChartData[];
|
||||||
|
if (diskChartData.length === 0) {
|
||||||
|
newData = [{ timeStamp: timestamp, disk: disk }, { timeStamp: timestamp, disk: disk }];
|
||||||
|
} else {
|
||||||
|
newData = [...diskChartData, { timeStamp: timestamp, disk: disk }];
|
||||||
|
}
|
||||||
if (newData.length > 30) {
|
if (newData.length > 30) {
|
||||||
newData.shift();
|
newData.shift();
|
||||||
}
|
}
|
||||||
@ -487,10 +501,12 @@ function NetworkChart({ data }: { data: NezhaAPISafe }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const timestamp = Date.now().toString();
|
const timestamp = Date.now().toString();
|
||||||
const newData = [
|
let newData = [] as networkChartData[];
|
||||||
...networkChartData,
|
if (networkChartData.length === 0) {
|
||||||
{ timeStamp: timestamp, upload: up, download: down },
|
newData = [{ timeStamp: timestamp, upload: up, download: down }, { timeStamp: timestamp, upload: up, download: down }];
|
||||||
];
|
} else {
|
||||||
|
newData = [...networkChartData, { timeStamp: timestamp, upload: up, download: down }];
|
||||||
|
}
|
||||||
if (newData.length > 30) {
|
if (newData.length > 30) {
|
||||||
newData.shift();
|
newData.shift();
|
||||||
}
|
}
|
||||||
@ -605,10 +621,12 @@ function ConnectChart({ data }: { data: NezhaAPISafe }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const timestamp = Date.now().toString();
|
const timestamp = Date.now().toString();
|
||||||
const newData = [
|
let newData = [] as connectChartData[];
|
||||||
...connectChartData,
|
if (connectChartData.length === 0) {
|
||||||
{ timeStamp: timestamp, tcp: tcp, udp: udp },
|
newData = [{ timeStamp: timestamp, tcp: tcp, udp: udp }, { timeStamp: timestamp, tcp: tcp, udp: udp }];
|
||||||
];
|
} else {
|
||||||
|
newData = [...connectChartData, { timeStamp: timestamp, tcp: tcp, udp: udp }];
|
||||||
|
}
|
||||||
if (newData.length > 30) {
|
if (newData.length > 30) {
|
||||||
newData.shift();
|
newData.shift();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user