@@ -449,6 +449,8 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) { |
449 | 449 | } |
450 | 450 | } |
451 | 451 |
|
| 452 | + protected Path mGenerateFilledPathBuffer = new Path(); |
| 453 | + |
452 | 454 | /** |
453 | 455 | * Draws a filled linear path on the canvas. |
454 | 456 | * |
@@ -459,60 +461,92 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) { |
459 | 461 | */ |
460 | 462 | protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, XBounds bounds) { |
461 | 463 |
|
462 | | - Path filled = generateFilledPath(dataSet, bounds); |
| 464 | + final Path filled = mGenerateFilledPathBuffer; |
463 | 465 |
|
464 | | - trans.pathValueToPixel(filled); |
| 466 | + final int startingIndex = bounds.min; |
| 467 | + final int endingIndex = bounds.range + bounds.min; |
| 468 | + final int indexInterval = 128; |
465 | 469 |
|
466 | | - final Drawable drawable = dataSet.getFillDrawable(); |
467 | | - if (drawable != null) { |
| 470 | + int currentStartIndex = 0; |
| 471 | + int currentEndIndex = indexInterval; |
| 472 | + int iterations = 0; |
468 | 473 |
|
469 | | - drawFilledPath(c, filled, drawable); |
470 | | - } else { |
| 474 | + // Doing this iteratively in order to avoid OutOfMemory errors that can happen on large bounds sets. |
| 475 | + do{ |
| 476 | + currentStartIndex = startingIndex + (iterations * indexInterval); |
| 477 | + currentEndIndex = currentStartIndex + indexInterval; |
| 478 | + currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex; |
| 479 | + |
| 480 | + if(currentStartIndex <= currentEndIndex) { |
| 481 | + generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled); |
| 482 | + |
| 483 | + |
| 484 | + |
| 485 | + trans.pathValueToPixel(filled); |
| 486 | + |
| 487 | + final Drawable drawable = dataSet.getFillDrawable(); |
| 488 | + if (drawable != null) { |
| 489 | + |
| 490 | + drawFilledPath(c, filled, drawable); |
| 491 | + } else { |
| 492 | + |
| 493 | + drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha()); |
| 494 | + } |
| 495 | + } |
| 496 | + |
| 497 | + iterations++; |
| 498 | + |
| 499 | + }while(currentStartIndex <= currentEndIndex); |
471 | 500 |
|
472 | | - drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha()); |
473 | | - } |
474 | 501 | } |
475 | 502 |
|
476 | | - protected Path mGenerateFilledPathBuffer = new Path(); |
477 | 503 | /** |
478 | | - * Generates the path that is used for filled drawing. |
| 504 | + * Generates a path that is used for filled drawing. |
| 505 | + * |
| 506 | + * @param dataSet The dataset from which to read the entries. |
| 507 | + * @param startIndex The index from which to start reading the dataset |
| 508 | + * @param endIndex The index from which to stop reading the dataset |
| 509 | + * @param outputPath The path object that will be assigned the chart data. |
479 | 510 | * |
480 | | - * @param dataSet |
481 | 511 | * @return |
482 | 512 | */ |
483 | | - private Path generateFilledPath(ILineDataSet dataSet, XBounds bounds) { |
| 513 | + private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) { |
484 | 514 |
|
485 | | - float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); |
486 | | - float phaseY = mAnimator.getPhaseY(); |
| 515 | + final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); |
| 516 | + final float phaseY = mAnimator.getPhaseY(); |
487 | 517 | final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED; |
488 | 518 |
|
489 | | - Path filled = mGenerateFilledPathBuffer; |
| 519 | + final Path filled = outputPath; |
490 | 520 | filled.reset(); |
491 | | - Entry entry = dataSet.getEntryForIndex(bounds.min); |
| 521 | + |
| 522 | + final Entry entry = dataSet.getEntryForIndex(startIndex); |
492 | 523 |
|
493 | 524 | filled.moveTo(entry.getX(), fillMin); |
494 | 525 | filled.lineTo(entry.getX(), entry.getY() * phaseY); |
495 | 526 |
|
496 | 527 | // create a new path |
497 | | - for (int x = bounds.min + 1; x <= bounds.range + bounds.min; x++) { |
498 | | - |
499 | | - Entry e = dataSet.getEntryForIndex(x); |
| 528 | + Entry currentEntry = null; |
| 529 | + Entry previousEntry = null; |
| 530 | + for (int x = startIndex + 1 ; x <= endIndex ; x++) { |
500 | 531 |
|
501 | | - if (isDrawSteppedEnabled) { |
502 | | - final Entry ePrev = dataSet.getEntryForIndex(x - 1); |
503 | | - if (ePrev == null) continue; |
| 532 | + currentEntry = dataSet.getEntryForIndex(x); |
504 | 533 |
|
505 | | - filled.lineTo(e.getX(), ePrev.getY() * phaseY); |
| 534 | + if (isDrawSteppedEnabled && previousEntry != null) { |
| 535 | + filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY); |
506 | 536 | } |
507 | 537 |
|
508 | | - filled.lineTo(e.getX(), e.getY() * phaseY); |
| 538 | + filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY); |
| 539 | + |
| 540 | + previousEntry = currentEntry; |
509 | 541 | } |
510 | 542 |
|
511 | 543 | // close up |
512 | | - filled.lineTo(dataSet.getEntryForIndex(bounds.range + bounds.min).getX(), fillMin); |
| 544 | + if(currentEntry != null) { |
| 545 | + filled.lineTo(currentEntry.getX(), fillMin); |
| 546 | + } |
| 547 | + |
513 | 548 | filled.close(); |
514 | 549 |
|
515 | | - return filled; |
516 | 550 | } |
517 | 551 |
|
518 | 552 | @Override |
|