geomap_ttip = (data, json, jourChoisi, width = 800, height= 500) => {
const margin = {top: 25, right: 35, bottom: 35, left: 45},
legend = { x : 0, y : 0, step: 25,
sym:{
x: 0, y: 0, size: 8
}, cap:{
x: 0, height: 0, size: 13.5
}},
div = d3.create('div'),
svg = div.append("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height]),
path = d3.geoPath()
.projection(projection),
color = d3.scaleQuantize()
.range(["#edf8e9", "#bae4b3", "#74c476", "#31a354", "#006d2c"]);
const cleanData = data;
let length = json.features.length
let dep_data;
let day_data = d3.group(cleanData, d => d.jour).get(jourChoisi);
for (var j = 0; j < length; j++) {
var departement = +json.features[j].properties.code
if ([undefined, NaN, null].includes(departement))
continue;
dep_data = d3.filter(day_data, d =>{return d.dep == departement})[0]
json.features[j].properties.value = dep_data.hosp;
}
color.domain(
d3.extent(day_data, d => d.hosp)
);
const tooltip = d3.select("body")
.append("div")
.attr("class", "ttip")
.style("position", "absolute")
.style("padding", "1%")
.style("visibility", "hidden")
.style("z-index", "8")
.style("border", "1px solid black")
.style("border-radius", "5%")
.style("font-family", "arial");
svg.selectAll("g")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("fill", (d,i) => {
var value = d.properties.value;
return value ? color(value) : color(0);
})
.attr("stroke", "#eee")
.on('mouseover', function(event,d) {
tooltip.style("visibility", "visible")
.html(`${d.properties.nom}:${d.properties.value}`)
.style("left", (event.pageX + 20) + "px")
.style("top", (event.pageY - 20) + "px")
.style("background", color(d3.max([0, d.properties.value])));
})
.on('mouseout', function(e){tooltip.style("visibility", "hidden")});
return div.node();
}