Closed ateucher closed 11 years ago
I've since figured out this was wrong... but I'm a bit confused as to why.
Yes, that is confusing, but deliberate. :-)
bars.enter()
is for entering bars. When you click the text, one new data value is added, and the enter()
selection represents the new, corresponding element. The new bar is placed just beyond the right edge of the SVG.
The subsequent "update" portion bars.transition()…
updates values for all bars, including the new one, so all bars move into their new positions. The new bar appears to "slide in" from the right side.
Your're right that there is probably more redundancy in this example than is needed, because only width
and x
need to change. But this example is building up to more complex examples later in the chapter.
Thanks very much Scott - I get it now. After playing with it a bit more, I see that y
and height
also need to change because the input domain to yScale
may change, depending on the value of the new datum (i.e., if it is greater than the previous maximum).
Yes! Good catch. Yet I think this particular example has a max value of 25, so, in reality the yScale
doesn't change (but this is more flexible, and would work with larger values, if you allowed them).
I think there is a bit of redundancy in these two code sections? In the
bars.enter()
chain"x"
,"y"
,"width"
,"height"
, and"fill"
are set. In thebars.transition()
chain, the only things that change are"x"
and"width"
, so I think setting"y"
and"height"
there again is unnecessary.