visualizationOne_HorizontalBar_Zoom_PlusHover = {
const chartdata = averageCriticScoreByPlatform;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const x = d3.scaleLinear()
.domain([90, d3.max(chartdata, d => d.average)])
.range([margin.left, width - margin.right]);
const y = d3.scaleBand()
.domain(chartdata.map(d => d.platform))
.rangeRound([margin.top, height - margin.bottom])
.padding(0.1);
const tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("background", "white")
.style("padding", "4px 8px")
.style("border", "1px solid gray")
.style("border-radius", "4px")
.style("font-weight", "bold")
.style("pointer-events", "none")
.style("opacity", 0);
svg.selectAll("rect")
.data(chartdata)
.join("rect")
.attr("x", d => x(90))
.attr("y", d => y(d.platform))
.attr("height", y.bandwidth())
.attr("width", d => x(d.average) - x(90))
.attr("fill", "steelblue")
// NEW
.on("mouseover", function(event, d) {
d3.select(this)
.attr("fill", "orange"); // Highlight this bar, this is where color changes?
tooltip
.html(`Score: ${d.average.toFixed(1)}`) // Set HTML inside the box
.style("left", (event.pageX + 10) + "px") // Position it near the mouse (X)
.style("top", (event.pageY - 20) + "px") // Slightly above the mouse (Y)
.style("opacity", 1); // Show it
})
.on("mousemove", function(event, d) {
// Update tooltip position as mouse moves
tooltip
.style("left", (event.pageX + 10) + "px")
.style("top", (event.pageY - 20) + "px");
})
.on("mouseout", function(event, d) {
d3.select(this)
.attr("fill", "steelblue"); // Reset bar color when mouseover leaves
tooltip
.style("opacity", 0); // Hide tooltip
});
// END NEW
const xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x));
const yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y));
svg.append("g")
.call(xAxis)
.call(g => g.select(".tick:last-of-type text")
.clone()
.attr("text-anchor", "middle")
.attr("x", -(width - margin.left - margin.right) / 2)
.attr("y", margin.bottom - 10)
.attr("font-weight", "bold")
.text("Average Critic Score"));
svg.append("g")
.call(yAxis)
.call(g => g.select(".tick:last-of-type text")
.clone()
.attr("transform", "rotate(-90)")
.attr("text-anchor", "middle")
.attr("x", -(15 - margin.top - margin.bottom) / 2)
.attr("y", -80)
.attr("font-weight", "bold")
.text("Platform"));
return svg.node();
}