Queue with D3


I’ve known about Queue.js for a while, but finally used it for the first time today. It is an “asynchronous helper library”.

In short, reading in data is fundamental to data analysis. The typical way to read in a file in D3 is of the form:

d3.json("path/to/file.json", function(error, json) {
    if (error) return console.warn(error);
    data = json;
    visualizeit();
}); 

as described by Bostock here. However, often a visualization may require several different data files. This is especially true if maps are involved because you’ll need a json file for the shape of the country or other geographic features. This can start to make the code look confusing if you need to read in multiple files, waiting for each one before acting on the data. Queue solves that. More importantly, it allows you to read in files in parallel.

I used it for the first time today in this project.

I was inspired by reading this tutorial for another project I was working on where I wanted to use small multiple maps.

This explanation and bl.ocks example are also quite useful.