country_4 = {
const svg = d3.create("svg")
.attr("height", height)
.attr("width", width)
const projection = d3.geoMercator()
.fitSize([width, height], europe_extent)
const path = d3.geoPath()
.projection(projection)
svg.selectAll("path")
.data(world.features)
.enter()
.append("path")
.attr("d", path)
.style("fill", "#eaeaea")
.style("stroke", "#fff")
const uk = world.features.find(country => country.properties.NAME === "United Kingdom")
const cheese_data = trade_data.filter(d => d.Item === "Cheese, whole cow milk")
const data_extent = d3.extent(cheese_data, d => d["Value"])
const line_width = d3.scaleSqrt().domain(data_extent).range([0, 5])
svg.selectAll("line.base")
.data(world.features.filter(country => european_countries.find(c => c === country.properties.NAME)))
.enter()
.append("line")
.attr("x1", d => path.centroid(d)[0])
.attr("x2", d => path.centroid(uk)[0])
.attr("y1", d => path.centroid(d)[1])
.attr("y2", d => path.centroid(uk)[1])
.style("stroke", "#20bbfc")
.style("stroke-opacity", "0.2")
.style("stroke-width", d => {
const data = cheese_data.find(c => c["Partner Countries"] === d.properties.NAME)
return line_width(data["Value"])
})
svg.selectAll("line.overlap")
.data(world.features.filter(country => european_countries.find(c => c === country.properties.NAME)))
.enter()
.append("line")
.attr("x1", d => path.centroid(d)[0])
.attr("x2", d => path.centroid(uk)[0])
.attr("y1", d => path.centroid(d)[1])
.attr("y2", d => path.centroid(uk)[1])
.style("stroke-width", d => {
const data = cheese_data.find(c => c["Partner Countries"] === d.properties.NAME)
return line_width(data["Value"])
})
.classed("animated-line", true)
svg.selectAll("text")
.data(world.features.filter(country => european_countries.find(c => c === country.properties.NAME)))
.enter()
.append("text")
.attr("x", d => path.centroid(d)[0])
.attr("y", d => path.centroid(d)[1])
.text(d => d.properties.NAME)
return svg.node();
}