From 7f983c1d8769d9d5cdc67e26df37031d424e9146 Mon Sep 17 00:00:00 2001 From: Bran <1055025755@qq.com> Date: Wed, 10 May 2023 17:54:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E6=98=8E=E7=BB=86=E8=A1=A8=E5=88=97?= =?UTF-8?q?=E5=A4=B4=E6=96=87=E6=9C=AC=E4=B8=8D=E5=B1=85=E4=B8=AD=20close?= =?UTF-8?q?=20#2199?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/cell/col-cell.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/s2-core/src/cell/col-cell.ts b/packages/s2-core/src/cell/col-cell.ts index bfb53957ae..554d8398e1 100644 --- a/packages/s2-core/src/cell/col-cell.ts +++ b/packages/s2-core/src/cell/col-cell.ts @@ -202,7 +202,7 @@ export class ColCell extends HeaderCell { width: width + (scrollContainsRowHeader ? cornerWidth : 0), }; - this.handleViewport(viewport); + // this.handleViewport(viewport); const { textAlign } = this.getTextStyle(); const adjustedViewport = adjustColHeaderScrollingViewport( From 2c91a91d02a63e617f81c793ef4540b78e8fffa4 Mon Sep 17 00:00:00 2001 From: Bran <1055025755@qq.com> Date: Wed, 17 May 2023 11:30:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?test(=E6=98=8E=E7=BB=86=E8=A1=A8):=20?= =?UTF-8?q?=E5=88=97=E5=A4=B4=E6=96=87=E6=9C=AC=E4=B8=8D=E5=B1=85=E4=B8=AD?= =?UTF-8?q?=20bug=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=20#2199?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s2-core/__tests__/bugs/issue-2199-spec.ts | 32 ++++ .../__tests__/data/data-issue-2199.json | 147 ++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 packages/s2-core/__tests__/bugs/issue-2199-spec.ts create mode 100644 packages/s2-core/__tests__/data/data-issue-2199.json diff --git a/packages/s2-core/__tests__/bugs/issue-2199-spec.ts b/packages/s2-core/__tests__/bugs/issue-2199-spec.ts new file mode 100644 index 0000000000..e1dad7d564 --- /dev/null +++ b/packages/s2-core/__tests__/bugs/issue-2199-spec.ts @@ -0,0 +1,32 @@ +/** + * @description spec for issue #2199 + * https://github.com/antvis/S2/issues/2199 + * 明细表: 当有冻结列 + 列分组的情况下, 会出现列头文本不居中现象 + */ +import { getContainer } from 'tests/util/helpers'; +import dataCfg from '../data/data-issue-2199.json'; +import { TableSheet } from '@/sheet-type'; +import type { S2Options } from '@/common/interface'; + +const s2Options: S2Options = { + width: 300, + height: 480, + showSeriesNumber: true, + frozenColCount: 1, +}; + +describe('ColCell Text Center Tests', () => { + test('should draw text centered in cell', () => { + const s2 = new TableSheet(getContainer(), dataCfg, s2Options); + s2.render(); + + s2.facet.updateScrollOffset({ offsetX: { value: 500, animate: false } }); + + const node = s2.getColumnNodes(0).slice(-1)?.[0]; + const cell = node?.belongsCell; + const { width: nodeWidth, x: nodeX } = node; + const { width: textWidth, x: textXActual } = cell.getContentArea(); + const textXCalc = nodeX + (nodeWidth - textWidth) / 2; + expect(textXCalc).toBeCloseTo(textXActual); + }); +}); diff --git a/packages/s2-core/__tests__/data/data-issue-2199.json b/packages/s2-core/__tests__/data/data-issue-2199.json new file mode 100644 index 0000000000..16629c6bcb --- /dev/null +++ b/packages/s2-core/__tests__/data/data-issue-2199.json @@ -0,0 +1,147 @@ +{ + "fields": { + "columns": [ + { + "key": "area", + "children": ["province", "city"] + }, + "type", + { + "key": "money", + "children": [ + { + "key": "price" + } + ] + } + ] + }, + "meta": [ + { + "field": "province", + "name": "省份" + }, + { + "field": "city", + "name": "城市" + }, + { + "field": "type", + "name": "商品类别" + }, + { + "field": "price", + "name": "价格" + }, + { + "field": "cost", + "name": "成本" + }, + { + "field": "area", + "name": "位置" + }, + { + "field": "money", + "name": "金额" + } + ], + "data": [ + { + "province": "浙江", + "city": "杭州", + "type": "笔", + "price": 1 + }, + { + "province": "浙江", + "city": "杭州", + "type": "纸张", + "price": 2 + }, + { + "province": "浙江", + "city": "舟山", + "type": "笔", + "price": 17 + }, + { + "province": "浙江", + "city": "舟山", + "type": "纸张", + "price": 6 + }, + { + "province": "吉林", + "city": "长春", + "type": "笔", + "price": 8 + }, + { + "province": "吉林", + "city": "白山", + "type": "笔", + "price": 12 + }, + { + "province": "吉林", + "city": "长春", + "type": "纸张", + "price": 3 + }, + { + "province": "吉林", + "city": "白山", + "type": "纸张", + "price": 25 + }, + { + "province": "浙江", + "city": "杭州", + "type": "笔", + "price": 20 + }, + { + "province": "浙江", + "city": "杭州", + "type": "纸张", + "price": 10 + }, + { + "province": "浙江", + "city": "舟山", + "type": "笔", + "price": 15 + }, + { + "province": "浙江", + "city": "舟山", + "type": "纸张", + "price": 2 + }, + { + "province": "吉林", + "city": "长春", + "type": "笔", + "price": 15 + }, + { + "province": "吉林", + "city": "白山", + "type": "笔", + "price": 30 + }, + { + "province": "吉林", + "city": "长春", + "type": "纸张", + "price": 40 + }, + { + "province": "吉林", + "city": "白山", + "type": "纸张", + "price": 50 + } + ] +} From 150a67d0d324e72d65dbcd9f2853650be2800ece Mon Sep 17 00:00:00 2001 From: Bran <1055025755@qq.com> Date: Wed, 17 May 2023 14:40:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(=E6=98=8E=E7=BB=86=E8=A1=A8):=20?= =?UTF-8?q?=E5=88=97=E5=A4=B4=E6=96=87=E6=9C=AC=E4=B8=8D=E5=B1=85=E4=B8=AD?= =?UTF-8?q?=20bug,=20=E5=88=A0=E9=99=A4=20handleViewport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/cell/col-cell.ts | 11 ----------- packages/s2-core/src/cell/table-col-cell.ts | 7 ------- 2 files changed, 18 deletions(-) diff --git a/packages/s2-core/src/cell/col-cell.ts b/packages/s2-core/src/cell/col-cell.ts index 554d8398e1..aa214831ad 100644 --- a/packages/s2-core/src/cell/col-cell.ts +++ b/packages/s2-core/src/cell/col-cell.ts @@ -202,8 +202,6 @@ export class ColCell extends HeaderCell { width: width + (scrollContainsRowHeader ? cornerWidth : 0), }; - // this.handleViewport(viewport); - const { textAlign } = this.getTextStyle(); const adjustedViewport = adjustColHeaderScrollingViewport( viewport, @@ -521,13 +519,4 @@ export class ColCell extends HeaderCell { protected isLastColumn() { return isLastColumnAfterHidden(this.spreadsheet, this.meta.id); } - - /** - * 计算文本位置时候需要,留给后代根据情况(固定列)覆盖 - * @param viewport - * @returns viewport - */ - protected handleViewport(viewport: AreaRange): AreaRange { - return viewport; - } } diff --git a/packages/s2-core/src/cell/table-col-cell.ts b/packages/s2-core/src/cell/table-col-cell.ts index 571bac4c4d..3368f9ffd6 100644 --- a/packages/s2-core/src/cell/table-col-cell.ts +++ b/packages/s2-core/src/cell/table-col-cell.ts @@ -137,11 +137,4 @@ export class TableColCell extends ColCell { fill: backgroundColor, }); } - - protected handleViewport(viewport: AreaRange): AreaRange { - if (this.isFrozenCell()) { - viewport.start = 0; - } - return viewport; - } }