svgFinalOutput = {
const svgSelection = d3.select(svgNode);
const tooltip = d3.select(tooltipContainerSimple);
if (tooltip.empty()){
console.error("Simple tooltip container selection failed!");
return svgNode;
}
let minX = 0, minY = 0, svgWidth = 550, svgHeight = 990;
const viewBoxAttr = svgNode.getAttribute("viewBox");
if (viewBoxAttr) {
try {
const parts = viewBoxAttr.split(" ").map(Number);
if (parts.length === 4 && parts.every(n => !isNaN(n))) {
[minX, minY, svgWidth, svgHeight] = parts;
} else throw new Error("Invalid viewBox value format");
} catch (e) {
console.error("Error parsing viewBox:", e, "Using fallback dimensions.");
}
} else {
console.warn("SVG viewBox attribute missing, using fallback dimensions.");
}
const centerX = minX + svgWidth / 2;
svgSelection.append("line")
.attr("class", "split-line")
.attr("x1", centerX - 1)
.attr("y1", minY)
.attr("x2", centerX - 1)
.attr("y2", minY + svgHeight)
.attr("stroke", "black")
.attr("stroke-width", 1)
.attr("stroke-dasharray", "3,3");
const labelYPosition = minY + 15;
const labelFontSize = "12px";
svgSelection.append("text")
.attr("class", "side-label female-label")
.attr("x", minX + 15)
.attr("y", labelYPosition)
.attr("text-anchor", "start")
.attr("dominant-baseline", "hanging")
.style("font-size", labelFontSize)
.style("font-weight", "bold")
.text("Female");
svgSelection.append("text")
.attr("class", "side-label male-label")
.attr("x", minX + svgWidth - 15)
.attr("y", labelYPosition)
.attr("text-anchor", "end")
.attr("dominant-baseline", "hanging")
.style("font-size", labelFontSize)
.style("font-weight", "bold")
.text("Male");
svgSelection.selectAll("path[id]")
.style("fill", "#d3d3d3").style("cursor", "default")
.on("pointerover", null).on("pointermove", null).on("pointerout", null);
transformedData.forEach(d => {
const selector = `#${d.label}`;
const pathElement = svgSelection.select(selector);
if (!pathElement.empty()) {
pathElement.style("fill", colorScale(d.value)).style("cursor", "pointer");
pathElement
.on("pointerover", function(event) { tooltip.html(`${d.label}: ${d.value.toFixed(2)}`).style("left", (event.pageX + 10) + "px").style("top", (event.pageY - 15) + "px").style("visibility", "visible"); d3.select(this).style("stroke", "black").style("stroke-width", "2px").raise(); })
.on("pointermove", function(event) { tooltip.style("left", (event.pageX + 10) + "px").style("top", (event.pageY - 15) + "px"); })
.on("pointerout", function() { tooltip.style("visibility", "hidden"); d3.select(this).style("stroke", null).style("stroke-width", null); });
}
});
const currentViewKey = mutable selectedView;
const targetViewBoxParams = viewDefinitions[currentViewKey];
if (targetViewBoxParams && targetViewBoxParams.length === 4) {
svgSelection
.transition("zoom_transition")
.duration(750)
.attr("viewBox", targetViewBoxParams.join(" "));
} else {
console.warn(`Zoom: Invalid view definition for "${currentViewKey}" in svgFinalOutput cell.`);
}
}
return svgNode;
}