IlludiumPu36
IlludiumPu36

Reputation: 4304

d3 tree - Adjust horizontal distance between first level of parent and child nodes

Is there a way to set the horizontal distance for the first level of parent and child nodes? At the moment, the distance betwenn those first level nodes to far, I would like to reduce this, but keep the distance between later levels the same as now.

// Normalize for fixed-depth.
            nodes.forEach( function ( d ) {
                d.y = d.depth * 250;
            } );

            nodes.forEach( function ( d ) {
                ( d.depth === 1 ) ? d.y = d.depth * 200: d.y = d.depth * 290;
            } );

Fiddle

Upvotes: 1

Views: 424

Answers (1)

Michael Rovinsky
Michael Rovinsky

Reputation: 7210

In your fiddle, modify the code in update function:

// Normalize for fixed-depth.
  nodes.forEach(function(d) {
    d.y = (d.depth === 0 ? 50 : d.depth * 200);
  });

Upvotes: 3

Related Questions