You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using transitions with the opacity style, values given in "%" units do not correctly transition from the prior value, but instead always transition from "0%". By contrast, using numbers for opacity values do correctly transition between opacity values.
Here's a simple example, where the intended effect is 5 circles who smoothly change to random opacities every update:
letdata=[];//Produce 5 points with increasing x values and random o values in range [0,100)functionupdateData(){data=[];for(leti=0;i<5;i++){data.push({x: i*100+50,o: Math.floor(Math.random()*100)});}}functionupdate(){d3.select('svg').selectAll('circle').data(data).join('circle').attr('cy',50).attr('r',40).attr('cx',(d)=>d.x).transition().duration(500).style('opacity',(d)=>d.o+"%");// using percent units}functionupdateAll(){updateData();update();}updateAll();
The actual resulting effect is each update, the circles fade in from 0 opacity, rather than smoothly from the prior opacity value:
percentTransition.mov
By changing the final line in update() to this:
.style('opacity',(d)=>d.o*0.01);// using decimal units
we get the intended effect:
decimalTransition.mov
I have not tested transitioning other style properties that use percent units, but it is possible this is an issue beyond just opacity.
The text was updated successfully, but these errors were encountered:
I think this probably isn’t fixable and is the same fundamental issue as #72 (comment) which is that transition.style depends on the computed value of the style property. In the case of opacity, the computed value is a number between 0 and 1. So you always need to specify the target value of the transition in the same manner as the computed value for the default interpolator to work correctly.
After reading the documentation for transition.style, that makes more sense. It does feel like an easy pitfall that others might run into because many style properties work just fine with alternative units when transitions are not involved. Perhaps the docs could include some warnings/guidelines on what units are appropriate for certain common style properties.
When using transitions with the opacity style, values given in "%" units do not correctly transition from the prior value, but instead always transition from "0%". By contrast, using numbers for opacity values do correctly transition between opacity values.
Here's a simple example, where the intended effect is 5 circles who smoothly change to random opacities every update:
The actual resulting effect is each update, the circles fade in from 0 opacity, rather than smoothly from the prior opacity value:
percentTransition.mov
By changing the final line in
update()
to this:we get the intended effect:
decimalTransition.mov
I have not tested transitioning other style properties that use percent units, but it is possible this is an issue beyond just opacity.
The text was updated successfully, but these errors were encountered: