Skip to content

Commit 8775860

Browse files
Revert "Crash fix - Create small clip paths (PhilJay#1895)"
This reverts commit d5df3ad.
1 parent d5df3ad commit 8775860

File tree

4 files changed

+31
-65
lines changed

4 files changed

+31
-65
lines changed

MPChartExample/res/layout/activity_linechart.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
android:layout_margin="8dp"
1919
android:layout_toLeftOf="@+id/tvYMax"
2020
android:layout_marginRight="5dp"
21-
android:max="150"
21+
android:max="200"
2222
android:paddingBottom="12dp" />
2323

2424
<SeekBar
@@ -30,7 +30,7 @@
3030
android:layout_marginBottom="35dp"
3131
android:layout_toLeftOf="@+id/tvXMax"
3232
android:layout_marginRight="5dp"
33-
android:max="1500"
33+
android:max="500"
3434
android:paddingBottom="12dp" />
3535

3636
<TextView

MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected void onCreate(Bundle savedInstanceState) {
111111

112112
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
113113

114-
LimitLine ll1 = new LimitLine(150f, "Upper Limit");
114+
LimitLine ll1 = new LimitLine(130f, "Upper Limit");
115115
ll1.setLineWidth(4f);
116116
ll1.enableDashedLine(10f, 10f, 0f);
117117
ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
@@ -129,7 +129,7 @@ protected void onCreate(Bundle savedInstanceState) {
129129
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
130130
leftAxis.addLimitLine(ll1);
131131
leftAxis.addLimitLine(ll2);
132-
leftAxis.setAxisMaxValue(200f);
132+
leftAxis.setAxisMaxValue(220f);
133133
leftAxis.setAxisMinValue(-50f);
134134
//leftAxis.setYOffset(20f);
135135
leftAxis.enableGridDashedLine(10f, 10f, 0f);

MPChartExample/src/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private LineDataSet createSet() {
157157
LineDataSet set = new LineDataSet(null, "Dynamic Data");
158158
set.setAxisDependency(AxisDependency.LEFT);
159159
set.setColor(ColorTemplate.getHoloBlue());
160-
set.setCircleColors(ColorTemplate.COLORFUL_COLORS);
160+
set.setCircleColor(Color.WHITE);
161161
set.setLineWidth(2f);
162162
set.setCircleRadius(4f);
163163
set.setFillAlpha(65);

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,6 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) {
449449
}
450450
}
451451

452-
protected Path mGenerateFilledPathBuffer = new Path();
453-
454452
/**
455453
* Draws a filled linear path on the canvas.
456454
*
@@ -461,92 +459,60 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) {
461459
*/
462460
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, XBounds bounds) {
463461

464-
final Path filled = mGenerateFilledPathBuffer;
465-
466-
final int startingIndex = bounds.min;
467-
final int endingIndex = bounds.range + bounds.min;
468-
final int indexInterval = 128;
469-
470-
int currentStartIndex = 0;
471-
int currentEndIndex = indexInterval;
472-
int iterations = 0;
473-
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-
462+
Path filled = generateFilledPath(dataSet, bounds);
483463

464+
trans.pathValueToPixel(filled);
484465

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++;
466+
final Drawable drawable = dataSet.getFillDrawable();
467+
if (drawable != null) {
498468

499-
}while(currentStartIndex <= currentEndIndex);
469+
drawFilledPath(c, filled, drawable);
470+
} else {
500471

472+
drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
473+
}
501474
}
502475

476+
protected Path mGenerateFilledPathBuffer = new Path();
503477
/**
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.
478+
* Generates the path that is used for filled drawing.
510479
*
480+
* @param dataSet
511481
* @return
512482
*/
513-
private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) {
483+
private Path generateFilledPath(ILineDataSet dataSet, XBounds bounds) {
514484

515-
final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
516-
final float phaseY = mAnimator.getPhaseY();
485+
float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
486+
float phaseY = mAnimator.getPhaseY();
517487
final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;
518488

519-
final Path filled = outputPath;
489+
Path filled = mGenerateFilledPathBuffer;
520490
filled.reset();
521-
522-
final Entry entry = dataSet.getEntryForIndex(startIndex);
491+
Entry entry = dataSet.getEntryForIndex(bounds.min);
523492

524493
filled.moveTo(entry.getX(), fillMin);
525494
filled.lineTo(entry.getX(), entry.getY() * phaseY);
526495

527496
// create a new path
528-
Entry currentEntry = null;
529-
Entry previousEntry = null;
530-
for (int x = startIndex + 1 ; x <= endIndex ; x++) {
497+
for (int x = bounds.min + 1; x <= bounds.range + bounds.min; x++) {
531498

532-
currentEntry = dataSet.getEntryForIndex(x);
499+
Entry e = dataSet.getEntryForIndex(x);
533500

534-
if (isDrawSteppedEnabled && previousEntry != null) {
535-
filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY);
536-
}
501+
if (isDrawSteppedEnabled) {
502+
final Entry ePrev = dataSet.getEntryForIndex(x - 1);
503+
if (ePrev == null) continue;
537504

538-
filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY);
505+
filled.lineTo(e.getX(), ePrev.getY() * phaseY);
506+
}
539507

540-
previousEntry = currentEntry;
508+
filled.lineTo(e.getX(), e.getY() * phaseY);
541509
}
542510

543511
// close up
544-
if(currentEntry != null) {
545-
filled.lineTo(currentEntry.getX(), fillMin);
546-
}
547-
512+
filled.lineTo(dataSet.getEntryForIndex(bounds.range + bounds.min).getX(), fillMin);
548513
filled.close();
549514

515+
return filled;
550516
}
551517

552518
@Override

0 commit comments

Comments
 (0)