Skip to content

Commit

Permalink
fix: init chart
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Oct 19, 2024
1 parent 4695819 commit a8358e0
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions app/[locale]/(main)/ClientComponents/ServerDetailChartClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ function CpuChart({ data }: { data: NezhaAPISafe }) {
const timestamp = Date.now().toString();
let newData = [] as cpuChartData[];
if (cpuChartData.length === 0) {
newData = [{ timeStamp: timestamp, cpu: cpu }, { timeStamp: timestamp, cpu: cpu }];
newData = [
{ timeStamp: timestamp, cpu: cpu },
{ timeStamp: timestamp, cpu: cpu },
];
} else {
newData = [...cpuChartData, { timeStamp: timestamp, cpu: cpu }];
}
Expand Down Expand Up @@ -201,9 +204,15 @@ function ProcessChart({ data }: { data: NezhaAPISafe }) {
const timestamp = Date.now().toString();
let newData = [] as processChartData[];
if (processChartData.length === 0) {
newData = [{ timeStamp: timestamp, process: process }, { timeStamp: timestamp, process: process }];
newData = [
{ timeStamp: timestamp, process: process },
{ timeStamp: timestamp, process: process },
];
} else {
newData = [...processChartData, { timeStamp: timestamp, process: process }];
newData = [
...processChartData,
{ timeStamp: timestamp, process: process },
];
}
if (newData.length > 30) {
newData.shift();
Expand Down Expand Up @@ -285,9 +294,15 @@ function MemChart({ data }: { data: NezhaAPISafe }) {
const timestamp = Date.now().toString();
let newData = [] as memChartData[];
if (memChartData.length === 0) {
newData = [{ timeStamp: timestamp, mem: mem, swap: swap }, { 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 }];
newData = [
...memChartData,
{ timeStamp: timestamp, mem: mem, swap: swap },
];
}
if (newData.length > 30) {
newData.shift();
Expand Down Expand Up @@ -406,7 +421,10 @@ function DiskChart({ data }: { data: NezhaAPISafe }) {
const timestamp = Date.now().toString();
let newData = [] as diskChartData[];
if (diskChartData.length === 0) {
newData = [{ timeStamp: timestamp, disk: disk }, { timeStamp: timestamp, disk: disk }];
newData = [
{ timeStamp: timestamp, disk: disk },
{ timeStamp: timestamp, disk: disk },
];
} else {
newData = [...diskChartData, { timeStamp: timestamp, disk: disk }];
}
Expand Down Expand Up @@ -503,9 +521,15 @@ function NetworkChart({ data }: { data: NezhaAPISafe }) {
const timestamp = Date.now().toString();
let newData = [] as networkChartData[];
if (networkChartData.length === 0) {
newData = [{ timeStamp: timestamp, upload: up, download: down }, { 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 }];
newData = [
...networkChartData,
{ timeStamp: timestamp, upload: up, download: down },
];
}
if (newData.length > 30) {
newData.shift();
Expand Down Expand Up @@ -623,9 +647,15 @@ function ConnectChart({ data }: { data: NezhaAPISafe }) {
const timestamp = Date.now().toString();
let newData = [] as connectChartData[];
if (connectChartData.length === 0) {
newData = [{ timeStamp: timestamp, tcp: tcp, udp: udp }, { 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 }];
newData = [
...connectChartData,
{ timeStamp: timestamp, tcp: tcp, udp: udp },
];
}
if (newData.length > 30) {
newData.shift();
Expand Down

0 comments on commit a8358e0

Please sign in to comment.