From a2e48566a5b43d221481e46cbed86258afb8dd6d Mon Sep 17 00:00:00 2001 From: wjgogogo <906626481@qq.com> Date: Mon, 11 Dec 2023 14:45:21 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=8D=95=E5=85=83=E6=A0=BC=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/facet/pivot-facet.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/s2-core/src/facet/pivot-facet.ts b/packages/s2-core/src/facet/pivot-facet.ts index 2957aa99f3..30a95fe158 100644 --- a/packages/s2-core/src/facet/pivot-facet.ts +++ b/packages/s2-core/src/facet/pivot-facet.ts @@ -351,10 +351,11 @@ export class PivotFacet extends FrozenFacet { */ private autoCalculateColNodeWidthAndX(colLeafNodes: Node[]) { let prevColParent: Node = null; + let i = 0; const leafNodes = colLeafNodes.slice(0); - while (leafNodes.length) { - const node = leafNodes.shift(); + while (i < leafNodes.length) { + const node = leafNodes[i++]; const parentNode = node.parent; if (prevColParent !== parentNode && parentNode) { leafNodes.push(parentNode); @@ -642,20 +643,21 @@ export class PivotFacet extends FrozenFacet { * @param rowLeafNodes */ private autoCalculateRowNodeHeightAndY(rowLeafNodes: Node[]) { - // 3、in grid type, all no-leaf node's height, y are auto calculated let prevRowParent = null; + let i = 0; const leafNodes = rowLeafNodes.slice(0); - while (leafNodes.length) { - const node = leafNodes.shift(); + while (i < leafNodes.length) { + const node = leafNodes[i++]; const parent = node.parent; if (prevRowParent !== parent && parent) { leafNodes.push(parent); // parent's y = first child's y parent.y = parent.children[0].y; // parent's height = all children's height - parent.height = parent.children - .map((value) => value.height) - .reduce((sum, current) => sum + current, 0); + parent.height = parent.children.reduce( + (sum, current) => sum + current.height, + 0, + ); prevRowParent = parent; } }