Текст выходит за пределы графика. Идея состоит в том, что если i больше 1500 и длина заголовка больше 5 символов, то текст смещается влево на 100 пикселей.
Что я делаю не так?
![enter image description here](https://i.stack.imgur.com/l50jl.png)
Codepen
Вот мой подход:
let rect = svg.selectAll('g')
.data(combined)
.enter()
.append('g')
.on('mouseover', function () {
d3.select(this)
.append('text')
.attr('class', 'text')
.attr('x', function (d) {
return xScale(d.revenue);
})
.attr('y', function (d) {
return yScale.bandwidth() + 175;
})
.style('font-size', 10)
.attr('dy', -20)
.attr('dx', function (d, i) {
if (d.title.length > 5 && i > 1500) {
return -100;
} else {
return 10;
}
})
.text(d => d.title)
})
.on("mouseout", function () {
d3.select('.text')
.remove();
});