geo_map = (w=400, h=400, g) => {
const svg =
g ||
d3
.create("svg")
.attr("viewBox", [0, 0, w, h])
.attr("width", w)
.attr("height", h);
let margin = { top: 10, right: 10, bottom: 10, left: 10 };
let width = w - margin.left - margin.right,
height = h - margin.top - margin.bottom;
let projection = d3geo.geoKavrayskiy7()
.fitSize([width*1.2, width*2/3*1.2], countries)
.translate([width*0.46, width*2/3*0.6])
let path = d3.geoPath(projection)
svg.append("g").selectAll("path")
.data(topojson.feature(world, world.objects.countries).features)
.enter()
.append("path")
.attr("d", path)
.style('fill-opacity', 0.1)
.attr("name-country", d => {
return countries_hash.get(d.id)
})
.on("mouseenter", (e, d) => {
svg.append("text")
.attr("id", "legend")
.attr("x", e.offsetX)
.attr("y", e.offsetY)
.text(countries_hash.get(d.id))
}).on("mouseleave", (e, d) => {
svg.selectAll("#legend").remove()
})
return svg.node()
}