Strange flicker Issue with coreplot CPXYGraph

68 views
Skip to first unread message

JoelF

unread,
Apr 6, 2011, 10:23:46 PM4/6/11
to coreplot-discuss
I am hoping this is the appropriate place to ask this question (my
first) -

I am using a CPXYGraph in an iPad application with the Y axis
displaying percentages and the X axis displaying time periods.

The graph's plotArea frame has padding on the bottom and left, in
which space the axes labels are displayed. Both axes have been
configured as "isFloatingAxis = YES" with contraints
" { CPConstraintFixed, CPConstraintFixed } " with
orthogonalCoordinateDecimal = 0.

The graph displays perfectly - except that when the graph appears or
repaints - it appears that only the axes labels are drawn offset to
the right (y-axis) and top (x-axis) of where they are supposed to be,
and then correct themselves to their correct position immediately
afterward. I used screen-recording software to be sure that this was
happening. It should be noted that the axis title, the actual plot
itself were all painting in their expected positions - except for the
axes labels.

Any ideas? I can share screen-shots if you wish.

Thanks in advance.

Eric

unread,
Apr 7, 2011, 7:17:42 PM4/7/11
to coreplot-discuss
It might have something to do with the order that things are being
initialized. Can you share your axis setup code? Screenshots would be
helpful, too.

Thanks,
Eric

JoelF

unread,
Apr 8, 2011, 1:39:52 PM4/8/11
to coreplot-discuss
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!
Reply all
Reply to author
Forward
0 new messages