Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to set restrictions for Y axis autoscaling. #3642

Merged
merged 2 commits into from
May 9, 2018
Merged

Option to set restrictions for Y axis autoscaling. #3642

merged 2 commits into from
May 9, 2018

Conversation

pagrzybe
Copy link
Contributor

I need to be able to set some restriction on autoscale so I keep autoscale working but also make sure that certain range is always visible.

Tried to do it in the way the rest of the API is done and with as limited changes as possible.

Copy link
Contributor

@almic almic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a good addition here! However, this can be done simply by having two bool flags, that when enabled, switches from using the strictly the mAxisMinimum and mAxisMaximum, to using the min and max only if the auto scale isn't enough. See my line comments.

/**
* Resets min value restriction for autoscale
*/
public void resetAutoScaleMinRestriction() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace both resetAutoScaleMinRestriction() and resetAutoScaleMaxRestriction() with appropriate setUseAutoScale???Restriction() and isUseAutoScale???Restriction() getters and setters.

* restriction value of autoscale min
*/

private float mAutoScaleMinRestriction = 0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove both mAutoScaleMinRestriction and mAutoScaleMaxRestriction variables

/**
* Sets min value restriction for autoscale
*/
public void setAutoScaleMinRestriction(float restrictionValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these two setters: setAutoScaleMinRestriction() and setAutoScaleMaxRestriction()

float max = mCustomAxisMax ? mAxisMaximum : dataMax;
if( mCustomAxisMin ) {
min = mAxisMinimum;
} else if( mUseAutoScaleRestrictionMin ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent this, so that the code checks for mUseAutoScale???Restriction ONLY if mCustomAxisMin is true, that way it uses the same mAxisMinum variable, but it two different possible ways.


if( mCustomAxisMax ) {
max = mAxisMaximum;
} else if( mUseAutoScaleRestrictionMax ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the same with this as above.

@pagrzybe
Copy link
Contributor Author

pagrzybe commented May 9, 2018

Done and tested.

@almic
Copy link
Contributor

almic commented May 9, 2018

LGTM

@almic almic merged commit 73054be into PhilJay:master May 9, 2018
@pagrzybe pagrzybe deleted the autoscale_restrictions branch May 9, 2018 19:01
@almic
Copy link
Contributor

almic commented Oct 29, 2018

Update for @pagrzybe, looks like this already existed with the methods setAxisMaximum() and setAxisMinimum(). I noticed a bug that causes graphs to gradually increase their y axis min and max range, mostly noticeable when dragging left-and-right on the seekbars to change the vertical range. This didn't exist on the horizontal range, however.

I think that the current implementation is good, but if you would like to I encourage you to see if the current version gives you what you wanted. If not, please open another pull request and test your changes by dragging the seekbars on the example app to make sure the ranges aren't drifting.

Sorry, and thanks for your patience!

regas99 pushed a commit to regas99/MPAndroidChart that referenced this pull request Apr 1, 2019
Option to set restrictions for Y axis autoscaling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants