Skip to content

Commit

Permalink
fix(web): fix mergeArrays function (#1672)
Browse files Browse the repository at this point in the history
* fix mergeArrays function

* lint
  • Loading branch information
newfish-cmyk authored Nov 10, 2023
1 parent afbdd36 commit ab61bf2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions web/src/pages/app/setting/SysSetting/AppMonitor/AreaCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,24 @@ const strokeColorArray = [
];

function mergeArrays(arrays: any) {
let mergedArray = [];
let mergedArray: any = [];
const maxLength = Math.max(...arrays.map((arr: any) => arr.length));
for (let i = 0; i < maxLength; i++) {
const newArrays = arrays.map((arr: any) => {
const padding = maxLength - arr.length;
const paddedArray = new Array(padding).fill({ xData: 0 }).concat(arr);
return paddedArray;
});

for (let i = maxLength - 1; i >= 0; i--) {
let mergedElement = { xData: 0 };
for (let j = 0; j < arrays.length; j++) {
if (i < arrays[j].length) {
mergedElement.xData = arrays[j][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}`] = arrays[j][i][`value${j}`];
mergedElement[`value${j}`] = newArrays[j][i][`value${j}`];
}
}
mergedArray.push(mergedElement);
mergedArray = [mergedElement, ...mergedArray];
}

return mergedArray;
Expand Down

0 comments on commit ab61bf2

Please sign in to comment.