diff options
author | Daniel Cohen Gindi <danielgindi@gmail.com> | 2020-01-22 13:43:42 +0200 |
---|---|---|
committer | Daniel Cohen Gindi <danielgindi@gmail.com> | 2020-01-22 13:43:42 +0200 |
commit | 13aee592b189fdfc803b6380318dba4853d4c476 (patch) | |
tree | aa2efd216fe4f9b18e7832061805b7efcef59813 | |
parent | c97c8d247f0a882ce1a034d2f08700a5550564f4 (diff) | |
download | MPAndroidChart-13aee592b189fdfc803b6380318dba4853d4c476.tar.gz |
Improve min/max calculation
https://github.com/danielgindi/Charts/pull/3650
-rw-r--r-- | MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java index a4e58c1b..d2071ec5 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java @@ -427,6 +427,26 @@ public class YAxis extends AxisBase { 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 |