Closed GoogleCodeExporter closed 9 years ago
Original comment by eskr...@mac.com
on 11 Jul 2012 at 11:05
I implemented It in my coreplot subclass.
Here are the things I did (probably isn't the best method, but I got things
working here):
1-Create a category for CPlot, and add a property called CGRect legendRect;
2-While initializing the plots, set this property as CGRectZero for each plot;
3-Add the <CPTLegendDelegate> and implement the method below:
-(BOOL)legend:(CPTLegend *)legend shouldDrawSwatchAtIndex:(NSUInteger)idx
forPlot:(CPTPlot *)plot inRect:(CGRect)rect inContext:(CGContextRef)context
{
if (CGRectEqualToRect(plot.legendRect, CGRectZero)) {
plot.legendRect = CGRectUnion(self.graph.legend.frame, rect);
}
return !plot.hidden;
}
3-Add the <CPTPlotSpaceDelegate> and implement the method below:
-(BOOL)plotSpace:(CPTPlotSpace *)space
shouldHandlePointingDeviceDownEvent:(UIEvent *)event atPoint:(CGPoint)point
{
if (CGRectContainsPoint(self.graph.legend.frame, point)) {
CGPoint pointInLegend = CGPointMake(point.x - self.graph.legend.frame.origin.x, point.y - self.graph.legend.frame.origin.y);
[self.graph.allPlots enumerateObjectsUsingBlock:^(CPTPlot *plot, NSUInteger idx, BOOL *stop) {
if (CGRectContainsPoint(plot.legendRect, pointInLegend))
{
plot.hidden = !plot.hidden;
[self configureLegend];
*stop = YES;
}
}];
}
return YES;
}
When user touch the legend item (swatch or label), the toched plot will be
hidden.
Probably this could be implemented inside coreplot.
Regards,
Almir
Original comment by almir....@gmail.com
on 19 Dec 2012 at 10:33
Original comment by eskr...@mac.com
on 26 Jul 2013 at 11:02
This issue was closed by revision 013f80d2139e.
Original comment by eskr...@mac.com
on 27 Jul 2013 at 7:15
Original issue reported on code.google.com by
danielpa...@gmail.com
on 11 Jul 2012 at 4:57