gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Subview won´t have a transparent background #284

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Adding the GraphHostingView as a subview to avoid other subviews being 
mirrored.
2. Adding a Subview presenting text as a legend on top of the GraphHostingView
3. The Background of the added subview is filled with any color but 
transparent. The rect will cover the graph.

What is the expected output? What do you see instead?
The Background should be transparent. 
in drawRect i tried various things to get a transparent background
1)
 [self setBackgroundColor:[UIColor clearColor]];
2)
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(ctx, [UIColor colorWithRed:0 green:0 blue:0 
alpha:0.0].CGColor)
(or)
CGContextSetFillColorWithColor(ctx, [UIColor clearColor].CGColor)
CGContextFillRect(ctx, rect);

Is there any other way to present a subview showing simple text? I red 
something about siblingviews. what´s that?

Thanks!

Original issue reported on code.google.com by Wrede....@gmail.com on 12 May 2011 at 11:35

GoogleCodeExporter commented 9 years ago
I now solved the whole thing using dynamicaxis labels. It´s just a workaround 
to avoid overlapping labels  but still works for me. A firther problem with 
this is that i don´t know how to setup the ranges for which [xySpace 
plotPoint:plotPoint forPlotAreaViewPoint:point] returns respective bar numbers. 
It´s hard to say but simply seems to be very imprecise.

-(BOOL)plotSpace:(CPPlotSpace *)space 
shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point{

    NSLog(@"clicked at point %@",NSStringFromCGPoint(point));
    //Debug the current touch point
    NSDecimal plotPoint[2]; 
    CPPlotSpace *xySpace = [self.graph defaultPlotSpace]; 
    [xySpace plotPoint:plotPoint forPlotAreaViewPoint:point]; 
          NSLog(@"bar:%d height:%f", 
          [[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateX]] intValue],
          [[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateY]] doubleValue]);

    CPXYAxisSet* axisSet = (CPXYAxisSet*)graph.axisSet;
    int i = [[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateX]] intValue] -1; //-1 to get the index
    int maxBarIndex = [self numberOfBars] -1;
    i = i > maxBarIndex ? maxBarIndex : i;
    i = i < 0 ? 0 : i;

    int clickHeight = [[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateY]] intValue] -10; //-10 for unknown reason 
    int barHeight = [[self numberForPlot:openBarPlot field:CPBarPlotFieldBarLength recordIndex:i]intValue];
    NSLog(@"bar:%d height:%d",i,clickHeight); 

    if (clickHeight > barHeight) {
        axisSet.xAxis.axisLabels = nil;
        axisSet.xAxis.labelingPolicy = CPAxisLabelingPolicyAutomatic;
    }
    else {
        axisSet.xAxis.labelingPolicy = CPAxisLabelingPolicyNone;
        //label Name
        NSString* name = [self nameForBarAtIndex:i];
        //array for labels (only label for current bar will be added)
        NSMutableArray* axisLabels = [[NSMutableArray alloc] init];
        //create label
        CPTextStyle* textStyle = [CPTextStyle textStyle];
        textStyle.color = [CPColor blackColor];
        textStyle.fontSize = 14.0;
        CPAxisLabel* label = [[CPAxisLabel alloc] initWithText:name textStyle:textStyle];
        label.tickLocation = [[NSNumber numberWithFloat:i+1] decimalValue];
        label.offset = 5;
        [axisLabels addObject:label];
        [label release];
        //provide labels to axis
        NSSet* labelSet = [NSSet setWithArray:axisLabels];
        axisSet.xAxis.axisLabels = labelSet;
        [axisLabels release]; 
    }
    [axisSet relabelAxes];

    return NO;
}

Original comment by Wrede....@gmail.com on 12 May 2011 at 1:30

GoogleCodeExporter commented 9 years ago
Instead of adding your view as a subview of your GraphHostingView, add it to 
the parent view of your GraphHostingView. Two views with the same parent == 
siblings.

Original comment by eskr...@mac.com on 12 May 2011 at 10:10

GoogleCodeExporter commented 9 years ago
Thanks for your reply!That´s exactly what i did. I created a parent view and 
added both the GraphHostingView and the custom view as subviews. 

Original comment by Wrede....@gmail.com on 13 May 2011 at 1:18