Skip to content

Commit

Permalink
Improve min/max calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 22, 2020
1 parent 96619a7 commit a16b339
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,26 @@ public void calculate(float dataMin, float dataMax) {
float min = mCustomAxisMin ? mAxisMinimum : dataMin;
float max = mCustomAxisMax ? mAxisMaximum : dataMax;

// Make sure max is greater than min
// Discussion: https://github.com/danielgindi/Charts/pull/3650#discussion_r221409991
if (min > max)
{
if (mCustomAxisMax && mCustomAxisMin)
{
float t = min;
min = max;
max = t;
}
else if (mCustomAxisMax)
{
min = max < 0f ? max * 1.5f : max * 0.5f;
}
else if (mCustomAxisMin)
{
max = min < 0f ? min * 0.5f : min * 1.5f;
}
}

// temporary range (before calculations)
float range = Math.abs(max - min);

Expand Down

0 comments on commit a16b339

Please sign in to comment.