objective c - Changing the position of a CorePlot annotation after zooming(iOS) -
i using coreplot scatterplot display data readings external bluetooth sensor. ive gone through following tutorial: http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2 , ive got working way 1 exception. when user taps on 1 of data points, annotation placed on top of data point.
here how create , add annotations:
nsnumber *value = [self numberforplot:plot field:cptscatterplotfieldy recordindex:idx]; if (!valueannotation) { nsnumber *x = [nsnumber numberwithint:0]; nsnumber *y = [nsnumber numberwithint:0]; nsarray *anchorpoint = [nsarray arraywithobjects:x, y, nil]; valueannotation = [[cptplotspaceannotation alloc] initwithplotspace:plot.plotspace anchorplotpoint:anchorpoint]; } // 5 - create text layer annotation nsstring *stringvalue = [nsstring stringwithformat:@"%@", value]; cpttextlayer *textlayer = [[cpttextlayer alloc] initwithtext:stringvalue style:style]; valueannotation.contentlayer = textlayer; // 7 - anchor point annotation cgfloat x = (cgfloat)idx; nsnumber *anchorx = [nsnumber numberwithfloat:x]; cgfloat y = [value floatvalue]; //edit line? nsnumber *anchory = [nsnumber numberwithfloat:y]; valueannotation.anchorplotpoint = [nsarray arraywithobjects:anchorx, anchory, nil]; // 8 - add annotation [plot.graph.plotareaframe.plotarea addannotation:valueannotation];
ive tried adding small value anchory move annotation above plot point:
cgfloat y = [value floatvalue] + 5;
although works great @ first, when user zooms in graph annotation moves further , further away plot point. how can keep annotation above or below plot point while zooming?
i thought might have implement cptplotspacedelegate method plotspace: shouldscaleby: aboutpoint: method, , im stuck. have:
-(bool)plotspace:(cptplotspace *)space shouldscaleby:(cgfloat)interactionscale aboutpoint:(cgpoint)interactionpoint { cptgraph *graph = self.hostview.hostedgraph; nsarray *annotations = graph.plotareaframe.plotarea.annotations; if (annotations.count > 0) { cptplotspaceannotation *annotation = [annotations objectatindex:0]; nsnumber *anchorx = /* ? */; nsnumber *anchory = /* ? */; annotation.anchorplotpoint = [nsarray arraywithobjects:anchorx, anchory, nil]; } return yes; }
im not sure go here. or direction provide appreciated.
use displacement
property offset annotation away anchor point. displacement measured in pixels won't change plot space.
Comments
Post a Comment