Skip to content

Commit 13aee59

Browse files
committed
Improve min/max calculation
ChartsOrg/Charts#3650
1 parent c97c8d2 commit 13aee59

File tree

1 file changed

+20
-0
lines changed
  • MPChartLib/src/main/java/com/github/mikephil/charting/components

1 file changed

+20
-0
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,26 @@ public void calculate(float dataMin, float dataMax) {
427427
float min = dataMin;
428428
float max = dataMax;
429429

430+
// Make sure max is greater than min
431+
// Discussion: https://github.com/danielgindi/Charts/pull/3650#discussion_r221409991
432+
if (min > max)
433+
{
434+
if (mCustomAxisMax && mCustomAxisMin)
435+
{
436+
float t = min;
437+
min = max;
438+
max = t;
439+
}
440+
else if (mCustomAxisMax)
441+
{
442+
min = max < 0f ? max * 1.5f : max * 0.5f;
443+
}
444+
else if (mCustomAxisMin)
445+
{
446+
max = min < 0f ? min * 0.5f : min * 1.5f;
447+
}
448+
}
449+
430450
float range = Math.abs(max - min);
431451

432452
// in case all values are equal

0 commit comments

Comments
 (0)