Data-Driven Documents
D3.js manipulates documents by binding data to them.
Selections
select
selectAll
under da hood
*dotted lines indicate parentNode
d3.select("tr")
d3.selectAll("tr")
d3.selectAll("tr").selectAll("td")
d3.selectAll("tr").style("color", "red")
d3.select("tr").datum([1, 2, 3])
d3.selectAll("tr").data([1, 2, 3])
d3.selectAll("tr").data([1, 2, 3, 4, 5])
body
tr
1
tr
2
tr
3
But where's 4 and 5?
d3.selectAll("tr").data([1, 2, 3, 4, 5]).enter()
d3.selectAll("tr").data([1, 2, 3, 4, 5]).enter().append("tr")
d3.selectAll("tr").data([4, 5]).exit()
d3.selectAll("tr").data([4, 5]).enter().remove()