// Generated by CoffeeScript 1.10.0 (function() { var WeatherWheel, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; window.WeatherWheel = observer(WeatherWheel = (function(superClass) { extend(WeatherWheel, superClass); function WeatherWheel(conf) { var scale, zoom; WeatherWheel.__super__.constructor.call(this, conf); this.init(); this.weather = conf.weather; this.listen_to(this.weather, 'change', (function(_this) { return function() { return _this.redraw(); }; })(this)); scale = 230; this.svg = this.d3el.append('svg').attrs({ viewBox: (-scale / 2) + " " + (-scale / 2) + " " + scale + " " + scale }); this.zoomable_layer = this.svg.append('g'); zoom = d3.zoom().scaleExtent([-Infinity, Infinity]).on('zoom', (function(_this) { return function() { return _this.zoomable_layer.attrs({ transform: d3.event.transform }); }; })(this)); this.svg.call(zoom); this.temp2radius = d3.scaleLinear().domain([-40, 40]).range([10, 70]); this.temp2color = d3.scaleLinear().domain([-20, 0, 20, 40]).range([d3.hcl(290, 70, 15), d3.hcl(230, 70, 45), d3.hcl(80, 70, 75), d3.hcl(10, 70, 45)]).interpolate(d3.interpolateHcl); this.prec2radius = d3.scaleLinear().domain([0, 40]).range([80, 70]); this.cloud2radius = d3.scaleLinear().domain([0, 8]).range([80, 86]); this.wind2dradius = d3.scaleLinear().domain([0, 100]).range([0, 60]); this.zoomable_layer.append('circle').attrs({ "class": 'ref_line temp_line', r: this.temp2radius(-20) }); this.zoomable_layer.append('circle').attrs({ "class": 'ref_line temp_line emph', r: this.temp2radius(0) }); this.zoomable_layer.append('circle').attrs({ "class": 'ref_line temp_line', r: this.temp2radius(20) }); this.zoomable_layer.append('circle').attrs({ "class": 'ref_line prec_line', r: this.prec2radius(20) }); this.zoomable_layer.append('circle').attrs({ "class": 'ref_line prec_line', r: this.prec2radius(40) }); this.zoomable_layer.append('circle').attrs({ "class": 'ref_line wind_line', r: this.wind2dradius(20) + 87 }); this.zoomable_layer.append('path').attrs({ "class": 'ref_line year emph', d: "M" + 0. + " " + (-scale * 0.1) + " L " + 0. + " " + (-scale * 0.5) }); } WeatherWheel.prototype.redraw = function() { var ANIMATION_DURATION, EPSILON, all_cloud_bars, all_prec_bars, all_temp_bars, all_wind_bars, arc_generator, cloud_bars, day2radians, enter_cloud_bars, enter_prec_bars, enter_temp_bars, enter_wind_bars, ndays, prec_bars, temp_bars, wind_bars; EPSILON = 0.01; ANIMATION_DURATION = 1500; ndays = ((this.weather.year % 4 === 0) && (this.weather.year % 100 !== 0)) || (this.weather.year % 400 === 0) ? 366 : 365; day2radians = d3.scaleLinear().domain([1, ndays + 1]).range([0, 2 * Math.PI]); arc_generator = d3.arc(); temp_bars = this.zoomable_layer.selectAll('.temp_bar').data(this.weather.days, function(d) { return d.day; }); enter_temp_bars = temp_bars.enter().append('path').attrs({ "class": 'temp_bar bar' }); enter_temp_bars.append('title'); all_temp_bars = enter_temp_bars.merge(temp_bars); all_temp_bars.select('title').text(function(d) { return (d3.timeFormat('%Y, %B %e')(d.date)) + "\nTemperature:\n Maximum: " + d.MaxTemperatureC + " °C\n Mean: " + d.MeanTemperatureC + " °C\n Minimum: " + d.MinTemperatureC + " °C"; }); all_temp_bars.transition().duration(ANIMATION_DURATION).attrs({ d: (function(_this) { return function(d) { return arc_generator({ startAngle: day2radians(d.day), endAngle: day2radians(d.day + 1), innerRadius: _this.temp2radius(d.MinTemperatureC), outerRadius: _this.temp2radius(d.MaxTemperatureC + EPSILON) }); }; })(this), fill: (function(_this) { return function(d) { return _this.temp2color(d.MeanTemperatureC); }; })(this) }); temp_bars.exit().remove(); prec_bars = this.zoomable_layer.selectAll('.prec_bar').data(this.weather.days, function(d) { return d.day; }); enter_prec_bars = prec_bars.enter().append('path').attrs({ "class": 'prec_bar bar' }); enter_prec_bars.append('title'); all_prec_bars = enter_prec_bars.merge(prec_bars); all_prec_bars.select('title').text(function(d) { return (d3.timeFormat('%Y, %B %e')(d.date)) + "\nPrecipitation: " + d.Precipitationmm + " mm"; }); all_prec_bars.transition().duration(ANIMATION_DURATION).attrs({ d: (function(_this) { return function(d) { return arc_generator({ startAngle: day2radians(d.day), endAngle: day2radians(d.day + 1), innerRadius: _this.prec2radius(d.Precipitationmm), outerRadius: _this.prec2radius(-EPSILON) }); }; })(this) }); prec_bars.exit().remove(); cloud_bars = this.zoomable_layer.selectAll('.cloud_bar').data(this.weather.days, function(d) { return d.day; }); enter_cloud_bars = cloud_bars.enter().append('path').attrs({ "class": 'cloud_bar bar' }); enter_cloud_bars.append('title'); all_cloud_bars = enter_cloud_bars.merge(cloud_bars); all_cloud_bars.select('title').text(function(d) { return (d3.timeFormat('%Y, %B %e')(d.date)) + "\nCloud cover: " + d.CloudCover + "/8"; }); all_cloud_bars.transition().duration(ANIMATION_DURATION).attrs({ d: (function(_this) { return function(d) { return arc_generator({ startAngle: day2radians(d.day), endAngle: day2radians(d.day + 1), innerRadius: _this.cloud2radius(-EPSILON), outerRadius: _this.cloud2radius(d.CloudCover) }); }; })(this) }); cloud_bars.exit().remove(); wind_bars = this.zoomable_layer.selectAll('.wind_bar').data(this.weather.days, function(d) { return d.day; }); enter_wind_bars = wind_bars.enter().append('path').attrs({ "class": 'wind_bar bar' }); enter_wind_bars.append('title'); all_wind_bars = enter_wind_bars.merge(wind_bars); all_wind_bars.select('title').text(function(d) { return (d3.timeFormat('%Y, %B %e')(d.date)) + "\nMean wind speed: " + d['MeanWindSpeedKm/h'] + " Km/h\nWind direction: " + d.WindDirDegrees + " °"; }); all_wind_bars.transition().duration(ANIMATION_DURATION).attrs({ d: (function(_this) { return function(d) { var a, dax, day, dx, dy, r, rho, theta, x, y; theta = day2radians(d.day + 0.5) - Math.PI / 2; rho = 87; x = rho * Math.cos(theta); y = rho * Math.sin(theta); r = _this.wind2dradius(d['MeanWindSpeedKm/h']); dx = r * Math.cos(theta); dy = r * Math.sin(theta); a = 2 * Math.PI * (d.WindDirDegrees - 90) / 360; dax = 2 * Math.cos(a); day = 2 * Math.sin(a); return "M" + (x + dax) + " " + (y + day) + " l" + (-dax) + " " + (-day) + " l" + dx + " " + dy; }; })(this), stroke: 'teal' }); return wind_bars.exit().remove(); }; return WeatherWheel; })(View)); }).call(this);