I'm making a toggle in d3, and trying to avoid global variables.
I can go ahead and select the item as though it was already in the scene:
d3.select('#awesome_line_graph') and then test to see if I caught anything using
if (d3.select('#awesome_line_graph')[0].every(function(d){return d===null})){ // draw awesome line graph } else { d3.select('#awesome_line_graph').remove() } but this testing for the zeroth element for maybe more than one null thing seems terrible and hacky. How should I do it instead? Apologies for not knowing much javascript.
Use selection.empty(). Also, if the selection is empty, there's no need to remove it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With