3.0 - optimize code

This commit is contained in:
monitor1394
2022-03-04 22:17:32 +08:00
parent 1ee0df09eb
commit 5745fea9a1
59 changed files with 482 additions and 435 deletions

View File

@@ -38,7 +38,6 @@ namespace XCharts.Runtime
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 0.6f;
[SerializeField] private bool m_TooltipHighlight;
[SerializeField] private Color32 m_HighlightColor;
[SerializeField] private Color32 m_HighlightToColor;
@@ -88,14 +87,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 鼠标悬浮时是否高亮之前的区域
/// </summary>
public bool tooltipHighlight
{
get { return m_TooltipHighlight; }
set { if (PropertyUtil.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 高亮时区域填充的颜色如果highlightToColor不是默认值则表示渐变色的起点颜色。
/// </summary>

View File

@@ -12,7 +12,7 @@ namespace XCharts.Runtime
UnderLabel,
AboveLabel
}
[SerializeField] private bool m_Show;
[SerializeField] private bool m_Show = false;
[SerializeField] private Layer m_Layer;
[SerializeField] private Align m_Align = Align.Left;
[SerializeField] private Sprite m_Sprite;

View File

@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
@@ -11,24 +8,6 @@ namespace XCharts.Runtime
[System.Serializable]
public class ItemStyle : ChildComponent, ISerieDataComponent
{
/// <summary>
/// 线的类型。
/// </summary>
public enum Type
{
/// <summary>
/// 实线
/// </summary>
Solid,
/// <summary>
/// 虚线
/// </summary>
Dashed,
/// <summary>
/// 点线
/// </summary>
Dotted
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_Color0;
@@ -38,7 +17,6 @@ namespace XCharts.Runtime
[SerializeField] private float m_BackgroundWidth;
[SerializeField] private Color32 m_CenterColor;
[SerializeField] private float m_CenterGap;
[SerializeField] private Type m_BorderType = Type.Solid;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color32 m_BorderColor;
[SerializeField] private Color32 m_BorderColor0;
@@ -60,7 +38,6 @@ namespace XCharts.Runtime
m_BackgroundWidth = 0;
m_CenterColor = Color.clear;
m_CenterGap = 0;
m_BorderType = Type.Solid;
m_BorderWidth = 0;
m_BorderColor = Color.clear;
m_BorderColor0 = Color.clear;
@@ -155,14 +132,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的类型。
/// </summary>
public Type borderType
{
get { return m_BorderType; }
set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
/// </summary>
public Color32 borderColor
@@ -261,6 +230,7 @@ namespace XCharts.Runtime
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0()
{
if (m_Opacity == 1 || m_Color0.a == 0)
@@ -270,6 +240,7 @@ namespace XCharts.Runtime
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
@@ -280,6 +251,7 @@ namespace XCharts.Runtime
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_Color0) ? defaultColor : m_Color0;
@@ -290,6 +262,7 @@ namespace XCharts.Runtime
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetBorderColor(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_BorderColor) ? defaultColor : m_BorderColor;
@@ -300,6 +273,7 @@ namespace XCharts.Runtime
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetBorderColor0(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_BorderColor0) ? defaultColor : m_BorderColor0;

View File

@@ -83,7 +83,7 @@ namespace XCharts.Runtime
[SerializeField] private bool m_AutoOffset = false;
[SerializeField] private bool m_AutoColor = false;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
private DelegateSerieLabelFormatter m_FormatterFunction;
private SerieLabelFormatterFunction m_FormatterFunction;
public void Reset()
{
@@ -230,7 +230,7 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
}
public DelegateSerieLabelFormatter formatterFunction
public SerieLabelFormatterFunction formatterFunction
{
get { return m_FormatterFunction; }
set { m_FormatterFunction = value; }

View File

@@ -0,0 +1,33 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
[System.Serializable]
public class Level : ChildComponent
{
[SerializeField] private LabelStyle m_Label = new LabelStyle();
[SerializeField] private LabelStyle m_UpperLabel = new LabelStyle();
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
public LabelStyle label { get { return m_Label; } }
public LabelStyle upperLabel { get { return m_UpperLabel; } }
public ItemStyle itemStyle { get { return m_ItemStyle; } }
}
[System.Serializable]
public class LevelStyle : ChildComponent
{
[SerializeField] private bool m_Show = false;
[SerializeField] private List<Level> m_Levels = new List<Level>() { new Level() };
/// <summary>
/// 是否启用LevelStyle
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 各层节点对应的配置。当enableLevels为true时生效levels[0]对应的第一层的配置levels[1]对应第二层依次类推。当levels中没有对应层时用默认的设置。
/// </summary>
public List<Level> levels { get { return m_Levels; } }
}
}

View File

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

View File

@@ -78,19 +78,12 @@ namespace XCharts.Runtime
/// </summary>
FromData,
/// <summary>
/// Specify callback function for symbol size.
/// 通过回调函数获取。
/// Specify function for symbol size.
/// 通过委托函数获取。
/// </summary>
Callback,
Function,
}
/// <summary>
/// 获取标记大小的回调。
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public delegate float SymbolSizeCallback(List<double> data);
/// <summary>
/// 系列数据项的标记的图形
/// </summary>
@@ -105,8 +98,8 @@ namespace XCharts.Runtime
[SerializeField] private int m_DataIndex = 1;
[SerializeField] private float m_DataScale = 1;
[SerializeField] private float m_SelectedDataScale = 1.5f;
[SerializeField] private SymbolSizeCallback m_SizeCallback;
[SerializeField] private SymbolSizeCallback m_SelectedSizeCallback;
[SerializeField] private SymbolSizeFunction m_SizeFunction;
[SerializeField] private SymbolSizeFunction m_SelectedSizeFunction;
[SerializeField] private int m_StartIndex;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
@@ -128,8 +121,8 @@ namespace XCharts.Runtime
m_DataIndex = 1;
m_DataScale = 1;
m_SelectedDataScale = 1.5f;
m_SizeCallback = null;
m_SelectedSizeCallback = null;
m_SizeFunction = null;
m_SelectedSizeFunction = null;
m_StartIndex = 0;
m_Interval = 0;
m_ForceShowLast = false;
@@ -215,22 +208,22 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时,指定的回调函数。
/// the function of size when sizeType assined as Function.
/// 当sizeType指定为Function时,指定的委托函数。
/// </summary>
public SymbolSizeCallback sizeCallback
public SymbolSizeFunction sizeFunction
{
get { return m_SizeCallback; }
set { if (PropertyUtil.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); }
get { return m_SizeFunction; }
set { if (PropertyUtil.SetClass(ref m_SizeFunction, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时,指定的高亮回调函数。
/// the function of size when sizeType assined as Function.
/// 当sizeType指定为Function时,指定的高亮委托函数。
/// </summary>
public SymbolSizeCallback selectedSizeCallback
public SymbolSizeFunction selectedSizeFunction
{
get { return m_SelectedSizeCallback; }
set { if (PropertyUtil.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
get { return m_SelectedSizeFunction; }
set { if (PropertyUtil.SetClass(ref m_SelectedSizeFunction, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
@@ -341,8 +334,8 @@ namespace XCharts.Runtime
{
return size == 0 ? themeSize : size;
}
case SymbolSizeType.Callback:
if (data != null && sizeCallback != null) return sizeCallback(data);
case SymbolSizeType.Function:
if (data != null && sizeFunction != null) return sizeFunction(data);
else return size == 0 ? themeSize : size;
default: return size == 0 ? themeSize : size;
}
@@ -372,10 +365,10 @@ namespace XCharts.Runtime
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
case SymbolSizeType.Callback:
case SymbolSizeType.Function:
if (data != null && selectedSizeCallback != null)
return selectedSizeCallback(data);
if (data != null && selectedSizeFunction != null)
return selectedSizeFunction(data);
else
return selectedSize == 0 ? themeSelectedSize : selectedSize;