Skip to content

Commit

Permalink
Merge pull request #833 from VisActor/fix/chart-right-frozen
Browse files Browse the repository at this point in the history
fix: fix frozen chart cell active problem
  • Loading branch information
Rui-Sun committed Jan 2, 2024
2 parents 914692f + ddcda2d commit e6f20c1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "fix: fix frozen chart cell active problem ",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
44 changes: 37 additions & 7 deletions packages/vtable/src/scenegraph/graphic/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,14 @@ export class Chart extends Group {
*/
activate(table: BaseTableAPI) {
this.active = true;
const { col, row } = this.parent;
// this.chart = new TestChart(this.attribute.spec);
// const ctx = this.attribute.canvas.getContext('2d');
// const { x1, y1, x2, y2 } = this.attribute.viewBox;
const { x1, y1, x2, y2 } = this.getViewBox();
//获取渲染区域的bound 考虑被表头遮住部分的情况
const tableBound = table.scenegraph.tableGroup.globalAABBBounds;
const bodyBound = new Bounds();
bodyBound.x1 = tableBound.x1 + table.getFrozenColsWidth();
bodyBound.x2 = tableBound.x2 - table.getRightFrozenColsWidth();
bodyBound.y1 = tableBound.y1 + table.getFrozenRowsHeight();
bodyBound.y2 = tableBound.y2 - table.getBottomFrozenRowsHeight();
const clipBound = bodyBound.intersect({
const tableBound = getTableBounds(col, row, table);
const clipBound = tableBound.intersect({
x1: x1 - table.scrollLeft,
x2: x2 - table.scrollLeft,
y1: y1 - table.scrollTop,
Expand Down Expand Up @@ -189,3 +185,37 @@ export class Chart extends Group {
};
}
}

function getTableBounds(col: number, row: number, table: BaseTableAPI) {
const { layoutMap } = table.internalProps;
const bodyBound = new Bounds();
const tableBound = table.scenegraph.tableGroup.globalAABBBounds;
bodyBound.x1 = tableBound.x1;
bodyBound.x2 = tableBound.x2;
bodyBound.y1 = tableBound.y1;
bodyBound.y2 = tableBound.y2;

if (!layoutMap.isFrozenColumn(col, row) && !layoutMap.isRightFrozenColumn(col, row)) {
// no frozen body
bodyBound.x1 = tableBound.x1 + table.getFrozenColsWidth();
bodyBound.x2 = tableBound.x2 - table.getRightFrozenColsWidth();
bodyBound.y1 = tableBound.y1 + table.getFrozenRowsHeight();
bodyBound.y2 = tableBound.y2 - table.getBottomFrozenRowsHeight();
} else if (layoutMap.isLeftBottomCorner(col, row) || layoutMap.isRightTopCorner(col, row)) {
// frozen cornor
} else if (layoutMap.isFrozenColumn(col, row)) {
// left frozen
bodyBound.y1 = tableBound.y1 + table.getFrozenRowsHeight();
bodyBound.y2 = tableBound.y2 - table.getBottomFrozenRowsHeight();
} else if (layoutMap.isRightFrozenColumn(col, row)) {
// right frozen
bodyBound.y1 = tableBound.y1 + table.getFrozenRowsHeight();
bodyBound.y2 = tableBound.y2 - table.getBottomFrozenRowsHeight();
} else if (layoutMap.isBottomFrozenRow(col, row)) {
// bottom frozen
bodyBound.x1 = tableBound.x1 + table.getFrozenColsWidth();
bodyBound.x2 = tableBound.x2 - table.getRightFrozenColsWidth();
}

return bodyBound;
}

0 comments on commit e6f20c1

Please sign in to comment.