Created
November 29, 2012 19:23
-
-
Save tluyben/4171243 to your computer and use it in GitHub Desktop.
Working Draw2d touch Bezier curve route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draw2d.layout.connection.NewBezierConnectionRouter = draw2d.layout.connection.ManhattanConnectionRouter.extend({ | |
NAME : "draw2d.layout.connection.NewBezierConnectionRouter", | |
init : function() | |
{ | |
this.cheapRouter = null; | |
this.iteration = 5; | |
}, | |
route : function(conn) | |
{ | |
var start = conn.getStartPoint(); | |
var fromDir = this.getStartDirection(conn); | |
var end = conn.getEndPoint(); | |
var toDir = this.getEndDirection(conn); | |
var x1 = start.x; | |
var y1 = start.y; | |
var x4 = end.x; | |
var y4 = end.y; | |
var dx = Math.max(Math.abs(x1 - x4) / 2, 10); | |
var dy = Math.max(Math.abs(y1 - y4) / 2, 10); | |
var x2 = [x1, x1 + dx, x1, x1 - dx][fromDir].toFixed(3), | |
y2 = [y1 - dy, y1, y1 + dy, y1 ][fromDir].toFixed(3), | |
x3 = [x4, x4 + dx, x4, x4 - dx][toDir].toFixed(3), | |
y3 = [y4 - dy, y4 , y4 + dy, y4 ][toDir].toFixed(3); | |
var path = ["M", x1.toFixed(3), y1.toFixed(3), "C", x2, y2, x3, y3, x4.toFixed(3), y4.toFixed(3)].join(","); | |
conn.svgPathString = path; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment