diff --git a/packages/s2-core/__tests__/bugs/issue-1624-spec.ts b/packages/s2-core/__tests__/bugs/issue-1624-spec.ts index 2589ed7966..42ce501af1 100644 --- a/packages/s2-core/__tests__/bugs/issue-1624-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-1624-spec.ts @@ -37,9 +37,11 @@ describe('Data Cell Border Tests', () => { await sleep(40); - // @ts-ignore const meta = dataCell.getCellArea(); - const borderBbox = dataCell.getChildByIndex(2).getBBox(); + // @ts-ignore + const borderBbox = dataCell.stateShapes + .get('interactiveBorderShape') + .getBBox(); expect(meta.x).toEqual(borderBbox.x - borderWidth / 2); expect(meta.y).toEqual(borderBbox.y - borderWidth / 2); diff --git a/packages/s2-core/__tests__/unit/cell/header-cell-spec.ts b/packages/s2-core/__tests__/unit/cell/header-cell-spec.ts index 79c7f4ec74..14b9f566ee 100644 --- a/packages/s2-core/__tests__/unit/cell/header-cell-spec.ts +++ b/packages/s2-core/__tests__/unit/cell/header-cell-spec.ts @@ -83,6 +83,41 @@ describe('header cell formatter test', () => { expect(rowCell.getFieldValue()).toBe('小计'); }); + test('should not format pivot row grand total cell in tree mode', () => { + const rowGrandTotalNode = new Node({ + id: `root[&]总计`, + key: '', + value: '总计', + parent: root, + label: '总计', + isTotals: true, + isGrandTotals: true, + }); + + const rowSubTotalNode = new Node({ + id: `root[&]杭州`, + key: '', + value: '杭州', + parent: root, + label: '杭州', + isTotals: true, + isSubTotals: true, + isGrandTotals: false, + }); + + const formatter: Formatter = (value) => { + return `${value}1`; + }; + jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter); + jest.spyOn(s2, 'isHierarchyTreeType').mockReturnValue(true); + + const grandTotalCell = new ColCell(rowGrandTotalNode, s2); + const subTotalCell = new RowCell(rowSubTotalNode, s2); + + expect(grandTotalCell.getFieldValue()).toBe('总计'); + expect(subTotalCell.getFieldValue()).toBe('杭州1'); + }); + test('pivot corner cell not formatter', () => { const formatter: Formatter = (value) => { return `${value}1`; diff --git a/packages/s2-core/src/cell/data-cell.ts b/packages/s2-core/src/cell/data-cell.ts index 7457533eff..5e102d7cbd 100644 --- a/packages/s2-core/src/cell/data-cell.ts +++ b/packages/s2-core/src/cell/data-cell.ts @@ -192,12 +192,12 @@ export class DataCell extends BaseCell { this.resetTextAndConditionIconShapes(); this.drawBackgroundShape(); this.drawInteractiveBgShape(); - this.drawInteractiveBorderShape(); if (!this.shouldHideRowSubtotalData()) { this.drawConditionIntervalShape(); this.drawTextShape(); this.drawConditionIconShapes(); } + this.drawInteractiveBorderShape(); if (this.meta.isFrozenCorner) { this.drawBorderShape(); } diff --git a/packages/s2-core/src/cell/header-cell.ts b/packages/s2-core/src/cell/header-cell.ts index 24fd214b00..9fa1d8129a 100644 --- a/packages/s2-core/src/cell/header-cell.ts +++ b/packages/s2-core/src/cell/header-cell.ts @@ -85,17 +85,27 @@ export abstract class HeaderCell extends BaseCell { } protected getFormattedFieldValue(): FormatResult { - const { label, isTotals } = this.meta; + const { label, isTotals, isGrandTotals } = this.meta; const formatter = this.spreadsheet.dataSet.getFieldFormatter( this.meta.field, ); - // 如果是 总计/小计 文字单元格,不需要被格式化 // 如果是 table mode,列头不需要被格式化 - const isTableMode = this.spreadsheet.isTableMode(); + // 树状模式下,小计是父维度本身,需要被格式化,此时只有总计才不需要被格式化 + // 平铺模式下,总计/小计 文字单元格,不需要被格式化 + // 自定义树模式下,没有总计小计概念,isTotals 均为 false, 所以不受影响 + let shouldFormat = true; + if (this.spreadsheet.isTableMode()) { + shouldFormat = false; + } else if (this.spreadsheet.isHierarchyTreeType()) { + shouldFormat = !isGrandTotals; + } else { + shouldFormat = !isTotals; + } + const formattedValue = - formatter && !isTableMode && !isTotals + shouldFormat && formatter ? formatter(label, undefined, this.meta) : label;