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

@@ -5,9 +5,6 @@ using System;
namespace XCharts.Runtime
{
public delegate float CustomAnimationDelay(int dataIndex);
public delegate float CustomAnimationDuration(int dataIndex);
public enum AnimationType
{
/// <summary>
@@ -69,19 +66,19 @@ namespace XCharts.Runtime
/// <summary>
/// 自定义渐入动画延时函数。返回ms值。
/// </summary>
public CustomAnimationDelay customFadeInDelay;
public AnimationDelayFunction fadeInDelayFunction;
/// <summary>
/// 自定义渐入动画时长函数。返回ms值。
/// </summary>
public CustomAnimationDuration customFadeInDuration;
public AnimationDurationFunction fadeInDurationFunction;
/// <summary>
/// 自定义渐出动画延时函数。返回ms值。
/// </summary>
public CustomAnimationDelay customFadeOutDelay;
public AnimationDelayFunction fadeOutDelayFunction;
/// <summary>
/// 自定义渐出动画时长函数。返回ms值。
/// </summary>
public CustomAnimationDuration customFadeOutDuration;
public AnimationDurationFunction fadeOutDurationFunction;
public AnimationStyleContext context = new AnimationStyleContext();
/// <summary>
@@ -390,10 +387,10 @@ namespace XCharts.Runtime
public float GetIndexDelay(int dataIndex)
{
if (m_FadeOut && customFadeOutDelay != null)
return customFadeOutDelay(dataIndex);
else if (m_FadeIn && customFadeInDelay != null)
return customFadeInDelay(dataIndex);
if (m_FadeOut && fadeOutDelayFunction != null)
return fadeOutDelayFunction(dataIndex);
else if (m_FadeIn && fadeInDelayFunction != null)
return fadeInDelayFunction(dataIndex);
else
return 0;
}
@@ -492,10 +489,10 @@ namespace XCharts.Runtime
{
if (dataIndex >= 0)
{
if (m_FadeOut && customFadeOutDuration != null)
return customFadeOutDuration(dataIndex) / 1000f;
if (m_FadeIn && customFadeInDuration != null)
return customFadeInDuration(dataIndex) / 1000f;
if (m_FadeOut && fadeOutDurationFunction != null)
return fadeOutDurationFunction(dataIndex) / 1000f;
if (m_FadeIn && fadeInDurationFunction != null)
return fadeInDurationFunction(dataIndex) / 1000f;
}
if (m_FadeOut)

View File

@@ -57,8 +57,8 @@ namespace XCharts
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
if (j != lastPointerValue)
{
if (chart.onUpdateAxisPointer != null)
chart.onUpdateAxisPointer(axis, j);
if (chart.onAxisPointerValueChanged != null)
chart.onAxisPointerValueChanged(axis, j);
}
break;
}
@@ -74,8 +74,8 @@ namespace XCharts
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
if (j != lastPointerValue)
{
if (chart.onUpdateAxisPointer != null)
chart.onUpdateAxisPointer(axis, j);
if (chart.onAxisPointerValueChanged != null)
chart.onAxisPointerValueChanged(axis, j);
}
break;
}
@@ -97,8 +97,8 @@ namespace XCharts
axis.context.pointerLabelPosition = new Vector3(labelX, chart.pointerPos.y);
if (yValue != lastPointerValue)
{
if (chart.onUpdateAxisPointer != null)
chart.onUpdateAxisPointer(axis, yValue);
if (chart.onAxisPointerValueChanged != null)
chart.onAxisPointerValueChanged(axis, yValue);
}
}
else
@@ -114,8 +114,8 @@ namespace XCharts
axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY);
if (xValue != lastPointerValue)
{
if (chart.onUpdateAxisPointer != null)
chart.onUpdateAxisPointer(axis, xValue);
if (chart.onAxisPointerValueChanged != null)
chart.onAxisPointerValueChanged(axis, xValue);
}
}
}
@@ -750,7 +750,7 @@ namespace XCharts
}
internal static void DrawAxisSplit(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
Orient orient, float startX, float startY, float axisLength, float splitLength)
Orient orient, float startX, float startY, float axisLength, float splitLength, Axis relativedAxis = null)
{
var lineColor = axis.splitLine.GetColor(theme.splitLineColor);
var lineWidth = axis.splitLine.GetWidth(theme.lineWidth);
@@ -803,6 +803,7 @@ namespace XCharts
{
if (orient == Orient.Horizonal)
{
if (relativedAxis == null || MathUtil.Approximately(current, relativedAxis.context.x))
ChartDrawer.DrawLineStyle(vh,
lineType,
lineWidth,
@@ -812,12 +813,13 @@ namespace XCharts
}
else
{
ChartDrawer.DrawLineStyle(vh,
lineType,
lineWidth,
new Vector3(startX, current),
new Vector3(startX + splitLength, current),
lineColor);
if (relativedAxis == null || MathUtil.Approximately(current, relativedAxis.context.y))
ChartDrawer.DrawLineStyle(vh,
lineType,
lineWidth,
new Vector3(startX, current),
new Vector3(startX + splitLength, current),
lineColor);
}
}

View File

@@ -81,6 +81,8 @@ namespace XCharts.Runtime
{
if (dataCount < 1)
dataCount = 1;
if (axis.IsValue())
return dataCount > 1 ? coordinateWidth / (dataCount - 1) : coordinateWidth;
var categoryCount = axis.GetDataCount(dataZoom);
int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1);
segment = segment <= 0 ? dataCount : segment;

View File

@@ -26,7 +26,7 @@ namespace XCharts.Runtime
[SerializeField] private bool m_ShowEndLabel = true;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
private DelegateAxisLabelFormatter m_FormatterFunction;
private AxisLabelFormatterFunction m_FormatterFunction;
/// <summary>
/// Set this to false to prevent the axis label from appearing.
@@ -158,7 +158,7 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
public DelegateAxisLabelFormatter formatterFunction
public AxisLabelFormatterFunction formatterFunction
{
set { m_FormatterFunction = value; }
}

View File

@@ -92,6 +92,7 @@ namespace XCharts.Runtime
if (grid == null)
return;
var relativedAxis = chart.GetChartComponent<YAxis>(xAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
@@ -99,7 +100,8 @@ namespace XCharts.Runtime
grid.context.x,
grid.context.y,
grid.context.width,
grid.context.height);
grid.context.height,
relativedAxis);
}
}

View File

@@ -89,14 +89,15 @@ namespace XCharts.Runtime
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
if (grid == null)
return;
var relativedAxis = chart.GetChartComponent<XAxis>(yAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
Orient.Vertical,
grid.context.x,
grid.context.y,
grid.context.height,
grid.context.width);
grid.context.width,
relativedAxis);
}
}

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;

View File

@@ -10,7 +10,7 @@ namespace XCharts.Runtime
public class DebugInfo
{
[SerializeField] private bool m_ShowDebugInfo = false;
[SerializeField] protected bool m_ShowAllChildObject = false;
[SerializeField] protected bool m_ShowAllChartObject = false;
[SerializeField] protected bool m_FoldSeries = false;
[SerializeField]
private TextStyle m_DebugInfoTextStyle = new TextStyle()
@@ -32,7 +32,7 @@ namespace XCharts.Runtime
private ChartLabel m_Label;
private List<float> m_FpsList = new List<float>();
public bool showAllChildObject { get { return m_ShowAllChildObject; } }
public bool showAllChartObject { get { return m_ShowAllChartObject; } }
public bool foldSeries { get { return m_FoldSeries; } set { m_FoldSeries = value; } }
public float fps { get; private set; }
public float avgFps { get; private set; }

View File

@@ -1,6 +1,5 @@
using System;
using System.Text;
using UnityEngine;
namespace XCharts.Runtime