chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const bandajdust = 0.7
var font = x.bandwidth()*0.34
svg.append("g")
.call(yAxis)
.selectAll("text")
.attr("class", "axis-label");
const tooltip = d3.select("body").append("div")
.attr("class", "svg-tooltip")
.style("position", "absolute")
.style("visibility", "hidden")
.style("font-family", "sans-serif")
.style("background", "rgba(235, 235, 235,0.9)")
.style("border-radius", ".4rem")
.style("color", "#000000")
.style("display", "block")
.style("font-size", "10px")
.style("max-width", "320px")
.style("padding", ".2rem .4rem")
.style("position", "absol")
const bars = svg.append("g")
.attr("fill-opacity", 0.1)
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => x(i))
.attr("y", d => y(d.upper_bound))
.attr("ry",x.bandwidth()*bandajdust/2) // changes radius of tip for bar charts
.attr("rx",x.bandwidth()*bandajdust/2) // not sure
.attr("height", d => y(d.lower_bound)-y(d.upper_bound)) // height of bars
.attr("width", x.bandwidth()*bandajdust*0.5) // width of rectangles
.attr("fill", d => (d.ml > 1) ? negativeColor : positiveColor) // fill bar condition based on d.ml value
const nodes = svg.append("g")
.selectAll("circle")
.data(data)
.enter()
// Add one g element for each data node here.
.append("g")
.attr("class", "nodes")
.attr("transform", function(d, i) {
return "translate(" + (x(i) + (x.bandwidth()*bandajdust*0.57)/2) + "," + y(d.ml) + ")";
}) // nodes placement
.on("mouseover", function(d){
tooltip
.style("visibility", "visible")
.html(`${siglas[d.state]} <br> Rt: ${d.ml}`)
// .text("RT: " + d.ml)
})
.on("mousemove", function(){
tooltip.style("top", (d3.event.pageY-(x.bandwidth()*2.1))+"px").style("left",(d3.event.pageX-(x.bandwidth()*1.1))+"px");
})
.on("mouseout", function(){
tooltip.style("visibility", "hidden");
});
nodes.append("circle")
.attr("class", "node")
.attr("fill", "white") // color
.attr("stroke", d => (d.ml > 1) ? negativeColor : positiveColor) // stroke line color
.attr("r", x.bandwidth()*bandajdust/2.25) // circle radius
.on("mousemove click touchmove", function() { // add animation where opacity increases with mouse on top and goes back to normal opacity
d3.select(this).attr("r", x.bandwidth()*bandajdust/1.9)
})
.on("mouseout", function() {
d3.select(this).attr("r", x.bandwidth()*bandajdust/2.25)
})
// Add a text element to the previously added g element.
nodes.append("text")
.attr("text-anchor", "start")
.style("font", font+"px sans-serif")
.attr("transform", `translate(${x.bandwidth()*-0.27}, ${x.bandwidth()*0.13})`)
.attr("fill", d => (d.ml > 1) ? negativeColor: positiveColor)
.attr("class", "node-text") // for rotation
.text(d => d.state)
// svg.append("g")
// .call(yAxis)
// .selectAll("text")
// .attr("class", "axis-label");
return svg.node();
}