Permalink
Browse files

Merge pull request #12 from mikaa123/master

Edge label support in springyui
  • Loading branch information...
2 parents da536e5 + a48a749 commit 771dcd24fb0cd2d8162439f8643ee8e5321eae2b @dhotson committed Mar 24, 2012
Showing with 15 additions and 1 deletion.
  1. +1 −1 demo.html
  2. +14 −0 springyui.js
View
@@ -16,7 +16,7 @@
var james = graph.newNode({label: 'James'});
var bianca = graph.newNode({label: 'Bianca'});
-graph.newEdge(dennis, michael, {color: '#00A0B0'});
+graph.newEdge(dennis, michael, {color: '#00A0B0', label: 'Foo bar'});
graph.newEdge(michael, dennis, {color: '#6A4A3C'});
graph.newEdge(michael, jessica, {color: '#CC333F'});
graph.newEdge(jessica, barbara, {color: '#EB6841'});
View
@@ -218,6 +218,20 @@ jQuery.fn.springy = function(params) {
ctx.fill();
ctx.restore();
}
+
+ // label
+
+ if (typeof(edge.data.label) !== 'undefined') {
+ text = edge.data.label
+ ctx.save();
+ ctx.textAlign = "center";
+ ctx.textBaseline = "top";
+ ctx.font = "10px Helvetica, sans-serif";
+ ctx.fillStyle = "#5BA6EC";
+ ctx.fillText(text, (x1+x2)/2, (y1+y2)/2);
+ ctx.restore();
+ }
+
},
function drawNode(node, p) {
var s = toScreen(p);

0 comments on commit 771dcd2

Please sign in to comment.