Skip to content

Commit

Permalink
fix(web): fix monitor mergeArrays (#1675)
Browse files Browse the repository at this point in the history
* fix(web): fix padding array with front and end

* delete console
  • Loading branch information
newfish-cmyk authored Nov 10, 2023
1 parent ab61bf2 commit 51ef7fe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions web/src/pages/app/setting/SysSetting/AppMonitor/AreaCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,28 @@ const strokeColorArray = [
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 newArrays = arrays.map((arr: any) => {
const padding = maxLength - arr.length;
const paddedArray = new Array(padding).fill({ xData: 0 }).concat(arr);
return paddedArray;
let frontPadding = 0;
let endPadding = 0;
for (let i = 0; i < longestArray.length; i++) {
if (longestArray[i].xData === arr[0].xData) {
frontPadding = i;
} else if (longestArray[i].xData === arr[arr.length - 1].xData) {
endPadding = longestArray.length - i - 1;
}
}
return [
...Array(frontPadding).fill({ xData: 0 }),
...arr,
...Array(endPadding).fill({ xData: 0 }),
];
});

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

0 comments on commit 51ef7fe

Please sign in to comment.