Core Plot: Pinch to change x axis range - ios

So I have a simple line XY Graph with integer values on the Y axis and dates on the X axis. What I would be like to be able to do is do a horizontal two-finger pinch and adjust the range dynamically. Eg, pinching in would give you a bigger range (mental model being that you're setting the start and end date shown to be further apart) and then pinching out would give you smaller time window.
Is there some stuff built in for this already? Reasonably new to CorePlot and the default finger stuff just zooms the graph itself, none of the values.
Would I need to put a gesture recgoniser on it? or does coreplot have stuff build into it for this?
Cheers

This is how the built-in zoom features work. Use a plot space delegate to monitor changes to the plot space while zooming and make changes to the axis appearance as needed based on the changes. See my answer to your other question for more info.

Related

Core Plot Scrolling

I am using the plot Interaction property set to YES to allow scrolling. Now it allows scrolling on the axes till infinity and also on the negative side of the axes . How can the scrolling be restricted only along the horizontal axis and also not extending upto infinity on the same axis.
You can use the globalYRange to limit the zooming and scrolling along the y-axis. If you need more control, use a plot space delegate to monitor changes to the plot space and respond accordingly. There are several examples in the Plot Gallery example app.

iOS Core Plot Get visible labels X axis

I am using Core Plot and I am really still new to it. I have searched but could not find the answer. I have allowsUserInteraction enabled. I have implemented zoom in/out with that. I want to be able to get first and last visible label on X axis every time when user has zoomed in/out. I know that there is willChangePlotRangeTo I have called there expandRangeByFactor method on my CPTMutablePlotRange. I want to be able to get every time text from first and last visible label on X axis. Is there any delegate method that I have missed?
Whenever you need to find out what the current axis labels are, call -layoutIfNeeded on the axis to make sure the labels are up-to-date and get the set of labels from the axisLabels property. Since it's a set, the collection is unordered. You'll have to search the whole set to find the first and last ones. Each label has a tickLocation that is the location along the axis and a contentLayer that is the label displayed at the location. The automatic axis labels are always CPTTextLayer objects, so you can extract the text property from there.

How to detect the coordinates of a custom UIView on CPTPlotspace?

In my App, I am using Coreplot to draw a CPTScatterPlot. Now i want to do a scanner on the chart and this animation of UIView (a line) should be like a Line aligned with Y-axis and travels through x=0 to whatever the last value of x is.
I want to perform an action based on the y value while this custom UIView (scanner) travels.
Any help would be appreciated.
Thanks,
i have something similar in an app of mine, the way i went about it was to add a bar graph on top of the scatter plot, i used that bar graph to represent the line that tracks the user's touch.
then i have a UIView that is overlaid on the plot and tracks the scatter plot touches and displays details of the point being touched.
if you just want to display a line, adding a bar graph is probably the easiest, then you don't have to worry about plot space coordinates vs superview coordinates.
the bar graph data source is only returning a value for the location the user is touching, with a height to match the size of the scatter plot.
the quick version is you can use handlePlotTouchEventInSpace:atPoint:isNewEvent to track the user's touches on the graph.
from there you can use the plotPoint:forPlotAreaViewPoint method on the plot space to get the coordinates of the touch.
something like this is a good starting point. it's a bit of a journey to get it all working, but its not too bad once you get the puzzle started.
-(void)handlePlotTouchEventInSpace:(CPTPlotSpace *)space atPoint:(CGPoint)point isNewEvent:(BOOL)newEvent {
NSDecimal plotPoint[2];
CPTXYPlotSpace *xySpace = (CPTXYPlotSpace *)space;
[xySpace plotPoint:plotPoint forPlotAreaViewPoint:point];
after that plotPoint will contain the x and y location of the touch inside the plot space.

Coreplot: Axis Labels Fixed Location

I'm trying to customize a Coreplot graph in many ways I can and the next thing I would like to do is place the X Axis Labels (one that is custom as well) at the bottom of the graph, independent of the X axis' position (whether it's scrolled up or down).
To make it clear, it is similar to giving the labels an offset value of something like 50.0. But offset is not the property I'm looking for since it fixes the labels location relative to the X axis.
Any way this can be done? Or do I have to skip the axisLabels property and place and layer or something manually at the bottom of the graph?
EDIT: Alright, I managed to place an axis on the bottom with CPTConstraints. But it's not on the bottommost. If a plot point is on those levels, the plot line overlaps the labels. I tired padding of the graph but of course, it moves the whole graph, hence the issue persists.
Thanks in advance
Make a second x-axis. Have the first one draw the axis line, tick marks, etc., as normal but no labels. Label the second one and set all of the line style properties to nil so it doesn't draw any of the lines.
Turns out that aside from the graph, the plotAreaFrame property of the CPTGrpah also has paddings. If you give more paddings to plotAreaFrame than that of the graph, the plot will be drawn in a smaller frame and the rest of the graph area will be for you to add what you want (i.e., a second Axis).
Big thanks to #Eric, for trying to answer Every single CorePlot question as soon as possible.
CorePlot does have a lot of customisation than I thought.

Core Plot: Pan and zoom two plot spaces along x-axis and auto-scaling both y-axes

I have a Core Plot chart with two line plots (plot 1 uses the y-axis on the LHS, plot 2 uses the y2-axis on the RHS) and two plot spaces (lhsPlotSpace and rhsPlotSpace).
For the initial plot set-up, I use scaleToFitPlotsto autoscale the two plots, which works as expected:
[lhsPlotSpace scaleToFitPlots:lhsPlots];
[rhsPlotSpace scaleToFitPlots:rhsPlots];
The plot then looks similar to the screen shot below.
In order to show more details, I would like to allow the user to pan horizontally and to zoom horizontally as long there is more data to be shown on the left and right (panning and zooming should be user driven only along the x-axis).
The y-axis and y2-axis should be scaled automatically depending on the range visible after panning and zooming.
Could you please help me a bit with this problem? I tried to use the delegate
Based on the code example I have found in the Core Plot forums and on StackOverFlow I tried to do this using the delegate method plotSpace:willChangePlotRangeTo:forCoordinate
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate
{
if (coordinate == CPTCoordinateY) {
newRange = ((CPTXYPlotSpace*)space).yRange;
return newRange
}
but besides getting very basic zooming, I did not found a solution which is even close to my problem.
Could you please point me to which delegates methods to use, how to restrict scrolling and how and where to set the new y-scale factor after panning and zooming?
Thank you very much!
Set the globalYRange of each plot space to the corresponding yRange to prevent scaling and scrolling in the y-direction.
-scaleToFitPlots: uses all plot data for the given plots when computing the new ranges. If you want to scale the plot space yRange based on the visible data, you'll have to do that yourself in the plot space delegate. The -plotSpace:willChangePlotRangeTo:forCoordinate: delegate method is a good choice for this.

Resources