{
const svg = d3.create("svg").attr("width", width).attr("height", height);
svg
.append("rect")
.attr("width", width)
.attr("height", height)
.attr("fill", backgroundColor);
for (let i = 0; i < leftData.length; i++) {
const leftState = leftData[i];
const rightState = rightData[i];
svg
.append("rect")
.attr("width", barWidthScale(rightState[dataKey]))
.attr("height", barHeight)
.attr("x", width / 2 + innerMargin / 2)
.attr("y", i * barHeight + margin)
.attr(
"fill",
d3.interpolateOranges(1 - rightColorScale(rightState[dataKey]))
)
.attr("stroke", "white")
.attr("stroke-width", 2);
svg
.append("rect")
.attr("width", barWidthScale(leftState[dataKey]))
.attr("height", barHeight)
.attr(
"x",
width / 2 - barWidthScale(leftState[dataKey]) - innerMargin / 2
)
.attr("y", i * barHeight + margin)
.attr(
"fill",
d3.interpolatePurples(1 - leftColorScale(leftState[dataKey]))
)
.attr("stroke", "white")
.attr("stroke-width", 2);
svg
.append("text")
.text(leftData[i].abbreviation)
.attr("x", width / 2)
.attr("y", i * barHeight + margin + barHeight / 2)
.attr("text-anchor", "middle")
.attr("alignment-baseline", "middle")
.attr("fill", "white")
.attr("font-family", "courier");
}
svg
.append("text")
.text(leftCreatorType + " : " + leftRacialCategory)
.attr("x", margin / 2)
.attr("y", height / 2)
.attr("fill", "white")
.attr("font-family", "courier")
.attr("alignment-baseline", "middle")
.attr("text-anchor", "middle")
.attr("transform", `rotate(-90 ${margin / 2} ${height / 2} )`);
svg
.append("text")
.text(rightCreatorType + " : " + rightRacialCategory)
.attr("x", width - margin / 2)
.attr("y", height / 2)
.attr("fill", "white")
.attr("font-family", "courier")
.attr("text-anchor", "end")
.attr("alignment-baseline", "middle")
.attr("text-anchor", "middle")
.attr("transform", `rotate(90 ${width - margin / 2} ${height / 2} )`);
svg
.append("text")
.attr("x", width / 2)
.attr("y", margin / 2)
.text(
`${leftCreatorType} (${leftRacialCategory}) Compared with ${rightCreatorType} (${rightRacialCategory}) | ${dataMode}`
)
.attr("text-anchor", "middle")
.attr("fill", "white")
.attr("font-family", "courier");
return svg.node();
}