transitionMaster = (transition, pathIndex) => {
globalState.animationCurrentTime = (d3.now() - globalState.animationStartTime);
transition
.delay(function(d) {
return pathIndex < d.path.length ? d.path[pathIndex-1].rest
: null;
})
.attrTween("cx", function(d) {
return pathIndex < d.path.length ? d3.interpolateNumber(this.getAttribute("cx"), d.path[pathIndex].x) : null;
})
.attrTween("cy", function(d) {
return pathIndex < d.path.length ? d3.interpolateNumber(this.getAttribute("cy"), d.path[pathIndex].y) : null;
})
.ease(d3.easeLinear)
.duration(function(d) {
const rateLocal =
pathIndex < d.path.length ?
(
d.path[pathIndex].pathType === "robot" ?
0.1 :
0.2
)
: null;
return pathIndex < d.path.length ?
(
distance(d.path[pathIndex-1].x, d.path[pathIndex-1].y, d.path[pathIndex].x,
d.path[pathIndex].y)/rateLocal
)
: null;
})
.on('end', function(d) {
d.pathIndex = pathIndex
})
.transition()
.styleTween("opacity", function(d) {
return pathIndex >= d.path.length ? d3.interpolate(0.8, 0)
: null;
})
.duration(1000)
.on('end', function(d) {
return pathIndex >= d.path.length ?
(
d.path.length === 4 ? globalState.scrap += 1
: updatePartsCompleted()
)
: null;
})
.remove()
}