From 406d17e4481f7a252f094da54997e16b833c24c8 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Fri, 22 Sep 2023 19:46:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20=F0=9F=A4=96=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20changelog=20=E6=96=87=E4=BB=B6=20(#2356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/CHANGELOG.md | 8 ++++++++ packages/s2-core/package.json | 2 +- packages/s2-react/CHANGELOG.md | 8 ++++++++ packages/s2-react/package.json | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/s2-core/CHANGELOG.md b/packages/s2-core/CHANGELOG.md index b7c074f82d..c1c342e399 100644 --- a/packages/s2-core/CHANGELOG.md +++ b/packages/s2-core/CHANGELOG.md @@ -1,3 +1,11 @@ +# [@antv/s2-v1.51.0](https://github.com/antvis/S2/compare/@antv/s2-v1.50.0...@antv/s2-v1.51.0) (2023-09-22) + + +### Features + +* 对比值无波动时也显示灰色 ([#2351](https://github.com/antvis/S2/issues/2351)) ([12f2d02](https://github.com/antvis/S2/commit/12f2d0268d447ec99a1227ffedd5ed266d93e86b)) +* 小计/总计功能,支持按维度分组汇总 ([#2346](https://github.com/antvis/S2/issues/2346)) ([20e608f](https://github.com/antvis/S2/commit/20e608f2447e9ffdb135d98e4cc7f39f1cfb308d)) + # [@antv/s2-v1.50.0](https://github.com/antvis/S2/compare/@antv/s2-v1.49.2...@antv/s2-v1.50.0) (2023-09-09) diff --git a/packages/s2-core/package.json b/packages/s2-core/package.json index 6337125605..d818a75808 100644 --- a/packages/s2-core/package.json +++ b/packages/s2-core/package.json @@ -1,7 +1,7 @@ { "private": false, "name": "@antv/s2", - "version": "1.50.0", + "version": "1.51.0", "main": "lib/index.js", "unpkg": "dist/index.min.js", "module": "esm/index.js", diff --git a/packages/s2-react/CHANGELOG.md b/packages/s2-react/CHANGELOG.md index 7c49b535a6..b0a6bd9ed3 100644 --- a/packages/s2-react/CHANGELOG.md +++ b/packages/s2-react/CHANGELOG.md @@ -1,3 +1,11 @@ +# [@antv/s2-react-v1.44.0](https://github.com/antvis/S2/compare/@antv/s2-react-v1.43.0...@antv/s2-react-v1.44.0) (2023-09-22) + + +### Features + +* 对比值无波动时也显示灰色 ([#2351](https://github.com/antvis/S2/issues/2351)) ([12f2d02](https://github.com/antvis/S2/commit/12f2d0268d447ec99a1227ffedd5ed266d93e86b)) +* 小计/总计功能,支持按维度分组汇总 ([#2346](https://github.com/antvis/S2/issues/2346)) ([20e608f](https://github.com/antvis/S2/commit/20e608f2447e9ffdb135d98e4cc7f39f1cfb308d)) + # [@antv/s2-react-v1.43.0](https://github.com/antvis/S2/compare/@antv/s2-react-v1.42.1...@antv/s2-react-v1.43.0) (2023-09-09) diff --git a/packages/s2-react/package.json b/packages/s2-react/package.json index 2337ce8698..202ab32399 100644 --- a/packages/s2-react/package.json +++ b/packages/s2-react/package.json @@ -1,7 +1,7 @@ { "private": false, "name": "@antv/s2-react", - "version": "1.43.0", + "version": "1.44.0", "main": "lib/index.js", "unpkg": "dist/index.min.js", "module": "esm/index.js", From c8d2c94c21527ae52ece3485524d374d09b1cba7 Mon Sep 17 00:00:00 2001 From: NoobNot <56724970+NoobNotN@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:15:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix(layout):=20=E4=BF=AE=E5=A4=8D=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E7=BB=93=E7=82=B9=E6=97=B6=E5=AF=B9=E7=88=B6=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E5=B8=83=E5=B1=80=E8=AE=A1=E7=AE=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20close=20#2355=20(#2360)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(layout): 修复隐藏结点时对父节点的布局计算错误 close #2355 * chore: 增加废弃标记 --------- Co-authored-by: JuZe --- .../spreadsheet/hidden-columns-spec.ts | 28 +++++++++++++++++++ packages/s2-core/src/facet/layout/node.ts | 3 ++ packages/s2-core/src/facet/pivot-facet.ts | 4 +-- .../src/utils/layout/generate-header-nodes.ts | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index b6c4a11dbd..7aecda2f1d 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -347,6 +347,34 @@ describe('SpreadSheet Hidden Columns Tests', () => { expect(hiddenColumnsInfo).toBeTruthy(); expect(parentNode.hiddenChildNodeInfo).toEqual(hiddenColumnsInfo); }); + // https://github.com/antvis/S2/issues/2355 + test('should render correctly x and width after hide columns when there is only one value for the higher-level dimension.', () => { + const nodeId = 'root[&]笔[&]义乌[&]price'; + + pivotSheet.setOptions({ + style: { + colCfg: { + width: 100, + }, + }, + }); + const data = pivotSheet.dataCfg.data.map((i) => ({ ...i, cost: 0 })); + pivotSheet.setDataCfg({ + data, + fields: { + values: ['cost', 'price'], + }, + }); + pivotSheet.render(); + + pivotSheet.interaction.hideColumns([nodeId]); + const rootNode = pivotSheet + .getColumnNodes() + .find((node) => node.id === 'root[&]笔'); + + expect(rootNode.width).toEqual(300); + expect(rootNode.x).toEqual(0); + }); // https://github.com/antvis/S2/issues/2194 test('should render correctly when always hidden last column', () => { diff --git a/packages/s2-core/src/facet/layout/node.ts b/packages/s2-core/src/facet/layout/node.ts index cfc09d5466..e9e7ee0c0f 100644 --- a/packages/s2-core/src/facet/layout/node.ts +++ b/packages/s2-core/src/facet/layout/node.ts @@ -306,6 +306,9 @@ export class Node { public isTotalRoot?: boolean; + /** + * @deprecated 已废弃, 该属性只记录相邻一级的隐藏信息,将会在未来版本中移除 + */ public hiddenChildNodeInfo?: HiddenColumnsInfo | null; public extra?: Record; diff --git a/packages/s2-core/src/facet/pivot-facet.ts b/packages/s2-core/src/facet/pivot-facet.ts index 3b432f44b5..c5da151310 100644 --- a/packages/s2-core/src/facet/pivot-facet.ts +++ b/packages/s2-core/src/facet/pivot-facet.ts @@ -252,9 +252,9 @@ export class PivotFacet extends BaseFacet { leafNodes.push(parentNode); const firstVisibleChildNode = parentNode.children?.find( - (childNode) => !childNode.hiddenChildNodeInfo, + (childNode) => childNode.width, ); - // 父节点 x 坐标 = 第一个未隐藏的子节点的 x 坐标 + // 父节点 x 坐标 = 第一个正常布局处理过的子节点 x 坐标(width 有值认为是正常布局过) const parentNodeX = firstVisibleChildNode?.x; // 父节点宽度 = 所有子节点宽度之和 const parentNodeWidth = sumBy(parentNode.children, 'width'); diff --git a/packages/s2-core/src/utils/layout/generate-header-nodes.ts b/packages/s2-core/src/utils/layout/generate-header-nodes.ts index 402eb59120..aa33a7bf42 100644 --- a/packages/s2-core/src/utils/layout/generate-header-nodes.ts +++ b/packages/s2-core/src/utils/layout/generate-header-nodes.ts @@ -113,6 +113,7 @@ export const generateHeaderNodes = (params: HeaderNodesParams) => { // 如果当前是隐藏节点, 给其父节点挂载相应信息 (兄弟节点, 当前哪个子节点隐藏了), 这样在 facet 层可以直接使用, 不用每次都去遍历 const hiddenColumnsInfo = spreadsheet?.facet?.getHiddenColumnsInfo(node); if (hiddenColumnsInfo && parentNode) { + // hiddenChildNodeInfo 属性在 S2 中没有用到,但是没删怕外部有使用,已标记为废弃 parentNode.hiddenChildNodeInfo = hiddenColumnsInfo; } From b719c8adbb2cbba8635686aa6d77ff0e52e15b56 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Wed, 11 Oct 2023 17:44:37 +0800 Subject: [PATCH 3/5] =?UTF-8?q?docs:=20=E4=BF=AE=E5=A4=8D=20headerActionIc?= =?UTF-8?q?ons=20=E9=94=99=E8=AF=AF=E6=96=87=E6=A1=A3=20close=20#2362=20(#?= =?UTF-8?q?2363)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- s2-site/docs/common/header-action-icon.zh.md | 18 +++++++++--------- s2-site/docs/common/icon.zh.md | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/s2-site/docs/common/header-action-icon.zh.md b/s2-site/docs/common/header-action-icon.zh.md index bac525cb2b..e192e145e8 100644 --- a/s2-site/docs/common/header-action-icon.zh.md +++ b/s2-site/docs/common/header-action-icon.zh.md @@ -7,12 +7,12 @@ | 参数 | 说明 | 类型 | 默认值 | 必选 | 取值 | 版本 | | ---------------- | ----------- | ----------- | ------ | ---- | ----------- | --- | | iconNames | 已经注册的 icon 名称,或用户通过 customSVGIcons 注册的 icon 名称 | `string[]` | | ✓ | | | -| belongsCell | 需要增加操作图标的单元格名称 | `string[]` | | ✓ | 角头:'cornerCell';
列头:'colCell';
行头:'rowCell' | | -| defaultHide | 控制是否 hover 才展示 icon | `boolean | (meta: Node, iconName: string) => boolean` | false | | true | `1.26.0` 支持配置为一个函数 | -| displayCondition | 展示的过滤条件,可以通过该回调函数用户自定义行列头哪些层级或单元格需要展示 icon。 所有返回值为 true 的 icon 会展示给用户。 | `(mete: Node, iconName: string) => boolean;` | | | | `1.26.0` 回传 `iconName` 并按单个 icon 控制显隐 | -| action | icon 点击之后的执行函数 | `(headerActionIconProps: HeaderActionIconProps) => void;` | | | | 已废弃,请使用 `onClick` | -| onClick | icon 点击之后的执行函数 | `(headerIconClickParams: HeaderIconClickParams) => void;` | | | | `1.26.0` | -| onHover | icon hover 开始及结束之后的执行函数 | `(headerIconHoverParams: HeaderIconHoverParams) => void;` | | | | `1.26.0` | +| belongsCell | 需要增加操作图标的单元格名称 | `string` | | ✓ | 角头:`cornerCell`;
列头:`colCell`;
行头:`rowCell` | | +| defaultHide | 控制是否 hover 在对应单元格时才展示 icon, 默认始终展示 | `boolean \| (meta: Node, iconName: string) => boolean` | false | | | `1.26.0` 支持配置为一个函数 | +| displayCondition | 自定义展示条件,可根据当前单元格信息动态控制 icon 是否展示 | `(mete: Node, iconName: string) => boolean` | | | | `1.26.0` 回传 `iconName` 并按单个 icon 控制显隐 | +| action | icon 点击之后的执行函数 (已废弃,请使用 `onClick`) | `(headerActionIconProps: HeaderActionIconProps) => void` | | | | | +| onClick | icon 点击之后的执行函数 | `(headerIconClickParams: HeaderIconClickParams) => void` | | | | `1.26.0` | +| onHover | icon hover 开始及结束之后的执行函数 | `(headerIconHoverParams: HeaderIconHoverParams) => void` | | | | `1.26.0` | ​ @@ -24,9 +24,9 @@ | 参数 | 功能描述 | 类型 | 默认值 | 必选 | | --- | --- | --- | --- | --- | -| iconName | 当前点击的 icon 名称 | string | | ✓ | -| meta |当前 cell 的 meta 信息| Node | | ✓ | -| event |当前点击事件信息| Event |false| ✓ | +| iconName | 当前 icon 名称 | string | | ✓ | +| meta |当前 cell 的 meta 信息| [Node](/api/basic-class/node) | | ✓ | +| event |当前点击事件信息| Event | false | ✓ | ## CustomSVGIcon diff --git a/s2-site/docs/common/icon.zh.md b/s2-site/docs/common/icon.zh.md index 58a8b63450..9838273b7a 100644 --- a/s2-site/docs/common/icon.zh.md +++ b/s2-site/docs/common/icon.zh.md @@ -7,12 +7,12 @@ order: 3 | icon 名称 | icon 图标 | 功能描述 | icon 名称 | icon 图标 | 功能描述 | | ------------- | --------------------- | ---------- | ---------------- | ----------- | ------------------ | -| CellDown | icon | 同环比下降 | ExpandColIcon | icon | 明细表隐藏展开 | +| CellDown | icon | 同环比下降 | ExpandColIcon | icon | 展开列头 | | CellUp | icon | 同环比上升 | Plus | icon | 树状表格展开 | | GlobalAsc | icon | 全局升序 | Minus | icon | 树状表格收起 | -| GlobalDesc | icon | 全局降序 | SortDown | icon | 明细表降序 | -| GroupAsc | icon | 组内升序 | SortDownSelected | icon | 明细表降序选择状态 | -| GroupDesc | icon | 组内降序 | SortUp | icon | 明细表升序 | -| Trend | icon | 趋势图 | SortUpSelected | icon | 明细表升序选择状态 | +| GlobalDesc | icon | 全局降序 | SortDown | icon | 降序 | +| GroupAsc | icon | 组内升序 | SortDownSelected | icon | 降序选中状态 | +| GroupDesc | icon | 组内降序 | SortUp | icon | 升序 | +| Trend | icon | 趋势图 | SortUpSelected | icon | 升序选中状态 | | ArrowUp | icon | 指标上升 |ArrowDown | icon | 指标下降 | | DrillDownIcon | icon | 下钻 | | | | From 7751c4968b69752243928cbcd2c50333b06b2c66 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Wed, 11 Oct 2023 20:04:59 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix(table-sheet):=20=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E8=A1=A8=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA=E6=97=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E5=B1=95=E7=A4=BA=E4=B8=80=E8=A1=8C=E7=A9=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=20close=20#2255=20(#2357)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(table-sheet): 明细表数据为空时错误的展示一行空数据 close #2255 * test: 修复测试 * test: 修复测试 * fix: 重命名 --------- Co-authored-by: Wenjun Xu <906626481@qq.com> --- .../unit/data-set/pivot-data-set-spec.ts | 4 ++++ .../unit/data-set/table-data-set-spec.ts | 4 ++++ .../__tests__/unit/facet/table-facet-spec.ts | 6 ++++++ packages/s2-core/src/cell/table-col-cell.ts | 1 + .../s2-core/src/data-set/base-data-set.ts | 5 +++++ packages/s2-core/src/facet/table-facet.ts | 21 +++++++++++-------- .../s2-core/src/sheet-type/table-sheet.ts | 1 + .../docs/api/basic-class/base-data-set.zh.md | 1 + 8 files changed, 34 insertions(+), 9 deletions(-) diff --git a/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts b/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts index 2206b0f4b4..ab9f72ce28 100644 --- a/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts +++ b/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts @@ -158,6 +158,10 @@ describe('Pivot Dataset Test', () => { getDimensionsWithoutPathPre(sortedDimensionValues[EXTRA_FIELD]), ).toEqual(['number', 'number', 'number', 'number']); }); + + test('should get correctly empty dataset result', () => { + expect(dataSet.isEmpty()).toBeFalsy(); + }); }); describe('test for query data', () => { diff --git a/packages/s2-core/__tests__/unit/data-set/table-data-set-spec.ts b/packages/s2-core/__tests__/unit/data-set/table-data-set-spec.ts index 4da12e138b..8e990596c3 100644 --- a/packages/s2-core/__tests__/unit/data-set/table-data-set-spec.ts +++ b/packages/s2-core/__tests__/unit/data-set/table-data-set-spec.ts @@ -99,6 +99,10 @@ describe('Table Mode Dataset Test', () => { test('should get correct meta data', () => { expect(dataSet.meta).toEqual(expect.objectContaining([])); }); + + test('should get correctly empty dataset result', () => { + expect(dataSet.isEmpty()).toBeFalsy(); + }); }); describe('test for query data', () => { diff --git a/packages/s2-core/__tests__/unit/facet/table-facet-spec.ts b/packages/s2-core/__tests__/unit/facet/table-facet-spec.ts index 428e07a9fa..ad72e6226a 100644 --- a/packages/s2-core/__tests__/unit/facet/table-facet-spec.ts +++ b/packages/s2-core/__tests__/unit/facet/table-facet-spec.ts @@ -13,9 +13,11 @@ import { DataCell, DEFAULT_STYLE, type Fields, Node } from '@/index'; import { getFrozenLeafNodesCount } from '@/facet/utils'; import { SpreadSheet } from '@/sheet-type'; import { getTheme } from '@/theme'; + const actualDataSet = jest.requireActual( '@/data-set/base-data-set', ).BaseDataSet; + jest.mock('@/sheet-type', () => { const container = new Canvas({ width: 100, @@ -59,6 +61,9 @@ jest.mock('@/sheet-type', () => { interaction: { clearHoverTimer: jest.fn(), }, + dataSet: { + isEmpty: jest.fn(), + }, }; }), }; @@ -77,6 +82,7 @@ jest.mock('@/data-set/table-data-set', () => { getCellData: () => 1, getFieldMeta: jest.fn(), getFieldFormatter: actualDataSet.prototype.getFieldFormatter, + isEmpty: jest.fn(), }; }), }; diff --git a/packages/s2-core/src/cell/table-col-cell.ts b/packages/s2-core/src/cell/table-col-cell.ts index 3368f9ffd6..be1c6a04c4 100644 --- a/packages/s2-core/src/cell/table-col-cell.ts +++ b/packages/s2-core/src/cell/table-col-cell.ts @@ -77,6 +77,7 @@ export class TableColCell extends ColCell { y, }; } + return { x: position.x + x - scrollX, y: position.y + y, diff --git a/packages/s2-core/src/data-set/base-data-set.ts b/packages/s2-core/src/data-set/base-data-set.ts index 1c95f5e736..92ffb6ae8e 100644 --- a/packages/s2-core/src/data-set/base-data-set.ts +++ b/packages/s2-core/src/data-set/base-data-set.ts @@ -3,6 +3,7 @@ import { find, get, identity, + isEmpty, isNil, map, max, @@ -117,6 +118,10 @@ export abstract class BaseDataSet { return this.displayData; } + public isEmpty() { + return isEmpty(this.getDisplayDataSet()); + } + public getValueRangeByField(field: string): ValueRange { const cacheRange = getValueRangeState(this.spreadsheet, field); if (cacheRange) { diff --git a/packages/s2-core/src/facet/table-facet.ts b/packages/s2-core/src/facet/table-facet.ts index 0cd0f14ed2..e1608eb241 100644 --- a/packages/s2-core/src/facet/table-facet.ts +++ b/packages/s2-core/src/facet/table-facet.ts @@ -43,7 +43,7 @@ import { getFrozenRowsForGrid, getRowsForGrid, } from '../utils/grid'; -import type { PanelIndexes } from '../utils/indexes'; +import type { Indexes, PanelIndexes } from '../utils/indexes'; import { getValidFrozenOptions } from '../utils/layout/frozen'; import { BaseFacet } from './base-facet'; import { CornerBBox } from './bbox/cornerBBox'; @@ -1129,14 +1129,17 @@ export class TableFacet extends BaseFacet { } } - const indexes = calculateInViewIndexes( - scrollX, - scrollY, - this.viewCellWidths, - this.viewCellHeights, - finalViewport, - this.getRealScrollX(this.cornerBBox.width), - ); + // https://github.com/antvis/S2/issues/2255 + const indexes = this.spreadsheet.dataSet.isEmpty() + ? ([] as unknown as Indexes) + : calculateInViewIndexes( + scrollX, + scrollY, + this.viewCellWidths, + this.viewCellHeights, + finalViewport, + this.getRealScrollX(this.cornerBBox.width), + ); this.panelScrollGroupIndexes = indexes; diff --git a/packages/s2-core/src/sheet-type/table-sheet.ts b/packages/s2-core/src/sheet-type/table-sheet.ts index 3612f9d960..21f372f269 100644 --- a/packages/s2-core/src/sheet-type/table-sheet.ts +++ b/packages/s2-core/src/sheet-type/table-sheet.ts @@ -123,6 +123,7 @@ export class TableSheet extends SpreadSheet { } return new TableDataCell(facet, this); }; + return { ...this.options, ...fields, diff --git a/s2-site/docs/api/basic-class/base-data-set.zh.md b/s2-site/docs/api/basic-class/base-data-set.zh.md index 3b8523fc5a..b259e92ced 100644 --- a/s2-site/docs/api/basic-class/base-data-set.zh.md +++ b/s2-site/docs/api/basic-class/base-data-set.zh.md @@ -28,6 +28,7 @@ s2.dataSet.getFieldName('type') | getCellData | 获取单个的单元格数据 | (params: [CellDataParams](#celldataparams)) => [DataType[]](#datatype) | | | getMultiData | 获取批量的单元格数据 | (query: [DataType](#datatype), isTotals?: boolean, isRow?: boolean, drillDownFields?: string[]) => [DataType[]](#datatype) | | | moreThanOneValue | 是否超过 1 个数值 | () => [ViewMeta](#viewmeta) | | +| isEmpty | 是否为空数据集 | () => `boolean` | `@antv/s2-v1.51.1` | ### DataType From 4953b4e430f3c1857ce6648bcdc2493c37bb1092 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Fri, 13 Oct 2023 17:25:16 +0800 Subject: [PATCH 5/5] =?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) {