{
let bandwidth = plotWidth/(data2.length+1);
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const plot = svg
.append("g")
.attr("transform",`translate(${margin.left},${margin.top})`)
plot.append("line")
.attr("x1",0)
.attr("x2",plotWidth)
.attr("y1",plotHeight-valueScale(0))
.attr("y2",plotHeight-valueScale(0))
.attr("stroke","black")
data2.forEach((d,i)=>{
plot.append("rect")
.attr("x", i * bandwidth)
.attr("y", plotHeight - valueScale(d.negative ? d.start : d.end))
.attr("width", bandwidth/2)
.attr("height", valueScale(Math.abs(d.value)))
.attr("fill", (d.negative ? 'red':'green'))
.attr("stroke-width",1)
.attr("stroke",(d.negative ? 'red':'green'))
.attr("shape-rendering","crispEdges");
plot.append("line")
.attr("x1",i * bandwidth)
.attr("x2",(i+1) * bandwidth)
.attr("y1",plotHeight-valueScale(d.end))
.attr("y2",plotHeight-valueScale(d.end))
.attr("stroke","black")
.attr("stroke-width",1)
.attr("shape-rendering","crispEdges")
console.log("i",i, data2.length-1);
if(i == data2.length-1){
console.log("here");
plot.append("rect")
.attr("x",(i+1) * bandwidth)
.attr("y",plotHeight-valueScale(d.end))
.attr("width",bandwidth/2)
.attr("height",valueScale(d.end))
}
})
return svg.node();
}