khan
khan

Reputation: 137

Nodes with links are closer than nodes without links in force layout d3.js

Nodes with links are closer to each other than nodes without links,how do i keep distance between them same.Here is sample code:

scope.force = d3.layout.force()
                        .gravity(.2)
                        .distance(100)
                        .charge(function(){
                            if(nodes.length > 20){
                                return -700;
                            }
                            return -2000;
                        })
                        .size([700, 700]); 

Upvotes: 0

Views: 176

Answers (1)

Bragolgirith
Bragolgirith

Reputation: 2238

Maybe what you need is linkDistance? You can set it to the same value as your distance() value (100).

scope.force = d3.layout.force()
                        .gravity(.2)
                        .distance(100)
                        .linkDistance(100)
                        .charge(function(){
                            if(nodes.length > 20){
                                return -700;
                            }
                            return -2000;
                        })
                        .size([700, 700]); 

Upvotes: 1

Related Questions