mirror of
https://github.com/projectstorm/react-diagrams.git
synced 2025-08-14 16:51:29 +08:00
feat(link): improve rendering of vertical links
This commit is contained in:
@ -43,9 +43,12 @@ export class Toolkit {
|
||||
}
|
||||
|
||||
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},${
|
||||
lastPoint.y
|
||||
} ${lastPoint.x},${lastPoint.y}`;
|
||||
var isHorizontal = Math.abs(firstPoint.x - lastPoint.x) > Math.abs(firstPoint.y - lastPoint.y);
|
||||
var curvyX = isHorizontal ? curvy : 0;
|
||||
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[][]) {
|
||||
|
@ -305,10 +305,13 @@ export class DefaultLinkWidget extends BaseWidget<DefaultLinkProps, DefaultLinkS
|
||||
// See @link{#isSmartRoutingApplicable()}.
|
||||
if (paths.length === 0) {
|
||||
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
|
||||
//if the points are too close, just draw a straight line
|
||||
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;
|
||||
}
|
||||
|
||||
@ -317,7 +320,7 @@ export class DefaultLinkWidget extends BaseWidget<DefaultLinkProps, DefaultLinkS
|
||||
|
||||
//some defensive programming to make sure the smoothing is
|
||||
//always in the right direction
|
||||
if (pointLeft.x > pointRight.x) {
|
||||
if (pointLeft[xOrY] > pointRight[xOrY]) {
|
||||
pointLeft = points[1];
|
||||
pointRight = points[0];
|
||||
}
|
||||
|
Reference in New Issue
Block a user