Skip to content

Commit

Permalink
fix: 构造含总计的 tree 行头布局时报错 (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcx-seima authored Jun 21, 2022
1 parent f668513 commit faff65c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ const s2Options: S2Options = {
width: 400,
height: 400,
hierarchyType: 'tree',
// 测试总计行节点分支
totals: {
row: {
showGrandTotals: true,
},
},
};

describe('build row tree hierarchy', () => {
// https://stackblitz.com/edit/react-ts-aj2r8w?file=data.ts
test('should get order hierarchy when order is group ascend', () => {
Expand All @@ -30,13 +37,14 @@ describe('build row tree hierarchy', () => {
const s2 = new PivotSheet(getContainer(), s2DataConfig, s2Options);
s2.render();
const rowLeafNodes = s2.facet.layoutResult.rowLeafNodes;
expect(rowLeafNodes.length).toBe(6);
expect(rowLeafNodes.length).toBe(7);
expect(rowLeafNodes[0].label).toEqual('浙江');
expect(rowLeafNodes[1].label).toEqual('杭州');
expect(rowLeafNodes[2].label).toEqual('舟山');
expect(rowLeafNodes[3].label).toEqual('吉林');
expect(rowLeafNodes[4].label).toEqual('丹东');
expect(rowLeafNodes[5].label).toEqual('白山');
expect(rowLeafNodes[6].label).toEqual('总计');
});
test('should get order hierarchy when order is group desc', () => {
const s2DataConfig: S2DataConfig = {
Expand All @@ -57,12 +65,13 @@ describe('build row tree hierarchy', () => {
const s2 = new PivotSheet(getContainer(), s2DataConfig, s2Options);
s2.render();
const rowLeafNodes = s2.facet.layoutResult.rowLeafNodes;
expect(rowLeafNodes.length).toBe(6);
expect(rowLeafNodes.length).toBe(7);
expect(rowLeafNodes[0].label).toEqual('浙江');
expect(rowLeafNodes[1].label).toEqual('舟山');
expect(rowLeafNodes[2].label).toEqual('杭州');
expect(rowLeafNodes[3].label).toEqual('吉林');
expect(rowLeafNodes[4].label).toEqual('丹东');
expect(rowLeafNodes[5].label).toEqual('白山');
expect(rowLeafNodes[6].label).toEqual('总计');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const buildRowTreeHierarchy = (params: TreeHeaderParams) => {
hierarchy.maxLevel = level;
}

const emptyChildren = !pivotMetaValue.children?.size;
const emptyChildren = !pivotMetaValue?.children?.size;
if (emptyChildren || isTotals) {
node.isLeaf = true;
}
Expand Down

0 comments on commit faff65c

Please sign in to comment.