I am trying to trigger a stroke-dashoffset
animation conditionally based on an existing stroke-dasharray
animation. But when the stroke-dashoffset
tween kicks in; the existing stroke-dasharray
does not tween anymore. How can I run both of them in parallel? My original intention is to author the tween to kick off with #1 stroke-dasharray
and keep on checking the interpolatedValue
. When the interpolatedValue
is >
than 10% of total pathLength to trigger #2stroke-dashoffset
without stopping the existing #1 stroke-dasharray
. The following code starts with #1, triggers #2 AND stops #1; which I donāt want.
It is based on this
const path =
bound
.append("path")
.classed('path', true)
.datum(data)
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(d => scaleX(d.date))
.y(d => scaleY(d.close))
)
.transition()
.duration(8000)
.attrTween('stroke-dasharray', function() {
const length = this.getTotalLength();
return function(t) {
const interpolatedValue = d3.interpolate(0, length)(t);
return `0,${length}`, `${interpolatedValue},${length}`
}
}
)
.attrTween('stroke-dashoffset', function() {
const length = this.getTotalLength();
const lengthPct = length * 0.1;
return function(t) {
const interpolatedValue = d3.interpolate(0, length)(t);
if (interpolatedValue > lengthPct) {
// Trigger the stroke-dashoffset animation
const dashOffset = length * -1;
d3.select(this)
.attr('stroke-dashoffset', dashOffset)
.transition()
.duration(8000)
.attrTween('stroke-dashoffset', function() {
return d3.interpolate(0, dashOffset);
})
}
}
})
Thank you in advance
@Fil