{
var svg = d3.select("#top10").html("")
.append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("transform", "translate(0," + (height - margin.bottom) + ")")
.call(d3.axisBottom(x).tickFormat(d => d.toString()))
.call(g => g.select(".domain").remove());
svg.append("g")
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove());
data_country.forEach(e => {
svg.append("path")
.attr("fill", "none")
.attr("stroke", color(e[0]))
.attr("stroke-width", 4)
.attr("d", line(e[1]));
svg.selectAll(".point")
.data(e[1].filter(d => d.Rank <= 10))
.enter()
.append("circle")
.attr("cx", d => x(d.Year))
.attr("cy", d => y(d.Rank))
.attr("r", 6)
.style("fill", d => color(d.Country))
.on("mouseover", function() {
var infos = d3.select(this).data()[0];
d3.select(this).attr("r", 9);
d3.select("#popup")
.style("visibility", "visible")
.html(infos.Country + " (" + infos.Year + ") : " + infos.Documents + " documents");
})
.on("mouseout", function() {
d3.select(this).attr("r", 6);
d3.select("#popup")
.style("visibility", "hidden")
})
});
svg.selectAll(".pays")
.data(data_country.map(d => {
var r = d[1].filter(d => d.Rank <= 10),
last_year = d3.max(r, d => d.Year),
last_rank = r.filter(d => d.Year == last_year)[0].Rank;
return { Country: d[0], Year: last_year, Rank: last_rank }
}))
.enter()
.append("text")
.attr("x", d => x(d.Year))
.attr("y", d => y(d.Rank))
.attr("dy", d => d.Year == d3.max(data, d => d.Year) ? -10 : 15)
.style("text-anchor",d => d.Year == d3.max(data, d => d.Year) ? "start" : "middle")
.style("fill", d => color(d.Country))
.style("font-size", ".75em")
.html(d => d.Country);
svg.append("g").append("text")
.attr("id", "popup")
.attr("y", -30)
.style("visibility", "hidden")
}