aboutsummaryrefslogtreecommitdiff
path: root/MPChartLib/src
diff options
context:
space:
mode:
authoralmic <mick.ashton@flare-esports.net>2018-10-26 10:30:22 -0600
committeralmic <mick.ashton@flare-esports.net>2018-10-26 10:30:22 -0600
commitd67ea481af1e8528c617dfd404d0c7827b0134b2 (patch)
tree3a7ffdd7c36c0861cb9e046fe8036b6be405fd40 /MPChartLib/src
parent20bca4a8ca6a6d9e0c508ec6363d387df1aaa999 (diff)
downloadMPAndroidChart-d67ea481af1e8528c617dfd404d0c7827b0134b2.tar.gz
Huge Project Refresh
Before anyone freaks out, all these changes are under-the-hood, meaning that you probably won't even notice them at all. The biggest difference is raising the minSdkVersion from 9 to 14. Recently android bumped this number interally as there are basically no devices running lower than 14 anymore. Sorry but you are just wasting your time if you are trying to support anything lower than 14 now. The next biggest change is updating the project to the new AndroidX libraries, which changes some imports and nothing else really. The third biggest change is fixing a few bugs in the code that cause values to be drawn even if there are none, which results in your app crashing. Surprisingly, these checks already existed in a few of the newer chart types, but most lacked this simple check. Other than those three changes, nothing else is functionally different. Well, saving to gallery works on all charts in the example app now, and you can quickly see the code for each example in the menus. The only real potential "breaking" change is that charts are now saved as PNGs by default instead of JPGs if you go the route of not specifying as a JPG. You may want to double check your file sizes as PNGs can be larger than low quality JPGs. I still have more plans for simplifying the API and fixing other issues with the project, for the small few that closely pay attention to individual commits: there's going to be more soon.
Diffstat (limited to 'MPChartLib/src')
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/animation/ChartAnimator.java2
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/animation/Easing.java3
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java17
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java36
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.java1
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java5
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java2
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java6
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java5
9 files changed, 41 insertions, 36 deletions
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/animation/ChartAnimator.java b/MPChartLib/src/main/java/com/github/mikephil/charting/animation/ChartAnimator.java
index 026a1b30..b33b3fb6 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/animation/ChartAnimator.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/animation/ChartAnimator.java
@@ -3,7 +3,7 @@ package com.github.mikephil.charting.animation;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
-import android.support.annotation.RequiresApi;
+import androidx.annotation.RequiresApi;
import com.github.mikephil.charting.animation.Easing.EasingFunction;
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/animation/Easing.java b/MPChartLib/src/main/java/com/github/mikephil/charting/animation/Easing.java
index 631e313b..2c64777a 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/animation/Easing.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/animation/Easing.java
@@ -2,7 +2,7 @@
package com.github.mikephil.charting.animation;
import android.animation.TimeInterpolator;
-import android.support.annotation.RequiresApi;
+import androidx.annotation.RequiresApi;
/**
* Easing options.
@@ -62,7 +62,6 @@ public class Easing {
* @param easing EasingOption to get
* @return EasingFunction
*/
- @SuppressWarnings("deprecation")
@Deprecated
public static EasingFunction getEasingFunctionFromOption(EasingOption easing) {
switch (easing) {
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 35ec2ec1..718d7e2a 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
@@ -17,7 +17,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore.Images;
-import android.support.annotation.RequiresApi;
+import androidx.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -1527,6 +1527,8 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
*/
public boolean saveToPath(String title, String pathOnSD) {
+
+
Bitmap b = getChartBitmap();
OutputStream stream = null;
@@ -1642,7 +1644,18 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
* @return returns true if saving was successful, false if not
*/
public boolean saveToGallery(String fileName, int quality) {
- return saveToGallery(fileName, "", "MPAndroidChart-Library Save", Bitmap.CompressFormat.JPEG, quality);
+ return saveToGallery(fileName, "", "MPAndroidChart-Library Save", Bitmap.CompressFormat.PNG, quality);
+ }
+
+ /**
+ * Saves the current state of the chart to the gallery as a PNG image.
+ * NOTE: Needs permission WRITE_EXTERNAL_STORAGE
+ *
+ * @param fileName e.g. "my_image"
+ * @return returns true if saving was successful, false if not
+ */
+ public boolean saveToGallery(String fileName) {
+ return saveToGallery(fileName, "", "MPAndroidChart-Library Save", Bitmap.CompressFormat.PNG, 40);
}
/**
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java
index 2381dbf8..030603f5 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java
@@ -370,6 +370,7 @@ public class YAxis extends AxisBase {
/**
* Returns true if autoscale restriction for axis min value is enabled
*/
+ @Deprecated
public boolean isUseAutoScaleMinRestriction( ) {
return mUseAutoScaleRestrictionMin;
}
@@ -377,6 +378,7 @@ public class YAxis extends AxisBase {
/**
* Sets autoscale restriction for axis min value as enabled/disabled
*/
+ @Deprecated
public void setUseAutoScaleMinRestriction( boolean isEnabled ) {
mUseAutoScaleRestrictionMin = isEnabled;
}
@@ -384,6 +386,7 @@ public class YAxis extends AxisBase {
/**
* Returns true if autoscale restriction for axis max value is enabled
*/
+ @Deprecated
public boolean isUseAutoScaleMaxRestriction() {
return mUseAutoScaleRestrictionMax;
}
@@ -391,6 +394,7 @@ public class YAxis extends AxisBase {
/**
* Sets autoscale restriction for axis max value as enabled/disabled
*/
+ @Deprecated
public void setUseAutoScaleMaxRestriction( boolean isEnabled ) {
mUseAutoScaleRestrictionMax = isEnabled;
}
@@ -402,24 +406,6 @@ public class YAxis extends AxisBase {
float min = dataMin;
float max = dataMax;
- // if custom, use value as is, else use data value
- if( mCustomAxisMin ) {
- if( mUseAutoScaleRestrictionMin ) {
- min = Math.min( dataMin, mAxisMinimum );
- } else {
- min = mAxisMinimum;
- }
- }
-
- if( mCustomAxisMax ) {
- if( mUseAutoScaleRestrictionMax ) {
- max = Math.max( max, mAxisMaximum );
- } else {
- max = mAxisMaximum;
- }
- }
-
- // temporary range (before calculations)
float range = Math.abs(max - min);
// in case all values are equal
@@ -428,13 +414,13 @@ public class YAxis extends AxisBase {
min = min - 1f;
}
- float bottomSpace = range / 100f * getSpaceBottom();
- this.mAxisMinimum = (min - bottomSpace);
-
- float topSpace = range / 100f * getSpaceTop();
- this.mAxisMaximum = (max + topSpace);
+ // recalculate
+ range = Math.abs(max - min);
+
+ // calc extra spacing
+ this.mAxisMinimum = mCustomAxisMin ? this.mAxisMinimum : min - (range / 100f) * getSpaceBottom();
+ this.mAxisMaximum = mCustomAxisMax ? this.mAxisMaximum : max + (range / 100f) * getSpaceTop();
- // calc actual range
- this.mAxisRange = Math.abs(this.mAxisMaximum - this.mAxisMinimum);
+ this.mAxisRange = Math.abs(this.mAxisMinimum - this.mAxisMaximum);
}
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.java b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.java
index 52761747..d3527f92 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.java
@@ -45,6 +45,7 @@ public class PieRadarChartTouchListener extends ChartTouchListener<PieRadarChart
return true;
// if rotation by touch is enabled
+ // TODO: Also check if the pie itself is being touched, rather than the entire chart area
if (mChart.isRotationEnabled()) {
float x = event.getX();
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 17bba048..d53dcd47 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
@@ -67,6 +67,9 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
protected void drawDataSet(Canvas c, IBubbleDataSet dataSet) {
+ if (dataSet.getEntryCount() < 1)
+ return;
+
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float phaseY = mAnimator.getPhaseY();
@@ -131,7 +134,7 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
IBubbleDataSet dataSet = dataSets.get(i);
- if (!shouldDrawValues(dataSet))
+ if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1)
continue;
// apply the text-styling defined by the DataSet
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 e4c06fe4..991b7021 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
@@ -264,7 +264,7 @@ public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
ICandleDataSet dataSet = dataSets.get(i);
- if (!shouldDrawValues(dataSet))
+ if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1)
continue;
// apply the text-styling defined by the DataSet
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 a0e17775..744bf654 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
@@ -497,12 +497,12 @@ public class LineChartRenderer extends LineRadarRenderer {
// create a new path
Entry currentEntry = null;
- Entry previousEntry = null;
+ Entry previousEntry = entry;
for (int x = startIndex + 1; x <= endIndex; x++) {
currentEntry = dataSet.getEntryForIndex(x);
- if (isDrawSteppedEnabled && previousEntry != null) {
+ if (isDrawSteppedEnabled) {
filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY);
}
@@ -530,7 +530,7 @@ public class LineChartRenderer extends LineRadarRenderer {
ILineDataSet dataSet = dataSets.get(i);
- if (!shouldDrawValues(dataSet))
+ if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1)
continue;
// apply the text-styling defined by the DataSet
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 36a38a53..ccd077e5 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
@@ -49,6 +49,9 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {
+ if (dataSet.getEntryCount() < 1)
+ return;
+
ViewPortHandler viewPortHandler = mViewPortHandler;
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
@@ -101,7 +104,7 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
IScatterDataSet dataSet = dataSets.get(i);
- if (!shouldDrawValues(dataSet))
+ if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1)
continue;
// apply the text-styling defined by the DataSet