Skip to content

Commit

Permalink
fix: 修复树状角头,当有存在icon时,内容与box宽度恰好相等,出现换行 close #2389 (#2390)
Browse files Browse the repository at this point in the history
* fix: 树状角头,当有两个icon时,内容与box宽度恰好相等,出现换行

* fix: 树状角头,当有两个icon时,内容与box宽度恰好相等,出现换行 close:2389

* fix: 树状角头,当有两个icon时,内容与box宽度恰好相等,出现换行 close:2389

* chore: 增加注释

---------

Co-authored-by: JuZe <[email protected]>
  • Loading branch information
NoobNotN and JuZe authored Oct 27, 2023
1 parent 2443762 commit 19497b3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Array [
"rowIndex": undefined,
"seriesNumberWidth": 0,
"value": "province/city/数值",
"width": 150,
"width": 151,
"x": 0,
"y": 0,
},
Expand Down Expand Up @@ -253,7 +253,7 @@ Array [
"rowIndex": undefined,
"seriesNumberWidth": 80,
"value": "province/city/数值",
"width": 150,
"width": 151,
"x": 80,
"y": 0,
},
Expand Down Expand Up @@ -448,7 +448,7 @@ Array [
"rowIndex": undefined,
"seriesNumberWidth": 0,
"value": "province/city",
"width": 122,
"width": 123,
"x": 0,
"y": 0,
},
Expand Down Expand Up @@ -513,7 +513,7 @@ Array [
"rowIndex": undefined,
"seriesNumberWidth": 80,
"value": "province/city",
"width": 122,
"width": 123,
"x": 80,
"y": 0,
},
Expand Down Expand Up @@ -708,7 +708,7 @@ Array [
"rowIndex": undefined,
"seriesNumberWidth": 0,
"value": "province/city",
"width": 122,
"width": 123,
"x": 0,
"y": 0,
},
Expand Down Expand Up @@ -773,7 +773,7 @@ Array [
"rowIndex": undefined,
"seriesNumberWidth": 80,
"value": "province/city",
"width": 122,
"width": 123,
"x": 80,
"y": 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('SpreadSheet Tree Mode Tests', () => {
s2.render();

const rowsHierarchyWidth = s2.facet.layoutResult.rowsHierarchy.width;
expect(Math.round(rowsHierarchyWidth)).toEqual(123);
expect(Math.round(rowsHierarchyWidth)).toEqual(124);

// 行头维度均更改为较长的 name
const newDataCfg: S2DataConfig = {
Expand All @@ -49,5 +49,39 @@ describe('SpreadSheet Tree Mode Tests', () => {
rowsHierarchyWidth,
);
});

// https://github.com/antvis/S2/issues/2389
test('the corner should only have one line with action icon', () => {
// 行头维度更改为较长的 name
const newDataCfg: S2DataConfig = {
...mockDataConfig,
meta: [
{
field: 'province',
name: '省1234567890份',
},
{
field: 'city',
name: '城1234567890市',
},
],
};
// 添加icon
const newS2Options: S2Options = {
...s2Options,
headerActionIcons: [
{
iconNames: ['SortDownSelected'],
belongsCell: 'cornerCell',
},
],
};
const s2 = new PivotSheet(container, newDataCfg, newS2Options);
s2.render();

// 检查文本是否只有一行
const textLen = s2.facet.cornerHeader.cfg.children[0].textShapes.length;
expect(textLen).toEqual(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Col width Test', () => {
});
s2.render();
const { colLeafNodes } = s2.facet.layoutResult;
expect(Math.round(colLeafNodes[0].width)).toBe(339);
expect(Math.round(colLeafNodes[0].width)).toBe(338);
});

test('get correct width in layoutWidthType adaptive tree mode when enable seriesnumber', () => {
Expand All @@ -63,7 +63,7 @@ describe('Col width Test', () => {
});
s2.render();
const { colLeafNodes } = s2.facet.layoutResult;
expect(Math.round(colLeafNodes[0].width)).toBe(299);
expect(Math.round(colLeafNodes[0].width)).toBe(298);
});

test('get correct width in layoutWidthType compact mode', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,11 @@ export class PivotFacet extends BaseFacet {
.join('/');
const { bolderText: cornerCellTextStyle, icon: cornerIconStyle } =
this.spreadsheet.theme.cornerCell;
// 初始化角头时,保证其在树形模式下不换行,给与两个icon的宽度空余(tree icon 和 action icon),减少复杂的 action icon 判断
// 初始化角头时,保证其在树形模式下不换行
// 给与两个icon的宽度空余(tree icon 和 action icon),减少复杂的 action icon 判断
// 额外增加 1,当内容和容器宽度恰好相等时会出现换行
const maxLabelWidth =
1 +
this.spreadsheet.measureTextWidth(treeHeaderLabel, cornerCellTextStyle) +
cornerIconStyle.size * 2 +
cornerIconStyle.margin?.left +
Expand Down

1 comment on commit 19497b3

@vercel
Copy link

@vercel vercel bot commented on 19497b3 Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2.vercel.app
antvis-s2-antv-s2.vercel.app
antvis-s2-git-master-antv-s2.vercel.app

Please sign in to comment.