victory icon indicating copy to clipboard operation
victory copied to clipboard

Unwanted Label Tweening

Open thochi opened this issue 10 years ago • 5 comments

I'm not sure if this bug, a feature or a missing feature.

On grouped bars i need to display individual labels composed from the current bar values. So i have to add them as data attributes, which will be automatically animated together with the other data attributes via Victory-Animation.

See: https://jsfiddle.net/thochi/dgnvkjzd/

How can i avoid this?

I have some ideas and would love to implement one or a better approach

  1. exclude attributes of type string or somehow hardcoded or configured attributes from tweening in Victory-Animation
  2. add an animationData prop to the charts w/ the attributes or attribute names to animate

thochi avatar Feb 12 '16 09:02 thochi

Thanks for the demo, @thochi!

You can see where we choose which props to tween here. The issue is that the labels are stored in your data prop, and we definitely want to tween the data prop – just not the nested label property; unfortunately VictoryAnimation is kind of a blunt instrument and we don't get that kind of granularity currently, it's either the whole data prop or nothing. We should definitely improve this so that your demo works!

Excluding strings altogether would unfortunately lose us color tweening, and in general we do want our general-purpose interpolator to support formatted numbers like this (e.g. "1%" → "5%" like in your demo, "$5.00" → "$1.99", although the results could look better).

You'll notice that we don't tween the labels prop, which is another way to give VictoryBar the same info. So what you can do to work around this for now is remove label properties from your data, and in your render method, do something like:

const labels = this.state.data.map((group) => {
  return `${group[0].y}%`;
});

...snip...

<VictoryBar
  ...snip...
  labels={labels}/>

(Although when I tried this the labels didn't get applied correctly; code above might be slightly wrong or VictoryBar has a bug, but you get the general idea – the labels don't get tweened anymore.)

exogen avatar Feb 12 '16 10:02 exogen

Hi @exogen!

thanks for your fast reply.

Unfortunately for now the labels prop can not handle array of arrays to allow individual labels for grouped bars. Thats why i had to put them into the data prop. Even with VictoryPie i have the same issue. There is no lables prop at all.

Maybe it would be a good approach to tween numbers in strings only with the given precision?

thochi avatar Feb 12 '16 11:02 thochi

@thochi Absolutely, if we can be sure it's a label-like number like this we should try to ensure that the number of digits remain roughly the same as the start & end values.

But we should also just add support for labels being an array of arrays, that would be pretty easy.

exogen avatar Feb 12 '16 11:02 exogen

OK, then i will implement array of arrays for labels. Do i need an VictoryBar ticket for this or will be a pr enough?

thochi avatar Feb 12 '16 12:02 thochi

I like the idea of being able to pass animateData as a prop. It seems it would be pretty simple to change this to a prop instead, with what is now hardcoded as its default.

The use-case where I've run up against this is while placing charts in responsive layouts, wanting only to animate changes to chart data, but getting unwanted animation of layout updates.

mdarens avatar Apr 01 '16 17:04 mdarens