All examples By author By category About

mbostock

Processing Fixed-Width Data

This example demonstrates how to convert awkward fixed-width text data, such as that released by the U.S. Bureau of Labor Statistics, into tab-separated values.

The source data file for this chart of seasonally-adjusted unemployment rates for 380 metropolitan areas is a whopping 9.9 MB. However, by pulling out only the data needed for this chart and by converting to a more efficient representation that eliminates redundant information, we can reduce it to a svelte 258 KB (44 KB gzipped). This is a savings of 98%! The resulting file is small enough to download and display quickly, despite having more than 63,000 data points.

The Makefile is responsible for downloading the source file from the BLS. Then, the process-data script converts and reduces the source data to TSV. The resulting tabular file is very wide, containing a row for each metropolitan area and a column for each month. You can run this example locally by cloning this gist, and then running the following commands:

npm install
make

When the BLS releases new data, you can update the chart by running make clean all.