I loved the reusable chart article, and am excited for more.
> Take for example the following code which spawns 3 boxes for a filter
sentence: ...
This section is confusing to me because I equate
|> d3.select('ul')
> .selectAll('li')
> .data([{...}, {...}, {...}])
> .enter()
> .append('li')
with| "render". Is that wrong? After all, it makes new pixels appear on my screen.
It would be more understandable if you filled in actual elements in .data() and
made all the code on the page available in a runnable package.
> In reusable components, we take the idea of joins to the max by also
using them
> for the _generation_ of the structure of the component itself
(typically, |.data([0])|.
What does this mean? Why [0]? If you have no data, why not just an empty
data element?
My understanding of d3 is that you define, as you say, a render
sequence, and then
only when you have data available you call .data(), and if you call
.data([]) the elements should vanish.
I suspect I'm totally missing the point.
> One effect this gives rise to is called the “re-render everything
principle”.
> Because D3 calculates the difference between the current state and the
> desired state, then selectively applies operations (if at all), “re-render
> everything” suddenly becomes much more inexpensive (but not free).
Please elaborate on this. As someone still learning d3, it has been
confusing to me what a "render" is.
Is a "render" when d3 updates the DOM? Is it when the browser takes the
DOM and redraws the pixels?
In order to get our plots to change with new data, my project group fell
into the trap of writing a redraw()
and calling it in a loop. It felt wrong, but I did not know enough to
explain why. I also want to know d3's diffing
algorithm; if we insert two elements in different spots near the middle
of a 100,000 element list, does d3 scan the
entire list looking for them? And when it finds them, what does it store
and how much work does that trigger?
I am glad to see writeups like this coming along. I get the impression
D3 has been mostly learned by example,
and the people who understand the philosophy get it and the people who
don't are stumped. Bridges like these are critical.
--
-Nick Guenther
4A Stats/CS
University of Waterloo