From 8e7feca3c37239499d507b33f63331ba1b516e57 Mon Sep 17 00:00:00 2001 From: Grant Kaming Date: Fri, 1 Apr 2022 13:54:58 -0500 Subject: [PATCH 1/4] Fix Drawable LineChart Fill Bug The LineChart fill draws using intervals to avoid memory issues, but with a larger data set and many different (darker) colors Android does not draw the drawable all the way to the edge of the interval. This makes it look like there are spaces between the fill. Draw a little beyond the existing interval so there are no gaps. --- .../charting/renderer/LineChartRenderer.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 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 a86c16f76b..bb75a797e6 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 @@ -462,14 +462,25 @@ protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, do { currentStartIndex = startingIndex + (iterations * indexInterval); currentEndIndex = currentStartIndex + indexInterval; - currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex; + currentEndIndex = Math.min(currentEndIndex, endingIndex); if (currentStartIndex <= currentEndIndex) { - generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled); + final Drawable drawable = dataSet.getFillDrawable(); + + int startIndex = currentStartIndex; + int endIndex = currentEndIndex; + + // Add a little extra to the path for drawables, larger data sets were showing space between adjacent drawables + if (drawable != null) { + + startIndex = Math.max(0, currentStartIndex - 1); + endIndex = Math.min(endingIndex, currentEndIndex + 1); + } + + generateFilledPath(dataSet, startIndex, endIndex, filled); trans.pathValueToPixel(filled); - final Drawable drawable = dataSet.getFillDrawable(); if (drawable != null) { drawFilledPath(c, filled, drawable); From 8cf9b11ed8b8daa86a3d285f845a6e31aee8da34 Mon Sep 17 00:00:00 2001 From: giantramen Date: Fri, 24 Feb 2023 13:21:00 -0600 Subject: [PATCH 2/4] Update Linear Fill Bugfix Only do it for larger sets so we can still use opacity on smaller datasets. --- .../github/mikephil/charting/renderer/LineChartRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bb75a797e6..2df71adfb4 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 @@ -471,7 +471,7 @@ protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, int endIndex = currentEndIndex; // Add a little extra to the path for drawables, larger data sets were showing space between adjacent drawables - if (drawable != null) { + if (drawable != null && dataSet.getEntryCount() > 200) { startIndex = Math.max(0, currentStartIndex - 1); endIndex = Math.min(endingIndex, currentEndIndex + 1); From 1ff9c0bc7a65a53e393654e994f038dd7b75002e Mon Sep 17 00:00:00 2001 From: giantramen Date: Wed, 17 Jan 2024 12:42:12 -0600 Subject: [PATCH 3/4] Allow Custom Axis Decimals --- .../mikephil/charting/renderer/AxisRenderer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java index 72ea2d17c8..f75fbc047c 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java @@ -243,10 +243,12 @@ else if (last == first && n == 0) { } // set decimals - if (interval < 1) { - mAxis.mDecimals = (int) Math.ceil(-Math.log10(interval)); - } else { - mAxis.mDecimals = 0; + if (!mAxis.mHasCustomDecimals) { + if (interval < 1) { + mAxis.mDecimals = (int) Math.ceil(-Math.log10(interval)); + } else { + mAxis.mDecimals = 0; + } } if (mAxis.isCenterAxisLabelsEnabled()) { From 7c8f583bd900d72e6e1afa24622f46decd94861a Mon Sep 17 00:00:00 2001 From: giantramen Date: Wed, 17 Jan 2024 12:44:51 -0600 Subject: [PATCH 4/4] Allow Custom Axis Decimals 2 --- .../mikephil/charting/components/AxisBase.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java index c90b4fc9b9..c69e2304f4 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java @@ -51,6 +51,11 @@ public abstract class AxisBase extends ComponentBase { * the number of decimal digits to use */ public int mDecimals; + + /** + * if the user set a custom number of decimals + */ + public boolean mHasCustomDecimals = false; /** * the number of label entries the axis should have, default 6 @@ -813,4 +818,13 @@ public void setSpaceMax(float mSpaceMax) { this.mSpaceMax = mSpaceMax; } + + /** + * Sets the number of decimals to use when formatting values on the axis + */ + public void setDecimals(int mDecimals) + { + this.mDecimals = mDecimals; + this.mHasCustomDecimals = true; + } }