Skip to content

Commit

Permalink
perf: merge bbox & set refresh flag recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Apr 13, 2023
1 parent 2beba3d commit 90e4f6c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/g-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-base",
"version": "0.5.14",
"version": "0.5.15",
"description": "A common util collection for antv projects",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
44 changes: 26 additions & 18 deletions packages/g-base/src/abstract/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,27 @@ abstract class Container extends Element implements IContainer {
let maxX = -Infinity;
let minY = Infinity;
let maxY = -Infinity;
const xArr = [];
const yArr = [];
// 将可见元素、图形以及不为空的图形分组筛选出来,用于包围盒合并
const children = this.getChildren().filter(
(child) =>
child.get('visible') && (!child.isGroup() || (child.isGroup() && (child as IGroup).getChildren().length > 0))
);
if (children.length > 0) {
each(children, (child: IElement) => {
const box = child.getBBox();
xArr.push(box.minX, box.maxX);
yArr.push(box.minY, box.maxY);
const { minX: childMinX, maxX: childMaxX, minY: childMinY, maxY: childMaxY } = child.getBBox();
if (childMinX < minX) {
minX = childMinX;
}
if (childMaxX > maxX) {
maxX = childMaxX;
}
if (childMinY < minY) {
minY = childMinY;
}
if (childMaxY > maxY) {
maxY = childMaxY;
}
});
minX = min(xArr);
maxX = max(xArr);
minY = min(yArr);
maxY = max(yArr);
} else {
minX = 0;
maxX = 0;
Expand All @@ -119,23 +123,27 @@ abstract class Container extends Element implements IContainer {
let maxX = -Infinity;
let minY = Infinity;
let maxY = -Infinity;
const xArr = [];
const yArr = [];
// 将可见元素、图形以及不为空的图形分组筛选出来,用于包围盒合并
const children = this.getChildren().filter(
(child) =>
child.get('visible') && (!child.isGroup() || (child.isGroup() && (child as IGroup).getChildren().length > 0))
);
if (children.length > 0) {
each(children, (child: IElement) => {
const box = child.getCanvasBBox();
xArr.push(box.minX, box.maxX);
yArr.push(box.minY, box.maxY);
const { minX: childMinX, maxX: childMaxX, minY: childMinY, maxY: childMaxY } = child.getCanvasBBox();
if (childMinX < minX) {
minX = childMinX;
}
if (childMaxX > maxX) {
maxX = childMaxX;
}
if (childMinY < minY) {
minY = childMinY;
}
if (childMaxY > maxY) {
maxY = childMaxY;
}
});
minX = min(xArr);
maxX = max(xArr);
minY = min(yArr);
maxY = max(yArr);
} else {
minX = 0;
maxX = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "0.5.13",
"version": "0.5.14",
"description": "A canvas library which providing 2d",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/g-canvas/src/util/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export function clearChanged(elements: IElement[]) {
function setChildrenRefresh(children: IElement[], region: Region) {
for (let i = 0; i < children.length; i++) {
const child = children[i] as IElement;
if (!child.cfg.visible) {
continue;
}
// let refresh = true;
// 获取缓存的 bbox,如果这个 bbox 还存在则说明父元素不是矩阵发生了改变
// const bbox = child.cfg.canvasBBox;
Expand Down

0 comments on commit 90e4f6c

Please sign in to comment.