olunx

Add options for chart legend font style.

@@ -25,7 +25,8 @@ typedef NS_ENUM(NSUInteger, PNLegendItemStyle) { @@ -25,7 +25,8 @@ typedef NS_ENUM(NSUInteger, PNLegendItemStyle) {
25 @property (assign, nonatomic) BOOL hasLegend; 25 @property (assign, nonatomic) BOOL hasLegend;
26 @property (assign, nonatomic) PNLegendPosition legendPosition; 26 @property (assign, nonatomic) PNLegendPosition legendPosition;
27 @property (assign, nonatomic) PNLegendItemStyle legendStyle; 27 @property (assign, nonatomic) PNLegendItemStyle legendStyle;
28 -@property (assign, nonatomic) CGFloat legendFontSize; 28 +@property (assign, nonatomic) UIFont *legendFont;
  29 +@property (assign, nonatomic) UIColor *legendFontColor;
29 30
30 /** 31 /**
31 * returns the Legend View, or nil if no chart data is present. 32 * returns the Legend View, or nil if no chart data is present.
@@ -821,13 +821,13 @@ @@ -821,13 +821,13 @@
821 * should be in the middle of the first row */ 821 * should be in the middle of the first row */
822 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test" 822 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test"
823 withWidth:MAXFLOAT 823 withWidth:MAXFLOAT
824 - font:[UIFont systemFontOfSize:self.legendFontSize]].height; 824 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]].height;
825 825
826 for (PNLineChartData *pdata in self.chartData) { 826 for (PNLineChartData *pdata in self.chartData) {
827 /* Expected label size*/ 827 /* Expected label size*/
828 CGSize labelsize = [PNLineChart sizeOfString:pdata.dataTitle 828 CGSize labelsize = [PNLineChart sizeOfString:pdata.dataTitle
829 withWidth:maxLabelWidth 829 withWidth:maxLabelWidth
830 - font:[UIFont systemFontOfSize:self.legendFontSize]]; 830 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]];
831 831
832 /* draw lines */ 832 /* draw lines */
833 833
@@ -869,7 +869,8 @@ @@ -869,7 +869,8 @@
869 869
870 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + legendLineWidth, y, maxLabelWidth, labelsize.height)]; 870 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + legendLineWidth, y, maxLabelWidth, labelsize.height)];
871 label.text = pdata.dataTitle; 871 label.text = pdata.dataTitle;
872 - label.font = [UIFont systemFontOfSize:self.legendFontSize]; 872 + label.textColor = self.legendFontColor ? self.legendFontColor : [UIColor blackColor];
  873 + label.font = self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f];
873 label.lineBreakMode = NSLineBreakByWordWrapping; 874 label.lineBreakMode = NSLineBreakByWordWrapping;
874 label.numberOfLines = 0; 875 label.numberOfLines = 0;
875 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + legendLineWidth; 876 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + legendLineWidth;
@@ -277,13 +277,13 @@ @@ -277,13 +277,13 @@
277 * should be in the middle of the first row */ 277 * should be in the middle of the first row */
278 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test" 278 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test"
279 withWidth:MAXFLOAT 279 withWidth:MAXFLOAT
280 - font:[UIFont systemFontOfSize:self.legendFontSize]].height; 280 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]].height;
281 281
282 for (PNPieChartDataItem *pdata in self.items) { 282 for (PNPieChartDataItem *pdata in self.items) {
283 /* Expected label size*/ 283 /* Expected label size*/
284 CGSize labelsize = [PNLineChart sizeOfString:pdata.textDescription 284 CGSize labelsize = [PNLineChart sizeOfString:pdata.textDescription
285 withWidth:maxLabelWidth 285 withWidth:maxLabelWidth
286 - font:[UIFont systemFontOfSize:self.legendFontSize]]; 286 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]];
287 287
288 288
289 // Add inflexion type 289 // Add inflexion type
@@ -293,7 +293,8 @@ @@ -293,7 +293,8 @@
293 293
294 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + legendCircle, y, maxLabelWidth, labelsize.height)]; 294 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + legendCircle, y, maxLabelWidth, labelsize.height)];
295 label.text = pdata.textDescription; 295 label.text = pdata.textDescription;
296 - label.font = [UIFont systemFontOfSize:self.legendFontSize]; 296 + label.textColor = self.legendFontColor ? self.legendFontColor : [UIColor blackColor];
  297 + label.font = self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f];
297 label.lineBreakMode = NSLineBreakByWordWrapping; 298 label.lineBreakMode = NSLineBreakByWordWrapping;
298 label.numberOfLines = 0; 299 label.numberOfLines = 0;
299 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + legendCircle; 300 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + legendCircle;
@@ -80,7 +80,8 @@ @@ -80,7 +80,8 @@
80 80
81 [self.view addSubview:self.lineChart]; 81 [self.view addSubview:self.lineChart];
82 self.lineChart.legendStyle = PNLegendItemStyleStacked; 82 self.lineChart.legendStyle = PNLegendItemStyleStacked;
83 - self.lineChart.legendFontSize = 12.0; 83 + self.lineChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
  84 + self.lineChart.legendFontColor = [UIColor redColor];
84 85
85 UIView *legend = [self.lineChart getLegendWithMaxWidth:200]; 86 UIView *legend = [self.lineChart getLegendWithMaxWidth:200];
86 [legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.width)]; 87 [legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.width)];
@@ -153,7 +154,7 @@ @@ -153,7 +154,7 @@
153 154
154 155
155 self.pieChart.legendStyle = PNLegendItemStyleStacked; 156 self.pieChart.legendStyle = PNLegendItemStyleStacked;
156 - self.pieChart.legendFontSize = 12.0; 157 + self.pieChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
157 158
158 UIView *legend = [self.pieChart getLegendWithMaxWidth:200]; 159 UIView *legend = [self.pieChart getLegendWithMaxWidth:200];
159 [legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.width)]; 160 [legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.width)];