piaoyongren / core-plot

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

Bar plot labels do not remain centered over vertical bars when the label fontsize is changed #216

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Fontsize for barplot label is changed in dataLabelForPlot using 
label.textStyle.fontsize
2. When the font size is altered significantly over a skinny bar it obviously 
shifts the label off of center (and further up away from the bar).

What is the expected output? What do you see instead?
The expected output is that the label would remain centered over its bar 
regardless of its fontsize. In the attached image the labels have been set to 
"opaque = YES" to show their frames. At the default font size the text exactly 
filled the frame width with a little extra space at the bottom. Setting the 
font size to be smaller shifts the text to the top left. I would expect the 
text to remain centered and remain at the same distance from the bottom of the 
frame or for the frame to resize according to the font size and remain in the 
appropriate place in regard to the bar.

What version of the product are you using? On what operating system?
Core Plot rev dfa4bbbf92 as of Oct. 14
iOS 4.1

Please provide any additional information below.
A UILabel has a textAlignment property that can be set to 
UITextAlignmentCenter. Something similar for these labels would be helpful in 
this case.

Original issue reported on code.google.com by jeremy.e...@gmail.com on 23 Oct 2010 at 12:41

Attachments:

GoogleCodeExporter commented 8 years ago
The problem is that when you use the label.textStyle.fontsize syntax, the label 
has no way of knowing that its text style has changed.

There are two coding patterns that will eliminate this problem until changes 
are made to Core Plot:
#1.
    CPTextStyle *newStyle = [label.textStyle copy];
    newStyle.fontSize = newSize;
    // set other text style properties as needed
    label.textStyle = newStyle;
    [newStyle release];

#2.
    CPTextStyle *newStyle = [CPTextStyle textStyle];
    newStyle.fontSize = newSize;
    // set other text style properties as needed
    label.textStyle = newStyle;

Original comment by eskr...@mac.com on 23 Oct 2010 at 2:40

GoogleCodeExporter commented 8 years ago
Thanks for the tip. Everything looks great now.

Original comment by jeremy.e...@gmail.com on 23 Oct 2010 at 6:51

Attachments:

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 5b7172dc37.

Original comment by eskr...@mac.com on 31 Oct 2010 at 3:02