javascript - D3.js packed circle layout - how to adjust child radius -


i useing d3's packed cicle layout(this) , have noticed when parent has 1 child, radius of child same parents.

is possible modify using the .radius method layout provides? ideally if parent has 1 child child's radius should 1/2 of parents.

i found partial solution, add placeholder nodes tree, run layout, remove them again. isnt want, since makes layout on sided.

hope makes sense. take @ fiddle see mean: jsfiddle

the below posted sample should show 2 circles( in circle 2 in img).

var root = {      "name": "controls",      "children": [       {"name": "anchorcontrol", "size": 2138}      ] }; 

enter image description here

thx

i took stab @ , managed solve issue. might not optimal hey, works. =)

this.calculatelayout = function( dim, tree ) {      var packlayout = d3.layout.pack()         .size( [dim, dim] )         .padding( 80 )         .sort( d3.descending )         .value( function( d ) { return 150 } );      addplaceholders(tree);      var nodes = packlayout( tree );      removeplaceholders(nodes);      centernodes( nodes );      makepositionsrelativetozero( nodes );      return nodes; };  function addplaceholders( node ) {      if(node.children) {          for( var = 0; < node.children.length; i++ ) {              var child = node.children[i];             addplaceholders( child );         }          if(node.children.length === 1) {              node.children.push({ name:'placeholder', children: [ { name:'placeholder', children:[] }] });         }     } };  function removeplaceholders( nodes ) {      for( var = nodes.length - 1; >= 0; i-- ) {          var node = nodes[i];          if( node.name === 'placeholder' ) {              nodes.splice(i,1);         } else {              if( node.children ) {                  removeplaceholders( node.children );             }         }     } };  function centernodes( nodes ) {      for( var = 0; < nodes.length; ++ ) {          var node = nodes[i];          if( node.children ) {              if( node.children.length === 1) {                  var offset = node.x - node.children[0].x;                 node.children[0].x += offset;                 reposition(node.children[0],offset);             }         }     }      function reposition( node, offset ) {          if(node.children) {             for( var = 0; < node.children.length; i++ ) {                  node.children[i].x += offset;                 reposition( node.children[i], offset );             }         }     }; };  function makepositionsrelativetozero( nodes ) {      //use have vis centered @ 0,0,0 (easier positioning)     var offsetx = nodes[0].x;     var offsety = nodes[0].y;      for( var = 0; < nodes.length; ++ ) {          var node = nodes[i];          node.x -= offsetx;         node.y -= offsety;     } }; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -