Kevin

Merge pull request #175 from lunzii/master

Add options for chart legend font style.
@@ -25,8 +25,10 @@ typedef NS_ENUM(NSUInteger, PNLegendItemStyle) { @@ -25,8 +25,10 @@ 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 +
  29 +@property (assign, nonatomic) UIFont *legendFont;
  30 +@property (assign, nonatomic) UIColor *legendFontColor;
28 @property (assign, nonatomic) NSUInteger labelRowsInSerialMode; 31 @property (assign, nonatomic) NSUInteger labelRowsInSerialMode;
29 -@property (assign, nonatomic) CGFloat legendFontSize;  
30 32
31 /** 33 /**
32 * returns the Legend View, or nil if no chart data is present. 34 * returns the Legend View, or nil if no chart data is present.
@@ -818,7 +818,7 @@ @@ -818,7 +818,7 @@
818 * should be in the middle of the first row */ 818 * should be in the middle of the first row */
819 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test" 819 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test"
820 withWidth:MAXFLOAT 820 withWidth:MAXFLOAT
821 - font:[UIFont systemFontOfSize:self.legendFontSize]].height; 821 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]].height;
822 822
823 NSUInteger counter = 0; 823 NSUInteger counter = 0;
824 NSUInteger rowMaxHeight = 0; 824 NSUInteger rowMaxHeight = 0;
@@ -827,7 +827,7 @@ @@ -827,7 +827,7 @@
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
@@ -874,7 +874,8 @@ @@ -874,7 +874,8 @@
874 874
875 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + legendLineWidth, y, maxLabelWidth, labelsize.height)]; 875 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + legendLineWidth, y, maxLabelWidth, labelsize.height)];
876 label.text = pdata.dataTitle; 876 label.text = pdata.dataTitle;
877 - label.font = [UIFont systemFontOfSize:self.legendFontSize]; 877 + label.textColor = self.legendFontColor ? self.legendFontColor : [UIColor blackColor];
  878 + label.font = self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f];
878 label.lineBreakMode = NSLineBreakByWordWrapping; 879 label.lineBreakMode = NSLineBreakByWordWrapping;
879 label.numberOfLines = 0; 880 label.numberOfLines = 0;
880 881
@@ -348,7 +348,7 @@ @@ -348,7 +348,7 @@
348 * should be in the middle of the first row */ 348 * should be in the middle of the first row */
349 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test" 349 CGFloat singleRowHeight = [PNLineChart sizeOfString:@"Test"
350 withWidth:MAXFLOAT 350 withWidth:MAXFLOAT
351 - font:[UIFont systemFontOfSize:self.legendFontSize]].height; 351 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]].height;
352 352
353 NSUInteger counter = 0; 353 NSUInteger counter = 0;
354 NSUInteger rowWidth = 0; 354 NSUInteger rowWidth = 0;
@@ -358,7 +358,7 @@ @@ -358,7 +358,7 @@
358 /* Expected label size*/ 358 /* Expected label size*/
359 CGSize labelsize = [PNLineChart sizeOfString:pdata.textDescription 359 CGSize labelsize = [PNLineChart sizeOfString:pdata.textDescription
360 withWidth:maxLabelWidth 360 withWidth:maxLabelWidth
361 - font:[UIFont systemFontOfSize:self.legendFontSize]]; 361 + font:self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f]];
362 362
363 if ((rowWidth + labelsize.width + beforeLabel > mWidth)&&(self.legendStyle == PNLegendItemStyleSerial)) { 363 if ((rowWidth + labelsize.width + beforeLabel > mWidth)&&(self.legendStyle == PNLegendItemStyleSerial)) {
364 rowWidth = 0; 364 rowWidth = 0;
@@ -376,7 +376,8 @@ @@ -376,7 +376,8 @@
376 376
377 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + beforeLabel, y, labelsize.width, labelsize.height)]; 377 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + beforeLabel, y, labelsize.width, labelsize.height)];
378 label.text = pdata.textDescription; 378 label.text = pdata.textDescription;
379 - label.font = [UIFont systemFontOfSize:self.legendFontSize]; 379 + label.textColor = self.legendFontColor ? self.legendFontColor : [UIColor blackColor];
  380 + label.font = self.legendFont ? self.legendFont : [UIFont systemFontOfSize:12.0f];
380 label.lineBreakMode = NSLineBreakByWordWrapping; 381 label.lineBreakMode = NSLineBreakByWordWrapping;
381 label.numberOfLines = 0; 382 label.numberOfLines = 0;
382 383
@@ -80,8 +80,10 @@ @@ -80,8 +80,10 @@
80 80
81 81
82 [self.view addSubview:self.lineChart]; 82 [self.view addSubview:self.lineChart];
83 - self.lineChart.legendStyle = PNLegendItemStyleSerial; 83 +
84 - self.lineChart.legendFontSize = 12.0; 84 + self.lineChart.legendStyle = PNLegendItemStyleStacked;
  85 + self.lineChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
  86 + self.lineChart.legendFontColor = [UIColor redColor];
85 87
86 UIView *legend = [self.lineChart getLegendWithMaxWidth:320]; 88 UIView *legend = [self.lineChart getLegendWithMaxWidth:320];
87 [legend setFrame:CGRectMake(30, 340, legend.frame.size.width, legend.frame.size.width)]; 89 [legend setFrame:CGRectMake(30, 340, legend.frame.size.width, legend.frame.size.width)];
@@ -154,7 +156,7 @@ @@ -154,7 +156,7 @@
154 156
155 157
156 self.pieChart.legendStyle = PNLegendItemStyleStacked; 158 self.pieChart.legendStyle = PNLegendItemStyleStacked;
157 - self.pieChart.legendFontSize = 12.0; 159 + self.pieChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
158 160
159 UIView *legend = [self.pieChart getLegendWithMaxWidth:200]; 161 UIView *legend = [self.pieChart getLegendWithMaxWidth:200];
160 [legend setFrame:CGRectMake(130, 350, legend.frame.size.width, legend.frame.size.height)]; 162 [legend setFrame:CGRectMake(130, 350, legend.frame.size.width, legend.frame.size.height)];