diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index bd4d46ca..707c0086 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -34,6 +34,7 @@ ## Latest +* (2021.05.01) Fixed an issue where some super large or super small values could not be properly represented * (2021.04.29) Fixed an issue with `Radar` switching to `Circle` anomaly #139 * (2021.04.29) Added `Settings`'s `reversePainter` to set whether or not `Serie` is drawn in reverse order * (2021.04.28) Fixed bug where `AxisLabel` displayed incorrectly with `DataRoom` (#138) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d4a3fe..457afaa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ ## Latest +* (2021.05.01) 修复无法正确表示部分超大或超小数值的问题 * (2021.04.29) 修复`Radar`切换到`Circle`异常的问题 #139 * (2021.04.29) 增加`Settings`的`reversePainter`可设置`Serie`的绘制是否逆序 * (2021.04.28) 增加`SerieData`的`ignore`可忽略当前数据项 diff --git a/Runtime/Component/Main/Axis.cs b/Runtime/Component/Main/Axis.cs index 2d7e42ed..53730b1b 100644 --- a/Runtime/Component/Main/Axis.cs +++ b/Runtime/Component/Main/Axis.cs @@ -107,7 +107,7 @@ namespace XCharts [SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine; [SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea; - [NonSerialized] private float m_MinMaxValueRange; + [NonSerialized] private double m_MinMaxValueRange; [NonSerialized] private bool m_NeedUpdateFilterData; /// @@ -412,7 +412,7 @@ namespace XCharts 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); } } internal bool runtimeLastCheckInverse { get; set; } - internal float runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } } + internal double runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } } internal List runtimeData { get { return m_RuntimeData; } } private int filterStart; private int filterEnd; diff --git a/Runtime/Component/Main/Serie.cs b/Runtime/Component/Main/Serie.cs index e75da2a1..7b372c23 100644 --- a/Runtime/Component/Main/Serie.cs +++ b/Runtime/Component/Main/Serie.cs @@ -1098,7 +1098,7 @@ namespace XCharts { get { - float max = int.MinValue; + float max = float.MinValue; foreach (var sdata in data) { if (sdata.show && sdata.data[1] > max) @@ -1117,7 +1117,7 @@ namespace XCharts { get { - float max = int.MinValue; + float max = float.MinValue; foreach (var sdata in data) { if (sdata.show && sdata.data[0] > max) @@ -1136,7 +1136,7 @@ namespace XCharts { get { - float min = int.MaxValue; + float min = float.MaxValue; foreach (var sdata in data) { if (sdata.show && sdata.data[1] < min) @@ -1155,7 +1155,7 @@ namespace XCharts { get { - float min = int.MaxValue; + float min = float.MaxValue; foreach (var sdata in data) { if (sdata.show && sdata.data[0] < min) diff --git a/Runtime/GanttChart.cs b/Runtime/GanttChart.cs index f3c2525b..4b706168 100644 --- a/Runtime/GanttChart.cs +++ b/Runtime/GanttChart.cs @@ -40,8 +40,8 @@ namespace XCharts #endif protected override void GetSeriesMinMaxValue(Axis axis, int axisIndex, out float tempMinValue, out float tempMaxValue) { - tempMinValue = int.MaxValue; - tempMaxValue = int.MinValue; + tempMinValue = float.MaxValue; + tempMaxValue = float.MinValue; foreach (var serie in m_Series.list) { if (serie.type != SerieType.Gantt) continue; @@ -57,9 +57,8 @@ namespace XCharts } } } - if (tempMinValue == int.MaxValue) tempMinValue = 0; - if (tempMaxValue == int.MinValue) tempMaxValue = 0; - //AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true, 60); + if (tempMinValue == float.MaxValue) tempMinValue = 0; + if (tempMaxValue == float.MinValue) tempMaxValue = 0; } protected override void OnRefreshLabel() diff --git a/Runtime/Helper/AxisHelper.cs b/Runtime/Helper/AxisHelper.cs index 23b8f96d..a615f976 100644 --- a/Runtime/Helper/AxisHelper.cs +++ b/Runtime/Helper/AxisHelper.cs @@ -37,12 +37,12 @@ namespace XCharts if (axis.interval > 0) { if (coordinateWid <= 0) return 0; - int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval); + int num = (int)(axis.runtimeMinMaxRange / axis.interval); int maxNum = Mathf.CeilToInt(coordinateWid / 15); if (num > maxNum) { axis.interval *= 2; - num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval); + num = (int)(axis.runtimeMinMaxRange / axis.interval); } return num; } @@ -56,12 +56,12 @@ namespace XCharts if (axis.interval > 0) { if (coordinateWid <= 0) return 0; - int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval); + int num = (int)(axis.runtimeMinMaxRange / axis.interval); int maxNum = Mathf.CeilToInt(coordinateWid / 15); if (num > maxNum) { axis.interval *= 2; - num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval); + num = (int)(axis.runtimeMinMaxRange / axis.interval); } return num; } @@ -238,8 +238,14 @@ namespace XCharts if (axis.type == Axis.AxisType.Value && axis.interval > 0) { if (axis.runtimeMinMaxRange <= 0) return 0; - if (index >= splitNum) return coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange; - else return axis.interval * coordinateWidth / axis.runtimeMinMaxRange; + if (index >= splitNum) + { + return (float)(coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange); + } + else + { + return (float)(axis.interval * coordinateWidth / axis.runtimeMinMaxRange); + } } else { @@ -343,7 +349,7 @@ namespace XCharts break; } } - var tempRange = maxValue - minValue; + double tempRange = maxValue - minValue; if (axis.runtimeMinMaxRange != tempRange) { axis.runtimeMinMaxRange = tempRange; diff --git a/Runtime/Helper/SeriesHelper.cs b/Runtime/Helper/SeriesHelper.cs index 9f6878ce..5b642847 100644 --- a/Runtime/Helper/SeriesHelper.cs +++ b/Runtime/Helper/SeriesHelper.cs @@ -432,8 +432,8 @@ namespace XCharts 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) { - float min = int.MaxValue; - float max = int.MinValue; + float min = float.MaxValue; + float max = float.MinValue; var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar); if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue)) { @@ -512,8 +512,8 @@ namespace XCharts } } } - float tmax = int.MinValue; - float tmin = int.MaxValue; + float tmax = float.MinValue; + float tmin = float.MaxValue; foreach (var tt in _serieTotalValueForMinMax) { if (tt.Value > tmax) tmax = tt.Value; @@ -523,15 +523,15 @@ namespace XCharts if (tmin < min) min = tmin; } } - if (max == int.MinValue && min == int.MaxValue) + if (max == float.MinValue && min == float.MaxValue) { minVaule = 0; maxValue = 0; } else { - minVaule = min > 1 ? Mathf.FloorToInt(min) : min; - maxValue = max > 1 ? Mathf.CeilToInt(max) : max; + minVaule = min > 1 ? Mathf.Floor(min) : min; + maxValue = max > 1 ? Mathf.Ceil(max) : max; } } diff --git a/Runtime/Internal/CoordinateChart_DrawBar.cs b/Runtime/Internal/CoordinateChart_DrawBar.cs index 0c5a7dba..a441c527 100644 --- a/Runtime/Internal/CoordinateChart_DrawBar.cs +++ b/Runtime/Internal/CoordinateChart_DrawBar.cs @@ -221,15 +221,15 @@ 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.runtimeHeight) : 0; + barHig = valueTotal != 0 ? (float)(value / valueTotal * grid.runtimeHeight) : 0; } else { - valueTotal = yMaxValue - yMinValue; + valueTotal = (double)(yMaxValue - yMinValue); if (valueTotal != 0) { if (yAxis.IsLog()) @@ -240,7 +240,7 @@ namespace XCharts } else { - barHig = (yMinValue > 0 ? value - yMinValue : value) / valueTotal * grid.runtimeHeight; + barHig = (float)((yMinValue > 0 ? value - yMinValue : value) / valueTotal * grid.runtimeHeight); } } } diff --git a/Runtime/Internal/CoordinateChart_DrawCandlestick.cs b/Runtime/Internal/CoordinateChart_DrawCandlestick.cs index 9b655bae..e2b20f9b 100644 --- a/Runtime/Internal/CoordinateChart_DrawCandlestick.cs +++ b/Runtime/Internal/CoordinateChart_DrawCandlestick.cs @@ -60,12 +60,12 @@ namespace XCharts if (!xAxis.boundaryGap) pX -= categoryWidth / 2; float pY = zeroY; var barHig = 0f; - var valueTotal = yMaxValue - yMinValue; + double valueTotal = yMaxValue - yMinValue; var minCut = (yMinValue > 0 ? yMinValue : 0); if (valueTotal != 0) { - barHig = (close - open) / valueTotal * grid.runtimeHeight; - pY += (open - minCut) / valueTotal * grid.runtimeHeight; + barHig = (float)((close - open) / valueTotal * grid.runtimeHeight); + pY += (float)((open - minCut) / valueTotal * grid.runtimeHeight); } serieData.runtimeStackHig = barHig; var isBarEnd = false; @@ -96,8 +96,8 @@ namespace XCharts var itemWidth = Mathf.Abs(prt.x - plb.x); var itemHeight = Mathf.Abs(plt.y - prb.y); var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2); - var lowPos = new Vector3(center.x, zeroY + (lowest - minCut) / valueTotal * grid.runtimeHeight); - var heighPos = new Vector3(center.x, zeroY + (heighest - minCut) / valueTotal * grid.runtimeHeight); + var lowPos = new Vector3(center.x, zeroY + (float)((lowest - minCut) / valueTotal * grid.runtimeHeight)); + var heighPos = new Vector3(center.x, zeroY + (float)((heighest - minCut) / valueTotal * grid.runtimeHeight)); var openCenterPos = new Vector3(center.x, prb.y); var closeCenterPos = new Vector3(center.x, prt.y); if (barWidth > 2f * borderWidth) diff --git a/Runtime/Internal/CoordinateChart_DrawLine.cs b/Runtime/Internal/CoordinateChart_DrawLine.cs index ad12063c..1186499e 100644 --- a/Runtime/Internal/CoordinateChart_DrawLine.cs +++ b/Runtime/Internal/CoordinateChart_DrawLine.cs @@ -455,8 +455,9 @@ namespace XCharts } else { - if ((yMaxValue - yMinValue) <= 0) yDataHig = 0; - else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * grid.runtimeHeight; + double valueTotal = yMaxValue - yMinValue; + if (valueTotal <= 0) yDataHig = 0; + else yDataHig = (float)((yValue - yMinValue) / valueTotal * grid.runtimeHeight); } np = new Vector3(pX + xDataHig, pY + yDataHig); } @@ -481,8 +482,9 @@ namespace XCharts } else { - if ((yMaxValue - yMinValue) <= 0) yDataHig = 0; - else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * grid.runtimeHeight; + double valueTotal = yMaxValue - yMinValue; + if (valueTotal <= 0) yDataHig = 0; + else yDataHig = (float)((yValue - yMinValue) / valueTotal * grid.runtimeHeight); } np = new Vector3(pX, pY + yDataHig); } diff --git a/Runtime/Internal/CoordinateChart_DrawScatter.cs b/Runtime/Internal/CoordinateChart_DrawScatter.cs index 5614d043..f3582672 100644 --- a/Runtime/Internal/CoordinateChart_DrawScatter.cs +++ b/Runtime/Internal/CoordinateChart_DrawScatter.cs @@ -95,7 +95,7 @@ namespace XCharts } else { - return (value - axis.runtimeMinValue) / (axis.runtimeMaxValue - axis.runtimeMinValue) * totalWidth; + return (float)((value - axis.runtimeMinValue) / axis.runtimeMinMaxRange * totalWidth); } } } diff --git a/Runtime/Internal/Utility/ChartHelper.cs b/Runtime/Internal/Utility/ChartHelper.cs index f7d43b79..505e117d 100644 --- a/Runtime/Internal/Utility/ChartHelper.cs +++ b/Runtime/Internal/Utility/ChartHelper.cs @@ -712,20 +712,20 @@ namespace XCharts } if (ceilRate == 0) { - int bigger = Mathf.CeilToInt(Mathf.Abs(max)); + var bigger = Mathf.Ceil(Mathf.Abs(max)); int n = 1; while (bigger / (Mathf.Pow(10, n)) > 10) { n++; } float mm = bigger; - if (mm > 10) + 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.CeilToInt(mm); - else return Mathf.CeilToInt(mm); + if (max < 0) return -Mathf.Ceil(mm); + else return Mathf.Ceil(mm); } else { @@ -752,20 +752,20 @@ namespace XCharts } if (ceilRate == 0) { - int bigger = Mathf.FloorToInt(Mathf.Abs(min)); + var bigger = Mathf.Floor(Mathf.Abs(min)); int n = 1; while (bigger / (Mathf.Pow(10, n)) > 10) { n++; } float mm = bigger; - if (mm > 10) + 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.FloorToInt(mm); - else return Mathf.FloorToInt(mm); + if (min < 0) return -Mathf.Floor(mm); + else return Mathf.Floor(mm); } else { diff --git a/Runtime/PolarChart.cs b/Runtime/PolarChart.cs index 4df2ae38..8d5c1de5 100644 --- a/Runtime/PolarChart.cs +++ b/Runtime/PolarChart.cs @@ -706,7 +706,7 @@ namespace XCharts if (dist > radius) dist = radius; float min = m_RadiusAxis.runtimeMinValue; float max = m_RadiusAxis.runtimeMaxValue; - var value = min + dist / radius * m_RadiusAxis.runtimeMinMaxRange; + var value = (float)(min + dist / radius * m_RadiusAxis.runtimeMinMaxRange); m_RadiusAxis.UpdateTooptipLabelText(ChartCached.FloatToStr(value)); m_RadiusAxis.UpdateTooltipLabelPos(ChartHelper.GetPos(cenPos, dist, m_AngleAxis.runtimeStartAngle, true)); }