andi

rotation management

@@ -273,10 +273,13 @@ @@ -273,10 +273,13 @@
273 273
274 NSMutableArray *legendViews = [[NSMutableArray alloc] init]; 274 NSMutableArray *legendViews = [[NSMutableArray alloc] init];
275 275
276 - NSUInteger numLabelsPerRow = ceil((float)[self.items count] / self.labelRowsInSerialMode);  
277 -  
278 /* Determine the max width of each legend item */ 276 /* Determine the max width of each legend item */
279 - CGFloat maxLabelWidth = self.legendStyle == PNLegendItemStyleStacked ? (mWidth - beforeLabel) : (mWidth / numLabelsPerRow - beforeLabel); 277 + CGFloat maxLabelWidth;
  278 + if (self.legendStyle == PNLegendItemStyleStacked) {
  279 + maxLabelWidth = mWidth - beforeLabel;
  280 + }else{
  281 + maxLabelWidth = MAXFLOAT;
  282 + }
280 283
281 /* this is used when labels wrap text and the line 284 /* this is used when labels wrap text and the line
282 * should be in the middle of the first row */ 285 * should be in the middle of the first row */
@@ -285,6 +288,7 @@ @@ -285,6 +288,7 @@
285 font:[UIFont systemFontOfSize:self.legendFontSize]].height; 288 font:[UIFont systemFontOfSize:self.legendFontSize]].height;
286 289
287 NSUInteger counter = 0; 290 NSUInteger counter = 0;
  291 + NSUInteger rowWidth = 0;
288 NSUInteger rowMaxHeight = 0; 292 NSUInteger rowMaxHeight = 0;
289 293
290 for (PNPieChartDataItem *pdata in self.items) { 294 for (PNPieChartDataItem *pdata in self.items) {
@@ -293,20 +297,20 @@ @@ -293,20 +297,20 @@
293 withWidth:maxLabelWidth 297 withWidth:maxLabelWidth
294 font:[UIFont systemFontOfSize:self.legendFontSize]]; 298 font:[UIFont systemFontOfSize:self.legendFontSize]];
295 299
296 - 300 + if (rowWidth + labelsize.width > mWidth) {
297 - if (counter != 0 && counter % numLabelsPerRow == 0) { 301 + rowWidth = 0;
298 x = 0; 302 x = 0;
299 y += rowMaxHeight; 303 y += rowMaxHeight;
300 rowMaxHeight = 0; 304 rowMaxHeight = 0;
301 } 305 }
302 - 306 + rowWidth += labelsize.width;
303 // Add inflexion type 307 // Add inflexion type
304 [legendViews addObject:[self drawInflexion:legendCircle * .6 308 [legendViews addObject:[self drawInflexion:legendCircle * .6
305 center:CGPointMake(x + legendCircle / 2, y + singleRowHeight / 2) 309 center:CGPointMake(x + legendCircle / 2, y + singleRowHeight / 2)
306 andColor:pdata.color]]; 310 andColor:pdata.color]];
307 311
308 312
309 - UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + beforeLabel, y, maxLabelWidth, labelsize.height)]; 313 + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + beforeLabel, y, labelsize.width, labelsize.height)];
310 label.text = pdata.textDescription; 314 label.text = pdata.textDescription;
311 label.font = [UIFont systemFontOfSize:self.legendFontSize]; 315 label.font = [UIFont systemFontOfSize:self.legendFontSize];
312 label.lineBreakMode = NSLineBreakByWordWrapping; 316 label.lineBreakMode = NSLineBreakByWordWrapping;
@@ -314,7 +318,7 @@ @@ -314,7 +318,7 @@
314 318
315 319
316 rowMaxHeight = fmaxf(rowMaxHeight, labelsize.height); 320 rowMaxHeight = fmaxf(rowMaxHeight, labelsize.height);
317 - x += self.legendStyle == PNLegendItemStyleStacked ? 0 : maxLabelWidth + beforeLabel; 321 + x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + beforeLabel;
318 y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0; 322 y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0;
319 323
320 324