LM20
LM20
Fig. 2.6 A simple stacked bar chart (blue = apples, orange = oranges,
green = grapes)
ii. Paths:
o We define our first geographic path generator:
//Define path generator, using the Albers USA projection
var path = d3.geoPath()
.projection(d3.geoAlbersUsa());
o d3.geoPath() is a total lifesaver of a function.
o It does all the dirty work of translating that mess of GeoJSON coordinates into even
messier messes of SVG path codes.
iv. Choropleth:
o This word, which can be difficult to pronounce, refers to a geomap with areas filled
in with different values (light or dark) or colors to reflect associated data values.
o In the United States, so-called “red state, blue state” choropleth maps showing the
Republican and Democratic leanings of each state are ubiquitous, especially around
election time.
o But choropleths can be generated from any values, not just political ones.
iii. SVG:
o Finally, you probably realized that, since we are using D3 to generate images in
SVG format, we could just save out a copy of the SVG image directly.
o This has all the benefits of PDF: you maintain the original vector data, it’s scalable,
and you can even bring the results into Illustrator, Inkscape, Sketch, or another
SVG-compatible editor and tweak it after the fact.
Figure 15-3. Copying the D3-generated SVG code from the DOM