// Generated by CoffeeScript 1.10.0 (function() { var clean, defs, draw, height, noop, path, projectLineString, projection, svg, voronoi, width, zoom, zoomable_layer; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; defs = svg.append('defs'); svg.attr({ width: width, height: height }); zoomable_layer = svg.append('g'); zoom = d3.zoom().scaleExtent([-Infinity, Infinity]).on('zoom', function() { return zoomable_layer.attrs({ transform: d3.event.transform }); }); svg.call(zoom); projection = d3.geoAzimuthalEqualArea().clipAngle(180 - 1e-3).scale(3000).rotate([-12.22, -42, 0]).translate([width / 2, height / 2]).precision(0.1); path = d3.geoPath().projection(projection); voronoi = d3.voronoi().x(function(d) { return projection([d.longitude, d.latitude])[0]; }).y(function(d) { return projection([d.longitude, d.latitude])[1]; }).extent([[-1, -1], [width + 1, height + 1]]); noop = function() {}; projectLineString = function(feature, projection) { var line; line = null; d3.geoStream(feature, projection.stream({ polygonStart: noop, polygonEnd: noop, lineStart: function() { return line = []; }, lineEnd: noop, point: function(x, y) { return line.push([x, y]); }, sphere: noop })); return line; }; draw = function(error, tj, pumps_data) { var cell_g, coordinates, enter_gradients, gradients, pumps; gradients = defs.selectAll('.gradient').data(pumps_data); enter_gradients = gradients.enter().append('radialGradient').attrs({ "class": 'gradient', gradientUnits: 'userSpaceOnUse', id: function(d, i) { return "gradient_" + i; }, cx: function(d) { return projection([d.longitude, d.latitude])[0]; }, cy: function(d) { return projection([d.longitude, d.latitude])[1]; }, r: 3 }); enter_gradients.append('stop').attrs({ offset: '0%', 'stop-color': d3.hcl(80 + 0, 40, 100) }); enter_gradients.append('stop').attrs({ offset: '25%', 'stop-color': d3.hcl(80 + 40, 40, 75) }); enter_gradients.append('stop').attrs({ offset: '50%', 'stop-color': d3.hcl(80 + 80, 40, 50) }); enter_gradients.append('stop').attrs({ offset: '75%', 'stop-color': d3.hcl(80 + 120, 40, 25) }); enter_gradients.append('stop').attrs({ offset: '100%', 'stop-color': d3.hcl(80 + 160, 40, 0) }); zoomable_layer.append('path').datum(topojson.merge(tj, tj.objects.reg2011_g.geometries)).attr('class', 'land').attr('d', path); cell_g = zoomable_layer.selectAll('.cell_g').data(pumps_data).enter().append('g').attr('class', 'cell_g'); coordinates = pumps_data.map(function(d) { return [d.longitude, d.latitude]; }); cell_g.append('path').data(voronoi.polygons(pumps_data)).attr('class', 'cell').attr('d', function(d) { if (d != null) { return 'M' + d.join('L') + 'Z'; } else { return null; } }).attr('fill', function(d, i) { return "url(#gradient_" + i + ")"; }); pumps = zoomable_layer.selectAll('.pump').data(pumps_data); pumps.enter().append('circle').attrs({ "class": 'site', r: 0.1, cx: function(d) { return projection([d.longitude, d.latitude])[0]; }, cy: function(d) { return projection([d.longitude, d.latitude])[1]; } }); }; clean = function(d) { d.longitude = +d.longitude; d.latitude = +d.latitude; return d; }; d3.queue().defer(d3.json, 'italy.topo.json').defer(d3.csv, 'pumps.csv', clean).await(draw); }).call(this);