map2 = {
const outerDiv = d3_5.create("div").attr("id", "outerDiv");
const svg = outerDiv.append("svg")
.attr("width", 600)
.attr("height", 350);
const legend = outerDiv.append("svg")
.attr("class", "legend")
.attr("height", 100)
.attr("width", 100)
.style("float","right");
legend
.append("text")
.attr("x", 10)
.attr("y", 20)
.text("Continent")
.style("font-family", "sans-serif")
.style('font-size', '10px')
.style('font-weight','bold');
legend.selectAll('rect')
.data(legend_hack)
.enter()
.append("rect")
.attr("x", 10)
.attr("y", function(d, i){ return i * 15 + 25;})
.attr("width", 10)
.attr("height", 10)
.style("fill", d => d.color);
legend.selectAll('txt')
.data(legend_hack)
.enter()
.append("text")
.attr("x", 25)
.attr("y", function(d, i){ return i * 15 + 35;})
.attr("height", 10)
.text(d => d.continent)
.style("font-family", "sans-serif")
.style('font-size', '10px');
const resetbar = outerDiv.append('form').attr('onsubmit', 'return false;');
resetbar.append('input')
.attr('type', 'button')
.attr('value', 'Reset View')
.on('click', function () { reset(); });
const path = d3_5.geoPath()
.projection(projection);
const topg = svg.append("g")
.attr("class", "topg")
.style("pointer-events", "all");
const circleR = 6;
const colors = d3_5.scaleOrdinal()
.domain(['Africa', 'Asia', 'Europe', 'North America', 'South America'])
.range(['#DC9C76','#74A588','#42282F','#D6CCAD', '#D6655A']);
topg.selectAll("path")
.data(topojson.feature(topodata, topodata.objects.countries)
.features)
.enter().append("path")
.attr("d", path);
var defs = svg.append("defs");
var filter = defs.append("filter")
.attr("id","blur")
.attr("y", "-500%")
.attr("x", "-500%")
.attr("width","1000%")
.attr("height","1000%");
filter.append("feGaussianBlur")
.attr("stdDeviation","5")
.attr("result","coloredBlur");
var feMerge = filter.append("feMerge");
feMerge.append("feMergeNode")
.attr("in","coloredBlur");
feMerge.append("feMergeNode")
.attr("in","SourceGraphic");
var circles = topg.selectAll("circle")
.data(citydata)
.enter()
.append("circle")
.attr("id", "city")
.attr("cx", function(d) {
return projection([d.lon, d.lat])[0];
})
.attr("cy", function(d) {
return projection([d.lon, d.lat])[1];
})
.attr("r", d => circleR * Math.sqrt(d.recipes/1500))
.style("fill", d => colors(d.continent))
.style("opacity", 0.8)
.style("filter","url(#blur)");
const zoom = d3_5.zoom()
.scaleExtent([0.7, 8])
.on('zoom', function() {
const { transform } = d3_5.event;
topg
.attr('transform', transform);
});
svg.call(zoom);
function reset() {
svg.transition()
.duration(750)
.call(zoom.transform, d3_5.zoomIdentity);
}
return outerDiv.node();
}