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,12 +4313,16 @@ 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) {
// 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 minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY; var minY = Number.POSITIVE_INFINITY;
var maxX = 0; var maxX = 0;
var maxY = 0; var maxY = 0;
var margin = 26; var margin = 26;
d.nodes.forEach(function(n) { d.nodes.forEach(function(n) {
groupOpCount++
if (n.type !== "group") { if (n.type !== "group") {
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-n.w/2-margin-((n._def.button && n._def.align!=="right")?20:0));
minY = Math.min(minY,n.y-n.h/2-margin); minY = Math.min(minY,n.y-n.h/2-margin);
@ -4332,6 +4340,9 @@ RED.view = (function() {
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;