I would like to visualize a directed graph using the forced layout algorithm from d3. The nodes should displayed as their names inside a rectangle like this. My problem is to calculate the position outside the rectangle where the arrows should point to.
I think it should be done inside the tick() function. To avoid extreme effort like angle calculations i could use the Intercept theorem.
I dont know how to get the parameters for the edges which will be set using attributes and I couldnt find an example for this.
var force = d3.layout.force().nodes(dataset.nodes).links(dataset.edges)...
var edges = svg.selectAll("line").data(dataset.edges).enter().append("line")...
var nodes = svg.selectAll("text").data(dataset.nodes).enter().append("text")...
force.on("tick", function(){
// Why does the following function not work? How to implement this correctly?
edges.attr(function(d){
var x1 = d.source.x
var y1 = d.source.y
var x2 = d.target.x
var y2 = d.target.y
// ... calulate new source and targetcoordinates ... I can do this myself
return {
"x1": newSourceX,
"y1": newSourceY,
"x2": newTargetX,
"y2": newTargetY
}
});
});
How to implement the function for each edge to extract any source- and target-parameter and save the new positions?
Do you think this is the best performing solution?