function clockMap(parentSvg, topology, data, colormap, updateId) { var rotate = [-60,-20], velocity = [.015, -0], width = parentSvg.style("width").slice(0, -2), height = parentSvg.style("height").slice(0, -2); this.data = data; this.colormap = colormap; projection = d3.geo.orthographic() .rotate(rotate) .clipAngle(90) .scale(200) .translate([width / 2, height / 2]) .precision(.2); path = d3.geo.path() .projection(projection); map = parentSvg.append("g") .attr("transform", "translate(0,0)") .attr("id","clockMap"); // draw grid var graticule = d3.geo.graticule(); map.append("path") .datum(graticule) .attr("class", "graticule") .attr("d", path); // draw countries var country = map .selectAll(".countries") .data(topojson.feature(topology, topology.objects.countries).features) .enter() .append("path") .attr("d", path) .attr("class", "countries"); var tooltipMap = d3.select("#world-map").append("div").attr("class", "tooltipMap hidden"); // draw country boundaries map.append("path") .datum(topojson.mesh(topology, topology.objects.countries, function(a, b) { return a !== b; })) .attr("class", "boundaries") .attr("d", path); // // rotate var startTime = Date.now(); d3.timer(function() { // get current time var dt = Date.now() - startTime; projection.rotate([rotate[0] + velocity[0] * dt, rotate[1] + velocity[1] * dt]); map.selectAll("path").attr("d", path); }); _this = this; this.updateYear = function (year) { // set up color map and function var colorid = function(d) { try { return _this.colormap(_this.data.get(d.id).data.get(year).value); } catch(err) {return "Gainsboro";} } var strid = function(d) { try { var datum = _this.data.get(d.id).data.get(year).value if (datum) { return Math.round(datum).toLocaleString('en');} else{return "no data"} } catch(err) { return "no data"} } map.selectAll(".countries") .style('fill', colorid) .on('mousemove', function(d) { d3.select(this).style( "fill", "#666"); var mouse = d3.mouse(svg.node()).map(function(d) { return parseInt(d); }); tooltipMap.classed('hidden', false) .attr('style', 'left:' + (mouse[0] + 15) + 'px; top:' + (mouse[1] - 35) + 'px') .html(_this.data.get(d.id).name+": "+strid(d)); }) .on('mouseout', function() { d3.select(this).style('fill', colorid); tooltipMap.classed('hidden', true); }) .on('click', function(d) { updateId(d.id); }) .attr("d", path); } }