ios - How to update CorePlot Y range with animation? -


in app, there 100 x-points in scatter plot, , plot xrange length 5, mean show 5 points in 1 screen. want update yrange dynamically animation based on visible points.

for example, visible points x: {1,2,3,4,5}, y: {15,25,35.45,55}, y range [cptplotrange plotrangewithlocation:cptdecimalfromfloat(15) length:cptdecimalfromfloat(5)]. after scrolling plot x values change {8,9,10,11,12} , y values {100,200,300,400,500}, hence new y range changes [cptplotrange plotrangewithlocation:cptdecimalfromfloat(100) length:cptdecimalfromfloat(5)]. want change happen animation. how add animation update plot range?

here's code use vertical range animation. note need take care several points (global , local y range, axis labels).

- (void)updateverticalmaingraphrange {     cptxyplotspace *plotspace = (id)maingraph.defaultplotspace;     cptxyaxisset *axisset = (id)maingraph.axisset;      float animationduration = 0.3;     if (([[nsapp currentevent] modifierflags] & nsshiftkeymask) != 0) {         animationduration = 3;     }      // set y axis ticks depending on maximum value.     cptxyaxis *y = axisset.yaxis;  ...        compute roundedlocalminvalue , roundedlocalmaxvalue here smallest , largest        values in local (visible) y range. ...      // let larger area (negative or positive) determine size of major tick range.     nsdecimalnumber *minabsolute = [roundedlocalminvalue abs];     nsdecimalnumber *maxabsolute = [roundedlocalmaxvalue abs];     float           interval;     if ([minabsolute compare: maxabsolute] == nsordereddescending) {         interval = [self intervalfromrange: minabsolute];     } else {         interval = [self intervalfromrange: maxabsolute];     }  ...        intervalfromrange: local function determine amount of ticks given range value. ...      // apply new interval length , minor ticks if lead equal or less labels.     // otherwise after animation.     // necessary avoid potentially large intermittent number of labels during animation.     nsdecimal newinterval = cptdecimalfromfloat(interval);     nsdecimal oldinterval = y.majorintervallength;     if (nsdecimalcompare(&oldinterval, &newinterval) == nsorderedascending) {         y.majorintervallength = newinterval;         y.minorticksperinterval = [self minorticksfrominterval: interval];         newmainyinterval = -1;     } else {         newmainyinterval = interval; // keep temporarily in ivar. applied @ end of animation.     }      cptplotrange *plotrange = [cptplotrange plotrangewithlocation: roundedlocalminvalue.decimalvalue                                                            length: [[roundedlocalmaxvalue decimalnumberbysubtracting: roundedlocalminvalue] decimalvalue]];      [cptanimation animate: plotspace                  property: @"globalyrange"             fromplotrange: plotspace.globalyrange               toplotrange: plotrange                  duration: animationduration                 withdelay: 0            animationcurve: cptanimationcurvecubicinout                  delegate: self];     [cptanimation animate: plotspace                  property: @"yrange"             fromplotrange: plotspace.yrange               toplotrange: plotrange                  duration: animationduration                 withdelay: 0            animationcurve: cptanimationcurvecubicinout                  delegate: self]; }  #pragma mark - coreplot delegate methods  - (void)animationdidfinish: (cptanimationoperation *)operation {     if (operation.boundobject == maingraph.defaultplotspace) {         // animation of main graph vertical plot space.         // can set final interval length , tick count.         if (newmainyinterval > 0) {             cptxyaxisset *axisset = (id)maingraph.axisset;             cptxyaxis    *y = axisset.yaxis;              y.majorintervallength = cptdecimalfromfloat(newmainyinterval);             y.minorticksperinterval = [self minorticksfrominterval: newmainyinterval];             newmainyinterval = 0;         }     } }  - (void)animationcancelled: (cptanimationoperation *)operation {     if (operation.boundobject == maingraph.defaultplotspace) {         // animation of main graph vertical plot space.         // can set final interval length , tick count.         if (newmainyinterval > 0) {             cptxyaxisset *axisset = (id)maingraph.axisset;             cptxyaxis    *y = axisset.yaxis;              y.majorintervallength = cptdecimalfromfloat(newmainyinterval);             y.minorticksperinterval = [self minorticksfrominterval: newmainyinterval];             newmainyinterval = 0;         }     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -