Skip to content

Commit

Permalink
Merge pull request #846 from VisActor/831-bug-setRecords-performance
Browse files Browse the repository at this point in the history
831 bug set records performance
  • Loading branch information
fangsmile authored Jan 3, 2024
2 parents c0353d4 + 1a5ca56 commit 36e1a04
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: setRecords process scrollTop update scenegraph #831\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
18 changes: 16 additions & 2 deletions packages/vtable/src/scenegraph/group-creater/progress/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,29 +434,43 @@ export class SceneProxy {
}

async setY(y: number) {
const yLimitTop = this.table.getRowsHeight(this.bodyTopRow, this.bodyTopRow + this.totalActualBodyRowCount) / 2;
const yLimitTop =
this.table.getRowsHeight(this.bodyTopRow, this.bodyTopRow + (this.rowEnd - this.rowStart + 1)) / 2;
const yLimitBottom = this.table.getAllRowsHeight() - yLimitTop;
if (y < yLimitTop && this.rowStart === this.bodyTopRow) {
// 执行真实body group坐标修改
this.table.scenegraph.setBodyAndRowHeaderY(-y);
} else if (y > yLimitBottom && this.rowEnd === this.bodyBottomRow) {
// 执行真实body group坐标修改
this.table.scenegraph.setBodyAndRowHeaderY(-y);
} else if (
!this.table.scenegraph.bodyGroup.firstChild ||
this.table.scenegraph.bodyGroup.firstChild.childrenCount === 0
) {
// 兼容异步加载数据promise的情况 childrenCount=0 如果用户立即调用setScrollTop执行dynamicSetY会出错
this.table.scenegraph.setBodyAndRowHeaderY(-y);
} else {
// 执行动态更新节点
this.dynamicSetY(y);
}
}

async setX(x: number) {
const xLimitLeft = this.table.getColsWidth(this.bodyLeftCol, this.bodyLeftCol + this.totalActualBodyColCount) / 2;
const xLimitLeft =
this.table.getColsWidth(this.bodyLeftCol, this.bodyLeftCol + (this.colEnd - this.colStart + 1)) / 2;
const xLimitRight = this.table.getAllColsWidth() - xLimitLeft;
if (x < xLimitLeft && this.colStart === this.bodyLeftCol) {
// 执行真实body group坐标修改
this.table.scenegraph.setBodyAndColHeaderX(-x);
} else if (x > xLimitRight && this.colEnd === this.bodyRightCol) {
// 执行真实body group坐标修改
this.table.scenegraph.setBodyAndColHeaderX(-x);
} else if (
this.table.scenegraph.bodyGroup.firstChild && //注意判断关系 这里不是 || 而是 &&
this.table.scenegraph.bodyGroup.firstChild.childrenCount === 0
) {
// 兼容异步加载数据promise的情况 childrenCount=0 如果用户立即调用setScrollLeft执行dynamicSetX会出错
this.table.scenegraph.setBodyAndColHeaderX(-x);
} else {
// 执行动态更新节点
this.dynamicSetX(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,24 @@ function updatePartRowPosition(startRow: number, endRow: number, direction: 'up'
}

function updateCellGroupPosition(colGroup: Group, direction: 'up' | 'down', proxy: SceneProxy) {
if (direction === 'up') {
const cellGroup = colGroup.firstChild as Group;
proxy.updateCellGroupPosition(
cellGroup,
(colGroup.lastChild as Group).row + 1,
(colGroup.lastChild as Group).attribute.y + proxy.table.getRowHeight((colGroup.lastChild as Group).row) // (colGroup.lastChild as Group).attribute.height
);
colGroup.appendChild(cellGroup);
} else {
const cellGroup = colGroup.lastChild as Group;
proxy.updateCellGroupPosition(
cellGroup,
(colGroup.firstChild as Group).row - 1,
(colGroup.firstChild as Group).attribute.y - proxy.table.getRowHeight((cellGroup as Group).row) // cellGroup.attribute.height
);
colGroup.insertBefore(cellGroup, colGroup.firstChild);
if (colGroup.childrenCount >= 1) {
if (direction === 'up') {
const cellGroup = colGroup.firstChild as Group;
proxy.updateCellGroupPosition(
cellGroup,
(colGroup.lastChild as Group).row + 1,
(colGroup.lastChild as Group).attribute.y + proxy.table.getRowHeight((colGroup.lastChild as Group).row) // (colGroup.lastChild as Group).attribute.height
);
colGroup.appendChild(cellGroup);
} else {
const cellGroup = colGroup.lastChild as Group;
proxy.updateCellGroupPosition(
cellGroup,
(colGroup.firstChild as Group).row - 1,
(colGroup.firstChild as Group).attribute.y - proxy.table.getRowHeight((cellGroup as Group).row) // cellGroup.attribute.height
);
colGroup.insertBefore(cellGroup, colGroup.firstChild);
}
}
}

Expand Down

0 comments on commit 36e1a04

Please sign in to comment.