Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): fix app monitor longest array #1682

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions web/src/pages/app/setting/SysSetting/AppMonitor/AreaCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,39 @@ const strokeColorArray = [
"#FAAD14",
];

const generateChartData = () => {
const now = new Date();
now.setSeconds(0);
now.setMilliseconds(0);
const currentTimestamp = now.getTime();
let chartData = [];

for (let i = 0; i <= 60; i++) {
const timestamp = currentTimestamp - (60 - i) * 60 * 1000;
chartData.push({ xData: timestamp });
}

return chartData;
};

function mergeArrays(arrays: any) {
let mergedArray: any = [];
const maxLength = Math.max(...arrays.map((arr: any) => arr.length));
const longestArray = arrays.find((arr: any) => arr.length === maxLength);
const longestArray = generateChartData();
const newArrays = arrays.map((arr: any) => {
let frontPadding = 0;
let endPadding = 0;
for (let i = 0; i < longestArray.length; i++) {
if (longestArray[i].xData === arr[0].xData) {
const lastTime = new Date(arr[arr.length - 1].xData);
lastTime.setSeconds(0);
lastTime.setMilliseconds(0);
const firstTime = new Date(arr[0].xData);
firstTime.setSeconds(0);
firstTime.setMilliseconds(0);

if (longestArray[i].xData === firstTime.getTime()) {
frontPadding = i;
} else if (longestArray[i].xData === arr[arr.length - 1].xData) {
}
if (longestArray[i].xData === lastTime.getTime()) {
endPadding = longestArray.length - i - 1;
}
}
Expand All @@ -61,14 +83,12 @@ function mergeArrays(arrays: any) {
];
});

for (let i = maxLength - 1; i >= 0; i--) {
for (let i = 60; i >= 0; i--) {
let mergedElement = { xData: 0 };
mergedElement.xData = longestArray[i].xData;
for (let j = 0; j < newArrays.length; j++) {
if (newArrays[j][i]?.xData > 0) {
mergedElement.xData = newArrays[j][i].xData;
// @ts-ignore
mergedElement[`value${j}`] = newArrays[j][i][`value${j}`];
}
// @ts-ignore
mergedElement[`value${j}`] = newArrays[j][i][`value${j}`];
}
mergedArray = [mergedElement, ...mergedArray];
}
Expand Down