整理重构代码

This commit is contained in:
monitor1394
2020-07-07 06:53:02 +08:00
parent d343ff9d07
commit aa2f90d048
9 changed files with 143 additions and 116 deletions

View File

@@ -943,7 +943,6 @@ namespace XCharts
/// </summary> /// </summary>
public float runtimePieDataTotal { get; internal set; } public float runtimePieDataTotal { get; internal set; }
public float runtimeWaveSpeed { get; internal set; } public float runtimeWaveSpeed { get; internal set; }
internal int runtimeLastCheckDataCount { get; set; }
internal float runtimeCheckValue { get; set; } internal float runtimeCheckValue { get; set; }
public bool nameDirty { get { return m_NameDirty; } } public bool nameDirty { get { return m_NameDirty; } }
@@ -1547,22 +1546,21 @@ namespace XCharts
public void ClearHighlight() public void ClearHighlight()
{ {
highlighted = false; highlighted = false;
foreach (var sd in m_Data) foreach (var serieData in m_Data)
{ {
sd.highlighted = false; serieData.highlighted = false;
} }
} }
/// <summary> /// <summary>
/// 设置指定索引的数据为高亮状态 /// 设置指定索引的数据为高亮状态
/// </summary> /// </summary>
/// <param name="index"></param> public void SetHighlight(int index, bool flag)
public void SetHighlight(int index)
{ {
if (index <= 0) return; var serieData = GetSerieData(index);
for (int i = 0; i < m_Data.Count; i++) if (serieData != null)
{ {
m_Data[i].highlighted = index == i; serieData.highlighted = flag;
} }
} }
@@ -1572,13 +1570,6 @@ namespace XCharts
else return m_BarWidth * categoryWidth; else return m_BarWidth * categoryWidth;
} }
internal float GetBarGap(float categoryWidth)
{
if (m_BarGap == -1) return 0;
else if (m_BarGap <= 1) return GetBarWidth(categoryWidth) * m_BarGap;
else return m_BarGap;
}
/// <summary> /// <summary>
/// 设置所有数据的图标是否显示 /// 设置所有数据的图标是否显示
/// </summary> /// </summary>
@@ -1633,15 +1624,6 @@ namespace XCharts
} }
} }
internal bool IsNeedShowDataIcon()
{
foreach (var data in m_Data)
{
if (data.iconStyle.show) return true;
}
return false;
}
public bool IsIgnoreIndex(int index, int dimension) public bool IsIgnoreIndex(int index, int dimension)
{ {
if (m_Ignore) if (m_Ignore)

View File

@@ -14,7 +14,7 @@ namespace XCharts
/// Vessel component for liquid chart. /// Vessel component for liquid chart.
/// <para> /// <para>
/// 容器组件。 /// 容器组件。
/// 一般用于LiquidChart。 /// 一般用于LiquidChart。可以有多个VesselSerie中用vesselIndex来对应。
/// </para> /// </para>
/// </summary> /// </summary>
[Serializable] [Serializable]
@@ -73,6 +73,7 @@ namespace XCharts
set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetVerticesDirty(); } set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetVerticesDirty(); }
} }
/// <summary> /// <summary>
/// Thickness of vessel.
/// 容器厚度。 /// 容器厚度。
/// </summary> /// </summary>
public float shapeWidth public float shapeWidth
@@ -81,6 +82,7 @@ namespace XCharts
set { if (PropertyUtility.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); } set { if (PropertyUtility.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); }
} }
/// <summary> /// <summary>
/// The gap between the vessel and the liquid.
/// 间隙。容器和液体的间隙。 /// 间隙。容器和液体的间隙。
/// </summary> /// </summary>
public float gap public float gap
@@ -152,7 +154,8 @@ namespace XCharts
/// </summary> /// </summary>
public float runtimeRadius { get; internal set; } public float runtimeRadius { get; internal set; }
/// <summary> /// <summary>
/// 运行时内半径。 /// The actual radius after deducting shapeWidth and gap.
/// 运行时内半径。扣除厚度和间隙后的实际半径。
/// </summary> /// </summary>
public float runtimeInnerRadius { get; internal set; } public float runtimeInnerRadius { get; internal set; }
public static Vessel defaultVessel public static Vessel defaultVessel

View File

@@ -0,0 +1,86 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Text;
using UnityEngine;
namespace XCharts
{
public static partial class SerieHelper
{
/// <summary>
/// Gets the maximum and minimum values of the specified dimension of a serie.
/// 获得系列指定维数的最大最小值。
/// </summary>
/// <param name="serie">指定系列</param>
/// <param name="dimension">指定维数</param>
/// <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, DataZoom dataZoom = null)
{
max = float.MinValue;
min = float.MaxValue;
var dataList = serie.GetDataList(dataZoom);
for (int i = 0; i < dataList.Count; i++)
{
var serieData = dataList[i];
if (serieData.show && serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value > max) max = value;
if (value < min) min = value;
}
}
}
/// <summary>
/// Gets the maximum and minimum values of all data in the serie.
/// 获得系列所有数据的最大最小值。
/// </summary>
/// <param name="serie"></param>
/// <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)
{
max = float.MinValue;
min = float.MaxValue;
var dataList = serie.GetDataList(dataZoom);
for (int i = 0; i < dataList.Count; i++)
{
var serieData = dataList[i];
if (serieData.show)
{
var count = serie.showDataDimension > serieData.data.Count ? serieData.data.Count : serie.showDataDimension;
for (int j = 0; j < count; j++)
{
var value = serieData.data[j];
if (value > max) max = value;
if (value < min) min = value;
}
}
}
}
/// <summary>
/// Whether the data for the specified dimension of serie are all 0.
/// 系列指定维数的数据是否全部为0。
/// </summary>
/// <param name="serie">系列</param>
/// <param name="dimension">指定维数</param>
/// <returns></returns>
public static bool IsAllZeroValue(Serie serie, int dimension = 1)
{
foreach (var serieData in serie.data)
{
if (serieData.GetData(dimension) != 0) return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c031417514104eebb5bbd60dd1f90fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,15 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class SerieDataHelper
{
}
}

View File

@@ -4,14 +4,15 @@
/* https://github.com/monitor1394 */ /* https://github.com/monitor1394 */
/* */ /* */
/******************************************/ /******************************************/
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
namespace XCharts namespace XCharts
{ {
internal static class SerieHelper public static partial class SerieHelper
{ {
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight, bool useDefault = true) internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
bool highlight, bool useDefault = true)
{ {
var color = Color.clear; var color = Color.clear;
if (highlight) if (highlight)
@@ -109,7 +110,7 @@ namespace XCharts
} }
} }
public static bool IsDownPoint(Serie serie, int index) internal static bool IsDownPoint(Serie serie, int index)
{ {
var dataPoints = serie.dataPoints; var dataPoints = serie.dataPoints;
if (dataPoints.Count < 2) return false; if (dataPoints.Count < 2) return false;
@@ -135,7 +136,7 @@ namespace XCharts
} }
} }
public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false) internal static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
{ {
if (highlight) if (highlight)
{ {
@@ -148,7 +149,7 @@ namespace XCharts
else return serie.itemStyle; else return serie.itemStyle;
} }
public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData) internal static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
{ {
if (!serie.IsPerformanceMode() && serieData != null && serieData.enableEmphasis && serieData.emphasis.show) if (!serie.IsPerformanceMode() && serieData != null && serieData.enableEmphasis && serieData.emphasis.show)
return serieData.emphasis.itemStyle; return serieData.emphasis.itemStyle;
@@ -156,7 +157,7 @@ namespace XCharts
else return null; else return null;
} }
public static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false) internal static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
{ {
if (highlight) if (highlight)
{ {
@@ -172,13 +173,13 @@ namespace XCharts
} }
} }
public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData) internal static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
{ {
if (!serie.IsPerformanceMode() && serieData.enableSymbol) return serieData.symbol; if (!serie.IsPerformanceMode() && serieData.enableSymbol) return serieData.symbol;
else return serie.symbol; else return serie.symbol;
} }
public static Color GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight) internal static Color GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{ {
var areaStyle = serie.areaStyle; var areaStyle = serie.areaStyle;
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : (Color)theme.GetColor(index); var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : (Color)theme.GetColor(index);
@@ -191,7 +192,7 @@ namespace XCharts
return color; return color;
} }
public static Color GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight) internal static Color GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{ {
var areaStyle = serie.areaStyle; var areaStyle = serie.areaStyle;
if (!ChartHelper.IsClearColor(areaStyle.toColor)) if (!ChartHelper.IsClearColor(areaStyle.toColor))
@@ -211,7 +212,7 @@ namespace XCharts
} }
} }
public static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight) internal static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{ {
var color = Color.clear; var color = Color.clear;
if (highlight) if (highlight)
@@ -235,7 +236,7 @@ namespace XCharts
return color; return color;
} }
public static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight, bool useLineWidth = true) internal static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight, bool useLineWidth = true)
{ {
var itemStyle = GetItemStyle(serie, serieData, highlight); var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth; if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
@@ -243,7 +244,7 @@ namespace XCharts
else return 0; else return 0;
} }
public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight) internal static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
{ {
var itemStyle = GetItemStyle(serie, serieData, highlight); var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle != null) return itemStyle.cornerRadius; if (itemStyle != null) return itemStyle.cornerRadius;
@@ -266,27 +267,23 @@ namespace XCharts
serie.runtimeOutsideRadius = serie.radius[1] <= 1 ? minWidth * serie.radius[1] : serie.radius[1]; serie.runtimeOutsideRadius = serie.radius[1] <= 1 ? minWidth * serie.radius[1] : serie.radius[1];
} }
internal static string GetNumericFormatter(Serie serie, SerieData serieData)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
else return string.Empty;
}
/// <summary> /// <summary>
/// 获得指定维数的最大最小值 /// 获得指定维数的最大最小值
/// </summary> /// </summary>
/// <param name="dimension"></param> /// <param name="dimension"></param>
/// <param name="dataZoom"></param> /// <param name="dataZoom"></param>
/// <returns></returns> /// <returns></returns>
public static void GetDimensionMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null) internal static void UpdateMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null)
{ {
var dataList = serie.GetDataList(dataZoom); float min = 0, max = 0;
float max = float.MinValue; GetMinMaxData(serie, dimension, out min, out max, dataZoom);
float min = float.MaxValue;
for (int i = 0; i < dataList.Count; i++)
{
var serieData = dataList[i];
if (serieData.show && serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value > max) max = value;
if (value < min) min = value;
}
}
if (ceilRate < 0) if (ceilRate < 0)
{ {
serie.runtimeDataMin = min; serie.runtimeDataMin = min;
@@ -299,43 +296,20 @@ namespace XCharts
} }
} }
public static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null) internal static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null)
{ {
var dataList = serie.GetDataList(dataZoom); float min = 0, max = 0;
float max = float.MinValue; GetMinMaxData(serie, out min, out max, dataZoom);
float min = float.MaxValue; if (ceilRate < 0)
for (int i = 0; i < dataList.Count; i++)
{ {
var serieData = dataList[i]; serie.runtimeDataMin = min;
if (serieData.show) serie.runtimeDataMax = max;
{
var count = serie.showDataDimension > serieData.data.Count ? serieData.data.Count : serie.showDataDimension;
for (int j = 0; j < count; j++)
{
var value = serieData.data[j];
if (value > max) max = value;
if (value < min) min = value;
}
}
} }
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate); else
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
}
public static bool IsAllZeroValue(Serie serie, int dimension = 1)
{
foreach (var serieData in serie.data)
{ {
if (serieData.GetData(dimension) != 0) return false; serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
} }
return true;
}
public static string GetNumericFormatter(Serie serie, SerieData serieData)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
else return string.Empty;
} }
} }
} }

View File

@@ -1,14 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
namespace XCharts
{
public static class VisualMapHelper
{
}
}

View File

@@ -550,7 +550,7 @@ namespace XCharts
case SerieType.Line: case SerieType.Line:
bool refresh = false; bool refresh = false;
var count = serie.data.Count; var count = serie.data.Count;
SerieHelper.GetDimensionMinMaxData(serie, 1, -1); SerieHelper.UpdateMinMaxData(serie, 1, -1);
var diff = (serie.runtimeDataMax - serie.runtimeDataMin) / (count - 1); var diff = (serie.runtimeDataMax - serie.runtimeDataMin) / (count - 1);
for (int j = 0; j < count; j++) for (int j = 0; j < count; j++)
{ {

View File

@@ -375,7 +375,7 @@ namespace XCharts
var pointList = radar.runtimeDataPosList[key]; var pointList = radar.runtimeDataPosList[key];
var startIndex = GetStartShowIndex(serie); var startIndex = GetStartShowIndex(serie);
var endIndex = GetEndShowIndex(serie); var endIndex = GetEndShowIndex(serie);
SerieHelper.GetDimensionMinMaxData(serie, 1, radar.ceilRate); SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate);
for (int j = 0; j < serie.data.Count; j++) for (int j = 0; j < serie.data.Count; j++)
{ {
var serieData = serie.data[j]; var serieData = serie.data[j];