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 e84caab76b..2d2782cf85 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 @@ -38,6 +38,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 */ @@ -357,12 +367,57 @@ public boolean needsOffset() { 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);