整理代码结构,支持Package Manager添加

This commit is contained in:
monitor1394
2019-10-22 04:09:04 +08:00
parent e4d47684f6
commit b2b4f1a65f
218 changed files with 197991 additions and 97171 deletions

View File

@@ -0,0 +1,241 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// the animation of serie.
/// 动画表现。
/// </summary>
[System.Serializable]
public class Animation : SubComponent
{
public enum Easing
{
Linear,
}
[SerializeField] private bool m_Enable = true;
[SerializeField] private Easing m_Easting;
[SerializeField] private int m_Duration = 1000;
[SerializeField] private int m_Threshold = 2000;
[SerializeField] private int m_Delay = 0;
[SerializeField] private int m_ActualDuration;
/// <summary>
/// Whether to enable animation.
/// 是否开启动画效果。
/// </summary>
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
/// <summary>
/// Easing method used for the first animation.
/// 动画的缓动效果。
/// </summary>
/// <value></value>
public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// 设定的动画时长(毫秒)。
/// </summary>
/// <value></value>
public int duration { get { return m_Duration; } set { m_Duration = value; } }
/// <summary>
/// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。
/// </summary>
/// <value></value>
public int actualDuration { get { return m_ActualDuration; } }
/// <summary>
/// Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.
/// 是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
/// </summary>
/// <value></value>
public int threshold { get { return m_Threshold; } set { m_Threshold = value; } }
/// <summary>
/// The milliseconds delay before updating the first animation.
/// 动画延时(毫秒)。
/// </summary>
/// <value></value>
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
private bool m_IsStart = false;
private bool m_IsEnd = true;
private bool m_Inited = false;
private float startTime { get; set; }
private int m_CurrDataProgress { get; set; }
private int m_DestDataProgress { get; set; }
[SerializeField] private float m_CurrDetailProgress;
[SerializeField] private float m_DestDetailProgress;
private float m_CurrSymbolProgress;
public void Start()
{
if (m_IsStart) return;
startTime = Time.time;
m_IsStart = true;
m_IsEnd = false;
m_Inited = false;
m_CurrDataProgress = 1;
m_DestDataProgress = 1;
m_CurrDetailProgress = 0;
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_DataAnimationState.Clear();
}
public void Stop()
{
m_IsStart = false;
m_IsEnd = true;
m_Inited = false;
m_DataAnimationState.Clear();
}
public void End()
{
if (m_IsEnd) return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
m_CurrDataProgress = m_DestDataProgress + 1;
m_IsEnd = true;
}
public void Reset()
{
Stop();
Start();
}
public void InitProgress(int data, float curr, float dest)
{
if (!m_Inited && !m_IsEnd)
{
m_Inited = true;
m_DestDataProgress = data;
m_CurrDetailProgress = curr;
m_DestDetailProgress = dest;
}
}
public void SetDataFinish(int dataIndex)
{
if (!m_IsEnd)
{
m_CurrDataProgress = dataIndex + 1;
}
}
public void SetDataState(int index, float state)
{
m_DataAnimationState[index] = state;
}
public float GetDataState(int index)
{
if (IsInDelay()) return 0;
if (!m_DataAnimationState.ContainsKey(index))
{
m_DataAnimationState.Add(index, 0);
}
return m_DataAnimationState[index];
}
public bool IsFinish()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return true;
#endif
return !enable || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress);
}
public bool IsInDelay()
{
return (delay > 0 && Time.time - startTime < delay / 1000);
}
public bool CheckDetailBreak(int dataIndex, float detail)
{
return !IsFinish() && detail > m_CurrDetailProgress;
}
public bool CheckDetailBreak(Vector3 pos, bool isYAxis)
{
if (IsFinish()) return false;
if (isYAxis) return pos.y > m_CurrDetailProgress;
else return pos.x > m_CurrDetailProgress;
}
public bool NeedAnimation(int dataIndex)
{
if (!m_Enable || m_IsEnd) return true;
if (IsInDelay()) return false;
return dataIndex <= m_CurrDataProgress;
}
public void CheckProgress(float delta)
{
if (!enable) return;
if (IsInDelay()) return;
if (m_IsEnd) return;
if (m_CurrDetailProgress > m_DestDetailProgress)
{
End();
}
else
{
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
m_CurrDetailProgress += delta;
}
}
public void CheckSymbol(float delta, float dest)
{
m_CurrSymbolProgress += delta;
if (m_CurrSymbolProgress > dest) m_CurrSymbolProgress = dest;
}
public float GetSysmbolSize(float dest)
{
#if UNITY_EDITOR
if (!Application.isPlaying) return dest;
#endif
if (!enable || m_IsEnd) return dest;
return m_CurrSymbolProgress;
}
public float GetCurrDetail()
{
return m_CurrDetailProgress;
}
public float GetCurrRate()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return 1;
#endif
if (!enable || m_IsEnd) return 1;
return m_CurrDetailProgress;
}
public int GetCurrIndex()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return -1;
#endif
if (!enable || m_IsEnd) return -1;
return (int)m_CurrDetailProgress;
}
public float GetCurrData()
{
return m_CurrDataProgress;
}
}
}

View File

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

View File

@@ -0,0 +1,106 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of area.
/// 区域填充样式。
/// </summary>
[System.Serializable]
public class AreaStyle : SubComponent
{
/// <summary>
/// Origin position of area.
/// 图形区域的起始位置。默认情况下,图形会从坐标轴轴线到数据间进行填充。如果需要填充的区域是坐标轴最大值到数据间,或者坐标轴最小值到数据间,则可以通过这个配置项进行设置。
/// </summary>
public enum AreaOrigin
{
/// <summary>
/// to fill between axis line to data.
/// 填充坐标轴轴线到数据间的区域。
/// </summary>
Auto,
/// <summary>
/// to fill between min axis value (when not inverse) to data.
/// 填充坐标轴底部到数据间的区域。
/// </summary>
Start,
/// <summary>
/// to fill between max axis value (when not inverse) to data.
/// 填充坐标轴顶部到数据间的区域。
/// </summary>
End
}
[SerializeField] private bool m_Show;
[SerializeField] private AreaOrigin m_Origin;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_ToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity;
[SerializeField] private bool m_TooltipHighlight;
[SerializeField] private Color m_HighlightColor;
[SerializeField] private Color m_HighlightToColor;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// the origin of area.
/// 区域填充的起始位置。
/// </summary>
public AreaOrigin origin { get { return m_Origin; } set { m_Origin = value; } }
/// <summary>
/// the color of area,default use serie color.
/// 区域填充的颜色如果toColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
public Color toColor { get { return m_ToColor; } set { m_ToColor = value; } }
/// <summary>
/// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
/// 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
/// <summary>
/// 鼠标悬浮时是否高亮之前的区域
/// </summary>
public bool tooltipHighlight { get { return m_TooltipHighlight; } set { m_TooltipHighlight = value; } }
/// <summary>
/// the color of area,default use serie color.
/// 高亮时区域填充的颜色如果highlightToColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color highlightColor { get { return m_HighlightColor; } set { m_HighlightColor = value; } }
/// <summary>
/// Gradient color, start highlightColor to highlightToColor.
/// 高亮时渐变色的终点颜色。
/// </summary>
public Color highlightToColor { get { return m_HighlightToColor; } set { m_HighlightToColor = value; } }
public static AreaStyle defaultAreaStyle
{
get
{
var area = new AreaStyle
{
m_Show = false,
m_Color = Color.clear,
m_ToColor = Color.clear,
m_Opacity = 1
};
return area;
}
}
}
}

View File

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

View File

@@ -0,0 +1,171 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to axis label.
/// 坐标轴刻度标签的相关设置。
/// </summary>
[Serializable]
public class AxisLabel : SubComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Formatter;
[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; } }
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {value}{value:f1} 表示取1为小数
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
public static AxisLabel defaultAxisLabel
{
get
{
return new AxisLabel()
{
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Rotate = 0,
m_Margin = 8,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
};
}
}
public void Copy(AxisLabel other)
{
m_Show = other.show;
m_Interval = other.interval;
m_Inside = other.inside;
m_Rotate = other.rotate;
m_Margin = other.margin;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
m_Formatter = other.formatter;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisLabel)obj;
return m_Show == other.show &&
m_Interval.Equals(other.interval) &&
m_Inside == other.inside &&
m_Rotate == other.rotate &&
m_Margin == other.margin &&
m_Color == other.color &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle &&
m_Formatter == other.formatter;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public string GetFormatterContent(string category)
{
if (string.IsNullOrEmpty(m_Formatter))
return category;
else
{
var content = m_Formatter.Replace("{value}", category);
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
public string GetFormatterContent(float value)
{
if (string.IsNullOrEmpty(m_Formatter))
if (value - (int)value == 0)
return ChartCached.IntToStr((int)value);
else
return ChartCached.FloatToStr(value, 1);
else
{
var content = m_Formatter;
if (content.Contains("{value:f2}"))
content = m_Formatter.Replace("{value:f2}", ChartCached.FloatToStr(value, 2));
else if (content.Contains("{value:f1}"))
content = m_Formatter.Replace("{value:f1}", ChartCached.FloatToStr(value, 1));
else if (content.Contains("{value}"))
{
if (value - (int)value == 0)
content = m_Formatter.Replace("{value}", ChartCached.IntToStr((int)value));
else
content = m_Formatter.Replace("{value}", ChartCached.FloatToStr(value, 1));
}
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
}
}

View File

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

View File

@@ -0,0 +1,88 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to axis line.
/// 坐标轴的分隔线。
/// </summary>
[System.Serializable]
public class AxisLine : SubComponent
{
[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
{
get
{
var axisLine = new AxisLine
{
m_Show = true,
m_OnZero = true,
m_Width = 0.7f,
m_Symbol = false,
m_SymbolWidth = 10,
m_SymbolHeight = 15,
m_SymbolOffset = 0,
m_SymbolDent = 3,
};
return axisLine;
}
}
}
}

View File

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

View File

@@ -0,0 +1,131 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// the name of axis.
/// 坐标轴名称。
/// </summary>
[Serializable]
public class AxisName : SubComponent
{
/// <summary>
/// the location of axis name.
/// 坐标轴名称显示位置。
/// </summary>
public enum Location
{
Start,
Middle,
End
}
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField] private Location m_Location;
[SerializeField] private Vector2 m_Offset;
[SerializeField] private float m_Rotate;
[SerializeField] private Color m_Color;
[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>
/// the offset of axis name and axis line.
/// 坐标轴名称与轴线之间的偏移。
/// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = 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
{
get
{
return new AxisName()
{
m_Show = false,
m_Name = "axisName",
m_Location = Location.End,
m_Rotate = 0,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
};
}
}
public void Copy(AxisName other)
{
m_Show = other.show;
m_Name = other.name;
m_Location = other.location;
m_Offset = other.offset;
m_Rotate = other.rotate;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisName)obj;
return m_Show == other.show &&
m_Name.Equals(other.name) &&
m_Location == other.location &&
m_Rotate == other.rotate &&
m_Color == other.color &&
m_Offset == other.offset &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

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

View File

@@ -0,0 +1,58 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Split area of axis in grid area, not shown by default.
/// 坐标轴在 grid 区域中的分隔区域,默认不显示。
/// </summary>
[Serializable]
public class AxisSplitArea : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private List<Color> m_Color;
/// <summary>
/// Set this to true to show the splitArea.
/// 是否显示分隔区域。
/// </summary>
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>
public List<Color> color { get { return m_Color; } set { m_Color = value; } }
public static AxisSplitArea defaultSplitArea
{
get
{
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color>(){
new Color32(250,250,250,77),
new Color32(200,200,200,77)
}
};
}
}
public Color getColor(int index)
{
var i = index % color.Count;
return color[i];
}
}
}

View File

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

View File

@@ -0,0 +1,61 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to axis tick.
/// 坐标轴刻度相关设置。
/// </summary>
[System.Serializable]
public class AxisTick : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_AlignWithLabel;
[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
{
get
{
var tick = new AxisTick
{
m_Show = true,
m_AlignWithLabel = false,
m_Inside = false,
m_Length = 5f
};
return tick;
}
}
}
}

View File

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

View File

@@ -0,0 +1,35 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// 高亮的图形样式和文本标签样式。
/// </summary>
[System.Serializable]
public class Emphasis : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private SerieLabel m_Label = new SerieLabel();
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
/// <summary>
/// 是否启用高亮样式。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 图形文本标签。
/// </summary>
public SerieLabel label { get { return m_Label; } }
/// <summary>
/// 图形样式。
/// </summary>
public ItemStyle itemStyle { get { return m_ItemStyle; } }
}
}

View File

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

View File

@@ -0,0 +1,69 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// 图形样式。
/// </summary>
[System.Serializable]
public class ItemStyle : SubComponent
{
/// <summary>
/// 线的类型。
/// </summary>
public enum Type
{
/// <summary>
/// 实线
/// </summary>
Solid,
/// <summary>
/// 虚线
/// </summary>
Dashed,
/// <summary>
/// 点线
/// </summary>
Dotted
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Color m_Color;
[SerializeField] private Type m_BorderType = Type.Solid;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color m_BorderColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// 是否启用。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 数据项颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// 边框的类型。
/// </summary>
public Type borderType { get { return m_BorderType; } set { m_BorderType = value; } }
/// <summary>
/// 边框的颜色。
/// </summary>
public Color borderColor { get { return m_BorderColor; } set { m_BorderColor = value; } }
/// <summary>
/// 边框宽。
/// </summary>
public float borderWidth { get { return m_BorderWidth; } set { m_BorderWidth = value; } }
/// <summary>
/// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
}
}

View File

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

View File

@@ -0,0 +1,67 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// </summary>
[Serializable]
public class LineArrow : SubComponent
{
public enum Position
{
/// <summary>
/// 末端箭头
/// </summary>
End,
/// <summary>
/// 头端箭头
/// </summary>
Start
}
[SerializeField] private bool m_Show;
[SerializeField] Position m_Position;
[SerializeField] private float m_Width = 10;
[SerializeField] private float m_Height = 15;
[SerializeField] private float m_Offset = 0;
[SerializeField] private float m_Dent = 3;
/// <summary>
/// Whether to show the arrow.
/// 是否显示箭头。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// The position of arrow.
/// 箭头位置。
/// </summary>
public Position position { get { return m_Position; } set { m_Position = value; } }
/// <summary>
/// The widht of arrow.
/// 箭头宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// The height of arrow.
/// 箭头高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
/// <summary>
/// The offset of arrow.
/// 箭头偏移。
/// </summary>
public float offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// The dent of arrow.
/// 箭头的凹度。
/// </summary>
public float dent { get { return m_Dent; } set { m_Dent = value; } }
}
}

View File

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

View File

@@ -0,0 +1,79 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of line.
/// 线条样式。
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color线条颜色默认也会取改颜色。
/// </summary>
[System.Serializable]
public class LineStyle : SubComponent
{
/// <summary>
/// 线的类型。
/// </summary>
public enum Type
{
/// <summary>
/// 实线
/// </summary>
Solid,
/// <summary>
/// 虚线
/// </summary>
Dashed,
/// <summary>
/// 点线
/// </summary>
Dotted,
/// <summary>
/// 点划线
/// </summary>
DashDot,
/// <summary>
/// 双点划线
/// </summary>
DashDotDot,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color m_Color;
[SerializeField] private float m_Width = 0.8f;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// Whether show line.
/// 是否显示线条。在折线图中无效。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// the type of line.
/// 线的类型。
/// </summary>
public Type type { get { return m_Type; } set { m_Type = value; } }
/// <summary>
/// the color of line, default use serie color.
/// 线的颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// the width of line.
/// 线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0.
/// 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
}
}

View File

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

View File

@@ -0,0 +1,322 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Location type. Quick to set the general location.
/// 位置类型。通过Align快速设置大体位置再通过leftrighttopbottom微调具体位置。
/// </summary>
[Serializable]
public class Location : SubComponent, IPropertyChanged, IEquatable<Location>
{
/// <summary>
/// 对齐方式
/// </summary>
public enum Align
{
TopLeft,
TopRight,
TopCenter,
BottomLeft,
BottomRight,
BottomCenter,
Center,
CenterLeft,
CenterRight
}
[SerializeField] private Align m_Align = Align.TopCenter;
[SerializeField] private float m_Left;
[SerializeField] private float m_Right;
[SerializeField] private float m_Top;
[SerializeField] private float m_Bottom;
private TextAnchor m_TextAnchor;
private Vector2 m_AnchorMin;
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
{
get
{
return new Location()
{
align = Align.CenterLeft,
left = 5,
right = 0,
top = 0,
bottom = 0
};
}
}
public static Location defaultRight
{
get
{
return new Location()
{
align = Align.CenterRight,
left = 0,
right = 5,
top = 0,
bottom = 0
};
}
}
public static Location defaultTop
{
get
{
return new Location()
{
align = Align.TopCenter,
left = 0,
right = 0,
top = 5,
bottom = 0
};
}
}
public static Location defaultBottom
{
get
{
return new Location()
{
align = Align.BottomCenter,
left = 0,
right = 0,
top = 0,
bottom = 5
};
}
}
private void UpdateAlign()
{
switch (m_Align)
{
case Align.BottomCenter:
m_TextAnchor = TextAnchor.LowerCenter;
m_AnchorMin = new Vector2(0.5f, 0);
m_AnchorMax = new Vector2(0.5f, 0);
m_Pivot = new Vector2(0.5f, 0);
break;
case Align.BottomLeft:
m_TextAnchor = TextAnchor.LowerLeft;
m_AnchorMin = new Vector2(0, 0);
m_AnchorMax = new Vector2(0, 0);
m_Pivot = new Vector2(0, 0);
break;
case Align.BottomRight:
m_TextAnchor = TextAnchor.LowerRight;
m_AnchorMin = new Vector2(1, 0);
m_AnchorMax = new Vector2(1, 0);
m_Pivot = new Vector2(1, 0);
break;
case Align.Center:
m_TextAnchor = TextAnchor.MiddleCenter;
m_AnchorMin = new Vector2(0.5f, 0.5f);
m_AnchorMax = new Vector2(0.5f, 0.5f);
m_Pivot = new Vector2(0.5f, 0.5f);
break;
case Align.CenterLeft:
m_TextAnchor = TextAnchor.MiddleLeft;
m_AnchorMin = new Vector2(0, 0.5f);
m_AnchorMax = new Vector2(0, 0.5f);
m_Pivot = new Vector2(0, 0.5f);
break;
case Align.CenterRight:
m_TextAnchor = TextAnchor.MiddleRight;
m_AnchorMin = new Vector2(1, 0.5f);
m_AnchorMax = new Vector2(1, 0.5f);
m_Pivot = new Vector2(1, 0.5f);
break;
case Align.TopCenter:
m_TextAnchor = TextAnchor.UpperCenter;
m_AnchorMin = new Vector2(0.5f, 1);
m_AnchorMax = new Vector2(0.5f, 1);
m_Pivot = new Vector2(0.5f, 1);
break;
case Align.TopLeft:
m_TextAnchor = TextAnchor.UpperLeft;
m_AnchorMin = new Vector2(0, 1);
m_AnchorMax = new Vector2(0, 1);
m_Pivot = new Vector2(0, 1);
break;
case Align.TopRight:
m_TextAnchor = TextAnchor.UpperRight;
m_AnchorMin = new Vector2(1, 1);
m_AnchorMax = new Vector2(1, 1);
m_Pivot = new Vector2(1, 1);
break;
default:
break;
}
}
/// <summary>
/// 返回在坐标系中的具体位置
/// </summary>
/// <param name="chartWidth"></param>
/// <param name="chartHeight"></param>
/// <returns></returns>
public Vector3 GetPosition(float chartWidth, float chartHeight)
{
switch (align)
{
case Align.BottomCenter:
return new Vector3(chartWidth / 2, bottom);
case Align.BottomLeft:
return new Vector3(left, bottom);
case Align.BottomRight:
return new Vector3(chartWidth - right, bottom);
case Align.Center:
return new Vector3(chartWidth / 2, chartHeight / 2);
case Align.CenterLeft:
return new Vector3(left, chartHeight / 2);
case Align.CenterRight:
return new Vector3(chartWidth - right, chartHeight / 2);
case Align.TopCenter:
return new Vector3(chartWidth / 2, chartHeight - top);
case Align.TopLeft:
return new Vector3(left, chartHeight - top);
case Align.TopRight:
return new Vector3(chartWidth - right, chartHeight - top);
default:
return Vector2.zero;
}
}
public void Copy(Location location)
{
m_Align = location.align;
m_Left = location.left;
m_Right = location.right;
m_Top = location.top;
m_Bottom = location.bottom;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Location)
{
return Equals((Location)obj);
}
else
{
return false;
}
}
public bool Equals(Location other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return align == other.align &&
left == other.left &&
right == other.right &&
top == other.top &&
bottom == other.bottom;
}
public static bool operator ==(Location left, Location 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 !=(Location left, Location right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
/// </summary>
public void OnChanged()
{
UpdateAlign();
}
}
}

View File

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

View File

@@ -0,0 +1,264 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// A data item of serie.
/// 系列中的一个数据项。可存储数据名和1-n维的数据。
/// </summary>
[System.Serializable]
public class SerieData : SubComponent
{
[SerializeField] private string m_Name;
[SerializeField] private bool m_Selected;
[SerializeField] private float m_Radius;
[SerializeField] private bool m_ShowIcon;
[SerializeField] private Sprite m_IconImage;
[SerializeField] private Color m_IconColor = Color.white;
[SerializeField] private float m_IconWidth = 40;
[SerializeField] private float m_IconHeight = 40;
[SerializeField] private Vector3 m_IconOffset;
[SerializeField] private List<float> m_Data = new List<float>();
private bool m_Show = true;
private bool m_LabelAutoSize;
private float m_LabelPaddingLeftRight;
private float m_LabelPaddingTopBottom;
private float m_RtPieOutsideRadius;
public int index { get; set; }
/// <summary>
/// the name of data item.
/// 数据项名称。
/// </summary>
public string name { get { return m_Name; } set { m_Name = value; } }
/// <summary>
/// 数据项图例名称。当数据项名称不为空时图例名称即为系列名称反之则为索引index。
/// </summary>
/// <value></value>
public string legendName { get { return string.IsNullOrEmpty(name) ? ChartCached.IntToStr(index) : name; } }
/// <summary>
/// 自定义半径。可用在饼图中自定义某个数据项的半径。
/// </summary>
public float radius { get { return m_Radius; } set { m_Radius = value; } }
/// <summary>
/// Whether the data item is selected.
/// 该数据项是否被选中。
/// </summary>
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
/// <summary>
/// Whether the data icon is show.
/// 是否显示图标。
/// </summary>
public bool showIcon { get { return m_ShowIcon; } set { m_ShowIcon = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite iconImage { get { return m_IconImage; } set { m_IconImage = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color iconColor { get { return m_IconColor; } set { m_IconColor = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float iconWidth { get { return m_IconWidth; } set { m_IconWidth = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float iconHeight { get { return m_IconHeight; } set { m_IconHeight = value; } }
/// <summary>
/// 图标偏移。
/// </summary>
public Vector3 iconOffset { get { return m_IconOffset; } set { m_IconOffset = value; } }
/// <summary>
/// An arbitrary dimension data list of data item.
/// 可指定任意维数的数值列表。
/// </summary>
public List<float> data { get { return m_Data; } set { m_Data = value; } }
/// <summary>
/// [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.
/// 该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
/// </summary>
public bool highlighted { get; set; }
/// <summary>
/// the label of data item.
/// 该数据项的文本标签。
/// </summary>
public Text labelText { get; private set; }
public RectTransform labelRect { get; private set; }
/// <summary>
/// 标志位置。
/// </summary>
public Vector3 labelPosition { get; set; }
public bool m_CanShowLabel = true;
/// <summary>
/// 是否可以显示Label
/// </summary>
public bool canShowLabel { get { return m_CanShowLabel; } set { m_CanShowLabel = value; } }
/// <summary>
/// the maxinum value.
/// 最大值。
/// </summary>
public float max { get { return m_Data.Max(); } }
/// <summary>
/// the mininum value.
/// 最小值。
/// </summary>
public float min { get { return m_Data.Min(); } }
public Image icon { get; private set; }
public RectTransform iconRect { get; private set; }
/// <summary>
/// 关联的gameObject
/// </summary>
public GameObject gameObject { get; private set; }
/// <summary>
/// 饼图数据项的开始角度(运行时自动计算)
/// </summary>
public float pieStartAngle { get; set; }
/// <summary>
/// 饼图数据项的结束角度(运行时自动计算)
/// </summary>
public float pieToAngle { get; set; }
/// <summary>
/// 饼图数据项的一半时的角度(运行时自动计算)
/// </summary>
public float pieHalfAngle { get; set; }
/// <summary>
/// 饼图数据项的当前角度(运行时自动计算)
/// </summary>
public float pieCurrAngle { get; set; }
/// <summary>
/// 饼图数据项的内半径
/// </summary>
public float pieInsideRadius { get; set; }
/// <summary>
/// 饼图数据项的外半径
/// </summary>
public float pieOutsideRadius
{
get
{
if (radius > 0) return radius;
else return m_RtPieOutsideRadius;
}
set
{
m_RtPieOutsideRadius = value;
}
}
/// <summary>
/// 饼图数据项的偏移半径
/// </summary>
public float pieOffsetRadius { get; set; }
public Vector3 pieOffsetCenter { get; set; }
public float GetData(int index)
{
if (index >= 0 && index < m_Data.Count) return m_Data[index];
else return 0;
}
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
{
gameObject = labelObj;
m_LabelAutoSize = autoSize;
m_LabelPaddingLeftRight = paddingLeftRight;
m_LabelPaddingTopBottom = paddingTopBottom;
labelText = labelObj.GetComponentInChildren<Text>();
labelRect = labelText.GetComponent<RectTransform>();
}
public void SetLabelActive(bool active)
{
if (labelRect)
{
ChartHelper.SetActive(labelRect, active);
}
}
public bool SetLabelText(string text)
{
if (labelText)
{
labelText.text = text;
if (m_LabelAutoSize)
{
var newSize = new Vector2(labelText.preferredWidth + m_LabelPaddingLeftRight * 2,
labelText.preferredHeight + m_LabelPaddingTopBottom * 2);
var sizeChange = newSize.x != labelRect.sizeDelta.x || newSize.y != labelRect.sizeDelta.y;
if (sizeChange) labelRect.sizeDelta = newSize;
return sizeChange;
}
}
return false;
}
public float GetLabelWidth()
{
if (labelRect) return labelRect.sizeDelta.x;
else return 0;
}
public float GetLabelHeight()
{
if (labelRect) return labelRect.sizeDelta.y;
return 0;
}
public void SetGameObjectPosition(Vector3 position)
{
if (gameObject)
{
gameObject.transform.localPosition = position;
}
}
public void SetLabelPosition(Vector3 position)
{
if (labelRect) labelRect.localPosition = position;
}
public void SetIconObj(GameObject iconObj)
{
icon = iconObj.GetComponent<Image>();
iconRect = iconObj.GetComponent<RectTransform>();
UpdateIcon();
}
public void UpdateIcon()
{
if (icon == null) return;
if (m_ShowIcon)
{
ChartHelper.SetActive(icon.gameObject, true);
icon.sprite = m_IconImage;
icon.color = m_IconColor;
iconRect.sizeDelta = new Vector2(m_IconWidth, m_IconHeight);
icon.transform.localPosition = m_IconOffset;
}
else
{
ChartHelper.SetActive(icon.gameObject, false);
}
}
}
}

View File

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

View File

@@ -0,0 +1,250 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
/// <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 : SubComponent
{
/// <summary>
/// The position of label.
/// 标签的位置。
/// </summary>
public enum Position
{
/// <summary>
/// Outside of sectors of pie chart, which relates to corresponding sector through visual guide line.
/// 饼图扇区外侧,通过视觉引导线连到相应的扇区。
/// </summary>
Outside,
/// <summary>
/// Inside the sectors of pie chart.
/// 饼图扇区内部。
/// </summary>
Inside,
/// <summary>
/// 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,
}
/// <summary>
/// 标签视觉引导线类型
/// </summary>
public enum LineType
{
/// <summary>
/// 折线
/// </summary>
BrokenLine,
/// <summary>
/// 曲线
/// </summary>
Curves,
/// <summary>
/// 水平线
/// </summary>
HorizontalLine
}
[SerializeField] private bool m_Show = false;
[SerializeField] Position m_Position;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_PaddingLeftRight = 2f;
[SerializeField] private float m_PaddingTopBottom = 2f;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth = 0;
[SerializeField] private float m_BackgroundHeight = 0;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_Line = true;
[SerializeField] private LineType m_LineType = LineType.BrokenLine;
[SerializeField] private Color m_LineColor = Color.clear;
[SerializeField] private float m_LineWidth = 1.0f;
[SerializeField] private float m_LineLength1 = 25f;
[SerializeField] private float m_LineLength2 = 15f;
[SerializeField] private bool m_Border = true;
[SerializeField] private float m_BorderWidth = 0.5f;
[SerializeField] private Color m_BorderColor = Color.grey;
/// <summary>
/// Whether the label is showed.
/// 是否显示文本标签。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// The position of label.
/// 标签的位置。
/// </summary>
public Position position { get { return m_Position; } set { m_Position = value; } }
/// <summary>
/// 标签内容字符串模版格式器。支持用 \n 换行。
/// 模板变量有:
/// <list type="bullet">
/// <item><description>{a}:系列名。</description></item>
/// <item><description>{b}:数据名。</description></item>
/// <item><description>{c}:数据值。</description></item>
/// <item><description>{d}:百分比。</description></item>
/// </list>
/// </summary>
/// <example>
/// 示例:“{b}:{c}”
/// </example>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <summary>
/// offset to the host graphic element.
/// 距离图形元素的偏移
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// Text color,If set as default ,the color will assigned as series color.
/// 自定义文字颜色,默认和系列的颜色一致。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// the background color. If set as default, it means than don't show background.
/// 标签的背景色,默认无颜色。
/// </summary>
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
/// <summary>
/// the width of background. If set as default value 0, it means than the background width auto set as the text width.
/// 标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
/// </summary>
/// <value></value>
public float backgroundWidth { get { return m_BackgroundWidth; } set { m_BackgroundWidth = value; } }
/// <summary>
/// the height of background. If set as default value 0, it means than the background height auto set as the text height.
/// 标签的背景高度。一般不用指定,不指定时则自动是文字的高度。
/// </summary>
/// <value></value>
public float backgroundHeight { get { return m_BackgroundHeight; } set { m_BackgroundHeight = value; } }
/// <summary>
/// Rotate label.
/// 标签旋转。
/// </summary>
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
/// <summary>
/// the text padding of left and right. defaut:2.
/// 左右边距。
/// </summary>
public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
/// <summary>
/// the text padding of top and bottom. defaut:2.
/// 上下边距。
/// </summary>
public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = 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; } }
/// <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 type of visual guide line.
/// 视觉引导线类型。
/// </summary>
public LineType lineType { get { return m_LineType; } set { m_LineType = value; } }
/// <summary>
/// the color of visual guild line.
/// 视觉引导线颜色。默认和serie一致取自调色板。
/// </summary>
public Color lineColor { get { return m_LineColor; } set { m_LineColor = 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; } }
/// <summary>
/// Whether to show border.
/// 是否显示边框。
/// </summary>
public bool border { get { return m_Border; } set { m_Border = value; } }
/// <summary>
/// the width of border.
/// 边框宽度。
/// </summary>
public float borderWidth { get { return m_BorderWidth; } set { m_BorderWidth = value; } }
/// <summary>
/// the color of border.
/// 边框颜色。
/// </summary>
public Color borderColor { get { return m_BorderColor; } set { m_BorderColor = value; } }
public string GetFormatterContent(string serieName, string dataName, float dataValue, float dataTotal = 0)
{
if (string.IsNullOrEmpty(m_Formatter))
return ChartCached.FloatToStr(dataValue);
else
{
var content = m_Formatter.Replace("{a}", serieName);
content = content.Replace("{b}", dataName);
content = content.Replace("{c}", ChartCached.FloatToStr(dataValue));
content = content.Replace("{c:f0}", ChartCached.IntToStr((int)Mathf.Round(dataValue)));
content = content.Replace("{c:f1}", ChartCached.FloatToStr(dataValue, 1));
content = content.Replace("{c:f2}", ChartCached.FloatToStr(dataValue, 2));
if (dataTotal > 0)
{
var percent = dataValue / dataTotal * 100;
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
content = content.Replace("{d:f0}", ChartCached.IntToStr((int)Mathf.Round(percent)));
content = content.Replace("{d:f1}", ChartCached.FloatToStr(percent, 1));
content = content.Replace("{d:f2}", ChartCached.FloatToStr(percent, 2));
}
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
}
}

View File

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

View File

@@ -0,0 +1,238 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
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.
/// 获取标记图形大小的方式。
/// </summary>
public enum SerieSymbolSizeType
{
/// <summary>
/// Specify constant for symbol size.
/// 自定义大小。
/// </summary>
Custom,
/// <summary>
/// Specify the dataIndex and dataScale to calculate symbol size.
/// 通过 dataIndex 从数据中获取,再乘以一个比例系数 dataScale 。
/// </summary>
FromData,
/// <summary>
/// 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 : SubComponent
{
[SerializeField] private SerieSymbolType m_Type = SerieSymbolType.EmptyCircle;
[SerializeField] private SerieSymbolSizeType m_SizeType = SerieSymbolSizeType.Custom;
[SerializeField] private float m_Size = 6f;
[SerializeField] private float m_SelectedSize = 10f;
[SerializeField] private int m_DataIndex = 1;
[SerializeField] private float m_DataScale = 1;
[SerializeField] private float m_SelectedDataScale = 1.5f;
[SerializeField] private SymbolSizeCallback m_SizeCallback;
[SerializeField] private SymbolSizeCallback m_SelectedSizeCallback;
[SerializeField] private Color m_Color;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField] private int m_StartIndex;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
/// <summary>
/// the type of symbol.
/// 标记类型。
/// </summary>
public SerieSymbolType type { get { return m_Type; } set { m_Type = value; } }
/// <summary>
/// the type of symbol size.
/// 标记图形的大小获取方式。
/// </summary>
public SerieSymbolSizeType sizeType { get { return m_SizeType; } set { m_SizeType = value; } }
/// <summary>
/// the size of symbol.
/// 标记的大小。
/// </summary>
public float size { get { return m_Size; } set { m_Size = value; } }
/// <summary>
/// the size of selected symbol.
/// 被选中的标记的大小。
/// </summary>
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>
public int dataIndex { get { return m_DataIndex; } set { m_DataIndex = value; } }
/// <summary>
/// the scale of data when sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的倍数系数。
/// </summary>
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>
public float selectedDataScale { get { return m_SelectedDataScale; } set { m_SelectedDataScale = value; } }
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时指定的回调函数。
/// </summary>
public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } }
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时指定的高亮回调函数。
/// </summary>
public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } }
/// <summary>
/// the color of symbol,default from serie.
/// 标记图形的颜色,默认和系列一致。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// the opacity of color.
/// 图形标记的透明度。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
/// <summary>
/// the index start to show symbol.
/// 开始显示图形标记的索引。
/// </summary>
public int startIndex { get { return m_StartIndex; } set { m_StartIndex = value; } }
/// <summary>
/// the interval of show symbol.
/// 显示图形标记的间隔。0表示显示所有标签1表示隔一个隔显示一个标签以此类推。
/// </summary>
public int interval { get { return m_Interval; } set { m_Interval = value; } }
/// <summary>
/// whether to show the last symbol.
/// 是否强制显示最后一个图形标记。
/// </summary>
public bool forceShowLast { get { return m_ForceShowLast; } set { m_ForceShowLast = value; } }
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
/// <summary>
/// the setting for effect scatter.
/// 带有涟漪特效动画的散点图的动画参数。
/// </summary>
public List<float> animationSize { get { return m_AnimationSize; } }
/// <summary>
/// 根据指定的sizeType获得标记的大小
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSize(List<float> data)
{
if (data == null) return size;
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
return size;
case SerieSymbolSizeType.FromData:
if (dataIndex >= 0 && dataIndex < data.Count)
{
return data[dataIndex] * m_DataScale;
}
else
{
return size;
}
case SerieSymbolSizeType.Callback:
if (sizeCallback != null) return sizeCallback(data);
else return size;
default: return size;
}
}
/// <summary>
/// 根据sizeType获得高亮时的标记大小
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSelectedSize(List<float> data)
{
if (data == null) return selectedSize;
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
return selectedSize;
case SerieSymbolSizeType.FromData:
if (dataIndex >= 0 && dataIndex < data.Count)
{
return data[dataIndex] * m_SelectedDataScale;
}
else
{
return selectedSize;
}
case SerieSymbolSizeType.Callback:
if (selectedSizeCallback != null) return selectedSizeCallback(data);
else return selectedSize;
default: return selectedSize;
}
}
public bool ShowSymbol(int dataIndex, int dataCount)
{
if (type == SerieSymbolType.None) return false;
if (dataIndex < startIndex) return false;
if (m_Interval <= 0) return true;
if (m_ForceShowLast && dataIndex == dataCount - 1) return true;
return (dataIndex - startIndex) % (m_Interval + 1) == 0;
}
}
}

View File

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