Improved calculation of text angle and spacing
This commit is contained in:
parent
36c885871e
commit
00cbc7f64e
17
springyui.js
17
springyui.js
|
@ -168,7 +168,7 @@ jQuery.fn.springy = function(params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//change default to 10.0 to allow text fit between edges
|
//change default to 10.0 to allow text fit between edges
|
||||||
var spacing = 10.0; //was 6.0 before
|
var spacing = 12.0;
|
||||||
|
|
||||||
// Figure out how far off center the line should be drawn
|
// Figure out how far off center the line should be drawn
|
||||||
var offset = normal.multiply(-((total - 1) * spacing)/2.0 + (n * spacing));
|
var offset = normal.multiply(-((total - 1) * spacing)/2.0 + (n * spacing));
|
||||||
|
@ -235,11 +235,10 @@ jQuery.fn.springy = function(params) {
|
||||||
ctx.textAlign = "center";
|
ctx.textAlign = "center";
|
||||||
ctx.textBaseline = "top";
|
ctx.textBaseline = "top";
|
||||||
ctx.font = (edge.data.font !== undefined) ? edge.data.font : edgeFont;
|
ctx.font = (edge.data.font !== undefined) ? edge.data.font : edgeFont;
|
||||||
ctx.fillStyle = "#5BA6EC";
|
ctx.fillStyle = stroke;
|
||||||
var xText = (s1.x+s2.x)/2;
|
var textPos = s1.add(s2).divide(2).add(normal.multiply(-8));
|
||||||
var yText = (s1.y+s2.y)/2;
|
ctx.translate(textPos.x, textPos.y);
|
||||||
ctx.translate(xText, yText);
|
ctx.rotate(Math.atan2(s2.y - s1.y, s2.x - s1.x));
|
||||||
ctx.rotate(getTextAngle(s1.x,s1.y,s2.x,s2.y));
|
|
||||||
ctx.fillText(text, 0,-2);
|
ctx.fillText(text, 0,-2);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
@ -280,12 +279,6 @@ jQuery.fn.springy = function(params) {
|
||||||
|
|
||||||
renderer.start();
|
renderer.start();
|
||||||
|
|
||||||
// return angle of text in radian
|
|
||||||
function getTextAngle(x1, y1, x2, y2){
|
|
||||||
var tan = (y2-y1)/(x2-x1);
|
|
||||||
return Math.atan(tan);
|
|
||||||
}
|
|
||||||
|
|
||||||
// helpers for figuring out where to draw arrows
|
// helpers for figuring out where to draw arrows
|
||||||
function intersect_line_line(p1, p2, p3, p4) {
|
function intersect_line_line(p1, p2, p3, p4) {
|
||||||
var denom = ((p4.y - p3.y)*(p2.x - p1.x) - (p4.x - p3.x)*(p2.y - p1.y));
|
var denom = ((p4.y - p3.y)*(p2.x - p1.x) - (p4.x - p3.x)*(p2.y - p1.y));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user