diff --git a/packages/s2-core/__tests__/spreadsheet/__snapshots__/corner-spec.ts.snap b/packages/s2-core/__tests__/spreadsheet/__snapshots__/corner-spec.ts.snap index 2bf7afd75d..e906a49ea1 100644 --- a/packages/s2-core/__tests__/spreadsheet/__snapshots__/corner-spec.ts.snap +++ b/packages/s2-core/__tests__/spreadsheet/__snapshots__/corner-spec.ts.snap @@ -10,6 +10,7 @@ Array [ "extra": undefined, "field": "province", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -19,15 +20,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "province", - "label": "province", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "province", - "width": 100, + "width": 99, "x": 0, "y": 0, }, @@ -39,6 +40,7 @@ Array [ "extra": undefined, "field": "city", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -48,16 +50,16 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "city", - "label": "city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "city", - "width": 100, - "x": 100, + "width": 99, + "x": 99, "y": 0, }, ] @@ -71,8 +73,9 @@ Array [ "colIndex": -1, "cornerType": "series", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -82,13 +85,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "series-number-node", - "label": "序号", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "序号", "width": 80, "x": 0, @@ -102,6 +105,7 @@ Array [ "extra": undefined, "field": "province", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -111,13 +115,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "province", - "label": "province", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "province", "width": 96, "x": 80, @@ -131,6 +135,7 @@ Array [ "extra": undefined, "field": "city", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -140,13 +145,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "city", - "label": "city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "city", "width": 96, "x": 176, @@ -163,8 +168,9 @@ Array [ "colIndex": -1, "cornerType": "row", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -174,15 +180,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "", - "label": "province/city/数值", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": 0, + "spreadsheet": Anything, "value": "province/city/数值", - "width": 150, + "width": 145, "x": 0, "y": 0, }, @@ -197,8 +203,9 @@ Array [ "colIndex": -1, "cornerType": "series", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -208,13 +215,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "series-number-node", - "label": "序号", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "序号", "width": 80, "x": 0, @@ -226,8 +233,9 @@ Array [ "colIndex": -1, "cornerType": "row", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -237,15 +245,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "", - "label": "province/city/数值", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": 80, + "spreadsheet": Anything, "value": "province/city/数值", - "width": 150, + "width": 145, "x": 80, "y": 0, }, @@ -262,6 +270,7 @@ Array [ "extra": undefined, "field": "province", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -271,15 +280,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "province", - "label": "province", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "province", - "width": 150, + "width": 149, "x": 0, "y": 0, }, @@ -291,6 +300,7 @@ Array [ "extra": undefined, "field": "city", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -300,16 +310,16 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "city", - "label": "city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "city", - "width": 150, - "x": 150, + "width": 149, + "x": 149, "y": 0, }, ] @@ -323,8 +333,9 @@ Array [ "colIndex": -1, "cornerType": "series", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -334,13 +345,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "series-number-node", - "label": "序号", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "序号", "width": 80, "x": 0, @@ -354,6 +365,7 @@ Array [ "extra": undefined, "field": "province", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -363,15 +375,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "province", - "label": "province", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "province", - "width": 110, + "width": 109, "x": 80, "y": 0, }, @@ -383,6 +395,7 @@ Array [ "extra": undefined, "field": "city", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -392,16 +405,16 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "city", - "label": "city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "city", - "width": 110, - "x": 190, + "width": 109, + "x": 189, "y": 0, }, ] @@ -415,8 +428,9 @@ Array [ "colIndex": -1, "cornerType": "row", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -426,15 +440,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "", - "label": "province/city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": 0, + "spreadsheet": Anything, "value": "province/city", - "width": 122, + "width": 120, "x": 0, "y": 0, }, @@ -449,8 +463,9 @@ Array [ "colIndex": -1, "cornerType": "series", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -460,13 +475,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "series-number-node", - "label": "序号", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "序号", "width": 80, "x": 0, @@ -478,8 +493,9 @@ Array [ "colIndex": -1, "cornerType": "row", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -489,15 +505,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "", - "label": "province/city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": 80, + "spreadsheet": Anything, "value": "province/city", - "width": 122, + "width": 120, "x": 80, "y": 0, }, @@ -514,6 +530,7 @@ Array [ "extra": undefined, "field": "province", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -523,15 +540,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "province", - "label": "province", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "province", - "width": 100, + "width": 99, "x": 0, "y": 0, }, @@ -543,6 +560,7 @@ Array [ "extra": undefined, "field": "city", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -552,16 +570,16 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "city", - "label": "city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "city", - "width": 100, - "x": 100, + "width": 99, + "x": 99, "y": 0, }, ] @@ -575,8 +593,9 @@ Array [ "colIndex": -1, "cornerType": "series", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -586,13 +605,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "series-number-node", - "label": "序号", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "序号", "width": 80, "x": 0, @@ -606,6 +625,7 @@ Array [ "extra": undefined, "field": "province", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -615,13 +635,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "province", - "label": "province", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "province", "width": 96, "x": 80, @@ -635,6 +655,7 @@ Array [ "extra": undefined, "field": "city", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -644,13 +665,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "city", - "label": "city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "city", "width": 96, "x": 176, @@ -667,8 +688,9 @@ Array [ "colIndex": -1, "cornerType": "row", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -678,15 +700,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "", - "label": "province/city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": 0, + "spreadsheet": Anything, "value": "province/city", - "width": 122, + "width": 120, "x": 0, "y": 0, }, @@ -701,8 +723,9 @@ Array [ "colIndex": -1, "cornerType": "series", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -712,13 +735,13 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "series-number-node", - "label": "序号", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": undefined, + "spreadsheet": Anything, "value": "序号", "width": 80, "x": 0, @@ -730,8 +753,9 @@ Array [ "colIndex": -1, "cornerType": "row", "extra": undefined, - "field": undefined, + "field": "", "height": 30, + "hierarchy": undefined, "id": "", "inCollapseNode": undefined, "isCollapsed": undefined, @@ -741,15 +765,15 @@ Array [ "isSubTotals": undefined, "isTotalMeasure": undefined, "isTotals": undefined, - "key": "", - "label": "province/city", "level": undefined, "padding": 0, + "parent": undefined, "query": undefined, "rowIndex": undefined, "seriesNumberWidth": 80, + "spreadsheet": Anything, "value": "province/city", - "width": 122, + "width": 120, "x": 80, "y": 0, }, diff --git a/packages/s2-core/__tests__/spreadsheet/corner-spec.ts b/packages/s2-core/__tests__/spreadsheet/corner-spec.ts index 03a55ce4bd..4327bf734a 100644 --- a/packages/s2-core/__tests__/spreadsheet/corner-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/corner-spec.ts @@ -60,7 +60,15 @@ describe('PivotSheet Corner Tests', () => { DEFAULT_STYLE.colCell!.height, ); expect(cornerNodes).toHaveLength(cornerNodeCount); - expect(s2.facet.getCornerNodes()).toMatchSnapshot(); + expect(s2.facet.getCornerNodes()).toMatchSnapshot( + Array.from({ + length: cornerNodeCount, + }).map(() => { + return { + spreadsheet: expect.anything(), + }; + }), + ); }, ); @@ -82,7 +90,7 @@ describe('PivotSheet Corner Tests', () => { const { colsHierarchy } = s2.facet.layoutResult; expect(colsHierarchy.width).not.toBeLessThan( - DEFAULT_STYLE.colCell!.width as number, + DEFAULT_STYLE.dataCell!.width as number, ); expect(colsHierarchy.height).toEqual(DEFAULT_STYLE.colCell!.height); expect(colsHierarchy.sampleNodeForLastLevel!.y).toEqual(0); @@ -90,7 +98,15 @@ describe('PivotSheet Corner Tests', () => { DEFAULT_STYLE.colCell!.height, ); expect(cornerNodes).toHaveLength(cornerNodeCount); - expect(s2.facet.getCornerNodes()).toMatchSnapshot(); + expect(s2.facet.getCornerNodes()).toMatchSnapshot( + Array.from({ + length: cornerNodeCount, + }).map(() => { + return { + spreadsheet: expect.anything(), + }; + }), + ); }, ); @@ -117,8 +133,16 @@ describe('PivotSheet Corner Tests', () => { expect(colsHierarchy.width).toEqual(0); expect(colsHierarchy.height).toEqual(0); expect(colsHierarchy.sampleNodeForLastLevel).toBeNull(); - expect(cornerNodes).toHaveLength(cornerNodeCount); - expect(cornerNodes).toMatchSnapshot(); + expect(cornerNodes.length).toEqual(cornerNodeCount); + expect(cornerNodes).toMatchSnapshot( + Array.from({ + length: cornerNodeCount, + }).map(() => { + return { + spreadsheet: expect.anything(), + }; + }), + ); }, ); diff --git a/packages/s2-core/src/facet/header/corner.ts b/packages/s2-core/src/facet/header/corner.ts index 1971f7afc9..6cfa61dc90 100644 --- a/packages/s2-core/src/facet/header/corner.ts +++ b/packages/s2-core/src/facet/header/corner.ts @@ -114,9 +114,8 @@ export class CornerHeader extends BaseHeader { /* * check if show series number node - * spreadsheet must have at least one node in last level */ - if (seriesNumberWidth && leafNode) { + if (seriesNumberWidth) { const sNode: Node = new Node({ id: '', field: '', @@ -125,10 +124,10 @@ export class CornerHeader extends BaseHeader { sNode.x = position?.x; // different type different y - sNode.y = leafNode?.y; + sNode.y = leafNode?.y ?? 0; sNode.width = seriesNumberWidth; // different type different height - sNode.height = leafNode?.height; + sNode.height = leafNode?.height! ?? (colCell?.height as number); sNode.isPivotMode = true; sNode.spreadsheet = spreadsheet; sNode.cornerType = CornerNodeType.Series;