What's the best way to hack in animation for stacked bar graphs?

59 views
Skip to first unread message

Drew Crawford

unread,
May 17, 2012, 7:22:31 AM5/17/12
to coreplot-discuss
Hi guys,

I've got a stacked bar chart that looks like this:

http://dl.dropbox.com/u/59605/Screen%20Shot%202012-05-17%20at%206.05.55%20AM.png

I am trying to achieve an effect where the sizes of the regions within
a bar undergo a shrink or grow animation when reloadData is called and
new data is provided.

I've seen examples like
http://stackoverflow.com/questions/2070993/core-plot-iphone-animation-examples
http://groups.google.com/group/coreplot-discuss/browse_thread/thread/bf41ffa4caf83edb/7c5d348769cac462?lnk=gst&q=animation#7c5d348769cac462

But these discussions seem to be

1) Limited to non-stacked bar charts
2) Interested in primarily animating from nothing to data, rather than
animating from arbitrary "before reload" configuration to arbitrary
"after reload" configuration.

I'm pretty sure that the answer is "CorePlot has no support for this",
but how would I go about hacking it in? My naive approximation would
be to try and use CAAnimation and mutate the transform matrix of the
layer that handles each section of each bar in the bar chart, but my
understanding is that these CALayers are discarded when reloadData is
called, rather than recycled. If so, I'm not sure what the
implications of recycling those layers would be, or where that code
even lives. And maybe this whole approach is a silly idea.

Can anyone chime in with a basic plan of attack?

Eric

unread,
May 18, 2012, 7:41:38 PM5/18/12
to coreplot...@googlegroups.com
Core Plot doesn't discard the plot layer when you give it new data; it just forces it to redraw. You might be able to animate stretching the plots between the old and new sizes. Start the animation, let it finish, and then call -reloadData to make the plot redraw at full resolution with the new data.

Eric

Drew Crawford

unread,
May 21, 2012, 6:36:44 PM5/21/12
to coreplot-discuss
I'm actually hoping to animate the individual bars moving as the data
changes, not the plot as a whole.

It looks like the plot is a CALayer, but each individual bar is hand-
drawn in Quartz in -[CPTBarPlot drawBarInContext].

Potentially the implementation could be changed to render each
individual bar as a CALayer that is then composited by the system and
animated. However, it's not really clear what would be the best way
to handle other changes (such as plot space changes) where reusing a
previous bar might be a bad idea.

Does this sound like a reasonable plan of attack, or are there other
issues to be aware of? Presumably Quartz was used here for some
reason...

On May 18, 6:41 pm, Eric <eskr...@mac.com> wrote:
> Core Plot doesn't discard the plot layer when you give it new data; it just
> forces it to redraw. You might be able to animate stretching the plots
> between the old and new sizes. Start the animation, let it finish, and then
> call -reloadData to make the plot redraw at full resolution with the new
> data.
>
> Eric
>
>
>
>
>
>
>
> On Thursday, May 17, 2012 7:22:31 AM UTC-4, Drew Crawford wrote:
>
> > Hi guys,
>
> > I've got a stacked bar chart that looks like this:
>
> >http://dl.dropbox.com/u/59605/Screen%20Shot%202012-05-17%20at%206.05....
>
> > I am trying to achieve an effect where the sizes of the regions within
> > a bar undergo a shrink or grow animation when reloadData is called and
> > new data is provided.
>
> > I've seen examples like
>
> >http://stackoverflow.com/questions/2070993/core-plot-iphone-animation...
>
> >http://groups.google.com/group/coreplot-discuss/browse_thread/thread/...

Eric

unread,
May 21, 2012, 6:51:36 PM5/21/12
to coreplot...@googlegroups.com
As long as you don't have too many bars, you could create a separate plot for each bar. That would give each bar its own layer.

Eric
Reply all
Reply to author
Forward
0 new messages