Skip to content

Commit

Permalink
Only recalculate group label offsets when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
knolleary committed Sep 3, 2020
1 parent 716dc78 commit 02c20e9
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions packages/node_modules/@node-red/editor-client/src/js/ui/view.js
Expand Up @@ -4437,6 +4437,7 @@ RED.view = (function() {
}
if (d.dirty || dirtyGroups[d.id]) {
var g = d3.select(this);
var recalculateLabelOffsets = false;
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
Expand Down Expand Up @@ -4465,6 +4466,7 @@ RED.view = (function() {
d.y = minY;
d.w = maxX - minX;
d.h = maxY - minY;
recalculateLabelOffsets = true;
// if set explicitly to false, this group has just been
// imported so needed this initial resize calculation.
// Now that's done, delete the flag so the normal
Expand All @@ -4478,28 +4480,31 @@ RED.view = (function() {
} else {
d.w = 40;
d.h = 40;
recalculateLabelOffsets = true;
}
if (!d.minWidth) {
if (d.style.label && d.name) {
var labelParts = getLabelParts(d.name||"","red-ui-flow-group-label");
d.minWidth = labelParts.width + 8;
d.labels = labelParts.lines;
} else {
d.minWidth = 40;
d.labels = [];
}
}
d.w = Math.max(d.minWidth,d.w);
if (d.style.label && d.labels.length > 0) {
var labelPos = d.style["label-position"] || "nw";
var h = (d.labels.length-1) * 16;
if (labelPos[0] === "s") {
h += 8;
if (recalculateLabelOffsets) {
if (!d.minWidth) {
if (d.style.label && d.name) {
var labelParts = getLabelParts(d.name||"","red-ui-flow-group-label");
d.minWidth = labelParts.width + 8;
d.labels = labelParts.lines;
} else {
d.minWidth = 40;
d.labels = [];
}
}
d.h += h;
if (labelPos[0] === "n") {
if (d.nodes.length > 0) {
d.y -= h;
d.w = Math.max(d.minWidth,d.w);
if (d.style.label && d.labels.length > 0) {
var labelPos = d.style["label-position"] || "nw";
var h = (d.labels.length-1) * 16;
if (labelPos[0] === "s") {
h += 8;
}
d.h += h;
if (labelPos[0] === "n") {
if (d.nodes.length > 0) {
d.y -= h;
}
}
}
}
Expand Down

0 comments on commit 02c20e9

Please sign in to comment.