diff --git a/packages/s2-core/__tests__/unit/facet/layout/col-node-width-spec.ts b/packages/s2-core/__tests__/unit/facet/layout/col-node-width-spec.ts index dd7fab840d..7f75250124 100644 --- a/packages/s2-core/__tests__/unit/facet/layout/col-node-width-spec.ts +++ b/packages/s2-core/__tests__/unit/facet/layout/col-node-width-spec.ts @@ -134,8 +134,10 @@ describe('Col width Test', () => { const { colLeafNodes } = s2.facet.layoutResult; - expect(Math.round(colLeafNodes[0].width)).toBe(47); // 列头标签更长 - expect(Math.round(colLeafNodes[1].width)).toBe(168); // 表身标签更长(格式化) + // price 列,列头标签比表身数据更长 + expect(Math.round(colLeafNodes[0].width)).toBe(46); + // cost 列,表身数据比列头更长(格式化) + expect(Math.round(colLeafNodes[1].width)).toBe(168); }); }); }); diff --git a/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts b/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts index fd41dc2021..e6e06f1932 100644 --- a/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts @@ -323,7 +323,7 @@ describe('drawInterval Test', () => { }); const horizontalBorderWidth = - getTheme({})?.dataCell?.cell?.horizontalBorderWidth || 1; + getTheme({})?.dataCell?.cell?.horizontalBorderWidth ?? 1; const options = assembleOptions({ style: { dataCell: { diff --git a/packages/s2-core/src/facet/table-facet.ts b/packages/s2-core/src/facet/table-facet.ts index ada2adbb90..1e280a755c 100644 --- a/packages/s2-core/src/facet/table-facet.ts +++ b/packages/s2-core/src/facet/table-facet.ts @@ -501,7 +501,7 @@ export class TableFacet extends BaseFacet { // 计算表头 label+icon 占用的空间 const colHeaderNodeWidth = - spreadsheet.measureTextWidth(colNode.label, colCellTextStyle) + + spreadsheet.measureTextWidth(colNode.value, colCellTextStyle) + getOccupiedWidthForTableCol( this.spreadsheet, colNode, diff --git a/packages/s2-core/src/utils/cell/table-col-cell.ts b/packages/s2-core/src/utils/cell/table-col-cell.ts index 1bb52da47e..86d1508e7d 100644 --- a/packages/s2-core/src/utils/cell/table-col-cell.ts +++ b/packages/s2-core/src/utils/cell/table-col-cell.ts @@ -63,6 +63,7 @@ export const getOccupiedWidthForTableCol = ( style: DefaultCellTheme, ) => { const padding = get(style, 'cell.padding'); + const horizontalBorderWidth = style?.cell?.horizontalBorderWidth ?? 1; const expandIconPadding = getExtraPaddingForExpandIcon(s2, meta.field, style); const iconsWidth = getTableColIconsWidth( s2, @@ -76,6 +77,7 @@ export const getOccupiedWidthForTableCol = ( padding.right + iconsWidth + expandIconPadding.left + - expandIconPadding.right + expandIconPadding.right + + horizontalBorderWidth ); };