How do I add labels to edges in arbor.js It is a graph visualization library.
Suppose A and B are nodes and E is the edge One crude way would be insert a "text node" T and join A-T and T-B
But i don't want to this, is there any other way?
Here's the sample code
var theUI = {
nodes:{A:{color:"red", shape:"dot", alpha:1},
B:{color:"#b2b19d", shape:"dot", alpha:1},
C:{color:"#b2b19d", shape:"dot", alpha:1},
D:{color:"#b2b19d", shape:"dot", alpha:1},
},
edges:{
A:{
B:{length:.8},
C:{length:.8},
D:{length:.8}
}
}
}
var sys = arbor.ParticleSystem()
sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015})
sys.renderer = Renderer("#sitemap")
sys.graft(theUI)
In this, A is connected to B, C and D. How to supply label to edges?
arbor.js allows you to write a code to render the whole graph. You can do whatever you want in render method including drawing edges titles which you can store in a separate map.
Just override method render in Renderer this way:
This code expected data property of each edge to be filled while initialization.
I create all nodes and edges manually using my custom map and methods addNode/addEdge, bu I suppose you can change a little your code to initialize edges with custom data this way:
P.S.: take a look at this example, I learned a lot from it.
edge.data
is{length:.8, data:{name:"A->B"}}
so replace the last line of the methodparticleSystem.eachEdge()
with the following codewhich worked for me.