con_box = {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
svg
.append("text")
.text("Consumption (kg/person)")
.attr("x", width / 2)
.attr("y", 475)
.attr("font-size", "small");
svg
.append("text")
.text("Food Category Consumption Distribution")
.attr("x", width / 2 - 100)
.attr("y", 50);
const tooltip = d3
.select("body")
.append("div")
.attr("class", "tooltip2")
.style("position", "absolute")
.style("background-color", "#d5e3f2")
.style("opacity", 0.7)
.style("visibility", "hidden");
const tip = svg
.append("text")
.style("pointer-events", "none")
.style("text-anchor", "left");
svg
.selectAll("vertLines")
.data(dd)
.enter()
.append("line")
.attr("x1", d => xb(d.Min))
.attr("x2", d => xb(d.Max))
.attr("y1", d => yb(d.food_category) + 20)
.attr("y2", d => yb(d.food_category) + 20)
.attr("stroke", "black");
svg
.selectAll("boxes")
.data(dd)
.enter()
.append("rect")
.attr("x", d => xb(d.q1))
.attr("y", d => yb(d.food_category) + 8)
.attr("height", 25)
.attr("width", d => xb(d.q3) - xb(d.q1))
.attr("stroke", "black")
.attr("fill", "#5f94cf")
.style("opacity", 0.7)
.on("mouseover", function(event, d) {
let t = "median: " + d.Median + "\n max: " + d.Max;
showToolTip(t, [event.pageX, event.pageY]);
})
.on("mousemove", function(event) {
d3.select(".tooltip")
.style("top", event.pageY - 10 + "px")
.style("left", event.pageX + 10 + "px");
})
.on("mouseout", function() {
d3.select(".tooltip").style("visibility", "hidden");
});
svg
.selectAll("toto")
.data(dd)
.enter()
.append("line")
.attr("x1", d => xb(d.Min))
.attr("x2", d => xb(d.Min))
.attr("y1", d => yb(d.food_category) + 8)
.attr("y2", d => yb(d.food_category) + 33)
.attr("stroke", "black");
svg
.selectAll("toto")
.data(dd)
.enter()
.append("line")
.attr("x1", d => xb(d.Median))
.attr("x2", d => xb(d.Median))
.attr("y1", d => yb(d.food_category) + 8)
.attr("y2", d => yb(d.food_category) + 33)
.attr("stroke", "black");
svg
.selectAll("toto")
.data(dd)
.enter()
.append("line")
.attr("x1", d => xb(d.Max))
.attr("x2", d => xb(d.Max))
.attr("y1", d => yb(d.food_category) + 8)
.attr("y2", d => yb(d.food_category) + 33)
.attr("stroke", "black");
svg.append("g").call(xAx);
svg.append("g").call(yAx);
return svg.node();
}