aboutsummaryrefslogtreecommitdiff
path: root/MPChartLib/src/main/java/com/github
diff options
context:
space:
mode:
authorMick A <mick.ashton@flare-esports.net>2018-05-09 08:29:22 -0600
committerGitHub <noreply@github.com>2018-05-09 08:29:22 -0600
commit73054bedc36c32bffa77f23e3be711636c91c136 (patch)
tree164f12c2790c3e5f25f8d3fb7ad49c7f22ba5b9f /MPChartLib/src/main/java/com/github
parent0b6632f2cb4443805bd699def8c60928c7d9919a (diff)
parent92c14db5b4de4efd43c9fd74361886b92111ca9f (diff)
downloadMPAndroidChart-73054bedc36c32bffa77f23e3be711636c91c136.tar.gz
Merge pull request #3642 from pagrzybe/autoscale_restrictions
Option to set restrictions for Y axis autoscaling.
Diffstat (limited to 'MPChartLib/src/main/java/com/github')
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java59
1 files changed, 57 insertions, 2 deletions
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 571e0f39..2381dbf8 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
@@ -39,6 +39,16 @@ public class YAxis extends AxisBase {
protected boolean mDrawZeroLine = false;
/**
+ * flag indicating that auto scale min restriction should be used
+ */
+ private boolean mUseAutoScaleRestrictionMin = false;
+
+ /**
+ * flag indicating that auto scale max restriction should be used
+ */
+ private boolean mUseAutoScaleRestrictionMax = false;
+
+ /**
* Color of the zero line
*/
protected int mZeroLineColor = Color.GRAY;
@@ -357,12 +367,57 @@ public class YAxis extends AxisBase {
return false;
}
+ /**
+ * Returns true if autoscale restriction for axis min value is enabled
+ */
+ public boolean isUseAutoScaleMinRestriction( ) {
+ return mUseAutoScaleRestrictionMin;
+ }
+
+ /**
+ * Sets autoscale restriction for axis min value as enabled/disabled
+ */
+ public void setUseAutoScaleMinRestriction( boolean isEnabled ) {
+ mUseAutoScaleRestrictionMin = isEnabled;
+ }
+
+ /**
+ * Returns true if autoscale restriction for axis max value is enabled
+ */
+ public boolean isUseAutoScaleMaxRestriction() {
+ return mUseAutoScaleRestrictionMax;
+ }
+
+ /**
+ * Sets autoscale restriction for axis max value as enabled/disabled
+ */
+ public void setUseAutoScaleMaxRestriction( boolean isEnabled ) {
+ mUseAutoScaleRestrictionMax = isEnabled;
+ }
+
+
@Override
public void calculate(float dataMin, float dataMax) {
+ float min = dataMin;
+ float max = dataMax;
+
// if custom, use value as is, else use data value
- float min = mCustomAxisMin ? mAxisMinimum : dataMin;
- float max = mCustomAxisMax ? mAxisMaximum : dataMax;
+ 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);