canyon289
canyon289

Reputation: 3505

Link Length and Strength from attribute

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

Answers (1)

meetamit
meetamit

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

Related Questions