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

Better vertical path routing

This commit is contained in:
Nick O'Leary 2019-11-25 11:15:48 +00:00
parent fb1918d839
commit e2b7377ab7
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -596,12 +596,101 @@ RED.view = (function() {
}
}
function generateLinkPathV(origX,origY, destX, destY, sc) {
var dy = destY-origY;
var dx = destX-origX;
var delta = Math.sqrt(dy*dy+dx*dx);
var scale = lineCurveScale*2;
var fullScale = scale;
if (dy*sc > 0) {
if (delta < node_height) {
scale = scale-scale*((node_height-delta)/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) {
if (delta < (1.5*node_width)) {
scale = fullScale-fullScale*(((1.5*node_width)-delta)/(1.5*node_width));
}
return "M "+origX+" "+origY+
" C "+origX+" "+(origY+sc*node_height*scale)+" "+
destX+" "+(destY-sc*scale*node_height)+" "+
destX+" "+destY
// +drawCross(origX,(origY+sc*(node_height*scale)))
// +drawCross(destX,(destY-sc*scale*node_height))
} else {
var scx = dx>0?1:-1;
var midX = Math.floor(destX-dx/2);
var midY = Math.floor(destY-dy/2);
//
if (Math.abs(dx) < node_width) {
midX = destX - 1.3*scx*node_width;
}
var cp_width = node_width/2;
var x1 = (destX + midX)/2
var topY = origY + 2*sc*node_height*scale;
var topX = dx>0?Math.min(x1 - dx/2 , origX+cp_width):Math.max(x1 - dx/2 , origX-cp_width);
var bottomY = destY - 2*sc*node_height*scale;
var bottomX = dx>0?Math.max(x1, destX-cp_width):Math.min(x1, destX+cp_width);
var y1 = (origY+topY)/2;
var cp = [
// Orig -> Top
[origX,y1],
[dx>0?Math.max(origX, topX-cp_width):Math.min(origX, topX+cp_width),topY],
// Top -> Mid
// [Mirror previous cp]
[dx>0?Math.min(midX, topX+cp_width):Math.max(midX, topX-cp_width),y1],
// Mid -> Bottom
// [Mirror previous cp]
[dx>0?Math.max(midX, bottomX-cp_width):Math.min(midX, bottomX+cp_width), bottomY],
// Bottom -> Dest
// [Mirror previous cp]
[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+
" C "+
cp[0][0]+" "+cp[0][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
// +drawCross(cp[0][0],cp[0][1])
// +drawCross(cp[1][0],cp[1][1])
// +drawCross(cp[2][0],cp[2][1])
// +drawCross(cp[3][0],cp[3][1])
// +drawCross(cp[4][0],cp[4][1])
}
}
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 ";
// 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) {
@ -613,31 +702,6 @@ RED.view = (function() {
return " M "+x1+","+y1+" L "+x2+","+y2+" "
}
function generateLinkPathV(origX,origY, destX, destY, sc) {
var dy = destY-origY;
var dx = destX-origX;
var delta = Math.sqrt(dy*dy+dx*dx);
var fullScale = lineCurveScale*4;
var scale = fullScale;
var scaleX = 0;
if (dy*sc <= 0) {
var r = 1-Math.max(0,((2*node_height) - Math.abs(dy*sc))/(2*node_height));
scale = fullScale+(fullScale*r);
} else if (delta < (1.5*node_width)) {
scale = fullScale-fullScale*(((1.5*node_width)-delta)/(1.5*node_width));
}
var cp = [
[origX, origY+sc*scale*node_height],
[destX, destY-sc*scale*node_height]
];
return "M "+origX+" "+origY+
" C "+cp[0][0]+" "+cp[0][1]+" "+
cp[1][0]+" "+cp[1][1]+" "+
destX+" "+destY
}
function addNode(type,x,y) {
var m = /^subflow:(.+)$/.exec(type);