mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
整理重构代码
This commit is contained in:
@@ -943,7 +943,6 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public float runtimePieDataTotal { get; internal set; }
|
||||
public float runtimeWaveSpeed { get; internal set; }
|
||||
internal int runtimeLastCheckDataCount { get; set; }
|
||||
internal float runtimeCheckValue { get; set; }
|
||||
public bool nameDirty { get { return m_NameDirty; } }
|
||||
|
||||
@@ -1547,22 +1546,21 @@ namespace XCharts
|
||||
public void ClearHighlight()
|
||||
{
|
||||
highlighted = false;
|
||||
foreach (var sd in m_Data)
|
||||
foreach (var serieData in m_Data)
|
||||
{
|
||||
sd.highlighted = false;
|
||||
serieData.highlighted = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定索引的数据为高亮状态
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
public void SetHighlight(int index)
|
||||
public void SetHighlight(int index, bool flag)
|
||||
{
|
||||
if (index <= 0) return;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
var serieData = GetSerieData(index);
|
||||
if (serieData != null)
|
||||
{
|
||||
m_Data[i].highlighted = index == i;
|
||||
serieData.highlighted = flag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1572,13 +1570,6 @@ namespace XCharts
|
||||
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>
|
||||
@@ -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)
|
||||
{
|
||||
if (m_Ignore)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace XCharts
|
||||
/// Vessel component for liquid chart.
|
||||
/// <para>
|
||||
/// 容器组件。
|
||||
/// 一般用于LiquidChart。
|
||||
/// 一般用于LiquidChart。可以有多个Vessel,Serie中用vesselIndex来对应。
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
@@ -73,6 +73,7 @@ namespace XCharts
|
||||
set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Thickness of vessel.
|
||||
/// 容器厚度。
|
||||
/// </summary>
|
||||
public float shapeWidth
|
||||
@@ -81,6 +82,7 @@ namespace XCharts
|
||||
set { if (PropertyUtility.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The gap between the vessel and the liquid.
|
||||
/// 间隙。容器和液体的间隙。
|
||||
/// </summary>
|
||||
public float gap
|
||||
@@ -152,7 +154,8 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public float runtimeRadius { get; internal set; }
|
||||
/// <summary>
|
||||
/// 运行时内半径。
|
||||
/// The actual radius after deducting shapeWidth and gap.
|
||||
/// 运行时内半径。扣除厚度和间隙后的实际半径。
|
||||
/// </summary>
|
||||
public float runtimeInnerRadius { get; internal set; }
|
||||
public static Vessel defaultVessel
|
||||
|
||||
86
Runtime/Helper/SerieHelper.cs
Normal file
86
Runtime/Helper/SerieHelper.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/SerieHelper.cs.meta
Normal file
11
Runtime/Helper/SerieHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c031417514104eebb5bbd60dd1f90fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,15 +0,0 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieDataHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,15 @@
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
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;
|
||||
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;
|
||||
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)
|
||||
{
|
||||
@@ -148,7 +149,7 @@ namespace XCharts
|
||||
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)
|
||||
return serieData.emphasis.itemStyle;
|
||||
@@ -156,7 +157,7 @@ namespace XCharts
|
||||
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)
|
||||
{
|
||||
@@ -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;
|
||||
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 color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : (Color)theme.GetColor(index);
|
||||
@@ -191,7 +192,7 @@ namespace XCharts
|
||||
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;
|
||||
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;
|
||||
if (highlight)
|
||||
@@ -235,7 +236,7 @@ namespace XCharts
|
||||
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);
|
||||
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
|
||||
@@ -243,7 +244,7 @@ namespace XCharts
|
||||
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);
|
||||
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];
|
||||
}
|
||||
|
||||
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>
|
||||
/// <param name="dimension"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <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 max = float.MinValue;
|
||||
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;
|
||||
}
|
||||
}
|
||||
float min = 0, max = 0;
|
||||
GetMinMaxData(serie, dimension, out min, out max, dataZoom);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
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 max = float.MinValue;
|
||||
float min = float.MaxValue;
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
float min = 0, max = 0;
|
||||
GetMinMaxData(serie, out min, out max, dataZoom);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
serie.runtimeDataMin = min;
|
||||
serie.runtimeDataMax = max;
|
||||
}
|
||||
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
|
||||
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
|
||||
}
|
||||
|
||||
public static bool IsAllZeroValue(Serie serie, int dimension = 1)
|
||||
{
|
||||
foreach (var serieData in serie.data)
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class VisualMapHelper
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -550,7 +550,7 @@ namespace XCharts
|
||||
case SerieType.Line:
|
||||
bool refresh = false;
|
||||
var count = serie.data.Count;
|
||||
SerieHelper.GetDimensionMinMaxData(serie, 1, -1);
|
||||
SerieHelper.UpdateMinMaxData(serie, 1, -1);
|
||||
var diff = (serie.runtimeDataMax - serie.runtimeDataMin) / (count - 1);
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
|
||||
@@ -375,7 +375,7 @@ namespace XCharts
|
||||
var pointList = radar.runtimeDataPosList[key];
|
||||
var startIndex = GetStartShowIndex(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++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
|
||||
Reference in New Issue
Block a user