Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  37] [ 7]  / answers: 1 / hits: 34494  / 12 Years ago, sun, march 25, 2012, 12:00:00

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.


More From » d3.js

 Answers
7

Use selection.empty(). Also, if the selection is empty, there's no need to remove it.


[#86619] Friday, March 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chazw

Total Points: 127
Total Questions: 129
Total Answers: 92

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;