From d200b13ffaced2af37e69739077b4734a516dd95 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Thu, 2 Jan 2025 15:09:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=A0=87=E8=AE=B0=E6=97=B6,=20=E7=B4=A7?= =?UTF-8?q?=E5=87=91=E6=A8=A1=E5=BC=8F=E4=B8=8B=E6=9C=89=E5=87=A0=E7=8E=87?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9C=81=E7=95=A5=E5=8F=B7=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#3061)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spreadsheet/compare-layout-spec.ts | 60 ++++++++++++++++++- packages/s2-core/src/facet/pivot-facet.ts | 7 +-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts b/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts index 2ccf650541..f77a329a02 100644 --- a/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts @@ -3,7 +3,7 @@ * https://github.com/antvis/S2/issues/2385 */ import { PivotSheet, SpreadSheet, TableSheet } from '@/sheet-type'; -import { LayoutWidthType, type S2Options } from '../../src'; +import { LayoutWidthType, customMerge, type S2Options } from '../../src'; import * as mockDataConfig from '../data/data-issue-2385.json'; import { getContainer } from '../util/helpers'; @@ -320,6 +320,64 @@ describe('Compare Layout Tests', () => { expectTextOverflowing(s2); }); + test.each([{ showIcon: true }, { showIcon: false }])( + 'should get max col leaf node width for pivot sheet conditions and header action icons by %o', + async (options) => { + const s2 = new PivotSheet( + getContainer(), + customMerge(mockDataConfig, { fields: { columns: [] } }), + { + ...s2Options, + headerActionIcons: options.showIcon + ? [ + { + icons: ['SortDown'], + belongsCell: 'colCell', + }, + ] + : [], + conditions: { + icon: [ + { + field: 'price', + position: 'left', + mapping(fieldValue: number) { + if (!fieldValue) { + return null; + } + + return fieldValue > 0 + ? { + fill: 'red', + icon: 'CellUp', + } + : { + fill: 'green', + icon: 'CellDown', + }; + }, + }, + ], + }, + }, + ); + + s2.setDataCfg({ + meta: [ + { + field: 'price', + name: '环比差值', + formatter: () => '2,248.92万', + }, + ], + }); + + await s2.render(); + + expectTextOverflowing(s2); + }, + ); + test.each([ { text: '中文文本测试中文文本测试', width: 145 }, { text: '中文文本测试中文文本123', width: 142 }, diff --git a/packages/s2-core/src/facet/pivot-facet.ts b/packages/s2-core/src/facet/pivot-facet.ts index f118aa4689..0bff5524f5 100644 --- a/packages/s2-core/src/facet/pivot-facet.ts +++ b/packages/s2-core/src/facet/pivot-facet.ts @@ -952,10 +952,9 @@ export class PivotFacet extends FrozenFacet { dataCellIconStyle?.margin?.left + dataCellIconStyle?.margin?.right : 0; - const cellLabelWidth = this.measureTextWidth( - cellLabel as string, - dataCellTextStyle, - ); + const cellLabelWidth = + this.measureTextWidth(cellLabel as string, dataCellTextStyle) + + dataCellIconWidth; if (cellLabelWidth > maxDataLabelWidth) { maxDataLabel = cellLabel as string;