mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Minimise work done to calculate node label widths
Currently, everytime the tab is switched, we recalculate the width of every node. There's no need to do that as the width will not have changed - unless it has changed, but then the dirty/changed flag will be set on that one node and it will get handled. Also avoid endless added/removing an element to calculate the dimenstions - keep it on the dom (keyed by className) and positioned well away from the visible space.
This commit is contained in:
parent
c4f5df0cd0
commit
97f11e38cd
@ -1758,11 +1758,18 @@ RED.view = (function() {
|
||||
return calculateTextDimensions(str,className,offset,0)[0];
|
||||
}
|
||||
|
||||
var textDimensionPlaceholder = {};
|
||||
function calculateTextDimensions(str,className,offsetW,offsetH) {
|
||||
var sp = $('<span>',{class: className,style: "position: absolute; top: -1000px"}).text(str||"").appendTo("#red-ui-editor");
|
||||
var w = sp.width();
|
||||
var h = sp.height();
|
||||
sp.remove();
|
||||
if (!textDimensionPlaceholder[className]) {
|
||||
textDimensionPlaceholder[className] = document.createElement("span");
|
||||
textDimensionPlaceholder[className].className = className;
|
||||
textDimensionPlaceholder[className].style.position = "absolute";
|
||||
textDimensionPlaceholder[className].style.top = "-1000px";
|
||||
document.getElementById("red-ui-editor").appendChild(textDimensionPlaceholder[className]);
|
||||
}
|
||||
textDimensionPlaceholder[className].textContent = (str||"");
|
||||
var w = textDimensionPlaceholder[className].offsetWidth;
|
||||
var h = textDimensionPlaceholder[className].offsetHeight;
|
||||
return [offsetW+w,offsetH+h];
|
||||
}
|
||||
|
||||
@ -2564,10 +2571,12 @@ RED.view = (function() {
|
||||
var hideLabel = d.hasOwnProperty('l')?!d.l : isLink;
|
||||
node.attr("id",d.id);
|
||||
var l = RED.utils.getNodeLabel(d);
|
||||
if (hideLabel) {
|
||||
d.w = node_height;
|
||||
} else {
|
||||
d.w = Math.max(node_width,20*(Math.ceil((calculateTextWidth(l, "red-ui-flow-node-label", 50)+(d._def.inputs>0?7:0))/20)) );
|
||||
if (d.w === undefined) {
|
||||
if (hideLabel) {
|
||||
d.w = node_height;
|
||||
} else {
|
||||
d.w = Math.max(node_width,20*(Math.ceil((calculateTextWidth(l, "red-ui-flow-node-label", 50)+(d._def.inputs>0?7:0))/20)) );
|
||||
}
|
||||
}
|
||||
d.h = Math.max(node_height,(d.outputs||0) * 15);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user