[ Launch: Weather stations pseudo heatmap (using topoJSON; colored by Voronoi) ] 5130927 by ptvans
[ Launch: Weather stations pseudo heatmap (using topoJSON) ] 5130752 by poezn
[ Launch: Weather stations pseudo heatmap (using topoJSON) ] 4759487 by poezn
[ Launch: Weather stations pseudo heatmap ] 4758743 by poezn
[ Launch: Weather stations pseudo heatmap ] 4746489 by poezn
[ Launch: Weather stations pseudo heatmap ] 4744710 by poezn
[ Launch: Weather stations ] 4743404 by poezn
-
-
Save ptvans/5130927 to your computer and use it in GitHub Desktop.
Weather stations pseudo heatmap (using topoJSON; colored by Voronoi)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"Weather stations pseudo heatmap (using topoJSON; colored by Voronoi)","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}},"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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var r = 5, | |
month = Math.floor(10); // 1 = January, 12 = December | |
var projection = d3.geo.equirectangular() | |
.scale(143) | |
var c = tb.ctx; | |
c.fillStyle = '#5C5C5C'; | |
var path = d3.geo.path() | |
.projection(projection) | |
.context(c); | |
var world = tb['countries']; | |
var countries = topojson.object(world, world.objects.land); | |
// clipping path | |
//c.beginPath(); | |
//path(countries); | |
//c.closePath(); | |
//c.clip(); | |
// background | |
path(countries); | |
c.fill(); | |
//var values = _.map(stations.features | |
var colorScale = d3.scale.linear() | |
.domain([-500, 1500, 4000]) | |
.range(['#21C4F7', '#F0F8B3', '#D52323']) | |
.interpolate(d3.interpolateLab) | |
var stations = tb['stations']; | |
var delta = 9500; | |
var lowerLimit = -4000; | |
var upperLimit = lowerLimit + delta; | |
var data = _.filter(stations.features, function(d, i) { | |
return d.properties["val" + month] > lowerLimit && d.properties["val" + month] < upperLimit; | |
}); // filter out unknown results | |
var drawGradient = function(p, i) { | |
var coords = _.map(p, function(d, i) { return projection(d) }); | |
var station = data[i]; | |
var value = station.properties["val" + month]; | |
path.pointRadius(r); | |
c.fillStyle = colorScale(value); | |
c.strokeStyle = colorScale(value); | |
c.beginPath(); | |
c.moveTo(coords[0][0], coords[0][1]); | |
_.each(coords.splice(1, coords.length-1), function(d) { | |
c.lineTo(d[0], d[1]); | |
}), | |
c.fill(); | |
c.stroke(); | |
c.closePath(); | |
}; | |
var drawPoint = function(p) { | |
path.pointRadius(0.5); | |
var color = colorScale(p.properties["val" + month]); | |
c.fillStyle = "#B9B9B9"; | |
c.beginPath(); | |
path(p) | |
c.closePath(); | |
c.fill(); | |
}; | |
c.save(); | |
var dataVoronoi = _.map(data, function(d) { return d.geometry.coordinates; }); | |
var points = d3.geom.voronoi(dataVoronoi); | |
_.each(points, drawGradient); | |
//_.each(data, drawPoint); | |
c.restore(); |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment