diff --git a/packages/s2-core/src/facet/header/series-number.ts b/packages/s2-core/src/facet/header/series-number.ts index ccd12cb2f3..58015b152a 100644 --- a/packages/s2-core/src/facet/header/series-number.ts +++ b/packages/s2-core/src/facet/header/series-number.ts @@ -5,7 +5,7 @@ import { measureTextWidth } from '@/utils/text'; import { getAdjustPosition } from '@/utils/text-absorption'; import { BBox, IGroup, IShape } from '@antv/g-canvas'; import { each } from 'lodash'; -import { ViewMeta } from '@/common/interface'; +import { Padding, ViewMeta } from '@/common/interface'; import { translateGroup } from '../utils'; import { BaseHeader, BaseHeaderConfig } from './base'; @@ -145,13 +145,7 @@ export class SeriesNumberHeader extends BaseHeader { isLeaf, isTotals, } = cellData; - const padding = { ...rowCellTheme.cell.padding }; - const labelWidth = measureTextWidth( - label, - this.headerConfig.spreadsheet.theme.rowCell.text, - ); - padding.left = Math.max(Math.abs((cellWidth - labelWidth) / 2), 4); - padding.right = padding.left; + const padding = this.getTextPadding(label, cellWidth); const textStyle = isLeaf && !isTotals ? rowCellTheme.text : rowCellTheme.bolderText; const textY = getAdjustPosition( @@ -172,4 +166,15 @@ export class SeriesNumberHeader extends BaseHeader { }, }); } + + private getTextPadding(text: string, cellWidth: number): Padding { + const rowCellTheme = this.headerConfig.spreadsheet.theme.rowCell; + const textWidth = measureTextWidth(text, rowCellTheme.text); + const padding = Math.max(Math.abs((cellWidth - textWidth) / 2), 4); + return { + ...rowCellTheme.cell.padding, + left: padding, + right: padding, + }; + } }