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 c97c8d2 commit 13aee59
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,26 @@ public void calculate(float dataMin, float dataMax) {
float min = dataMin;
float max = 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;
}
}

float range = Math.abs(max - min);

// in case all values are equal
Expand Down

0 comments on commit 13aee59

Please sign in to comment.