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

Only recalculate group label offsets when needed

This commit is contained in:
Nick O'Leary 2020-09-03 13:49:42 +01:00
parent 716dc781e4
commit 02c20e97b7
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -4437,6 +4437,7 @@ 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);
var recalculateLabelOffsets = false;
if (d.nodes.length > 0) { if (d.nodes.length > 0) {
// If the group was just moved, all of its contents was // If the group was just moved, all of its contents was
// also moved - so no need to recalculate its bounding box // also moved - so no need to recalculate its bounding box
@ -4465,6 +4466,7 @@ 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;
recalculateLabelOffsets = true;
// if set explicitly to false, this group has just been // if set explicitly to false, this group has just been
// imported so needed this initial resize calculation. // imported so needed this initial resize calculation.
// Now that's done, delete the flag so the normal // Now that's done, delete the flag so the normal
@ -4478,28 +4480,31 @@ RED.view = (function() {
} else { } else {
d.w = 40; d.w = 40;
d.h = 40; d.h = 40;
recalculateLabelOffsets = true;
} }
if (!d.minWidth) { if (recalculateLabelOffsets) {
if (d.style.label && d.name) { if (!d.minWidth) {
var labelParts = getLabelParts(d.name||"","red-ui-flow-group-label"); if (d.style.label && d.name) {
d.minWidth = labelParts.width + 8; var labelParts = getLabelParts(d.name||"","red-ui-flow-group-label");
d.labels = labelParts.lines; d.minWidth = labelParts.width + 8;
} else { d.labels = labelParts.lines;
d.minWidth = 40; } else {
d.labels = []; d.minWidth = 40;
d.labels = [];
}
} }
} d.w = Math.max(d.minWidth,d.w);
d.w = Math.max(d.minWidth,d.w); if (d.style.label && d.labels.length > 0) {
if (d.style.label && d.labels.length > 0) { var labelPos = d.style["label-position"] || "nw";
var labelPos = d.style["label-position"] || "nw"; var h = (d.labels.length-1) * 16;
var h = (d.labels.length-1) * 16; if (labelPos[0] === "s") {
if (labelPos[0] === "s") { h += 8;
h += 8; }
} d.h += h;
d.h += h; if (labelPos[0] === "n") {
if (labelPos[0] === "n") { if (d.nodes.length > 0) {
if (d.nodes.length > 0) { d.y -= h;
d.y -= h; }
} }
} }
} }