Merge pull request #3642 from pagrzybe/autoscale_restrictions

Option to set restrictions for Y axis autoscaling.
This commit is contained in:
Mick A 2018-05-09 08:29:22 -06:00 committed by GitHub
commit 73054bedc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 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);