Closed GoogleCodeExporter closed 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
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
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
Original issue reported on code.google.com by
Wrede....@gmail.com
on 12 May 2011 at 11:35