From e14147af9c9df9d4c3917b21431c6264d4bdbd24 Mon Sep 17 00:00:00 2001 From: angcyo Date: Sat, 11 Apr 2020 16:40:19 +0800 Subject: [PATCH 1/5] * update gradle --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index cee7a83e80..e39c65dee0 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:3.6.2' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f8bc4e375..52a8bd35b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Apr 27 15:48:29 CEST 2019 +#Sat Apr 11 16:37:45 CST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip From 7d4ded561151f8771bfb817d50f9e237f1cfbedf Mon Sep 17 00:00:00 2001 From: angcyo Date: Sat, 11 Apr 2020 16:58:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?+=20Entry=20=E6=94=AF=E6=8C=81=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E6=8E=A7=E5=88=B6=20Draw=20Value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/mikephil/charting/data/BaseEntry.java | 11 +++++++++++ .../charting/renderer/BarChartRenderer.java | 6 +++--- .../charting/renderer/BubbleChartRenderer.java | 2 +- .../renderer/CandleStickChartRenderer.java | 2 +- .../renderer/HorizontalBarChartRenderer.java | 6 +++--- .../charting/renderer/LineChartRenderer.java | 2 +- .../charting/renderer/PieChartRenderer.java | 16 ++++++++++++---- .../charting/renderer/RadarChartRenderer.java | 2 +- .../charting/renderer/ScatterChartRenderer.java | 2 +- 9 files changed, 34 insertions(+), 15 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseEntry.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseEntry.java index eb1ada84d8..a2f672df16 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseEntry.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseEntry.java @@ -16,6 +16,9 @@ public abstract class BaseEntry { /** optional icon image */ private Drawable mIcon = null; + /**单独控制是否绘制value*/ + private boolean mDrawValue = true; + public BaseEntry() { } @@ -94,4 +97,12 @@ public Object getData() { public void setData(Object data) { this.mData = data; } + + public boolean isDrawValue() { + return mDrawValue; + } + + public void setDrawValue(boolean mDrawValue) { + this.mDrawValue = mDrawValue; + } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java index 18975557cd..a878a147da 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java @@ -264,7 +264,7 @@ public void drawValues(Canvas c) { BarEntry entry = dataSet.getEntryForIndex(j / 4); float val = entry.getY(); - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getBarLabel(entry), x, val >= 0 ? (buffer.buffer[j + 1] + posOffset) : (buffer.buffer[j + 3] + negOffset), @@ -322,7 +322,7 @@ public void drawValues(Canvas c) { || !mViewPortHandler.isInBoundsLeft(x)) continue; - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getBarLabel(entry), x, buffer.buffer[bufferIndex + 1] + (entry.getY() >= 0 ? posOffset : negOffset), color); @@ -393,7 +393,7 @@ public void drawValues(Canvas c) { || !mViewPortHandler.isInBoundsLeft(x)) continue; - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getBarStackedLabel(val, entry), x, y, color); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java index be141c46a0..7975443727 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java @@ -173,7 +173,7 @@ public void drawValues(Canvas c) { BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getBubbleLabel(entry), x, y + (0.5f * lineHeight), valueTextColor); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java index 027dda31d8..6b53ef48c4 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java @@ -298,7 +298,7 @@ public void drawValues(Canvas c) { CandleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getCandleLabel(entry), x, y - yOffset, dataSet.getValueTextColor(j / 2)); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java index b42ef1284a..f3bd054933 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java @@ -223,7 +223,7 @@ public void drawValues(Canvas c) { negOffset = -negOffset - valueTextWidth; } - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formattedValue, buffer.buffer[j + 2] + (val >= 0 ? posOffset : negOffset), @@ -292,7 +292,7 @@ public void drawValues(Canvas c) { negOffset = -negOffset - valueTextWidth; } - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formattedValue, buffer.buffer[bufferIndex + 2] + (entry.getY() >= 0 ? posOffset : negOffset), @@ -379,7 +379,7 @@ public void drawValues(Canvas c) { if (!mViewPortHandler.isInBoundsBottom(y)) continue; - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formattedValue, x, y + halfTextHeight, color); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java index a00860b5a6..3d01738705 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java @@ -581,7 +581,7 @@ public void drawValues(Canvas c) { Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getPointLabel(entry), x, y - valOffset, dataSet.getValueTextColor(j / 2)); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java index f427ffe5d3..fabac59f4e 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java @@ -583,7 +583,9 @@ else if (valueLineColor != ColorTemplate.COLOR_NONE) // draw everything, depending on settings if (drawXOutside && drawYOutside) { - drawValue(c, formattedValue, labelPtx, labelPty, dataSet.getValueTextColor(j)); + if (entry.isDrawValue()) { + drawValue(c, formattedValue, labelPtx, labelPty, dataSet.getValueTextColor(j)); + } if (j < data.getEntryCount() && entryLabel != null) { drawEntryLabel(c, entryLabel, labelPtx, labelPty + lineHeight); @@ -595,7 +597,9 @@ else if (valueLineColor != ColorTemplate.COLOR_NONE) } } else if (drawYOutside) { - drawValue(c, formattedValue, labelPtx, labelPty + lineHeight / 2.f, dataSet.getValueTextColor(j)); + if (entry.isDrawValue()) { + drawValue(c, formattedValue, labelPtx, labelPty + lineHeight / 2.f, dataSet.getValueTextColor(j)); + } } } @@ -609,7 +613,9 @@ else if (valueLineColor != ColorTemplate.COLOR_NONE) // draw everything, depending on settings if (drawXInside && drawYInside) { - drawValue(c, formattedValue, x, y, dataSet.getValueTextColor(j)); + if (entry.isDrawValue()) { + drawValue(c, formattedValue, x, y, dataSet.getValueTextColor(j)); + } if (j < data.getEntryCount() && entryLabel != null) { drawEntryLabel(c, entryLabel, x, y + lineHeight); @@ -620,7 +626,9 @@ else if (valueLineColor != ColorTemplate.COLOR_NONE) drawEntryLabel(c, entryLabel, x, y + lineHeight / 2f); } } else if (drawYInside) { - drawValue(c, formattedValue, x, y + lineHeight / 2f, dataSet.getValueTextColor(j)); + if (entry.isDrawValue()) { + drawValue(c, formattedValue, x, y + lineHeight / 2f, dataSet.getValueTextColor(j)); + } } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java index 3f932f8725..fc9328eb0b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java @@ -190,7 +190,7 @@ public void drawValues(Canvas c) { sliceangle * j * phaseX + mChart.getRotationAngle(), pOut); - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getRadarLabel(entry), pOut.x, pOut.y - yoffset, dataSet.getValueTextColor(j)); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java index 98dddb93f9..bb5dabc57a 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java @@ -136,7 +136,7 @@ public void drawValues(Canvas c) { Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); - if (dataSet.isDrawValuesEnabled()) { + if (dataSet.isDrawValuesEnabled() && entry.isDrawValue()) { drawValue(c, formatter.getPointLabel(entry), positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min)); } From 8a19aef3ee4c2cf30446d2b6398ae851b32cb0a2 Mon Sep 17 00:00:00 2001 From: angcyo Date: Sat, 11 Apr 2020 17:28:50 +0800 Subject: [PATCH 3/5] =?UTF-8?q?+=20description=20=E6=94=AF=E6=8C=81=20grav?= =?UTF-8?q?ity=20=E5=AE=9A=E4=BD=8D=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mikephil/charting/charts/Chart.java | 65 +++++++++++++++++-- .../charting/components/Description.java | 15 ++++- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java index b104935d30..ef6068e411 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java @@ -13,19 +13,19 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Environment; import android.provider.MediaStore.Images; -import androidx.annotation.RequiresApi; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; +import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; +import androidx.annotation.RequiresApi; + import com.github.mikephil.charting.animation.ChartAnimator; -import com.github.mikephil.charting.animation.Easing; import com.github.mikephil.charting.animation.Easing.EasingFunction; import com.github.mikephil.charting.components.Description; import com.github.mikephil.charting.components.IMarker; @@ -442,18 +442,71 @@ protected void drawDescription(Canvas c) { mDescPaint.setColor(mDescription.getTextColor()); mDescPaint.setTextAlign(mDescription.getTextAlign()); + String descriptionText = mDescription.getText(); + + float textHeight = mDescPaint.descent() - mDescPaint.ascent(); + float textWidth; + + if (TextUtils.isEmpty(descriptionText)) { + textWidth = 0f; + } else { + textWidth= mDescPaint.measureText(descriptionText); + } + float x, y; // if no position specified, draw on default position if (position == null) { - x = getWidth() - mViewPortHandler.offsetRight() - mDescription.getXOffset(); - y = getHeight() - mViewPortHandler.offsetBottom() - mDescription.getYOffset(); + //x = getWidth() - mViewPortHandler.offsetRight() - mDescription.getXOffset(); + //y = getHeight() - mViewPortHandler.offsetBottom() - mDescription.getYOffset(); + + float xOffset = mDescription.getXOffset(); + float yOffset = mDescription.getYOffset(); + + final int width = getWidth(); + final int height = getHeight(); + + int gravity = mDescription.getGravity(); + if (gravity == -1) { + gravity = Gravity.RIGHT | Gravity.BOTTOM; + } + + final int layoutDirection = 0; + final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); + final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; + + switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { + case Gravity.CENTER_HORIZONTAL: + x = mViewPortHandler.offsetLeft() + (mViewPortHandler.contentWidth() - textWidth) / 2 + xOffset; + break; + case Gravity.RIGHT: + x = width - textWidth - mViewPortHandler.offsetRight() - xOffset; + break; + case Gravity.LEFT: + default: + x = mViewPortHandler.offsetLeft() + xOffset; + } + + switch (verticalGravity) { + case Gravity.TOP: + y = mViewPortHandler.offsetTop() + yOffset; + break; + case Gravity.CENTER_VERTICAL: + y = mViewPortHandler.offsetTop() + (mViewPortHandler.contentHeight() - textHeight) / 2 + yOffset; + break; + case Gravity.BOTTOM: + y = height - mViewPortHandler.offsetBottom() - yOffset; + break; + default: + y = mViewPortHandler.offsetTop() + textHeight + yOffset; + } + } else { x = position.x; y = position.y; } - c.drawText(mDescription.getText(), x, y, mDescPaint); + c.drawText(descriptionText, x, y, mDescPaint); } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java index 18294a3270..a3033986e3 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java @@ -1,6 +1,8 @@ package com.github.mikephil.charting.components; import android.graphics.Paint; +import android.view.Gravity; +import android.widget.TextView; import com.github.mikephil.charting.utils.MPPointF; import com.github.mikephil.charting.utils.Utils; @@ -23,7 +25,10 @@ public class Description extends ComponentBase { /** * the alignment of the description text */ - private Paint.Align mTextAlign = Paint.Align.RIGHT; + private Paint.Align mTextAlign = Paint.Align.LEFT; + + /**@see TextView#setGravity(int)*/ + private int mGravity = Gravity.RIGHT | Gravity.BOTTOM; public Description() { super(); @@ -92,4 +97,12 @@ public void setTextAlign(Paint.Align align) { public Paint.Align getTextAlign() { return mTextAlign; } + + public int getGravity() { + return mGravity; + } + + public void setGravity(int gravity) { + this.mGravity = gravity; + } } From 119cdaac17d45e5649e5578f8928a96e2da915e0 Mon Sep 17 00:00:00 2001 From: angcyo Date: Wed, 15 Apr 2020 18:26:55 +0800 Subject: [PATCH 4/5] * fix line chart entry draw value control --- .../mikephil/charting/charts/Chart.java | 2 +- .../charting/highlight/ChartHighlighter.java | 2 +- .../charting/renderer/LineChartRenderer.java | 28 ++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java index ef6068e411..a391dac526 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java @@ -846,7 +846,7 @@ protected void drawMarkers(Canvas canvas) { int entryIndex = set.getEntryIndex(e); // make sure entry not null - if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX()) + if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX() || !e.isDrawValue()) continue; float[] pos = getMarkerPosition(highlight); diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java index f889bf19d4..7055e14b9a 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java @@ -166,7 +166,7 @@ protected List buildHighlights(IDataSet set, int dataSetIndex, float if (entries.size() == 0) { // Try to find closest x-value and take all entries for that x-value final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding); - if (closest != null) + if (closest != null && closest.isDrawValue()) { //noinspection unchecked entries = set.getEntriesForXValue(closest.getX()); diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java index 3d01738705..fb70f81dfa 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java @@ -333,7 +333,7 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) { for (int j = mXBounds.min; j < max; j++) { Entry e = dataSet.getEntryForIndex(j); - if (e == null) continue; + if (e == null || !e.isDrawValue()) continue; mLineBuffer[0] = e.getX(); mLineBuffer[1] = e.getY() * phaseY; @@ -342,7 +342,7 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) { e = dataSet.getEntryForIndex(j + 1); - if (e == null) break; + if (e == null || !e.isDrawValue()) break; if (isDrawSteppedEnabled) { mLineBuffer[2] = e.getX(); @@ -398,7 +398,7 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) { e1 = dataSet.getEntryForIndex(mXBounds.min); - if (e1 != null) { + if (e1 != null && e1.isDrawValue()) { int j = 0; for (int x = mXBounds.min; x <= mXBounds.range + mXBounds.min; x++) { @@ -406,7 +406,7 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) { e1 = dataSet.getEntryForIndex(x == 0 ? 0 : (x - 1)); e2 = dataSet.getEntryForIndex(x); - if (e1 == null || e2 == null) continue; + if (e1 == null || e2 == null || !e2.isDrawValue()) continue; mLineBuffer[j++] = e1.getX(); mLineBuffer[j++] = e1.getY() * phaseY; @@ -516,6 +516,22 @@ private void generateFilledPath(final ILineDataSet dataSet, final int startIndex currentEntry = dataSet.getEntryForIndex(x); + if (!currentEntry.isDrawValue()) { + //当前不需要绘制value + if (previousEntry.isDrawValue()) { + //上一个需要绘制value + filled.lineTo(previousEntry.getX(), fillMin); + } + previousEntry = currentEntry; + continue; + } + + if (!previousEntry.isDrawValue()) { + //上一次不需要绘制Value, 但是这次需要 + filled.moveTo(previousEntry.getX(), fillMin); + filled.lineTo(previousEntry.getX(), previousEntry.getY() * phaseY); + } + if (isDrawSteppedEnabled) { filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY); } @@ -682,6 +698,10 @@ protected void drawCircles(Canvas c) { if (e == null) break; + if (!e.isDrawValue()) { + continue; + } + mCirclesBuffer[0] = e.getX(); mCirclesBuffer[1] = e.getY() * phaseY; From 81d62e832017c54410cb52236aad60668e91b5ab Mon Sep 17 00:00:00 2001 From: angcyo Date: Wed, 15 Apr 2020 18:52:52 +0800 Subject: [PATCH 5/5] * fix line chart entry draw value control #2 --- .../charting/renderer/LineChartRenderer.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java index fb70f81dfa..739aa2be3a 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java @@ -154,6 +154,11 @@ protected void drawHorizontalBezier(ILineDataSet dataSet) { prev = cur; cur = dataSet.getEntryForIndex(j); + if (!cur.isDrawValue()) { + //不支持分段, 第一个不绘制的Value开始中断绘制. + break; + } + final float cpx = (prev.getX()) + (cur.getX() - prev.getX()) / 2.0f; @@ -217,7 +222,7 @@ protected void drawCubicBezier(ILineDataSet dataSet) { Entry next = cur; int nextIndex = -1; - if (cur == null) return; + if (cur == null || !cur.isDrawValue()) return; // let the spline start cubicPath.moveTo(cur.getX(), cur.getY() * phaseY); @@ -228,6 +233,11 @@ protected void drawCubicBezier(ILineDataSet dataSet) { prev = cur; cur = nextIndex == j ? next : dataSet.getEntryForIndex(j); + if (!cur.isDrawValue()) { + //不支持分段, 第一个不绘制的Value开始中断绘制. + break; + } + nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j; next = dataSet.getEntryForIndex(nextIndex); @@ -267,7 +277,19 @@ protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transf float fillMin = dataSet.getFillFormatter() .getFillLinePosition(dataSet, mChart); - spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).getX(), fillMin); + Entry endEntry = null; + Entry curEntry = null; + for (int i = bounds.min; i <= bounds.min + bounds.range; i++) { + curEntry = dataSet.getEntryForIndex(i); + if (!curEntry.isDrawValue()) { + break; + } + endEntry = curEntry; + } + + if (endEntry != null) { + spline.lineTo(endEntry.getX(), fillMin); + } spline.lineTo(dataSet.getEntryForIndex(bounds.min).getX(), fillMin); spline.close();