I'm trying to track position of a line by xScale. So as soon as x1 becomes xScale1.range()[1] it reaches its final position and should change a colour. In the DOM line has x1 attribute with a certain value of 500. What am I doing wrong?
g1.append('line')
.attr('stroke-width', 1)
.style('stroke', 'white')
.attr('x1', xScale1.range()[0] + 100)
.attr('x2', xScale1.range()[0] + 100)
.attr('y1', yScale1.range()[0])
.attr('y2', yScale1.range()[1])
.transition()
.duration(duration)
.ease(d3.easeLinear)
.attr('x1', xScale1.range()[1])
.attr('x2', xScale1.range()[1])
.style('stroke', function (d) {
changeColour();
})
function changeColour(d) {
if (d3.select(this).attr('x1') === xScale1.range()[1]){
return 'red';
};
}