diff --git a/packages/s2-core/src/facet/header/series-number.ts b/packages/s2-core/src/facet/header/series-number.ts index c0ca50c06a..86d097b9b6 100644 --- a/packages/s2-core/src/facet/header/series-number.ts +++ b/packages/s2-core/src/facet/header/series-number.ts @@ -37,18 +37,18 @@ export class SeriesNumberHeader extends BaseHeader { leafNodes.forEach((node: Node): void => { // 1、is spreadsheet and node is not total(grand or sub) // 2、is listSheet - if (!node.isTotals || isHierarchyTreeType) { - const sNode = new Node({ - id: '', - key: '', - value: `${seriesNodes.length + 1}`, - }); - sNode.x = node.x; - sNode.y = node.y; - sNode.height = node.height; - sNode.width = seriesNumberWidth; - seriesNodes.push(sNode); - } + const sNode = new Node({ + id: '', + key: '', + value: `${seriesNodes.length + 1}`, + }); + sNode.x = node.x; + sNode.y = node.y; + sNode.height = isHierarchyTreeType + ? node.getTotalHeightForTreeHierarchy() + : node.height; + sNode.width = seriesNumberWidth; + seriesNodes.push(sNode); }); return new SeriesNumberHeader({ width: cornerWidth, diff --git a/packages/s2-core/src/facet/layout/node.ts b/packages/s2-core/src/facet/layout/node.ts index e9e7ee0c0f..143f53394a 100644 --- a/packages/s2-core/src/facet/layout/node.ts +++ b/packages/s2-core/src/facet/layout/node.ts @@ -335,4 +335,17 @@ export class Node { } return leafChild; } + + /** + * 获取树状模式下,当前节点以及其所有子节点的高度总和 + * */ + public getTotalHeightForTreeHierarchy(): number { + if (this.height === 0 || isEmpty(this.children)) { + return this.height; + } + return this.children.reduce( + (sum, child) => sum + child.getTotalHeightForTreeHierarchy(), + this.height, + ); + } }