Interactive Data Lab, University of Washington
@kanitw / kanitw.yellowpigz.com
(Based on Vadim Ogievetsky and Scott Murray's work)
.select() + .append()
d3 use CSS Selector
Note: .append()
return a new selection–containing the appended object(s)
.select()
+ .attr()
, .style()
Select and modify elements's properties
Note: notice chained syntax, object as argument
.select()
only selects one item!.selectAll()
See also: http://mbostock.github.io/d3/tutorial/circle.html
.data()
.data()
Tell D3 that you want the selected elements to correspond to data!
.data()
is called, __data__
of each element will contain the data mapped to that element.You should have seen this from last slide!
Data can be objects too!
.data()
Calling .data()
create three arrays – enter
, update
, exit
. .data()
returns the update.
Source: http://bost.ocks.org/mike/join/
.enter()
.enter()
Shorter: append, then update all together!
.enter()
from scratchThis is a common way that people build visualization in D3!
.exit()
.transition()
Note: Transitions in D3 use cubic-in-out as default easing functions. But there are others.
.transition()
& .delay()
The default is index mapping.
.data(...,key)
A key should be a unique string.
http://bost.ocks.org/mike/selection/#key
.data(...,key)
Notice how you can save lines of code with selection.call()
http://bost.ocks.org/mike/selection/#key
New Data?
See even better bars transition.