Adding edge label support in springyui

This commit is contained in:
Michael Sokol 2012-03-23 09:37:34 +01:00
parent da536e5a0f
commit bbfcf99b72
2 changed files with 10 additions and 1 deletions

View File

@ -16,7 +16,7 @@ var monty = graph.newNode({label: 'Monty'});
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 File

@ -218,6 +218,15 @@ jQuery.fn.springy = function(params) {
ctx.fill();
ctx.restore();
}
// label
ctx.textAlign = "center";
ctx.textBaseline = "top";
ctx.font = "10px Helvetica, sans-serif";
ctx.fillStyle = "#5BA6EC";
var text = typeof(edge.data.label) !== 'undefined' ? edge.data.label : '';
ctx.fillText(text, (x1+x2)/2, (y1+y2)/2);
ctx.restore();
},
function drawNode(node, p) {
var s = toScreen(p);