From 3af7230f7bc696d2c682c9304d941338ec849790 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Wed, 3 Aug 2022 18:21:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(layout):=20=E4=BF=AE=E5=A4=8D=20treeRowsWid?= =?UTF-8?q?th=20=E9=85=8D=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88=20close=20#1?= =?UTF-8?q?622?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/unit/facet/pivot-facet-spec.ts | 26 +++++++++++++++++++ .../interaction/row-column-resize-spec.ts | 1 + .../s2-core/src/common/constant/options.ts | 3 ++- .../s2-core/src/common/interface/basic.ts | 6 +++-- packages/s2-core/src/facet/pivot-facet.ts | 13 +++++++--- .../src/interaction/row-column-resize.ts | 4 +++ packages/s2-react/playground/config.ts | 5 ++++ s2-site/docs/common/style.zh.md | 4 +-- 8 files changed, 54 insertions(+), 8 deletions(-) diff --git a/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts b/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts index d55757e813..a4085b6163 100644 --- a/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts +++ b/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts @@ -314,4 +314,30 @@ describe('Pivot Mode Facet Test', () => { } }, ); + + // https://github.com/antvis/S2/issues/1622 + test('should render custom column leaf node width and use treeRowsWidth first for tree mode', () => { + const mockDataSet = new MockPivotDataSet(s2); + const customWidthFacet = new PivotFacet({ + spreadsheet: s2, + dataSet: mockDataSet, + ...assembleDataCfg().fields, + ...assembleOptions(), + hierarchyType: 'tree', + cellCfg: {}, + colCfg: {}, + rowCfg: { + // 行头宽度 + width: 200, + // 已废弃 + treeRowsWidth: 300, + }, + // 树状结构下行头宽度 (优先级最高) + treeRowsWidth: 400, + }); + + customWidthFacet.layoutResult.rowNodes.forEach((node) => { + expect(node.width).toStrictEqual(400); + }); + }); }); diff --git a/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts b/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts index bc14438738..700a523d49 100644 --- a/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts @@ -414,6 +414,7 @@ describe('Interaction Row Column Resize Tests', () => { ResizeAreaEffect.Tree, ); + expect(s2.options.style.treeRowsWidth).toEqual(resizeInfo.width); expect(s2.options.style.rowCfg.treeRowsWidth).toEqual(resizeInfo.width); }); diff --git a/packages/s2-core/src/common/constant/options.ts b/packages/s2-core/src/common/constant/options.ts index 8eb533bf34..9b8097534d 100644 --- a/packages/s2-core/src/common/constant/options.ts +++ b/packages/s2-core/src/common/constant/options.ts @@ -15,10 +15,11 @@ export enum LayoutWidthTypes { Compact = 'compact', } +export const DEFAULT_TREE_ROW_WIDTH = 120; + export const DEFAULT_STYLE: Readonly