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

feat: optimize the performance of large data interaction #3

Merged
merged 6 commits into from
Jun 7, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ packages/vtable-docs/public/zh/documents
packages/vtable-docs/public/en/documents
packages/vtable-docs/public/*.html

#git-hook
# git-hook
common/scripts/pre-commit
11 changes: 7 additions & 4 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
import { MenuHandler } from '../menu/dom/MenuHandler';
import type { BaseTableAPI, BaseTableConstructorOptions, IBaseTableProtected } from '../ts-types/base-table';
import { FocusInput } from './FouseInput';
import { defaultPixelRatio } from '../tools/pixel-ratio';
const { toBoxArray } = utilStyle;
const { isTouchEvent } = event;
const rangeReg = /^\$(\d+)\$(\d+)$/;
Expand Down Expand Up @@ -156,7 +157,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
menu,
select: click,
customRender,
pixelRatio = 1
pixelRatio = defaultPixelRatio
} = options;
this.options = options;
this._widthMode = widthMode;
Expand Down Expand Up @@ -700,7 +701,8 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
* @param pixelRatio
*/
setPixelRatio(pixelRatio: number) {
// do nothing
this.internalProps.pixelRatio = pixelRatio;
this.scenegraph.setPixelRatio(pixelRatio);
}
/**
* 窗口尺寸发生变化 或者像数比变化
Expand Down Expand Up @@ -2030,15 +2032,16 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
* 清除选中单元格
*/
clearSelected() {
// do nothing
this.stateManeger.updateSelectPos(-1, -1);
}
/**
* 选中单元格 和鼠标选中单元格效果一致
* @param col
* @param row
*/
selectCell(col: number, row: number) {
// do nothing
this.stateManeger.updateSelectPos(col, row);
this.stateManeger.endSelectCells();
}

abstract isListTable(): boolean;
Expand Down
14 changes: 9 additions & 5 deletions packages/vtable/src/scenegraph/group-creater/progress/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Group } from '../../graphic/group';
import type { WrapText } from '../../graphic/text';
import { updateCellHeightForColumn } from '../../layout/update-height';
import type { Scenegraph } from '../../scenegraph';
import { emptyGroup } from '../../scenegraph';
import { getProp } from '../../utils/get-prop';
import { getPadding } from '../../utils/padding';
import { createColGroup } from '../column';
Expand Down Expand Up @@ -251,6 +252,8 @@ export class SceneProxy {
// 不改变row,更新body group范围
this.updateBody(y);
}

this.scenegraph.updateNextFrame();
}

updateBody(y: number) {
Expand Down Expand Up @@ -304,7 +307,7 @@ export class SceneProxy {
for (let col = this.bodyLeftCol; col <= this.bodyRightCol; col++) {
for (let row = syncTopRow; row <= syncBottomRow; row++) {
// const cellGroup = this.table.scenegraph.getCell(col, row);
const cellGroup = this.highPerformanceGetCell(col, row);
const cellGroup = this.highPerformanceGetCell(col, row, distStartRow, distEndRow);
this.updateCellGroupContent(cellGroup);
}
}
Expand Down Expand Up @@ -367,7 +370,7 @@ export class SceneProxy {
for (let col = this.bodyLeftCol; col <= this.bodyRightCol; col++) {
for (let row = syncTopRow; row <= syncBottomRow; row++) {
// const cellGroup = this.table.scenegraph.getCell(col, row);
const cellGroup = this.highPerformanceGetCell(col, row);
const cellGroup = this.highPerformanceGetCell(col, row, distStartRow, distEndRow);
this.updateCellGroupContent(cellGroup);
}
}
Expand Down Expand Up @@ -398,8 +401,6 @@ export class SceneProxy {
(this.table as any).scenegraph.bodyGroup.firstChild.lastChild.row
);

this.scenegraph.renderSceneGraph();

if (!this.table.internalProps.autoRowHeight) {
await this.progress();
}
Expand Down Expand Up @@ -524,7 +525,10 @@ export class SceneProxy {
}
}

highPerformanceGetCell(col: number, row: number) {
highPerformanceGetCell(col: number, row: number, rowStart: number = this.rowStart, rowEnd: number = this.rowEnd) {
if (row < rowStart || row > rowEnd) {
return emptyGroup;
}
if (this.cellCache.get(col)) {
const cacheCellGoup = this.cellCache.get(col);
if ((cacheCellGoup._next || cacheCellGoup._prev) && Math.abs(cacheCellGoup.row - row) < row) {
Expand Down
Loading