Skip to content

Commit

Permalink
fix: 明细表compact模式宽度计算错误
Browse files Browse the repository at this point in the history
  • Loading branch information
lcx-seima committed Jan 13, 2023
1 parent 6493fe4 commit 6e9268f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe('drawInterval Test', () => {
});

const horizontalBorderWidth =
getTheme({})?.dataCell?.cell?.horizontalBorderWidth || 1;
getTheme({})?.dataCell?.cell?.horizontalBorderWidth ?? 1;
const options = assembleOptions({
style: {
dataCell: {
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion packages/s2-core/src/utils/cell/table-col-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -76,6 +77,7 @@ export const getOccupiedWidthForTableCol = (
padding.right +
iconsWidth +
expandIconPadding.left +
expandIconPadding.right
expandIconPadding.right +
horizontalBorderWidth
);
};

0 comments on commit 6e9268f

Please sign in to comment.