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(layout): 修复隐藏结点时对父节点的布局计算错误 close #2355 #2360

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(hiddenColumnsInfo).toBeTruthy();
expect(parentNode.hiddenChildNodeInfo).toEqual(hiddenColumnsInfo);
});
// https://github.com/antvis/S2/issues/2355
test('should render correctly x and width after hide columns when there is only one value for the higher-level dimension.', () => {
const nodeId = 'root[&]笔[&]义乌[&]price';

pivotSheet.setOptions({
style: {
colCfg: {
width: 100,
},
},
});
const data = pivotSheet.dataCfg.data.map((i) => ({ ...i, cost: 0 }));
pivotSheet.setDataCfg({
data,
fields: {
values: ['cost', 'price'],
},
});
pivotSheet.render();

pivotSheet.interaction.hideColumns([nodeId]);
const rootNode = pivotSheet
.getColumnNodes()
.find((node) => node.id === 'root[&]笔');

expect(rootNode.width).toEqual(300);
expect(rootNode.x).toEqual(0);
});

// https://github.com/antvis/S2/issues/2194
test('should render correctly when always hidden last column', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export class PivotFacet extends BaseFacet {
leafNodes.push(parentNode);

const firstVisibleChildNode = parentNode.children?.find(
(childNode) => !childNode.hiddenChildNodeInfo,
(childNode) => childNode.width,
);
// 父节点 x 坐标 = 第一个未隐藏的子节点的 x 坐标
// 父节点 x 坐标 = 第一个正常布局处理过的子节点 x 坐标(width 有值认为是正常布局过)
const parentNodeX = firstVisibleChildNode?.x;
// 父节点宽度 = 所有子节点宽度之和
const parentNodeWidth = sumBy(parentNode.children, 'width');
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/utils/layout/generate-header-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const generateHeaderNodes = (params: HeaderNodesParams) => {
// 如果当前是隐藏节点, 给其父节点挂载相应信息 (兄弟节点, 当前哪个子节点隐藏了), 这样在 facet 层可以直接使用, 不用每次都去遍历
const hiddenColumnsInfo = spreadsheet?.facet?.getHiddenColumnsInfo(node);
if (hiddenColumnsInfo && parentNode) {
// hiddenChildNodeInfo 属性在 S2 中没有用到,但是没删怕外部有使用
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
parentNode.hiddenChildNodeInfo = hiddenColumnsInfo;
}

Expand Down