优化数据存储类型由float全部转为double

This commit is contained in:
monitor1394
2021-07-08 07:19:31 +08:00
parent af8391faee
commit 16058d7d30
45 changed files with 434 additions and 368 deletions

View File

@@ -112,14 +112,14 @@ namespace XCharts
/// <param name="maxValue"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
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
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
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)
{

View File

@@ -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;

View File

@@ -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);

View File

@@ -22,11 +22,11 @@ namespace XCharts
/// <param name="min">最小值</param>
/// <param name="max">最大值</param>
/// <param name="dataZoom">缩放组件默认null</param>
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
/// <param name="min"></param>
/// <param name="max"></param>
/// <param name="dataZoom"></param>
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
/// <returns></returns>
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;

View File

@@ -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)
{

View File

@@ -5,6 +5,7 @@
/* */
/************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -410,7 +411,7 @@ namespace XCharts
/// <param name="minVaule"></param>
/// <param name="maxValue"></param>
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
/// <param name="minVaule"></param>
/// <param name="maxValue"></param>
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<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
private static Dictionary<int, double> _serieTotalValueForMinMax = new Dictionary<int, double>();
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;
}
}

View File

@@ -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("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
@@ -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))
{

View File

@@ -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;
}