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:
Modified http://d3js.org/d3.v3.min.js to a secure url
Modified http://d3js.org/d3.geo.projection.v0.min.js to a secure url
Modified http://d3js.org/topojson.v1.min.js to a secure url
Changed /mbostock/raw/4090846/world-50m.json to a local referenece
https://d3js.org/d3.v3.min.js
https://d3js.org/d3.geo.projection.v0.min.js
https://d3js.org/topojson.v1.min.js