javascript - How to get the width of a d3 chart after updating? -


i'd width of main <g> element after expanding nodes in collapsible tree.

as can expected, structure #tree > svg > g > .... it's width of first <g> want. while can d3.select('#map>svg>g') (and calling .getbbox().width, want width after expanding clicked-on branch. d3.select('#map>svg>g') gives the width before expanding. (demo)

looking @ console output in demo (console.log() on line 156), it's clear clicking expands or collapses tree, of course changes width of <g>, newer value shown upon next click event.

am checking width early? need update make "new" width available in real time?

the problem you're using transition animates expansion of node. when you're checking it, nothing has happened yet. can use settimeout delay checking until transition has completed.

settimeout(function() {   var c = d3.select('#map>svg>g'),       curwidth = c[0][0].getbbox().width;   console.log(curwidth); }, duration); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -