Skip to content

Instantly share code, notes, and snippets.

@poezn
Created April 17, 2013 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poezn/5407618 to your computer and use it in GitHub Desktop.
Save poezn/5407618 to your computer and use it in GitHub Desktop.
Weather stations density hexbins
{"description":"Weather stations density hexbins","endpoint":"","display":"canvas","public":true,"require":[{"name":"TopoJSON","url":"http://d3js.org/topojson.v0.min.js"},{"name":"TopoJSON","url":"http://d3js.org/topojson.v0.min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"stations.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"countries.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"stations_1910.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"countries_simplified.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"hexbins.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var r = 5,
month = Math.floor(37) % 12 + 1; // 1 = January, 12 = December
var projection = d3.geo.equirectangular()
.center([0,0])
.scale(145)
var c = tb.ctx;
var path = d3.geo.path()
.projection(projection)
.context(c);
var world = tb['countries_simplified'];
var countries = topojson.object(world, world.objects.world);
c.fillStyle = "#181730";
c.rect(0,0, 1000, 800)
c.fill()
// clipping path
c.beginPath();
path(countries);
c.closePath();
c.clip();
var data_hexbins = tb["hexbins"];
var colorScaleHex = d3.scale.linear()
.domain([0, d3.max(data_hexbins.features, function(d, i) { return d.properties.COUNT })])
.range(["#F3FFE6", "#3BB945"])
// clipping path
_.each(data_hexbins.features, function(d, i) {
c.beginPath();
path(d);
c.closePath();
c.fillStyle = colorScaleHex(d.properties.COUNT);
c.fill()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment