From 91ad4fd5625f150c35f40ef2c8eb5723df4f7373 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Fri, 13 Oct 2023 17:25:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=97=E5=A4=B4=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E5=A4=9A=E5=88=97=E6=96=87=E6=9C=AC=E6=97=B6=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8=E4=BA=86=E6=95=B0=E5=80=BC=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=A0=BC=E7=9A=84=E6=A0=B7=E5=BC=8F=20close=20#2359?= =?UTF-8?q?=20(#2364)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s2-core/__tests__/bugs/issue-2359-spec.ts | 140 ++++++++++++++++++ packages/s2-core/src/utils/text.ts | 4 +- 2 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 packages/s2-core/__tests__/bugs/issue-2359-spec.ts diff --git a/packages/s2-core/__tests__/bugs/issue-2359-spec.ts b/packages/s2-core/__tests__/bugs/issue-2359-spec.ts new file mode 100644 index 0000000000..04079ebc2a --- /dev/null +++ b/packages/s2-core/__tests__/bugs/issue-2359-spec.ts @@ -0,0 +1,140 @@ +/** + * @description spec for issue #2359 + * https://github.com/antvis/S2/issues/2359 + * 明细表: 自定义列头误用 dataCell 样式 + */ +import { pick } from 'lodash'; +import { createTableSheet } from 'tests/util/helpers'; +import { TableColCell, drawObjectText } from '../../src'; +import type { S2CellType, S2Options } from '@/common/interface'; + +class TestColCell extends TableColCell { + drawTextShape() { + drawObjectText(this, { + values: [['A', 'B', 'C']], + }); + } +} + +const s2Options: S2Options = { + width: 300, + height: 480, + showSeriesNumber: true, + colCell: (...args) => new TestColCell(...args), +}; + +describe('Table Sheet Custom Multiple Values Tests', () => { + test('should use current cell text theme', () => { + const s2 = createTableSheet(s2Options); + + s2.setTheme({ + colCell: { + measureText: { + fontSize: 12, + }, + bolderText: { + fontSize: 14, + }, + text: { + fontSize: 20, + fill: 'red', + }, + }, + dataCell: { + text: { + fontSize: 30, + fill: 'green', + }, + }, + }); + s2.render(); + + const mapTheme = (cell: S2CellType) => { + return cell + .getTextShapes() + .map((shape) => pick(shape.attr(), ['fill', 'fontSize'])); + }; + + const colCellTexts = s2 + .getColumnNodes() + .map((node) => mapTheme(node.belongsCell)); + + const dataCellTexts = s2.interaction + .getPanelGroupAllDataCells() + .map(mapTheme); + + expect(colCellTexts).toMatchInlineSnapshot(` + Array [ + Array [ + Object { + "fill": "red", + "fontSize": 20, + }, + Object { + "fill": "red", + "fontSize": 20, + }, + Object { + "fill": "red", + "fontSize": 20, + }, + ], + Array [ + Object { + "fill": "red", + "fontSize": 20, + }, + Object { + "fill": "red", + "fontSize": 20, + }, + Object { + "fill": "red", + "fontSize": 20, + }, + ], + ] + `); + + expect(dataCellTexts).toMatchInlineSnapshot(` + Array [ + Array [ + Object { + "fill": "#000000", + "fontSize": 12, + }, + ], + Array [ + Object { + "fill": "#000000", + "fontSize": 12, + }, + ], + Array [ + Object { + "fill": "#000000", + "fontSize": 12, + }, + ], + Array [ + Object { + "fill": "green", + "fontSize": 30, + }, + ], + Array [ + Object { + "fill": "green", + "fontSize": 30, + }, + ], + Array [ + Object { + "fill": "green", + "fontSize": 30, + }, + ], + ] + `); + }); +}); diff --git a/packages/s2-core/src/utils/text.ts b/packages/s2-core/src/utils/text.ts index e0074ca635..833940b721 100644 --- a/packages/s2-core/src/utils/text.ts +++ b/packages/s2-core/src/utils/text.ts @@ -357,9 +357,7 @@ const calX = ( const getDrawStyle = (cell: S2CellType) => { const { isTotals } = cell.getMeta(); const isMeasureField = (cell as ColCell).isMeasureField?.(); - const cellStyle = cell.getStyle( - isMeasureField ? CellTypes.COL_CELL : CellTypes.DATA_CELL, - ); + const cellStyle = cell.getStyle(cell.cellType || CellTypes.DATA_CELL); let textStyle: TextTheme; if (isMeasureField) {