修复最大值小于10的浮点数图表显示异常

This commit is contained in:
monitor1394
2019-06-18 02:42:35 +08:00
parent b118081deb
commit 105637fb64
2 changed files with 8 additions and 11 deletions

View File

@@ -235,8 +235,8 @@ namespace XCharts
} }
else else
{ {
minVaule = (int)min; minVaule = Mathf.FloorToInt(min);
maxValue = (int)max; maxValue = Mathf.CeilToInt(max);
} }
} }

View File

@@ -483,7 +483,7 @@ namespace XCharts
public static int GetMaxDivisibleValue(float max) public static int GetMaxDivisibleValue(float max)
{ {
if (max == 0) return 0; if (max == 0) return 0;
int bigger = (int)Mathf.Abs(max); int bigger = Mathf.CeilToInt(Mathf.Abs(max));
int n = 1; int n = 1;
while (bigger / (Mathf.Pow(10, n)) > 10) while (bigger / (Mathf.Pow(10, n)) > 10)
{ {
@@ -495,14 +495,14 @@ namespace XCharts
mm = bigger - bigger % (Mathf.Pow(10, n)); mm = bigger - bigger % (Mathf.Pow(10, n));
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n); mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
} }
if (max < 0) return (int)-mm; if (max < 0) return -Mathf.CeilToInt(mm);
else return (int)mm; else return Mathf.CeilToInt(mm);
} }
public static int GetMinDivisibleValue(float min) public static int GetMinDivisibleValue(float min)
{ {
if (min == 0) return 0; if (min == 0) return 0;
int bigger = (int)Mathf.Abs(min); int bigger = Mathf.FloorToInt(Mathf.Abs(min));
int n = 1; int n = 1;
while (bigger / (Mathf.Pow(10, n)) > 10) while (bigger / (Mathf.Pow(10, n)) > 10)
{ {
@@ -514,11 +514,8 @@ namespace XCharts
mm = bigger - bigger % (Mathf.Pow(10, n)); mm = bigger - bigger % (Mathf.Pow(10, n));
mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n); mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
} }
if (min < 0) if (min < 0) return -Mathf.FloorToInt(mm);
{ else return Mathf.FloorToInt(mm);
return (int)-mm;
}
else return (int)mm;
} }
public static void AddEventListener(GameObject obj, EventTriggerType type, public static void AddEventListener(GameObject obj, EventTriggerType type,