diff --git a/packages/s2-core/__tests__/spreadsheet/__snapshots__/multi-line-text-spec.ts.snap b/packages/s2-core/__tests__/spreadsheet/__snapshots__/multi-line-text-spec.ts.snap index 6e1f64174a..5b04f4dac4 100644 --- a/packages/s2-core/__tests__/spreadsheet/__snapshots__/multi-line-text-spec.ts.snap +++ b/packages/s2-core/__tests__/spreadsheet/__snapshots__/multi-line-text-spec.ts.snap @@ -1625,6 +1625,385 @@ Array [ ] `; +exports[`SpreadSheet Multi Line Text Tests PivotSheet should not adaptive adjust cell height if hidden col cell 1`] = ` +Array [ + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 80, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 96, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 96, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 272, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 272, + }, +] +`; + +exports[`SpreadSheet Multi Line Text Tests PivotSheet should not adaptive adjust cell height if hidden col cell 2`] = ` +Array [ + Object { + "actualText": "1", + "actualTextHeight": 15, + "actualTextWidth": 7, + "height": 120, + "multiLineActualTexts": Array [ + "1", + ], + "originalText": "1", + "width": 80, + }, + Object { + "actualText": "2", + "actualTextHeight": 15, + "actualTextWidth": 7, + "height": 30, + "multiLineActualTexts": Array [ + "2", + ], + "originalText": "2", + "width": 80, + }, + Object { + "actualText": "3", + "actualTextHeight": 15, + "actualTextWidth": 7, + "height": 120, + "multiLineActualTexts": Array [ + "3", + ], + "originalText": "3", + "width": 80, + }, +] +`; + +exports[`SpreadSheet Multi Line Text Tests PivotSheet should not adaptive adjust cell height if hidden col cell 3`] = ` +Array [ + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 192, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 96, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 96, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 96, + }, + Object { + "actualText": undefined, + "actualTextHeight": 0, + "actualTextWidth": 0, + "height": 0, + "multiLineActualTexts": Array [], + "originalText": undefined, + "width": 96, + }, +] +`; + +exports[`SpreadSheet Multi Line Text Tests PivotSheet should not adaptive adjust cell height if hidden col cell 4`] = ` +Array [ + Object { + "actualText": "浙江省", + "actualTextHeight": 16, + "actualTextWidth": 37, + "height": 120, + "multiLineActualTexts": Array [ + "浙江省", + ], + "originalText": "浙江省", + "width": 96, + }, + Object { + "actualText": "浙江省浙江...", + "actualTextHeight": 16, + "actualTextWidth": 71, + "height": 30, + "multiLineActualTexts": Array [ + "浙江省浙江...", + ], + "originalText": "浙江省浙江省浙江省浙江省浙江省浙江省浙江省浙江省浙江省浙江省", + "width": 96, + }, + Object { + "actualText": "四川省", + "actualTextHeight": 16, + "actualTextWidth": 37, + "height": 120, + "multiLineActualTexts": Array [ + "四川省", + ], + "originalText": "四川省", + "width": 96, + }, +] +`; + +exports[`SpreadSheet Multi Line Text Tests PivotSheet should not adaptive adjust cell height if hidden col cell 5`] = ` +Array [ + Object { + "actualText": "2367236723...", + "actualTextHeight": 15, + "actualTextWidth": 77, + "height": 30, + "multiLineActualTexts": Array [ + "2367236723...", + ], + "originalText": "236723672361111", + "width": 96, + }, + Object { + "actualText": "3877", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "3877", + ], + "originalText": "3877", + "width": 96, + }, + Object { + "actualText": "4342", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "4342", + ], + "originalText": "4342", + "width": 96, + }, + Object { + "actualText": "-", + "actualTextHeight": 15, + "actualTextWidth": 4, + "height": 30, + "multiLineActualTexts": Array [ + "-", + ], + "originalText": "-", + "width": 96, + }, + Object { + "actualText": "-", + "actualTextHeight": 15, + "actualTextWidth": 4, + "height": 30, + "multiLineActualTexts": Array [ + "-", + ], + "originalText": "-", + "width": 96, + }, + Object { + "actualText": "1723", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "1723", + ], + "originalText": "1723", + "width": 96, + }, + Object { + "actualText": "1822", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "1822", + ], + "originalText": "1822", + "width": 96, + }, + Object { + "actualText": "1943", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "1943", + ], + "originalText": "1943", + "width": 96, + }, + Object { + "actualText": "2330", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "2330", + ], + "originalText": "2330", + "width": 96, + }, + Object { + "actualText": "632", + "actualTextHeight": 15, + "actualTextWidth": 21, + "height": 30, + "multiLineActualTexts": Array [ + "632", + ], + "originalText": "632", + "width": 96, + }, + Object { + "actualText": "7234", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "7234", + ], + "originalText": "7234", + "width": 96, + }, + Object { + "actualText": "834", + "actualTextHeight": 15, + "actualTextWidth": 21, + "height": 30, + "multiLineActualTexts": Array [ + "834", + ], + "originalText": "834", + "width": 96, + }, + Object { + "actualText": "5343", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "5343", + ], + "originalText": "5343", + "width": 96, + }, + Object { + "actualText": "-", + "actualTextHeight": 15, + "actualTextWidth": 4, + "height": 30, + "multiLineActualTexts": Array [ + "-", + ], + "originalText": "-", + "width": 96, + }, + Object { + "actualText": "2451", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "2451", + ], + "originalText": "2451", + "width": 96, + }, + Object { + "actualText": "2244", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "2244", + ], + "originalText": "2244", + "width": 96, + }, + Object { + "actualText": "2333", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "2333", + ], + "originalText": "2333", + "width": 96, + }, + Object { + "actualText": "2445", + "actualTextHeight": 15, + "actualTextWidth": 27, + "height": 30, + "multiLineActualTexts": Array [ + "2445", + ], + "originalText": "2445", + "width": 96, + }, +] +`; + exports[`SpreadSheet Multi Line Text Tests PivotSheet should not render word wrap text 1`] = ` Array [ Object { diff --git a/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts b/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts index fc88860bc1..9f160579af 100644 --- a/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts @@ -125,7 +125,7 @@ describe('SpreadSheet Multi Line Text Tests', () => { expectHierarchyHeight(90); }); - test.only('should custom two max text lines', async () => { + test('should custom two max text lines', async () => { updateTheme(2); await s2.render(false); @@ -301,6 +301,24 @@ describe('SpreadSheet Multi Line Text Tests', () => { expectHierarchyHeight(90, 60, 30); }); + + test('should not adaptive adjust cell height if hidden col cell', async () => { + s2.setOptions({ + style: { + colCell: { + height: 0, + }, + }, + }); + + updateTheme(1); + await s2.render(false); + + getCells().forEach((cells) => { + expect(mapCells(cells)).toMatchSnapshot(); + }); + expectHierarchyHeight(0, 0, 0); + }); }); describe('TableSheet', () => { @@ -397,7 +415,7 @@ describe('SpreadSheet Multi Line Text Tests', () => { expectHierarchyHeight(70, 0, 70, 1); }); - test.only.each([1, 2, 3, 4, 5])( + test.skip.each([1, 2, 3, 4, 5])( 'should always render default cell height when set %s line, but actual text not wrap', async (maxLines) => { updateTheme(maxLines); diff --git a/packages/s2-core/src/cell/base-cell.ts b/packages/s2-core/src/cell/base-cell.ts index 87b401ffb5..e94f7f4b23 100644 --- a/packages/s2-core/src/cell/base-cell.ts +++ b/packages/s2-core/src/cell/base-cell.ts @@ -196,6 +196,10 @@ export abstract class BaseCell extends Group { return this.theme[this.cellType]?.icon; } + public isShallowRender() { + return false; + } + /** * 获取实际渲染的文本 (含省略号) */ @@ -396,10 +400,11 @@ export abstract class BaseCell extends Group { options?: RenderTextShapeOptions, ): CustomText { const text = getDisplayText(style.text, this.getEmptyPlaceholder()); + const shallowRender = options?.shallowRender || this.isShallowRender(); this.textShape = renderText({ group: this, - textShape: options?.shallowRender ? undefined : this.textShape, + textShape: shallowRender ? undefined : this.textShape, style: { ...style, text, @@ -408,7 +413,7 @@ export abstract class BaseCell extends Group { this.addTextShape(this.textShape); - if (options?.shallowRender) { + if (shallowRender) { return this.textShape; } @@ -428,37 +433,21 @@ export abstract class BaseCell extends Group { this.textShape?.attr('y', position?.y ?? defaultPosition?.y); } - public drawTextShape(options?: RenderTextShapeOptions) { + public drawTextShape() { // G 遵循浏览器的规范, 空间不足以展示省略号时, 会裁剪文字, 而不是展示省略号 https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#ellipsis const maxTextWidth = Math.max(this.getMaxTextWidth(), 0); const textStyle = this.getTextStyle(); // 在坐标计算 (getTextPosition) 之前, 预渲染一次, 提前生成 textShape, 获得文字宽度, 用于计算 icon 绘制坐标 - const textShape = this.renderTextShape( - { - ...textStyle, - x: 0, - y: 0, - text: this.getFieldValue(), - wordWrapWidth: maxTextWidth, - // maxLines: 2, - }, - options, - ); - - if ( - textShape.parsedStyle.maxLines > 1 && - textShape.parsedStyle.metrics?.width < maxTextWidth - ) { - console.log( - this.getFieldValue(), - textShape.parsedStyle.metrics?.width, - maxTextWidth, - ); - textShape.attr('maxLines', 1); - } + this.renderTextShape({ + ...textStyle, + x: 0, + y: 0, + text: this.getFieldValue(), + wordWrapWidth: maxTextWidth, + }); - if (options?.shallowRender) { + if (this.isShallowRender()) { return; } diff --git a/packages/s2-core/src/cell/corner-cell.ts b/packages/s2-core/src/cell/corner-cell.ts index d58bf95726..dd61264bab 100644 --- a/packages/s2-core/src/cell/corner-cell.ts +++ b/packages/s2-core/src/cell/corner-cell.ts @@ -7,11 +7,7 @@ import { ResizeDirectionType, S2Event, } from '../common/constant'; -import type { - FormatResult, - RenderTextShapeOptions, - TextTheme, -} from '../common/interface'; +import type { FormatResult, TextTheme } from '../common/interface'; import { CellBorderPosition, CellClipBox } from '../common/interface'; import { CornerNodeType } from '../common/interface/node'; import { CustomRect } from '../engine'; @@ -57,7 +53,7 @@ export class CornerCell extends HeaderCell { this.drawResizeArea(); } - public drawTextShape(options?: RenderTextShapeOptions) { + public drawTextShape() { const { x, y, height, width } = this.getBBoxByType(CellClipBox.CONTENT_BOX); const textStyle = this.getTextStyle(); const cornerText = this.getFieldValue(); @@ -78,16 +74,13 @@ export class CornerCell extends HeaderCell { const textY = y + height / 2; - this.renderTextShape( - { - ...textStyle, - x: textX, - y: textY, - text: cornerText, - wordWrapWidth: maxWidth, - }, - options, - ); + this.renderTextShape({ + ...textStyle, + x: textX, + y: textY, + text: cornerText, + wordWrapWidth: maxWidth, + }); const { size = 0 } = this.getStyle()!.icon!; const iconY = getVerticalIconPosition( diff --git a/packages/s2-core/src/cell/data-cell.ts b/packages/s2-core/src/cell/data-cell.ts index aed4dc358c..76a086c80c 100644 --- a/packages/s2-core/src/cell/data-cell.ts +++ b/packages/s2-core/src/cell/data-cell.ts @@ -36,7 +36,6 @@ import { type HeaderActionNameOptions, type IconCondition, type InteractionStateTheme, - type RenderTextShapeOptions, } from '../common/interface'; import { getFieldValueOfViewMetaData } from '../data-set/cell-data'; import { @@ -247,10 +246,10 @@ export class DataCell extends BaseCell { this.initCell(); } - public drawTextShape(options?: RenderTextShapeOptions) { - super.drawTextShape(options); + public drawTextShape() { + super.drawTextShape(); - if (!options?.shallowRender) { + if (!this.isShallowRender()) { this.drawLinkField(this.meta); } } diff --git a/packages/s2-core/src/cell/header-cell.ts b/packages/s2-core/src/cell/header-cell.ts index ae93cca3fd..f2039de51b 100644 --- a/packages/s2-core/src/cell/header-cell.ts +++ b/packages/s2-core/src/cell/header-cell.ts @@ -74,6 +74,14 @@ export abstract class HeaderCell< return this.headerConfig || ({} as T); } + public isShallowRender() { + return this.headerConfig.shallowRender!; + } + + protected shouldInit() { + return super.shouldInit() && !this.isShallowRender(); + } + protected handleRestOptions(...[headerConfig]: [T]) { this.headerConfig = { ...headerConfig }; diff --git a/packages/s2-core/src/cell/merged-cell.ts b/packages/s2-core/src/cell/merged-cell.ts index fb1e3b3594..064fef3a09 100644 --- a/packages/s2-core/src/cell/merged-cell.ts +++ b/packages/s2-core/src/cell/merged-cell.ts @@ -1,6 +1,6 @@ import { isEmpty, isObject } from 'lodash'; import { CellType } from '../common/constant'; -import type { RenderTextShapeOptions, ViewMeta } from '../common/interface'; +import type { ViewMeta } from '../common/interface'; import type { S2CellType } from '../common/interface/interaction'; import type { SpreadSheet } from '../sheet-type'; import { renderPolygon } from '../utils/g-renders'; @@ -54,7 +54,7 @@ export class MergedCell extends DataCell { }); } - public drawTextShape(options?: RenderTextShapeOptions) { + public drawTextShape() { if (isEmpty(this.meta)) { return; } @@ -62,7 +62,7 @@ export class MergedCell extends DataCell { if (isObject(this.meta.fieldValue)) { drawObjectText(this); } else { - super.drawTextShape(options); + super.drawTextShape(); } } } diff --git a/packages/s2-core/src/cell/row-cell.ts b/packages/s2-core/src/cell/row-cell.ts index 12ae43b982..bb8d1bb688 100644 --- a/packages/s2-core/src/cell/row-cell.ts +++ b/packages/s2-core/src/cell/row-cell.ts @@ -11,7 +11,6 @@ import { CellBorderPosition, CellClipBox, type AreaRange, - type RenderTextShapeOptions, type ViewMeta, } from '../common/interface'; import { CustomRect } from '../engine'; @@ -201,9 +200,9 @@ export class RowCell extends HeaderCell { return (!isLeaf && level === 0) || isTotals; } - public drawTextShape(options?: RenderTextShapeOptions) { - super.drawTextShape(options); - if (!options?.shallowRender) { + public drawTextShape() { + super.drawTextShape(); + if (!this.isShallowRender()) { this.drawLinkField(this.meta); } } diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index e7c3c6bdd0..1cd3eeec29 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -324,34 +324,13 @@ export abstract class BaseFacet { const { padding } = cell.getStyle().cell; - cell.drawTextShape({ - shallowRender: true, - }); + cell.drawTextShape(); + const { parsedStyle } = cell.getTextShape(); const textHeight = cell.getActualTextHeight(); const adaptiveHeight = textHeight + padding.top + padding.bottom; - if (cell.cellType === 'colCell') { - console.log( - 'getCellAdaptiveHeight =>', - textHeight, - defaultHeight, - cell.getFieldValue(), - cell.getTextLineBoundingRects(), - cell.getTextShape().parsedStyle.maxLines, - cell.getTextShape().parsedStyle.metrics, - cell.getTextShape().parsedStyle.metrics?.width, - cell.getMaxTextWidth(), - ); - } - - const { parsedStyle } = cell.getTextShape(); - - const inValid = - parsedStyle.maxLines > 1 && - parsedStyle.metrics?.width < cell.getMaxTextWidth(); - - return !inValid && textHeight >= defaultHeight + return parsedStyle?.maxLines! > 1 && textHeight >= defaultHeight ? adaptiveHeight : defaultHeight; } diff --git a/packages/s2-core/src/facet/header/interface.ts b/packages/s2-core/src/facet/header/interface.ts index e58974b611..39220c87e2 100644 --- a/packages/s2-core/src/facet/header/interface.ts +++ b/packages/s2-core/src/facet/header/interface.ts @@ -31,6 +31,7 @@ export interface BaseHeaderConfig { spreadsheet: SpreadSheet; // leaf node sort params sortParam?: SortParam; + shallowRender?: boolean; } export interface ColHeaderConfig extends BaseHeaderConfig { diff --git a/packages/s2-core/src/facet/pivot-facet.ts b/packages/s2-core/src/facet/pivot-facet.ts index cfe52c155a..59253edf41 100644 --- a/packages/s2-core/src/facet/pivot-facet.ts +++ b/packages/s2-core/src/facet/pivot-facet.ts @@ -253,7 +253,7 @@ export class PivotFacet extends BaseFacet { leafNodes.push(parentNode); const firstVisibleChildNode = parentNode.children?.find( - (childNode) => !childNode.hiddenChildNodeInfo, + (childNode) => childNode.width, ); // 父节点 x 坐标 = 第一个未隐藏的子节点的 x 坐标 const parentNodeX = firstVisibleChildNode?.x ?? 0; @@ -384,7 +384,9 @@ export class PivotFacet extends BaseFacet { } private getRowNodeHeight(rowNode: Node): number { - const rowCell = new RowCell(rowNode, this.spreadsheet, {}); + const rowCell = new RowCell(rowNode, this.spreadsheet, { + shallowRender: true, + }); const defaultHeight = this.getRowCellHeight(rowNode); return this.getCellAdaptiveHeight(rowCell, defaultHeight); @@ -395,7 +397,10 @@ export class PivotFacet extends BaseFacet { return 0; } - const colCell = new ColCell(colNode, this.spreadsheet, {}); + const colCell = new ColCell(colNode, this.spreadsheet, { + shallowRender: true, + }); + const defaultHeight = this.getDefaultColNodeHeight(colNode, colsHierarchy); return this.getCellAdaptiveHeight(colCell, defaultHeight); diff --git a/packages/s2-core/src/facet/table-facet.ts b/packages/s2-core/src/facet/table-facet.ts index e71683d64c..5cba6012e0 100644 --- a/packages/s2-core/src/facet/table-facet.ts +++ b/packages/s2-core/src/facet/table-facet.ts @@ -350,7 +350,9 @@ export class TableFacet extends BaseFacet { } protected getColNodeHeight(colNode: Node, colsHierarchy: Hierarchy) { - const colCell = new TableColCell(colNode, this.spreadsheet, {}); + const colCell = new TableColCell(colNode, this.spreadsheet, { + shallowRender: true, + }); const defaultHeight = this.getDefaultColNodeHeight(colNode, colsHierarchy); return this.getCellAdaptiveHeight(colCell, defaultHeight); diff --git a/packages/s2-react/playground/components/ResizeConfig.tsx b/packages/s2-react/playground/components/ResizeConfig.tsx index ce65b13ac7..6601c70472 100644 --- a/packages/s2-react/playground/components/ResizeConfig.tsx +++ b/packages/s2-react/playground/components/ResizeConfig.tsx @@ -35,7 +35,9 @@ export const ResizeConfig: React.FC<{ setOptions: ( cb: (prev: SheetComponentOptions) => SheetComponentOptions, ) => void; -}> = ({ options, setThemeCfg, setOptions }) => { + onMaxLinesChange?: (maxLines: number) => void; +}> = (props) => { + const { options, setThemeCfg, setOptions } = props; const [showResizeArea, setShowResizeArea] = React.useState(false); const onShowResizeAreaChange = (enable: boolean) => { @@ -110,10 +112,11 @@ export const ResizeConfig: React.FC<{ colCell: cellTheme, rowCell: cellTheme, cornerCell: cellTheme, - dataCell: cellTheme, }; setThemeCfg((prev) => customMerge(prev, { theme })); + + props.onMaxLinesChange?.(maxLines); }; const resizeConfig = options.interaction?.resize as ResizeInteractionOptions; diff --git a/packages/s2-react/playground/config.tsx b/packages/s2-react/playground/config.tsx index 54f7066879..54006e552d 100644 --- a/packages/s2-react/playground/config.tsx +++ b/packages/s2-react/playground/config.tsx @@ -11,6 +11,7 @@ import { import { getBaseSheetComponentOptions } from '@antv/s2-shared'; import type { SliderSingleProps } from 'antd'; import React from 'react'; +import { PivotSheetMultiLineTextDataCfg } from '@antv/s2/__tests__/data/data-multi-line-text'; import { data, fields, @@ -71,6 +72,8 @@ export const pivotSheetDataCfg: S2DataConfig = { fields, }; +export const pivotSheetMultiLineTextDataCfg = PivotSheetMultiLineTextDataCfg; + export const s2ConditionsOptions: SheetComponentOptions['conditions'] = { text: [ { diff --git a/packages/s2-react/playground/index.tsx b/packages/s2-react/playground/index.tsx index 94a4669b42..f1b4a295b5 100644 --- a/packages/s2-react/playground/index.tsx +++ b/packages/s2-react/playground/index.tsx @@ -61,6 +61,7 @@ import { TableSheetFrozenOptions, defaultOptions, pivotSheetDataCfg, + pivotSheetMultiLineTextDataCfg, s2ConditionsOptions, s2Options, sliderOptions, @@ -1326,6 +1327,13 @@ function MainLayout() { options={mergedOptions} setOptions={setOptions} setThemeCfg={setThemeCfg} + onMaxLinesChange={(maxLines) => { + setDataCfg( + maxLines > 1 + ? pivotSheetMultiLineTextDataCfg + : pivotSheetDataCfg, + ); + }} /> ), }, diff --git a/packages/s2-react/src/components/sheets/chart-sheet/custom-cell/data-cell.ts b/packages/s2-react/src/components/sheets/chart-sheet/custom-cell/data-cell.ts index 85cbe3c01a..7d582ec3bd 100644 --- a/packages/s2-react/src/components/sheets/chart-sheet/custom-cell/data-cell.ts +++ b/packages/s2-react/src/components/sheets/chart-sheet/custom-cell/data-cell.ts @@ -1,11 +1,11 @@ -import { DataCell, type RenderTextShapeOptions } from '@antv/s2'; +import { DataCell } from '@antv/s2'; export class ChartSheetDataCell extends DataCell { - public drawTextShape(options?: RenderTextShapeOptions) { + public drawTextShape() { if (this.isMultiData()) { return null; } - super.drawTextShape(options); + super.drawTextShape(); } } diff --git a/packages/s2-react/src/components/sheets/grid-analysis-sheet/custom-cell/data-cell.ts b/packages/s2-react/src/components/sheets/grid-analysis-sheet/custom-cell/data-cell.ts index 35f4fbc76a..f9316a7b80 100644 --- a/packages/s2-react/src/components/sheets/grid-analysis-sheet/custom-cell/data-cell.ts +++ b/packages/s2-react/src/components/sheets/grid-analysis-sheet/custom-cell/data-cell.ts @@ -1,8 +1,4 @@ -import { - DataCell, - drawObjectText, - type RenderTextShapeOptions, -} from '@antv/s2'; +import { DataCell, drawObjectText } from '@antv/s2'; /** * Cell for panelGroup area @@ -13,11 +9,11 @@ import { * -------------------------------------- */ export class GridAnalysisSheetDataCell extends DataCell { - public drawTextShape(options?: RenderTextShapeOptions) { + public drawTextShape() { if (this.isMultiData()) { return drawObjectText(this); } - super.drawTextShape(options); + super.drawTextShape(); } } diff --git a/packages/s2-react/src/components/sheets/strategy-sheet/custom-cell/data-cell.ts b/packages/s2-react/src/components/sheets/strategy-sheet/custom-cell/data-cell.ts index 1f0da673b9..946e315a4f 100644 --- a/packages/s2-react/src/components/sheets/strategy-sheet/custom-cell/data-cell.ts +++ b/packages/s2-react/src/components/sheets/strategy-sheet/custom-cell/data-cell.ts @@ -1,8 +1,4 @@ -import { - DataCell, - drawObjectText, - type RenderTextShapeOptions, -} from '@antv/s2'; +import { DataCell, drawObjectText } from '@antv/s2'; /** * Cell for panelGroup area @@ -12,11 +8,11 @@ import { * -------------------------------------- */ export class StrategySheetDataCell extends DataCell { - public drawTextShape(options?: RenderTextShapeOptions) { + public drawTextShape() { if (this.isMultiData()) { return drawObjectText(this); } - super.drawTextShape(options); + super.drawTextShape(); } }