All examples By author By category About

rveciana

Automatic colouring World Map using Canvas

This example is the same as this Jason Davies GIST, but using Canvas instead of SVG.

How is the color selected:

The place was easy to find

context.fillStyle = color(d.color = d3.max(neighbors[i], function(n) { return countries[n].color; }) + 1 | 0);

I had to think for some time to understand how does this work. Let's separate it:

color(
    d.color = 
            d3.max(
                    neighbors[i], 
                    function(n) { return countries[n].color; }
                    ) 
                    + 1 | 0
);

Going from the inside to the outside: