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

Minimise link redrawing

This commit is contained in:
Nick O'Leary 2015-03-12 13:26:31 +00:00
parent eacf41a4f6
commit f26cadab7f

View File

@ -581,9 +581,8 @@ RED.view = (function() {
updateActiveNodes();
setDirty(true);
}
redraw();
// clear mouse event vars
resetMouseVars();
redraw();
}
$('#btn-zoom-out').click(function() {zoomOut();});
@ -1127,8 +1126,10 @@ RED.view = (function() {
vis.attr("transform","scale("+scaleFactor+")");
outer.attr("width", space_width*scaleFactor).attr("height", space_height*scaleFactor);
if (mouse_mode != RED.state.JOINING) {
// Don't bother redrawing nodes if we're drawing links
if (mouse_mode != RED.state.JOINING) {
var dirtyNodes = {};
if (activeSubflow) {
var subflowOutputs = vis.selectAll(".subflowoutput").data(activeSubflow.out,function(d,i){ return d.id;});
@ -1223,6 +1224,7 @@ RED.view = (function() {
output.selectAll(".subflowport").classed("node_selected",function(d) { return d.selected; })
output.selectAll(".port_index").text(function(d){ return d.i+1});
output.attr("transform", function(d) { return "translate(" + (d.x-d.w/2) + "," + (d.y-d.h/2) + ")"; });
dirtyNodes[d.id] = d;
d.dirty = false;
}
});
@ -1231,6 +1233,7 @@ RED.view = (function() {
var input = d3.select(this);
input.selectAll(".subflowport").classed("node_selected",function(d) { return d.selected; })
input.attr("transform", function(d) { return "translate(" + (d.x-d.w/2) + "," + (d.y-d.h/2) + ")"; });
dirtyNodes[d.id] = d;
d.dirty = false;
}
});
@ -1431,6 +1434,7 @@ RED.view = (function() {
node.each(function(d,i) {
if (d.dirty) {
dirtyNodes[d.id] = d;
//if (d.x < -50) deleteSelection(); // Delete nodes if dragged back to palette
if (d.resize) {
var l = d._def.label;
@ -1596,19 +1600,17 @@ RED.view = (function() {
d.dirty = false;
}
});
}
var link = vis.selectAll(".link").data(
activeLinks,
function(d) {
return d.source.id+":"+d.sourcePort+":"+d.target.id+":"+d.target.i;
}
);
var linkEnter = link.enter().insert("g",".node").attr("class","link");
linkEnter.each(function(d,i) {
var l = d3.select(this);
d.added = true;
l.append("svg:path").attr("class","link_background link_path")
.on("mousedown",function(d) {
mousedown_link = d;
@ -1634,9 +1636,11 @@ RED.view = (function() {
});
link.exit().remove();
var links = vis.selectAll(".link_path")
links.attr("d",function(d){
var links = vis.selectAll(".link_path");
links.each(function(d) {
var link = d3.select(this);
if (d.added || d===selected_link || d.selected || dirtyNodes[d.source.id] || dirtyNodes[d.target.id]) {
link.attr("d",function(d){
var numOutputs = d.source.outputs || 1;
var sourcePort = d.sourcePort || 0;
var y = -((numOutputs-1)/2)*13 +13*sourcePort;
@ -1666,10 +1670,16 @@ RED.view = (function() {
" C "+(d.source.x+d.source.w/2+scale*node_width)+" "+(d.source.y+y+scaleY*node_height)+" "+
(d.target.x-d.target.w/2-scale*node_width)+" "+(d.target.y-scaleY*node_height)+" "+
(d.target.x-d.target.w/2)+" "+d.target.y;
});
}
})
link.classed("link_selected", function(d) { return d === selected_link || d.selected; });
link.classed("link_selected", function(d) {
delete d.added;
return d === selected_link || d.selected;
});
link.classed("link_unknown",function(d) { return d.target.type == "unknown" || d.source.type == "unknown"});
}
if (d3.event) {
d3.event.preventDefault();