Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like there were a few issues here:</p> <ul> <li><p>Your data structure doesn't seem to be referencing the child nodes:</p> <pre><code>var nMap = {}; nMap.papa = {}; nMap.papa["children"] = []; nMap.papa["children"].push({ "name": "c1" }); // snip nMap.c1 = { size: 5 }; </code></pre> <p>Unless I'm missing something, your <code>getChildren</code> function gets the <code>{ name: "c1" }</code> object but never looks up <code>nMap.c1</code>. I'm not exactly certain what your alternative data structure is trying to achieve, but it seems like the most obvious option is to use a flat map of nodes, with children referenced by id, like this:</p> <pre><code>var nMap = {}; nMap.c1 = { name: "c1", value: 5 }; nMap.c2 = { name: "c2", value: 5 }; nMap.c3 = { name: "c3", value: 5 }; nMap.papa = { name: "papa", children: ['c1', 'c2', 'c3'] }; </code></pre> <p>With a structure like this, you can map to the real children in the <code>getChildren</code> function:</p> <pre><code>function getChildren(par){ var parName = par.name, childNames = parName in nMap &amp;&amp; nMap[parName].children; if (childNames) { // look up real nodes return childNames.map(function(name) { return nMap[name]; }); } } </code></pre></li> <li><p>Your children were using <code>size</code> instead of <code>value</code> to indicate weight, and the rest of the code expected <code>value</code> (so they all had weight <code>0</code>).</p></li> <li><p>Because you're using the "zoomable" treemap approach, which uses a specialized version of the treemap layout, you don't need to specify the <code>.children</code> accessor of the treemap layout. Instead, use your custom accessor in the the custom <code>layout</code> helper:</p> <pre><code>function layout(d) { // get the children with your accessor var children = getChildren(d); if (children &amp;&amp; children.length &gt; 0) { treemap.nodes({ children: children }); children.forEach(function(c) { c.x = d.x + c.x * d.dx; c.y = d.y + c.y * d.dy; c.dx *= d.dx; c.dy *= d.dy; c.parent = d; layout(c); }); } } </code></pre></li> </ul> <p>Working fiddle here: <a href="http://jsfiddle.net/nrabinowitz/WpQCy/" rel="nofollow">http://jsfiddle.net/nrabinowitz/WpQCy/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload