chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
const tooltip = d3.select("body").append("div")
.attr("class", "svg-tooltip")
.style("position", "absolute")
.style("visibility", "hidden")
const mouseover = function(d) {
tooltip.style("visibility", "visible")
d3.selectAll("rect")
.filter((e) => {
return d.crime === e.crime })
.style("stroke", "gray")
.style("stroke-width", 2)
.style("opacity", 1)
}
const mousemove = function(d) {
tooltip.style("visibility", "visible")
.style("top", (d3.event.pageY-10)+"px").style("left", (d3.event.pageX+10)+"px")
.html(d.crime)
}
const mouseleave = function(d) {
tooltip.style("visibility", "hidden");
d3.selectAll("rect")
.filter((e) => {
return d.crime === e.crime })
.style("stroke", "none")
.style("opacity", 0.8)
}
const g = svg.append("g")
.selectAll("g")
.data(augmentedData)
.join("g")
.selectAll("rect")
.data(d => d)
.join("rect")
.attr("fill", d => colorCrimes(d.crime))
.attr("x", (d, i) => x(d.data.area))
.attr("y", d => y(d[1]))
.attr("height", d => y(d[0]) - y(d[1]))
.attr("width", x.bandwidth())
.on("mouseover", mouseover)
.on("mousemove", mousemove)
.on("mouseleave", mouseleave)
svg.append("g")
.call(xAxis)
svg.append("g")
.call(yAxis)
svg.append("text")
.attr("x", (width/2))
.attr("y", margin.top)
.attr("text-anchor", "middle")
.attr("font-size", "24px")
.attr("font-family", "sans-serif")
.text(`Top 5 Crimes Per LA Police Area, ${currentYearData[0].year_rptd}`)
svg.append("text")
.attr("x", (width/2))
.attr("y", height - margin.bottom/3)
.attr("text-anchor", "middle")
.attr("font-size", "16px")
.attr("font-family", "sans-serif")
.text("Neighborhoods")
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("x", -height/2)
.attr("y", margin.left-40)
.attr("text-anchor", "middle")
.attr("font-size", "16px")
.attr("font-family", "sans-serif")
.text("Number of Incidents")
svg.selectAll(".tick")
.attr("font-size", "8px")
return svg.node()
}