fix(onlyRenderVisibleNodes): only render nodes that are inside the viewport

This commit is contained in:
moklick
2020-07-29 10:40:15 +02:00
parent 7c920d0a86
commit 16707eaa99
2 changed files with 10 additions and 5 deletions
+1 -3
View File
@@ -77,10 +77,8 @@ const NodeRenderer = ({ onlyRenderVisibleNodes = true, ...props }: NodeRendererP
const nodesDraggable = useStoreState((s) => s.nodesDraggable);
const nodesConnectable = useStoreState((s) => s.nodesConnectable);
const elementsSelectable = useStoreState((s) => s.elementsSelectable);
const [tX, tY, tScale] = transform;
const transformStyle = {
transform: `translate(${tX}px,${tY}px) scale(${tScale})`,
transform: `translate(${transform[0]}px,${transform[1]}px) scale(${transform[2]})`,
};
const renderNodes = onlyRenderVisibleNodes
+9 -2
View File
@@ -169,10 +169,17 @@ export const getNodesInside = (
const yOverlap = Math.max(0, Math.min(rBox.y2, nBox.y2) - Math.max(rBox.y, nBox.y));
const overlappingArea = xOverlap * yOverlap;
if (partially) {
return overlappingArea >= 0;
if (width === null || height === null) {
// at the beginnning all nodes have width & height === 0
return true;
}
if (partially) {
return overlappingArea > 0;
}
const area = width * height;
return overlappingArea >= area;
});
};