1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Improve performance of moving groups

This commit is contained in:
Nick O'Leary 2020-07-31 23:22:33 +01:00
parent 16c26d8098
commit 758f44e25f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -1339,6 +1339,7 @@ RED.view = (function() {
node.n.y = mousePos[1]+node.dy; node.n.y = mousePos[1]+node.dy;
node.n.dirty = true; node.n.dirty = true;
if (node.n.type === "group") { if (node.n.type === "group") {
node.n.groupMoved = true;
RED.group.markDirty(node.n); RED.group.markDirty(node.n);
minX = Math.min(node.n.x-5,minX); minX = Math.min(node.n.x-5,minX);
minY = Math.min(node.n.y-5,minY); minY = Math.min(node.n.y-5,minY);
@ -1711,6 +1712,7 @@ RED.view = (function() {
if (mouse_mode === RED.state.SELECTING_NODE && selectNodesOptions.single) { if (mouse_mode === RED.state.SELECTING_NODE && selectNodesOptions.single) {
return; return;
} }
clearSelection();
exitActiveGroup(); exitActiveGroup();
activeGroups.forEach(function(g) { activeGroups.forEach(function(g) {
if (!g.g) { if (!g.g) {
@ -2912,7 +2914,7 @@ RED.view = (function() {
} else { } else {
dblClickPrimed = false; dblClickPrimed = false;
} }
selectGroup(nodeGroup, !activeGroup); selectGroup(nodeGroup, !activeGroup, !!groupNodeSelectPrimed);
if (activeGroup) { if (activeGroup) {
mousedown_node.selected = true; mousedown_node.selected = true;
moving_set.push({n:mousedown_node}); moving_set.push({n:mousedown_node});
@ -4301,7 +4303,9 @@ RED.view = (function() {
}) })
} }
group[0].reverse(); group[0].reverse();
var groupOpCount=0;
group.each(function(d,i) { group.each(function(d,i) {
groupOpCount++
if (d.resize) { if (d.resize) {
d.minWidth = 0; d.minWidth = 0;
delete d.resize; delete d.resize;
@ -4309,29 +4313,36 @@ RED.view = (function() {
if (d.dirty || dirtyGroups[d.id]) { if (d.dirty || dirtyGroups[d.id]) {
var g = d3.select(this); var g = d3.select(this);
if (d.nodes.length > 0) { if (d.nodes.length > 0) {
var minX = Number.POSITIVE_INFINITY; // If the group was just moved, all of its contents was
var minY = Number.POSITIVE_INFINITY; // also moved - so no need to recalculate its bounding box
var maxX = 0; if (!d.groupMoved) {
var maxY = 0; var minX = Number.POSITIVE_INFINITY;
var margin = 26; var minY = Number.POSITIVE_INFINITY;
d.nodes.forEach(function(n) { var maxX = 0;
if (n.type !== "group") { var maxY = 0;
minX = Math.min(minX,n.x-n.w/2-margin-((n._def.button && n._def.align!=="right")?20:0)); var margin = 26;
minY = Math.min(minY,n.y-n.h/2-margin); d.nodes.forEach(function(n) {
maxX = Math.max(maxX,n.x+n.w/2+margin+((n._def.button && n._def.align=="right")?20:0)); groupOpCount++
maxY = Math.max(maxY,n.y+n.h/2+margin); if (n.type !== "group") {
} else { minX = Math.min(minX,n.x-n.w/2-margin-((n._def.button && n._def.align!=="right")?20:0));
minX = Math.min(minX,n.x-margin) minY = Math.min(minY,n.y-n.h/2-margin);
minY = Math.min(minY,n.y-margin) maxX = Math.max(maxX,n.x+n.w/2+margin+((n._def.button && n._def.align=="right")?20:0));
maxX = Math.max(maxX,n.x+n.w+margin) maxY = Math.max(maxY,n.y+n.h/2+margin);
maxY = Math.max(maxY,n.y+n.h+margin) } else {
} minX = Math.min(minX,n.x-margin)
}); minY = Math.min(minY,n.y-margin)
maxX = Math.max(maxX,n.x+n.w+margin)
maxY = Math.max(maxY,n.y+n.h+margin)
}
});
d.x = minX; d.x = minX;
d.y = minY; d.y = minY;
d.w = maxX - minX; d.w = maxX - minX;
d.h = maxY - minY; d.h = maxY - minY;
} else {
delete d.groupMoved;
}
} else { } else {
d.w = 40; d.w = 40;
d.h = 40; d.h = 40;