divyavamsee / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

capture the tap on legend row (swatch + label) #444

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I suggest an enhancement, where a user can tap the legend row (swatch + label) 
and we can capture that event to trigger actions, such as explode the 
corresponding slide or some other action.

Original issue reported on code.google.com by danielpa...@gmail.com on 11 Jul 2012 at 4:57

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 11 Jul 2012 at 11:05

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 26 Jul 2013 at 11:02

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 013f80d2139e.

Original comment by eskr...@mac.com on 27 Jul 2013 at 7:15