Reputation: 7032
I have a Core Plot scatter plot in an iOS app that I'm using to show some data. When the view loads I calculate the ideal ranges for the plot to fit its data on screen. I allow the user to zoom and pan, but include a button to return the graph to those ideal ranges.
The button works and the ranges change appropriately, but the change can be a bit jarring. One loses their mental 'map' of the plot because of the abrupt change. It would be much nicer to animate the pan and scale as necessary, like maps apps do.
I didn't see anything built into Core Plot that allows animation of this, but I may have missed something. Is there a way to do this with Core Plot (or a fork of it) or a reasonably easy way to do it manually?
Upvotes: 2
Views: 1092
Reputation: 311
In case anyone is wondering about this now, Eric's fix has been put in place and you can now animate a range using the following code:
CPTPlotRange *xRange = [CPTPlotRange
plotRangeWithLocation:CPTDecimalFromDouble(location)
length:CPTDecimalFromDouble(length)];
[CPTAnimation animate:plotSpace // CPTPlotSpace *
property:@"xRange"
fromPlotRange:plotSpace.xRange
toPlotRange:xRange
duration:5.0
withDelay:0
animationCurve:CPTAnimationCurveCubicInOut
delegate:nil];
Upvotes: 5
Reputation: 27381
The best solution available for now involves using a timer to adjust the range in small steps. I'm working on a more general solution, but it's not ready to include in the public code yet. Watch the status on Core Plot issue #398 to find out when the fix becomes available.
Upvotes: 1