d3 sunburst incomplete transitions
-
26-06-2021 - |
Pergunta
I was building on top of sunburst-zoom example (/examples/partition/partition-sunburst-zoom in d3 package),
and noticed that sometimes transitions stop "just before" the final point.
To fix this, arcTween had to be modifyed the following way:
function arcTween(d) {
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, 1]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d, i) {
return i
? function(t) { return arc(d); }
: function(t) {
if (t>.95) tt=1; else tt=t+0.05
x.domain(xd(tt)); y.domain(yd(tt)).range(yr(tt))
return arc(d)}
};
}
This cuts off little part of start of transition, but makes it almost certainly end in consistent state.
I experienced this issue even with original partition-sunburst-zoom, but not as much as with my data and modifications.
Does anyone know the "neat" way of fixing it?
Solução
Figured. "Neat way" would be the following:
function arcTween(d) {
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, 1]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d, i) {
return i
? function(t) { if (t==1) {x.domain(xd(1)); y.domain(yd(1)).range(yr(1));}
return arc(d); }
: function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t));
return arc(d); };
};
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow