mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
增加代码API注释文档,整理代码
This commit is contained in:
@@ -1,508 +0,0 @@
|
||||
using System.Net.Mime;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Axis : JsonDataSupport, IEquatable<Axis>
|
||||
{
|
||||
public enum AxisType
|
||||
{
|
||||
Value,
|
||||
Category,
|
||||
//Time,
|
||||
//Log
|
||||
}
|
||||
|
||||
public enum AxisMinMaxType
|
||||
{
|
||||
Default,
|
||||
MinMax,
|
||||
Custom
|
||||
}
|
||||
|
||||
public enum SplitLineType
|
||||
{
|
||||
None,
|
||||
Solid,
|
||||
Dashed,
|
||||
Dotted
|
||||
}
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
[SerializeField] protected AxisType m_Type;
|
||||
[SerializeField] protected AxisMinMaxType m_MinMaxType;
|
||||
[SerializeField] protected int m_Min;
|
||||
[SerializeField] protected int m_Max;
|
||||
[SerializeField] protected int m_SplitNumber = 5;
|
||||
[SerializeField] protected bool m_ShowSplitLine = false;
|
||||
[SerializeField] protected SplitLineType m_SplitLineType = SplitLineType.Dashed;
|
||||
[SerializeField] protected bool m_BoundaryGap = true;
|
||||
[SerializeField] protected List<string> m_Data = new List<string>();
|
||||
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
|
||||
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
|
||||
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
|
||||
[SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel;
|
||||
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public AxisType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public AxisMinMaxType minMaxType { get { return m_MinMaxType; } set { m_MinMaxType = value; } }
|
||||
public int min { get { return m_Min; } set { m_Min = value; } }
|
||||
public int max { get { return m_Max; } set { m_Max = value; } }
|
||||
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
public bool showSplitLine { get { return m_ShowSplitLine; } set { m_ShowSplitLine = value; } }
|
||||
public SplitLineType splitLineType { get { return m_SplitLineType; } set { m_SplitLineType = value; } }
|
||||
public bool boundaryGap { get { return m_BoundaryGap; } set { m_BoundaryGap = value; } }
|
||||
public List<string> data { get { return m_Data; } }
|
||||
|
||||
public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
|
||||
public AxisName axisName { get { return m_AxisName; } set { m_AxisName = value; } }
|
||||
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
|
||||
public AxisLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
|
||||
public AxisSplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
|
||||
|
||||
public int filterStart { get; set; }
|
||||
public int filterEnd { get; set; }
|
||||
public List<string> filterData { get; set; }
|
||||
|
||||
public float minValue { get; set; }
|
||||
public float maxValue { get; set; }
|
||||
public float zeroXOffset { get; set; }
|
||||
public float zeroYOffset { get; set; }
|
||||
private List<Text> m_AxisLabelTextList = new List<Text>();
|
||||
public List<Text> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } }
|
||||
|
||||
private GameObject m_TooltipLabel;
|
||||
private Text m_TooltipLabelText;
|
||||
private RectTransform m_TooltipLabelRect;
|
||||
|
||||
public void Copy(Axis other)
|
||||
{
|
||||
m_Show = other.show;
|
||||
m_Type = other.type;
|
||||
m_Min = other.min;
|
||||
m_Max = other.max;
|
||||
m_SplitNumber = other.splitNumber;
|
||||
|
||||
m_ShowSplitLine = other.showSplitLine;
|
||||
m_SplitLineType = other.splitLineType;
|
||||
m_BoundaryGap = other.boundaryGap;
|
||||
m_AxisName.Copy(other.axisName);
|
||||
m_AxisLabel.Copy(other.axisLabel);
|
||||
m_Data.Clear();
|
||||
foreach (var d in other.data) m_Data.Add(d);
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
}
|
||||
|
||||
public bool IsCategory()
|
||||
{
|
||||
return type == AxisType.Category;
|
||||
}
|
||||
|
||||
public bool IsValue()
|
||||
{
|
||||
return type == AxisType.Value;
|
||||
}
|
||||
|
||||
public void AddData(string category, int maxDataNumber)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
}
|
||||
m_Data.Add(category);
|
||||
}
|
||||
|
||||
public string GetData(int index, DataZoom dataZoom)
|
||||
{
|
||||
var showData = GetDataList(dataZoom);
|
||||
if (index >= 0 && index < showData.Count)
|
||||
return showData[index];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<string> GetDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (filterData == null || filterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return filterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFilterData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (startIndex != filterStart || endIndex != filterEnd)
|
||||
{
|
||||
filterStart = startIndex;
|
||||
filterEnd = endIndex;
|
||||
if (m_Data.Count > 0)
|
||||
{
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
filterData = m_Data.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
filterData = m_Data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
filterData = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetSplitNumber(DataZoom dataZoom)
|
||||
{
|
||||
if (type == AxisType.Value) return m_SplitNumber;
|
||||
int dataCount = GetDataList(dataZoom).Count;
|
||||
if (dataCount > 2 * m_SplitNumber || dataCount <= 0)
|
||||
return m_SplitNumber;
|
||||
else
|
||||
return dataCount;
|
||||
}
|
||||
|
||||
public float GetSplitWidth(float coordinateWidth, DataZoom dataZoom)
|
||||
{
|
||||
return coordinateWidth / (m_BoundaryGap ? GetSplitNumber(dataZoom) : GetSplitNumber(dataZoom) - 1);
|
||||
}
|
||||
|
||||
public int GetDataNumber(DataZoom dataZoom)
|
||||
{
|
||||
return GetDataList(dataZoom).Count;
|
||||
}
|
||||
|
||||
public float GetDataWidth(float coordinateWidth, DataZoom dataZoom)
|
||||
{
|
||||
var dataCount = GetDataNumber(dataZoom);
|
||||
return coordinateWidth / (m_BoundaryGap ? dataCount : dataCount - 1);
|
||||
}
|
||||
|
||||
private Dictionary<float, string> _cacheValue2str = new Dictionary<float, string>();
|
||||
public string GetLabelName(int index, float minValue, float maxValue, DataZoom dataZoom)
|
||||
{
|
||||
if (m_Type == AxisType.Value)
|
||||
{
|
||||
float value = (minValue + (maxValue - minValue) * index / (GetSplitNumber(dataZoom) - 1));
|
||||
if (_cacheValue2str.ContainsKey(value)) return _cacheValue2str[value];
|
||||
else
|
||||
{
|
||||
if (value - (int)value == 0)
|
||||
_cacheValue2str[value] = (value).ToString();
|
||||
else
|
||||
_cacheValue2str[value] = (value).ToString("f1");
|
||||
return _cacheValue2str[value];
|
||||
}
|
||||
}
|
||||
var showData = GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
|
||||
if (index == GetSplitNumber(dataZoom) - 1 && !m_BoundaryGap)
|
||||
{
|
||||
return showData[dataCount - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
float rate = dataCount / GetSplitNumber(dataZoom);
|
||||
if (rate < 1) rate = 1;
|
||||
int offset = m_BoundaryGap ? (int)(rate / 2) : 0;
|
||||
int newIndex = (int)(index * rate >= dataCount - 1 ?
|
||||
dataCount - 1 : offset + index * rate);
|
||||
return showData[newIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public int GetScaleNumber(DataZoom dataZoom)
|
||||
{
|
||||
if (type == AxisType.Value)
|
||||
{
|
||||
return m_BoundaryGap ? m_SplitNumber + 1 : m_SplitNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (dataCount > 2 * splitNumber || dataCount <= 0)
|
||||
return m_BoundaryGap ? m_SplitNumber + 1 : m_SplitNumber;
|
||||
else
|
||||
return m_BoundaryGap ? dataCount + 1 : dataCount;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetScaleWidth(float coordinateWidth, DataZoom dataZoom)
|
||||
{
|
||||
int num = GetScaleNumber(dataZoom) - 1;
|
||||
if (num <= 0) num = 1;
|
||||
return coordinateWidth / num;
|
||||
}
|
||||
|
||||
public void UpdateLabelText(DataZoom dataZoom)
|
||||
{
|
||||
for (int i = 0; i < axisLabelTextList.Count; i++)
|
||||
{
|
||||
if (axisLabelTextList[i] != null)
|
||||
{
|
||||
axisLabelTextList[i].text = GetLabelName(i, minValue, maxValue, dataZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTooltipLabel(GameObject label)
|
||||
{
|
||||
m_TooltipLabel = label;
|
||||
m_TooltipLabelRect = label.GetComponent<RectTransform>();
|
||||
m_TooltipLabelText = label.GetComponentInChildren<Text>();
|
||||
m_TooltipLabel.SetActive(true);
|
||||
}
|
||||
|
||||
public void SetTooltipLabelColor(Color bgColor, Color textColor)
|
||||
{
|
||||
m_TooltipLabel.GetComponent<Image>().color = bgColor;
|
||||
m_TooltipLabelText.color = textColor;
|
||||
}
|
||||
|
||||
public void SetTooltipLabelActive(bool flag)
|
||||
{
|
||||
if (m_TooltipLabel && m_TooltipLabel.activeInHierarchy != flag)
|
||||
{
|
||||
m_TooltipLabel.SetActive(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTooptipLabelText(string text)
|
||||
{
|
||||
if (m_TooltipLabelText)
|
||||
{
|
||||
m_TooltipLabelText.text = text;
|
||||
m_TooltipLabelRect.sizeDelta = new Vector2(m_TooltipLabelText.preferredWidth + 8,
|
||||
m_TooltipLabelText.preferredHeight + 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTooltipLabelPos(Vector2 pos)
|
||||
{
|
||||
if (m_TooltipLabel)
|
||||
{
|
||||
m_TooltipLabel.transform.localPosition = pos;
|
||||
}
|
||||
}
|
||||
|
||||
public void AdjustMinMaxValue(ref int minValue, ref int maxValue)
|
||||
{
|
||||
if (minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
{
|
||||
if (min != 0 || max != 0)
|
||||
{
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (minMaxType)
|
||||
{
|
||||
case Axis.AxisMinMaxType.Default:
|
||||
if (minValue > 0 && maxValue > 0)
|
||||
{
|
||||
minValue = 0;
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
}
|
||||
else if (minValue < 0 && maxValue < 0)
|
||||
{
|
||||
minValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
}
|
||||
break;
|
||||
case Axis.AxisMinMaxType.MinMax:
|
||||
minValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is Axis)
|
||||
{
|
||||
return Equals((Axis)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Axis other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return show == other.show &&
|
||||
type == other.type &&
|
||||
min == other.min &&
|
||||
max == other.max &&
|
||||
splitNumber == other.splitNumber &&
|
||||
showSplitLine == other.showSplitLine &&
|
||||
m_AxisLabel.Equals(other.axisLabel) &&
|
||||
splitLineType == other.splitLineType &&
|
||||
boundaryGap == other.boundaryGap &&
|
||||
axisName.Equals(other.axisName) &&
|
||||
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
|
||||
}
|
||||
|
||||
public static bool operator ==(Axis left, Axis right)
|
||||
{
|
||||
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Axis left, Axis right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
m_Data = ChartHelper.ParseStringFromString(jsonData);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class XAxis : Axis
|
||||
{
|
||||
|
||||
public XAxis Clone()
|
||||
{
|
||||
var axis = new XAxis();
|
||||
axis.show = show;
|
||||
axis.type = type;
|
||||
axis.min = min;
|
||||
axis.max = max;
|
||||
axis.splitNumber = splitNumber;
|
||||
|
||||
axis.showSplitLine = showSplitLine;
|
||||
axis.splitLineType = splitLineType;
|
||||
axis.boundaryGap = boundaryGap;
|
||||
axis.axisName.Copy(axisName);
|
||||
axis.axisLabel.Copy(axisLabel);
|
||||
axis.data.Clear();
|
||||
foreach (var d in data) axis.data.Add(d);
|
||||
return axis;
|
||||
}
|
||||
|
||||
public static XAxis defaultXAxis
|
||||
{
|
||||
get
|
||||
{
|
||||
var axis = new XAxis
|
||||
{
|
||||
m_Show = true,
|
||||
m_Type = AxisType.Category,
|
||||
m_Min = 0,
|
||||
m_Max = 0,
|
||||
m_SplitNumber = 5,
|
||||
m_ShowSplitLine = false,
|
||||
m_SplitLineType = SplitLineType.Dashed,
|
||||
m_BoundaryGap = true,
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"x1","x2","x3","x4","x5"
|
||||
}
|
||||
};
|
||||
return axis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class YAxis : Axis
|
||||
{
|
||||
public YAxis Clone()
|
||||
{
|
||||
var axis = new YAxis();
|
||||
axis.show = show;
|
||||
axis.type = type;
|
||||
axis.min = min;
|
||||
axis.max = max;
|
||||
axis.splitNumber = splitNumber;
|
||||
|
||||
axis.showSplitLine = showSplitLine;
|
||||
axis.splitLineType = splitLineType;
|
||||
axis.boundaryGap = boundaryGap;
|
||||
axis.axisName.Copy(axisName);
|
||||
axis.axisLabel.Copy(axisLabel);
|
||||
axis.data.Clear();
|
||||
foreach (var d in data) axis.data.Add(d);
|
||||
return axis;
|
||||
}
|
||||
|
||||
public static YAxis defaultYAxis
|
||||
{
|
||||
get
|
||||
{
|
||||
var axis = new YAxis
|
||||
{
|
||||
m_Show = true,
|
||||
m_Type = AxisType.Value,
|
||||
m_Min = 0,
|
||||
m_Max = 0,
|
||||
m_SplitNumber = 5,
|
||||
m_ShowSplitLine = false,
|
||||
m_SplitLineType = SplitLineType.Dashed,
|
||||
m_BoundaryGap = false,
|
||||
m_Data = new List<string>(5),
|
||||
};
|
||||
return axis;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84f640465300fb34facae554552063b9
|
||||
timeCreated: 1554422468
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,25 +3,61 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings related to axis label.
|
||||
/// 坐标轴刻度标签的相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AxisLabel
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private int m_Interval;
|
||||
[SerializeField] private bool m_Inside;
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private int m_Interval = 0;
|
||||
[SerializeField] private bool m_Inside = false;
|
||||
[SerializeField] private float m_Rotate;
|
||||
[SerializeField] private float m_Margin;
|
||||
[SerializeField] private Color m_Color;
|
||||
[SerializeField] private int m_FontSize;
|
||||
[SerializeField] private FontStyle m_FontStyle;
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent the axis label from appearing.
|
||||
/// 是否显示刻度标签。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// The display interval of the axis label.
|
||||
/// 坐标轴刻度标签的显示间隔,在类目轴中有效。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。
|
||||
/// </summary>
|
||||
public int interval { get { return m_Interval; } set { m_Interval = value; } }
|
||||
/// <summary>
|
||||
/// Set this to true so the axis labels face the inside direction.
|
||||
/// 刻度标签是否朝内,默认朝外。
|
||||
/// </summary>
|
||||
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
|
||||
/// <summary>
|
||||
/// Rotation degree of axis label, which is especially useful when there is no enough space for category axis.
|
||||
/// 刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。
|
||||
/// </summary>
|
||||
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||
/// <summary>
|
||||
/// The margin between the axis label and the axis line.
|
||||
/// 刻度标签与轴线之间的距离。
|
||||
/// </summary>
|
||||
public float margin { get { return m_Margin; } set { m_Margin = value; } }
|
||||
/// <summary>
|
||||
/// the color of axis label text.
|
||||
/// 刻度标签文字的颜色,默认取Theme的axisTextColor。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// font size.
|
||||
/// 文字的字体大小。
|
||||
/// </summary>
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
/// <summary>
|
||||
/// font style.
|
||||
/// 文字字体的风格。
|
||||
/// </summary>
|
||||
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||
|
||||
public static AxisLabel defaultAxisLabel
|
||||
|
||||
@@ -2,23 +2,61 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
/// <summary>
|
||||
/// Settings related to axis line.
|
||||
/// 坐标轴的分隔线。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class AxisLine
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private bool m_OnZero;
|
||||
[SerializeField] private float m_Width = 0.6f;
|
||||
[SerializeField] private bool m_Symbol;
|
||||
[SerializeField] private float m_SymbolWidth;
|
||||
[SerializeField] private float m_SymbolHeight;
|
||||
[SerializeField] private float m_SymbolOffset;
|
||||
[SerializeField] private float m_SymbolDent;
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent the axis line from showing.
|
||||
/// 是否显示坐标轴轴线。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// When mutiple axes exists, this option can be used to specify which axis can be "onZero" to.
|
||||
/// X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效。
|
||||
/// </summary>
|
||||
public bool onZero { get { return m_OnZero; } set { m_OnZero = value; } }
|
||||
/// <summary>
|
||||
/// line style line width.
|
||||
/// 坐标轴线线宽。
|
||||
/// </summary>
|
||||
public float width { get { return m_Width; } set { m_Width = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show the arrow symbol of axis.
|
||||
/// 是否显示箭头。
|
||||
/// </summary>
|
||||
public bool symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
||||
/// <summary>
|
||||
/// the width of arrow symbol.
|
||||
/// 箭头宽。
|
||||
/// </summary>
|
||||
public float symbolWidth { get { return m_SymbolWidth; } set { m_SymbolWidth = value; } }
|
||||
/// <summary>
|
||||
/// the height of arrow symbol.
|
||||
/// 箭头高。
|
||||
/// </summary>
|
||||
public float symbolHeight { get { return m_SymbolHeight; } set { m_SymbolHeight = value; } }
|
||||
/// <summary>
|
||||
/// the offset of arrow symbol.
|
||||
/// 箭头偏移。
|
||||
/// </summary>
|
||||
public float symbolOffset { get { return m_SymbolOffset; } set { m_SymbolOffset = value; } }
|
||||
/// <summary>
|
||||
/// the dent of arrow symbol.
|
||||
/// 箭头的凹陷程度。
|
||||
/// </summary>
|
||||
public float symbolDent { get { return m_SymbolDent; } set { m_SymbolDent = value; } }
|
||||
|
||||
public static AxisLine defaultAxisLine
|
||||
@@ -29,6 +67,7 @@ namespace XCharts
|
||||
{
|
||||
m_Show = true,
|
||||
m_OnZero = true,
|
||||
m_Width = 0.7f,
|
||||
m_Symbol = false,
|
||||
m_SymbolWidth = 10,
|
||||
m_SymbolHeight = 15,
|
||||
|
||||
@@ -3,10 +3,17 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the name of axis.
|
||||
/// 坐标轴名称。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AxisName
|
||||
{
|
||||
[Serializable]
|
||||
/// <summary>
|
||||
/// the location of axis name.
|
||||
/// 坐标轴名称显示位置。
|
||||
/// </summary>
|
||||
public enum Location
|
||||
{
|
||||
Start,
|
||||
@@ -22,13 +29,45 @@ namespace XCharts
|
||||
[SerializeField] private int m_FontSize;
|
||||
[SerializeField] private FontStyle m_FontStyle;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show axis name.
|
||||
/// 是否显示坐标名称。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// the name of axis.
|
||||
/// 坐标轴名称。
|
||||
/// </summary>
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
/// <summary>
|
||||
/// Location of axis name.
|
||||
/// 坐标轴名称显示位置。
|
||||
/// </summary>
|
||||
public Location location { get { return m_Location; } set { m_Location = value; } }
|
||||
/// <summary>
|
||||
/// Gap between axis name and axis line.
|
||||
/// 坐标轴名称与轴线之间的距离。
|
||||
/// </summary>
|
||||
public float gap { get { return m_Gap; } set { m_Gap = value; } }
|
||||
/// <summary>
|
||||
/// Rotation of axis name.
|
||||
/// 坐标轴名字旋转,角度值。
|
||||
/// </summary>
|
||||
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||
/// <summary>
|
||||
/// Color of axis name.
|
||||
/// 坐标轴名称的文字颜色。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// axis name font size.
|
||||
/// 坐标轴名称的文字大小。
|
||||
/// </summary>
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
/// <summary>
|
||||
/// axis name font style.
|
||||
/// 坐标轴名称的文字风格。
|
||||
/// </summary>
|
||||
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||
|
||||
public static AxisName defaultAxisName
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Split area of axis in grid area, not shown by default.
|
||||
/// 坐标轴在 grid 区域中的分隔区域,默认不显示。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AxisSplitArea
|
||||
@@ -15,15 +16,15 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Set this to true to show the splitArea.
|
||||
/// 是否显示分隔区域。
|
||||
/// </summary>
|
||||
/// <value>false</value>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// Color of split area. SplitArea color could also be set in color array,
|
||||
/// which the split lines would take as their colors in turns.
|
||||
/// Dark and light colors in turns are used by default.
|
||||
/// 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
|
||||
/// </summary>
|
||||
/// <value>['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']</value>
|
||||
public List<Color> color { get { return m_Color; } set { m_Color = value; } }
|
||||
|
||||
public static AxisSplitArea defaultSplitArea
|
||||
|
||||
@@ -3,6 +3,10 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings related to axis tick.
|
||||
/// 坐标轴刻度相关设置。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class AxisTick
|
||||
{
|
||||
@@ -11,9 +15,25 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Inside;
|
||||
[SerializeField] private float m_Length;
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent the axis tick from showing.
|
||||
/// 是否显示坐标轴刻度。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis.
|
||||
/// 类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。
|
||||
/// </summary>
|
||||
public bool alignWithLabel { get { return m_AlignWithLabel; } set { m_AlignWithLabel = value; } }
|
||||
/// <summary>
|
||||
/// Set this to true so the axis labels face the inside direction.
|
||||
/// 坐标轴刻度是否朝内,默认朝外。
|
||||
/// </summary>
|
||||
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
|
||||
/// <summary>
|
||||
/// The length of the axis tick.
|
||||
/// 坐标轴刻度的长度。
|
||||
/// </summary>
|
||||
public float length { get { return m_Length; } set { m_Length = value; } }
|
||||
|
||||
public static AxisTick defaultTick
|
||||
|
||||
@@ -6,9 +6,19 @@ using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the layout is horizontal or vertical.
|
||||
/// 垂直还是水平布局方式。
|
||||
/// </summary>
|
||||
public enum Orient
|
||||
{
|
||||
/// <summary>
|
||||
/// 水平
|
||||
/// </summary>
|
||||
Horizonal,
|
||||
/// <summary>
|
||||
/// 垂直
|
||||
/// </summary>
|
||||
Vertical
|
||||
}
|
||||
|
||||
@@ -167,22 +177,22 @@ namespace XCharts
|
||||
ChartHelper.HideAllObject(titleObject, s_TitleObjectName);
|
||||
|
||||
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.textColor, anchor, anchorMin, anchorMax, pivot,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.textFontSize), m_Title.textFontSize);
|
||||
|
||||
titleText.alignment = anchor;
|
||||
titleText.gameObject.SetActive(m_Title.show);
|
||||
titleText.transform.localPosition = Vector2.zero;
|
||||
titleText.text = m_Title.text;
|
||||
titleText.text = m_Title.text.Replace("\\n", "\n");
|
||||
|
||||
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.textColor, anchor, anchorMin, anchorMax, pivot,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.subTextFontSize), m_Title.subTextFontSize);
|
||||
|
||||
subText.alignment = anchor;
|
||||
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
|
||||
subText.transform.localPosition = subTitlePosition;
|
||||
subText.text = m_Title.subText;
|
||||
subText.text = m_Title.subText.Replace("\\n", "\n");
|
||||
}
|
||||
|
||||
private void InitLegend()
|
||||
@@ -221,7 +231,7 @@ namespace XCharts
|
||||
Button btn = ChartHelper.AddButtonObject(s_LegendObjectName + "_" + i + "_" + legendName, legendObject.transform,
|
||||
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
|
||||
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
|
||||
var bgColor = IsLegendActive(legendName) ? m_ThemeInfo.GetColor(i) : m_ThemeInfo.legendUnableColor;
|
||||
var bgColor = IsActiveByLegend(legendName) ? m_ThemeInfo.GetColor(i) : m_ThemeInfo.legendUnableColor;
|
||||
m_Legend.SetButton(legendName, btn, datas.Count);
|
||||
m_Legend.UpdateButtonColor(legendName, bgColor);
|
||||
btn.GetComponentInChildren<Text>().text = legendName;
|
||||
@@ -366,7 +376,7 @@ namespace XCharts
|
||||
|
||||
private void CheckTooltip()
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.isInited)
|
||||
if (!m_Tooltip.show || !m_Tooltip.inited)
|
||||
{
|
||||
|
||||
if (m_Tooltip.dataIndex[0] != 0 || m_Tooltip.dataIndex[1] != 0)
|
||||
|
||||
@@ -3,18 +3,47 @@ using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// The base class of all charts.
|
||||
/// 所有Chart的基类,不可直接使用。
|
||||
/// </summary>
|
||||
public partial class BaseChart
|
||||
{
|
||||
/// <summary>
|
||||
/// The title setting of chart.
|
||||
/// 标题组件
|
||||
/// </summary>
|
||||
public Title title { get { return m_Title; } }
|
||||
/// <summary>
|
||||
/// The legend setting of chart.
|
||||
/// 图例组件
|
||||
/// </summary>
|
||||
public Legend legend { get { return m_Legend; } }
|
||||
/// <summary>
|
||||
/// The tooltip setting of chart.
|
||||
/// 提示框组件
|
||||
/// </summary>
|
||||
public Tooltip tooltip { get { return m_Tooltip; } }
|
||||
/// <summary>
|
||||
/// The series setting of chart.
|
||||
/// 系列列表
|
||||
/// </summary>
|
||||
public Series series { get { return m_Series; } }
|
||||
|
||||
/// <summary>
|
||||
/// The width of chart.
|
||||
/// 图表的宽
|
||||
/// </summary>
|
||||
public float chartWidth { get { return m_ChartWidth; } }
|
||||
/// <summary>
|
||||
/// The height of chart.
|
||||
/// 图表的高
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float chartHeight { get { return m_ChartHeight; } }
|
||||
|
||||
/// <summary>
|
||||
/// The min number of data to show in chart.
|
||||
/// 图表所显示数据的最小索引
|
||||
/// </summary>
|
||||
public int minShowDataNumber
|
||||
{
|
||||
@@ -24,6 +53,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// The max number of data to show in chart.
|
||||
/// 图表所显示数据的最大索引
|
||||
/// </summary>
|
||||
public int maxShowDataNumber
|
||||
{
|
||||
@@ -35,6 +65,7 @@ namespace XCharts
|
||||
/// The max number of serie and axis data cache.
|
||||
/// The first data will be remove when the size of serie and axis data is larger then maxCacheDataNumber.
|
||||
/// default:0,unlimited.
|
||||
/// 图表每个系列中可缓存的最大数据量。默认为0没有限制,大于0时超过指定值会移除旧数据再插入新数据。
|
||||
/// </summary>
|
||||
public int maxCacheDataNumber
|
||||
{
|
||||
@@ -44,6 +75,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Set the size of chart.
|
||||
/// 设置图表的大小。
|
||||
/// </summary>
|
||||
/// <param name="width">width</param>
|
||||
/// <param name="height">height</param>
|
||||
@@ -60,6 +92,7 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// Remove all series and legend data.
|
||||
/// It just emptying all of serie's data without emptying the list of series.
|
||||
/// 清除所有数据,系列中只是移除数据,列表会保留。
|
||||
/// </summary>
|
||||
public virtual void ClearData()
|
||||
{
|
||||
@@ -68,8 +101,21 @@ namespace XCharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series and legend.
|
||||
/// The series list is also cleared.
|
||||
/// 清除所有系列和图例数据,系列的列表也会被清除。
|
||||
/// </summary>
|
||||
public virtual void RemoveData()
|
||||
{
|
||||
m_Legend.ClearData();
|
||||
m_Series.RemoveAll();
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove legend and serie by name.
|
||||
/// 清除指定系列名称的数据。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
public virtual void RemoveData(string serieName)
|
||||
@@ -79,19 +125,9 @@ namespace XCharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series and legend.
|
||||
/// The series list is also cleared.
|
||||
/// </summary>
|
||||
public virtual void RemoveData()
|
||||
{
|
||||
m_Legend.ClearData();
|
||||
m_Series.RemoveAll();
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a serie to serie list.
|
||||
/// 添加一个系列到系列列表中。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="type">the type of serie</param>
|
||||
@@ -106,6 +142,7 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// If serieName doesn't exist in legend,will be add to legend.
|
||||
/// 添加一个数据到指定的系列中。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="data">the data to add</param>
|
||||
@@ -121,6 +158,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// 添加一个数据到指定的系列中。
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="data">the data to add</param>
|
||||
@@ -135,6 +173,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Add an arbitray dimension data to serie,such as (x,y,z,...).
|
||||
/// 添加多维数据(x,y,z...)到指定的系列中。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
||||
@@ -149,6 +188,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Add an arbitray dimension data to serie,such as (x,y,z,...).
|
||||
/// 添加多维数据(x,y,z...)到指定的系列中。
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie,index starts at 0</param>
|
||||
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
||||
@@ -163,6 +203,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Add a (x,y) data to serie.
|
||||
/// 添加(x,y)数据到指定系列中。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="xValue">x data</param>
|
||||
@@ -178,6 +219,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Add a (x,y) data to serie.
|
||||
/// 添加(x,y)数据到指定系列中。
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="xValue">x data</param>
|
||||
@@ -193,6 +235,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Update serie data by serie name.
|
||||
/// 更新指定系列中的指定索引数据。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="value">the data will be update</param>
|
||||
@@ -205,6 +248,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Update serie data by serie index.
|
||||
/// 更新指定系列中的指定索引数据。
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="value">the data will be update</param>
|
||||
@@ -216,7 +260,8 @@ namespace XCharts
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show serie and legend.
|
||||
/// Whether to show serie.
|
||||
/// 设置指定系列是否显示。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="active">Active or not</param>
|
||||
@@ -230,7 +275,8 @@ namespace XCharts
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show serie and legend.
|
||||
/// Whether to show serie.
|
||||
/// 设置指定系列是否显示。
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="active">Active or not</param>
|
||||
@@ -247,6 +293,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Whether serie is activated.
|
||||
/// 获取指定系列是否显示。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <returns>True when activated</returns>
|
||||
@@ -257,6 +304,7 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Whether serie is activated.
|
||||
/// 获取指定系列是否显示。
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <returns>True when activated</returns>
|
||||
@@ -265,13 +313,20 @@ namespace XCharts
|
||||
return m_Series.IsActive(serieIndex);
|
||||
}
|
||||
|
||||
public virtual bool IsLegendActive(string legendName)
|
||||
/// <summary>
|
||||
/// Whether serie is activated.
|
||||
/// 获得指定图例名字的系列是否显示。
|
||||
/// </summary>
|
||||
/// <param name="legendName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool IsActiveByLegend(string legendName)
|
||||
{
|
||||
return IsActive(legendName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redraw chart next frame.
|
||||
/// Redraw chart in next frame.
|
||||
/// 在下一帧刷新图表。
|
||||
/// </summary>
|
||||
public void RefreshChart()
|
||||
{
|
||||
@@ -279,7 +334,8 @@ namespace XCharts
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update chart theme
|
||||
/// Update chart theme.
|
||||
/// 切换图表主题。
|
||||
/// </summary>
|
||||
/// <param name="theme">theme</param>
|
||||
public void UpdateTheme(Theme theme)
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[Serializable]
|
||||
public class Coordinate : IEquatable<Coordinate>
|
||||
{
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private int m_FontSize;
|
||||
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
|
||||
public static Coordinate defaultCoordinate
|
||||
{
|
||||
get
|
||||
{
|
||||
var coordinate = new Coordinate
|
||||
{
|
||||
m_Left = 50,
|
||||
m_Right = 30,
|
||||
m_Top = 50,
|
||||
m_Bottom = 30,
|
||||
m_Tickness = 0.6f,
|
||||
m_FontSize = 16,
|
||||
};
|
||||
return coordinate;
|
||||
}
|
||||
}
|
||||
public void Copy(Coordinate other)
|
||||
{
|
||||
m_Left = other.left;
|
||||
m_Right = other.right;
|
||||
m_Top = other.top;
|
||||
m_Bottom = other.bottom;
|
||||
m_Tickness = other.tickness;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is Coordinate)
|
||||
{
|
||||
return Equals((Coordinate)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Coordinate other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_Left == other.left &&
|
||||
m_Right == other.right &&
|
||||
m_Top == other.top &&
|
||||
m_Bottom == other.bottom &&
|
||||
m_Tickness == other.tickness &&
|
||||
m_FontSize == other.fontSize;
|
||||
}
|
||||
|
||||
public static bool operator ==(Coordinate left, Coordinate right)
|
||||
{
|
||||
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Coordinate left, Coordinate right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7dea6e12aeb93945888247ea97dbd13
|
||||
timeCreated: 1554422468
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,13 +6,13 @@ using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class CoordinateChart : BaseChart
|
||||
public partial class CoordinateChart : BaseChart
|
||||
{
|
||||
private static readonly string s_DefaultAxisY = "axis_y";
|
||||
private static readonly string s_DefaultAxisX = "axis_x";
|
||||
private static readonly string s_DefaultDataZoom = "datazoom";
|
||||
|
||||
[SerializeField] protected Coordinate m_Coordinate = Coordinate.defaultCoordinate;
|
||||
[SerializeField] protected Grid m_Grid = Grid.defaultGrid;
|
||||
[SerializeField] protected List<XAxis> m_XAxises = new List<XAxis>();
|
||||
[SerializeField] protected List<YAxis> m_YAxises = new List<YAxis>();
|
||||
[SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom;
|
||||
@@ -22,85 +22,9 @@ namespace XCharts
|
||||
private bool m_DataZoomEndDrag;
|
||||
private float m_DataZoomLastStartIndex;
|
||||
private float m_DataZoomLastEndIndex;
|
||||
|
||||
private List<XAxis> m_CheckXAxises = new List<XAxis>();
|
||||
private List<YAxis> m_CheckYAxises = new List<YAxis>();
|
||||
private Coordinate m_CheckCoordinate = Coordinate.defaultCoordinate;
|
||||
|
||||
public float coordinateX { get { return m_Coordinate.left; } }
|
||||
public float coordinateY { get { return m_Coordinate.bottom; } }
|
||||
public float coordinateWid { get { return chartWidth - m_Coordinate.left - m_Coordinate.right; } }
|
||||
public float coordinateHig { get { return chartHeight - m_Coordinate.top - m_Coordinate.bottom; } }
|
||||
public List<XAxis> xAxises { get { return m_XAxises; } }
|
||||
public List<YAxis> yAxises { get { return m_YAxises; } }
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series,legend and axis.
|
||||
/// It just emptying all of serie's data without emptying the list of series.
|
||||
/// </summary>
|
||||
public override void ClearData()
|
||||
{
|
||||
base.ClearData();
|
||||
ClearAxisData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series,legend and axis.
|
||||
/// The series list is also cleared.
|
||||
/// </summary>
|
||||
public override void RemoveData()
|
||||
{
|
||||
base.RemoveData();
|
||||
ClearAxisData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data of axises.
|
||||
/// </summary>
|
||||
public void ClearAxisData()
|
||||
{
|
||||
foreach (var item in m_XAxises) item.data.Clear();
|
||||
foreach (var item in m_YAxises) item.data.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a category data to xAxis.
|
||||
/// </summary>
|
||||
/// <param name="category">the category data</param>
|
||||
/// <param name="xAxisIndex">which xAxis should category add to</param>
|
||||
public void AddXAxisData(string category, int xAxisIndex = 0)
|
||||
{
|
||||
m_XAxises[xAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a category data to yAxis.
|
||||
/// </summary>
|
||||
/// <param name="category">the category data</param>
|
||||
/// <param name="yAxisIndex">which yAxis should category add to</param>
|
||||
public void AddYAxisData(string category, int yAxisIndex = 0)
|
||||
{
|
||||
m_YAxises[yAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether is Cartesian coordinates, reutrn true when all the show axis is `Value` type.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsCartesian()
|
||||
{
|
||||
foreach (var axis in m_XAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsValue()) return false;
|
||||
}
|
||||
foreach (var axis in m_YAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsValue()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private Grid m_CheckCoordinate = Grid.defaultGrid;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -127,7 +51,7 @@ namespace XCharts
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
m_Coordinate = Coordinate.defaultCoordinate;
|
||||
m_Grid = Grid.defaultGrid;
|
||||
m_XAxises.Clear();
|
||||
m_YAxises.Clear();
|
||||
Awake();
|
||||
@@ -151,7 +75,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var isCartesian = IsCartesian();
|
||||
var isCartesian = IsValue();
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
@@ -250,7 +174,7 @@ namespace XCharts
|
||||
base.RefreshTooltip();
|
||||
int index;
|
||||
Axis tempAxis;
|
||||
bool isCartesian = IsCartesian();
|
||||
bool isCartesian = IsValue();
|
||||
if (isCartesian)
|
||||
{
|
||||
index = m_Tooltip.dataIndex[0];
|
||||
@@ -440,14 +364,14 @@ namespace XCharts
|
||||
{
|
||||
txt = ChartHelper.AddTextObject(objName + i, axisObj.transform,
|
||||
m_ThemeInfo.font, labelColor, TextAnchor.MiddleLeft, Vector2.zero,
|
||||
Vector2.zero, new Vector2(0, 0.5f), new Vector2(m_Coordinate.left, 20),
|
||||
Vector2.zero, new Vector2(0, 0.5f), new Vector2(m_Grid.left, 20),
|
||||
yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
txt = ChartHelper.AddTextObject(objName + i, axisObj.transform,
|
||||
m_ThemeInfo.font, labelColor, TextAnchor.MiddleRight, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(m_Coordinate.left, 20),
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(m_Grid.left, 20),
|
||||
yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle);
|
||||
}
|
||||
|
||||
@@ -667,9 +591,9 @@ namespace XCharts
|
||||
|
||||
private void CheckCoordinate()
|
||||
{
|
||||
if (m_CheckCoordinate != m_Coordinate)
|
||||
if (m_CheckCoordinate != m_Grid)
|
||||
{
|
||||
m_CheckCoordinate.Copy(m_Coordinate);
|
||||
m_CheckCoordinate.Copy(m_Grid);
|
||||
OnCoordinateChanged();
|
||||
}
|
||||
}
|
||||
@@ -780,6 +704,7 @@ namespace XCharts
|
||||
|
||||
private void DrawCoordinate(VertexHelper vh)
|
||||
{
|
||||
DrawGrid(vh);
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
DrawXAxisTickAndSplit(vh, i, m_XAxises[i]);
|
||||
@@ -798,6 +723,18 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGrid(VertexHelper vh)
|
||||
{
|
||||
if (m_Grid.show && m_Grid.backgroundColor != Color.clear)
|
||||
{
|
||||
var p1 = new Vector2(coordinateX, coordinateY);
|
||||
var p2 = new Vector2(coordinateX, coordinateY + coordinateHig);
|
||||
var p3 = new Vector2(coordinateX + coordinateWid, coordinateY + coordinateHig);
|
||||
var p4 = new Vector2(coordinateX + coordinateWid, coordinateY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_Grid.backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawYAxisTickAndSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis)
|
||||
{
|
||||
if (yAxis.show)
|
||||
@@ -834,11 +771,11 @@ namespace XCharts
|
||||
pX += startX - yAxis.axisTick.length;
|
||||
}
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, pY), new Vector3(pX, pY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
yAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
if (yAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, true, yAxis.splitLineType, new Vector3(coordinateX, pY),
|
||||
DrawSplitLine(vh, yAxis, yAxis.splitLineType, new Vector3(coordinateX, pY),
|
||||
new Vector3(coordinateX + coordinateWid, pY), m_ThemeInfo.axisSplitLineColor);
|
||||
}
|
||||
}
|
||||
@@ -881,11 +818,11 @@ namespace XCharts
|
||||
pY += startY - xAxis.axisTick.length;
|
||||
}
|
||||
ChartHelper.DrawLine(vh, new Vector3(pX, startY), new Vector3(pX, pY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
xAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
if (xAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, false, xAxis.splitLineType, new Vector3(pX, coordinateY),
|
||||
DrawSplitLine(vh, xAxis, xAxis.splitLineType, new Vector3(pX, coordinateY),
|
||||
new Vector3(pX, coordinateY + coordinateHig), m_ThemeInfo.axisSplitLineColor);
|
||||
}
|
||||
}
|
||||
@@ -898,9 +835,9 @@ namespace XCharts
|
||||
{
|
||||
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].zeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHig;
|
||||
var left = new Vector3(coordinateX - m_Coordinate.tickness, lineY);
|
||||
var top = new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, lineY);
|
||||
ChartHelper.DrawLine(vh, left, top, m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
var left = new Vector3(coordinateX - xAxis.axisLine.width, lineY);
|
||||
var top = new Vector3(coordinateX + coordinateWid + xAxis.axisLine.width, lineY);
|
||||
ChartHelper.DrawLine(vh, left, top, xAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
if (xAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = xAxis.axisLine;
|
||||
@@ -920,9 +857,9 @@ namespace XCharts
|
||||
{
|
||||
var lineX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].zeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += coordinateWid;
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHig + m_Coordinate.tickness);
|
||||
ChartHelper.DrawLine(vh, new Vector3(lineX, coordinateY - m_Coordinate.tickness),
|
||||
top, m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHig + yAxis.axisLine.width);
|
||||
ChartHelper.DrawLine(vh, new Vector3(lineX, coordinateY - yAxis.axisLine.width),
|
||||
top, yAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
if (yAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = yAxis.axisLine;
|
||||
@@ -943,10 +880,11 @@ namespace XCharts
|
||||
var p2 = new Vector2(coordinateX, m_DataZoom.bottom + m_DataZoom.height);
|
||||
var p3 = new Vector2(coordinateX + coordinateWid, m_DataZoom.bottom + m_DataZoom.height);
|
||||
var p4 = new Vector2(coordinateX + coordinateWid, m_DataZoom.bottom);
|
||||
ChartHelper.DrawLine(vh, p1, p2, m_Coordinate.tickness, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartHelper.DrawLine(vh, p2, p3, m_Coordinate.tickness, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartHelper.DrawLine(vh, p3, p4, m_Coordinate.tickness, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartHelper.DrawLine(vh, p4, p1, m_Coordinate.tickness, m_ThemeInfo.dataZoomLineColor);
|
||||
var xAxis = xAxises[0];
|
||||
ChartHelper.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartHelper.DrawLine(vh, p2, p3, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartHelper.DrawLine(vh, p3, p4, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartHelper.DrawLine(vh, p4, p1, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||
if (m_DataZoom.showDataShadow && m_Series.Count > 0)
|
||||
{
|
||||
Serie serie = m_Series.series[0];
|
||||
@@ -968,12 +906,12 @@ namespace XCharts
|
||||
if (i > 0)
|
||||
{
|
||||
Color color = m_ThemeInfo.dataZoomLineColor;
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Coordinate.tickness, color);
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - m_Coordinate.tickness);
|
||||
Vector3 anp = new Vector3(np.x, np.y - m_Coordinate.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, np, xAxis.axisLine.width, color);
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - xAxis.axisLine.width);
|
||||
Vector3 anp = new Vector3(np.x, np.y - xAxis.axisLine.width);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
Vector3 tnp = new Vector3(np.x, m_DataZoom.bottom + m_Coordinate.tickness);
|
||||
Vector3 tlp = new Vector3(lp.x, m_DataZoom.bottom + m_Coordinate.tickness);
|
||||
Vector3 tnp = new Vector3(np.x, m_DataZoom.bottom + xAxis.axisLine.width);
|
||||
Vector3 tlp = new Vector3(lp.x, m_DataZoom.bottom + xAxis.axisLine.width);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
lp = np;
|
||||
@@ -989,15 +927,16 @@ namespace XCharts
|
||||
p3 = new Vector2(end, m_DataZoom.bottom + m_DataZoom.height);
|
||||
p4 = new Vector2(end, m_DataZoom.bottom);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.dataZoomSelectedColor);
|
||||
ChartHelper.DrawLine(vh, p1, p2, m_Coordinate.tickness, m_ThemeInfo.dataZoomSelectedColor);
|
||||
ChartHelper.DrawLine(vh, p3, p4, m_Coordinate.tickness, m_ThemeInfo.dataZoomSelectedColor);
|
||||
ChartHelper.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomSelectedColor);
|
||||
ChartHelper.DrawLine(vh, p3, p4, xAxis.axisLine.width, m_ThemeInfo.dataZoomSelectedColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawSplitLine(VertexHelper vh, bool isYAxis, Axis.SplitLineType type,
|
||||
protected void DrawSplitLine(VertexHelper vh, Axis axis, Axis.SplitLineType type,
|
||||
Vector3 startPos, Vector3 endPos, Color color)
|
||||
{
|
||||
bool isYAxis = axis is YAxis;
|
||||
switch (type)
|
||||
{
|
||||
case Axis.SplitLineType.Dashed:
|
||||
@@ -1013,21 +952,21 @@ namespace XCharts
|
||||
{
|
||||
var toX = startX + dashLen;
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, startY), new Vector3(toX, startY),
|
||||
m_Coordinate.tickness, color);
|
||||
axis.axisLine.width, color);
|
||||
startX += dashLen * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
var toY = startY + dashLen;
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, startY), new Vector3(startX, toY),
|
||||
m_Coordinate.tickness, color);
|
||||
axis.axisLine.width, color);
|
||||
startY += dashLen * 2;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case Axis.SplitLineType.Solid:
|
||||
ChartHelper.DrawLine(vh, startPos, endPos, m_Coordinate.tickness, color);
|
||||
ChartHelper.DrawLine(vh, startPos, endPos, axis.axisLine.width, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1052,12 +991,12 @@ namespace XCharts
|
||||
if (xAxis.IsValue()) pX = m_Tooltip.pointerPos.x;
|
||||
Vector2 sp = new Vector2(pX, coordinateY);
|
||||
Vector2 ep = new Vector2(pX, coordinateY + coordinateHig);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, xAxis, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, yAxis, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
@@ -1084,6 +1023,7 @@ namespace XCharts
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var yAxis = m_YAxises[i];
|
||||
var xAxis = m_XAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
float splitWidth = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
@@ -1094,12 +1034,12 @@ namespace XCharts
|
||||
float pY = coordinateY + m_Tooltip.yValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(coordinateX, pY);
|
||||
Vector2 ep = new Vector2(coordinateX + coordinateWid, pY);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, xAxis, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, yAxis, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
|
||||
131
Scripts/UI/Internal/CoordinateChart_API.cs
Normal file
131
Scripts/UI/Internal/CoordinateChart_API.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// The basic class of rectangular coordinate chart,such as LineChart,BarChart and ScatterChart.
|
||||
/// 直角坐标系类型图表的基类,如折线图LineChart,柱状图BarChart,散点图ScatterChart都属于这类型的图表。
|
||||
/// 不可用直接将CoordinateChart绑定到GameObject上。
|
||||
/// </summary>
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
/// <summary>
|
||||
/// The lower left position x of coordinate system.
|
||||
/// 坐标系的左下角坐标X。
|
||||
/// </summary>
|
||||
public float coordinateX { get { return m_Grid.left; } }
|
||||
/// <summary>
|
||||
/// The lower left position y of coordinate system.
|
||||
/// 坐标系的左下角坐标Y。
|
||||
/// </summary>
|
||||
public float coordinateY { get { return m_Grid.bottom; } }
|
||||
/// <summary>
|
||||
/// the width of coordinate system。
|
||||
/// 坐标系的宽。
|
||||
/// </summary>
|
||||
public float coordinateWid { get { return chartWidth - m_Grid.left - m_Grid.right; } }
|
||||
/// <summary>
|
||||
/// the height of coordinate system。
|
||||
/// 坐标系的高。
|
||||
/// </summary>
|
||||
public float coordinateHig { get { return chartHeight - m_Grid.top - m_Grid.bottom; } }
|
||||
/// <summary>
|
||||
/// grid component.
|
||||
/// 网格组件。
|
||||
/// </summary>
|
||||
public Grid grid { get { return m_Grid; } }
|
||||
/// <summary>
|
||||
/// the x axises,xAxises[0] is the first x axis, xAxises[1] is the second x axis.
|
||||
/// 两个x轴。
|
||||
/// </summary>
|
||||
public List<XAxis> xAxises { get { return m_XAxises; } }
|
||||
/// <summary>
|
||||
/// the y axises, yAxises[0] is the first y axis, yAxises[1] is the second y axis.
|
||||
/// 两个y轴。
|
||||
/// </summary>
|
||||
public List<YAxis> yAxises { get { return m_YAxises; } }
|
||||
/// <summary>
|
||||
/// dataZoom component.
|
||||
/// 区域缩放组件。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public DataZoom dataZoom { get { return m_DataZoom; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series,legend and axis.
|
||||
/// It just emptying all of serie's data without emptying the list of series.
|
||||
/// 清空所有图例,系列和坐标轴类目数据。系列中指示清空系列中的数据,会保留系列列表。
|
||||
/// </summary>
|
||||
public override void ClearData()
|
||||
{
|
||||
base.ClearData();
|
||||
ClearAxisData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series,legend and axis.
|
||||
/// The series list is also cleared.
|
||||
/// 清空所有图例,系列和坐标轴类目数据。系列的列表也会被清空。
|
||||
/// </summary>
|
||||
public override void RemoveData()
|
||||
{
|
||||
base.RemoveData();
|
||||
ClearAxisData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data of axises.
|
||||
/// 清除所有x轴和y轴的类目数据。
|
||||
/// </summary>
|
||||
public void ClearAxisData()
|
||||
{
|
||||
foreach (var item in m_XAxises) item.data.Clear();
|
||||
foreach (var item in m_YAxises) item.data.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a category data to xAxis.
|
||||
/// 添加一个类目数据到指定的x轴。
|
||||
/// </summary>
|
||||
/// <param name="category">the category data</param>
|
||||
/// <param name="xAxisIndex">which xAxis should category add to</param>
|
||||
public void AddXAxisData(string category, int xAxisIndex = 0)
|
||||
{
|
||||
m_XAxises[xAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a category data to yAxis.
|
||||
/// 添加一个类目数据到指定的y轴。
|
||||
/// </summary>
|
||||
/// <param name="category">the category data</param>
|
||||
/// <param name="yAxisIndex">which yAxis should category add to</param>
|
||||
public void AddYAxisData(string category, int yAxisIndex = 0)
|
||||
{
|
||||
m_YAxises[yAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reutrn true when all the show axis is `Value` type.
|
||||
/// 纯数值坐标。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsValue()
|
||||
{
|
||||
foreach (var axis in m_XAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsValue()) return false;
|
||||
}
|
||||
foreach (var axis in m_YAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsValue()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dd59b655decf420ca27dfb742be4fdf
|
||||
guid: dbe51753d5fc64acfab72f95e03773c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,239 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// DataZoom component is used for zooming a specific area,
|
||||
/// which enables user to investigate data in detail,
|
||||
/// or get an overview of the data, or get rid of outlier points.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class DataZoom
|
||||
{
|
||||
public enum DataZoomType
|
||||
{
|
||||
/// <summary>
|
||||
/// DataZoom functionalities is embeded inside coordinate systems, enable user to
|
||||
/// zoom or roam coordinate system by mouse dragging, mouse move or finger touch (in touch screen).
|
||||
/// </summary>
|
||||
Inside,
|
||||
/// <summary>
|
||||
/// A special slider bar is provided, on which coordinate systems can be zoomed or
|
||||
/// roamed by mouse dragging or finger touch (in touch screen).
|
||||
/// </summary>
|
||||
Slider
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generally dataZoom component zoom or roam coordinate system through data filtering
|
||||
/// and set the windows of axes internally.
|
||||
/// Its behaviours vary according to filtering mode settings
|
||||
/// </summary>
|
||||
public enum FilterMode
|
||||
{
|
||||
/// <summary>
|
||||
/// data that outside the window will be filtered, which may lead to some changes of windows of other axes.
|
||||
/// For each data item, it will be filtered if one of the relevant dimensions is out of the window.
|
||||
/// </summary>
|
||||
Filter,
|
||||
/// <summary>
|
||||
/// data that outside the window will be filtered, which may lead to some changes of windows of other axes.
|
||||
/// For each data item, it will be filtered only if all of the relevant dimensions are out of the same side of the window.
|
||||
/// </summary>
|
||||
WeakFilter,
|
||||
/// <summary>
|
||||
/// data that outside the window will be set to NaN, which will not lead to changes of windows of other axes
|
||||
/// </summary>
|
||||
Empty,
|
||||
/// <summary>
|
||||
/// Do not filter data.
|
||||
/// </summary>
|
||||
None
|
||||
}
|
||||
public enum RangeMode
|
||||
{
|
||||
//Value,
|
||||
/// <summary>
|
||||
/// percent value
|
||||
/// </summary>
|
||||
Percent
|
||||
}
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private DataZoomType m_Type;
|
||||
[SerializeField] private FilterMode m_FilterMode;
|
||||
[SerializeField] private Orient m_Orient;
|
||||
[SerializeField] private int m_XAxisIndex;
|
||||
[SerializeField] private int m_YAxisIndex;
|
||||
|
||||
[SerializeField] private bool m_ShowDataShadow;
|
||||
[SerializeField] private bool m_ShowDetail;
|
||||
[SerializeField] private bool m_ZoomLock;
|
||||
[SerializeField] private bool m_Realtime;
|
||||
[SerializeField] private Color m_BackgroundColor;
|
||||
[SerializeField] private float m_Height;
|
||||
[SerializeField] private float m_Bottom;
|
||||
[SerializeField] private RangeMode m_RangeMode;
|
||||
[SerializeField] private float m_Start;
|
||||
[SerializeField] private float m_End;
|
||||
[SerializeField] private float m_StartValue;
|
||||
[SerializeField] private float m_EndValue;
|
||||
[Range(1f, 20f)]
|
||||
[SerializeField] private float m_ScrollSensitivity;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public DataZoomType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
|
||||
/// <summary>
|
||||
/// Specify whether the layout of dataZoom component is horizontal or vertical.
|
||||
/// </summary>
|
||||
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
|
||||
public int xAxisIndex { get { return m_XAxisIndex; } set { m_XAxisIndex = value; } }
|
||||
public int yAxisIndex { get { return m_YAxisIndex; } set { m_YAxisIndex = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show data shadow, to indicate the data tendency in brief.
|
||||
/// default:true
|
||||
/// </summary>
|
||||
public bool showDataShadow { get { return m_ShowDataShadow; } set { m_ShowDataShadow = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show detail, that is, show the detailed data information when dragging.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public bool showDetail { get { return m_ShowDetail; } set { m_ShowDetail = value; } }
|
||||
/// <summary>
|
||||
/// Specify whether to lock the size of window (selected area).
|
||||
/// default:false
|
||||
/// </summary>
|
||||
public bool zoomLock { get { return m_ZoomLock; } set { m_ZoomLock = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief.
|
||||
/// default:true
|
||||
/// </summary>
|
||||
public bool realtime { get { return m_Realtime; } set { m_Realtime = value; } }
|
||||
/// <summary>
|
||||
/// The background color of the component.
|
||||
/// </summary>
|
||||
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
|
||||
/// <summary>
|
||||
/// Distance between dataZoom component and the bottom side of the container.
|
||||
/// bottom value is a instant pixel value like 10.
|
||||
/// default:10
|
||||
/// </summary>
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
/// <summary>
|
||||
/// The height of dataZoom component.
|
||||
/// height value is a instant pixel value like 10.
|
||||
/// default:50
|
||||
/// </summary>
|
||||
public float height { get { return m_Height; } set { m_Height = value; } }
|
||||
/// <summary>
|
||||
/// Use absolute value or percent value in DataZoom.start and DataZoom.end.
|
||||
/// default:RangeMode.Percent
|
||||
/// </summary>
|
||||
public RangeMode rangeMode { get { return m_RangeMode; } set { m_RangeMode = value; } }
|
||||
/// <summary>
|
||||
/// The start percentage of the window out of the data extent, in the range of 0 ~ 100.
|
||||
/// default:30
|
||||
/// </summary>
|
||||
public float start { get { return m_Start; } set { m_Start = value; } }
|
||||
/// <summary>
|
||||
/// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
|
||||
/// default:70
|
||||
/// </summary>
|
||||
public float end { get { return m_End; } set { m_End = value; } }
|
||||
/// <summary>
|
||||
/// The sensitivity of dataZoom scroll.
|
||||
/// The larger the number, the more sensitive it is.
|
||||
/// default:10
|
||||
/// </summary>
|
||||
public float scrollSensitivity { get { return m_ScrollSensitivity; } set { m_ScrollSensitivity = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// DataZoom is in draging.
|
||||
/// </summary>
|
||||
public bool isDraging { get; set; }
|
||||
/// <summary>
|
||||
/// The start label.
|
||||
/// </summary>
|
||||
public Text startLabel { get; set; }
|
||||
/// <summary>
|
||||
/// The end label.
|
||||
/// </summary>
|
||||
public Text endLabel { get; set; }
|
||||
|
||||
public static DataZoom defaultDataZoom
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DataZoom()
|
||||
{
|
||||
m_Type = DataZoomType.Slider,
|
||||
filterMode = FilterMode.None,
|
||||
orient = Orient.Horizonal,
|
||||
xAxisIndex = 0,
|
||||
yAxisIndex = 0,
|
||||
showDataShadow = true,
|
||||
showDetail = false,
|
||||
zoomLock = false,
|
||||
realtime = true,
|
||||
m_Height = 50,
|
||||
m_Bottom = 10,
|
||||
rangeMode = RangeMode.Percent,
|
||||
start = 30,
|
||||
end = 70,
|
||||
m_ScrollSensitivity = 10,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInZoom(Vector2 pos, float startX, float width)
|
||||
{
|
||||
Rect rect = Rect.MinMaxRect(startX, m_Bottom, startX + width, m_Bottom + m_Height);
|
||||
return rect.Contains(pos);
|
||||
}
|
||||
|
||||
public bool IsInSelectedZoom(Vector2 pos, float startX, float width)
|
||||
{
|
||||
var start = startX + width * m_Start / 100;
|
||||
var end = startX + width * m_End / 100;
|
||||
Rect rect = Rect.MinMaxRect(start, m_Bottom, end, m_Bottom + m_Height);
|
||||
return rect.Contains(pos);
|
||||
}
|
||||
|
||||
public bool IsInStartZoom(Vector2 pos, float startX, float width)
|
||||
{
|
||||
var start = startX + width * m_Start / 100;
|
||||
Rect rect = Rect.MinMaxRect(start - 10, m_Bottom, start + 10, m_Bottom + m_Height);
|
||||
return rect.Contains(pos);
|
||||
}
|
||||
|
||||
public bool IsInEndZoom(Vector2 pos, float startX, float width)
|
||||
{
|
||||
var end = startX + width * m_End / 100;
|
||||
Rect rect = Rect.MinMaxRect(end - 10, m_Bottom, end + 10, m_Bottom + m_Height);
|
||||
return rect.Contains(pos);
|
||||
}
|
||||
|
||||
public void SetLabelActive(bool flag)
|
||||
{
|
||||
if (startLabel && startLabel.gameObject.activeInHierarchy != flag)
|
||||
{
|
||||
startLabel.gameObject.SetActive(flag);
|
||||
}
|
||||
if (endLabel && endLabel.gameObject.activeInHierarchy != flag)
|
||||
{
|
||||
endLabel.gameObject.SetActive(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStartLabelText(string text)
|
||||
{
|
||||
if (startLabel) startLabel.text = text;
|
||||
}
|
||||
|
||||
public void SetEndLabelText(string text)
|
||||
{
|
||||
if (endLabel) endLabel.text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55000eccffd85064ea6a4d1d39ff63bb
|
||||
timeCreated: 1559526210
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,11 +3,18 @@ using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 支持从json格式的字符串中导入数据
|
||||
/// </summary>
|
||||
public class JsonDataSupport : IJsonData, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField] protected string m_JsonData;
|
||||
[SerializeField] protected bool m_DataFromJson;
|
||||
|
||||
/// <summary>
|
||||
/// json格式的字符串数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string jsonData { get { return m_JsonData; } set { m_JsonData = value; ParseJsonData(value); } }
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
|
||||
@@ -1,247 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Legend : JsonDataSupport, IPropertyChanged, IEquatable<Legend>
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Orient m_Orient = Orient.Horizonal;
|
||||
[SerializeField] private Location m_Location = Location.defaultRight;
|
||||
[SerializeField] private float m_ItemWidth = 50.0f;
|
||||
[SerializeField] private float m_ItemHeight = 20.0f;
|
||||
[SerializeField] private float m_ItemGap = 5;
|
||||
[SerializeField] private int m_ItemFontSize = 18;
|
||||
[SerializeField] private List<string> m_Data = new List<string>();
|
||||
|
||||
private Dictionary<string, Button> m_DataBtnList = new Dictionary<string, Button>();
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
|
||||
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
|
||||
|
||||
public Location location { get { return m_Location; } set { m_Location = value; } }
|
||||
|
||||
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
|
||||
|
||||
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
|
||||
|
||||
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
|
||||
|
||||
public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } }
|
||||
|
||||
public List<string> data { get { return m_Data; } }
|
||||
|
||||
public static Legend defaultLegend
|
||||
{
|
||||
get
|
||||
{
|
||||
var legend = new Legend
|
||||
{
|
||||
m_Show = false,
|
||||
m_Orient = Orient.Horizonal,
|
||||
m_Location = Location.defaultTop,
|
||||
m_ItemWidth = 60.0f,
|
||||
m_ItemHeight = 20.0f,
|
||||
m_ItemGap = 5,
|
||||
m_ItemFontSize = 16
|
||||
};
|
||||
legend.location.top = 30;
|
||||
return legend;
|
||||
}
|
||||
}
|
||||
public void Copy(Legend legend)
|
||||
{
|
||||
m_Show = legend.show;
|
||||
m_Orient = legend.orient;
|
||||
m_Location.Copy(legend.location);
|
||||
m_ItemWidth = legend.itemWidth;
|
||||
m_ItemHeight = legend.itemHeight;
|
||||
m_ItemGap = legend.itemGap;
|
||||
m_ItemFontSize = legend.itemFontSize;
|
||||
m_Data.Clear();
|
||||
foreach (var d in legend.data) m_Data.Add(d);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is Legend)
|
||||
{
|
||||
return Equals((Legend)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Legend other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return show == other.show &&
|
||||
orient == other.orient &&
|
||||
location == other.location &&
|
||||
itemWidth == other.itemWidth &&
|
||||
itemHeight == other.itemHeight &&
|
||||
itemGap == other.itemGap &&
|
||||
itemFontSize == other.itemFontSize &&
|
||||
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
|
||||
}
|
||||
|
||||
public static bool operator ==(Legend left, Legend right)
|
||||
{
|
||||
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Legend left, Legend right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
}
|
||||
|
||||
public bool ContainsData(string name)
|
||||
{
|
||||
return m_Data.Contains(name);
|
||||
}
|
||||
|
||||
public void RemoveData(string name)
|
||||
{
|
||||
if (m_Data.Contains(name))
|
||||
{
|
||||
m_Data.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(string name)
|
||||
{
|
||||
if (!m_Data.Contains(name) && !string.IsNullOrEmpty(name))
|
||||
{
|
||||
m_Data.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetData(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
return m_Data[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int GetIndex(string legendName)
|
||||
{
|
||||
return m_Data.IndexOf(legendName);
|
||||
}
|
||||
|
||||
public void RemoveButton()
|
||||
{
|
||||
m_DataBtnList.Clear();
|
||||
}
|
||||
|
||||
public void SetButton(string name, Button btn, int total)
|
||||
{
|
||||
int index = m_DataBtnList.Values.Count;
|
||||
btn.transform.localPosition = GetButtonLocationPosition(total, index);
|
||||
m_DataBtnList[name] = btn;
|
||||
btn.gameObject.SetActive(show);
|
||||
btn.GetComponentInChildren<Text>().text = name;
|
||||
}
|
||||
|
||||
public void UpdateButtonColor(string name, Color color)
|
||||
{
|
||||
if (m_DataBtnList.ContainsKey(name))
|
||||
{
|
||||
m_DataBtnList[name].GetComponent<Image>().color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
m_Location.OnChanged();
|
||||
}
|
||||
|
||||
private Vector2 GetButtonLocationPosition(int size, int index)
|
||||
{
|
||||
switch (m_Orient)
|
||||
{
|
||||
case Orient.Vertical:
|
||||
switch (m_Location.align)
|
||||
{
|
||||
case Location.Align.TopCenter:
|
||||
case Location.Align.TopLeft:
|
||||
case Location.Align.TopRight:
|
||||
return new Vector2(0, -index * (itemHeight + itemGap));
|
||||
|
||||
case Location.Align.Center:
|
||||
case Location.Align.CenterLeft:
|
||||
case Location.Align.CenterRight:
|
||||
float totalHeight = size * itemHeight + (size - 1) * itemGap;
|
||||
float startY = totalHeight / 2;
|
||||
return new Vector2(0, startY - index * (itemHeight + itemGap));
|
||||
|
||||
case Location.Align.BottomCenter:
|
||||
case Location.Align.BottomLeft:
|
||||
case Location.Align.BottomRight:
|
||||
return new Vector2(0, (size - index - 1) * (itemHeight + itemGap));
|
||||
}
|
||||
return Vector2.zero;
|
||||
|
||||
case Orient.Horizonal:
|
||||
switch (m_Location.align)
|
||||
{
|
||||
case Location.Align.TopLeft:
|
||||
case Location.Align.CenterLeft:
|
||||
case Location.Align.BottomLeft:
|
||||
return new Vector2(index * (itemWidth + itemGap), 0);
|
||||
|
||||
case Location.Align.TopCenter:
|
||||
case Location.Align.Center:
|
||||
case Location.Align.BottomCenter:
|
||||
float totalWidth = size * itemWidth + (size - 1) * itemGap;
|
||||
float startX = totalWidth / 2;
|
||||
return new Vector2(-startX + itemWidth / 2 + index * (itemWidth + itemGap), 0);
|
||||
case Location.Align.TopRight:
|
||||
case Location.Align.CenterRight:
|
||||
case Location.Align.BottomRight:
|
||||
return new Vector2(-(size - index - 1) * (itemWidth + itemGap), 0);
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
m_Data = ChartHelper.ParseStringFromString(jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fba76b49d7dd644cb3953355d6caae4
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,45 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Line
|
||||
{
|
||||
public enum StepType
|
||||
{
|
||||
Start,
|
||||
Middle,
|
||||
End
|
||||
}
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private bool m_Smooth;
|
||||
[SerializeField] [Range(1f, 10f)] private float m_SmoothStyle;
|
||||
[SerializeField] private bool m_Area;
|
||||
[SerializeField] private bool m_Step;
|
||||
[SerializeField] private StepType m_StepType;
|
||||
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
public float smoothStyle { get { return m_SmoothStyle; } set { m_SmoothStyle = value; } }
|
||||
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
public bool step { get { return m_Step; } set { m_Step = value; } }
|
||||
public StepType stepTpe { get { return m_StepType; } set { m_StepType = value; } }
|
||||
|
||||
public static Line defaultLine
|
||||
{
|
||||
get
|
||||
{
|
||||
var line = new Line
|
||||
{
|
||||
m_Tickness = 0.8f,
|
||||
m_Smooth = false,
|
||||
m_SmoothStyle = 2f,
|
||||
m_Area = false,
|
||||
m_Step = false,
|
||||
m_StepType = StepType.Middle
|
||||
};
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86acdbfd671c43949bf0cc4880a4ccb7
|
||||
timeCreated: 1555671450
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,9 +3,16 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Location type. Quick to set the general location.
|
||||
/// 位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Location : IPropertyChanged, IEquatable<Location>
|
||||
{
|
||||
/// <summary>
|
||||
/// 对齐方式
|
||||
/// </summary>
|
||||
public enum Align
|
||||
{
|
||||
TopLeft,
|
||||
@@ -30,15 +37,54 @@ namespace XCharts
|
||||
private Vector2 m_AnchorMax;
|
||||
private Vector2 m_Pivot;
|
||||
|
||||
/// <summary>
|
||||
/// 对齐方式。
|
||||
/// </summary>
|
||||
public Align align { get { return m_Align; } set { m_Align = value; UpdateAlign(); } }
|
||||
/// <summary>
|
||||
/// Distance between component and the left side of the container.
|
||||
/// 离容器左侧的距离。
|
||||
/// </summary>
|
||||
public float left { get { return m_Left; } set { m_Left = value; UpdateAlign(); } }
|
||||
/// <summary>
|
||||
/// Distance between component and the left side of the container.
|
||||
/// 离容器右侧的距离。
|
||||
/// </summary>
|
||||
public float right { get { return m_Right; } set { m_Right = value; UpdateAlign(); } }
|
||||
/// <summary>
|
||||
/// Distance between component and the left side of the container.
|
||||
/// 离容器上侧的距离。
|
||||
/// </summary>
|
||||
public float top { get { return m_Top; } set { m_Top = value; UpdateAlign(); } }
|
||||
/// <summary>
|
||||
/// Distance between component and the left side of the container.
|
||||
/// 离容器下侧的距离。
|
||||
/// </summary>
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; UpdateAlign(); } }
|
||||
|
||||
/// <summary>
|
||||
/// the anchor of text.
|
||||
/// Location对应的Anchor锚点
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public TextAnchor textAnchor { get { return m_TextAnchor; } }
|
||||
/// <summary>
|
||||
/// the minimum achor.
|
||||
/// Location对应的anchorMin。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Vector2 anchorMin { get { return m_AnchorMin; } }
|
||||
/// <summary>
|
||||
/// the maximun achor.
|
||||
/// Location对应的anchorMax.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Vector2 anchorMax { get { return m_AnchorMax; } }
|
||||
/// <summary>
|
||||
/// the povot.
|
||||
/// Loation对应的中心点。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Vector2 pivot { get { return m_Pivot; } }
|
||||
|
||||
public static Location defaultLeft
|
||||
@@ -164,6 +210,12 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回在坐标系中的具体位置
|
||||
/// </summary>
|
||||
/// <param name="chartWidht"></param>
|
||||
/// <param name="chartHeight"></param>
|
||||
/// <returns></returns>
|
||||
public Vector2 GetPosition(float chartWidht, float chartHeight)
|
||||
{
|
||||
switch (align)
|
||||
@@ -252,6 +304,9 @@ namespace XCharts
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
|
||||
/// </summary>
|
||||
public void OnChanged()
|
||||
{
|
||||
UpdateAlign();
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Pie
|
||||
{
|
||||
[SerializeField] private float m_TooltipExtraRadius;
|
||||
[SerializeField] private float m_SelectedOffset;
|
||||
public float tooltipExtraRadius { get { return m_TooltipExtraRadius; } set { m_TooltipExtraRadius = value; } }
|
||||
public float selectedOffset { get { return m_SelectedOffset; } set { m_SelectedOffset = value; } }
|
||||
|
||||
public static Pie defaultPie
|
||||
{
|
||||
get
|
||||
{
|
||||
var pie = new Pie
|
||||
{
|
||||
m_TooltipExtraRadius = 10f,
|
||||
m_SelectedOffset = 10f,
|
||||
};
|
||||
return pie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f38ef4633bae5247a8c382a4d20fc39
|
||||
timeCreated: 1555671161
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,232 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Radar : JsonDataSupport, IEquatable<Radar>
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Indicator : IEquatable<Indicator>
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_Max;
|
||||
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public float max { get { return m_Max; } set { m_Max = value; } }
|
||||
|
||||
public Indicator Clone()
|
||||
{
|
||||
return new Indicator()
|
||||
{
|
||||
name = name,
|
||||
max = max
|
||||
};
|
||||
}
|
||||
|
||||
public bool Equals(Indicator other)
|
||||
{
|
||||
return name.Equals(other.name);
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Cricle;
|
||||
[SerializeField] private bool m_Area;
|
||||
|
||||
[SerializeField] private float m_Radius = 100;
|
||||
[SerializeField] private int m_SplitNumber = 5;
|
||||
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
|
||||
[SerializeField] private float m_LineTickness = 1f;
|
||||
[SerializeField] private float m_LinePointSize = 5f;
|
||||
[SerializeField] private Color m_LineColor = Color.grey;
|
||||
[Range(0, 255)]
|
||||
[SerializeField] private int m_AreaAlpha;
|
||||
|
||||
[SerializeField] private List<Color> m_BackgroundColorList = new List<Color>();
|
||||
[SerializeField] private bool m_Indicator = true;
|
||||
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
|
||||
|
||||
public bool cricle { get { return m_Cricle; } set { m_Cricle = value; } }
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
|
||||
public float radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
|
||||
public float lineTickness { get { return m_LineTickness; } set { m_LineTickness = value; } }
|
||||
public float linePointSize { get { return m_LinePointSize; } set { m_LinePointSize = value; } }
|
||||
public Color lineColor { get { return m_LineColor; } set { m_LineColor = value; } }
|
||||
public int areaAipha { get { return m_AreaAlpha; } set { m_AreaAlpha = value; } }
|
||||
public List<Color> backgroundColorList { get { return m_BackgroundColorList; } }
|
||||
public bool indicator { get { return m_Indicator; } set { m_Indicator = value; } }
|
||||
public List<Indicator> indicatorList { get { return m_IndicatorList; } }
|
||||
|
||||
public static Radar defaultRadar
|
||||
{
|
||||
get
|
||||
{
|
||||
var radar = new Radar
|
||||
{
|
||||
m_Cricle = false,
|
||||
m_Area = false,
|
||||
m_Radius = 100,
|
||||
m_SplitNumber = 5,
|
||||
m_Left = 0,
|
||||
m_Right = 0,
|
||||
m_Top = 0,
|
||||
m_Bottom = 0,
|
||||
m_LineTickness = 1f,
|
||||
m_LinePointSize = 5f,
|
||||
m_AreaAlpha = 150,
|
||||
m_LineColor = Color.grey,
|
||||
m_Indicator = true,
|
||||
m_BackgroundColorList = new List<Color> {
|
||||
new Color32(246, 246, 246, 255),
|
||||
new Color32(231, 231, 231, 255)
|
||||
},
|
||||
m_IndicatorList = new List<Indicator>(5){
|
||||
new Indicator(){name="radar1",max = 100},
|
||||
new Indicator(){name="radar2",max = 100},
|
||||
new Indicator(){name="radar3",max = 100},
|
||||
new Indicator(){name="radar4",max = 100},
|
||||
new Indicator(){name="radar5",max = 100},
|
||||
}
|
||||
};
|
||||
return radar;
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(Radar other)
|
||||
{
|
||||
m_Radius = other.radius;
|
||||
m_SplitNumber = other.splitNumber;
|
||||
m_Left = other.left;
|
||||
m_Right = other.right;
|
||||
m_Top = other.top;
|
||||
m_Bottom = other.bottom;
|
||||
m_Indicator = other.indicator;
|
||||
m_AreaAlpha = other.areaAipha;
|
||||
indicatorList.Clear();
|
||||
foreach (var d in other.indicatorList) indicatorList.Add(d.Clone());
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is Radar)
|
||||
{
|
||||
return Equals((Radar)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Radar other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return radius == other.radius &&
|
||||
splitNumber == other.splitNumber &&
|
||||
left == other.left &&
|
||||
right == other.right &&
|
||||
top == other.top &&
|
||||
bottom == other.bottom &&
|
||||
indicator == other.indicator &&
|
||||
IsEqualsIndicatorList(indicatorList, other.indicatorList);
|
||||
}
|
||||
|
||||
private bool IsEqualsIndicatorList(List<Indicator> indicators1, List<Indicator> indicators2)
|
||||
{
|
||||
if (indicators1.Count != indicators2.Count) return false;
|
||||
for (int i = 0; i < indicators1.Count; i++)
|
||||
{
|
||||
var indicator1 = indicators1[i];
|
||||
var indicator2 = indicators2[i];
|
||||
if (!indicator1.Equals(indicator2)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool operator ==(Radar left, Radar right)
|
||||
{
|
||||
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Radar left, Radar right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
string pattern = "[\"|'](.*?)[\"|']";
|
||||
if (Regex.IsMatch(jsonData, pattern))
|
||||
{
|
||||
m_IndicatorList.Clear();
|
||||
MatchCollection m = Regex.Matches(jsonData, pattern);
|
||||
foreach (Match match in m)
|
||||
{
|
||||
m_IndicatorList.Add(new Indicator()
|
||||
{
|
||||
name = match.Groups[1].Value
|
||||
});
|
||||
}
|
||||
}
|
||||
pattern = "(\\d+)";
|
||||
if (Regex.IsMatch(jsonData, pattern))
|
||||
{
|
||||
MatchCollection m = Regex.Matches(jsonData, pattern);
|
||||
int index = 0;
|
||||
foreach (Match match in m)
|
||||
{
|
||||
if (m_IndicatorList[index] != null)
|
||||
{
|
||||
m_IndicatorList[index].max = int.Parse(match.Groups[1].Value);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float GetIndicatorMax(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_IndicatorList.Count)
|
||||
{
|
||||
return m_IndicatorList[index].max;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3a368484f9598e4eb9dfce2471d34da
|
||||
timeCreated: 1555562622
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Scatter
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_InsideRadius;
|
||||
[SerializeField] private float m_OutsideRadius;
|
||||
[SerializeField] private float m_TooltipExtraRadius;
|
||||
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
|
||||
public static Scatter defaultScatter
|
||||
{
|
||||
get
|
||||
{
|
||||
var scatter = new Scatter
|
||||
{
|
||||
};
|
||||
return scatter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,552 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public enum SerieType
|
||||
{
|
||||
Line,
|
||||
Bar,
|
||||
Pie,
|
||||
Radar,
|
||||
Scatter,
|
||||
EffectScatter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show as Nightingale chart, which distinguishs data through radius.
|
||||
/// 是否展示成南丁格尔图,通过半径区分数据大小。
|
||||
/// </summary>
|
||||
public enum RoseType
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't show as Nightingale chart.不展示成南丁格尔玫瑰图
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// Use central angle to show the percentage of data, radius to show data size.
|
||||
/// 扇区圆心角展现数据的百分比,半径展现数据的大小。
|
||||
/// </summary>
|
||||
Radius,
|
||||
/// <summary>
|
||||
/// All the sectors will share the same central angle, the data size is shown only through radiuses.
|
||||
/// 所有扇区圆心角相同,仅通过半径展现数据大小。
|
||||
/// </summary>
|
||||
Area
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Serie : JsonDataSupport
|
||||
{
|
||||
[SerializeField] [DefaultValue("true")] private bool m_Show = true;
|
||||
[SerializeField] private SerieType m_Type;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Stack;
|
||||
[SerializeField] [Range(0, 1)] private int m_AxisIndex;
|
||||
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
||||
#region PieChart
|
||||
[SerializeField] private bool m_ClickOffset = true;
|
||||
[SerializeField] private RoseType m_RoseType = RoseType.None;
|
||||
[SerializeField] private float m_Space;
|
||||
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
|
||||
[SerializeField] private float[] m_Radius = new float[2] { 0, 80 };
|
||||
#endregion
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
[SerializeField] private SerieLabel m_HighlightLabel = new SerieLabel();
|
||||
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
|
||||
[SerializeField] private bool m_ShowDataName;
|
||||
[FormerlySerializedAs("m_Data")]
|
||||
[SerializeField] private List<float> m_YData = new List<float>();
|
||||
[SerializeField] private List<float> m_XData = new List<float>();
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public SerieType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public string stack { get { return m_Stack; } set { m_Stack = value; } }
|
||||
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
|
||||
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
||||
public bool clickOffset { get { return m_ClickOffset; } set { m_ClickOffset = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show as Nightingale chart.
|
||||
/// 是否展示成南丁格尔图,通过半径区分数据大小。
|
||||
/// </summary>
|
||||
public RoseType roseType { get { return m_RoseType; } set { m_RoseType = value; } }
|
||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||
public float[] center { get { return m_Center; } set { m_Center = value; } }
|
||||
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
/// <summary>
|
||||
/// Text label of graphic element,to explain some data information about graphic item like value, name and so on.
|
||||
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||
/// </summary>
|
||||
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
|
||||
public SerieLabel highlightLabel { get { return m_HighlightLabel; } set { m_HighlightLabel = value; } }
|
||||
public List<float> yData { get { return m_YData; } }
|
||||
public List<float> xData { get { return m_XData; } }
|
||||
public List<SerieData> data { get { return m_Data; } }
|
||||
|
||||
/// <summary>
|
||||
/// The index of serie,start at 0.
|
||||
/// 系列的索引,从0开始。
|
||||
/// </summary>
|
||||
public int index { get; set; }
|
||||
/// <summary>
|
||||
/// Whether the serie is highlighted.
|
||||
/// 该系列是否高亮,一般由图例悬停触发。
|
||||
/// </summary>
|
||||
public bool highlighted { get; set; }
|
||||
public int dataCount { get { return m_Data.Count; } }
|
||||
public int filterStart { get; set; }
|
||||
public int filterEnd { get; set; }
|
||||
|
||||
private List<float> yFilterData { get; set; }
|
||||
private List<float> xFilterData { get; set; }
|
||||
private List<SerieData> filterData { get; set; }
|
||||
|
||||
public float yMax
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = int.MinValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[1] > max)
|
||||
{
|
||||
max = sdata.data[1];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
public float xMax
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = int.MinValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[0] > max)
|
||||
{
|
||||
max = sdata.data[0];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
public float yMin
|
||||
{
|
||||
get
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[1] < min)
|
||||
{
|
||||
min = sdata.data[1];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
}
|
||||
|
||||
public float xMin
|
||||
{
|
||||
get
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[0] < min)
|
||||
{
|
||||
min = sdata.data[0];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
}
|
||||
|
||||
public float yTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show)
|
||||
total += sdata.data[1];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public float xTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show)
|
||||
total += sdata.data[0];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_XData.Clear();
|
||||
m_YData.Clear();
|
||||
m_Data.Clear();
|
||||
}
|
||||
|
||||
public void RemoveData(int index)
|
||||
{
|
||||
m_XData.RemoveAt(index);
|
||||
m_YData.RemoveAt(index);
|
||||
m_Data.RemoveAt(index);
|
||||
}
|
||||
|
||||
public void AddYData(float value, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_XData.Count > maxDataNumber) m_XData.RemoveAt(0);
|
||||
while (m_YData.Count > maxDataNumber) m_YData.RemoveAt(0);
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
}
|
||||
int xValue = m_XData.Count;
|
||||
m_XData.Add(xValue);
|
||||
m_YData.Add(value);
|
||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, value }, name = dataName });
|
||||
}
|
||||
|
||||
public void AddXYData(float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_XData.Count > maxDataNumber) m_XData.RemoveAt(0);
|
||||
while (m_YData.Count > maxDataNumber) m_YData.RemoveAt(0);
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
}
|
||||
m_XData.Add(xValue);
|
||||
m_YData.Add(yValue);
|
||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
|
||||
}
|
||||
|
||||
public void AddData(List<float> valueList, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
if (valueList == null || valueList.Count == 0) return;
|
||||
if (valueList.Count == 1)
|
||||
{
|
||||
AddYData(valueList[0], dataName, maxDataNumber);
|
||||
}
|
||||
else if (valueList.Count == 2)
|
||||
{
|
||||
AddXYData(valueList[0], valueList[1], dataName, maxDataNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_XData.Count > maxDataNumber) m_XData.RemoveAt(0);
|
||||
while (m_YData.Count > maxDataNumber) m_YData.RemoveAt(0);
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
}
|
||||
var serieData = new SerieData();
|
||||
serieData.name = dataName;
|
||||
for (int i = 0; i < valueList.Count; i++)
|
||||
{
|
||||
if (i == 0) m_XData.Add(valueList[i]);
|
||||
else if (i == 1) m_YData.Add(valueList[i]);
|
||||
serieData.data.Add(valueList[0]);
|
||||
}
|
||||
m_Data.Add(serieData);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetYData(int index, DataZoom dataZoom = null)
|
||||
{
|
||||
if (index < 0) return 0;
|
||||
var serieData = GetDataList(dataZoom);
|
||||
if (index < serieData.Count)
|
||||
{
|
||||
return serieData[index].data[1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void GetYData(int index, out float yData, out string dataName, DataZoom dataZoom = null)
|
||||
{
|
||||
yData = 0;
|
||||
dataName = null;
|
||||
if (index < 0) return;
|
||||
var serieData = GetDataList(dataZoom);
|
||||
if (index < serieData.Count)
|
||||
{
|
||||
yData = serieData[index].data[1];
|
||||
dataName = serieData[index].name;
|
||||
}
|
||||
}
|
||||
|
||||
public SerieData GetSerieData(int index, DataZoom dataZoom = null)
|
||||
{
|
||||
var data = GetDataList(dataZoom);
|
||||
if (index >= 0 && index <= data.Count - 1)
|
||||
{
|
||||
return data[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void GetXYData(int index, DataZoom dataZoom, out float xValue, out float yVlaue)
|
||||
{
|
||||
xValue = 0;
|
||||
yVlaue = 0;
|
||||
if (index < 0) return;
|
||||
var showData = GetDataList(dataZoom);
|
||||
if (index < showData.Count)
|
||||
{
|
||||
var serieData = showData[index];
|
||||
xValue = serieData.data[0];
|
||||
yVlaue = serieData.data[1];
|
||||
}
|
||||
}
|
||||
|
||||
public List<float> GetYDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((yData.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((yData.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (yFilterData == null || yFilterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return yFilterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_YData;
|
||||
}
|
||||
}
|
||||
|
||||
public List<float> GetXDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((xData.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((xData.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (xFilterData == null || xFilterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return xFilterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_XData;
|
||||
}
|
||||
}
|
||||
|
||||
public List<SerieData> GetDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((m_Data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((m_Data.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (filterData == null || filterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return filterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFilterData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((yData.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((yData.Count - 1) * dataZoom.end / 100);
|
||||
if (startIndex != filterStart || endIndex != filterEnd)
|
||||
{
|
||||
filterStart = startIndex;
|
||||
filterEnd = endIndex;
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (m_YData.Count > 0)
|
||||
{
|
||||
yFilterData = m_YData.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
yFilterData = m_YData;
|
||||
}
|
||||
if (m_XData.Count > 0)
|
||||
{
|
||||
xFilterData = m_XData.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
xFilterData = m_XData;
|
||||
}
|
||||
if (m_Data.Count > 0)
|
||||
{
|
||||
filterData = m_Data.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
filterData = m_Data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
yFilterData = new List<float>();
|
||||
xFilterData = new List<float>();
|
||||
filterData = new List<SerieData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateYData(int index, float value)
|
||||
{
|
||||
UpdateData(index, 2, value);
|
||||
}
|
||||
|
||||
public void UpdateXYData(int index, float xValue, float yValue)
|
||||
{
|
||||
UpdateData(index, 1, xValue);
|
||||
UpdateData(index, 2, yValue);
|
||||
}
|
||||
|
||||
public void UpdateData(int index, int dimension, float value)
|
||||
{
|
||||
if (index < 0) return;
|
||||
if (dimension == 1)
|
||||
{
|
||||
if (index < m_XData.Count) m_XData[index] = value;
|
||||
}
|
||||
else if (dimension == 2)
|
||||
{
|
||||
if (index < m_YData.Count) m_YData[index] = value;
|
||||
}
|
||||
if (index < m_Data.Count && dimension < m_Data[index].data.Count)
|
||||
{
|
||||
m_Data[index].data[dimension] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearHighlight()
|
||||
{
|
||||
highlighted = false;
|
||||
foreach (var sd in m_Data)
|
||||
{
|
||||
sd.highlighted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHighlight(int index)
|
||||
{
|
||||
if (index <= 0) return;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
m_Data[i].highlighted = index == i;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
jsonData = jsonData.Replace("\r\n", "");
|
||||
jsonData = jsonData.Replace(" ", "");
|
||||
jsonData = jsonData.Replace("\n", "");
|
||||
int startIndex = jsonData.IndexOf("[");
|
||||
int endIndex = jsonData.LastIndexOf("]");
|
||||
if (startIndex == -1 || endIndex == -1)
|
||||
{
|
||||
Debug.LogError("json data need include in [ ]");
|
||||
return;
|
||||
}
|
||||
ClearData();
|
||||
string temp = jsonData.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||
if (temp.IndexOf("],") > -1 || temp.IndexOf("] ,") > -1)
|
||||
{
|
||||
string[] datas = temp.Split(new string[] { "],", "] ," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
var data = datas[i].Split(new char[] { '[', ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var serieData = new SerieData();
|
||||
for (int j = 0; j < data.Length; j++)
|
||||
{
|
||||
var txt = data[j].Trim().Replace("]", "");
|
||||
float value;
|
||||
var flag = float.TryParse(txt, out value);
|
||||
if (flag)
|
||||
{
|
||||
serieData.data.Add(value);
|
||||
if (j == 0) m_XData.Add(value);
|
||||
else if (j == 1) m_YData.Add(value);
|
||||
}
|
||||
else serieData.name = txt.Replace("\"", "").Trim();
|
||||
}
|
||||
m_Data.Add(serieData);
|
||||
}
|
||||
}
|
||||
else if (temp.IndexOf("value") > -1 && temp.IndexOf("name") > -1)
|
||||
{
|
||||
string[] datas = temp.Split(new string[] { "},", "} ,", "}" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
var arr = datas[i].Replace("{", "").Split(',');
|
||||
var serieData = new SerieData();
|
||||
foreach (var a in arr)
|
||||
{
|
||||
if (a.StartsWith("value:"))
|
||||
{
|
||||
float value = float.Parse(a.Substring(6, a.Length - 6));
|
||||
serieData.data = new List<float>() { i, value };
|
||||
}
|
||||
else if (a.StartsWith("name:"))
|
||||
{
|
||||
string name = a.Substring(6, a.Length - 6 - 1);
|
||||
serieData.name = name;
|
||||
}
|
||||
else if (a.StartsWith("selected:"))
|
||||
{
|
||||
string selected = a.Substring(9, a.Length - 9);
|
||||
serieData.selected = bool.Parse(selected);
|
||||
}
|
||||
}
|
||||
m_Data.Add(serieData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] datas = temp.Split(',');
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
float value;
|
||||
var flag = float.TryParse(datas[i].Trim(), out value);
|
||||
if (flag)
|
||||
{
|
||||
var serieData = new SerieData();
|
||||
serieData.data = new List<float>() { i, value };
|
||||
m_Data.Add(serieData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bde61eb0785bad4d91d84d5511514ba
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,10 +4,11 @@ using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
/// <summary>
|
||||
/// A data item of serie.系列中的一个数据项。
|
||||
/// A data item of serie.
|
||||
/// 系列中的一个数据项。可存储数据名和1-n维的数据。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class SerieData
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
@@ -17,30 +18,34 @@ namespace XCharts
|
||||
private bool m_Show = true;
|
||||
|
||||
/// <summary>
|
||||
/// the name of data item.数据项名称。
|
||||
/// the name of data item.
|
||||
/// 数据项名称。
|
||||
/// </summary>
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
/// <summary>
|
||||
/// Whether the data item is selected.该数据项是否被选中。
|
||||
/// Whether the data item is selected.
|
||||
/// 该数据项是否被选中。
|
||||
/// </summary>
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
/// <summary>
|
||||
/// An arbitrary dimension data list of data item.可指定任意维数的数值列表。
|
||||
/// An arbitrary dimension data list of data item.
|
||||
/// 可指定任意维数的数值列表。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public List<float> data { get { return m_Data; } set { m_Data = value; } }
|
||||
/// <summary>
|
||||
/// Whether the data item is showed.该数据项是否要显示。
|
||||
/// [default:true] Whether the data item is showed.
|
||||
/// 该数据项是否要显示。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// Whether the data item is highlighted.该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||
/// Whether the data item is highlighted.
|
||||
/// 该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||
/// </summary>
|
||||
public bool highlighted { get; set; }
|
||||
/// <summary>
|
||||
/// the label of data item.该数据项的文本标签。
|
||||
/// the label of data item.
|
||||
/// 该数据项的文本标签。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Text label { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
/// <summary>
|
||||
/// Text label of chart, to explain some data information about graphic item like value, name and so on.
|
||||
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class SerieLabel
|
||||
{
|
||||
/// <summary>
|
||||
/// The position of label.标签的位置。
|
||||
/// The position of label.
|
||||
/// 标签的位置。
|
||||
/// </summary>
|
||||
public enum Position
|
||||
{
|
||||
@@ -20,15 +21,34 @@ namespace XCharts
|
||||
/// </summary>
|
||||
Outside,
|
||||
/// <summary>
|
||||
/// Inside the sectors of pie chart.饼图扇区内部。
|
||||
/// Inside the sectors of pie chart.
|
||||
/// 饼图扇区内部。
|
||||
/// </summary>
|
||||
Inside,
|
||||
/// <summary>
|
||||
/// In the center of pie chart.在饼图中心位置。
|
||||
/// In the center of pie chart.
|
||||
/// 在饼图中心位置。
|
||||
/// </summary>
|
||||
Center,
|
||||
/// <summary>
|
||||
/// top of symbol.
|
||||
/// 图形标志的顶部。
|
||||
/// </summary>
|
||||
Top,
|
||||
/// <summary>
|
||||
/// the left of symbol.
|
||||
/// 图形标志的左边。
|
||||
/// </summary>
|
||||
Left,
|
||||
/// <summary>
|
||||
/// the right of symbol.
|
||||
/// 图形标志的右边。
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// the bottom of symbol.
|
||||
/// 图形标志的底部。
|
||||
/// </summary>
|
||||
Bottom,
|
||||
}
|
||||
[SerializeField] private bool m_Show = false;
|
||||
@@ -43,11 +63,13 @@ namespace XCharts
|
||||
[SerializeField] private float m_LineLength1 = 25f;
|
||||
[SerializeField] private float m_LineLength2 = 15f;
|
||||
/// <summary>
|
||||
/// Whether the label is showed.是否显示文本标签。
|
||||
/// Whether the label is showed.
|
||||
/// 是否显示文本标签。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// The position of label.标签的位置。
|
||||
/// The position of label.
|
||||
/// 标签的位置。
|
||||
/// </summary>
|
||||
public Position position { get { return m_Position; } set { m_Position = value; } }
|
||||
/// <summary>
|
||||
@@ -61,20 +83,39 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// Rotate label.标签旋转。
|
||||
/// Rotate label.
|
||||
/// 标签旋转。
|
||||
/// </summary>
|
||||
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||
/// <summary>
|
||||
/// font size.文字的字体大小。
|
||||
/// font size.
|
||||
/// 文字的字体大小。
|
||||
/// </summary>
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
/// <summary>
|
||||
/// font style.文字的字体风格。
|
||||
/// font style.
|
||||
/// 文字的字体风格。
|
||||
/// </summary>
|
||||
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show visual guide line.Will show when label position is set as 'outside'.
|
||||
/// 是否显示视觉引导线。在 label 位置 设置为'outside'的时候会显示视觉引导线。
|
||||
/// </summary>
|
||||
public bool line { get { return m_Line; } set { m_Line = value; } }
|
||||
/// <summary>
|
||||
/// the width of visual guild line.
|
||||
/// 视觉引导线的宽度。
|
||||
/// </summary>
|
||||
public float lineWidth { get { return m_LineWidth; } set { m_LineWidth = value; } }
|
||||
/// <summary>
|
||||
/// The length of the first segment of visual guide line.
|
||||
/// 视觉引导线第一段的长度。
|
||||
/// </summary>
|
||||
public float lineLength1 { get { return m_LineLength1; } set { m_LineLength1 = value; } }
|
||||
/// <summary>
|
||||
/// The length of the second segment of visual guide line.
|
||||
/// 视觉引导线第二段的长度。
|
||||
/// </summary>
|
||||
public float lineLength2 { get { return m_LineLength2; } set { m_LineLength2 = value; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,40 +3,71 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the type of symbol.
|
||||
/// 标记图形的类型。
|
||||
/// </summary>
|
||||
public enum SerieSymbolType
|
||||
{
|
||||
/// <summary>
|
||||
/// 空心圆。
|
||||
/// </summary>
|
||||
EmptyCircle,
|
||||
/// <summary>
|
||||
/// 圆形。
|
||||
/// </summary>
|
||||
Circle,
|
||||
/// <summary>
|
||||
/// 正方形。
|
||||
/// </summary>
|
||||
Rect,
|
||||
/// <summary>
|
||||
/// 三角形。
|
||||
/// </summary>
|
||||
Triangle,
|
||||
/// <summary>
|
||||
/// 菱形。
|
||||
/// </summary>
|
||||
Diamond,
|
||||
/// <summary>
|
||||
/// 不显示标记。
|
||||
/// </summary>
|
||||
None,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The way to get serie symbol size.
|
||||
/// <para> `Custom`:Specify constant for symbol size. </para>
|
||||
/// <para> `FromData`:Specify the dataIndex and dataScale to calculate symbol size,the formula:data[dataIndex]*dataScale. </para>
|
||||
/// <para> `Callback`:Specify callback function for symbol size. </para>
|
||||
/// 获取标记图形大小的方式。
|
||||
/// </summary>
|
||||
public enum SerieSymbolSizeType
|
||||
{
|
||||
/// <summary>
|
||||
/// Specify constant for symbol size.
|
||||
/// 自定义大小。
|
||||
/// </summary>
|
||||
Custom,
|
||||
/// <summary>
|
||||
/// Specify the dataIndex and dataScale to calculate symbol size
|
||||
/// Specify the dataIndex and dataScale to calculate symbol size.
|
||||
/// 通过 dataIndex 从数据中获取,再乘以一个比例系数 dataScale 。
|
||||
/// </summary>
|
||||
FromData,
|
||||
/// <summary>
|
||||
/// Specify callback function for symbol size
|
||||
/// Specify callback function for symbol size.
|
||||
/// 通过回调函数获取。
|
||||
/// </summary>
|
||||
Callback,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取标记大小的回调。
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public delegate float SymbolSizeCallback(List<float> data);
|
||||
|
||||
/// <summary>
|
||||
/// 系列数据项的标记的图形
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class SerieSymbol
|
||||
{
|
||||
@@ -50,19 +81,74 @@ namespace XCharts
|
||||
[SerializeField] private SymbolSizeCallback m_SizeCallback;
|
||||
[SerializeField] private SymbolSizeCallback m_SelectedSizeCallback;
|
||||
|
||||
/// <summary>
|
||||
/// the type of symbol.
|
||||
/// 标记类型。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SerieSymbolType type { get { return m_Type; } set { m_Type = value; } }
|
||||
/// <summary>
|
||||
/// the type of symbol size.
|
||||
/// 标记图形的大小获取方式。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SerieSymbolSizeType sizeType { get { return m_SizeType; } set { m_SizeType = value; } }
|
||||
/// <summary>
|
||||
/// the size of symbol.
|
||||
/// 标记的大小。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float size { get { return m_Size; } set { m_Size = value; } }
|
||||
/// <summary>
|
||||
/// the size of selected symbol.
|
||||
/// 被选中的标记的大小。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float selectedSize { get { return m_SelectedSize; } set { m_SelectedSize = value; } }
|
||||
/// <summary>
|
||||
/// whitch data index is when the sizeType assined as FromData.
|
||||
/// 当sizeType指定为FromData时,指定的数据源索引。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int dataIndex { get { return m_DataIndex; } set { m_DataIndex = value; } }
|
||||
/// <summary>
|
||||
/// the scale of data when sizeType assined as FromData.
|
||||
/// 当sizeType指定为FromData时,指定的倍数系数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float dataScale { get { return m_DataScale; } set { m_DataScale = value; } }
|
||||
/// <summary>
|
||||
/// the scale of selected data when sizeType assined as FromData.
|
||||
/// 当sizeType指定为FromData时,指定的高亮倍数系数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float selectedDataScale { get { return m_SelectedDataScale; } set { m_SelectedDataScale = value; } }
|
||||
/// <summary>
|
||||
/// the callback of size when sizeType assined as Callback.
|
||||
/// 当sizeType指定为Callback时,指定的回调函数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } }
|
||||
/// <summary>
|
||||
/// the callback of size when sizeType assined as Callback.
|
||||
/// 当sizeType指定为Callback时,指定的高亮回调函数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } }
|
||||
|
||||
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
|
||||
/// <summary>
|
||||
/// the setting for effect scatter.
|
||||
/// 带有涟漪特效动画的散点图的动画参数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public List<float> animationSize { get { return m_AnimationSize; } }
|
||||
public Color animationColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定的sizeType获得标记的大小
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public float GetSize(List<float> data)
|
||||
{
|
||||
if (data == null) return size;
|
||||
@@ -86,6 +172,11 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据sizeType获得高亮时的标记大小
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public float GetSelectedSize(List<float> data)
|
||||
{
|
||||
if (data == null) return selectedSize;
|
||||
|
||||
@@ -1,564 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Series : JsonDataSupport
|
||||
{
|
||||
[SerializeField] protected List<Serie> m_Series;
|
||||
|
||||
public List<Serie> series { get { return m_Series; } }
|
||||
|
||||
public int Count { get { return m_Series.Count; } }
|
||||
|
||||
public static Series defaultSeries
|
||||
{
|
||||
get
|
||||
{
|
||||
var series = new Series
|
||||
{
|
||||
m_Series = new List<Serie>(){new Serie(){
|
||||
show = true,
|
||||
name = "serie1",
|
||||
index = 0
|
||||
}}
|
||||
};
|
||||
return series;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
serie.ClearData();
|
||||
}
|
||||
}
|
||||
|
||||
public float GetData(int serieIndex, int dataIndex)
|
||||
{
|
||||
if (serieIndex >= 0 && serieIndex < Count)
|
||||
{
|
||||
return m_Series[serieIndex].GetYData(dataIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Serie GetSerie(string name)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (name.Equals(m_Series[i].name))
|
||||
{
|
||||
m_Series[i].index = i;
|
||||
return m_Series[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Serie> GetSeries(string name)
|
||||
{
|
||||
var list = new List<Serie>();
|
||||
if (name == null) return list;
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (name.Equals(serie.name)) list.Add(serie);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public Serie GetSerie(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_Series.Count)
|
||||
{
|
||||
return m_Series[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Contains(string name)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (name.Equals(m_Series[i].name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove serie from series.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
public void Remove(string serieName)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
m_Series.Remove(serie);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all serie from series.
|
||||
/// </summary>
|
||||
public void RemoveAll()
|
||||
{
|
||||
m_Series.Clear();
|
||||
}
|
||||
|
||||
public Serie AddSerie(string serieName, SerieType type, bool show = true)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie == null)
|
||||
{
|
||||
serie = new Serie();
|
||||
serie.type = type;
|
||||
serie.show = show;
|
||||
serie.name = serieName;
|
||||
serie.index = m_Series.Count;
|
||||
|
||||
if (type == SerieType.Scatter)
|
||||
{
|
||||
serie.symbol.type = SerieSymbolType.Circle;
|
||||
serie.symbol.size = 20f;
|
||||
serie.symbol.selectedSize = 30f;
|
||||
}
|
||||
else if (type == SerieType.Line)
|
||||
{
|
||||
serie.symbol.type = SerieSymbolType.EmptyCircle;
|
||||
serie.symbol.size = 2.5f;
|
||||
serie.symbol.selectedSize = 5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.symbol.type = SerieSymbolType.None;
|
||||
}
|
||||
m_Series.Add(serie);
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.show = show;
|
||||
}
|
||||
return serie;
|
||||
}
|
||||
|
||||
public bool AddData(string serieName, float value, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddYData(value, dataName, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AddData(int index, float value, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddYData(value, dataName, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AddData(string serieName, List<float> multidimensionalData, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddData(multidimensionalData, dataName, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AddData(int serieIndex, List<float> multidimensionalData, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddData(multidimensionalData, dataName, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AddXYData(string serieName, float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddXYData(xValue, yValue, dataName, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AddXYData(int index, float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddXYData(xValue, yValue, dataName, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateData(string name, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateYData(dataIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateXYData(string name, float xValue, float yValue, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateXYData(dataIndex, xValue, yValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(int index, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateYData(dataIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateXYData(int index, float xValue, float yValue, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateXYData(dataIndex, xValue, yValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFilterData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
m_Series[i].UpdateFilterData(dataZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsActive(string name)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
return serie == null ? false : serie.show;
|
||||
}
|
||||
|
||||
public bool IsActive(int index)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
return serie == null ? false : serie.show;
|
||||
}
|
||||
|
||||
public void SetActive(string name, bool active)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.show = active;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(int index, bool active)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.show = active;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsUsedAxisIndex(int axisIndex)
|
||||
{
|
||||
foreach (var serie in series)
|
||||
{
|
||||
if (serie.axisIndex == axisIndex) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsTooltipSelected(int serieIndex)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null) return serie.highlighted;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, false, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
public void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, true, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
private Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool yValue, out int minVaule, out int maxValue)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
if (IsStack())
|
||||
{
|
||||
GetStackSeries(ref _stackSeriesForMinMax);
|
||||
foreach (var ss in _stackSeriesForMinMax)
|
||||
{
|
||||
_serieTotalValueForMinMax.Clear();
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex) continue;
|
||||
var showData = yValue ? serie.GetYDataList(dataZoom) : serie.GetXDataList(dataZoom);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + showData[j];
|
||||
}
|
||||
}
|
||||
float tmax = int.MinValue;
|
||||
float tmin = int.MaxValue;
|
||||
foreach (var tt in _serieTotalValueForMinMax)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
if (tt.Value < tmin) tmin = tt.Value;
|
||||
}
|
||||
if (tmax > max) max = tmax;
|
||||
if (tmin < min) min = tmin;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series[i].axisIndex != axisIndex) continue;
|
||||
if (IsActive(i))
|
||||
{
|
||||
var showData = yValue ? m_Series[i].GetYDataList(dataZoom) : m_Series[i].GetXDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
if (data > max) max = data;
|
||||
if (data < min) min = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (max == int.MinValue && min == int.MaxValue)
|
||||
{
|
||||
minVaule = 0;
|
||||
maxValue = 90;
|
||||
}
|
||||
else
|
||||
{
|
||||
minVaule = Mathf.FloorToInt(min);
|
||||
maxValue = Mathf.CeilToInt(max);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetMaxValue(int index)
|
||||
{
|
||||
float max = int.MinValue;
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var showData = m_Series[i].yData;
|
||||
if (showData[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
if (showData[index] < min)
|
||||
{
|
||||
min = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
}
|
||||
if (max < 1 && max > -1) return max;
|
||||
if (max < 0 && min < 0) max = min;
|
||||
return ChartHelper.GetMaxDivisibleValue(max);
|
||||
}
|
||||
|
||||
public float GetMinValue(int index)
|
||||
{
|
||||
float max = int.MinValue;
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var showData = m_Series[i].yData;
|
||||
if (showData[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
if (showData[index] < min)
|
||||
{
|
||||
min = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
}
|
||||
if (min < 1 && min > -1) return min;
|
||||
if (min < 0 && max < 0) min = max;
|
||||
return ChartHelper.GetMinDivisibleValue(min);
|
||||
}
|
||||
|
||||
private HashSet<string> _setForStack = new HashSet<string>();
|
||||
public bool IsStack()
|
||||
{
|
||||
_setForStack.Clear();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack)) continue;
|
||||
if (_setForStack.Contains(serie.stack)) return true;
|
||||
else
|
||||
{
|
||||
_setForStack.Add(serie.stack);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Dictionary<int, List<Serie>> GetStackSeries()
|
||||
{
|
||||
int count = 0;
|
||||
Dictionary<string, int> sets = new Dictionary<string, int>();
|
||||
Dictionary<int, List<Serie>> stackSeries = new Dictionary<int, List<Serie>>();
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series[i];
|
||||
serie.index = i;
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
stackSeries[count] = new List<Serie>();
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sets.ContainsKey(serie.stack))
|
||||
{
|
||||
sets.Add(serie.stack, count);
|
||||
stackSeries[count] = new List<Serie>();
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int stackIndex = sets[serie.stack];
|
||||
stackSeries[stackIndex].Add(serie);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stackSeries;
|
||||
}
|
||||
|
||||
private Dictionary<string, int> sets = new Dictionary<string, int>();
|
||||
public void GetStackSeries(ref Dictionary<int, List<Serie>> stackSeries)
|
||||
{
|
||||
int count = 0;
|
||||
sets.Clear();
|
||||
if (stackSeries == null)
|
||||
{
|
||||
stackSeries = new Dictionary<int, List<Serie>>(m_Series.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var kv in stackSeries)
|
||||
{
|
||||
kv.Value.Clear();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series[i];
|
||||
serie.index = i;
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (!stackSeries.ContainsKey(count))
|
||||
stackSeries[count] = new List<Serie>(m_Series.Count);
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sets.ContainsKey(serie.stack))
|
||||
{
|
||||
sets.Add(serie.stack, count);
|
||||
if (!stackSeries.ContainsKey(count))
|
||||
stackSeries[count] = new List<Serie>(m_Series.Count);
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int stackIndex = sets[serie.stack];
|
||||
stackSeries[stackIndex].Add(serie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> serieNameList = new List<string>();
|
||||
public List<string> GetSerieNameList()
|
||||
{
|
||||
serieNameList.Clear();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (serie.type == SerieType.Pie)
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(data.name) && !serieNameList.Contains(data.name))
|
||||
{
|
||||
serieNameList.Add(data.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.name) && !serieNameList.Contains(serie.name))
|
||||
{
|
||||
serieNameList.Add(serie.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return serieNameList;
|
||||
}
|
||||
|
||||
public void SetSerieSymbolSizeCallback(SymbolSizeCallback size, SymbolSizeCallback selectedSize)
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
serie.symbol.sizeCallback = size;
|
||||
serie.symbol.selectedSizeCallback = selectedSize;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
//TODO:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 137f78d348f866943a9fb8c1c8eaceef
|
||||
timeCreated: 1556016849
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,468 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public enum Theme
|
||||
{
|
||||
Default,
|
||||
Light,
|
||||
Dark
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ThemeInfo : IEquatable<ThemeInfo>
|
||||
{
|
||||
[SerializeField] private Theme m_Theme = Theme.Default;
|
||||
[SerializeField] private Font m_Font;
|
||||
[SerializeField] private Color32 m_BackgroundColor;
|
||||
[SerializeField] private Color32 m_TextColor;
|
||||
[SerializeField] private Color32 m_TitleSubTextColor;
|
||||
[SerializeField] private Color32 m_LegendTextColor;
|
||||
[SerializeField] private Color32 m_LegendUnableColor;
|
||||
[SerializeField] private Color32 m_AxisTextColor;
|
||||
[SerializeField] private Color32 m_AxisLineColor;
|
||||
[SerializeField] private Color32 m_AxisSplitLineColor;
|
||||
[SerializeField] private Color32 m_TooltipBackgroundColor;
|
||||
[SerializeField] private Color32 m_TooltipFlagAreaColor;
|
||||
[SerializeField] private Color32 m_TooltipTextColor;
|
||||
[SerializeField] private Color32 m_TooltipLabelColor;
|
||||
[SerializeField] private Color32 m_TooltipLineColor;
|
||||
[SerializeField] private Color32 m_DataZoomTextColor;
|
||||
[SerializeField] private Color32 m_DataZoomLineColor;
|
||||
[SerializeField] private Color32 m_DataZoomSelectedColor;
|
||||
[SerializeField] private Color32[] m_ColorPalette;
|
||||
|
||||
[SerializeField] private Font m_CustomFont;
|
||||
[SerializeField] private Color32 m_CustomBackgroundColor;
|
||||
[SerializeField] private Color32 m_CustomTextColor;
|
||||
[SerializeField] private Color32 m_CustomTitleSubTextColor;
|
||||
[SerializeField] private Color32 m_CustomLegendTextColor;
|
||||
[SerializeField] private Color32 m_CustomLegendUnableColor;
|
||||
[SerializeField] private Color32 m_CustomAxisTextColor;
|
||||
[SerializeField] private Color32 m_CustomAxisLineColor;
|
||||
[SerializeField] private Color32 m_CustomAxisSplitLineColor;
|
||||
[SerializeField] private Color32 m_CustomTooltipBackgroundColor;
|
||||
[SerializeField] private Color32 m_CustomTooltipFlagAreaColor;
|
||||
[SerializeField] private Color32 m_CustomTooltipTextColor;
|
||||
[SerializeField] private Color32 m_CustomTooltipLabelColor;
|
||||
[SerializeField] private Color32 m_CustomTooltipLineColor;
|
||||
[SerializeField] private Color32 m_CustomDataZoomTextColor;
|
||||
[SerializeField] private Color32 m_CustomDataZoomLineColor;
|
||||
[SerializeField] private Color32 m_CustomDataZoomSelectedColor;
|
||||
[SerializeField] private List<Color32> m_CustomColorPalette = new List<Color32>(13);
|
||||
|
||||
public Theme theme { get { return m_Theme; } set { m_Theme = value; } }
|
||||
public Font font
|
||||
{
|
||||
get { return m_CustomFont != null ? m_CustomFont : m_Font; }
|
||||
set { m_CustomFont = value; }
|
||||
}
|
||||
public Color32 backgroundColor
|
||||
{
|
||||
get { return m_CustomBackgroundColor != Color.clear ? m_CustomBackgroundColor : m_BackgroundColor; }
|
||||
set { m_CustomBackgroundColor = value; }
|
||||
}
|
||||
public Color32 textColor
|
||||
{
|
||||
get { return m_CustomTextColor != Color.clear ? m_CustomTextColor : m_TextColor; }
|
||||
set { m_CustomTextColor = value; }
|
||||
}
|
||||
public Color32 titleSubTextColor
|
||||
{
|
||||
get { return m_CustomTitleSubTextColor != Color.clear ? m_CustomTitleSubTextColor : m_TitleSubTextColor; }
|
||||
set { m_CustomTitleSubTextColor = value; }
|
||||
}
|
||||
public Color32 legendTextColor
|
||||
{
|
||||
get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; }
|
||||
set { m_CustomLegendTextColor = value; }
|
||||
}
|
||||
public Color32 legendUnableColor
|
||||
{
|
||||
get { return m_CustomLegendUnableColor != Color.clear ? m_CustomLegendUnableColor : m_LegendUnableColor; }
|
||||
set { m_CustomLegendUnableColor = value; }
|
||||
}
|
||||
public Color32 axisTextColor
|
||||
{
|
||||
get { return m_CustomAxisTextColor != Color.clear ? m_CustomAxisTextColor : m_AxisTextColor; }
|
||||
set { m_CustomAxisTextColor = value; }
|
||||
}
|
||||
public Color32 axisLineColor
|
||||
{
|
||||
get { return m_CustomAxisLineColor != Color.clear ? m_CustomAxisLineColor : m_AxisLineColor; }
|
||||
set { m_CustomAxisLineColor = value; }
|
||||
}
|
||||
public Color32 axisSplitLineColor
|
||||
{
|
||||
get { return m_CustomAxisSplitLineColor != Color.clear ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; }
|
||||
set { m_CustomAxisSplitLineColor = value; }
|
||||
}
|
||||
public Color32 tooltipBackgroundColor
|
||||
{
|
||||
get { return m_CustomTooltipBackgroundColor != Color.clear ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; }
|
||||
set { m_CustomTooltipBackgroundColor = value; }
|
||||
}
|
||||
public Color32 tooltipFlagAreaColor
|
||||
{
|
||||
get { return m_CustomTooltipFlagAreaColor != Color.clear ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; }
|
||||
set { m_CustomTooltipFlagAreaColor = value; }
|
||||
}
|
||||
public Color32 tooltipTextColor
|
||||
{
|
||||
get { return m_CustomTooltipTextColor != Color.clear ? m_CustomTooltipTextColor : m_TooltipTextColor; }
|
||||
set { m_CustomTooltipTextColor = value; }
|
||||
}
|
||||
public Color32 tooltipLabelColor
|
||||
{
|
||||
get { return m_CustomTooltipLabelColor != Color.clear ? m_CustomTooltipLabelColor : m_TooltipLabelColor; }
|
||||
set { m_CustomTooltipLabelColor = value; }
|
||||
}
|
||||
public Color32 tooltipLineColor
|
||||
{
|
||||
get { return m_CustomTooltipLineColor != Color.clear ? m_CustomTooltipLineColor : m_TooltipLineColor; }
|
||||
set { m_CustomTooltipLineColor = value; }
|
||||
}
|
||||
public Color32 dataZoomTextColor
|
||||
{
|
||||
get { return m_CustomDataZoomTextColor != Color.clear ? m_CustomDataZoomTextColor : m_DataZoomTextColor; }
|
||||
set { m_CustomDataZoomTextColor = value; }
|
||||
}
|
||||
public Color32 dataZoomLineColor
|
||||
{
|
||||
get { return m_CustomDataZoomLineColor != Color.clear ? m_CustomDataZoomLineColor : m_DataZoomLineColor; }
|
||||
set { m_CustomDataZoomLineColor = value; }
|
||||
}
|
||||
public Color32 dataZoomSelectedColor
|
||||
{
|
||||
get { return m_CustomDataZoomSelectedColor != Color.clear ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; }
|
||||
set { m_CustomDataZoomSelectedColor = value; }
|
||||
}
|
||||
public List<Color32> colorPalette { set { m_CustomColorPalette = value; } }
|
||||
|
||||
public Color32 GetColor(int index)
|
||||
{
|
||||
if (index < 0) index = 0;
|
||||
var customIndex = index >= m_CustomColorPalette.Count ? index : index % m_CustomColorPalette.Count;
|
||||
if (customIndex < m_CustomColorPalette.Count && m_CustomColorPalette[customIndex] != Color.clear)
|
||||
{
|
||||
return m_CustomColorPalette[customIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
var newIndex = index >= m_ColorPalette.Length ? index : index % m_ColorPalette.Length;
|
||||
if (newIndex < m_ColorPalette.Length)
|
||||
return m_ColorPalette[newIndex];
|
||||
else return Color.clear;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<int, string> _colorDic = new Dictionary<int, string>();
|
||||
public string GetColorStr(int index)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
index = index % m_ColorPalette.Length;
|
||||
if (_colorDic.ContainsKey(index)) return _colorDic[index];
|
||||
else
|
||||
{
|
||||
_colorDic[index] = ColorUtility.ToHtmlStringRGBA(GetColor(index));
|
||||
return _colorDic[index];
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(ThemeInfo theme)
|
||||
{
|
||||
m_Theme = theme.theme;
|
||||
m_Font = theme.m_Font;
|
||||
m_BackgroundColor = theme.m_BackgroundColor;
|
||||
m_LegendUnableColor = theme.m_LegendUnableColor;
|
||||
m_TextColor = theme.m_TextColor;
|
||||
m_TitleSubTextColor = theme.m_TitleSubTextColor;
|
||||
m_LegendTextColor = theme.m_LegendTextColor;
|
||||
m_AxisTextColor = theme.m_AxisTextColor;
|
||||
m_AxisLineColor = theme.m_AxisLineColor;
|
||||
m_AxisSplitLineColor = theme.m_AxisSplitLineColor;
|
||||
m_TooltipBackgroundColor = theme.m_TooltipBackgroundColor;
|
||||
m_TooltipTextColor = theme.m_TooltipTextColor;
|
||||
m_TooltipLabelColor = theme.m_TooltipLabelColor;
|
||||
m_TooltipLineColor = theme.m_TooltipLineColor;
|
||||
m_DataZoomLineColor = theme.m_DataZoomLineColor;
|
||||
m_DataZoomSelectedColor = theme.m_DataZoomSelectedColor;
|
||||
m_DataZoomTextColor = theme.m_DataZoomTextColor;
|
||||
m_ColorPalette = new Color32[theme.m_ColorPalette.Length];
|
||||
for (int i = 0; i < theme.m_ColorPalette.Length; i++)
|
||||
{
|
||||
m_ColorPalette[i] = theme.m_ColorPalette[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_Theme = Theme.Default;
|
||||
m_Font = null;
|
||||
m_BackgroundColor = Color.clear;
|
||||
m_LegendUnableColor = Color.clear;
|
||||
m_TextColor = Color.clear;
|
||||
m_TitleSubTextColor = Color.clear;
|
||||
m_LegendTextColor = Color.clear;
|
||||
m_AxisTextColor = Color.clear;
|
||||
m_AxisLineColor = Color.clear;
|
||||
m_AxisSplitLineColor = Color.clear;
|
||||
m_TooltipBackgroundColor = Color.clear;
|
||||
m_TooltipTextColor = Color.clear;
|
||||
m_TooltipLabelColor = Color.clear;
|
||||
m_TooltipLineColor = Color.clear;
|
||||
m_DataZoomLineColor = Color.clear;
|
||||
m_DataZoomSelectedColor = Color.clear;
|
||||
m_DataZoomTextColor = Color.clear;
|
||||
for (int i = 0; i < m_CustomColorPalette.Count; i++)
|
||||
{
|
||||
m_CustomColorPalette[i] = Color.clear;
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
m_Theme = Theme.Default,
|
||||
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
m_BackgroundColor = new Color32(255, 255, 255, 255),
|
||||
m_LegendUnableColor = GetColor("#cccccc"),
|
||||
m_TextColor = GetColor("#514D4D"),
|
||||
m_TitleSubTextColor = GetColor("#514D4D"),
|
||||
m_LegendTextColor = GetColor("#eee"),
|
||||
m_AxisTextColor = GetColor("#514D4D"),
|
||||
m_AxisLineColor = GetColor("#514D4D"),
|
||||
m_AxisSplitLineColor = GetColor("#51515120"),
|
||||
m_TooltipBackgroundColor = GetColor("#515151C8"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_TooltipLabelColor = GetColor("#292929FF"),
|
||||
m_TooltipLineColor = GetColor("#29292964"),
|
||||
m_DataZoomLineColor = GetColor("#51515120"),
|
||||
m_DataZoomSelectedColor = GetColor("#51515120"),
|
||||
m_DataZoomTextColor = GetColor("#514D4D"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(194, 53, 49, 255),
|
||||
new Color32(47, 69, 84, 255),
|
||||
new Color32(97, 160, 168, 255),
|
||||
new Color32(212, 130, 101, 255),
|
||||
new Color32(145, 199, 174, 255),
|
||||
new Color32(116, 159, 131, 255),
|
||||
new Color32(202, 134, 34, 255),
|
||||
new Color32(189, 162, 154, 255),
|
||||
new Color32(110, 112, 116, 255),
|
||||
new Color32(84, 101, 112, 255),
|
||||
new Color32(196, 204, 211, 255)
|
||||
},
|
||||
m_CustomColorPalette = new List<Color32>{
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Light
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
m_Theme = Theme.Light,
|
||||
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
m_BackgroundColor = new Color32(255, 255, 255, 255),
|
||||
m_LegendUnableColor = GetColor("#cccccc"),
|
||||
m_TextColor = GetColor("#514D4D"),
|
||||
m_TitleSubTextColor = GetColor("#514D4D"),
|
||||
m_LegendTextColor = GetColor("#514D4D"),
|
||||
m_AxisTextColor = GetColor("#514D4D"),
|
||||
m_AxisLineColor = GetColor("#514D4D"),
|
||||
m_AxisSplitLineColor = GetColor("#51515120"),
|
||||
m_TooltipBackgroundColor = GetColor("#515151C8"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_TooltipLabelColor = GetColor("#292929FF"),
|
||||
m_TooltipLineColor = GetColor("#29292964"),
|
||||
m_DataZoomLineColor = GetColor("#51515120"),
|
||||
m_DataZoomSelectedColor = GetColor("#51515120"),
|
||||
m_DataZoomTextColor = GetColor("#514D4D"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(55, 162, 218, 255),
|
||||
new Color32(255, 159, 127, 255),
|
||||
new Color32(50, 197, 233, 255),
|
||||
new Color32(251, 114, 147, 255),
|
||||
new Color32(103, 224, 227, 255),
|
||||
new Color32(224, 98, 174, 255),
|
||||
new Color32(159, 230, 184, 255),
|
||||
new Color32(230, 144, 209, 255),
|
||||
new Color32(255, 219, 92, 255),
|
||||
new Color32(230, 188, 243, 255),
|
||||
new Color32(157, 150, 245, 255),
|
||||
new Color32(131, 120, 234, 255),
|
||||
new Color32(150, 191, 255, 255)
|
||||
},
|
||||
m_CustomColorPalette = new List<Color32>{
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Dark
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
m_Theme = Theme.Dark,
|
||||
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
m_LegendUnableColor = GetColor("#cccccc"),
|
||||
m_BackgroundColor = new Color32(34, 34, 34, 255),
|
||||
m_TextColor = GetColor("#eee"),
|
||||
m_TitleSubTextColor = GetColor("#eee"),
|
||||
m_LegendTextColor = GetColor("#eee"),
|
||||
m_AxisTextColor = GetColor("#eee"),
|
||||
m_AxisLineColor = GetColor("#eee"),
|
||||
m_AxisSplitLineColor = GetColor("#aaa"),
|
||||
m_TooltipBackgroundColor = GetColor("#515151C8"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_TooltipLabelColor = GetColor("#A7A7A7FF"),
|
||||
m_TooltipLineColor = GetColor("#eee"),
|
||||
m_DataZoomLineColor = GetColor("#FFFFFF45"),
|
||||
m_DataZoomSelectedColor = GetColor("#D0D0D03D"),
|
||||
m_DataZoomTextColor = GetColor("#FFFFFFFF"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(221, 107, 102, 255),
|
||||
new Color32(117, 154, 160, 255),
|
||||
new Color32(230, 157, 135, 255),
|
||||
new Color32(141, 193, 169, 255),
|
||||
new Color32(234, 126, 83, 255),
|
||||
new Color32(238, 221, 120, 255),
|
||||
new Color32(115, 163, 115, 255),
|
||||
new Color32(115, 185, 188, 255),
|
||||
new Color32(114, 137, 171, 255),
|
||||
new Color32(145, 202, 140, 255),
|
||||
new Color32(244, 159, 66, 255)
|
||||
},
|
||||
m_CustomColorPalette = new List<Color32>{
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear,
|
||||
Color.clear
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Color32 GetColor(string hexColorStr)
|
||||
{
|
||||
Color color;
|
||||
ColorUtility.TryParseHtmlString(hexColorStr, out color);
|
||||
return (Color32)color;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is ThemeInfo)
|
||||
{
|
||||
return Equals((ThemeInfo)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(ThemeInfo other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_Font == other.m_Font &&
|
||||
ChartHelper.IsValueEqualsColor(m_LegendUnableColor, other.m_LegendUnableColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.m_BackgroundColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TextColor, other.m_TextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TitleSubTextColor, other.m_TitleSubTextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisTextColor, other.m_AxisTextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisLineColor, other.m_AxisLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisSplitLineColor, other.m_AxisSplitLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TooltipBackgroundColor, other.m_TooltipBackgroundColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisSplitLineColor, other.m_AxisSplitLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TooltipTextColor, other.m_TooltipTextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TooltipFlagAreaColor, other.m_TooltipFlagAreaColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_DataZoomLineColor, other.m_DataZoomLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_DataZoomSelectedColor, other.m_DataZoomSelectedColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_DataZoomTextColor, other.m_DataZoomTextColor) &&
|
||||
m_ColorPalette.Length == other.m_ColorPalette.Length;
|
||||
}
|
||||
|
||||
public static bool operator ==(ThemeInfo left, ThemeInfo right)
|
||||
{
|
||||
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(ThemeInfo left, ThemeInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 337565e835799d44bb794677abf84498
|
||||
timeCreated: 1554221927
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,112 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[Serializable]
|
||||
public class Title : IPropertyChanged, IEquatable<Title>
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private string m_Text;
|
||||
[SerializeField] private int m_TextFontSize;
|
||||
[SerializeField] private string m_SubText;
|
||||
[SerializeField] private int m_SubTextFontSize;
|
||||
[SerializeField] private float m_ItemGap;
|
||||
[SerializeField] private Location m_Location;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public string text { get { return m_Text; } set { m_Text = value; } }
|
||||
public int textFontSize { get { return m_TextFontSize; } set { m_TextFontSize = value; } }
|
||||
public string subText { get { return m_SubText; } set { m_Text = value; } }
|
||||
public int subTextFontSize { get { return m_SubTextFontSize; } set { m_SubTextFontSize = value; } }
|
||||
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
|
||||
public Location location { get { return m_Location; } set { m_Location = value; } }
|
||||
|
||||
public static Title defaultTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
var title = new Title
|
||||
{
|
||||
m_Show = true,
|
||||
m_Text = "Chart Title",
|
||||
m_TextFontSize = 16,
|
||||
m_SubText = "",
|
||||
m_SubTextFontSize = 14,
|
||||
m_ItemGap = 14,
|
||||
m_Location = Location.defaultTop
|
||||
};
|
||||
return title;
|
||||
}
|
||||
}
|
||||
public void Copy(Title title)
|
||||
{
|
||||
m_Show = title.show;
|
||||
m_Text = title.text;
|
||||
m_TextFontSize = title.textFontSize;
|
||||
m_SubText = title.subText;
|
||||
m_SubTextFontSize = title.subTextFontSize;
|
||||
m_ItemGap = title.itemGap;
|
||||
m_Location.Copy(title.location);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is Title)
|
||||
{
|
||||
return Equals((Title)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Title other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_Show == other.show &&
|
||||
m_Text.Equals(other.text) &&
|
||||
m_TextFontSize == other.textFontSize &&
|
||||
m_SubText.Equals(other.subText) &&
|
||||
m_SubTextFontSize == other.subTextFontSize &&
|
||||
m_ItemGap == other.itemGap &&
|
||||
m_Location.Equals(other.location);
|
||||
}
|
||||
|
||||
public static bool operator ==(Title left, Title right)
|
||||
{
|
||||
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Title left, Title right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
m_Location.OnChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e41a7f82b5a931408f301257fbc09e2
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,192 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Tooltip
|
||||
{
|
||||
/// <summary>
|
||||
/// Type of triggering.
|
||||
/// </summary>
|
||||
public enum Trigger
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggered by axes, which is mainly used for charts that have category axes,
|
||||
/// like bar charts or line charts.
|
||||
/// </summary>
|
||||
Axis,
|
||||
/// <summary>
|
||||
/// Triggered by data item, which is mainly used for charts that don't have a
|
||||
/// category axis like scatter charts or pie charts.
|
||||
/// </summary>
|
||||
Item
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicator type.
|
||||
/// </summary>
|
||||
public enum Type
|
||||
{
|
||||
/// <summary>
|
||||
/// line indicator.
|
||||
/// </summary>
|
||||
Line,
|
||||
/// <summary>
|
||||
/// shadow crosshair indicator.
|
||||
/// </summary>
|
||||
Shadow,
|
||||
/// <summary>
|
||||
/// no indicator displayed.
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
|
||||
/// </summary>
|
||||
Corss
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private Type m_Type;
|
||||
[SerializeField] private Trigger m_Trigger;
|
||||
|
||||
[NonSerialized] private GameObject m_GameObject;
|
||||
[NonSerialized] private GameObject m_Content;
|
||||
[NonSerialized] private Text m_ContentText;
|
||||
[NonSerialized] private RectTransform m_ContentRect;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; SetActive(value); } }
|
||||
public Type type { get { return m_Type; } set { m_Type = value; } }
|
||||
public Trigger trigger { get { return m_Trigger; } set { m_Trigger = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The data index currently indicated by Tooltip.
|
||||
/// </summary>
|
||||
public List<int> dataIndex { get; set; }
|
||||
public List<int> lastDataIndex { get; set; }
|
||||
public float[] xValues { get; set; }
|
||||
public float[] yValues { get; set; }
|
||||
|
||||
public Vector2 pointerPos { get; set; }
|
||||
public float width { get { return m_ContentRect.sizeDelta.x; } }
|
||||
public float height { get { return m_ContentRect.sizeDelta.y; } }
|
||||
public bool isInited { get { return m_GameObject != null; } }
|
||||
public GameObject gameObject { get { return m_GameObject; } }
|
||||
|
||||
public static Tooltip defaultTooltip
|
||||
{
|
||||
get
|
||||
{
|
||||
var tooltip = new Tooltip
|
||||
{
|
||||
m_Show = true,
|
||||
xValues = new float[2],
|
||||
yValues = new float[2],
|
||||
dataIndex = new List<int>() { -1, -1 },
|
||||
lastDataIndex = new List<int>() { -1, -1 }
|
||||
};
|
||||
return tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetObj(GameObject obj)
|
||||
{
|
||||
m_GameObject = obj;
|
||||
m_GameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void SetContentObj(GameObject content)
|
||||
{
|
||||
m_Content = content;
|
||||
m_ContentRect = m_Content.GetComponent<RectTransform>();
|
||||
m_ContentText = m_Content.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void UpdateToTop()
|
||||
{
|
||||
int count = m_GameObject.transform.parent.childCount;
|
||||
m_GameObject.GetComponent<RectTransform>().SetSiblingIndex(count - 1);
|
||||
}
|
||||
|
||||
public void SetContentBackgroundColor(Color color)
|
||||
{
|
||||
m_Content.GetComponent<Image>().color = color;
|
||||
}
|
||||
|
||||
public void SetContentTextColor(Color color)
|
||||
{
|
||||
if (m_ContentText)
|
||||
{
|
||||
m_ContentText.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateContentText(string txt)
|
||||
{
|
||||
if (m_ContentText)
|
||||
{
|
||||
m_ContentText.text = txt;
|
||||
m_ContentRect.sizeDelta = new Vector2(m_ContentText.preferredWidth + 8,
|
||||
m_ContentText.preferredHeight + 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearValue()
|
||||
{
|
||||
dataIndex[0] = dataIndex[1] = -1;
|
||||
xValues[0] = xValues[1] = -1;
|
||||
yValues[0] = yValues[1] = -1;
|
||||
}
|
||||
|
||||
public bool IsActive()
|
||||
{
|
||||
return m_GameObject != null && m_GameObject.activeInHierarchy;
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
lastDataIndex[0] = lastDataIndex[1] = -1;
|
||||
if (m_GameObject && m_GameObject.activeInHierarchy != flag)
|
||||
m_GameObject.SetActive(flag);
|
||||
}
|
||||
|
||||
public void UpdateContentPos(Vector2 pos)
|
||||
{
|
||||
if (m_Content)
|
||||
m_Content.transform.localPosition = pos;
|
||||
}
|
||||
|
||||
public Vector3 GetContentPos()
|
||||
{
|
||||
if (m_Content)
|
||||
return m_Content.transform.localPosition;
|
||||
else
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
public bool IsDataIndexChanged()
|
||||
{
|
||||
return dataIndex[0] != lastDataIndex[0] ||
|
||||
dataIndex[1] != lastDataIndex[1];
|
||||
}
|
||||
|
||||
public void UpdateLastDataIndex()
|
||||
{
|
||||
lastDataIndex[0] = dataIndex[0];
|
||||
lastDataIndex[1] = dataIndex[1];
|
||||
}
|
||||
|
||||
public bool IsSelected()
|
||||
{
|
||||
return dataIndex[0] >= 0 || dataIndex[1] >= 0;
|
||||
}
|
||||
|
||||
public bool IsSelectedDataIndex(int index)
|
||||
{
|
||||
return dataIndex[0] == index || dataIndex[1] == index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 015f1aafb9c2e8940be9ef79b984b843
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user