[ 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 poezn/5130752 to your computer and use it in GitHub Desktop.
Weather stations showing variability throughout the year (US)
This file contains hidden or 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 showing variability throughout the year (US)","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},"us.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 hidden or 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(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 values = _.map(stations.features | |
| var colorScale = d3.scale.linear() | |
| .domain([-500, 1500, 4000]) | |
| .range(['#21C4F7', '#F0F8B3', '#D52323']) | |
| .interpolate(d3.interpolateLab) | |
| var varianceColorScale = d3.scale.linear() | |
| .domain([0, 7000]) | |
| .range(['#FFF', '#000']) | |
| .interpolate(d3.interpolateLab) | |
| var stations = tb['stations']; | |
| var delta = 9500; | |
| var lowerLimit = -4000; | |
| var upperLimit = lowerLimit + delta; | |
| var data = _.chain(stations.features) | |
| .map(function(d, i) { | |
| var temps = _.chain(d3.range(1, 13)) | |
| .map(function(month, i) { | |
| return d.properties["val" + month]; | |
| }) | |
| .filter(function(d, i) { | |
| return !_.isNull(d) && d > -9999; | |
| }) | |
| .value(); | |
| d.properties.temps = temps; | |
| return d; | |
| }) | |
| .filter(function(d, i) { | |
| return d.properties.temps.length == 12; | |
| }) | |
| .value(); // filter out unknown results | |
| console.log(data); | |
| 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); | |
| var variance = d3.max(station.properties.temps) - d3.min(station.properties.temps); | |
| c.fillStyle = varianceColorScale(variance); | |
| c.strokeStyle = varianceColorScale(variance); | |
| 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(); | |
| }; | |
| c.save(); | |
| var dataVoronoi = _.map(data, function(d) { return d.geometry.coordinates; }); | |
| var points = d3.geom.voronoi(dataVoronoi); | |
| _.each(points, drawGradient); | |
| c.restore(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment