Reputation: 3505
It is possible to have a different link strength or length attribute for each link in a force based layout?
Below is an example dataset where the length and strength of each link would be defined as an attribute
var dataset = {
nodes: [
{ name: "Adam" },
{ name: "Iris" },
{ name: "Jerry" }
],
edges: [
{ source: 0, target: 1, strength : .1, length: 50 },
{ source: 0, target: 2, strength: 1, length: 100 },
Upvotes: 1
Views: 66
Reputation: 25157
Yes, force.linkStrength
accepts a function. Likewise for linkDistance. You can even see how it's implemented.
d3.layout.force()
...
.links(dataset.edges)
.linkStrength( function(edge, i) { return edge.strength; } )
Upvotes: 1