24. SELECTIONS ARE ARRAYS
/ slc al<ice eeet
/ eet l crl> lmns
vrcrl =d.eetl(crl";
a ice 3slcAl"ice)
/ stsm atiue adsye
/ e oe trbts n tls
crl.tr"x,2)
iceat(c" 0;
crl.tr"y,1)
iceat(c" 2;
crl.tr"" 2)
iceat(r, 4;
crl.tl(fl" "e";
icesye"il, rd)
25. METHOD CHAINING
/ slc al<ice eeet
/ eet l crl> lmns
/ adstsm atiue adsye
/ n e oe trbts n tls
d.eetl(crl"
3slcAl"ice)
.tr"x,2)
at(c" 0
.tr"y,1)
at(c" 2
.tr"" 2)
at(r, 4
.tl(fl" "e";
sye"il, rd)
26. SELECTION.APPEND
Single
/ slc te<oy eeet
/ eet h bd> lmn
vrbd =d.eet"oy)
a oy 3slc(bd";
/ ada <1 eeet
/ d n h> lmn
vrh =bd.ped"1)
a 1 oyapn(h";
h.et"el!)
1tx(Hlo";
Collection
/ slc al<eto>eeet
/ eet l scin lmns
vrscin=d.eetl(scin)
a eto 3slcAl"eto";
/ ada <1 eeett ec
/ d n h> lmn o ah
vrh =scinapn(h";
a 1 eto.ped"1)
h.et"el!)
1tx(Hlo";
27. WARNING!!
Use caution with method chaining: append returns a new
selection!
vrh =d.eetl(scin)
a 1 3slcAl"eto"
.tl(bcgon" "tebu"
sye"akrud, selle)
.ped"1)
apn(h"
.et"el!)
tx(Hlo";
29. DATA ARE ARRAYS
Selections are arrays
Data are arrays
Coincidence?
30. DATA
Numbers
/ Abrcat pras
/ a hr, ehp?
vrdt =[,1 2 3 5 8;
a aa 1 , , , , ]
Objects
/ Asatrlt pras
/ ctepo, ehp?
vrdt =[
a aa
{:1.,y 91}
x 00 : .4,
{: 80 y 81}
x ., : .4,
{:1.,y 87}
x 30 : .4,
{: 90 y 87}
x ., : .7,
{:1.,y 92}
x 10 : .6
];
31. DATA TO ELEMENTS
Use data to create multiple elements.
sgslcAl"ice)
v.eetl(crl"
.aadt)
dt(aa
.ne(.ped"ice)
etr)apn(crl"
.tr"x,x
at(c" )
.tr"y,y
at(c" )
.tr"" 25;
at(r, .)
We want the selection “circle” to correspond to data.
32. .DATA()
Use data to create multiple elements.
vrcrl =sgslcAl"ice)
a ice v.eetl(crl"
.aadt)
dt(aa;
The data method computes the join, defining enter and exit.
33. vrcrl =sgslcAl"ice)
a ice v.eetl(crl"
.aadt)
dt(aa;
crl.ne(.ped"ice)
iceetr)apn(crl";
Appending to the enter selection creates the missing
elements.
34. fnto xd {rtr dx }
ucin () eun .;
fnto yd {rtr dy }
ucin () eun .;
vrcrl =sgslcAl"ice)
a ice v.eetl(crl"
.aadt)
dt(aa;
crl.ne(.ped"ice)
iceetr)apn(crl"
.tr"x,x
at(c" )
.tr"y,y
at(c" )
.tr"" 25;
at(r, .)
The new elements are bound to data, so we can compute
attributes.
52. DOMAIN => RANGE
Scales are functions that map from data-space to visual-
space.
fnto xd {
ucin ()
rtr d*4 +"x;
eun 2 p"
}
Scales are convenient but optional; you can roll your own.
53. QUANTITATIVE SCALES
Map a continuous (numeric) domain to a continuous range.
linear
sqrt
pow
log
quantize
threshold
quantile
identity
67. Create
vryxs=d.v.xs)
a Ai 3sgai(
.cl()
saey
.ret"et)
oin(lf";
Render
sgapn(g)
v.ped""
.tr"ls" " ai"
at(cas, y xs)
.alyxs;
cl(Ai)
Style
.xspt,.xsln {
ai ah ai ie
fl:nn;
il oe
srk:#0;
toe 00
saerneig cipde;
hp-edrn: rsEgs
}
68.
69. TICKS
Quantitative scales can be queried for “human-readable”
values.
vrx=d.cl.ier)
a 3saelna(
.oan[2 2]
dmi(1, 4)
.ag(0 70)
rne[, 2];
xtcs5;/ [2 1,1,1,2,2,2]
.ik() / 1, 4 6 8 0 2 4
The requested count is only a hint (for better or worse).
73. vrsg=d.eet"oy)apn(sg)
a v 3slc(bd".ped"v"
.tr"it" otrit)
at(wdh, ueWdh
.tr"egt,otregt;
at(hih" ueHih)
vrg=sgapn(g)
a v.ped""
.tr"rnfr" "rnlt(
at(tasom, tasae"
+mriLf +""
agnet ,
+mriTp+"";
agno ))
Use margins for decorative elements, such as axes.
79. LINE INTERPOLATORS
Line and area generators support multiple interpolation
modes.
Linear, Step and Basis Interpolation
80. RADIAL AREAS & LINES
Similar to d3.svg.{area,line}, except in polar coordinates.
d3.svg.arc
81. D3.SVG.ARC
vrmEaper ={
a yxmlAc
"neRdu" 0
inrais: ,
"ueRdu" 30
otrais: 6,
"trAge:0 / 1 ocok
satnl" , / 2 'lc
"nAge:12/ rdas
ednl" . / ain
};
vrac=d.v.r(
a r 3sgac)
.neRdu()
inrais0
.ueRdu(6)
otrais30;
/ cntutadfutpelyu
/ osrc eal i aot
vrpe=d.aotpe)
a i 3lyu.i(;
/ drv dt t fe t d.v.r
/ eie aa o ed o 3sgac
vrmAc =penmes;
a yrs i(ubr)
vrpt =sgslcAl"ah)
a ah v.eetl(pt"
.aamAc)
dt(yrs
.ne(.ped"ah)
etr)apn(pt"
.tr"" ac;
at(d, r)
86. HIERARCHICAL LAYOUTS
There are lots of ways to visualize hierarchical data!
d3.layout.treemap
d3.layout.tree
d3.layout.pack
d3.layout.partition
d3.layout.force
d3.layout.bundle
d3.geom.voronoi
d3.geom.chord