Skip to content

Commit

Permalink
fix(interaction): 优化resetSheetStyle性能 (#1653)
Browse files Browse the repository at this point in the history
* fix: 优化reset性能

* fix: icon draw
  • Loading branch information
YardWill authored Aug 9, 2022
1 parent ab470cb commit 972afc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
5 changes: 3 additions & 2 deletions packages/s2-core/src/interaction/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ export class RootInteraction {
}

public clearState() {
clearState(this.spreadsheet);
this.draw();
if (clearState(this.spreadsheet)) {
this.draw();
}
}

public changeState(interactionStateInfo: InteractionStateInfo) {
Expand Down
38 changes: 22 additions & 16 deletions packages/s2-core/src/utils/interaction/state-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,37 @@ import type { SpreadSheet } from '../../sheet-type';
* @desc clear the interaction state information
* @param spreadsheet sheet instance
*/
export const clearState = (spreadsheet: SpreadSheet) => {
export const clearState = (spreadsheet: SpreadSheet): boolean => {
const activeIcons = spreadsheet.store.get('visibleActionIcons');
const allInteractedCells = spreadsheet.interaction.getInteractedCells();
const cellMetas = spreadsheet.interaction.getState().cells;
// 如果都处于初始化状态 不需要clear
if (
isEmpty(allInteractedCells) &&
isEmpty(cellMetas) &&
isEmpty(activeIcons)
) {
return false;
}
forEach(activeIcons, (icon) => {
icon.set('visible', false);
});
spreadsheet.store.set('visibleActionIcons', []);

const allInteractedCells = spreadsheet.interaction.getInteractedCells();
const cellMetas = spreadsheet.interaction.getState().cells;

if (!isEmpty(allInteractedCells) || !isEmpty(cellMetas)) {
forEach(allInteractedCells, (cell: S2CellType) => {
cell.hideInteractionShape();
});
forEach(allInteractedCells, (cell: S2CellType) => {
cell.hideInteractionShape();
});

spreadsheet.interaction.resetState();
if (spreadsheet.options.interaction.selectedCellsSpotlight) {
const unSelectedCells =
spreadsheet.interaction.getPanelGroupAllUnSelectedDataCells() || [];
spreadsheet.interaction.resetState();
if (spreadsheet.options.interaction.selectedCellsSpotlight) {
const unSelectedCells =
spreadsheet.interaction.getPanelGroupAllUnSelectedDataCells() || [];

forEach(unSelectedCells, (cell) => {
cell.clearUnselectedState();
});
}
forEach(unSelectedCells, (cell) => {
cell.clearUnselectedState();
});
}
return true;
};

/**
Expand Down

1 comment on commit 972afc6

@vercel
Copy link

@vercel vercel bot commented on 972afc6 Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2-git-master-antv-s2.vercel.app
antvis-s2-antv-s2.vercel.app
antvis-s2.vercel.app

Please sign in to comment.