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 051971d89d..9f160579af 100644 --- a/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts @@ -6,6 +6,7 @@ import { PivotSheetMultiLineTextDataCfg, TableSheetMultiLineTextDataCfg, } from '../data/data-multi-line-text'; +import SimpleDataCfg from '../data/simple-data.json'; describe('SpreadSheet Multi Line Text Tests', () => { let s2: SpreadSheet; @@ -114,7 +115,7 @@ describe('SpreadSheet Multi Line Text Tests', () => { }); afterEach(() => { - s2.destroy(); + // s2.destroy(); }); test('should default render one line text', () => { @@ -300,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', () => { @@ -395,5 +414,17 @@ describe('SpreadSheet Multi Line Text Tests', () => { expectHierarchyHeight(70, 0, 70, 1); }); + + 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); + + s2.setDataCfg(SimpleDataCfg); + await s2.render(); + + expectHierarchyHeight(30, 0, 30, 1); + }, + ); }); }); diff --git a/packages/s2-core/src/cell/base-cell.ts b/packages/s2-core/src/cell/base-cell.ts index be85d5327d..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,24 +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 绘制坐标 - this.renderTextShape( - { - ...textStyle, - x: 0, - y: 0, - text: this.getFieldValue(), - wordWrapWidth: maxTextWidth, - }, - options, - ); + 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 e2d73d04b1..1cd3eeec29 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -324,13 +324,15 @@ 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; - return textHeight >= defaultHeight ? adaptiveHeight : 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-core/src/sheet-type/spread-sheet.ts b/packages/s2-core/src/sheet-type/spread-sheet.ts index 6aba27d534..ac13d77501 100644 --- a/packages/s2-core/src/sheet-type/spread-sheet.ts +++ b/packages/s2-core/src/sheet-type/spread-sheet.ts @@ -525,10 +525,17 @@ export abstract class SpreadSheet extends EE { } /** - * 获取 HTML元素 + * 获取 G Canvas 实例 + */ + public getCanvas(): Canvas { + return this.container; + } + + /** + * 获取 HTML 元素 */ public getCanvasElement(): HTMLCanvasElement { - return this.container + return this.getCanvas() .getContextService() .getDomElement() as HTMLCanvasElement; } diff --git a/packages/s2-react/__tests__/data/custom-tree-fields.ts b/packages/s2-react/__tests__/data/custom-tree-fields.ts index e82f6bc2cb..757ca5f87b 100644 --- a/packages/s2-react/__tests__/data/custom-tree-fields.ts +++ b/packages/s2-react/__tests__/data/custom-tree-fields.ts @@ -52,7 +52,7 @@ export const customTreeFields: S2DataConfig['fields'] = { }, { field: 'measure-e', - title: '指标E', + title: '自定义节点A', description: '指标E描述', children: [ { 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 ec83c917f4..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, @@ -376,7 +377,7 @@ function MainLayout() { children: ( <> { + 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(); } } diff --git a/s2-site/docs/api/basic-class/spreadsheet.zh.md b/s2-site/docs/api/basic-class/spreadsheet.zh.md index 8bb6926c95..b5e6bbfc7b 100644 --- a/s2-site/docs/api/basic-class/spreadsheet.zh.md +++ b/s2-site/docs/api/basic-class/spreadsheet.zh.md @@ -60,6 +60,7 @@ s2.isPivotMode() | getTotalsConfig | 获取总计小计配置 | (dimension: string) => [Total](/docs/api/general/S2Options#totals) | | | getInitColLeafNodes | 获取初次渲染的列头叶子节点 (比如:隐藏列头前) | () => [Node[]](/docs/api/basic-class/node/) | | | getCanvasElement | 获取表格对应的 `` HTML 元素 | () => [HTMLCanvasElement](https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLCanvasElement) | | +| getCanvas | 获取 G Canvas 实例 | () => [Canvas](https://g.antv.antgroup.com/api/renderer/canvas) | | | clearInitColLeafNodes | 清空存储在 store 中的初始叶子节点 | () => void | | | updateSortMethodMap | 更新存储在 store 中的节点排序方式 map, replace 为是否覆盖上一次的值 | (nodeId: string, sortMethod: string, replace?: boolean) => void | | | getMenuDefaultSelectedKeys | 获取 tooltip 中选中的菜单项 key 值 | `(nodeId: string) => string[]` | |