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: 修复合并单元格滚动出可视范围后边框绘制错误 close #3048 #3049

Merged
merged 2 commits into from
Dec 20, 2024
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
58 changes: 58 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-3048-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @description spec for issue #3048
* https://github.com/antvis/S2/issues/3048
*/
import { createPivotSheet, sleep } from '../util/helpers';

describe('Merged Cells Scroll Tests', () => {
test('should render correctly borders after scroll out of view', async () => {
const s2 = createPivotSheet(
{
width: 800,
height: 600,
mergedCellsInfo: [
[
{
rowIndex: 0,
colIndex: 1,
},
{
rowIndex: 1,
colIndex: 1,
showText: true,
},
],
],
style: {
dataCell: {
height: 150,
},
},
},
{ useSimpleData: false },
);

await s2.render();

// 让合并单元格滚动出可视范围内
s2.interaction.scrollToBottom({ animate: false });
await sleep(500);

// 滚动回来
s2.interaction.scrollToTop({ animate: false });
await sleep(500);

const mergedCellChildNodes = s2.facet
.getMergedCells()[0]
.children.map((node) => node.nodeName);

// 边框线正常添加
expect(mergedCellChildNodes).toEqual([
'polygon',
'text',
'line',
'line',
'line',
]);
});
});
1 change: 1 addition & 0 deletions packages/s2-core/__tests__/unit/utils/merge-cell-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Merge Cells Test', () => {
mockInstance.store = new Store();
mockInstance.options = {
conditions: [],
dataCell: jest.fn(() => ({})),
};
mockInstance.interaction = {
getPanelGroupAllDataCells() {
Expand Down
12 changes: 10 additions & 2 deletions packages/s2-core/src/utils/interaction/merge-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ export const getInvisibleInfo = (
);

if (meta) {
const cell = sheet?.options?.dataCell?.(meta, meta.spreadsheet);
const cell = sheet?.options?.dataCell?.(meta, meta.spreadsheet)!;

if (cell) {
/**
* 避免移除可视范围后丢失 position 属性: https://github.com/antvis/S2/issues/3048
* 绘制线依赖 position 属性 => packages/s2-core/src/utils/cell/merged-cell.ts#getRightAndBottomCells
*/
cell.position = [cellInfo.rowIndex!, cellInfo.colIndex!];
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved
cells.push(cell!);
}

viewMeta = cellInfo?.showText ? meta : viewMeta;
cells.push(cell!);
}
});

Expand Down
Loading