i need implement xy dynamic plot - drawing in realtime. have 2 methods, first of draw circle fill color:
- (void) drawcirclewithfillcolorcomponent:(float)value { cgpoint center = cgpointmake(self.bounds.size.width / 2, self.bounds.size.height / 2); cgfloat radius = min(center.x, center.y)-5.f; uibezierpath *path = [self bezierarcwithcenter:center startangle:0 endangle:m_pi*2 radius:radius]; [[uicolor whiteappcolor] setstroke]; [[self colorwithvalue:currentvalue] setfill]; [path setlinewidth:1.f]; [path fill]; [path stroke]; }
and draw graph:
- (void)drawhistoryincontext:(cgcontextref)context bounds:(cgrect)bounds { cgfloat value; uibezierpath *graph = [uibezierpath new]; (nsuinteger counter = 0; counter < historyarray.count; counter++) { value = [historyarray[counter] floatvalue]; if (counter == 0) { [graph movetopoint:cgpointmake(bounds.origin.x+5+bounds.size.width/2/50, bounds.origin.y+bounds.size.height/2-(value-1)*bounds.size.height/12)]; } else { [graph addlinetopoint:cgpointmake(bounds.origin.x+5+(float)counter/(float)(50-1)*bounds.size.width/2, max(bounds.origin.y+bounds.size.height/2-(value-1)*bounds.size.height/12,0))]; } } [graph setlinewidth:2.f]; [[uicolor lightblueappcolor] setstroke]; [graph stroke]; }
the problem - background of graph circle. need clip graph inside circle. area drawing graph rectangle - graph line displayed outside of circle borders. how can clip graph?
the unwanted behaviour this:
you can clip context, depending on drawrect:
implementation. in essence, clip before drawing graph line, draw. clipping affects drawing happening afterwards, can save context (using cgcontextsavegstate
) , restore (using cgcontextrestoregstate
) if need draw later not want clipped.
Comments
Post a Comment