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 23, 2020
1 parent 6d5ed58 commit ed6064c
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 ed6064c

Please sign in to comment.