Skip to content

Commit

Permalink
fix: 修复计算列宽时计算的文字宽度和判断文本是否溢出隐藏的文字宽度不一致的问题 (#2689)
Browse files Browse the repository at this point in the history
* fix: 修复存在字段标记时, 紧凑模式宽度计算错误

* fix: 修复紧凑模式下单元格宽度计算忽略了icon宽度的问题

* fix: 修改类型引用路径

* test: 补充utils单测

* fix: 修复计算列宽时计算的文字宽度和判断文本是否溢出隐藏的文字宽度不一致的问题

* fix: 修改变量名

---------

Co-authored-by: lijinke666 <[email protected]>
Co-authored-by: 张斌 <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent 84ebee2 commit 49aa4cf
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class PivotFacet extends FrozenFacet {
} = this.spreadsheet.theme.colCell;
const { text: dataCellTextStyle } = this.spreadsheet.theme.dataCell;

// leaf node rough width
// leaf node width
const cellFormatter = this.spreadsheet.dataSet.getFieldFormatter(
col.field,
);
Expand All @@ -421,11 +421,9 @@ export class PivotFacet extends FrozenFacet {
this.spreadsheet.options.showDefaultHeaderActionIcon,
colIconStyle,
);
const leafNodeRoughWidth =
this.spreadsheet.measureTextWidthRoughly(
leafNodeLabel,
colCellTextStyle,
) + colIconWidth;
const leafNodeWidth =
this.spreadsheet.measureTextWidth(leafNodeLabel, colCellTextStyle) +
colIconWidth;

const measureInfo = this.getMeasureInfo();

Expand Down Expand Up @@ -467,10 +465,8 @@ export class PivotFacet extends FrozenFacet {
);
const dataCellIconWidth = size + left + right;
const cellLabelWidth =
this.spreadsheet.measureTextWidthRoughly(
cellLabel,
dataCellTextStyle,
) + dataCellIconWidth;
this.spreadsheet.measureTextWidth(cellLabel, dataCellTextStyle) +
dataCellIconWidth;

if (cellLabelWidth > maxDataLabelWidth) {
maxDataLabel = cellLabel;
Expand All @@ -481,7 +477,7 @@ export class PivotFacet extends FrozenFacet {
}
}

const isLeafNodeWidthLonger = leafNodeRoughWidth > maxDataLabelWidth;
const isLeafNodeWidthLonger = leafNodeWidth > maxDataLabelWidth;
const maxLabel = isLeafNodeWidthLonger ? leafNodeLabel : maxDataLabel;
const appendedWidth = isLeafNodeWidthLonger
? colIconWidth
Expand Down

0 comments on commit 49aa4cf

Please sign in to comment.