js/directives.js
// Resolves collisions between d and all other circles.
Resolves collisions between d and all other circles.
Resolves collisions between d and all other circles .
function collide(alpha) {
                            var quadtree = d3.geom.quadtree(nodes);
                            return function(d) {
                                var r = d.radius + maxRadius + Math.max(padding, clusterPadding),
                                    nx1 = d.x - r,
                                    nx2 = d.x + r,
                                    ny1 = d.y - r,
                                    ny2 = d.y + r;
                                quadtree.visit(function(quad, x1, y1, x2, y2) {
                                    if (quad.point && (quad.point !== d)) {
                                        var x = d.x - quad.point.x,
                                            y = d.y - quad.point.y,
                                            l = Math.sqrt(x * x + y * y),
                                            r = d.radius + quad.point.radius + (d.cluster === quad.point.cluster ? padding : clusterPadding);
                                        if (l < r) {
                                            l = (l - r) / l * alpha;
                                            d.x -= x *= l;
                                            d.y -= y *= l;
                                            quad.point.x += x;
                                            quad.point.y += y;
                                        }
                                    }
                                    return x1 > nx2 || x2 < nx1 || y1 > ny2 || y2 < ny1;
                                });
                            };
                        }
function collide ( alpha ) { var quadtree = d3 . geom . quadtree ( nodes ) ; return function ( d ) { var r = d . radius + maxRadius + Math . max ( padding , clusterPadding ) , nx1 = d . x - r , nx2 = d . x + r , ny1 = d . y - r , ny2 = d . y + r ; quadtree . visit ( function ( quad , x1 , y1 , x2 , y2 ) { if ( quad . point && ( quad . point !== d ) ) { var x = d . x - quad . point . x , y = d . y - quad . point . y , l = Math . sqrt ( x * x + y * y ) , r = d . radius + quad . point . radius + ( d . cluster === quad . point . cluster ? padding : clusterPadding ) ; if ( l < r ) { l = ( l - r ) / l * alpha ; d . x -= x *= l ; d . y -= y *= l ; quad . point . x += x ; quad . point . y += y ; } } return x1 > nx2 || x2 < nx1 || y1 > ny2 || y2 < ny1 ; } ) ; } ; }
Resolves collisions between d and all other circles.
Resolves collisions between d and all other circles .