graphs+sliders interaction in Xcode

I am trying to make a dynamic graph using thre "quartz" library. I am changing the points on graph with the sliders in xcode in real time in my application. Currently it is functioning but the scaling of slider values with the graph axes values is not efficient, i.e. the values plotted on the graph do not exactly map to the places they are intended to.


So can someone suggest the best way to do this ? That is, interfacing sliders with a graph and cleanly be able to plot the points on those very values selected by the slider ?

It's not a question of efficiency, it is rather a question of right or wrong. It sounds like you are making an error as you transpose the value on the slider to the correct position on the graph. I find the best way of drawing a graph is to use three coordinate systems - the functions coordinates, the graphs coordinates and the views coordinates. A function might be X=Y and it might have a point at 25,25 that you want to display - that's the function coordinate system. Transposing that to the graph coordinate system requires knowing that the graph is displaying, for example, Xmin=0, Xmax=100, Ymin=0, Ymax=50 so the 25,25 is converted to 0.25,0.50 in the graph coordinate system. The view is displaying the graph in a view with the Xmin,Ymin position at location, say 20,200 and Xmax,Ymax at 180,120 so in the view coordinate system the point is at 20 +0.25*(180-20)=60, 200+0.50*(120-200)=160. The app calculates everything originally in the function coordinates. The app hands to Quartz the variables for Xmin,Ymin,Xmax,Ymax descibed above (e.g. 0,100,0,50 and 20,200,180,120). Then the app hands to Quartz each value of the function that it wants to graph (and lines, and circles etc. all in the function coordinate system). Quartz does two transformations - first placing the function points onto the displayed area of the graph and then placing those displayed areas of the graph onto the view.


The slider affects only the function coordinate system. If you rotate the device or otherwise change the view screen that affects only those numbers above 20,200,180,120. If you change the graph axes to zoom in or move right or left then that affects only the numbers above 0,100,50,25.


To see it work look at the apps OptionPosition+ or Beat The Market.

graphs+sliders interaction in Xcode
 
 
Q