mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 09:20:08 +00:00
优化Axis的数值Label的默认显示格式
This commit is contained in:
@@ -53,10 +53,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (string.IsNullOrEmpty(formatter))
|
||||
{
|
||||
if (value - (int) value == 0)
|
||||
s_NumberToStr[value][formatter] = ((int) value).ToString();
|
||||
else
|
||||
s_NumberToStr[value][formatter] = value.ToString();
|
||||
s_NumberToStr[value][formatter] = value.ToString();
|
||||
}
|
||||
else if (formatter.StartsWith(NUMERIC_FORMATTER_D) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_d) ||
|
||||
@@ -64,7 +61,7 @@ namespace XCharts.Runtime
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_x)
|
||||
)
|
||||
{
|
||||
s_NumberToStr[value][formatter] = ((int) value).ToString(formatter, ci);
|
||||
s_NumberToStr[value][formatter] = ((int)value).ToString(formatter, ci);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -782,19 +782,7 @@ namespace XCharts.Runtime
|
||||
return min;
|
||||
}
|
||||
|
||||
public static int GetFloatAccuracy(double value)
|
||||
{
|
||||
if (value > 1 || value < -1) return 0;
|
||||
int count = 1;
|
||||
int intvalue = (int) (value * Mathf.Pow(10, count));
|
||||
while (intvalue == 0 && count < 38)
|
||||
{
|
||||
count++;
|
||||
intvalue = (int) (value * Mathf.Pow(10, count));
|
||||
}
|
||||
if (count == 38 && (value == 0 || value == 1)) return 1;
|
||||
else return count;
|
||||
}
|
||||
|
||||
|
||||
public static void AddEventListener(GameObject obj, EventTriggerType type,
|
||||
UnityEngine.Events.UnityAction<BaseEventData> call)
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
@@ -41,5 +36,23 @@ namespace XCharts.Runtime
|
||||
{
|
||||
return a + (b - a) * Clamp01(t);
|
||||
}
|
||||
|
||||
public static bool IsInteger(double value)
|
||||
{
|
||||
return Math.Abs(value % 1) <= (Double.Epsilon * 100);
|
||||
}
|
||||
|
||||
public static int GetPrecision(double value)
|
||||
{
|
||||
if (IsInteger(value)) return 0;
|
||||
int count = 1;
|
||||
double intvalue = value * Mathf.Pow(10, count);
|
||||
while (!IsInteger(intvalue) && count < 38)
|
||||
{
|
||||
count++;
|
||||
intvalue = value * Mathf.Pow(10, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user