Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复树状角头,当有存在icon时,内容与box宽度恰好相等,出现换行 close #2389 #2390

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
});

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 @@ -501,7 +501,7 @@
this.autoCalculateRowNodeHeightAndY(rowLeafNodes);
if (!isEmpty(spreadsheet.options.totals?.row)) {
this.adjustTotalNodesCoordinate({
hierarchy: rowsHierarchy,

Check warning on line 504 in packages/s2-core/src/facet/pivot-facet.ts

View check run for this annotation

Codecov / codecov/patch

packages/s2-core/src/facet/pivot-facet.ts#L504

Added line #L504 was not covered by tests
isRowHeader: true,
isSubTotal: false,
});
Expand Down Expand Up @@ -563,7 +563,7 @@
multipleMap[level] = 0;
}
}
return multipleMap;

Check warning on line 566 in packages/s2-core/src/facet/pivot-facet.ts

View check run for this annotation

Codecov / codecov/patch

packages/s2-core/src/facet/pivot-facet.ts#L566

Added line #L566 was not covered by tests
}

// please read README-adjustTotalNodesCoordinate.md to understand this function
Expand Down Expand Up @@ -745,8 +745,11 @@
.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
Loading