objective c - Zooming axes in CorePlot -
i have app use coreplot plot graph. have implemented zooming of graph pinch gestures, still can't make labels near axis (which contain numbers 1, 2 etc.) zoom properly, instead of 1 major interval changes 5 or 0.5 (or other number) depending on pinch gesture.
-(void) viewdidappear { uipinchgesturerecognizer* rec = [[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(scalepiece:)]; // set options recognizer. [self.view addgesturerecognizer:rec]; ... xmajorinterval = 1; ymajorinterval = 1; axisset = (cpxyaxisset *)graph.axisset; axisset.xaxis.majorintervallength = cpdecimalfromfloat(xmajorinterval); axisset.xaxis.minorticksperinterval = 4; axisset.xaxis.minorticklength = 4.0f; axisset.xaxis.majorticklength = 8.0f; axisset.xaxis.labeloffset = 1.0f; axisset.yaxis.majorintervallength = cpdecimalfromfloat(ymajorinterval); axisset.yaxis.minorticksperinterval = 4; axisset.yaxis.minorticklength = 4.0f; axisset.yaxis.majorticklength = 8.0f; axisset.yaxis.labeloffset = 1.0f; ... } - (void)scalepiece:(uipinchgesturerecognizer *)gesturerecognizer { //here tried change xmajorinterval , ymajorinterval , redraw axes }
here's how zoom plot
- (void)scalepiece:(uipinchgesturerecognizer *)gesturerecognizer { if (plotspacex > -0.1) { if ([gesturerecognizer scale] > 1) { plotspacey = plotspacey - 0.1; plotspacex = plotspacex - 0.1; } } if (plotspacey >= -0.1) { if ([gesturerecognizer scale] < 1){ plotspacey = plotspacey + 0.1; plotspacex = plotspacex + 0.1; } } plotspace.xrange = [cpplotrange plotrangewithlocation:plotspace.xrange.location length:cpdecimalfromfloat(plotspacex * 2.0)]; plotspace.yrange = [cpplotrange plotrangewithlocation:plotspace.yrange.location length:cpdecimalfromfloat(plotspacey * 2.0)]; majorinterval = majorinterval*plotspacex/4; intmajorinterval = majorinterval; nslog(@"%i", intmajorinterval); axisset.xaxis.majorintervallength = cpdecimalfromint(intmajorinterval); axisset.yaxis.majorintervallength = cpdecimalfromint(intmajorinterval); }
in scalepiece method tried change xmajorinterval , ymajorinterval , redraw axes but, unfortunately, method called during pinch gesture labels display huuuge numbers.
can me, please?
it seems answer question depends on how you're doing zooming of graph itself.
you'll want scale majorintervallength in same way you're scaling ranges plot space. is, if expand range factor of 2 want change value of majorintervallength twice it's current value. if expand 1.1, you'll multiply current value of majorintervallength 1.1 , set majorintervallength new value.
if post code graph scaling can provide more detailed answer code.
[update] after looking @ code. recommend following changes
before update plotspacex this:
intervalscale = (plotspacex + 0.1 / plotspacex)
then update majorinterval
this
majorinterval = majorinterval*intervalscale
this should scale axis interval in same way x coordinate.
Comments
Post a Comment