How to make the coordinate of a graph user interactive? - iphone

I have tried to plot a graph using Quartz 2D . It looks more like a drawing. But I am fixing the axes and plotting the coordinates according to the axes. But the problem is I want to make the graph user interactive. Each coordinate on the graph will further have to drill down showing the details of the coordinate. So how can I make the coordinates interactive .

Rather than rolling your own Quartz graph with interactivity, you might want to take a look at the Core Plot framework, which is available for Mac and iPhone. The stubs are there to provide user interactivity, but we haven't filled in any implementations of this yet.
If you wish, you can implement
-(BOOL)containsPoint:(CGPoint)thePoint
-(void)mouseOrFingerDownAtPoint:(CGPoint)interactionPoint
-(void)mouseOrFingerUpAtPoint:(CGPoint)interactionPoint
-(void)mouseOrFingerDraggedAtPoint:(CGPoint)interactionPoint
-(void)mouseOrFingerCancelled
within the appropriate CPLayer subclass to make that Core Plot element respond to user interaction. We will also be setting up a delegation pattern so that your controllers can handle the logic for interaction events as well.

Related

Get every point plot data information when clicked on graph core plot

I am using the core plot to draw graph but i need to show every plot point info on touch on every plot coordinate.Please help me how can i show the info my data on every plot accordingly.
Thanks in advance.
I guess you should save the location and information of each plot point and check that against the touch you receive from the user. When you have drawn something on a canvas there is no way to ask it for information about a certain point.
Use a plot delegate to get notified of the touch. There are several examples in the Plot Gallery and CPTTestApp (Mac) example apps.

Draw graph using accelerometer data in core-plot

I'm new to this core-plot framework and trying to draw a line graph based on X and Y acceleration. I can already get my X and Y values and have successfully added core-plot in my project. I'm quite lost on how to start this, so basically, I will have X and Y values and how do I plot this using core-plot? any help is suggested. Thanks!
Maybe my answer is a little bit off topic, as it's not using core-plot, but did you look at the "AccelerometerGraph" sample app provided with Xcode?
It provides a nice plot which is dynamically updated while new accelerometer events are registered. The great of this sample is the way CoreAnimation has been used to "speed-up" Quartz2D. And you get all of this using system framework only and no third party code (apart your adaptation of Apple's one).
Look at the Core Plot examples to see how to set up a basic graph. You'll want to use a scatter plot. Call -reloadData on the plot whenever you have new data to display. If only some of the data points change on each frame, you can use the following methods to do a partial update:
-(void)reloadDataInIndexRange:(NSRange)indexRange;
-(void)insertDataAtIndex:(NSUInteger)index
numberOfRecords:(NSUInteger)numberOfRecords;
-(void)deleteDataInIndexRange:(NSRange)indexRange;
The Real Time Plot in the Plot Gallery example app shows one way to use these methods.

Core Plot: Data point labels shown, or when data points touched?

Is there a way using Core Plot to have periodic labels assigned to data plots? Such as 10-20 labels listed across my plot points.
Here is an example (mockup) of what I am hoping to do:
Is it possible to do this when the graph loads, or maybe when you swipe across the graph you see the data points showing their call out?
You'll have to draw the callout bubbles yourself, but it is possible to label data points. To make a callout, you could subclass CPTextLayer and have it draw the bubble around the text. Use this new class to make your labels.
You can implement a datasource method to inform Core Plot which data points should be labeled and provide your own labels if you wish (this is how you'd do the callouts). You can also respond to touch events (click events on the Mac) and show a label for the point that was touched. You have to touch each point individually--you won't get the delegate notification if you drag from one point to the next.
The examples included with Core Plot demonstrate how both techniques work.

Continously Updating UIViews in Objective C

I am very new to Iphone programming with Objective-C but I have picked up pretty fast in the last 1 month.
I have an application that reads data from a .csv which I then use to plot a continous graph on the Iphone. The problem is that there are close to 84,000 data points ( a major requirement) and the current design I used with Quartz 2D has helped to make the required plots but it takes close to 3mins for the UIView to show the infinitely long plot I desire.
The solution I am looking for is this
I intend to use a function in normal C language to sequential access the file within a thread and pass it to the drawing function which will then update the screen as the data arrives so that the user has a feel of how the data is been plotted continously. The problem I have however is that the CGRECT drawing function and the setNEEDSDisplay would just take all the points at once and display on the UIView,
How do I update only specific point on the UIView as the data arrives without clearing the whole View
You'll want to use setNeedsDisplayInRect as described here:
Drawing incrementally in a UIView (iPhone)
Have you looked at using Core Plot?
http://code.google.com/p/core-plot/
It's a little hard to figure out, google for example uses. But it may be able to handle what you need through selective plotting of large data sets.

How does one interact with OBJ-based 3D models on iPhone?

I have a few different OBJ files that I am able to parse and display. This code is based on Jeff LaMarche's The Start of a WaveFront OBJ File Loader Class. However, I need some means of detecting what coordinates I have selected within a displayed model. Usually there is one model displayed at a time but sometimes there will be two or more on the screen and I want to set up a NSNotificationCenter object to notify other sections of code as to which object is "selected". I have also looked at javacom's "OpenGL ES for iPhone : A Simple Tutorial" and would like to model the behavior of what I'm trying to program after his.
This is my current line of logic:
Setup a means to detect where a user has touched the screen
Have those coordinates compared with the current coordinates of a OBJ-based model
If they match, indicate said touch as being within the bounds of the object
The touchable set of coordinates must scale with the model. Currently the model is able to scale so I will most likely need to be able follow this scaling.
Also note, I don't need to move the model around on the screen. Just detect when it's been touched whether there is one model or several being displayed.
While this is most likely quite simple, I've been stumped by this for months now. I would really appreciate any light others can shed on this topic.
Use gluUnProject on the touch coordinates to get a vector going from the screen into the world, and then intersect it with your models to see if one of them has been touched. gluUnProject isn't by default available on iPhone, but you can look up implementations of it. http://www.mesa3d.org/ has an open source implementation.
Read about gluUnProject here: http://web.iiit.ac.in/~vkrishna/data/unproj.html