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