diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index 710e50b2..572c4b87 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -828,6 +828,8 @@ namespace XCharts.Runtime public double GetLogMinIndex() { + if (context.minValue <= 0 || context.minValue == 1) + return 0; return logBaseE ? Math.Log(context.minValue) : Math.Log(context.minValue, logBase); @@ -835,6 +837,8 @@ namespace XCharts.Runtime public double GetLogMaxIndex() { + if (context.maxValue <= 0 || context.maxValue == 1) + return 0; return logBaseE ? Math.Log(context.maxValue) : Math.Log(context.maxValue, logBase); diff --git a/Runtime/Component/Axis/AxisHelper.cs b/Runtime/Component/Axis/AxisHelper.cs index ff39cb7b..b70c62b4 100644 --- a/Runtime/Component/Axis/AxisHelper.cs +++ b/Runtime/Component/Axis/AxisHelper.cs @@ -344,7 +344,8 @@ namespace XCharts.Runtime int maxSplit = 0; maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit); minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit); - var splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit); + + var splitNumber = maxSplit + minSplit; if (splitNumber > 15) splitNumber = 15; axis.splitNumber = splitNumber; diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index c32f6a88..c4d59f21 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -682,7 +682,7 @@ namespace XCharts.Runtime public static double GetMaxDivisibleValue(double max, double ceilRate) { if (max == 0) return 0; - double pow = 1; + double pow = 1; if (max > -1 && max < 1) { pow = Mathf.Pow(10, MathUtil.GetPrecision(max)); @@ -739,7 +739,7 @@ namespace XCharts.Runtime public static double GetMinDivisibleValue(double min, double ceilRate) { if (min == 0) return 0; - double pow = 1; + double pow = 1; if (min > -1 && min < 1) { pow = Mathf.Pow(10, MathUtil.GetPrecision(min)); @@ -770,20 +770,13 @@ namespace XCharts.Runtime public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber) { - splitNumber = 0; + splitNumber = 1; if (value <= 0) return 0; - double max = 0; + double max = isLogBaseE ? Math.Exp(splitNumber) : Math.Pow(logBase, splitNumber); while (max < value) { - if (isLogBaseE) - { - max = Math.Exp(splitNumber); - } - else - { - max = Math.Pow(logBase, splitNumber); - } splitNumber++; + max = isLogBaseE ? Math.Exp(splitNumber) : Math.Pow(logBase, splitNumber); } return max; } @@ -791,19 +784,13 @@ namespace XCharts.Runtime public static double GetMinLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber) { splitNumber = 0; + if (value <= 0) return 0; if (value > 1) return 1; - double min = 1; + double min = isLogBaseE ? Math.Exp(-splitNumber) : Math.Pow(logBase, -splitNumber); while (min > value) { - if (isLogBaseE) - { - min = Math.Exp(-splitNumber); - } - else - { - min = Math.Pow(logBase, -splitNumber); - } splitNumber++; + min = isLogBaseE ? Math.Exp(-splitNumber) : Math.Pow(logBase, -splitNumber); } return min; }