setYAxisDirection = (axis, reverseDirection) => {
const textAnchor = axis.attr("text-anchor");
const reverseTextAnchor = textAnchor == "start" ? "end" : "start";
axis.selectAll(".tick").each(function (d, i) {
const tick = d3.select(this);
const tickSize = tick.select("line").attr("x2");
const tickTextX = tick.select("text").attr("x");
tick
.attr(
"text-anchor",
reverseDirection(data[i]) ? reverseTextAnchor : textAnchor
)
.select("line")
.attr("x2", reverseDirection(data[i]) ? -tickSize : tickSize);
tick
.select("text")
.attr("x", reverseDirection(data[i]) ? -tickTextX : tickTextX);
});
}