kaiserfarrell / core-plot

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

Custom axis labels and collapsesLayers #421

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a custom CPTAxisLabel for an axis with a CPTTextLayer
2. Set the text layer's backgroundColor property
3. Set the graph hosting view collapsesLayers property to YES 
4. Run the app

What is the expected output? What do you see instead?
The expected output is the custom label with the background color and the text, 
but the background is missing.

What version of the product are you using? On what operating system?
core-plot 1.0, on iOS 5.0 and 4.0.

Please provide any additional information below.
The custom layer displays properly wehen setting collapsesLayers to NO in the 
graph's hosting view.

I want to set collapsesLayer to YES because it greatly improves scrolling 
performance.

I also tried to get the image from the graph and set it to an UIImageView to 
improve the scrolling performance with the same results, the custom label's 
background is missing.

I need to have custom labels for the x axis and each label has three text 
layers with different background colors inside.

I'm attaching the code snippet I'm using to create the custom label, a bit 
simplified.

Original issue reported on code.google.com by irodrig...@gmail.com on 4 Apr 2012 at 8:15

Attachments:

GoogleCodeExporter commented 8 years ago
Even simpler, if you create a CPTAxisLabel with some text and set it's 
background color, you won't see the background when you enable collapsesLayers 
in the hosting view. It displays properly with the collapsesLayers property set 
to NO.

Code snippet:

CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:@"X" 
textStyle:[CPTTextStyle textStyle]];
newLabel.contentLayer.backgroundColor = [[CPTColor redColor] cgColor];
newLabel.tickLocation = << The tick location >>;
newLabel.offset       = << The offset >>;

Original comment by irodrig...@gmail.com on 4 Apr 2012 at 8:33

GoogleCodeExporter commented 8 years ago
Issue 419 has been merged into this issue.

Original comment by eskr...@mac.com on 4 Apr 2012 at 11:21

GoogleCodeExporter commented 8 years ago
I solved this by adding a CPTBorderedLayer with fill set to fillWithColor right 
behind the CPTTextLayer instead of using the backgroundColor property of the 
CPTTextLayer.

Original comment by irodrig...@gmail.com on 5 Apr 2012 at 1:52

GoogleCodeExporter commented 8 years ago
Core Plot doesn't support the backgroundColor property. The superclass of 
CPTTextLayer was changed after the 1.0 release. It is now a subclass of 
CPTBorderedLayer which gives it a fill property.

Pull the latest code with Mercurial. Then the code in comment #1 can be changed 
to the following:

((CPTTextLayer *)(newLabel.contentLayer)).fill = [CPTFill 
fillWithColor:[CPTColor redColor]];

Original comment by eskr...@mac.com on 22 Apr 2012 at 1:05