Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat is the point of calling selectAll when there are no existing nodes yet on D3.js
    text
    copied!<p>when i do this :</p> <pre><code>var link = svg.selectAll('.link') .data(links) .enter().append('path') .attr('class', 'link') .attr('d', diagonal) </code></pre> <p>There is no node with the <code>.link</code> class. So selectAll returns en empty selection. But i've found that, when you call this for the first time, you can <code>selectAll('whaterverYouWant')</code> </p> <p>That is because D3 doesn't matter about what you select, as you provide the tag name and the classes later <code>.append('path')</code>, <code>.attr(class ...)</code>.</p> <p>And, if you want to select elements that already exist, i read in the doc that <code>.enter</code> returns a placeholder selection. But if it returns a selection of placeholders (anonymous tags with .link class ?), there is no point to append a path to a path.</p> <p>When i call .append, it does what i want, i.e. append a path to svg. But i don't understand the logic behind that. (I'm glad it works though, because d3 is powerful)</p> <p>So, ok i selectAll('anything') and append what i want, regardless of what i selected. But if i try this:</p> <pre><code>d3.select('#savestring-debug') .selectAll('div') .data(debugobjs) .enter().append('span') .attr('style', function(d) { return 'background:#'+d.color }) .text(function(d) { return d.aff }); </code></pre> <p>This would create placeholders for divs, but i append spans. Actually spans are created but i'm still looking for my divs ;)</p> <p>So, what is the principle behind selectAll >> data >> enter >> append ?</p> <p>thanks</p>
 

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