Skip to content

Commit

Permalink
fix: fix style in exportCellImage() #1603
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Apr 25, 2024
1 parent a8c4cd0 commit c10dc56
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
55 changes: 54 additions & 1 deletion packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3893,13 +3893,44 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
if (col < this.frozenColCount && row < this.frozenRowCount) {
return true;
}

const colHeaderRangeRect = this.getCellRangeRelativeRect({
start: {
col: 0,
row: 0
},
end: {
col: this.colCount - 1,
row: this.columnHeaderLevelCount
}
});
const rowHeaderRangeRect = this.getCellRangeRelativeRect({
start: {
col: 0,
row: 0
},
end: {
col: this.rowHeaderLevelCount,
row: this.rowCount - 1
}
});

if (
rect.top >= drawRange.top &&
rect.bottom <= drawRange.bottom &&
rect.left >= drawRange.left &&
rect.right <= drawRange.right
) {
return true;
// return true;
if (this.isHeader(col, row)) {
return true;
} else if (
// body cell drawRange do not intersect colHeaderRangeRect&rowHeaderRangeRect
drawRange.top >= colHeaderRangeRect.bottom &&
drawRange.left >= rowHeaderRangeRect.right
) {
return true;
}
}
return false;
}
Expand Down Expand Up @@ -3942,6 +3973,9 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
}
const { col: hoverCol, row: hoverRow } = this.stateManager.hover.cellPos;
this.stateManager.updateHoverPos(-1, -1);
// hide scroll bar
this.scenegraph.component.hideVerticalScrollBar();
this.scenegraph.component.hideHorizontalScrollBar();

this.scenegraph.renderSceneGraph();

Expand Down Expand Up @@ -3990,6 +4024,18 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
start: { col: minCol, row: minRow },
end: { col: maxCol, row: maxRow }
});

// disable hover&select style
if (this.stateManager.select?.ranges?.length > 0) {
hideCellSelectBorder(this.scenegraph);
}
const { col: hoverCol, row: hoverRow } = this.stateManager.hover.cellPos;
this.stateManager.updateHoverPos(-1, -1);
// hide scroll bar
this.scenegraph.component.hideVerticalScrollBar();
this.scenegraph.component.hideHorizontalScrollBar();
this.scenegraph.renderSceneGraph();

const c = this.scenegraph.stage.toCanvas(
false,
new AABBBounds().set(
Expand All @@ -4005,6 +4051,13 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
this.setScrollTop(scrollTop);
this.setScrollLeft(scrollLeft);
}

// restore hover&select style
if (this.stateManager.select?.ranges?.length > 0) {
restoreCellSelectBorder(this.scenegraph);
}
this.stateManager.updateHoverPos(hoverCol, hoverRow);

return base64Image;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/vtable/src/scenegraph/select/update-select-border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,18 +602,18 @@ export function updateCellSelectBorder(

export function hideCellSelectBorder(scene: Scenegraph) {
scene.selectingRangeComponents.forEach((selectComp: { rect: IRect; role: CellSubLocation }, key: string) => {
selectComp.rect.setAttribute('visible', false);
selectComp.rect.setAttribute('opacity', 0);
});
scene.selectedRangeComponents.forEach((selectComp: { rect: IRect; role: CellSubLocation }, key: string) => {
selectComp.rect.setAttribute('visible', false);
selectComp.rect.setAttribute('opacity', 0);
});
}

export function restoreCellSelectBorder(scene: Scenegraph) {
scene.selectingRangeComponents.forEach((selectComp: { rect: IRect; role: CellSubLocation }, key: string) => {
selectComp.rect.setAttribute('visible', false);
selectComp.rect.setAttribute('opacity', 1);
});
scene.selectedRangeComponents.forEach((selectComp: { rect: IRect; role: CellSubLocation }, key: string) => {
selectComp.rect.setAttribute('visible', false);
selectComp.rect.setAttribute('opacity', 1);
});
}

0 comments on commit c10dc56

Please sign in to comment.