diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index edf0f8ad..1be69cfb 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -38,6 +38,7 @@ ## master +* (2021.07.08) Optimize data storage type from `float` to `double` * (2021.07.05) Fixed `Piechart` `avoidLabelOverlap` parameter not working * (2021.07.04) Fixed incorrect mouse area indication after `PieChart` selected sector * (2021.07.04) Optimize when the `Label` of `PieChart` is `Inside`, the offset can be adjusted by the parameter `Margin` diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd78269..29b8664e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ ## master +* (2021.07.08) 优化数据存储类型由`float`全部转为`double` * (2021.07.05) 修复`PieChart`的`avoidLabelOverlap`参数不生效的问题 * (2021.07.04) 修复`PieChart`选中扇区后鼠标区域指示不准确的问题 * (2021.07.04) 优化`PieChart`的`Label`为`Inside`时可通过参数`Margin`调节偏移 diff --git a/Examples/Runtime/Example40_Radar.cs b/Examples/Runtime/Example40_Radar.cs index e838efa9..c5a537f2 100644 --- a/Examples/Runtime/Example40_Radar.cs +++ b/Examples/Runtime/Example40_Radar.cs @@ -70,15 +70,15 @@ namespace XCharts.Examples serie = chart.AddSerie(SerieType.Radar, "test"); serie.radarIndex = 0; - chart.AddData(0, new List { 10, 20, 60, 40, 20 }, "data1"); - chart.AddData(0, new List { 40, 60, 90, 80, 70 }, "data2"); + chart.AddData(0, new List { 10, 20, 60, 40, 20 }, "data1"); + chart.AddData(0, new List { 40, 60, 90, 80, 70 }, "data2"); yield return new WaitForSeconds(1); } IEnumerator RadarUpdate() { chart.UpdateIndicator(0, 0, "new1", 0, 100); - chart.UpdateData(0, 0, new List { 15, 30, 50, 60, 50 }); + chart.UpdateData(0, 0, new List { 15, 30, 50, 60, 50 }); chart.UpdateDataName(0, 0, "new1"); yield return new WaitForSeconds(1); } @@ -113,11 +113,11 @@ namespace XCharts.Examples serie = chart.AddSerie(SerieType.Radar, "test1"); serie.radarIndex = 0; - chart.AddData(0, new List { 10, 20, 60, 40, 20 }, "data1"); + chart.AddData(0, new List { 10, 20, 60, 40, 20 }, "data1"); serie1 = chart.AddSerie(SerieType.Radar, "test2"); serie1.radarIndex = 1; - chart.AddData(1, new List { 10, 20, 60, 40, 20 }, "data2"); + chart.AddData(1, new List { 10, 20, 60, 40, 20 }, "data2"); yield return new WaitForSeconds(1); } } diff --git a/Examples/Runtime/Example41_RadarUpdate.cs b/Examples/Runtime/Example41_RadarUpdate.cs index c6d9bd16..a7655bfb 100644 --- a/Examples/Runtime/Example41_RadarUpdate.cs +++ b/Examples/Runtime/Example41_RadarUpdate.cs @@ -16,7 +16,7 @@ namespace XCharts.Examples { RadarChart chart; int count = 0; - float max = 0; + double max = 0; void Awake() { diff --git a/Examples/Runtime/Example50_Scatter.cs b/Examples/Runtime/Example50_Scatter.cs index 0cb57ed1..e20cbbba 100644 --- a/Examples/Runtime/Example50_Scatter.cs +++ b/Examples/Runtime/Example50_Scatter.cs @@ -5,6 +5,7 @@ /* */ /************************************************/ +using System; using System.Collections.Generic; using UnityEngine; @@ -23,16 +24,14 @@ namespace XCharts.Examples chart.series.SetSerieSymbolSizeCallback(SymbolSize, SymbolSelectedSize); } - float SymbolSize(List data) + float SymbolSize(List data) { - //return Mathf.Clamp(data[1] * 10,1,100); - return (float)(Mathf.Sqrt(data[2]) / 6e2); + return (float)(Math.Sqrt(data[2]) / 6e2); } - float SymbolSelectedSize(List data) + float SymbolSelectedSize(List data) { - //return Mathf.Clamp(data[1] * 10,1,100); - return (float)(Mathf.Sqrt(data[2]) / 5e2); + return (float)(Math.Sqrt(data[2]) / 5e2); } } } \ No newline at end of file diff --git a/Examples/Runtime/Example60_Heatmap.cs b/Examples/Runtime/Example60_Heatmap.cs index 8b64d8f3..ef71099e 100644 --- a/Examples/Runtime/Example60_Heatmap.cs +++ b/Examples/Runtime/Example60_Heatmap.cs @@ -94,7 +94,7 @@ namespace XCharts.Examples var rate = Random.Range(0, 101); if (rate > 70) value = Random.Range(8f, 10f); else value = Random.Range(1f, 8f); - var list = new List { i, j, value }; + var list = new List { i, j, value }; //至少是一个三位数据:(x,y,value) chart.AddData(0, list); } diff --git a/Runtime/API/BaseChart_API.cs b/Runtime/API/BaseChart_API.cs index 13d5f025..f5f7007d 100644 --- a/Runtime/API/BaseChart_API.cs +++ b/Runtime/API/BaseChart_API.cs @@ -234,7 +234,7 @@ namespace XCharts /// the data to add /// the name of data /// Returns True on success - public virtual SerieData AddData(string serieName, float data, string dataName = null) + public virtual SerieData AddData(string serieName, double data, string dataName = null) { var serieData = m_Series.AddData(serieName, data, dataName); if (serieData != null) @@ -257,7 +257,7 @@ namespace XCharts /// the data to add /// the name of data /// Returns True on success - public virtual SerieData AddData(int serieIndex, float data, string dataName = null) + public virtual SerieData AddData(int serieIndex, double data, string dataName = null) { var serieData = m_Series.AddData(serieIndex, data, dataName); if (serieData != null) @@ -280,7 +280,7 @@ namespace XCharts /// the (x,y,z,...) data /// the name of data /// Returns True on success - public virtual SerieData AddData(string serieName, List multidimensionalData, string dataName = null) + public virtual SerieData AddData(string serieName, List multidimensionalData, string dataName = null) { var serieData = m_Series.AddData(serieName, multidimensionalData, dataName); if (serieData != null) @@ -303,7 +303,7 @@ namespace XCharts /// the (x,y,z,...) data /// the name of data /// Returns True on success - public virtual SerieData AddData(int serieIndex, List multidimensionalData, string dataName = null) + public virtual SerieData AddData(int serieIndex, List multidimensionalData, string dataName = null) { var serieData = m_Series.AddData(serieIndex, multidimensionalData, dataName); if (serieData != null) @@ -327,7 +327,7 @@ namespace XCharts /// y data /// the name of data /// Returns True on success - public virtual SerieData AddData(string serieName, float xValue, float yValue, string dataName = null) + public virtual SerieData AddData(string serieName, double xValue, double yValue, string dataName = null) { var serieData = m_Series.AddXYData(serieName, xValue, yValue, dataName); if (serieData != null) @@ -351,7 +351,7 @@ namespace XCharts /// y data /// the name of data /// Returns True on success - public virtual SerieData AddData(int serieIndex, float xValue, float yValue, string dataName = null) + public virtual SerieData AddData(int serieIndex, double xValue, double yValue, string dataName = null) { var serieData = m_Series.AddXYData(serieIndex, xValue, yValue, dataName); if (serieData != null) @@ -365,7 +365,7 @@ namespace XCharts } return serieData; } - public virtual SerieData AddData(int serieIndex, float open, float close, float lowest, float heighest, string dataName = null) + public virtual SerieData AddData(int serieIndex, double open, double close, double lowest, double heighest, string dataName = null) { var serieData = m_Series.AddData(serieIndex, open, close, lowest, heighest, dataName); if (serieData != null) @@ -387,7 +387,7 @@ namespace XCharts /// the name of serie /// the index of data /// the data will be update - public virtual bool UpdateData(string serieName, int dataIndex, float value) + public virtual bool UpdateData(string serieName, int dataIndex, double value) { if (m_Series.UpdateData(serieName, dataIndex, value)) { @@ -404,7 +404,7 @@ namespace XCharts /// the index of serie /// the index of data /// the data will be update - public virtual bool UpdateData(int serieIndex, int dataIndex, float value) + public virtual bool UpdateData(int serieIndex, int dataIndex, double value) { if (m_Series.UpdateData(serieIndex, dataIndex, value)) { @@ -420,7 +420,7 @@ namespace XCharts /// /// /// 一个数据项的多维数据列表,而不是多个数据项的数据 - public virtual bool UpdateData(string serieName, int dataIndex, List multidimensionalData) + public virtual bool UpdateData(string serieName, int dataIndex, List multidimensionalData) { if (m_Series.UpdateData(serieName, dataIndex, multidimensionalData)) { @@ -436,7 +436,7 @@ namespace XCharts /// /// /// 一个数据项的多维数据列表,而不是多个数据项的数据 - public virtual bool UpdateData(int serieIndex, int dataIndex, List multidimensionalData) + public virtual bool UpdateData(int serieIndex, int dataIndex, List multidimensionalData) { if (m_Series.UpdateData(serieIndex, dataIndex, multidimensionalData)) { @@ -453,7 +453,7 @@ namespace XCharts /// /// 指定维数,从0开始 /// - public virtual bool UpdateData(string serieName, int dataIndex, int dimension, float value) + public virtual bool UpdateData(string serieName, int dataIndex, int dimension, double value) { if (m_Series.UpdateData(serieName, dataIndex, dimension, value)) { @@ -470,7 +470,7 @@ namespace XCharts /// /// 指定维数,从0开始 /// - public virtual bool UpdateData(int serieIndex, int dataIndex, int dimension, float value) + public virtual bool UpdateData(int serieIndex, int dataIndex, int dimension, double value) { if (m_Series.UpdateData(serieIndex, dataIndex, dimension, value)) { diff --git a/Runtime/API/RingChart_API.cs b/Runtime/API/RingChart_API.cs index 264b1f77..a8d281e6 100644 --- a/Runtime/API/RingChart_API.cs +++ b/Runtime/API/RingChart_API.cs @@ -16,7 +16,7 @@ namespace XCharts /// /// /// - public bool UpdateMax(int serieIndex, int dataIndex, float value) + public bool UpdateMax(int serieIndex, int dataIndex, double value) { var serie = m_Series.GetSerie(serieIndex); if (serie != null) @@ -32,7 +32,7 @@ namespace XCharts /// /// /// - public bool UpdateMax(int serieIndex, float value) + public bool UpdateMax(int serieIndex, double value) { var serie = m_Series.GetSerie(serieIndex); if (serie != null) @@ -52,7 +52,7 @@ namespace XCharts /// /// /// - public bool UpdateMax(float value) + public bool UpdateMax(double value) { return UpdateMax(0, 0, value); } @@ -66,7 +66,7 @@ namespace XCharts /// the max data /// the name of data /// Returns True on success - public override SerieData AddData(string serieName, float value, float max, string dataName = null) + public override SerieData AddData(string serieName, double value, double max, string dataName = null) { return base.AddData(serieName, value, max, dataName); } @@ -80,7 +80,7 @@ namespace XCharts /// the max data /// the name of data /// Returns True on success - public override SerieData AddData(int serieIndex, float value, float max, string dataName = null) + public override SerieData AddData(int serieIndex, double value, double max, string dataName = null) { return base.AddData(serieIndex, value, max, dataName); } diff --git a/Runtime/Component/Main/Axis.cs b/Runtime/Component/Main/Axis.cs index 07a7a348..e0b1e5b7 100644 --- a/Runtime/Component/Main/Axis.cs +++ b/Runtime/Component/Main/Axis.cs @@ -397,7 +397,7 @@ namespace XCharts /// the current minimun value. /// 当前最小值。 /// - public float runtimeMinValue + public double runtimeMinValue { get { return m_RuntimeMinValue; } internal set @@ -412,7 +412,7 @@ namespace XCharts /// the current maximum value. /// 当前最大值。 /// - public float runtimeMaxValue + public double runtimeMaxValue { get { return m_RuntimeMaxValue; } internal set @@ -433,8 +433,8 @@ namespace XCharts /// 坐标轴原点在Y轴的偏移。 /// public float runtimeZeroYOffset { get; internal set; } - public int runtimeMinLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMinValue) : (int)Mathf.Log(runtimeMinValue, logBase); } } - public int runtimeMaxLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMaxValue) : (int)Mathf.Log(runtimeMaxValue, logBase); } } + public int runtimeMinLogIndex { get { return logBaseE ? (int)Math.Log(runtimeMinValue) : (int)Math.Log(runtimeMinValue, logBase); } } + public int runtimeMaxLogIndex { get { return logBaseE ? (int)Math.Log(runtimeMaxValue) : (int)Math.Log(runtimeMaxValue, logBase); } } public bool runtimeLastCheckInverse { get; set; } public double runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } } public List runtimeData { get { return m_RuntimeData; } } @@ -447,12 +447,12 @@ namespace XCharts private GameObject m_TooltipLabel; private ChartText m_TooltipLabelText; private RectTransform m_TooltipLabelRect; - private float m_RuntimeMinValue; - private float m_RuntimeLastMinValue; + private double m_RuntimeMinValue; + private double m_RuntimeLastMinValue; private bool m_RuntimeMinValueChanged; private float m_RuntimeMinValueUpdateTime; - private float m_RuntimeMaxValue; - private float m_RuntimeLastMaxValue; + private double m_RuntimeMaxValue; + private double m_RuntimeLastMaxValue; private bool m_RuntimeMaxValueChanged; private float m_RuntimeMaxValueUpdateTime; private bool m_RuntimeMinValueFirstChanged = true; @@ -809,7 +809,7 @@ namespace XCharts } } - internal void UpdateMinValue(float value, bool check) + internal void UpdateMinValue(double value, bool check) { if (value != m_RuntimeMaxValue) { @@ -837,7 +837,7 @@ namespace XCharts } } - internal void UpdateMaxValue(float value, bool check) + internal void UpdateMaxValue(double value, bool check) { if (value != m_RuntimeMaxValue) { @@ -865,7 +865,7 @@ namespace XCharts } } - public float GetCurrMinValue(float duration) + public double GetCurrMinValue(float duration) { if (!Application.isPlaying) return m_RuntimeMinValue; if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0; @@ -875,7 +875,7 @@ namespace XCharts var total = duration / 1000; if (duration > 0 && time <= total) { - var curr = Mathf.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total); + var curr = MathUtil.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total); return curr; } else @@ -885,7 +885,7 @@ namespace XCharts } } - public float GetCurrMaxValue(float duration) + public double GetCurrMaxValue(float duration) { if (!Application.isPlaying) return m_RuntimeMaxValue; if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0; @@ -895,7 +895,7 @@ namespace XCharts var total = duration / 1000; if (duration > 0 && time < total) { - var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total); + var curr = MathUtil.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total); return curr; } else @@ -918,10 +918,10 @@ namespace XCharts } } - public float GetLogValue(float value) + public float GetLogValue(double value) { if (value <= 0 || value == 1) return 0; - return logBaseE ? Mathf.Log(value) : Mathf.Log(value, logBase); + return logBaseE ? (float)Math.Log(value) : (float)Math.Log(value, logBase); } public bool IsLeft() diff --git a/Runtime/Component/Main/DataZoom.cs b/Runtime/Component/Main/DataZoom.cs index 783c85b7..dfea9df3 100644 --- a/Runtime/Component/Main/DataZoom.cs +++ b/Runtime/Component/Main/DataZoom.cs @@ -400,17 +400,17 @@ namespace XCharts /// /// 运行时实际范围的开始值 /// - public float runtimeStartValue { get; internal set; } + public double runtimeStartValue { get; internal set; } /// /// 运行时实际范围的结束值 /// - public float runtimeEndValue { get; internal set; } + public double runtimeEndValue { get; internal set; } public bool runtimeInvert { get; set; } class AxisIndexValueInfo { - public float min; - public float max; + public double min; + public double max; } private Dictionary m_XAxisIndexInfos = new Dictionary(); private Dictionary m_YAxisIndexInfos = new Dictionary(); @@ -660,7 +660,7 @@ namespace XCharts runtimeHeight = chartHeight - runtimeTop - runtimeBottom; } - internal void SetXAxisIndexValueInfo(int xAxisIndex, float min, float max) + internal void SetXAxisIndexValueInfo(int xAxisIndex, double min, double max) { if (!m_XAxisIndexInfos.ContainsKey(xAxisIndex)) { @@ -677,7 +677,7 @@ namespace XCharts } } - internal void SetYAxisIndexValueInfo(int yAxisIndex, float min, float max) + internal void SetYAxisIndexValueInfo(int yAxisIndex, double min, double max) { if (!m_YAxisIndexInfos.ContainsKey(yAxisIndex)) { @@ -704,7 +704,7 @@ namespace XCharts return m_YAxisIndexInfos.ContainsKey(axisIndex); } - internal void GetXAxisIndexValue(int axisIndex, out float min, out float max) + internal void GetXAxisIndexValue(int axisIndex, out double min, out double max) { min = 0; max = 0; @@ -715,7 +715,7 @@ namespace XCharts max = info.max; } } - internal void GetYAxisIndexValue(int axisIndex, out float min, out float max) + internal void GetYAxisIndexValue(int axisIndex, out double min, out double max) { min = 0; max = 0; @@ -1128,8 +1128,8 @@ namespace XCharts float scaleWid = dataZoom.runtimeWidth / (showData.Count - 1); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; - float minValue = 0; - float maxValue = 0; + double minValue = 0; + double maxValue = 0; SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsValue(), axis.inverse, out minValue, out maxValue); AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true); @@ -1143,11 +1143,11 @@ namespace XCharts var dataChanging = false; for (int i = 0; i < maxCount; i += rate) { - float value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, + double value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis); float pX = dataZoom.runtimeX + i * scaleWid; - float dataHig = (maxValue - minValue) == 0 ? 0 : - (value - minValue) / (maxValue - minValue) * dataZoom.runtimeHeight; + float dataHig = (float)((maxValue - minValue) == 0 ? 0 : + (value - minValue) / (maxValue - minValue) * dataZoom.runtimeHeight); np = new Vector3(pX, chart.chartY + dataZoom.bottom + dataHig); if (i > 0) { @@ -1209,8 +1209,8 @@ namespace XCharts float scaleWid = dataZoom.runtimeHeight / (showData.Count - 1); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; - float minValue = 0; - float maxValue = 0; + double minValue = 0; + double maxValue = 0; SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsValue(), axis.inverse, out minValue, out maxValue); AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true); @@ -1224,11 +1224,11 @@ namespace XCharts var dataChanging = false; for (int i = 0; i < maxCount; i += rate) { - float value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, + double value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis); float pY = dataZoom.runtimeY + i * scaleWid; float dataHig = (maxValue - minValue) == 0 ? 0 : - (value - minValue) / (maxValue - minValue) * dataZoom.runtimeWidth; + (float)((value - minValue) / (maxValue - minValue) * dataZoom.runtimeWidth); np = new Vector3(chart.chartX + chart.chartWidth - dataZoom.right - dataHig, pY); if (i > 0) { diff --git a/Runtime/Component/Main/Radar.cs b/Runtime/Component/Main/Radar.cs index 8094ae9a..f4816e4b 100644 --- a/Runtime/Component/Main/Radar.cs +++ b/Runtime/Component/Main/Radar.cs @@ -54,8 +54,8 @@ namespace XCharts public class Indicator { [SerializeField] private string m_Name; - [SerializeField] private float m_Max; - [SerializeField] private float m_Min; + [SerializeField] private double m_Max; + [SerializeField] private double m_Min; [SerializeField] private TextStyle m_TextStyle = new TextStyle(); /// @@ -67,12 +67,12 @@ namespace XCharts /// The maximum value of indicator, with default value of 0, but we recommend to set it manually. /// 指示器的最大值,默认为 0 无限制。 /// - public float max { get { return m_Max; } set { m_Max = value; } } + public double max { get { return m_Max; } set { m_Max = value; } } /// /// The minimum value of indicator, with default value of 0. /// 指示器的最小值,默认为 0 无限制。 /// - public float min { get { return m_Min; } set { m_Min = value; } } + public double min { get { return m_Min; } set { m_Min = value; } } /// /// the style of text. /// 文本样式。 @@ -276,7 +276,7 @@ namespace XCharts return true; } - public float GetIndicatorMin(int index) + public double GetIndicatorMin(int index) { if (index >= 0 && index < m_IndicatorList.Count) { @@ -284,7 +284,7 @@ namespace XCharts } return 0; } - public float GetIndicatorMax(int index) + public double GetIndicatorMax(int index) { if (index >= 0 && index < m_IndicatorList.Count) { diff --git a/Runtime/Component/Main/Serie.cs b/Runtime/Component/Main/Serie.cs index e92f1b2a..78a93af3 100644 --- a/Runtime/Component/Main/Serie.cs +++ b/Runtime/Component/Main/Serie.cs @@ -324,7 +324,7 @@ namespace XCharts [SerializeField] private bool m_ShowDataIcon; [SerializeField] private bool m_Clip = false; [SerializeField] private bool m_Ignore = false; - [SerializeField] private float m_IgnoreValue = 0; + [SerializeField] private double m_IgnoreValue = 0; [SerializeField] private bool m_ShowAsPositiveNumber = false; [SerializeField] private bool m_Large = true; [SerializeField] private int m_LargeThreshold = 200; @@ -354,8 +354,8 @@ namespace XCharts [NonSerialized] internal int m_FilterStart; [NonSerialized] internal int m_FilterEnd; - [NonSerialized] internal float m_FilterStartValue; - [NonSerialized] internal float m_FilterEndValue; + [NonSerialized] internal double m_FilterStartValue; + [NonSerialized] internal double m_FilterEndValue; [NonSerialized] internal int m_FilterMinShow; [NonSerialized] internal bool m_NeedUpdateFilterData; [NonSerialized] internal List m_FilterData = new List(); @@ -763,7 +763,7 @@ namespace XCharts /// /// 忽略数据的默认值。当ignore为true才有效。 /// - public float ignoreValue + public double ignoreValue { get { return m_IgnoreValue; } set { if (PropertyUtil.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); } @@ -1137,18 +1137,18 @@ namespace XCharts /// /// 运行时的最大数据值 /// - public float runtimeDataMax { get; internal set; } + public double runtimeDataMax { get; internal set; } /// /// 运行时的最小数据值 /// - public float runtimeDataMin { get; internal set; } + public double runtimeDataMin { get; internal set; } /// /// 饼图的数据项之和 /// - public float runtimePieDataTotal { get; internal set; } + public double runtimePieDataTotal { get; internal set; } public float runtimeWaveSpeed { get; internal set; } public Painter runtimeCanvas { get; internal set; } - public float runtimeCheckValue { get; set; } + public double runtimeCheckValue { get; set; } public int runtimeGridIndex { get; internal set; } public float runtimeX { get; internal set; } public float runtimeY { get; internal set; } @@ -1214,11 +1214,11 @@ namespace XCharts /// /// 维度Y对应数据中最大值。 /// - public float yMax + public double yMax { get { - float max = float.MinValue; + var max = double.MinValue; foreach (var sdata in data) { if (sdata.show && sdata.data[1] > max) @@ -1233,11 +1233,11 @@ namespace XCharts /// /// 维度X对应数据中的最大值。 /// - public float xMax + public double xMax { get { - float max = float.MinValue; + var max = double.MinValue; foreach (var sdata in data) { if (sdata.show && sdata.data[0] > max) @@ -1252,11 +1252,11 @@ namespace XCharts /// /// 维度Y对应数据的最小值。 /// - public float yMin + public double yMin { get { - float min = float.MaxValue; + var min = double.MaxValue; foreach (var sdata in data) { if (sdata.show && sdata.data[1] < min) @@ -1271,11 +1271,11 @@ namespace XCharts /// /// 维度X对应数据的最小值。 /// - public float xMin + public double xMin { get { - float min = float.MaxValue; + var min = double.MaxValue; foreach (var sdata in data) { if (sdata.show && sdata.data[0] < min) @@ -1290,11 +1290,11 @@ namespace XCharts /// /// 维度Y数据的总和。 /// - public float yTotal + public double yTotal { get { - float total = 0; + double total = 0; foreach (var sdata in data) { if (sdata.show) @@ -1308,11 +1308,11 @@ namespace XCharts /// /// 维度X数据的总和。 /// - public float xTotal + public double xTotal { get { - float total = 0; + double total = 0; foreach (var sdata in data) { if (sdata.show) @@ -1373,7 +1373,7 @@ namespace XCharts /// /// /// - public SerieData AddYData(float value, string dataName = null) + public SerieData AddYData(double value, string dataName = null) { CheckMaxCache(); int xValue = m_Data.Count; @@ -1414,7 +1414,7 @@ namespace XCharts /// /// /// - public SerieData AddXYData(float xValue, float yValue, string dataName = null) + public SerieData AddXYData(double xValue, double yValue, string dataName = null) { CheckMaxCache(); var serieData = SerieDataPool.Get(); @@ -1439,7 +1439,7 @@ namespace XCharts /// /// /// - public SerieData AddData(float open, float close, float lowest, float heighest, string dataName = null) + public SerieData AddData(double open, double close, double lowest, double heighest, string dataName = null) { CheckMaxCache(); var serieData = SerieDataPool.Get(); @@ -1464,7 +1464,7 @@ namespace XCharts /// /// /// - public SerieData AddData(List valueList, string dataName = null) + public SerieData AddData(List valueList, string dataName = null) { if (valueList == null || valueList.Count == 0) return null; if (valueList.Count == 1) @@ -1512,7 +1512,7 @@ namespace XCharts /// /// /// - public float GetData(int index, int dimension, DataZoom dataZoom = null) + public double GetData(int index, int dimension, DataZoom dataZoom = null) { if (index < 0 || dimension < 0) return 0; var serieData = GetSerieData(index, dataZoom); @@ -1521,7 +1521,7 @@ namespace XCharts var value = serieData.GetData(dimension); if (showAsPositiveNumber) { - value = Mathf.Abs(value); + value = Math.Abs(value); } return value; } @@ -1537,7 +1537,7 @@ namespace XCharts /// /// /// - public float GetYData(int index, DataZoom dataZoom = null) + public double GetYData(int index, DataZoom dataZoom = null) { if (index < 0) return 0; var serieData = GetDataList(dataZoom); @@ -1546,14 +1546,14 @@ namespace XCharts var value = serieData[index].data[1]; if (showAsPositiveNumber) { - value = Mathf.Abs(value); + value = Math.Abs(value); } return value; } return 0; } - public float GetYCurrData(int index, DataZoom dataZoom = null) + public double GetYCurrData(int index, DataZoom dataZoom = null) { if (index < 0) return 0; var serieData = GetDataList(dataZoom); @@ -1562,7 +1562,7 @@ namespace XCharts var value = serieData[index].GetCurrData(1, animation.GetUpdateAnimationDuration()); if (showAsPositiveNumber) { - value = Mathf.Abs(value); + value = Math.Abs(value); } return value; } @@ -1576,7 +1576,7 @@ namespace XCharts /// 对应的数据值 /// 对应的数据名 /// 区域缩放 - public void GetYData(int index, out float yData, out string dataName, DataZoom dataZoom = null) + public void GetYData(int index, out double yData, out string dataName, DataZoom dataZoom = null) { yData = 0; dataName = null; @@ -1587,7 +1587,7 @@ namespace XCharts yData = serieData[index].data[1]; if (showAsPositiveNumber) { - yData = Mathf.Abs(yData); + yData = Math.Abs(yData); } dataName = serieData[index].name; } @@ -1616,7 +1616,7 @@ namespace XCharts /// /// /// - public void GetXYData(int index, DataZoom dataZoom, out float xValue, out float yVlaue) + public void GetXYData(int index, DataZoom dataZoom, out double xValue, out double yVlaue) { xValue = 0; yVlaue = 0; @@ -1629,15 +1629,15 @@ namespace XCharts yVlaue = serieData.data[1]; if (showAsPositiveNumber) { - xValue = Mathf.Abs(xValue); - yVlaue = Mathf.Abs(yVlaue); + xValue = Math.Abs(xValue); + yVlaue = Math.Abs(yVlaue); } } } - public float GetDataTotal(int dimension) + public double GetDataTotal(int dimension) { - float total = 0; + double total = 0; foreach (var sdata in data) { if (sdata.show) @@ -1670,7 +1670,7 @@ namespace XCharts /// /// /// - public bool UpdateYData(int index, float value) + public bool UpdateYData(int index, double value) { UpdateData(index, 1, value); return true; @@ -1695,7 +1695,7 @@ namespace XCharts /// 要更新数据的索引 /// 要更新数据的维数 /// 新的数据值 - public bool UpdateData(int index, int dimension, float value) + public bool UpdateData(int index, int dimension, double value) { if (index >= 0 && index < m_Data.Count) { @@ -1716,7 +1716,7 @@ namespace XCharts /// /// /// - public bool UpdateData(int index, List values) + public bool UpdateData(int index, List values) { if (index >= 0 && index < m_Data.Count && values != null) { @@ -1847,9 +1847,9 @@ namespace XCharts return IsIgnoreValue(serieData.GetData(dimension)); } - public bool IsIgnoreValue(float value) + public bool IsIgnoreValue(double value) { - return m_Ignore && Mathf.Approximately(value, m_IgnoreValue); + return m_Ignore && MathUtil.Approximately(value, m_IgnoreValue); } public bool IsIgnorePoint(int index) @@ -1940,8 +1940,8 @@ namespace XCharts for (int j = 0; j < data.Length; j++) { var txt = data[j].Trim().Replace("]", ""); - float value; - var flag = float.TryParse(txt, out value); + double value; + var flag = double.TryParse(txt, out value); if (flag) { serieData.data.Add(value); @@ -1962,8 +1962,8 @@ namespace XCharts { if (a.StartsWith("value:")) { - float value = float.Parse(a.Substring(6, a.Length - 6)); - serieData.data = new List() { i, value }; + double value = double.Parse(a.Substring(6, a.Length - 6)); + serieData.data = new List() { i, value }; } else if (a.StartsWith("name:")) { @@ -1984,12 +1984,12 @@ namespace XCharts string[] datas = temp.Split(','); for (int i = 0; i < datas.Length; i++) { - float value; - var flag = float.TryParse(datas[i].Trim(), out value); + double value; + var flag = double.TryParse(datas[i].Trim(), out value); if (flag) { var serieData = new SerieData(); - serieData.data = new List() { i, value }; + serieData.data = new List() { i, value }; AddSerieDataHeadOrTail(serieData); } } diff --git a/Runtime/Component/Main/Series.cs b/Runtime/Component/Main/Series.cs index 24f0a266..2a90febb 100644 --- a/Runtime/Component/Main/Series.cs +++ b/Runtime/Component/Main/Series.cs @@ -116,7 +116,7 @@ namespace XCharts /// /// /// - public float GetData(int serieIndex, int dataIndex) + public double GetData(int serieIndex, int dataIndex) { if (serieIndex >= 0 && serieIndex < Count) { @@ -128,7 +128,7 @@ namespace XCharts } } - public float GetCurrData(int serieIndex, int dataIndex) + public double GetCurrData(int serieIndex, int dataIndex) { if (serieIndex >= 0 && serieIndex < Count) { @@ -321,7 +321,7 @@ namespace XCharts /// /// /// 添加成功返回SerieData,否则返回null - public SerieData AddData(string serieName, float value, string dataName = null) + public SerieData AddData(string serieName, double value, string dataName = null) { var serie = GetSerie(serieName); if (serie != null) @@ -338,7 +338,7 @@ namespace XCharts /// /// /// 添加成功返回SerieData,否则返回null - public SerieData AddData(int index, float value, string dataName = null) + public SerieData AddData(int index, double value, string dataName = null) { var serie = GetSerie(index); if (serie != null) @@ -358,7 +358,7 @@ namespace XCharts /// /// /// - public SerieData AddData(int index, float open, float close, float lowest, float heighest, string dataName = null) + public SerieData AddData(int index, double open, double close, double lowest, double heighest, string dataName = null) { var serie = GetSerie(index); if (serie != null) @@ -368,7 +368,7 @@ namespace XCharts return null; } - public SerieData AddData(string serieName, float open, float close, float lowest, float heighest, string dataName = null) + public SerieData AddData(string serieName, double open, double close, double lowest, double heighest, string dataName = null) { var serie = GetSerie(serieName); if (serie != null) @@ -385,7 +385,7 @@ namespace XCharts /// /// /// 添加成功返回SerieData,否则返回null - public SerieData AddData(string serieName, List multidimensionalData, string dataName = null) + public SerieData AddData(string serieName, List multidimensionalData, string dataName = null) { var serie = GetSerie(serieName); if (serie != null) @@ -402,7 +402,7 @@ namespace XCharts /// /// /// 添加成功返回SerieData,否则返回null - public SerieData AddData(int serieIndex, List multidimensionalData, string dataName = null) + public SerieData AddData(int serieIndex, List multidimensionalData, string dataName = null) { var serie = GetSerie(serieIndex); if (serie != null) @@ -420,7 +420,7 @@ namespace XCharts /// /// /// 添加成功返回SerieData,否则返回null - public SerieData AddXYData(string serieName, float xValue, float yValue, string dataName = null) + public SerieData AddXYData(string serieName, double xValue, double yValue, string dataName = null) { var serie = GetSerie(serieName); if (serie != null) @@ -438,7 +438,7 @@ namespace XCharts /// /// /// 添加成功返回SerieData,否则返回null - public SerieData AddXYData(int index, float xValue, float yValue, string dataName = null) + public SerieData AddXYData(int index, double xValue, double yValue, string dataName = null) { var serie = GetSerie(index); if (serie != null) @@ -454,7 +454,7 @@ namespace XCharts /// /// /// - public bool UpdateData(string serieName, int dataIndex, float value) + public bool UpdateData(string serieName, int dataIndex, double value) { var serie = GetSerie(serieName); if (serie != null) @@ -502,7 +502,7 @@ namespace XCharts /// /// /// - public bool UpdateData(int serieIndex, int dataIndex, float value) + public bool UpdateData(int serieIndex, int dataIndex, double value) { var serie = GetSerie(serieIndex); if (serie != null) @@ -512,7 +512,7 @@ namespace XCharts return false; } - public bool UpdateData(string serieName, int dataIndex, List values) + public bool UpdateData(string serieName, int dataIndex, List values) { var serie = GetSerie(serieName); if (serie != null) @@ -521,7 +521,7 @@ namespace XCharts } return false; } - public bool UpdateData(int serieIndex, int dataIndex, List values) + public bool UpdateData(int serieIndex, int dataIndex, List values) { var serie = GetSerie(serieIndex); if (serie != null) @@ -538,7 +538,7 @@ namespace XCharts /// 数据项 /// 数据维数,从0开始 /// 值 - public bool UpdateData(int serieIndex, int dataIndex, int dimension, float value) + public bool UpdateData(int serieIndex, int dataIndex, int dimension, double value) { var serie = GetSerie(serieIndex); if (serie != null) @@ -555,7 +555,7 @@ namespace XCharts /// /// 数据维数,从0开始 /// - public bool UpdateData(string serieName, int dataIndex, int dimension, float value) + public bool UpdateData(string serieName, int dataIndex, int dimension, double value) { var serie = GetSerie(serieName); if (serie != null) diff --git a/Runtime/Component/Main/Tooltip.cs b/Runtime/Component/Main/Tooltip.cs index e32aece8..1916d6ec 100644 --- a/Runtime/Component/Main/Tooltip.cs +++ b/Runtime/Component/Main/Tooltip.cs @@ -257,14 +257,14 @@ namespace XCharts /// the value for x indicator label. /// 指示器X轴上要显示的值。 /// - public float[] runtimeXValues { get { return m_RuntimeXValue; } internal set { m_RuntimeXValue = value; } } - private float[] m_RuntimeXValue = new float[2] { -1, -1 }; + public double[] runtimeXValues { get { return m_RuntimeXValue; } internal set { m_RuntimeXValue = value; } } + private double[] m_RuntimeXValue = new double[2] { -1, -1 }; /// /// the value for y indicator label. /// 指示器Y轴上要显示的值。 /// - public float[] runtimeYValues { get { return m_RuntimeYValue; } internal set { m_RuntimeYValue = value; } } - private float[] m_RuntimeYValue = new float[2] { -1, -1 }; + public double[] runtimeYValues { get { return m_RuntimeYValue; } internal set { m_RuntimeYValue = value; } } + private double[] m_RuntimeYValue = new double[2] { -1, -1 }; /// /// the current pointer position. /// 当前鼠标位置。 diff --git a/Runtime/Component/Main/VisualMap.cs b/Runtime/Component/Main/VisualMap.cs index de614c0d..b943a1e0 100644 --- a/Runtime/Component/Main/VisualMap.cs +++ b/Runtime/Component/Main/VisualMap.cs @@ -53,19 +53,19 @@ namespace XCharts [System.Serializable] public class Pieces { - [SerializeField] private float m_Min; - [SerializeField] private float m_Max; + [SerializeField] private double m_Min; + [SerializeField] private double m_Max; [SerializeField] private string m_Label; [SerializeField] private Color32 m_Color; /// /// 范围最小值 /// - public float min { get { return m_Min; } set { m_Min = value; } } + public double min { get { return m_Min; } set { m_Min = value; } } /// /// 范围最大值 /// - public float max { get { return m_Max; } set { m_Max = value; } } + public double max { get { return m_Max; } set { m_Max = value; } } /// /// 文字描述 /// @@ -75,10 +75,10 @@ namespace XCharts /// public Color32 color { get { return m_Color; } set { m_Color = value; } } - public bool Contains(float value, float minMaxRange) + public bool Contains(double value, double minMaxRange) { - var cmin = Mathf.Abs(m_Min) < 1 ? minMaxRange * m_Min : m_Min; - var cmax = Mathf.Abs(m_Max) < 1 ? minMaxRange * m_Max : m_Max; + var cmin = System.Math.Abs(m_Min) < 1 ? minMaxRange * m_Min : m_Min; + var cmax = System.Math.Abs(m_Max) < 1 ? minMaxRange * m_Max : m_Max; return value >= cmin && value < cmax; } } @@ -87,10 +87,10 @@ namespace XCharts [SerializeField] private bool m_Show = true; [SerializeField] private Type m_Type = Type.Continuous; [SerializeField] private SelectedMode m_SelectedMode = SelectedMode.Multiple; - [SerializeField] private float m_Min = 0; - [SerializeField] private float m_Max = 100f; + [SerializeField] private double m_Min = 0; + [SerializeField] private double m_Max = 100; - [SerializeField] private float[] m_Range = new float[2] { 0, 100f }; + [SerializeField] private double[] m_Range = new double[2] { 0, 100 }; [SerializeField] private string[] m_Text = new string[2] { "", "" }; [SerializeField] private float[] m_TextGap = new float[2] { 10f, 10f }; [SerializeField] private int m_SplitNumber = 5; @@ -156,7 +156,7 @@ namespace XCharts /// /// 允许的最小值。`autoMinMax`为`false`时必须指定。[visualMap.min, visualMap.max] 形成了视觉映射的『定义域』。 /// - public float min + public double min { get { return m_Min; } set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); } @@ -166,7 +166,7 @@ namespace XCharts /// /// 允许的最大值。`autoMinMax`为`false`时必须指定。[visualMap.min, visualMax.max] 形成了视觉映射的『定义域』。 /// - public float max + public double max { get { return m_Max; } set { m_Max = (value < min ? min + 1 : value); SetVerticesDirty(); } @@ -176,7 +176,7 @@ namespace XCharts /// /// 指定手柄对应数值的位置。range 应在[min,max]范围内。 /// - public float[] range { get { return m_Range; } } + public double[] range { get { return m_Range; } } /// /// Text on both ends. /// 两端的文本,如 ['High', 'Low']。 @@ -356,14 +356,14 @@ namespace XCharts /// /// public int runtimeSelectedIndex { get; set; } - public float runtimeSelectedValue { get; set; } + public double runtimeSelectedValue { get; set; } /// /// the current pointer position. /// 当前鼠标位置。 /// public Vector2 runtimePointerPos { get; set; } public bool runtimeIsVertical { get { return orient == Orient.Vertical; } } - public float rangeMin + public double rangeMin { get { @@ -376,7 +376,7 @@ namespace XCharts } } - public float rangeMax + public double rangeMax { get { @@ -398,8 +398,8 @@ namespace XCharts } } - public float runtimeRangeMinHeight { get { return (rangeMin - min) / (max - min) * itemHeight; } } - public float runtimeRangeMaxHeight { get { return (rangeMax - min) / (max - min) * itemHeight; } } + public float runtimeRangeMinHeight { get { return (float)((rangeMin - min) / (max - min) * itemHeight); } } + public float runtimeRangeMaxHeight { get { return (float)((rangeMax - min) / (max - min) * itemHeight); } } public bool runtimeMinDrag { get; internal set; } public bool runtimeMaxDrag { get; internal set; } @@ -440,7 +440,7 @@ namespace XCharts } else { - var rate = (rtValue - inValue) / diff1; + var rate = (float)((rtValue - inValue) / diff1); m_RtInRange.Add(Color32.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate)); } } @@ -450,7 +450,7 @@ namespace XCharts } } - public Color32 GetColor(float value) + public Color32 GetColor(double value) { switch (type) { @@ -463,7 +463,7 @@ namespace XCharts } } - private Color32 GetPiecesColor(float value) + private Color32 GetPiecesColor(double value) { foreach (var piece in m_Pieces) { @@ -476,7 +476,7 @@ namespace XCharts else return ChartConst.clearColor32; } - private Color32 GetContinuousColor(float value) + private Color32 GetContinuousColor(double value) { if (value < m_Min || value > m_Max) { @@ -498,15 +498,15 @@ namespace XCharts var nowMin = m_Min + index * diff; var rate = (value - nowMin) / diff; if (index == splitNumber - 1) return runtimeInRange[index]; - else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], rate); + else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], (float)rate); } } - public int GetIndex(float value) + public int GetIndex(double value) { int splitNumber = runtimeInRange.Count; if (splitNumber <= 0) return -1; - value = Mathf.Clamp(value, m_Min, m_Max); + value = MathUtil.Clamp(value, m_Min, m_Max); var diff = (m_Max - m_Min) / (splitNumber - 1); var index = -1; @@ -526,7 +526,7 @@ namespace XCharts return m_Type == VisualMap.Type.Piecewise; } - public bool IsInSelectedValue(float value) + public bool IsInSelectedValue(double value) { if (runtimeSelectedIndex < 0) return true; else @@ -535,7 +535,7 @@ namespace XCharts } } - public float GetValue(Vector3 pos, Rect chartRect) + public double GetValue(Vector3 pos, Rect chartRect) { var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height); var pos1 = centerPos + (runtimeIsVertical ? Vector3.down : Vector3.left) * itemHeight / 2; @@ -726,7 +726,7 @@ namespace XCharts var halfHig = visualMap.itemHeight / 2; var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight); var selectedIndex = -1; - var value = 0f; + double value = 0; switch (visualMap.orient) { case Orient.Horizonal: diff --git a/Runtime/Component/Sub/AxisLabel.cs b/Runtime/Component/Sub/AxisLabel.cs index c35ea34f..89fb6ae1 100644 --- a/Runtime/Component/Sub/AxisLabel.cs +++ b/Runtime/Component/Sub/AxisLabel.cs @@ -249,11 +249,11 @@ namespace XCharts } } - public string GetFormatterContent(int labelIndex, float value, float minValue, float maxValue, bool isLog = false) + public string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false) { if (showAsPositiveNumber && value < 0) { - value = Mathf.Abs(value); + value = Math.Abs(value); } if (m_FormatterFunction != null) { @@ -283,7 +283,7 @@ namespace XCharts } } - public string GetFormatterDateTime(int labelIndex, float value) + public string GetFormatterDateTime(int labelIndex, double value) { if (m_FormatterFunction != null) { diff --git a/Runtime/Component/Sub/SerieAnimation.cs b/Runtime/Component/Sub/SerieAnimation.cs index db0fe31b..c7be66ed 100644 --- a/Runtime/Component/Sub/SerieAnimation.cs +++ b/Runtime/Component/Sub/SerieAnimation.cs @@ -358,14 +358,14 @@ namespace XCharts else return dataIndex <= m_CurrDataProgress; } - internal void CheckProgress(float total) + internal void CheckProgress(double total) { if (IsFinish()) return; if (!m_IsInit || m_IsPause || m_IsEnd) return; if (IsInDelay()) return; m_ActualDuration = (int)((Time.time - startTime) * 1000) - fadeInDelay; var duration = GetCurrAnimationDuration(); - var delta = total / duration * Time.deltaTime; + var delta = (float)(total / duration * Time.deltaTime); if (m_FadeOut) { m_CurrDetailProgress -= delta; diff --git a/Runtime/Component/Sub/SerieData.cs b/Runtime/Component/Sub/SerieData.cs index 3cf65215..594cc659 100644 --- a/Runtime/Component/Sub/SerieData.cs +++ b/Runtime/Component/Sub/SerieData.cs @@ -30,7 +30,7 @@ namespace XCharts [SerializeField] private Emphasis m_Emphasis = new Emphasis(); [SerializeField] private bool m_EnableSymbol = false; [SerializeField] private SerieSymbol m_Symbol = new SerieSymbol(); - [SerializeField] private List m_Data = new List(); + [SerializeField] private List m_Data = new List(); public ChartLabel labelObject { get; set; } @@ -106,7 +106,7 @@ namespace XCharts /// An arbitrary dimension data list of data item. /// 可指定任意维数的数值列表。 /// - public List data { get { return m_Data; } set { m_Data = value; } } + public List data { get { return m_Data; } set { m_Data = value; } } /// /// [default:true] Whether the data item is showed. /// 该数据项是否要显示。 @@ -171,7 +171,7 @@ namespace XCharts public float runtimeAngle { get; set; } public Vector3 runtiemPieOffsetCenter { get; set; } public float runtimeStackHig { get; set; } - private List m_PreviousData = new List(); + private List m_PreviousData = new List(); private List m_DataUpdateTime = new List(); private List m_DataUpdateFlag = new List(); private List m_PolygonPoints = new List(); @@ -200,7 +200,7 @@ namespace XCharts m_Emphasis.Reset(); } - public float GetData(int index, bool inverse = false) + public double GetData(int index, bool inverse = false) { if (index >= 0 && index < m_Data.Count) { @@ -209,7 +209,7 @@ namespace XCharts else return 0; } - public float GetData(int index, float min, float max) + public double GetData(int index, double min, double max) { if (index >= 0 && index < m_Data.Count) { @@ -221,7 +221,7 @@ namespace XCharts else return 0; } - public float GetPreviousData(int index, bool inverse = false) + public double GetPreviousData(int index, bool inverse = false) { if (index >= 0 && index < m_PreviousData.Count) { @@ -230,24 +230,24 @@ namespace XCharts else return 0; } - public float GetFirstData(float animationDuration = 500f) + public double GetFirstData(float animationDuration = 500f) { if (m_Data.Count > 0) return GetCurrData(0, animationDuration); return 0; } - public float GetLastData() + public double GetLastData() { if (m_Data.Count > 0) return m_Data[m_Data.Count - 1]; return 0; } - public float GetCurrData(int index, float animationDuration = 500f, bool inverse = false) + public double GetCurrData(int index, float animationDuration = 500f, bool inverse = false) { return GetCurrData(index, animationDuration, inverse, 0, 0); } - public float GetCurrData(int index, float animationDuration, bool inverse, float min, float max) + public double GetCurrData(int index, float animationDuration, bool inverse, double min, double max) { if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0) { @@ -259,7 +259,7 @@ namespace XCharts if (rate < 1) { CheckLastData(); - var curr = Mathf.Lerp(GetPreviousData(index), GetData(index), rate); + var curr = MathUtil.Lerp(GetPreviousData(index), GetData(index), rate); if (min != 0 || max != 0) { if (inverse) @@ -299,10 +299,10 @@ namespace XCharts /// the maxinum value. /// 最大值。 /// - public float GetMaxData(bool inverse = false) + public double GetMaxData(bool inverse = false) { if (m_Data.Count == 0) return 0; - float temp = float.MinValue; + var temp = double.MinValue; for (int i = 0; i < m_Data.Count; i++) { var value = GetData(i, inverse); @@ -310,15 +310,15 @@ namespace XCharts } return temp; } - + /// /// the mininum value. /// 最小值。 /// - public float GetMinData(bool inverse = false) + public double GetMinData(bool inverse = false) { if (m_Data.Count == 0) return 0; - float temp = float.MaxValue; + var temp = double.MaxValue; for (int i = 0; i < m_Data.Count; i++) { var value = GetData(i, inverse); @@ -327,7 +327,7 @@ namespace XCharts return temp; } - public bool UpdateData(int dimension, float value, bool updateAnimation, float animationDuration = 500f) + public bool UpdateData(int dimension, double value, bool updateAnimation, float animationDuration = 500f) { if (dimension >= 0 && dimension < data.Count) { diff --git a/Runtime/Component/Sub/SerieSymbol.cs b/Runtime/Component/Sub/SerieSymbol.cs index 0d051cef..c9e9ce65 100644 --- a/Runtime/Component/Sub/SerieSymbol.cs +++ b/Runtime/Component/Sub/SerieSymbol.cs @@ -70,7 +70,7 @@ namespace XCharts /// /// /// - public delegate float SymbolSizeCallback(List data); + public delegate float SymbolSizeCallback(List data); /// /// 系列数据项的标记的图形 @@ -249,7 +249,7 @@ namespace XCharts /// /// /// - public float GetSize(List data, float themeSize) + public float GetSize(List data, float themeSize) { switch (m_SizeType) { @@ -258,7 +258,7 @@ namespace XCharts case SerieSymbolSizeType.FromData: if (data != null && dataIndex >= 0 && dataIndex < data.Count) { - return data[dataIndex] * m_DataScale; + return (float)data[dataIndex] * m_DataScale; } else { @@ -276,7 +276,7 @@ namespace XCharts /// /// /// - public float GetSelectedSize(List data, float themeSelectedSize) + public float GetSelectedSize(List data, float themeSelectedSize) { switch (m_SizeType) { @@ -285,7 +285,7 @@ namespace XCharts case SerieSymbolSizeType.FromData: if (data != null && dataIndex >= 0 && dataIndex < data.Count) { - return data[dataIndex] * m_SelectedDataScale; + return (float)data[dataIndex] * m_SelectedDataScale; } else { diff --git a/Runtime/HeatmapChart.cs b/Runtime/HeatmapChart.cs index e7e2dfee..b59318d0 100644 --- a/Runtime/HeatmapChart.cs +++ b/Runtime/HeatmapChart.cs @@ -72,7 +72,7 @@ namespace XCharts var rate = Random.Range(0, 101); if (rate > 70) value = Random.Range(8f, 10f); else value = Random.Range(1f, 8f); - var list = new List { i, j, value }; + var list = new List { i, j, value }; AddData(0, list); } } diff --git a/Runtime/Helper/AxisHelper.cs b/Runtime/Helper/AxisHelper.cs index 6335173f..9a15fa2e 100644 --- a/Runtime/Helper/AxisHelper.cs +++ b/Runtime/Helper/AxisHelper.cs @@ -112,14 +112,14 @@ namespace XCharts /// /// /// - public static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue, + public static string GetLabelName(Axis axis, float coordinateWidth, int index, double minValue, double maxValue, DataZoom dataZoom, bool forcePercent) { int split = GetSplitNumber(axis, coordinateWidth, dataZoom); if (axis.type == Axis.AxisType.Value) { if (minValue == 0 && maxValue == 0) return string.Empty; - var value = 0f; + double value = 0; if (forcePercent) maxValue = 100; if (axis.interval > 0) { @@ -155,7 +155,7 @@ namespace XCharts else if (axis.type == Axis.AxisType.Time) { if (minValue == 0 && maxValue == 0) return string.Empty; - var value = 0f; + double value = 0; if (axis.interval > 0) { if (index == split) value = maxValue; @@ -323,7 +323,7 @@ namespace XCharts /// /// /// - public static void AdjustMinMaxValue(Axis axis, ref float minValue, ref float maxValue, bool needFormat, int ceilRate = 0) + public static void AdjustMinMaxValue(Axis axis, ref double minValue, ref double maxValue, bool needFormat, int ceilRate = 0) { if (axis.type == Axis.AxisType.Log) { diff --git a/Runtime/Helper/DataZoomHelper.cs b/Runtime/Helper/DataZoomHelper.cs index 09246999..421a05c1 100644 --- a/Runtime/Helper/DataZoomHelper.cs +++ b/Runtime/Helper/DataZoomHelper.cs @@ -43,8 +43,8 @@ namespace XCharts public static void UpdateDataZoomRuntimeStartEndValue(DataZoom dataZoom, Serie serie) { if (dataZoom == null || serie == null) return; - float min = 0; - float max = 0; + double min = 0; + double max = 0; SerieHelper.GetMinMaxData(serie, out min, out max, null); dataZoom.runtimeStartValue = min + (max - min) * dataZoom.start / 100; dataZoom.runtimeEndValue = min + (max - min) * dataZoom.end / 100; @@ -55,8 +55,8 @@ namespace XCharts foreach (var dataZoom in chart.dataZooms) { if (!dataZoom.enable) continue; - float min = float.MaxValue; - float max = float.MinValue; + double min = double.MaxValue; + double max = double.MinValue; foreach (var serie in chart.series.list) { if (!serie.show || serie.type != serieType) continue; @@ -70,8 +70,8 @@ namespace XCharts } else { - var serieMinValue = 0f; - var serieMaxValue = 0f; + double serieMinValue = 0; + double serieMaxValue = 0; SerieHelper.GetMinMaxData(serie, out serieMinValue, out serieMaxValue, null, 2); if (serieMinValue < min) min = serieMinValue; if (serieMaxValue > max) max = serieMaxValue; diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index 7ebda4ab..2b43c294 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -181,7 +181,7 @@ namespace XCharts return s_RegexNewLine.Replace(content.Trim(), PH_NN); } - public static void ReplaceAxisLabelContent(ref string content, string numericFormatter, float value) + public static void ReplaceAxisLabelContent(ref string content, string numericFormatter, double value) { var mc = s_RegexForAxisLabel.Matches(content); foreach (var m in mc) @@ -213,7 +213,7 @@ namespace XCharts content = TrimAndReplaceLine(content); } - public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, float value, float total, + public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, double value, double total, string serieName, string dataName, Color color) { var mc = s_RegexForSerieLabel.Matches(content); diff --git a/Runtime/Helper/SerieHelper.cs b/Runtime/Helper/SerieHelper.cs index fb5e5081..a77d7758 100644 --- a/Runtime/Helper/SerieHelper.cs +++ b/Runtime/Helper/SerieHelper.cs @@ -22,11 +22,11 @@ namespace XCharts /// 最小值 /// 最大值 /// 缩放组件,默认null - public static void GetMinMaxData(Serie serie, int dimension, out float min, out float max, + public static void GetMinMaxData(Serie serie, int dimension, out double min, out double max, DataZoom dataZoom = null) { - max = float.MinValue; - min = float.MaxValue; + max = double.MinValue; + min = double.MaxValue; var dataList = serie.GetDataList(dataZoom); for (int i = 0; i < dataList.Count; i++) { @@ -48,10 +48,10 @@ namespace XCharts /// /// /// - public static void GetMinMaxData(Serie serie, out float min, out float max, DataZoom dataZoom = null, int dimension = 0) + public static void GetMinMaxData(Serie serie, out double min, out double max, DataZoom dataZoom = null, int dimension = 0) { - max = float.MinValue; - min = float.MaxValue; + max = double.MinValue; + min = double.MaxValue; var dataList = serie.GetDataList(dataZoom); for (int i = 0; i < dataList.Count; i++) { @@ -406,7 +406,7 @@ namespace XCharts /// public static void UpdateMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null) { - float min = 0, max = 0; + double min = 0, max = 0; GetMinMaxData(serie, dimension, out min, out max, dataZoom); if (ceilRate < 0) { @@ -422,7 +422,7 @@ namespace XCharts public static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null) { - float min = 0, max = 0; + double min = 0, max = 0; GetMinMaxData(serie, out min, out max, dataZoom); if (ceilRate < 0) { @@ -448,7 +448,7 @@ namespace XCharts { if (dataZoom.IsXAxisIndexValue(serie.xAxisIndex)) { - float min = 0, max = 0; + double min = 0, max = 0; dataZoom.GetXAxisIndexValue(serie.xAxisIndex, out min, out max); UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max); } @@ -461,7 +461,7 @@ namespace XCharts { if (dataZoom.IsYAxisIndexValue(serie.yAxisIndex)) { - float min = 0, max = 0; + double min = 0, max = 0; dataZoom.GetYAxisIndexValue(serie.yAxisIndex, out min, out max); UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max); } @@ -472,7 +472,7 @@ namespace XCharts } } - private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, float min, float max) + private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, double min, double max) { var data = serie.data; var startValue = min + (max - min) * dataZoom.start / 100; diff --git a/Runtime/Helper/SerieLabelHelper.cs b/Runtime/Helper/SerieLabelHelper.cs index 7fc9be4d..2e6092e4 100644 --- a/Runtime/Helper/SerieLabelHelper.cs +++ b/Runtime/Helper/SerieLabelHelper.cs @@ -89,7 +89,7 @@ namespace XCharts } public static string GetFormatterContent(Serie serie, SerieData serieData, - float dataValue, float dataTotal, SerieLabel serieLabel, Color color) + double dataValue, double dataTotal, SerieLabel serieLabel, Color color) { if (serieLabel == null) { diff --git a/Runtime/Helper/SeriesHelper.cs b/Runtime/Helper/SeriesHelper.cs index 2f16e5d5..9dbe251c 100644 --- a/Runtime/Helper/SeriesHelper.cs +++ b/Runtime/Helper/SeriesHelper.cs @@ -5,6 +5,7 @@ /* */ /************************************************/ +using System; using System.Collections.Generic; using UnityEngine; @@ -410,7 +411,7 @@ namespace XCharts /// /// public static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, out float minVaule, out float maxValue, bool isPolar = false) + bool inverse, out double minVaule, out double maxValue, bool isPolar = false) { GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar); } @@ -423,18 +424,18 @@ namespace XCharts /// /// public static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, out float minVaule, out float maxValue, bool isPolar = false) + bool inverse, out double minVaule, out double maxValue, bool isPolar = false) { GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar); } private static Dictionary> _stackSeriesForMinMax = new Dictionary>(); - private static Dictionary _serieTotalValueForMinMax = new Dictionary(); + private static Dictionary _serieTotalValueForMinMax = new Dictionary(); public static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false) + bool inverse, bool yValue, out double minVaule, out double maxValue, bool isPolar = false) { - float min = float.MaxValue; - float max = float.MinValue; + double min = double.MaxValue; + double max = double.MinValue; var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar); if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue)) { @@ -499,7 +500,7 @@ namespace XCharts { if (!_serieTotalValueForMinMax.ContainsKey(j)) _serieTotalValueForMinMax[j] = 0; - var currData = 0f; + double currData = 0; if (serie.type == SerieType.Candlestick) { currData = showData[j].GetMaxData(false); @@ -513,8 +514,8 @@ namespace XCharts } } } - float tmax = float.MinValue; - float tmin = float.MaxValue; + double tmax = double.MinValue; + double tmin = double.MaxValue; foreach (var tt in _serieTotalValueForMinMax) { if (tt.Value > tmax) tmax = tt.Value; @@ -524,15 +525,15 @@ namespace XCharts if (tmin < min) min = tmin; } } - if (max == float.MinValue && min == float.MaxValue) + if (max == double.MinValue && min == double.MaxValue) { minVaule = 0; maxValue = 0; } else { - minVaule = min > 1 ? Mathf.Floor(min) : min; - maxValue = max > 1 ? Mathf.Ceil(max) : max; + minVaule = min > 1 ? Math.Floor(min) : min; + maxValue = max > 1 ? Math.Ceiling(max) : max; } } diff --git a/Runtime/Helper/TooltipHelper.cs b/Runtime/Helper/TooltipHelper.cs index 0bcd54d6..8646bdfa 100644 --- a/Runtime/Helper/TooltipHelper.cs +++ b/Runtime/Helper/TooltipHelper.cs @@ -26,7 +26,7 @@ namespace XCharts var dataIndex = dataIndexList[i]; var serieData = serie.GetSerieData(dataIndex); var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); - float xValue, yValue; + double xValue, yValue; serie.GetXYData(dataIndex, null, out xValue, out yValue); sb.Append("● "); @@ -50,7 +50,7 @@ namespace XCharts var serieData = serie.GetSerieData(index); var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); - float value = serieData.GetData(1); + var value = serieData.GetData(1); sb.Length = 0; if (!string.IsNullOrEmpty(serie.name)) { @@ -67,7 +67,7 @@ namespace XCharts { var serieData = serie.GetSerieData(index); var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); - float value = serieData.GetFirstData(); + var value = serieData.GetFirstData(); sb.Length = 0; if (!string.IsNullOrEmpty(serieData.name)) { @@ -86,7 +86,7 @@ namespace XCharts if (serie.index != index || serie.type != SerieType.Gauge) return; var serieData = serie.GetSerieData(0); var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); - float value = serieData.data[1]; + var value = serieData.data[1]; sb.Length = 0; if (!string.IsNullOrEmpty(serie.name)) { @@ -158,8 +158,8 @@ namespace XCharts sb.Append(serieData.name); for (int i = 0; i < radar.indicatorList.Count; i++) { - string key = radar.indicatorList[i].name; - float value = serieData.GetData(i); + var key = radar.indicatorList[i].name; + var value = serieData.GetData(i); if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append(FormatterHelper.PH_NN); sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, numericFormatter)); } @@ -193,7 +193,7 @@ namespace XCharts ChartTheme theme, bool isCartesian, DataZoom dataZoom = null) { string key = serie.name; - float xValue, yValue; + double xValue, yValue; serie.GetXYData(index, dataZoom, out xValue, out yValue); var isIngore = serie.IsIgnorePoint(index); if(isIngore) return; @@ -318,7 +318,7 @@ namespace XCharts var serieData = serie.GetSerieData(dataIndex); var itemFormatter = GetItemFormatter(tooltip, serie, serieData); var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); - float xValue, yValue; + double xValue, yValue; serie.GetXYData(dataIndex, null, out xValue, out yValue); if (string.IsNullOrEmpty(itemFormatter)) { diff --git a/Runtime/Helper/VisualMapHelper.cs b/Runtime/Helper/VisualMapHelper.cs index 4527e9cc..2e953824 100644 --- a/Runtime/Helper/VisualMapHelper.cs +++ b/Runtime/Helper/VisualMapHelper.cs @@ -15,8 +15,8 @@ namespace XCharts public static void AutoSetLineMinMax(VisualMap visualMap, Serie serie, XAxis xAxis, YAxis yAxis) { if (!IsNeedGradient(visualMap) || !visualMap.autoMinMax) return; - float min = 0; - float max = 0; + double min = 0; + double max = 0; if (visualMap.dimension == 0) { min = xAxis.IsCategory() ? 0 : xAxis.runtimeMinValue; @@ -31,7 +31,7 @@ namespace XCharts } } - public static void SetMinMax(VisualMap visualMap, float min, float max) + public static void SetMinMax(VisualMap visualMap, double min, double max) { if (visualMap.enable && (visualMap.min != min || visualMap.max != max)) { @@ -67,9 +67,9 @@ namespace XCharts public static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor) { - float value = 0; - var min = 0f; - var max = 0f; + double value = 0; + double min = 0; + double max = 0; if (visualMap.dimension == 0) { min = axis.runtimeMinValue; @@ -124,7 +124,7 @@ namespace XCharts var grid = chart.GetAxisGridOrDefault(axis); var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); var rate = (value - min) / (max - min); - var color = itemStyle.GetGradientColor(rate, defaultColor); + var color = itemStyle.GetGradientColor((float)rate, defaultColor); if (ChartHelper.IsClearColor(color)) return defaultColor; else return color; } @@ -137,7 +137,7 @@ namespace XCharts var grid = chart.GetAxisGridOrDefault(axis); var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); var rate = (value - min) / (max - min); - var color = lineStyle.GetGradientColor(rate, defaultColor); + var color = lineStyle.GetGradientColor((float)rate, defaultColor); if (ChartHelper.IsClearColor(color)) return defaultColor; else return color; } diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs index 25d759e2..41cb6f2e 100644 --- a/Runtime/Internal/CoordinateChart.cs +++ b/Runtime/Internal/CoordinateChart.cs @@ -10,6 +10,7 @@ using UnityEngine.UI; using System.Collections.Generic; using System.Text; using XUGL; +using System; namespace XCharts { @@ -286,8 +287,8 @@ namespace XCharts var symbol = SerieHelper.GetSerieSymbol(serie, serieData); var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data, m_Theme.serie.lineSymbolSize); - if (Mathf.Abs(xValue - xdata) / xRate < symbolSize - && Mathf.Abs(yValue - ydata) / yRate < symbolSize) + if (Math.Abs(xValue - xdata) / xRate < symbolSize + && Math.Abs(yValue - ydata) / yRate < symbolSize) { tooltip.runtimeDataIndex[i] = n; RefreshPainter(serie); @@ -900,8 +901,8 @@ namespace XCharts axis.runtimeMaxValue = SeriesHelper.GetMaxSerieDataCount(m_Series) - 1; return; } - float tempMinValue = 0; - float tempMaxValue = 0; + double tempMinValue = 0; + double tempMaxValue = 0; GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue); if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue) { @@ -919,13 +920,13 @@ namespace XCharts { axis.runtimeZeroXOffset = axis.runtimeMinValue > 0 ? 0 : axis.runtimeMaxValue < 0 ? grid.runtimeWidth : - Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeWidth / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue))); + (float)(Math.Abs(axis.runtimeMinValue) * (grid.runtimeWidth / (Math.Abs(axis.runtimeMinValue) + Math.Abs(axis.runtimeMaxValue)))); } if (grid != null && axis is YAxis && axis.IsValue()) { axis.runtimeZeroYOffset = axis.runtimeMinValue > 0 ? 0 : axis.runtimeMaxValue < 0 ? grid.runtimeHeight : - Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue))); + (float)(Math.Abs(axis.runtimeMinValue) * (grid.runtimeHeight / (Math.Abs(axis.runtimeMinValue) + Math.Abs(axis.runtimeMaxValue)))); } } var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(axis, dataZooms); @@ -947,7 +948,7 @@ namespace XCharts } } - protected virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out float tempMinValue, out float tempMaxValue) + protected virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue) { if (IsValue()) { @@ -1344,8 +1345,8 @@ namespace XCharts { case Tooltip.Type.Corss: case Tooltip.Type.Line: - float pX = grid.runtimeX + tooltip.runtimeXValues[i] * splitWidth - + (xAxis.boundaryGap ? splitWidth / 2 : 0); + float pX = (float)(grid.runtimeX + tooltip.runtimeXValues[i] * splitWidth + + (xAxis.boundaryGap ? splitWidth / 2 : 0)); if (xAxis.IsValue()) pX = tooltip.runtimePointerPos.x; Vector2 sp = new Vector2(pX, grid.runtimeY); Vector2 ep = new Vector2(pX, grid.runtimeY + grid.runtimeHeight); @@ -1360,9 +1361,9 @@ namespace XCharts break; case Tooltip.Type.Shadow: float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth; - pX = grid.runtimeX + splitWidth * tooltip.runtimeXValues[i] - - (xAxis.boundaryGap ? 0 : splitWidth / 2); - if (xAxis.IsValue()) pX = tooltip.runtimeXValues[i]; + pX = (float)(grid.runtimeX + splitWidth * tooltip.runtimeXValues[i] - + (xAxis.boundaryGap ? 0 : splitWidth / 2)); + if (xAxis.IsValue()) pX = (float)tooltip.runtimeXValues[i]; float pY = grid.runtimeY + grid.runtimeHeight; Vector3 p1 = new Vector3(pX, grid.runtimeY); Vector3 p2 = new Vector3(pX, pY); @@ -1396,7 +1397,7 @@ namespace XCharts { case Tooltip.Type.Corss: case Tooltip.Type.Line: - float pY = grid.runtimeY + tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0); + float pY = (float)(grid.runtimeY + tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0)); Vector2 sp = new Vector2(grid.runtimeX, pY); Vector2 ep = new Vector2(grid.runtimeX + grid.runtimeWidth, pY); var lineColor = TooltipHelper.GetLineColor(tooltip, m_Theme); @@ -1411,8 +1412,8 @@ namespace XCharts case Tooltip.Type.Shadow: float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth; float pX = grid.runtimeX + grid.runtimeWidth; - pY = grid.runtimeY + splitWidth * tooltip.runtimeYValues[i] - - (yAxis.boundaryGap ? 0 : splitWidth / 2); + pY = (float)(grid.runtimeY + splitWidth * tooltip.runtimeYValues[i] - + (yAxis.boundaryGap ? 0 : splitWidth / 2)); Vector3 p1 = new Vector3(grid.runtimeX, pY); Vector3 p2 = new Vector3(grid.runtimeX, pY + tooltipSplitWid); Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid); @@ -1559,7 +1560,7 @@ namespace XCharts serieData.labelObject.UpdateIcon(serieData.iconStyle); if (serie.show && serieLabel.show && serieData.canShowLabel && !isIgnore) { - float value = 0f; + double value = 0; if (serie.type == SerieType.Heatmap) { diff --git a/Runtime/Internal/CoordinateChart_DrawBar.cs b/Runtime/Internal/CoordinateChart_DrawBar.cs index 1fea6af1..c18a71f1 100644 --- a/Runtime/Internal/CoordinateChart_DrawBar.cs +++ b/Runtime/Internal/CoordinateChart_DrawBar.cs @@ -44,8 +44,8 @@ namespace XCharts var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); - float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); + double xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); + double xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { @@ -61,7 +61,7 @@ namespace XCharts var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); serieData.canShowLabel = true; - float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue); + double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue); float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; if (showData[i].IsDataChanged()) dataChanging = true; float axisLineWidth = value == 0 ? 0 @@ -79,11 +79,11 @@ namespace XCharts } var barHig = 0f; - var valueTotal = 0f; + double valueTotal = 0f; if (isPercentStack) { valueTotal = Internal_GetBarSameStackTotalValue(serie.stack, i, SerieType.Bar); - barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0; + barHig = valueTotal != 0 ? (float)((value / valueTotal * grid.runtimeWidth)) : 0; } else { @@ -97,8 +97,8 @@ namespace XCharts { valueTotal = xMaxValue - xMinValue; if (valueTotal != 0) - barHig = (xMinValue > 0 ? value - xMinValue : value) - / valueTotal * grid.runtimeWidth; + barHig = (float)((xMinValue > 0 ? value - xMinValue : value) + / valueTotal * grid.runtimeWidth); } } serieData.runtimeStackHig = barHig; @@ -193,8 +193,8 @@ namespace XCharts var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); - float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); + double yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); + double yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { @@ -208,7 +208,7 @@ namespace XCharts || serie.data[i].highlighted || serie.highlighted; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); - float value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); + double value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; if (serieData.IsDataChanged()) dataChanging = true; float pX = grid.runtimeX + i * categoryWidth; @@ -240,7 +240,7 @@ namespace XCharts if (yAxis.IsLog()) { int minIndex = yAxis.runtimeMinLogIndex; - float nowIndex = yAxis.GetLogValue(value); + var nowIndex = yAxis.GetLogValue(value); barHig = (nowIndex - minIndex) / yAxis.splitNumber * grid.runtimeHeight; } else @@ -621,10 +621,10 @@ namespace XCharts return gap; } - public float Internal_GetBarSameStackTotalValue(string stack, int dataIndex, SerieType type) + public double Internal_GetBarSameStackTotalValue(string stack, int dataIndex, SerieType type) { if (string.IsNullOrEmpty(stack)) return 0; - float total = 0; + double total = 0; foreach (var serie in m_Series.list) { if (serie.type == type) diff --git a/Runtime/Internal/CoordinateChart_DrawCandlestick.cs b/Runtime/Internal/CoordinateChart_DrawCandlestick.cs index a1c45f74..9bf64e4e 100644 --- a/Runtime/Internal/CoordinateChart_DrawCandlestick.cs +++ b/Runtime/Internal/CoordinateChart_DrawCandlestick.cs @@ -31,8 +31,8 @@ namespace XCharts bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); - float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); + double yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); + double yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); var isAllBarEnd = true; var isYAxis = false; for (int i = serie.minShow; i < maxCount; i++) diff --git a/Runtime/Internal/CoordinateChart_DrawLine.cs b/Runtime/Internal/CoordinateChart_DrawLine.cs index 5033bbe9..727edc9c 100644 --- a/Runtime/Internal/CoordinateChart_DrawLine.cs +++ b/Runtime/Internal/CoordinateChart_DrawLine.cs @@ -134,7 +134,7 @@ namespace XCharts } else { - float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, + double yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, yAxis); showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref np, dataChangeDuration); @@ -155,7 +155,7 @@ namespace XCharts } else { - float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); + double yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref np, dataChangeDuration); serie.dataPoints.Add(np); @@ -188,7 +188,7 @@ namespace XCharts } else { - float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); + double yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref firstLastPos, dataChangeDuration); } } @@ -206,7 +206,7 @@ namespace XCharts } else { - float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); + double yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref lastNextPos, dataChangeDuration); } } @@ -334,12 +334,12 @@ namespace XCharts return lp; } - internal float DataAverage(ref List showData, SampleType sampleType, int minCount, int maxCount, int rate) + internal double DataAverage(ref List showData, SampleType sampleType, int minCount, int maxCount, int rate) { - var totalAverage = 0f; + double totalAverage = 0; if (rate > 1 && sampleType == SampleType.Peak) { - var total = 0f; + double total = 0; for (int i = minCount; i < maxCount; i++) { total += showData[i].data[1]; @@ -349,13 +349,13 @@ namespace XCharts return totalAverage; } - internal float SampleValue(ref List showData, SampleType sampleType, int rate, - int minCount, int maxCount, float totalAverage, int index, float dataChangeDuration, + internal double SampleValue(ref List showData, SampleType sampleType, int rate, + int minCount, int maxCount, double totalAverage, int index, float dataChangeDuration, ref bool dataChanging, Axis axis) { var inverse = axis.inverse; - var minValue = axis.runtimeMinValue; - var MaxValue = axis.runtimeMaxValue; + double minValue = axis.runtimeMinValue; + double MaxValue = axis.runtimeMaxValue; if (rate <= 1 || index == minCount) { if (showData[index].IsDataChanged()) dataChanging = true; @@ -365,7 +365,7 @@ namespace XCharts { case SampleType.Sum: case SampleType.Average: - float total = 0; + double total = 0; for (int i = index; i > index - rate; i--) { total += showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue); @@ -374,7 +374,7 @@ namespace XCharts if (sampleType == SampleType.Average) return total / rate; else return total; case SampleType.Max: - float max = float.MinValue; + double max = double.MinValue; for (int i = index; i > index - rate; i--) { var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue); @@ -383,7 +383,7 @@ namespace XCharts } return max; case SampleType.Min: - float min = float.MaxValue; + double min = double.MaxValue; for (int i = index; i > index - rate; i--) { var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue); @@ -392,8 +392,8 @@ namespace XCharts } return min; case SampleType.Peak: - max = float.MinValue; - min = float.MaxValue; + max = double.MinValue; + min = double.MaxValue; total = 0; for (int i = index; i > index - rate; i--) { @@ -411,7 +411,7 @@ namespace XCharts return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue); } - private float GetDataPoint(Axis xAxis, Axis yAxis, List showData, float yValue, float startX, int i, + private float GetDataPoint(Axis xAxis, Axis yAxis, List showData, double yValue, float startX, int i, float scaleWid, bool isStack, ref Vector3 np, float duration, bool isIngoreValue = false) { if (isIngoreValue) @@ -420,15 +420,15 @@ namespace XCharts return 0; } float xDataHig, yDataHig; - float xMinValue = xAxis.GetCurrMinValue(duration); - float xMaxValue = xAxis.GetCurrMaxValue(duration); - float yMinValue = yAxis.GetCurrMinValue(duration); - float yMaxValue = yAxis.GetCurrMaxValue(duration); + double xMinValue = xAxis.GetCurrMinValue(duration); + double xMaxValue = xAxis.GetCurrMaxValue(duration); + double yMinValue = yAxis.GetCurrMinValue(duration); + double yMaxValue = yAxis.GetCurrMaxValue(duration); if (xAxis.IsValue() || xAxis.IsLog()) { var grid = GetAxisGridOrDefault(xAxis); var axisLineWidth = xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); - float xValue = i > showData.Count - 1 ? 0 : showData[i].GetData(0, xAxis.inverse); + double xValue = i > showData.Count - 1 ? 0 : showData[i].GetData(0, xAxis.inverse); float pX = grid.runtimeX + axisLineWidth; float pY = grid.runtimeY + axisLineWidth; if (isStack) @@ -447,7 +447,7 @@ namespace XCharts else { if ((xMaxValue - xMinValue) <= 0) xDataHig = 0; - else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth; + else xDataHig = (float)((xValue - xMinValue) / (xMaxValue - xMinValue)) * grid.runtimeWidth; } if (yAxis.IsLog()) { @@ -459,7 +459,7 @@ namespace XCharts { double valueTotal = yMaxValue - yMinValue; if (valueTotal <= 0) yDataHig = 0; - else yDataHig = (float)((yValue - yMinValue) / valueTotal * grid.runtimeHeight); + else yDataHig = (float)((yValue - yMinValue) / valueTotal) * grid.runtimeHeight; } np = new Vector3(pX + xDataHig, pY + yDataHig); } @@ -530,11 +530,11 @@ namespace XCharts if (rate < 1) rate = 1; var dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); - float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); + double xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); + double xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); for (i = serie.minShow; i < maxCount; i += rate) { - float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); + double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); float pY = startY + i * scaleWid; float pX = grid.runtimeX + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); if (isStack) @@ -553,7 +553,7 @@ namespace XCharts } else { - dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth; + dataHig = (float)((value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth); } showData[i].runtimeStackHig = dataHig; np = new Vector3(pX + dataHig, pY); @@ -567,7 +567,7 @@ namespace XCharts if (maxCount % rate != 0) { i = maxCount - 1; - float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); + double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); float pY = startY + i * scaleWid; float pX = grid.runtimeX + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); if (isStack) @@ -586,7 +586,7 @@ namespace XCharts } else { - dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth; + dataHig = (float)((value - xMinValue) / (xMaxValue - xMinValue)) * grid.runtimeWidth; } showData[i].runtimeStackHig = dataHig; np = new Vector3(pX + dataHig, pY); @@ -664,9 +664,9 @@ namespace XCharts } } - private float GetStackValue(List> stackDataList, int dataIndex, float dataChangeDuration, Axis xAxis) + private double GetStackValue(List> stackDataList, int dataIndex, float dataChangeDuration, Axis xAxis) { - float value = 0; + double value = 0; foreach (var dataList in stackDataList) { value += dataList[dataIndex].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); diff --git a/Runtime/Internal/CoordinateChart_DrawScatter.cs b/Runtime/Internal/CoordinateChart_DrawScatter.cs index 76a7d33c..884bb913 100644 --- a/Runtime/Internal/CoordinateChart_DrawScatter.cs +++ b/Runtime/Internal/CoordinateChart_DrawScatter.cs @@ -38,8 +38,8 @@ namespace XCharts var toColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight); var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight); var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); - float xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse); - float yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse); + double xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse); + double yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse); if (serieData.IsDataChanged()) dataChanging = true; float pX = grid.runtimeX + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); float pY = grid.runtimeY + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); @@ -88,7 +88,7 @@ namespace XCharts } } - private float GetDataHig(Axis axis, float value, float totalWidth) + private float GetDataHig(Axis axis, double value, float totalWidth) { if (axis.IsLog()) { diff --git a/Runtime/Internal/DrawSerieGauge.cs b/Runtime/Internal/DrawSerieGauge.cs index 0627ac88..55385a02 100644 --- a/Runtime/Internal/DrawSerieGauge.cs +++ b/Runtime/Internal/DrawSerieGauge.cs @@ -196,11 +196,11 @@ namespace XCharts var destAngle = GetCurrAngle(serie, true); serie.animation.InitProgress(0, serie.startAngle, destAngle); var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); - DrawProgressBar(vh, serie, currAngle); + DrawProgressBar(vh, serie, (float)currAngle); DrawStageColor(vh, serie); DrawLineStyle(vh, serie); DrawAxisTick(vh, serie); - DrawPointer(vh, serie, currAngle); + DrawPointer(vh, serie, (float)currAngle); TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText); SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText); CheckAnimation(serie); @@ -325,11 +325,11 @@ namespace XCharts { if (serie.animation.HasFadeOut()) { - return serie.animation.GetCurrDetail(); + return (float)serie.animation.GetCurrDetail(); } float rangeValue = serie.max - serie.min; float rangeAngle = serie.endAngle - serie.startAngle; - float value = 0; + double value = 0; float angle = serie.startAngle; if (serie.dataCount > 0) { @@ -337,11 +337,11 @@ namespace XCharts serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset; value = dest ? serieData.GetData(1) : serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); - value = Mathf.Clamp(value, serie.min, serie.max); + value = MathUtil.Clamp(value, serie.min, serie.max); } if (rangeValue > 0) { - angle += rangeAngle * (value - serie.min) / rangeValue; + angle += rangeAngle * (float)(value - serie.min) / rangeValue; } return angle; } @@ -382,7 +382,7 @@ namespace XCharts ? serie.runtimeInsideRadius * serie.gaugePointer.length : serie.gaugePointer.length; if (Vector3.Distance(local, serie.runtimeCenterPos) > len) continue; - var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); + var currAngle = (float)(serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail()); var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len); var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width); var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2); diff --git a/Runtime/Internal/DrawSerieLiquid.cs b/Runtime/Internal/DrawSerieLiquid.cs index 8a5c3f19..dc8e1eb0 100644 --- a/Runtime/Internal/DrawSerieLiquid.cs +++ b/Runtime/Internal/DrawSerieLiquid.cs @@ -224,7 +224,7 @@ namespace XCharts if (value <= 0) return; var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name); - var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2; + var realHig = (float)((value - serie.min) / (serie.max - serie.min) * radius * 2); serie.animation.InitProgress(1, 0, realHig); var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); @@ -338,7 +338,7 @@ namespace XCharts var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name); var realHig = (value - serie.min) / (serie.max - serie.min) * vessel.runtimeHeight; - serie.animation.InitProgress(1, 0, realHig); + serie.animation.InitProgress(1, 0, (float)realHig); var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false); @@ -351,7 +351,7 @@ namespace XCharts } else { - var startY = cenPos.y - vessel.runtimeHeight / 2 + hig; + var startY = (float)(cenPos.y - vessel.runtimeHeight / 2 + hig); var waveStartPos = new Vector3(cenPos.x - vessel.runtimeWidth / 2, startY); var waveEndPos = new Vector3(cenPos.x + vessel.runtimeWidth / 2, startY); var startX = waveStartPos.x; diff --git a/Runtime/Internal/DrawSeriePie.cs b/Runtime/Internal/DrawSeriePie.cs index 6d0787f3..f5e80d09 100644 --- a/Runtime/Internal/DrawSeriePie.cs +++ b/Runtime/Internal/DrawSeriePie.cs @@ -199,7 +199,7 @@ namespace XCharts { var serieData = data[n]; serieData.index = n; - float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration); + var value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration); serieData.runtimePieStartAngle = startDegree; serieData.runtimePieToAngle = startDegree; serieData.runtimePieHalfAngle = startDegree; @@ -210,12 +210,11 @@ namespace XCharts } float degree = serie.pieRoseType == RoseType.Area ? (totalDegree / showdataCount) - : (totalDegree * value / dataTotalFilterMinAngle); + : (float)(totalDegree * value / dataTotalFilterMinAngle); if (serie.minAngle > 0 && degree < serie.minAngle) degree = serie.minAngle; serieData.runtimePieToAngle = startDegree + degree; serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ? - serie.runtimeInsideRadius + - (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax : + serie.runtimeInsideRadius + (float)((serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax) : serie.runtimeOutsideRadius; if (serieData.highlighted) { @@ -266,7 +265,7 @@ namespace XCharts SerieLabelHelper.AvoidLabelOverlap(serie, chart.theme.common); } - private float GetTotalAngle(Serie serie, float dataTotal, ref float totalAngle) + private double GetTotalAngle(Serie serie, double dataTotal, ref float totalAngle) { totalAngle = 360f; if (serie.minAngle > 0) diff --git a/Runtime/Internal/DrawSerieRadar.cs b/Runtime/Internal/DrawSerieRadar.cs index 43b04a2b..aa5c3fca 100644 --- a/Runtime/Internal/DrawSerieRadar.cs +++ b/Runtime/Internal/DrawSerieRadar.cs @@ -334,15 +334,15 @@ namespace XCharts for (int n = 0; n < dataCount; n++) { if (n >= serieData.data.Count) break; - float max = radar.GetIndicatorMax(n); - float value = serieData.GetCurrData(n, dataChangeDuration); + var max = radar.GetIndicatorMax(n); + var value = serieData.GetCurrData(n, dataChangeDuration); if (serieData.IsDataChanged()) dataChanging = true; if (max == 0) { max = serie.runtimeDataMax; } - var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max - : radar.runtimeDataRadius * value / max; + var radius = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max + : radar.runtimeDataRadius * value / max); var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle; radius *= rate; if (n == 0) @@ -505,8 +505,8 @@ namespace XCharts { max = serie.runtimeDataMax; } - var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max - : radar.runtimeDataRadius * value / max; + var radius = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max + : radar.runtimeDataRadius * value / max); var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle; radius *= rate; if (index == startIndex) diff --git a/Runtime/Internal/DrawSerieRing.cs b/Runtime/Internal/DrawSerieRing.cs index 66a25d32..6c01e9c8 100644 --- a/Runtime/Internal/DrawSerieRing.cs +++ b/Runtime/Internal/DrawSerieRing.cs @@ -81,7 +81,7 @@ namespace XCharts if (serieData.IsDataChanged()) dataChanging = true; var value = serieData.GetFirstData(dataChangeDuration); var max = serieData.GetLastData(); - var degree = 360 * value / max; + var degree = (float)(360 * value / max); var startDegree = GetStartAngle(serie); var toDegree = GetToAngle(serie, degree); var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted); diff --git a/Runtime/Internal/Interface/DelegateFunction.cs b/Runtime/Internal/Interface/DelegateFunction.cs index 971b3872..10249463 100644 --- a/Runtime/Internal/Interface/DelegateFunction.cs +++ b/Runtime/Internal/Interface/DelegateFunction.cs @@ -16,7 +16,7 @@ namespace XCharts /// 当前label对应的数值数据,Value轴或Time轴有效 /// 当前label对应的类目数据,Category轴有效 /// 最终显示的文本内容 - public delegate string DelegateAxisLabelFormatter(int labelIndex, float value, string category); + public delegate string DelegateAxisLabelFormatter(int labelIndex, double value, string category); /// /// The delegate function for SerieLabel‘s formatter. /// SerieLabel的formatter自定义委托。 @@ -24,5 +24,5 @@ namespace XCharts /// 数据索引 /// 数值 /// 最终显示的文本内容 - public delegate string DelegateSerieLabelFormatter(int dataIndex, float value); + public delegate string DelegateSerieLabelFormatter(int dataIndex, double value); } \ No newline at end of file diff --git a/Runtime/Internal/Utility/ChartCached.cs b/Runtime/Internal/Utility/ChartCached.cs index 0990f9db..3693db42 100644 --- a/Runtime/Internal/Utility/ChartCached.cs +++ b/Runtime/Internal/Utility/ChartCached.cs @@ -28,10 +28,10 @@ namespace XCharts private static Dictionary s_AxisLabel = new Dictionary(); - private static Dictionary> s_NumberToStr = new Dictionary>(); + private static Dictionary> s_NumberToStr = new Dictionary>(); private static Dictionary> s_PrecisionToStr = new Dictionary>(); - public static string FloatToStr(float value, string numericFormatter = "F", int precision = 0) + public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0) { if (precision > 0 && numericFormatter.Length == 1) { @@ -51,7 +51,7 @@ namespace XCharts } } - public static string NumberToStr(float value, string formatter) + public static string NumberToStr(double value, string formatter) { if (!s_NumberToStr.ContainsKey(value)) { diff --git a/Runtime/Internal/Utility/ChartHelper.cs b/Runtime/Internal/Utility/ChartHelper.cs index 7ebdd84f..ae66e4c2 100644 --- a/Runtime/Internal/Utility/ChartHelper.cs +++ b/Runtime/Internal/Utility/ChartHelper.cs @@ -725,7 +725,7 @@ namespace XCharts return (Color32)color; } - public static float GetMaxDivisibleValue(float max, int ceilRate) + public static double GetMaxDivisibleValue(double max, int ceilRate) { if (max == 0) return 0; if (max > -1 && max < 1) @@ -742,20 +742,20 @@ namespace XCharts } if (ceilRate == 0) { - var bigger = Mathf.Ceil(Mathf.Abs(max)); + var bigger = Math.Ceiling(Math.Abs(max)); int n = 1; while (bigger / (Mathf.Pow(10, n)) > 10) { n++; } - float mm = bigger; + double mm = bigger; if (mm > 10 && n < 38) { mm = bigger - bigger % (Mathf.Pow(10, n)); mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n); } - if (max < 0) return -Mathf.Ceil(mm); - else return Mathf.Ceil(mm); + if (max < 0) return -Math.Ceiling(mm); + else return Math.Ceiling(mm); } else { @@ -765,7 +765,7 @@ namespace XCharts } } - public static float GetMinDivisibleValue(float min, int ceilRate) + public static double GetMinDivisibleValue(double min, int ceilRate) { if (min == 0) return 0; if (min > -1 && min < 1) @@ -782,20 +782,20 @@ namespace XCharts } if (ceilRate == 0) { - var bigger = Mathf.Floor(Mathf.Abs(min)); + var bigger = Math.Floor(Math.Abs(min)); int n = 1; while (bigger / (Mathf.Pow(10, n)) > 10) { n++; } - float mm = bigger; + double mm = bigger; if (mm > 10 && n < 38) { mm = bigger - bigger % (Mathf.Pow(10, n)); mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n); } - if (min < 0) return -Mathf.Floor(mm); - else return Mathf.Floor(mm); + if (min < 0) return -Math.Floor(mm); + else return Math.Floor(mm); } else { @@ -805,11 +805,11 @@ namespace XCharts } } - public static float GetMaxLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber) + public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber) { splitNumber = 0; if (value <= 0) return 0; - float max = 0; + double max = 0; while (max < value) { if (isLogBaseE) @@ -825,7 +825,7 @@ namespace XCharts return max; } - public static float GetMinLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber) + public static float GetMinLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber) { splitNumber = 0; if (value > 1) return 1; @@ -845,7 +845,7 @@ namespace XCharts return min; } - public static int GetFloatAccuracy(float value) + public static int GetFloatAccuracy(double value) { if (value > 1 || value < -1) return 0; int count = 1; diff --git a/Runtime/Internal/Utility/MathUtil.cs b/Runtime/Internal/Utility/MathUtil.cs new file mode 100644 index 00000000..f51a69f6 --- /dev/null +++ b/Runtime/Internal/Utility/MathUtil.cs @@ -0,0 +1,52 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Text; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace XCharts +{ + public static class MathUtil + { + public static double Abs(double d) + { + return d > 0 ? d : -d; + } + + public static double Clamp(double d, double min, double max) + { + if (d >= min && d <= max) return d; + else if (d < min) return min; + else return max; + } + + public static bool Approximately(double a, double b) + { + return Math.Abs(b - a) < Math.Max(0.000001f * Math.Max(Math.Abs(a), Math.Abs(b)), Mathf.Epsilon * 8); + } + + public static double Clamp01(double value) + { + if (value < 0F) + return 0F; + else if (value > 1F) + return 1F; + else + return value; + } + + public static double Lerp(double a, double b, double t) + { + return a + (b - a) * Clamp01(t); + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/Utility/MathUtil.cs.meta b/Runtime/Internal/Utility/MathUtil.cs.meta new file mode 100644 index 00000000..0c3d0170 --- /dev/null +++ b/Runtime/Internal/Utility/MathUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 094dc7b90e3a049b48f15f990c050db1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/PolarChart.cs b/Runtime/PolarChart.cs index ddde054f..7b5ad14e 100644 --- a/Runtime/PolarChart.cs +++ b/Runtime/PolarChart.cs @@ -5,6 +5,7 @@ /* */ /************************************************/ +using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -76,7 +77,7 @@ namespace XCharts for (int i = 0; i <= 13; i++) { m_AngleAxes[0].AddData("bar" + i); - AddData(0, Random.Range(0, 10)); + AddData(0, UnityEngine.Random.Range(0, 10)); } } #endif @@ -268,8 +269,8 @@ namespace XCharts private void UpdateAxisMinMaxValue(Axis axis, bool updateChart = true) { if (axis.IsCategory() || !axis.show) return; - float tempMinValue = 0; - float tempMaxValue = 0; + double tempMinValue = 0; + double tempMaxValue = 0; if (axis is RadiusAxis) { SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, @@ -457,8 +458,8 @@ namespace XCharts var datas = serie.data; if (datas.Count <= 0) return; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - float min = m_RadiusAxis.GetCurrMinValue(dataChangeDuration); - float max = m_RadiusAxis.GetCurrMaxValue(dataChangeDuration); + double min = m_RadiusAxis.GetCurrMinValue(dataChangeDuration); + double max = m_RadiusAxis.GetCurrMaxValue(dataChangeDuration); var firstSerieData = datas[0]; var startPos = GetPolarPos(m_Polar, m_AngleAxis, firstSerieData, min, max, radius); var nextPos = Vector3.zero; @@ -550,20 +551,20 @@ namespace XCharts } } - private Vector3 GetPolarPos(Polar m_Polar, AngleAxis m_AngleAxis, SerieData serieData, float min, float max, float polarRadius) + private Vector3 GetPolarPos(Polar m_Polar, AngleAxis m_AngleAxis, SerieData serieData, double min, double max, float polarRadius) { var angle = 0f; if (!m_AngleAxis.clockwise) { - angle = m_AngleAxis.runtimeStartAngle - serieData.GetData(1); + angle = m_AngleAxis.runtimeStartAngle - (float)serieData.GetData(1); } else { - angle = m_AngleAxis.runtimeStartAngle + serieData.GetData(1); + angle = m_AngleAxis.runtimeStartAngle + (float)serieData.GetData(1); } angle = (angle + 360) % 360; var value = serieData.GetData(0); - var radius = (value - min) / (max - min) * polarRadius; + var radius = (float)((value - min) / (max - min) * polarRadius); serieData.runtimeAngle = angle; serieData.runtimePosition = ChartHelper.GetPos(m_Polar.runtimeCenterPos, radius, angle, true); return serieData.runtimePosition; @@ -612,7 +613,7 @@ namespace XCharts for (int j = 0; j < count; j++) { var serieData = serie.data[j]; - var flag = Mathf.Abs(serieData.runtimeAngle - angle) < Mathf.Abs(diff / 2); + var flag = Math.Abs(serieData.runtimeAngle - angle) < Math.Abs(diff / 2); if (serieData.highlighted != flag) { refresh = true; @@ -704,9 +705,9 @@ namespace XCharts var dist = Vector2.Distance(pointerPos, cenPos); if (dist > radius) dist = radius; - float min = m_RadiusAxis.runtimeMinValue; - float max = m_RadiusAxis.runtimeMaxValue; - var value = (float)(min + dist / radius * m_RadiusAxis.runtimeMinMaxRange); + double min = m_RadiusAxis.runtimeMinValue; + double max = m_RadiusAxis.runtimeMaxValue; + var value = min + dist / radius * m_RadiusAxis.runtimeMinMaxRange; m_RadiusAxis.UpdateTooptipLabelText(ChartCached.FloatToStr(value)); m_RadiusAxis.UpdateTooltipLabelPos(ChartHelper.GetPos(cenPos, dist, m_AngleAxis.runtimeStartAngle, true)); } diff --git a/Runtime/Template/SerieTemplate.cs b/Runtime/Template/SerieTemplate.cs index f5815c9a..c81f996c 100644 --- a/Runtime/Template/SerieTemplate.cs +++ b/Runtime/Template/SerieTemplate.cs @@ -125,7 +125,7 @@ namespace XCharts serie.symbol.size = 4; serie.symbol.selectedSize = 6; serie.showDataName = true; - List data = new List(); + List data = new List(); for (int i = 0; i < 5; i++) { data.Add(Random.Range(20, 90));