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

Simplify vertical wire path

This commit is contained in:
Nick O'Leary 2019-11-22 15:40:59 +00:00
parent 61f42f9efa
commit 8e8cac60b0
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -596,74 +596,46 @@ RED.view = (function() {
} }
} }
function drawCross(x,y,i) {
var res = " M "+(x-4)+" "+y+" h8 M "+x+" "+(y-4)+" v8 ";
res += " M "+(x-8)+" "+(y-8)+" h2 ";
if (i>0) res += " M "+(x+8)+" "+(y-8)+" h2 ";
if (i>1) res += " M "+(x+8)+" "+(y+8)+" h2 ";
if (i>2) res += " M "+(x-8)+" "+(y+8)+" h2 ";
return res;
}
function drawCircle(x,y,w) {
return " M "+x+" "+y+" m -"+w+" 0 "+
"a "+w+","+w+" 0 1,0 "+(2*w)+",0 "+
"a "+w+","+w+" 0 1,0 -"+(2*w)+",0 "
}
function drawLine(x1,y1,x2,y2) {
return " M "+x1+","+y1+" L "+x2+","+y2+" "
}
function generateLinkPathV(origX,origY, destX, destY, sc) { function generateLinkPathV(origX,origY, destX, destY, sc) {
var dy = destY-origY; var dy = destY-origY;
var dx = destX-origX; var dx = destX-origX;
var delta = Math.sqrt(dy*dy+dx*dx); var delta = Math.sqrt(dy*dy+dx*dx);
var scale = lineCurveScale; var fullScale = lineCurveScale*4;
var scale = fullScale;
var scaleX = 0; var scaleX = 0;
if (dy*sc > 0) { if (dy*sc <= 0) {
if (delta < node_height) { var r = 1-Math.max(0,((2*node_height) - Math.abs(dy*sc))/(2*node_height));
scale = 0.75-0.75*((node_height-delta)/node_height); scale = fullScale+(2*fullScale*r);
// scale += 2*(Math.min(5*node_height,Math.abs(dx))/(5*node_height));
// if (Math.abs(dy) < 3*node_height) {
// scaleY = ((dy>0)?0.5:-0.5)*(((3*node_height)-Math.abs(dy))/(3*node_height))*(Math.min(node_height,Math.abs(dx))/(node_height)) ;
// }
}
} else {
scale = 0.4-0.2*(Math.max(0,(node_height-Math.min(Math.abs(dx),Math.abs(dy)))/node_height));
}
if (dy*sc > 0) {
return "M "+origX+" "+origY+
" C "+(origX+(node_width*scaleX))+" "+(origY+sc*scale*node_height)+" "+
(destX-(node_width*scaleX))+" "+(destY-sc*scale*node_height)+" "+
destX+" "+destY
} else {
var midX = Math.floor(destX-dx/2); } else if (delta < (1.5*node_width)) {
var midY = Math.floor(destY-dy/2); scale = fullScale-fullScale*(((1.5*node_width)-delta)/(1.5*node_width));
//
if (dx === 0) {
midX = destX + node_width;
} }
var cp_width = node_width/2;
var x1 = (destX + midX)/2;
var topX = dx>0? Math.min(x1 - dx/2 , origX+cp_width) : Math.max(x1 - dx/2 , origX-cp_width);
var topY = origY + sc*node_height*scale;
var bottomX = dx>0?Math.max(x1, destX-cp_width):Math.min(x1, destX+cp_width);
var bottomY = destY - sc*node_height*scale;
var y1 = (origY+topY)/2;
var scx = dx>0?1:-1;
var cp = [ var cp = [
[origX,y1], [origX, origY+sc*scale*node_height],
[dx>0 ? Math.max(origX, topX-cp_width) : Math.min(origX, topX+cp_width), topY], [destX, destY-sc*scale*node_height]
[dx>0 ? Math.max(midX, topX-cp_width) : Math.min(midX, topX-cp_width), y1],
[dx>0 ? Math.max(midX, bottomX-cp_width): Math.min(midX, bottomX+cp_width), bottomY],
[destX,(destY+bottomY)/2]
]; ];
if (cp[2][0] === topX+scx*cp_width) {
if (Math.abs(dx) < cp_width*10) {
cp[1][0] = topX-scx*cp_width/2;
cp[3][0] = bottomX-scx*cp_width/2;
}
cp[2][1] = topY;
}
return "M "+origX+" "+origY+ return "M "+origX+" "+origY+
" C "+ " C "+cp[0][0]+" "+cp[0][1]+" "+
cp[0][0]+" "+cp[0][1]+" "+
cp[1][0]+" "+cp[1][1]+" "+ cp[1][0]+" "+cp[1][1]+" "+
topX+" "+topY+
" S "+
cp[2][0]+" "+cp[2][1]+" "+
midX+" "+midY+
" S "+
cp[3][0]+" "+cp[3][1]+" "+
bottomX+" "+bottomY+
" S "+
cp[4][0]+" "+cp[4][1]+" "+
destX+" "+destY destX+" "+destY
} }
}
function addNode(type,x,y) { function addNode(type,x,y) {