0

Like the chrome dev tool's screen shot below, I'd tried

console.log(object)

to print the total attributes of the object. But I can't access the "depth" through

object.depth

but I was able to get the object's name,value,count in the meantime..

I was wondering what exactly the attr "depth" is.

enter image description here


The source code is from a D3.js tree demo in this post: D3.js Drag and Drop, Zoomable, Panning, Collapsible Tree with auto-sizing.

However, I was trying to customize the algorithm of caculating the the node's width, using each level of the node's max label length instead of the total tree's.

// Call visit function to establish maxLabelLength
visit(treeData, function(d) {
    totalNodes++;
    maxLabelLength = Math.max(d.name.length, maxLabelLength);

    console.log(d); //I was debuging here
}, function(d) {
    return d.children && d.children.length > 0 ? d.children : null;
});
Kwan
  • 73
  • 7
  • 1
    What does `JSON.stringify(object)` log? – Cerbrus Jan 31 '18 at 13:10
  • 1
    Since the top-line summary has exactly 4 properties (name, value, count, children) while the expanded version has many more, it looks like the object is modified after the time the object is logged but before it is expanded in the console. You are probably logging `object.depth` before those modifications take place. Can you provide a complete code sample that fully reproduces your issue? – apsillers Jan 31 '18 at 13:13
  • Thanks for the replying! I was trying custom a js tree using the d3.js, the source code is from this url: [link](http://bl.ocks.org/robschmuecker/7880033) – Kwan Jan 31 '18 at 13:22

0 Answers0