feat(link): improve rendering of vertical links

This commit is contained in:
Stephan Meijer
2018-02-28 10:15:07 +01:00
parent eb6fac30e0
commit fce1e0c7fe
2 changed files with 11 additions and 5 deletions

View File

@ -43,9 +43,12 @@ export class Toolkit {
} }
public static generateCurvePath(firstPoint: PointModel, lastPoint: PointModel, curvy: number = 0): string { public static generateCurvePath(firstPoint: PointModel, lastPoint: PointModel, curvy: number = 0): string {
return `M${firstPoint.x},${firstPoint.y} C ${firstPoint.x + curvy},${firstPoint.y} ${lastPoint.x + -curvy},${ var isHorizontal = Math.abs(firstPoint.x - lastPoint.x) > Math.abs(firstPoint.y - lastPoint.y);
lastPoint.y var curvyX = isHorizontal ? curvy : 0;
} ${lastPoint.x},${lastPoint.y}`; var curvyY = isHorizontal ? 0 : curvy;
return `M${firstPoint.x},${firstPoint.y} C ${firstPoint.x + curvyX},${firstPoint.y + curvyY}
${lastPoint.x - curvyX},${lastPoint.y - curvyY} ${lastPoint.x},${lastPoint.y}`;
} }
public static generateDynamicPath(pathCoords: number[][]) { public static generateDynamicPath(pathCoords: number[][]) {

View File

@ -305,10 +305,13 @@ export class DefaultLinkWidget extends BaseWidget<DefaultLinkProps, DefaultLinkS
// See @link{#isSmartRoutingApplicable()}. // See @link{#isSmartRoutingApplicable()}.
if (paths.length === 0) { if (paths.length === 0) {
if (points.length === 2) { if (points.length === 2) {
var isHorizontal = Math.abs(points[0].x - points[1].x) > Math.abs(points[0].y - points[1].y);
var xOrY = isHorizontal ? "x" : "y";
//draw the smoothing //draw the smoothing
//if the points are too close, just draw a straight line //if the points are too close, just draw a straight line
var margin = 50; var margin = 50;
if (Math.abs(points[0].x - points[1].x) < 50) { if (Math.abs(points[0][xOrY] - points[1][xOrY]) < 50) {
margin = 5; margin = 5;
} }
@ -317,7 +320,7 @@ export class DefaultLinkWidget extends BaseWidget<DefaultLinkProps, DefaultLinkS
//some defensive programming to make sure the smoothing is //some defensive programming to make sure the smoothing is
//always in the right direction //always in the right direction
if (pointLeft.x > pointRight.x) { if (pointLeft[xOrY] > pointRight[xOrY]) {
pointLeft = points[1]; pointLeft = points[1];
pointRight = points[0]; pointRight = points[0];
} }