Chapter 18. Mapping with D3

Building and customizing map visualizations is one of D3’s core strengths. It has some very sophisticated libraries, allowing for all kinds of projections, from the workhorse Mercator and orthographic to more esoteric ones such as conicEquidistant. Mapping seems to be something of an obsession for Mike Bostock and Jason Davies, D3’s core devs, and their attention to detail is striking. If you have a mapping problem, chances are D3 can do the heavy lifting required.1 In this chapter, we’ll use our Nobel Prize visualization (Nobel-viz) map (Figure 18-1) to introduce the core D3 mapping concepts.

dvpj 1403
Figure 18-1. This chapter’s target element

Available Maps

The most popular mapping format is the aging Shapefile, developed for geographic information system (GIS) software. There are many free and proprietary desktop programs2 to manipulate and produce Shapefiles.

Unfortunately, Shapefiles were not designed for the Web, which would far rather deal in a JSON-based map format, and demands small, efficient representations to limit bandwidth and related lag.

The good news is that there are many convenient ways to convert Shapefiles to our preferred TopoJSON format,3 meaning you can manipulate your Shapefiles in software and then convert them to a web-friendly format. The standard way of finding maps for web dataviz is to first look for TopoJSON or GeoJSON versions, ...

Get Data Visualization with Python and JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.