Thanks Eric -
I was digging a bit into the CorePlot Source - It appears that the
positionRelativeToViewPoint: method in CPAxis.m is being called twice.
The first time in updateAxisLabelsAtLocations, the labels are at the
wrong position, because it is not accounting for the padding of the
plot area. The second time it is called is in layoutSublayers with the
correct position. So, to kludge fix it, I set the label's hidden
property to NO in updateAxisLabelsAtLocations and set it to YES in
layoutSublayers - and the labels appear in the next frame, but at
least it does not show up and then correct itself. I also commented
out the code in updateAxisLabelsAtLocations which positions the
labels.
I am hoping this is just because of something I am doing incorrectly.
Screenshots can be found here:
https://picasaweb.google.com/lh/sredir?uname=111808811679421651282&target=ALBUM&id=5593265760697201457&authkey=Gv1sRgCMvMw-DP__nuQQ&feat=email
Here is an extract of my code in the order in which stuff is
initialized. I tried moving setHostedGraph to after everything else
was inited, but that did not help.:
<code>
//1. Create the Graph
CPXYGraph* graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
[graph applyTheme:[CPTheme themeNamed:kCPPlainWhiteTheme]];
[graph setPaddingTop:1.0];
[graph setPaddingBottom:1.0];
[graph setPaddingLeft:1.0];
[graph setPaddingRight:1.0];
[graph.plotAreaFrame setPaddingTop:2.0];
[graph.plotAreaFrame setPaddingBottom:60.0];
[graph.plotAreaFrame setPaddingLeft:85.0];
[graph.plotAreaFrame setPaddingRight:2.0];
[graph setFill:[CPFill fillWithColor:[CPColor colorWithGenericGray:
0.5]]];
[self setHostedGraph:graph]; //self is a CPGraphHostingView
//2. Setup Plot Space
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
[plotSpace setAllowsUserInteraction:YES];
// Compute Bounds (need some specific boundaries, based on the data
selected)
[data computeBounds];
NSDecimal maxX = [data.graphMaxX decimalValue];
NSDecimal maxY = [data.graphMaxY decimalValue];
NSDecimal minX = [data.graphMinX decimalValue];
NSDecimal minY = [data.graphMinY decimalValue];
CPPlotRange* xRange = [self computeXRangeWithMin:minX andMax:maxX];
CPPlotRange* yRange = [self computeYRangeWithMin:minY andMax:maxY];
[plotSpace setGlobalXRange:xRange];
[plotSpace setXRange:xRange];
[plotSpace setGlobalYRange:yRange];
[plotSpace setYRange:yRange];
//3. Setup the Axes
CPConstraints axiscontraints = { CPConstraintFixed,
CPConstraintFixed };
CPXYAxisSet* axisSet = (CPXYAxisSet *)graph.axisSet;
//X-Axis Configuration
CPXYAxis* x = axisSet.xAxis;
x.majorIntervalLength = [self computeMajorXIntervalForMin:minX
andMax:maxX];
x.minorTicksPerInterval = 0;
x.orthogonalCoordinateDecimal = CPDecimalFromString( @"0.0" );
x.labelingOrigin = minX;
x.labelFormatter = xAxisFormatter;
CPMutableTextStyle* style = [x.labelTextStyle mutableCopy];
style.fontSize = 12.0;
x.labelTextStyle = style;
[style release];
x.labelRotation = M_PI_2;
x.labelingPolicy = CPAxisLabelingPolicyFixedInterval;
x.isFloatingAxis = YES;
x.constraints = axiscontraints;
//Y-Axis Configuration
CPXYAxis* y = axisSet.yAxis;
y.majorIntervalLength = CPDecimalDivide( yRange.length,
CPDecimalFromInt( 5 ) );
y.minorTicksPerInterval = 3;
y.orthogonalCoordinateDecimal = CPDecimalFromString( @"0.0" );
y.isFloatingAxis = YES;
y.constraints = axiscontraints;
y.alternatingBandFills = [NSArray arrayWithObjects:[CPFill
fillWithColor:[CPColor colorWithGenericGray:0.95]],
[CPFill fillWithColor:[CPColor colorWithGenericGray:
1.0]],nil];
CPMutableLineStyle* lineStyle = [CPMutableLineStyle lineStyle];
[lineStyle setLineWidth:1.0];
[lineStyle setLineColor:[CPColor colorWithGenericGray:0.88]];
y.majorGridLineStyle = lineStyle;
y.labelFormatter = yAxisFormatter;
CPAxisTitle* title = [[CPAxisTitle alloc] initWithText:[data
yAxisLabel] textStyle:[CPTextStyle textStyle]];
y.axisTitle = title;
y.titleOffset = 58.0;
[title release];
</code>
Thanks!