海拔图和小地图

This commit is contained in:
lishuo committed 2021-03-28 18:17:15 +08:00
1 parent 45801dff22
commit c5bd9daba2
521 files changed
+1985033 -439

No files matched your search

@@ -0,0 +1,74 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
public class ChartComponent
{
[NonSerialized] protected bool m_VertsDirty;
[NonSerialized] protected bool m_ComponentDirty;
[NonSerialized] protected Painter m_Painter;
/// <summary>
/// 图表重绘标记。
/// </summary>
public virtual bool vertsDirty { get { return m_VertsDirty; } }
/// <summary>
/// 组件重新初始化标记。
/// </summary>
public virtual bool componentDirty { get { return m_ComponentDirty; } }
/// <summary>
/// 需要重绘图表或重新初始化组件。
/// </summary>
public bool anyDirty { get { return vertsDirty || componentDirty; } }
public Painter painter { get { return m_Painter; } set { m_Painter = value; } }
public Action refreshComponent { get; set; }
public GameObject gameObject { get; set; }
internal virtual void SetVerticesDirty()
{
m_VertsDirty = true;
}
internal virtual void ClearVerticesDirty()
{
m_VertsDirty = false;
}
internal virtual void SetComponentDirty()
{
m_ComponentDirty = true;
}
internal virtual void ClearComponentDirty()
{
m_ComponentDirty = false;
}
public virtual void ClearDirty()
{
ClearVerticesDirty();
ClearComponentDirty();
}
public virtual void SetAllDirty()
{
SetVerticesDirty();
SetComponentDirty();
}
}
public class MainComponent : ChartComponent
{
}
public class SubComponent : ChartComponent
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0af5e768fe0e407cb5b023b37c41597
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d1d3ce01c4a6f4e3482c1dc22f388889
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,978 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// The axis in rectangular coordinate.
/// 直角坐标系的坐标轴组件。
/// </summary>
[System.Serializable]
public class Axis : MainComponent
{
/// <summary>
/// the type of axis.
/// 坐标轴类型。
/// </summary>
public enum AxisType
{
/// <summary>
/// Numerical axis, suitable for continuous data.
/// 数值轴。适用于连续数据。
/// </summary>
Value,
/// <summary>
/// Category axis, suitable for discrete category data. Data should only be set via data for this type.
/// 类目轴。适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。
/// </summary>
Category,
/// <summary>
/// Log axis, suitable for log data.
/// 对数轴。适用于对数数据。
/// </summary>
Log,
/// <summary>
/// Time axis, suitable for continuous time series data.
/// 时间轴。适用于连续的时序数据。
/// </summary>
Time
}
/// <summary>
/// the type of axis min and max value.
/// 坐标轴最大最小刻度显示类型。
/// </summary>
public enum AxisMinMaxType
{
/// <summary>
/// 0 - maximum.
/// 0-最大值。
/// </summary>
Default,
/// <summary>
/// minimum - maximum.
/// 最小值-最大值。
/// </summary>
MinMax,
/// <summary>
/// Customize the minimum and maximum.
/// 自定义最小值最大值。
/// </summary>
Custom
}
/// <summary>
/// the position of axis in grid.
/// 坐标轴在Grid中的位置
/// </summary>
public enum AxisPosition
{
Left,
Right,
Bottom,
Top
}
[SerializeField] protected bool m_Show = true;
[SerializeField] protected AxisType m_Type;
[SerializeField] protected AxisMinMaxType m_MinMaxType;
[SerializeField] protected int m_GridIndex;
[SerializeField] protected int m_PolarIndex;
[SerializeField] protected AxisPosition m_Position;
[SerializeField] protected float m_Offset;
[SerializeField] protected float m_Min;
[SerializeField] protected float m_Max;
[SerializeField] protected int m_SplitNumber = 5;
[SerializeField] protected float m_Interval = 0;
[SerializeField] protected bool m_BoundaryGap = true;
[SerializeField] protected int m_MaxCache = 0;
[SerializeField] protected float m_LogBase = 10;
[SerializeField] protected bool m_LogBaseE = false;
[SerializeField] protected int m_CeilRate = 0;
[SerializeField] protected bool m_Inverse = false;
[SerializeField] private bool m_Clockwise = 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 AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[NonSerialized] private float m_MinMaxValueRange;
[NonSerialized] private bool m_NeedUpdateFilterData;
/// <summary>
/// Whether to show axis.
/// 是否显示坐标轴。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of axis.
/// 坐标轴类型。
/// </summary>
public AxisType type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); }
}
/// <summary>
/// the type of axis minmax.
/// 坐标轴刻度最大最小值显示类型。
/// </summary>
public AxisMinMaxType minMaxType
{
get { return m_MinMaxType; }
set { if (PropertyUtil.SetStruct(ref m_MinMaxType, value)) SetAllDirty(); }
}
/// <summary>
/// The index of the grid on which the axis are located, by default, is in the first grid.
/// 坐标轴所在的 grid 的索引,默认位于第一个 grid。
/// </summary>
public int gridIndex
{
get { return m_GridIndex; }
set { if (PropertyUtil.SetStruct(ref m_GridIndex, value)) SetAllDirty(); }
}
/// <summary>
/// The index of the polar on which the axis are located, by default, is in the first polar.
/// 坐标轴所在的 ploar 的索引,默认位于第一个 polar。
/// </summary>
public int polarIndex
{
get { return m_PolarIndex; }
set { if (PropertyUtil.SetStruct(ref m_PolarIndex, value)) SetAllDirty(); }
}
/// <summary>
/// the position of axis in grid.
/// 坐标轴在Grid中的位置。
/// </summary>
public AxisPosition position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); }
}
/// <summary>
/// the offset of axis from the default position. Useful when the same position has multiple axes.
/// 坐标轴相对默认位置的偏移。在相同position有多个坐标轴时有用。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
}
/// <summary>
/// The minimun value of axis.Valid when `minMaxType` is `Custom`
/// 设定的坐标轴刻度最小值,当minMaxType为Custom时有效。
/// </summary>
public float min
{
get { return m_Min; }
set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetAllDirty(); }
}
/// <summary>
/// The maximum value of axis.Valid when `minMaxType` is `Custom`
/// 设定的坐标轴刻度最大值,当minMaxType为Custom时有效。
/// </summary>
public float max
{
get { return m_Max; }
set { if (PropertyUtil.SetStruct(ref m_Max, value)) SetAllDirty(); }
}
/// <summary>
/// Number of segments that the axis is split into.
/// 坐标轴的分割段数。
/// </summary>
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
/// <summary>
/// Compulsively set segmentation interval for axis.This is unavailable for category axis.
/// 强制设置坐标轴分割间隔。无法在类目轴中使用。
/// </summary>
public float interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetAllDirty(); }
}
/// <summary>
/// The boundary gap on both sides of a coordinate axis, which is valid only for category axis with type: 'Category'.
/// 坐标轴两边是否留白。只对类目轴有效。
/// </summary>
public bool boundaryGap
{
get { return IsCategory() ? m_BoundaryGap : false; }
set { if (PropertyUtil.SetStruct(ref m_BoundaryGap, value)) SetAllDirty(); }
}
/// <summary>
/// Base of logarithm, which is valid only for numeric axes with type: 'Log'.
/// 对数轴的底数,只在对数轴(type:'Log')中有效。
/// </summary>
public float logBase
{
get { return m_LogBase; }
set
{
if (value <= 0 || value == 1) value = 10;
if (PropertyUtil.SetStruct(ref m_LogBase, value)) SetAllDirty();
}
}
/// <summary>
/// On the log axis, if base e is the natural number, and is true, logBase fails.
/// 对数轴是否以自然数 e 为底数,为 true 时 logBase 失效。
/// </summary>
public bool logBaseE
{
get { return m_LogBaseE; }
set { if (PropertyUtil.SetStruct(ref m_LogBaseE, value)) SetAllDirty(); }
}
/// <summary>
/// The max number of axis data cache.
/// The first data will be remove when the size of axis data is larger then maxCache.
/// 可缓存的最大数据量。默认为0没有限制,大于0时超过指定值会移除旧数据再插入新数据。
/// </summary>
public int maxCache
{
get { return m_MaxCache; }
set { if (PropertyUtil.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated.
/// 最大最小值向上取整的倍率。默认为0时自动计算。
/// </summary>
public int ceilRate
{
get { return m_CeilRate; }
set { if (PropertyUtil.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// Whether the axis are reversed or not. Invalid in `Category` axis.
/// 是否反向坐标轴。在类目轴中无效。
/// </summary>
public bool inverse
{
get { return m_Inverse; }
set { if (m_Type == AxisType.Value && PropertyUtil.SetStruct(ref m_Inverse, value)) SetAllDirty(); }
}
/// <summary>
/// Whether the positive position of axis is in clockwise. True for clockwise by default.
/// 刻度增长是否按顺时针,默认顺时针。
/// </summary>
public bool clockwise
{
get { return m_Clockwise; }
set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); }
}
/// <summary>
/// Category data, available in type: 'Category' axis.
/// 类目数据,在类目轴(type: 'category')中有效。
/// </summary>
public List<string> data
{
get { return m_Data; }
set { if (value != null) { m_Data = value; SetAllDirty(); } }
}
/// <summary>
/// axis Line.
/// 坐标轴轴线。
/// /// </summary>
public AxisLine axisLine
{
get { return m_AxisLine; }
set { if (value != null) { m_AxisLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis name.
/// 坐标轴名称。
/// </summary>
public AxisName axisName
{
get { return m_AxisName; }
set { if (value != null) { m_AxisName = value; SetComponentDirty(); } }
}
/// <summary>
/// axis tick.
/// 坐标轴刻度。
/// </summary>
public AxisTick axisTick
{
get { return m_AxisTick; }
set { if (value != null) { m_AxisTick = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis label.
/// 坐标轴刻度标签。
/// </summary>
public AxisLabel axisLabel
{
get { return m_AxisLabel; }
set { if (value != null) { m_AxisLabel = value; SetComponentDirty(); } }
}
/// <summary>
/// axis split line.
/// 坐标轴分割线。
/// </summary>
public AxisSplitLine splitLine
{
get { return m_SplitLine; }
set { if (value != null) { m_SplitLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis split area.
/// 坐标轴分割区域。
/// </summary>
public AxisSplitArea splitArea
{
get { return m_SplitArea; }
set { if (value != null) { m_SplitArea = value; SetVerticesDirty(); } }
}
public override bool vertsDirty
{
get { return m_VertsDirty || axisLine.anyDirty || axisTick.anyDirty || splitLine.anyDirty || splitArea.anyDirty; }
}
public override bool componentDirty
{
get { return m_ComponentDirty || axisName.anyDirty || axisLabel.anyDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
axisName.ClearComponentDirty();
axisLabel.ClearComponentDirty();
}
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
axisLine.ClearVerticesDirty();
axisTick.ClearVerticesDirty();
splitLine.ClearVerticesDirty();
splitArea.ClearVerticesDirty();
}
public int index { get; internal set; }
/// <summary>
/// the axis label text list.
/// 坐标轴刻度标签的Text列表。
/// </summary>
public List<ChartText> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } }
/// <summary>
/// the current minimun value.
/// 当前最小值。
/// </summary>
public float runtimeMinValue
{
get { return m_RuntimeMinValue; }
internal set
{
m_RuntimeMinValue = value;
m_RuntimeLastMinValue = value;
m_RuntimeMinValueUpdateTime = Time.time;
m_RuntimeMinValueChanged = true;
}
}
/// <summary>
/// the current maximum value.
/// 当前最大值。
/// </summary>
public float runtimeMaxValue
{
get { return m_RuntimeMaxValue; }
internal set
{
m_RuntimeMaxValue = value;
m_RuntimeLastMaxValue = value;
m_RuntimeMaxValueUpdateTime = Time.time;
m_RuntimeMaxValueChanged = false;
}
}
/// <summary>
/// the x offset of zero position.
/// 坐标轴原点在X轴的偏移。
/// </summary>
public float runtimeZeroXOffset { get; internal set; }
/// <summary>
/// the y offset of zero position.
/// 坐标轴原点在Y轴的偏移。
/// </summary>
public float runtimeZeroYOffset { get; internal set; }
public int runtimeMinLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMinValue) : (int)Mathf.Log(runtimeMinValue, logBase); } }
public int runtimeMaxLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMaxValue) : (int)Mathf.Log(runtimeMaxValue, logBase); } }
internal bool runtimeLastCheckInverse { get; set; }
internal float runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } }
internal List<string> runtimeData { get { return m_RuntimeData; } }
private int filterStart;
private int filterEnd;
private int filterMinShow;
private List<string> filterData;
private List<ChartText> m_AxisLabelTextList = new List<ChartText>();
private GameObject m_TooltipLabel;
private ChartText m_TooltipLabelText;
private RectTransform m_TooltipLabelRect;
private float m_RuntimeMinValue;
private float m_RuntimeLastMinValue;
private bool m_RuntimeMinValueChanged;
private float m_RuntimeMinValueUpdateTime;
private float m_RuntimeMaxValue;
private float m_RuntimeLastMaxValue;
private bool m_RuntimeMaxValueChanged;
private float m_RuntimeMaxValueUpdateTime;
private bool m_RuntimeMinValueFirstChanged = true;
private bool m_RuntimeMaxValueFirstChanged = true;
protected List<string> m_RuntimeData = new List<string>();
public Axis Clone()
{
var axis = new Axis();
axis.show = show;
axis.type = type;
axis.gridIndex = 0;
axis.minMaxType = minMaxType;
axis.min = min;
axis.max = max;
axis.splitNumber = splitNumber;
axis.interval = interval;
axis.boundaryGap = boundaryGap;
axis.maxCache = maxCache;
axis.logBase = logBase;
axis.logBaseE = logBaseE;
axis.ceilRate = ceilRate;
axis.axisLine = axisLine.Clone();
axis.axisName = axisName.Clone();
axis.axisTick = axisTick.Clone();
axis.axisLabel = axisLabel.Clone();
axis.splitLine = splitLine.Clone();
axis.splitArea = splitArea.Clone();
axis.data = new List<string>();
ChartHelper.CopyList(axis.data, data);
return axis;
}
public void Copy(Axis axis)
{
show = axis.show;
type = axis.type;
minMaxType = axis.minMaxType;
gridIndex = axis.gridIndex;
min = axis.min;
max = axis.max;
splitNumber = axis.splitNumber;
interval = axis.interval;
boundaryGap = axis.boundaryGap;
maxCache = axis.maxCache;
logBase = axis.logBase;
logBaseE = axis.logBaseE;
ceilRate = axis.ceilRate;
axisLine.Copy(axis.axisLine);
axisName.Copy(axis.axisName);
axisTick.Copy(axis.axisTick);
axisLabel.Copy(axis.axisLabel);
splitLine.Copy(axis.splitLine);
splitArea.Copy(axis.splitArea);
ChartHelper.CopyList(data, axis.data);
}
/// <summary>
/// 清空类目数据
/// </summary>
public void ClearData()
{
m_Data.Clear();
m_RuntimeData.Clear();
SetAllDirty();
}
/// <summary>
/// 是否为类目轴。
/// </summary>
/// <returns></returns>
public bool IsCategory()
{
return type == AxisType.Category;
}
/// <summary>
/// 是否为数值轴。
/// </summary>
/// <returns></returns>
public bool IsValue()
{
return type == AxisType.Value;
}
/// <summary>
/// 是否为对数轴。
/// </summary>
/// <returns></returns>
public bool IsLog()
{
return type == AxisType.Log;
}
/// <summary>
/// 添加一个类目到类目数据列表
/// </summary>
/// <param name="category"></param>
public void AddData(string category)
{
if (maxCache > 0)
{
while (m_Data.Count > maxCache)
{
m_NeedUpdateFilterData = true;
m_Data.RemoveAt(0);
}
}
m_Data.Add(category);
SetAllDirty();
}
/// <summary>
/// 获得指定索引的类目数据
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public string GetData(int index)
{
if (index >= 0 && index < m_Data.Count)
return m_Data[index];
else
return null;
}
/// <summary>
/// 获得在dataZoom范围内指定索引的类目数据
/// </summary>
/// <param name="index">类目数据索引</param>
/// <param name="dataZoom">区域缩放</param>
/// <returns></returns>
public string GetData(int index, DataZoom dataZoom)
{
var showData = GetDataList(dataZoom);
if (index >= 0 && index < showData.Count)
return showData[index];
else
return "";
}
/// <summary>
/// 获得指定区域缩放的类目数据列表
/// </summary>
/// <param name="dataZoom">区域缩放</param>
/// <returns></returns>
internal List<string> GetDataList(DataZoom dataZoom)
{
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxisIndex(index))
{
UpdateFilterData(dataZoom);
return filterData;
}
else
{
return m_Data.Count > 0 ? m_Data : m_RuntimeData;
}
}
internal List<string> GetDataList(){
return m_Data.Count > 0 ? m_Data : m_RuntimeData;
}
private List<string> emptyFliter = new List<string>();
/// <summary>
/// 更新dataZoom对应的类目数据列表
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateFilterData(DataZoom dataZoom)
{
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxisIndex(index))
{
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
if (endIndex < startIndex) endIndex = startIndex;
if (startIndex != filterStart || endIndex != filterEnd || dataZoom.minShowNum != filterMinShow || m_NeedUpdateFilterData)
{
filterStart = startIndex;
filterEnd = endIndex;
filterMinShow = dataZoom.minShowNum;
m_NeedUpdateFilterData = false;
var data = GetDataList();
if (data.Count > 0)
{
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
if (count < dataZoom.minShowNum)
{
if (dataZoom.minShowNum > data.Count) count = data.Count;
else count = dataZoom.minShowNum;
}
if (startIndex + count > data.Count)
{
int start = endIndex - count;
filterData = data.GetRange(start < 0 ? 0 : start, count);
}
else filterData = data.GetRange(startIndex, count);
}
else
{
filterData = data;
}
}
else if (endIndex == 0)
{
filterData = emptyFliter;
}
}
}
/// <summary>
/// 获得类目数据个数
/// </summary>
/// <param name="dataZoom"></param>
/// <returns></returns>
internal int GetDataNumber(DataZoom dataZoom)
{
return GetDataList(dataZoom).Count;
}
/// <summary>
/// 更新刻度标签文字
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateLabelText(float coordinateWidth, DataZoom dataZoom, bool forcePercent, float duration)
{
var minValue = GetCurrMinValue(duration);
var maxValue = GetCurrMaxValue(duration);
for (int i = 0; i < axisLabelTextList.Count; i++)
{
if (axisLabelTextList[i] != null)
{
var text = AxisHelper.GetLabelName(this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent);
axisLabelTextList[i].SetText(text);
}
}
}
internal void SetTooltipLabel(GameObject label)
{
m_TooltipLabel = label;
m_TooltipLabelRect = label.GetComponent<RectTransform>();
m_TooltipLabelText = new ChartText(label);
ChartHelper.SetActive(m_TooltipLabel, true);
}
internal void SetTooltipLabelColor(Color bgColor, Color textColor)
{
m_TooltipLabel.GetComponent<Image>().color = bgColor;
m_TooltipLabelText.SetColor(textColor);
}
internal void SetTooltipLabelActive(bool flag)
{
ChartHelper.SetActive(m_TooltipLabel, flag);
}
internal void UpdateTooptipLabelText(string text)
{
if (m_TooltipLabelText != null)
{
m_TooltipLabelText.SetText(text);
m_TooltipLabelRect.sizeDelta = new Vector2(m_TooltipLabelText.GetPreferredWidth() + 8,
m_TooltipLabelText.GetPreferredHeight() + 8);
}
}
internal void UpdateTooltipLabelPos(Vector2 pos)
{
if (m_TooltipLabel)
{
m_TooltipLabel.transform.localPosition = pos;
}
}
internal void UpdateMinValue(float value, bool check)
{
if (value != m_RuntimeMaxValue)
{
if (check && Application.isPlaying)
{
if (m_RuntimeMinValueFirstChanged)
{
m_RuntimeMinValueFirstChanged = false;
}
else
{
m_RuntimeLastMinValue = m_RuntimeMinValue;
m_RuntimeMinValueChanged = true;
m_RuntimeMinValueUpdateTime = Time.time;
}
m_RuntimeMinValue = value;
}
else
{
m_RuntimeMinValue = value;
m_RuntimeLastMinValue = value;
m_RuntimeMinValueUpdateTime = Time.time;
m_RuntimeMinValueChanged = true;
}
}
}
internal void UpdateMaxValue(float value, bool check)
{
if (value != m_RuntimeMaxValue)
{
if (check && Application.isPlaying)
{
if (m_RuntimeMaxValueFirstChanged)
{
m_RuntimeMaxValueFirstChanged = false;
}
else
{
m_RuntimeLastMaxValue = m_RuntimeMaxValue;
m_RuntimeMaxValueChanged = true;
m_RuntimeMaxValueUpdateTime = Time.time;
}
m_RuntimeMaxValue = value;
}
else
{
m_RuntimeMaxValue = value;
m_RuntimeLastMaxValue = value;
m_RuntimeMaxValueUpdateTime = Time.time;
m_RuntimeMaxValueChanged = false;
}
}
}
internal float GetCurrMinValue(float duration)
{
if (!Application.isPlaying) return m_RuntimeMinValue;
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMinValueChanged) return m_RuntimeMinValue;
var time = Time.time - m_RuntimeMinValueUpdateTime;
if (time == 0) return m_RuntimeMinValue;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
var curr = Mathf.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total);
return curr;
}
else
{
m_RuntimeMinValueChanged = false;
return m_RuntimeMinValue;
}
}
internal float GetCurrMaxValue(float duration)
{
if (!Application.isPlaying) return m_RuntimeMaxValue;
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMaxValueChanged) return m_RuntimeMaxValue;
var time = Time.time - m_RuntimeMaxValueUpdateTime;
if (time == 0) return m_RuntimeMaxValue;
var total = duration / 1000;
if (duration > 0 && time < total)
{
var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
return curr;
}
else
{
m_RuntimeMaxValueChanged = false;
return m_RuntimeMaxValue;
}
}
public bool IsValueChanging(float duration)
{
if (!Application.isPlaying) return false;
if (GetCurrMinValue(duration) != m_RuntimeMinValue || GetCurrMaxValue(duration) != m_RuntimeMaxValue)
{
return true;
}
else
{
return false;
}
}
public float GetLogValue(float value)
{
if (value <= 0 || value == 1) return 0;
return logBaseE ? Mathf.Log(value) : Mathf.Log(value, logBase);
}
public bool IsLeft()
{
return position == AxisPosition.Left;
}
public bool IsRight()
{
return position == AxisPosition.Right;
}
public bool IsTop()
{
return position == AxisPosition.Top;
}
public bool IsBottom()
{
return position == AxisPosition.Bottom;
}
}
/// <summary>
/// The x axis in cartesian(rectangular) coordinate. a grid component can place at most 2 x axis,
/// one on the bottom and another on the top.
/// <para>直角坐标系 grid 中的 x 轴,单个 grid 组件最多只能放上下两个 x 轴。</para>
/// </summary>
[System.Serializable]
public class XAxis : 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_BoundaryGap = true,
m_Position = AxisPosition.Bottom,
m_Offset = 0,
m_Data = new List<string>()
{
"x1","x2","x3","x4","x5"
}
};
axis.splitLine.show = false;
axis.splitLine.lineStyle.type = LineStyle.Type.None;
axis.axisLabel.textLimit.enable = true;
return axis;
}
}
}
/// <summary>
/// The x axis in cartesian(rectangular) coordinate. a grid component can place at most 2 x axis,
/// one on the bottom and another on the top.
/// <para>直角坐标系 grid 中的 y 轴,单个 grid 组件最多只能放左右两个 y 轴</para>
/// </summary>
[System.Serializable]
public class YAxis : 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_BoundaryGap = false,
m_Position = AxisPosition.Left,
m_Data = new List<string>(5),
};
axis.splitLine.show = true;
axis.splitLine.lineStyle.type = LineStyle.Type.None;
axis.axisLabel.textLimit.enable = false;
return axis;
}
}
}
/// <summary>
/// Radial axis of polar coordinate.
/// 极坐标系的径向轴。
/// </summary>
[System.Serializable]
public class RadiusAxis : Axis
{
public static RadiusAxis defaultRadiusAxis
{
get
{
var axis = new RadiusAxis
{
m_Show = true,
m_Type = AxisType.Value,
m_Min = 0,
m_Max = 0,
m_SplitNumber = 5,
m_BoundaryGap = false,
m_Data = new List<string>(5),
};
axis.splitLine.show = true;
axis.splitLine.lineStyle.type = LineStyle.Type.Solid;
axis.axisLabel.textLimit.enable = false;
return axis;
}
}
}
/// <summary>
/// Angle axis of Polar Coordinate.
/// 极坐标系的角度轴。
/// </summary>
[System.Serializable]
public class AngleAxis : Axis
{
[SerializeField] private float m_StartAngle = 90;
/// <summary>
/// Starting angle of axis. 90 degrees by default, standing for top position of center. 0 degree stands for right position of center.
/// 起始刻度的角度,默认为 90 度,即圆心的正上方。0 度为圆心的正右方。
/// </summary>
public float startAngle
{
get { return m_StartAngle; }
set { if (PropertyUtil.SetStruct(ref m_StartAngle, value)) SetAllDirty(); }
}
public float runtimeStartAngle { get; set; }
public static AngleAxis defaultAngleAxis
{
get
{
var axis = new AngleAxis
{
m_Show = true,
m_Type = AxisType.Value,
m_SplitNumber = 12,
m_BoundaryGap = false,
m_Data = new List<string>(12),
};
axis.splitLine.show = true;
axis.splitLine.lineStyle.type = LineStyle.Type.Solid;
axis.axisLabel.textLimit.enable = false;
axis.minMaxType = AxisMinMaxType.Custom;
axis.min = 0;
axis.max = 360;
return axis;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4e87b6a821d94304af45b2955c293bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
using System.Net.Mime;
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// Background component.
/// Due to the limitations of the framework, there are two limitations to the use of background component:
/// 1: The parent node of chart cannot have a layout control class component.
/// 2: The parent node of Chart can only have one child node of the current chart.
///
/// 背景组件。
/// 由于框架的局限性,背景组件使用有以下两个限制:
/// 1:chart的父节点不能有布局控制类组件。
/// 2:chart的父节点只能有当前chart一个子节点。
/// 背景组件的开启需要通过接口来开启:BaseChart.EnableBackground(bool flag)
/// </summary>
[Serializable]
public class Background : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Sprite m_Image;
[SerializeField] private Image.Type m_ImageType;
[SerializeField] private Color m_ImageColor = Color.white;
[SerializeField] private bool m_HideThemeBackgroundColor = true;
/// <summary>
/// Whether to enable the background component. However,
/// the ability to activate the background component is subject to other conditions.
/// 是否启用背景组件。但能否激活背景组件还要受其他条件限制。
/// </summary>
public bool show
{
get { return m_Show; }
internal set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the image of background.
/// 背景图。
/// </summary>
public Sprite image
{
get { return m_Image; }
set { if (PropertyUtil.SetClass(ref m_Image, value)) SetComponentDirty(); }
}
/// <summary>
/// the fill type of background image.
/// 背景图填充类型。
/// </summary>
public Image.Type imageType
{
get { return m_ImageType; }
set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetComponentDirty(); }
}
/// <summary>
/// 背景图颜色。
/// </summary>
public Color imageColor
{
get { return m_ImageColor; }
set { if (PropertyUtil.SetColor(ref m_ImageColor, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to hide the background color set in the theme when the background component is on.
/// 当background组件开启时,是否隐藏主题中设置的背景色。
/// </summary>
public bool hideThemeBackgroundColor
{
get { return m_HideThemeBackgroundColor; }
set { if (PropertyUtil.SetStruct(ref m_HideThemeBackgroundColor, value)) SetVerticesDirty(); }
}
public static Background defaultBackground
{
get
{
var background = new Background
{
m_Show = false,
m_Image = null,
m_ImageType = Image.Type.Sliced,
m_ImageColor = Color.white,
m_HideThemeBackgroundColor = true,
};
return background;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20bad62e2503e49dcacbecdc99542025
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,634 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
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.
///
/// <para>DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息,或者概览数据整体,或者去除离群点的影响。</para>
/// </summary>
[System.Serializable]
public class DataZoom : MainComponent
{
/// <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.
///
/// dataZoom 的运行原理是通过 数据过滤 来达到 数据窗口缩放 的效果。数据过滤模式的设置不同,效果也不同。
/// </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
}
/// <summary>
/// The value type of start and end.取值类型
/// </summary>
public enum RangeMode
{
//Value,
/// <summary>
/// percent value. 百分比
/// </summary>
Percent
}
[SerializeField] private bool m_Enable;
[SerializeField] private FilterMode m_FilterMode;
[SerializeField] private List<int> m_XAxisIndexs = new List<int>() { 0 };
[SerializeField] private List<int> m_YAxisIndexs = new List<int>() { };
[SerializeField] private bool m_SupportInside;
[SerializeField] private bool m_SupportSlider;
[SerializeField] private bool m_SupportSelect;
[SerializeField] private bool m_ShowDataShadow;
[SerializeField] private bool m_ShowDetail;
[SerializeField] private bool m_ZoomLock;
[SerializeField] private bool m_Realtime;
[SerializeField] protected Color32 m_FillerColor;
[SerializeField] protected Color32 m_BorderColor;
[SerializeField] protected float m_BorderWidth;
[SerializeField] protected Color32 m_BackgroundColor;
[SerializeField] private float m_Left;
[SerializeField] private float m_Right;
[SerializeField] private float m_Top;
[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;
[SerializeField] private int m_MinShowNum = 1;
[Range(1f, 20f)]
[SerializeField] private float m_ScrollSensitivity = 1.1f;
[SerializeField] private TextStyle m_TextStyle;
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid);
[SerializeField] private AreaStyle m_AreaStyle = new AreaStyle();
/// <summary>
/// Whether to show dataZoom.
/// 是否显示缩放区域。
/// </summary>
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
}
/// <summary>
/// The mode of data filter.
/// 数据过滤类型。
/// </summary>
public FilterMode filterMode
{
get { return m_FilterMode; }
set { if (PropertyUtil.SetStruct(ref m_FilterMode, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify which xAxis is controlled by the dataZoom.
/// 控制的 x 轴索引列表。
/// </summary>
public List<int> xAxisIndexs
{
get { return m_XAxisIndexs; }
set { if (PropertyUtil.SetClass(ref m_XAxisIndexs, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify which yAxis is controlled by the dataZoom.
/// 控制的 y 轴索引列表。
/// </summary>
public List<int> yAxisIndexs
{
get { return m_YAxisIndexs; }
set { if (PropertyUtil.SetClass(ref m_YAxisIndexs, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether built-in support is supported.
/// Built into the coordinate system to allow the user to zoom in and out of the coordinate system by mouse dragging,
/// mouse wheel, finger swiping (on the touch screen).
///
/// 是否支持内置。内置于坐标系中,使用户可以在坐标系上通过鼠标拖拽、鼠标滚轮、手指滑动(触屏上)来缩放或漫游坐标系。
/// </summary>
public bool supportInside
{
get { return m_SupportInside; }
set { if (PropertyUtil.SetStruct(ref m_SupportInside, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether a slider is supported. There are separate sliders on which the user zooms or roams.
/// 是否支持滑动条。有单独的滑动条,用户在滑动条上进行缩放或漫游。
/// </summary>
public bool supportSlider
{
get { return m_SupportSlider; }
set { if (PropertyUtil.SetStruct(ref m_SupportSlider, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否支持框选。提供一个选框进行数据区域缩放。
/// </summary>
private bool supportSelect
{
get { return m_SupportSelect; }
set { if (PropertyUtil.SetStruct(ref m_SupportSelect, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show data shadow, to indicate the data tendency in brief.
/// default:true
/// 是否显示数据阴影。数据阴影可以简单地反应数据走势。
/// </summary>
public bool showDataShadow
{
get { return m_ShowDataShadow; }
set { if (PropertyUtil.SetStruct(ref m_ShowDataShadow, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show detail, that is, show the detailed data information when dragging.
/// 是否显示detail,即拖拽时候显示详细数值信息。
/// [default: false]
/// </summary>
public bool showDetail
{
get { return m_ShowDetail; }
set { if (PropertyUtil.SetStruct(ref m_ShowDetail, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify whether to lock the size of window (selected area).
/// default:false
/// 是否锁定选择区域(或叫做数据窗口)的大小。
/// 如果设置为 true 则锁定选择区域的大小,也就是说,只能平移,不能缩放。
/// </summary>
public bool zoomLock
{
get { return m_ZoomLock; }
set { if (PropertyUtil.SetStruct(ref m_ZoomLock, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief.
/// default:true
/// 拖动时,是否实时更新系列的视图。如果设置为 false,则只在拖拽结束的时候更新。默认为true,暂不支持修改。
/// </summary>
public bool realtime { get { return true; } }
/// <summary>
/// The background color of the component.
/// 组件的背景颜色。
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of dataZoom data area.
/// 数据区域颜色。
/// </summary>
public Color32 fillerColor
{
get { return m_FillerColor; }
set { if (PropertyUtil.SetColor(ref m_FillerColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of dataZoom border.
/// 边框颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetComponentDirty(); }
}
/// <summary>
/// 边框宽。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// Distance between dataZoom component and the bottom side of the container.
/// bottom value is a instant pixel value like 10 or float value [0-1].
/// default:10
/// 组件离容器下侧的距离。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetVerticesDirty(); }
}
/// <summary>
/// Distance between dataZoom component and the top side of the container.
/// top value is a instant pixel value like 10 or float value [0-1].
/// default:10
/// 组件离容器上侧的距离。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetVerticesDirty(); }
}
/// <summary>
/// Distance between dataZoom component and the left side of the container.
/// left value is a instant pixel value like 10 or float value [0-1].
/// default:10
/// 组件离容器左侧的距离。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetVerticesDirty(); }
}
/// <summary>
/// Distance between dataZoom component and the right side of the container.
/// right value is a instant pixel value like 10 or float value [0-1].
/// default:10
/// 组件离容器右侧的距离。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetVerticesDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_RangeMode, value)) SetVerticesDirty(); }
}
/// <summary>
/// The start percentage of the window out of the data extent, in the range of 0 ~ 100.
/// [default:30].
/// 数据窗口范围的起始百分比。范围是:0 ~ 100。
/// </summary>
public float start
{
get { return m_Start; }
set { m_Start = value; if (m_Start < 0) m_Start = 0; if (m_Start > 100) m_Start = 100; SetVerticesDirty(); }
}
/// <summary>
/// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
/// default:70
/// 数据窗口范围的结束百分比。范围是:0 ~ 100。
/// </summary>
public float end
{
get { return m_End; }
set { m_End = value; if (m_End < 0) m_End = 0; if (m_End > 100) m_End = 100; SetVerticesDirty(); }
}
/// <summary>
/// Minimum number of display data. Minimum number of data displayed when DataZoom is enlarged to maximum.
/// 最小显示数据个数。当DataZoom放大到最大时,最小显示的数据个数。
/// </summary>
public int minShowNum
{
get { return m_MinShowNum; }
set { if (PropertyUtil.SetStruct(ref m_MinShowNum, value)) SetVerticesDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_ScrollSensitivity, value)) SetVerticesDirty(); }
}
/// <summary>
/// font style.
/// 文字格式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// 阴影线条样式。
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// 阴影填充样式。
/// </summary>
public AreaStyle areaStyle
{
get { return m_AreaStyle; }
set { if (PropertyUtil.SetClass(ref m_AreaStyle, value)) SetComponentDirty(); }
}
public int index { get; internal set; }
public float runtimeX { get; private set; }
public float runtimeY { get; private set; }
public float runtimeWidth { get; private set; }
public float runtimeHeight { get; private set; }
class AxisIndexValueInfo
{
public float min;
public float max;
}
private Dictionary<int, AxisIndexValueInfo> m_XAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
private Dictionary<int, AxisIndexValueInfo> m_YAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
/// <summary>
/// The start label.
/// 组件的开始信息文本。
/// </summary>
private ChartText m_StartLabel { get; set; }
/// <summary>
/// The end label.
/// 组件的结束信息文本。
/// </summary>
private ChartText m_EndLabel { get; set; }
public static DataZoom defaultDataZoom
{
get
{
return new DataZoom()
{
supportInside = true,
supportSlider = true,
filterMode = FilterMode.None,
xAxisIndexs = new List<int>() { 0 },
yAxisIndexs = new List<int>() { },
showDataShadow = true,
showDetail = false,
zoomLock = false,
m_Bottom = 10,
m_Left = 10,
m_Right = 10,
m_Top = 0.9f,
rangeMode = RangeMode.Percent,
start = 30,
end = 70,
m_ScrollSensitivity = 10,
m_TextStyle = new TextStyle(),
m_LineStyle = new LineStyle(LineStyle.Type.Solid)
{
opacity = 0.3f
},
m_AreaStyle = new AreaStyle()
{
show = true,
opacity = 0.3f,
},
};
}
}
/// <summary>
/// 给定的坐标是否在缩放区域内
/// </summary>
/// <param name="pos"></param>
/// <param name="startX"></param>
/// <param name="width"></param>
/// <returns></returns>
public bool IsInZoom(Vector2 pos)
{
if (pos.x < runtimeX - 1 || pos.x > runtimeX + runtimeWidth + 1 ||
pos.y < runtimeY - 1 || pos.y > runtimeY + runtimeHeight + 1)
{
return false;
}
return false;
}
/// <summary>
/// 给定的坐标是否在选中区域内
/// </summary>
/// <param name="pos"></param>
/// <param name="startX"></param>
/// <param name="width"></param>
/// <returns></returns>
public bool IsInSelectedZoom(Vector2 pos)
{
var start = runtimeX + runtimeWidth * m_Start / 100;
var end = runtimeX + runtimeWidth * m_End / 100;
Rect rect = Rect.MinMaxRect(start, runtimeY, end, runtimeY + runtimeHeight);
return rect.Contains(pos);
}
/// <summary>
/// 给定的坐标是否在开始活动条触发区域内
/// </summary>
/// <param name="pos"></param>
/// <param name="startX"></param>
/// <param name="width"></param>
/// <returns></returns>
public bool IsInStartZoom(Vector2 pos)
{
var start = runtimeX + runtimeWidth * m_Start / 100;
Rect rect = Rect.MinMaxRect(start - 10, runtimeY, start + 10, runtimeY + runtimeHeight);
return rect.Contains(pos);
}
/// <summary>
/// 给定的坐标是否在结束活动条触发区域内
/// </summary>
/// <param name="pos"></param>
/// <param name="startX"></param>
/// <param name="width"></param>
/// <returns></returns>
public bool IsInEndZoom(Vector2 pos)
{
var end = runtimeX + runtimeWidth * m_End / 100;
Rect rect = Rect.MinMaxRect(end - 10, runtimeY, end + 10, runtimeY + runtimeHeight);
return rect.Contains(pos);
}
public bool IsContainsAxisIndex(int index)
{
return xAxisIndexs.Contains(index);// || yAxisIndexs.Contains(index);
}
public Color32 GetFillerColor(Color32 themeColor)
{
if (ChartHelper.IsClearColor(fillerColor)) return themeColor;
else return fillerColor;
}
public Color32 GetBackgroundColor(Color32 themeColor)
{
if (ChartHelper.IsClearColor(backgroundColor)) return themeColor;
else return backgroundColor;
}
public Color32 GetBorderColor(Color32 themeColor)
{
if (ChartHelper.IsClearColor(borderColor)) return themeColor;
else return borderColor;
}
/// <summary>
/// 是否显示文本
/// </summary>
/// <param name="flag"></param>
internal void SetLabelActive(bool flag)
{
if (m_StartLabel != null && m_StartLabel.gameObject.activeInHierarchy != flag)
{
m_StartLabel.gameObject.SetActive(flag);
}
if (m_EndLabel != null && m_EndLabel.gameObject.activeInHierarchy != flag)
{
m_EndLabel.gameObject.SetActive(flag);
}
}
/// <summary>
/// 设置开始文本内容
/// </summary>
/// <param name="text"></param>
internal void SetStartLabelText(string text)
{
if (m_StartLabel != null) m_StartLabel.SetText(text);
}
/// <summary>
/// 设置结束文本内容
/// </summary>
/// <param name="text"></param>
internal void SetEndLabelText(string text)
{
if (m_EndLabel != null) m_EndLabel.SetText(text);
}
internal void SetStartLabel(ChartText startLabel)
{
m_StartLabel = startLabel;
}
internal void SetEndLabel(ChartText endLabel)
{
m_EndLabel = endLabel;
}
internal void UpdateStartLabelPosition(Vector3 pos)
{
m_StartLabel.SetLocalPosition(pos);
}
internal void UpdateEndLabelPosition(Vector3 pos)
{
m_EndLabel.SetLocalPosition(pos);
}
internal void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
{
var runtimeLeft = left <= 1 ? left * chartWidth : left;
var runtimeBottom = bottom <= 1 ? bottom * chartHeight : bottom;
var runtimeTop = top <= 1 ? top * chartHeight : top;
var runtimeRight = right <= 1 ? right * chartWidth : right;
runtimeX = chartX + runtimeLeft;
runtimeY = chartY + runtimeBottom;
runtimeWidth = chartWidth - runtimeLeft - runtimeRight;
runtimeHeight = chartHeight - runtimeTop - runtimeBottom;
}
internal void SetXAxisIndexValueInfo(int xAxisIndex, float min, float max)
{
if (!m_XAxisIndexInfos.ContainsKey(xAxisIndex))
{
m_XAxisIndexInfos[xAxisIndex] = new AxisIndexValueInfo()
{
min = min,
max = max
};
}
else
{
m_XAxisIndexInfos[xAxisIndex].min = min;
m_XAxisIndexInfos[xAxisIndex].max = max;
}
}
internal void SetYAxisIndexValueInfo(int yAxisIndex, float min, float max)
{
if (!m_YAxisIndexInfos.ContainsKey(yAxisIndex))
{
m_YAxisIndexInfos[yAxisIndex] = new AxisIndexValueInfo()
{
min = min,
max = max
};
}
else
{
m_YAxisIndexInfos[yAxisIndex].min = min;
m_YAxisIndexInfos[yAxisIndex].max = max;
}
}
internal bool IsXAxisIndexValue(int axisIndex)
{
return m_XAxisIndexInfos.ContainsKey(axisIndex);
}
internal bool IsYAxisIndexValue(int axisIndex)
{
return m_YAxisIndexInfos.ContainsKey(axisIndex);
}
internal void GetXAxisIndexValue(int axisIndex, out float min, out float max)
{
min = 0;
max = 0;
if (m_XAxisIndexInfos.ContainsKey(axisIndex))
{
var info = m_XAxisIndexInfos[axisIndex];
min = info.min;
max = info.max;
}
}
internal void GetYAxisIndexValue(int axisIndex, out float min, out float max)
{
min = 0;
max = 0;
if (m_YAxisIndexInfos.ContainsKey(axisIndex))
{
var info = m_YAxisIndexInfos[axisIndex];
min = info.min;
max = info.max;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2aa26f9acb5344a59c924a1f23f90d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,458 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Legend component.The legend component shows different sets of tags, colors, and names.
/// You can control which series are not displayed by clicking on the legend.
/// 图例组件。
/// 图例组件展现了不同系列的标记,颜色和名字。可以通过点击图例控制哪些系列不显示。
/// </summary>
[System.Serializable]
public class Legend : MainComponent, IPropertyChanged
{
public enum Type
{
/// <summary>
/// 自动匹配。
/// </summary>
Auto,
/// <summary>
/// 自定义图标。
/// </summary>
Custom,
/// <summary>
/// 空心圆。
/// </summary>
EmptyCircle,
/// <summary>
/// 圆形。
/// </summary>
Circle,
/// <summary>
/// 正方形。可通过Setting的legendIconCornerRadius参数调整圆角。
/// </summary>
Rect,
/// <summary>
/// 三角形。
/// </summary>
Triangle,
/// <summary>
/// 菱形。
/// </summary>
Diamond,
}
/// <summary>
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
/// 图例选择的模式,控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
/// </summary>
public enum SelectedMode
{
/// <summary>
/// 多选。
/// </summary>
Multiple,
/// <summary>
/// 单选。
/// </summary>
Single,
/// <summary>
/// 无法选择。
/// </summary>
None
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_IconType;
[SerializeField] private SelectedMode m_SelectedMode;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultRight;
[SerializeField] private float m_ItemWidth = 25.0f;
[SerializeField] private float m_ItemHeight = 12.0f;
[SerializeField] private float m_ItemGap = 10f;
[SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private string m_Formatter;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
[SerializeField] private List<string> m_Data = new List<string>();
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
private Dictionary<string, LegendItem> m_DataBtnList = new Dictionary<string, LegendItem>();
private Dictionary<int, float> m_RuntimeEachWidth = new Dictionary<int, float>();
/// <summary>
/// Whether to show legend component.
/// 是否显示图例组件。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// Type of legend.
/// 图例类型。
/// [default:Type.Auto]
/// </summary>
public Type iconType
{
get { return m_IconType; }
set { if (PropertyUtil.SetStruct(ref m_IconType, value)) SetAllDirty(); }
}
/// <summary>
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
/// 选择模式。控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
/// [default:SelectedMode.Multiple]
/// </summary>
public SelectedMode selectedMode
{
get { return m_SelectedMode; }
set { if (PropertyUtil.SetStruct(ref m_SelectedMode, value)) SetComponentDirty(); }
}
/// <summary>
/// Specify whether the layout of legend component is horizontal or vertical.
/// 布局方式是横还是竖。
/// [default:Orient.Horizonal]
/// </summary>
public Orient orient
{
get { return m_Orient; }
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetComponentDirty(); }
}
/// <summary>
/// The location of legend.
/// 图例显示的位置。
/// [default:Location.defaultTop]
/// </summary>
public Location location
{
get { return m_Location; }
set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); }
}
/// <summary>
/// Image width of legend symbol.
/// 图例标记的图形宽度。
/// [default:24f]
/// </summary>
public float itemWidth
{
get { return m_ItemWidth; }
set { if (PropertyUtil.SetStruct(ref m_ItemWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// Image height of legend symbol.
/// 图例标记的图形高度。
/// [default:12f]
/// </summary>
public float itemHeight
{
get { return m_ItemHeight; }
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// The distance between each legend, horizontal distance in horizontal layout, and vertical distance in vertical layout.
/// 图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。
/// [default:10f]
/// </summary>
public float itemGap
{
get { return m_ItemGap; }
set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether the legend symbol matches the color automatically.
/// 图例标记的图形是否自动匹配颜色。
/// [default:true]
/// </summary>
public bool itemAutoColor
{
get { return m_ItemAutoColor; }
set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
}
/// <summary>
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}.
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {name}。
/// [default:null]
/// </summary>
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
/// the style of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// Data array of legend. An array item is usually a name representing string. (If it is a pie chart,
/// it could also be the name of a single data in the pie chart) of a series.
/// If data is not specified, it will be auto collected from series.
/// 图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 name(如果是饼图,也可以是饼图单个数据的 name)。
/// 如果 data 没有被指定,会自动从当前系列中获取。指定data时里面的数据项和serie匹配时才会生效。
/// </summary>
public List<string> data
{
get { return m_Data; }
set { if (value != null) { m_Data = value; SetComponentDirty(); } }
}
/// <summary>
/// 自定义的图例标记图形。
/// </summary>
public List<Sprite> icons
{
get { return m_Icons; }
set { if (value != null) { m_Icons = value; SetComponentDirty(); } }
}
public int index { get; internal set; }
/// <summary>
/// 图表是否需要刷新(图例组件不需要刷新图表)
/// </summary>
public override bool vertsDirty { get { return false; } }
/// <summary>
/// 组件是否需要刷新
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
/// <summary>
/// the button list of legend.
/// 图例按钮列表。
/// </summary>
/// <value></value>
public Dictionary<string, LegendItem> buttonList { get { return m_DataBtnList; } }
/// <summary>
/// 运行时图例的总宽度
/// </summary>
public float runtimeWidth { get; internal set; }
/// <summary>
/// 运行时图例的总高度
/// </summary>
public float runtimeHeight { get; internal set; }
/// <summary>
/// 多列时每列的宽度
/// </summary>
public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; } }
/// <summary>
/// 单列高度
/// </summary>
public float runtimeEachHeight { get; internal set; }
/// <summary>
/// 一个在顶部居中显示的默认图例。
/// </summary>
public static Legend defaultLegend
{
get
{
var legend = new Legend
{
m_IconType = Type.Auto,
m_Show = false,
m_SelectedMode = SelectedMode.Multiple,
m_Orient = Orient.Horizonal,
m_Location = Location.defaultTop,
m_ItemWidth = 25.0f,
m_ItemHeight = 12.0f,
m_ItemGap = 10f,
};
legend.location.top = 35;
legend.textStyle.offset = new Vector2(2, 0);
legend.textStyle.fontSize = 0;
return legend;
}
}
/// <summary>
/// Clear legend data.
/// 清空。
/// </summary>
public void ClearData()
{
m_Data.Clear();
SetComponentDirty();
}
/// <summary>
/// Whether include in legend data by the specified name.
/// 是否包括由指定名字的图例
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool ContainsData(string name)
{
return m_Data.Contains(name);
}
/// <summary>
/// Removes the legend with the specified name.
/// 移除指定名字的图例。
/// </summary>
/// <param name="name"></param>
public void RemoveData(string name)
{
if (m_Data.Contains(name))
{
m_Data.Remove(name);
SetComponentDirty();
}
}
/// <summary>
/// Add legend data.
/// 添加图例。
/// </summary>
/// <param name="name"></param>
public void AddData(string name)
{
if (!m_Data.Contains(name) && !string.IsNullOrEmpty(name))
{
m_Data.Add(name);
SetComponentDirty();
}
}
/// <summary>
/// Gets the legend for the specified index.
/// 获得指定索引的图例。
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public string GetData(int index)
{
if (index >= 0 && index < m_Data.Count)
{
return m_Data[index];
}
return null;
}
/// <summary>
/// Gets the index of the specified legend.
/// 获得指定图例的索引。
/// </summary>
/// <param name="legendName"></param>
/// <returns></returns>
public int GetIndex(string legendName)
{
return m_Data.IndexOf(legendName);
}
/// <summary>
/// Remove all legend buttons.
/// 移除所有图例按钮。
/// </summary>
public void RemoveButton()
{
m_DataBtnList.Clear();
}
/// <summary>
/// Bind buttons to legends.
/// 给图例绑定按钮。
/// </summary>
/// <param name="name"></param>
/// <param name="btn"></param>
/// <param name="total"></param>
public void SetButton(string name, LegendItem item, int total)
{
m_DataBtnList[name] = item;
int index = m_DataBtnList.Values.Count;
item.SetIconActive(iconType == Type.Custom);
item.SetActive(show);
}
/// <summary>
/// Update the legend button color.
/// 更新图例按钮颜色。
/// </summary>
/// <param name="name"></param>
/// <param name="color"></param>
public void UpdateButtonColor(string name, Color color)
{
if (m_DataBtnList.ContainsKey(name))
{
m_DataBtnList[name].SetIconColor(color);
}
}
/// <summary>
/// Update the text color of legend.
/// 更新图例文字颜色。
/// </summary>
/// <param name="name"></param>
/// <param name="color"></param>
public void UpdateContentColor(string name, Color color)
{
if (m_DataBtnList.ContainsKey(name))
{
m_DataBtnList[name].SetContentColor(color);
}
}
/// <summary>
/// Gets the legend button for the specified index.
/// 获得指定索引的图例按钮。
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public Sprite GetIcon(int index)
{
if (index >= 0 && index < m_Icons.Count)
{
return m_Icons[index];
}
else
{
return null;
}
}
/// <summary>
/// Callback handling when parameters change.
/// 参数变更时的回调处理。
/// </summary>
public void OnChanged()
{
m_Location.OnChanged();
}
/// <summary>
/// 获得图例格式化后的显示内容。
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
public string GetFormatterContent(string category)
{
if (string.IsNullOrEmpty(m_Formatter))
return category;
else
{
var content = m_Formatter.Replace("{name}", category);
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a708805f5d8147b3b9a90b2f1d38e75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,94 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Polar coordinate can be used in scatter and line chart. Every polar coordinate has an angleAxis and a radiusAxis.
/// <para>
/// 极坐标系组件。
/// 极坐标系,可以用于散点图和折线图。每个极坐标系拥有一个角度轴和一个半径轴。
/// </para>
/// </summary>
[Serializable]
public class Polar : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private float m_Radius = 100;
[SerializeField] private Color m_BackgroundColor;
/// <summary>
/// Whether to show the polor component.
/// 是否显示极坐标。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// [default:[0.5f,0.45f]]The center of ploar. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 极坐标的中心点。数组的第一项是横坐标,第二项是纵坐标。
/// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
/// </summary>
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
/// [default:0.35f]the radius of polar.
/// 极坐标的半径。
/// </summary>
public float radius
{
get { return m_Radius; }
set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); }
}
/// <summary>
/// [default:Color.clear]Background color of polar, which is transparent by default.
/// 极坐标的背景色,默认透明。
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
public int index { get; internal set; }
/// <summary>
/// the center position of polar in container.
/// 极坐标在容器中的具体中心点。
/// </summary>
public Vector3 runtimeCenterPos { get; internal set; }
/// <summary>
/// the true radius of polar.
/// 极坐标的运行时实际半径。
/// </summary>
public float runtimeRadius { get; internal set; }
public static Polar defaultPolar
{
get
{
var polar = new Polar
{
m_Show = true,
m_Radius = 0.35f,
};
polar.center[0] = 0.5f;
polar.center[1] = 0.45f;
return polar;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9eb9ba0a1d154f11ba169fc07ad7a91
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,377 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using System.Collections.Generic;
using System;
using System.Text.RegularExpressions;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// Radar coordinate conponnet for radar charts.
/// 雷达图坐标系组件,只适用于雷达图。
/// </summary>
[System.Serializable]
public class Radar : MainComponent
{
/// <summary>
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
/// </summary>
public enum Shape
{
Polygon,
Circle
}
/// <summary>
/// The position type of radar.
/// 显示位置。
/// </summary>
public enum PositionType
{
/// <summary>
/// Display at the vertex.
/// 显示在顶点处。
/// </summary>
Vertice,
/// <summary>
/// Display at the middle of line.
/// 显示在两者之间。
/// </summary>
Between,
}
/// <summary>
/// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
/// </summary>
[System.Serializable]
public class Indicator
{
[SerializeField] private string m_Name;
[SerializeField] private float m_Max;
[SerializeField] private float m_Min;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// The name of indicator.
/// 指示器名称。
/// </summary>
public string name { get { return FormatterHelper.TrimAndReplaceLine(m_Name); } set { m_Name = value; } }
/// <summary>
/// The maximum value of indicator, with default value of 0, but we recommend to set it manually.
/// 指示器的最大值,默认为 0 无限制。
/// </summary>
public float max { get { return m_Max; } set { m_Max = value; } }
/// <summary>
/// The minimum value of indicator, with default value of 0.
/// 指示器的最小值,默认为 0 无限制。
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
/// <summary>
/// the style of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
/// <summary>
/// the text conponent of indicator.
/// 指示器的文本组件。
/// </summary>
public Text text { get; set; }
}
[SerializeField] private bool m_Show;
[SerializeField] private Shape m_Shape;
[SerializeField] private float m_Radius = 100;
[SerializeField] private int m_SplitNumber = 5;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] private AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] private bool m_Indicator = true;
[SerializeField] private PositionType m_PositionType = PositionType.Vertice;
[SerializeField] private float m_IndicatorGap = 10;
[SerializeField] private int m_CeilRate = 0;
[SerializeField] private bool m_IsAxisTooltip;
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
/// <summary>
/// [default:true]
/// Set this to false to prevent the radar from showing.
/// 是否显示雷达坐标系组件。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
/// </summary>
/// <value></value>
public Shape shape
{
get { return m_Shape; }
set { if (PropertyUtil.SetStruct(ref m_Shape, value)) SetAllDirty(); }
}
/// <summary>
/// the radius of radar.
/// 雷达图的半径。
/// </summary>
public float radius
{
get { return m_Radius; }
set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); }
}
/// <summary>
/// Segments of indicator axis.
/// 指示器轴的分割段数。
/// </summary>
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
/// <summary>
/// the center of radar chart.
/// 雷达图的中心点。数组的第一项是横坐标,第二项是纵坐标。
/// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
/// </summary>
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
/// axis line.
/// 轴线。
/// </summary>
public AxisLine axisLine
{
get { return m_AxisLine; }
set { if (PropertyUtil.SetClass(ref m_AxisLine, value, true)) SetAllDirty(); }
}
/// <summary>
/// split line.
/// 分割线。
/// </summary>
public AxisSplitLine splitLine
{
get { return m_SplitLine; }
set { if (PropertyUtil.SetClass(ref m_SplitLine, value, true)) SetAllDirty(); }
}
/// <summary>
/// Split area of axis in grid area.
/// 分割区域。
/// </summary>
public AxisSplitArea splitArea
{
get { return m_SplitArea; }
set { if (PropertyUtil.SetClass(ref m_SplitArea, value, true)) SetAllDirty(); }
}
/// <summary>
/// Whether to show indicator.
/// 是否显示指示器。
/// </summary>
public bool indicator
{
get { return m_Indicator; }
set { if (PropertyUtil.SetStruct(ref m_Indicator, value)) SetComponentDirty(); }
}
/// <summary>
/// The gap of indicator and radar.
/// 指示器和雷达的间距。
/// </summary>
public float indicatorGap
{
get { return m_IndicatorGap; }
set { if (PropertyUtil.SetStruct(ref m_IndicatorGap, value)) SetComponentDirty(); }
}
/// <summary>
/// The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated.
/// 最大最小值向上取整的倍率。默认为0时自动计算。
/// </summary>
public int ceilRate
{
get { return m_CeilRate; }
set { if (PropertyUtil.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// 是否Tooltip显示轴线上的所有数据。
/// </summary>
public bool isAxisTooltip
{
get { return m_IsAxisTooltip; }
set { if (PropertyUtil.SetStruct(ref m_IsAxisTooltip, value)) SetAllDirty(); }
}
/// <summary>
/// The position type of indicator.
/// 显示位置类型。
/// </summary>
public PositionType positionType
{
get { return m_PositionType; }
set { if (PropertyUtil.SetStruct(ref m_PositionType, value)) SetAllDirty(); }
}
/// <summary>
/// the indicator list.
/// 指示器列表。
/// </summary>
public List<Indicator> indicatorList { get { return m_IndicatorList; } }
public int index { get; internal set; }
/// <summary>
/// the center position of radar in container.
/// 雷达图在容器中的具体中心点。
/// </summary>
public Vector3 runtimeCenterPos { get; internal set; }
/// <summary>
/// the true radius of radar.
/// 雷达图的运行时实际半径。
/// </summary>
public float runtimeRadius { get; internal set; }
public float runtimeDataRadius { get; internal set; }
/// <summary>
/// the data position list of radar.
/// 雷达图的所有数据坐标点列表。
/// </summary>
public Dictionary<int, List<Vector3>> runtimeDataPosList = new Dictionary<int, List<Vector3>>();
public static Radar defaultRadar
{
get
{
var radar = new Radar
{
m_Show = true,
m_Shape = Shape.Polygon,
m_Radius = 0.35f,
m_SplitNumber = 5,
m_Indicator = true,
m_IndicatorList = new List<Indicator>(5){
new Indicator(){name="indicator1",max = 0},
new Indicator(){name="indicator2",max = 0},
new Indicator(){name="indicator3",max = 0},
new Indicator(){name="indicator4",max = 0},
new Indicator(){name="indicator5",max = 0},
}
};
radar.center[0] = 0.5f;
radar.center[1] = 0.4f;
radar.splitLine.show = true;
radar.splitArea.show = true;
return radar;
}
}
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 float GetIndicatorMin(int index)
{
if (index >= 0 && index < m_IndicatorList.Count)
{
return m_IndicatorList[index].min;
}
return 0;
}
public float GetIndicatorMax(int index)
{
if (index >= 0 && index < m_IndicatorList.Count)
{
return m_IndicatorList[index].max;
}
return 0;
}
internal void UpdateRadarCenter(Vector3 chartPosition, float chartWidth, float chartHeight)
{
if (center.Length < 2) return;
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
if (radius <= 0)
{
runtimeRadius = 0;
}
else if (radius <= 1)
{
runtimeRadius = Mathf.Min(chartWidth, chartHeight) * radius;
}
else
{
runtimeRadius = radius;
}
if (shape == Radar.Shape.Polygon && positionType == PositionType.Between)
{
var angle = Mathf.PI / indicatorList.Count;
runtimeDataRadius = runtimeRadius * Mathf.Cos(angle);
}
else
{
runtimeDataRadius = runtimeRadius;
}
}
public Vector3 GetIndicatorPosition(int index)
{
int indicatorNum = indicatorList.Count;
var angle = 0f;
switch (positionType)
{
case PositionType.Vertice:
angle = 2 * Mathf.PI / indicatorNum * index;
break;
case PositionType.Between:
angle = 2 * Mathf.PI / indicatorNum * (index + 0.5f);
break;
}
var x = runtimeCenterPos.x + (runtimeRadius + indicatorGap) * Mathf.Sin(angle);
var y = runtimeCenterPos.y + (runtimeRadius + indicatorGap) * Mathf.Cos(angle);
return new Vector3(x, y);
}
public void AddIndicator(Radar.Indicator indicator)
{
indicatorList.Add(indicator);
SetAllDirty();
}
public Radar.Indicator AddIndicator(string name, float min, float max)
{
var indicator = new Radar.Indicator();
indicator.name = name;
indicator.min = min;
indicator.max = max;
indicatorList.Add(indicator);
SetAllDirty();
return indicator;
}
public bool UpdateIndicator(int indicatorIndex, string name, float min, float max)
{
var indicator = GetIndicator(indicatorIndex);
if (indicator == null) return false;
indicator.name = name;
indicator.min = min;
indicator.max = max;
SetAllDirty();
return true;
}
public Radar.Indicator GetIndicator(int indicatorIndex)
{
if (indicatorIndex < 0 || indicatorIndex > indicatorList.Count - 1) return null;
return indicatorList[indicatorIndex];
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0874fd6b295f24cdb8b3cedb1faaa40f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aa9c09045961a4ea9a34a098f099f2a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,724 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using System.Collections.Generic;
using System;
namespace XCharts
{
/// <summary>
/// the list of series.
/// 系列列表。每个系列通过 type 决定自己的图表类型。
/// </summary>
[System.Serializable]
public class Series : MainComponent
{
[SerializeField] protected List<Serie> m_Series;
[NonSerialized] private bool m_LabelDirty;
/// <summary>
/// the list of serie
/// 系列列表。
/// </summary>
public List<Serie> list { get { return m_Series; } }
/// <summary>
/// the size of serie list.
/// 系列个数。
/// </summary>
public int Count { get { return m_Series.Count; } }
public bool labelDirty { get { return m_LabelDirty; } set { m_LabelDirty = value; } }
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 override bool vertsDirty
{
get
{
if (m_VertsDirty) return true;
foreach (var serie in m_Series)
{
if (serie.vertsDirty) return true;
}
return false;
}
}
public void SetLabelDirty()
{
m_LabelDirty = true;
}
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
foreach (var serie in m_Series)
{
serie.ClearVerticesDirty();
}
}
internal void ClearLabelDirty()
{
m_LabelDirty = false;
foreach (var serie in m_Series)
{
serie.label.ClearVerticesDirty();
}
}
public override void SetAllDirty()
{
base.SetAllDirty();
SetLabelDirty();
}
public override void ClearDirty()
{
base.ClearDirty();
ClearLabelDirty();
SeriesHelper.ClearNameDirty(this);
}
/// <summary>
/// 清空所有系列的数据
/// </summary>
public void ClearData()
{
AnimationFadeIn();
foreach (var serie in m_Series)
{
serie.ClearData();
}
}
/// <summary>
/// 获得指定序列指定索引的数据值
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <returns></returns>
public float GetData(int serieIndex, int dataIndex)
{
if (serieIndex >= 0 && serieIndex < Count)
{
return m_Series[serieIndex].GetYData(dataIndex);
}
else
{
return 0;
}
}
public float GetCurrData(int serieIndex, int dataIndex)
{
if (serieIndex >= 0 && serieIndex < Count)
{
return m_Series[serieIndex].GetYCurrData(dataIndex);
}
else
{
return 0;
}
}
/// <summary>
/// 获得指定系列名的第一个系列
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public Serie GetSerie(string name)
{
for (int i = 0; i < m_Series.Count; i++)
{
bool match = false;
if (string.IsNullOrEmpty(name))
{
if (string.IsNullOrEmpty(m_Series[i].name)) match = true;
}
else if (name.Equals(m_Series[i].name))
{
match = true;
}
if (match)
{
m_Series[i].index = i;
return m_Series[i];
}
}
return null;
}
/// <summary>
/// 获得指定系列名的所有系列
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 获得指定索引的系列
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public Serie GetSerie(int index)
{
if (index >= 0 && index < m_Series.Count)
{
return m_Series[index];
}
return null;
}
/// <summary>
/// 是否包含指定名字的系列
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
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()
{
AnimationFadeIn();
m_Series.Clear();
}
/// <summary>
/// 添加一个系列到列表中。
/// </summary>
/// <param name="serieName"></param>
/// <param name="type"></param>
/// <param name="show"></param>
/// <returns></returns>
public Serie AddSerie(SerieType type, string serieName, bool show = true)
{
var serie = new Serie();
serie.type = type;
serie.show = show;
serie.name = serieName;
serie.index = m_Series.Count;
if (type == SerieType.Scatter)
{
serie.symbol.show = true;
serie.symbol.type = SerieSymbolType.Circle;
}
else if (type == SerieType.Line)
{
serie.symbol.show = true;
serie.symbol.type = SerieSymbolType.EmptyCircle;
}
else
{
serie.symbol.show = false;
}
serie.animation.Restart();
m_Series.Add(serie);
SetVerticesDirty();
return serie;
}
/// <summary>
/// 添加一个数据到指定系列的维度Y数据中
/// </summary>
/// <param name="serieName"></param>
/// <param name="value"></param>
/// <param name="dataName"></param>
/// <returns>添加成功返回SerieData,否则返回null</returns>
public SerieData AddData(string serieName, float value, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.AddYData(value, dataName);
}
return null;
}
/// <summary>
/// 添加一个数据到指定系列的维度Y中
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
/// <param name="dataName"></param>
/// <returns>添加成功返回SerieData,否则返回null</returns>
public SerieData AddData(int index, float value, string dataName = null)
{
var serie = GetSerie(index);
if (serie != null)
{
return serie.AddYData(value, dataName);
}
return null;
}
/// <summary>
/// 添加[open, close, lowest, highest]数据
/// </summary>
/// <param name="index"></param>
/// <param name="open"></param>
/// <param name="close"></param>
/// <param name="lowest"></param>
/// <param name="heighest"></param>
/// <param name="dataName"></param>
/// <returns></returns>
public SerieData AddData(int index, float open, float close, float lowest, float heighest, string dataName = null)
{
var serie = GetSerie(index);
if (serie != null)
{
return serie.AddData(open, close, lowest, heighest, dataName);
}
return null;
}
public SerieData AddData(string serieName, float open, float close, float lowest, float heighest, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.AddData(open, close, lowest, heighest, dataName);
}
return null;
}
/// <summary>
/// 添加一组数据到指定的系列中
/// </summary>
/// <param name="serieName"></param>
/// <param name="multidimensionalData"></param>
/// <param name="dataName"></param>
/// <returns>添加成功返回SerieData,否则返回null</returns>
public SerieData AddData(string serieName, List<float> multidimensionalData, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.AddData(multidimensionalData, dataName);
}
return null;
}
/// <summary>
/// 添加一组数据到指定的系列中
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="multidimensionalData"></param>
/// <param name="dataName"></param>
/// <returns>添加成功返回SerieData,否则返回null</returns>
public SerieData AddData(int serieIndex, List<float> multidimensionalData, string dataName = null)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.AddData(multidimensionalData, dataName);
}
return null;
}
/// <summary>
/// 添加(x,y)数据到指定的系列中
/// </summary>
/// <param name="serieName"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
/// <param name="dataName"></param>
/// <returns>添加成功返回SerieData,否则返回null</returns>
public SerieData AddXYData(string serieName, float xValue, float yValue, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.AddXYData(xValue, yValue, dataName);
}
return null;
}
/// <summary>
/// 添加(x,y)数据到指定的系列中
/// </summary>
/// <param name="index"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
/// <param name="dataName"></param>
/// <returns>添加成功返回SerieData,否则返回null</returns>
public SerieData AddXYData(int index, float xValue, float yValue, string dataName = null)
{
var serie = GetSerie(index);
if (serie != null)
{
return serie.AddXYData(xValue, yValue, dataName);
}
return null;
}
/// <summary>
/// 更新指定系列的维度Y数据
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
/// <param name="dataIndex"></param>
public bool UpdateData(string serieName, int dataIndex, float value)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateYData(dataIndex, value);
}
return false;
}
/// <summary>
/// 更新指定系列的数据项名称
/// </summary>
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="dataName"></param>
public bool UpdateDataName(string serieName, int dataIndex, string dataName)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateDataName(dataIndex, dataName);
}
return false;
}
/// <summary>
/// 更新指定系列的数据项名称
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="dataName"></param>
public bool UpdateDataName(int serieIndex, int dataIndex, string dataName)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateDataName(dataIndex, dataName);
}
return false;
}
/// <summary>
/// 更新指定系列的维度Y数据项的值
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="value"></param>
public bool UpdateData(int serieIndex, int dataIndex, float value)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateYData(dataIndex, value);
}
return false;
}
public bool UpdateData(string serieName, int dataIndex, List<float> values)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateData(dataIndex, values);
}
return false;
}
public bool UpdateData(int serieIndex, int dataIndex, List<float> values)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateData(dataIndex, values);
}
return false;
}
/// <summary>
/// 更新指定系列指定数据项指定维度的数据值
/// </summary>
/// <param name="serieIndex">系列</param>
/// <param name="dataIndex">数据项</param>
/// <param name="dimension">数据维数,从0开始</param>
/// <param name="value">值</param>
public bool UpdateData(int serieIndex, int dataIndex, int dimension, float value)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateData(dataIndex, dimension, value);
}
return false;
}
/// <summary>
/// 更新指定系列指定数据项指定维度的数据值
/// </summary>
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="dimension">数据维数,从0开始</param>
/// <param name="value"></param>
public bool UpdateData(string serieName, int dataIndex, int dimension, float value)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateData(dataIndex, dimension, value);
}
return false;
}
/// <summary>
/// 更新指定系列的维度X和维度Y数据
/// </summary>
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
public bool UpdateXYData(string serieName, int dataIndex, float xValue, float yValue)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateXYData(dataIndex, xValue, yValue);
}
return false;
}
/// <summary>
/// 更新指定系列的维度X和维度Y数据
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
public bool UpdateXYData(int serieIndex, int dataIndex, float xValue, float yValue)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateXYData(dataIndex, xValue, yValue);
}
return false;
}
/// <summary>
/// dataZoom由变化是更新系列的缓存数据
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateFilterData(DataZoom dataZoom)
{
if (dataZoom != null && dataZoom.enable)
{
for (int i = 0; i < m_Series.Count; i++)
{
SerieHelper.UpdateFilterData(m_Series[i], dataZoom);
}
}
}
/// <summary>
/// 指定系列是否显示
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool IsActive(string name)
{
var serie = GetSerie(name);
return serie == null ? false : serie.show;
}
/// <summary>
/// 指定系列是否显示
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public bool IsActive(int index)
{
var serie = GetSerie(index);
return serie == null ? false : serie.show;
}
/// <summary>
/// 设置指定系列是否显示
/// </summary>
/// <param name="name"></param>
/// <param name="active"></param>
public void SetActive(string name, bool active)
{
var serie = GetSerie(name);
if (serie != null)
{
serie.show = active;
}
}
/// <summary>
/// 设置指定系列是否显示
/// </summary>
/// <param name="index"></param>
/// <param name="active"></param>
public void SetActive(int index, bool active)
{
var serie = GetSerie(index);
if (serie != null)
{
serie.show = active;
serie.animation.Reset();
if (active) serie.animation.FadeIn();
}
}
/// <summary>
/// 指定系列是否处于高亮选中状态
/// </summary>
/// <param name="serieIndex"></param>
/// <returns></returns>
public bool IsHighlight(int serieIndex)
{
var serie = GetSerie(serieIndex);
if (serie != null) return serie.highlighted;
else return false;
}
/// <summary>
/// 设置获得标志图形大小的回调
/// </summary>
/// <param name="size"></param>
/// <param name="selectedSize"></param>
public void SetSerieSymbolSizeCallback(SymbolSizeCallback size, SymbolSizeCallback selectedSize)
{
foreach (var serie in m_Series)
{
serie.symbol.sizeCallback = size;
serie.symbol.selectedSizeCallback = selectedSize;
}
}
/// <summary>
/// 启用或取消初始动画
/// </summary>
public void AnimationEnable(bool flag)
{
foreach (var serie in m_Series)
{
serie.animation.enable = flag;
}
}
/// <summary>
/// 渐入动画
/// </summary>
public void AnimationFadeIn()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable)
{
serie.animation.FadeIn();
}
}
}
/// <summary>
/// 渐出动画
/// </summary>
public void AnimationFadeOut()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.FadeOut();
}
}
/// <summary>
/// 暂停动画
/// </summary>
public void AnimationPause()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Pause();
}
}
/// <summary>
/// 继续动画
/// </summary>
public void AnimationResume()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Resume();
}
}
/// <summary>
/// 重置动画
/// </summary>
public void AnimationReset()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Reset();
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 57c808a15402a4d25a51a37cbb655a85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,133 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using System;
namespace XCharts
{
/// <summary>
/// Global parameter setting component. The default value can be used in general, and can be adjusted when necessary.
/// 全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
/// </summary>
[Serializable]
public class Settings : MainComponent
{
[SerializeField] [Range(1, 20)] protected int m_MaxPainter = 10;
[SerializeField] [Range(1, 10)] protected float m_LineSmoothStyle = 3f;
[SerializeField] [Range(1f, 20)] protected float m_LineSmoothness = 2f;
[SerializeField] [Range(1f, 20)] protected float m_LineSegmentDistance = 3f;
[SerializeField] [Range(1, 10)] protected float m_CicleSmoothness = 2f;
[SerializeField] protected float m_LegendIconLineWidth = 2;
[SerializeField] private float[] m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f };
/// <summary>
/// max painter.
/// 设定的painter数量。
/// </summary>
public int maxPainter
{
get { return m_MaxPainter; }
set { if (PropertyUtil.SetStruct(ref m_MaxPainter, value < 0 ? 1 : value)) SetVerticesDirty(); }
}
/// <summary>
/// Curve smoothing factor. By adjusting the smoothing coefficient, the curvature of the curve can be changed,
/// and different curves with slightly different appearance can be obtained.
/// 曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
/// </summary>
public float lineSmoothStyle
{
get { return m_LineSmoothStyle; }
set { if (PropertyUtil.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// Smoothness of curve. The smaller the value, the smoother the curve, but the number of vertices will increase.
/// When the area with gradient is filled, the larger the value, the worse the transition effect.
/// 曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
/// </summary>
/// <value></value>
public float lineSmoothness
{
get { return m_LineSmoothness; }
set { if (PropertyUtil.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// The partition distance of a line segment. A line in a normal line chart is made up of many segments,
/// the number of which is determined by the change in value. The smaller the number of segments,
/// the higher the number of vertices. When the area with gradient is filled, the larger the value, the worse the transition effect.
/// 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
/// </summary>
/// <value></value>
public float lineSegmentDistance
{
get { return m_LineSegmentDistance; }
set { if (PropertyUtil.SetStruct(ref m_LineSegmentDistance, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// the smoothess of cricle.
/// 圆形的平滑度。数越小圆越平滑,但顶点数也会随之增加。
/// </summary>
public float cicleSmoothness
{
get { return m_CicleSmoothness; }
set { if (PropertyUtil.SetStruct(ref m_CicleSmoothness, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of line serie legend.
/// Line类型图例图标的线条宽度。
/// </summary>
public float legendIconLineWidth
{
get { return m_LegendIconLineWidth; }
set { if (PropertyUtil.SetStruct(ref m_LegendIconLineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
/// 图例圆角半径。用数组分别指定4个圆角半径(顺时针左上,右上,右下,左下)。
/// </summary>
public float[] legendIconCornerRadius
{
get { return m_LegendIconCornerRadius; }
set { if (PropertyUtil.SetClass(ref m_LegendIconCornerRadius, value, true)) SetVerticesDirty(); }
}
public void Copy(Settings settings)
{
m_MaxPainter = settings.maxPainter;
m_LineSmoothStyle = settings.lineSmoothStyle;
m_LineSmoothness = settings.lineSmoothness;
m_LineSegmentDistance = settings.lineSegmentDistance;
m_CicleSmoothness = settings.cicleSmoothness;
m_LegendIconLineWidth = settings.legendIconLineWidth;
ChartHelper.CopyArray(m_LegendIconCornerRadius, settings.legendIconCornerRadius);
}
public void Reset()
{
Copy(DefaultSettings);
}
public static Settings DefaultSettings
{
get
{
return new Settings()
{
m_MaxPainter = XChartsSettings.maxPainter,
m_LineSmoothStyle = XChartsSettings.lineSmoothStyle,
m_LineSmoothness = XChartsSettings.lineSmoothness,
m_LineSegmentDistance = XChartsSettings.lineSegmentDistance,
m_CicleSmoothness = XChartsSettings.cicleSmoothness,
m_LegendIconLineWidth = 2,
m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f }
};
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 40d2c2f38d80f4b42acdba7db6918f14
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,125 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using System;
namespace XCharts
{
/// <summary>
/// Title component, including main title and subtitle.
/// 标题组件,包含主标题和副标题。
/// </summary>
[Serializable]
public class Title : MainComponent, IPropertyChanged
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Text;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
[SerializeField] private string m_SubText;
[SerializeField] private TextStyle m_SubTextStyle = new TextStyle();
[SerializeField] private float m_ItemGap = 8;
[SerializeField] private Location m_Location = Location.defaultTop;
/// <summary>
/// [default:true]
/// Set this to false to prevent the title from showing.
/// 是否显示标题组件。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// The main title text, supporting \n for newlines.
/// 主标题文本,支持使用 \n 换行。
/// </summary>
public string text { get { return m_Text; } set { if (PropertyUtil.SetClass(ref m_Text, value)) SetComponentDirty(); } }
/// <summary>
/// The text style of main title.
/// 主标题文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// Subtitle text, supporting for \n for newlines.
/// 副标题文本,支持使用 \n 换行。
/// </summary>
public string subText
{
get { return m_SubText; }
set { if (PropertyUtil.SetClass(ref m_SubText, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of sub title.
/// 副标题文本样式。
/// </summary>
public TextStyle subTextStyle
{
get { return m_SubTextStyle; }
set { if (PropertyUtil.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// [default:8]
/// The gap between the main title and subtitle.
/// 主副标题之间的间距。
/// </summary>
public float itemGap
{
get { return m_ItemGap; }
set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); }
}
/// <summary>
/// The location of title component.
/// 标题显示位置。
/// </summary>
public Location location
{
get { return m_Location; }
set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); }
}
public int index { get; internal set; }
public override bool vertsDirty { get { return false; } }
public override bool componentDirty
{
get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty || subTextStyle.componentDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
textStyle.ClearComponentDirty();
subTextStyle.ClearComponentDirty();
}
public static Title defaultTitle
{
get
{
var title = new Title
{
m_Show = true,
m_Text = "Chart Title",
m_TextStyle = new TextStyle(),
m_SubText = "",
m_SubTextStyle = new TextStyle(),
m_ItemGap = 0,
m_Location = Location.defaultTop
};
return title;
}
}
public void OnChanged()
{
m_Location.OnChanged();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91e9a1a59b4b64142a9aa260f618c1c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,538 @@
using System.Linq;
using System.Collections.ObjectModel;
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// Tooltip component.
/// 提示框组件。
/// </summary>
[System.Serializable]
public class Tooltip : MainComponent
{
/// <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.
/// 十字准星指示器。坐标轴显示Label和交叉线。
/// </summary>
Corss
}
[SerializeField] private bool m_Show;
[SerializeField] private Type m_Type;
[SerializeField] private string m_Formatter;
[SerializeField] private string m_ItemFormatter;
[SerializeField] private string m_TitleFormatter;
[SerializeField] private float m_FixedWidth = 0;
[SerializeField] private float m_FixedHeight = 0;
[SerializeField] private float m_MinWidth = 0;
[SerializeField] private float m_MinHeight = 0;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private float m_PaddingLeftRight = 5f;
[SerializeField] private float m_PaddingTopBottom = 5f;
[SerializeField] private bool m_IgnoreDataShow = false;
[SerializeField] private string m_IgnoreDataDefaultContent = "-";
[SerializeField] private bool m_AlwayShow = false;
[SerializeField] private Vector2 m_Offset = new Vector2(18f, -25f);
[SerializeField] private Sprite m_BackgroundImage;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
private GameObject m_GameObject;
private GameObject m_Content;
private ChartText m_ContentText;
private Image m_ContentImage;
private RectTransform m_ContentRect;
private RectTransform m_ContentTextRect;
private List<int> lastDataIndex { get; set; }
/// <summary>
/// Whether to show the tooltip component.
/// 是否显示提示框组件。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) { SetAllDirty(); SetActive(value); } }
}
/// <summary>
/// Indicator type.
/// 提示框指示器类型。
/// </summary>
public Type type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); }
}
/// <summary>
/// A string template formatter for the total content of the prompt box. Support for wrapping lines with \n.
/// When formatter is not null, use formatter first, otherwise use itemFormatter.
/// Template variables are {.}, {a}, {b}, {c}, {d}.
/// {.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.
/// {a} is the series name of the serie that is currently indicated or whose index is 0.
/// {b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
/// {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
/// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
/// {.1} represents a dot from serie corresponding color that specifies index as 1.
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
/// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
/// {c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify).
/// {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).
/// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).
/// Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"
/// 提示框总内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时,优先使用formatter,否则使用itemFormatter。
/// 模板变量有{.}、{a}、{b}、{c}、{d}。
/// {.}为当前所指示或index为0的serie的对应颜色的圆点。
/// {a}为当前所指示或index为0的serie的系列名name。
/// {b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。
/// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。
/// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。
/// {.1}表示指定index为1的serie对应颜色的圆点。
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。
/// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。
/// {d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。
/// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。
/// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}"
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <summary>
/// The string template formatter for the tooltip title content. Support for wrapping lines with \n.
/// This is only valid if the itemFormatter is in effect.
/// The placeholder {I} can be set separately to indicate that the title is ignored and not displayed.
/// 提示框标题内容的字符串模版格式器。支持用 \n 换行。仅当itemFormatter生效时才有效。可以单独设置占位符{i}表示忽略不显示title。
/// </summary>
public string titleFormatter { get { return m_TitleFormatter; } set { m_TitleFormatter = value; } }
/// <summary>
/// a string template formatter for a single Serie or data item content. Support for wrapping lines with \n.
/// When formatter is not null, use formatter first, otherwise use itemFormatter.
/// 提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时,优先使用formatter,否则使用itemFormatter。
/// </summary>
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
/// <summary>
/// Fixed width. Higher priority than minWidth.
/// 固定宽度。比 minWidth 优先。
/// </summary>
public float fixedWidth { get { return m_FixedWidth; } set { m_FixedWidth = value; } }
/// <summary>
/// Fixed height. Higher priority than minHeight.
/// 固定高度。比 minHeight 优先。
/// </summary>
public float fixedHeight { get { return m_FixedHeight; } set { m_FixedHeight = value; } }
/// <summary>
/// Minimum width. If fixedWidth has a value, get fixedWidth first.
/// 最小宽度。如若 fixedWidth 设有值,优先取 fixedWidth。
/// </summary>
public float minWidth { get { return m_MinWidth; } set { m_MinWidth = value; } }
/// <summary>
/// Minimum height. If fixedHeight has a value, take priority over fixedHeight.
/// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
/// </summary>
public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } }
/// <summary>
/// Standard numeric format string. Used to format numeric values to display as strings.
/// Using 'Axx' form: 'A' is the single character of the format specifier, supporting 'C' currency,
/// 'D' decimal, 'E' exponent, 'F' number of vertices, 'G' regular, 'N' digits, 'P' percentage,
/// 'R' round tripping, 'X' hex etc. 'XX' is the precision specification, from '0' - '99'.
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。
/// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of left and right. defaut:5.
/// 左右边距。
/// </summary>
public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
/// <summary>
/// the text padding of top and bottom. defaut:5.
/// 上下边距。
/// </summary>
public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } }
/// <summary>
/// Whether to show ignored data on tooltip.
/// 是否显示忽略数据在tooltip上。
/// </summary>
public bool ignoreDataShow { get { return m_IgnoreDataShow; } set { m_IgnoreDataShow = value; } }
/// <summary>
/// The default display character information for ignored data.
/// 被忽略数据的默认显示字符信息。
/// </summary>
public string ignoreDataDefaultContent { get { return m_IgnoreDataDefaultContent; } set { m_IgnoreDataDefaultContent = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetBackground(m_BackgroundImage); } }
/// <summary>
/// Whether to trigger after always display.
/// 是否触发后一直显示。
/// </summary>
public bool alwayShow { get { return m_AlwayShow; } set { m_AlwayShow = value; } }
/// <summary>
/// The position offset of tooltip relative to the mouse position.
/// 提示框相对于鼠标位置的偏移。
/// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// the text style of content.
/// 提示框内容文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (value != null) { m_TextStyle = value; SetComponentDirty(); } }
}
/// <summary>
/// the line style of indicator line.
/// 指示线样式。
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) m_LineStyle = value; SetComponentDirty(); }
}
/// <summary>
/// 组件是否需要刷新
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty || lineStyle.componentDirty || textStyle.componentDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
lineStyle.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
/// <summary>
/// 当前提示框所指示的Serie索引(目前只对散点图有效)。
/// </summary>
public Dictionary<int, List<int>> runtimeSerieIndex { get; internal set; }
/// <summary>
/// The data index currently indicated by Tooltip.
/// 当前提示框所指示的数据项索引。
/// </summary>
public List<int> runtimeDataIndex { get; internal set; }
/// <summary>
/// the value for x indicator label.
/// 指示器X轴上要显示的值。
/// </summary>
public float[] runtimeXValues { get; internal set; }
/// <summary>
/// the value for y indicator label.
/// 指示器Y轴上要显示的值。
/// </summary>
public float[] runtimeYValues { get; internal set; }
/// <summary>
/// the current pointer position.
/// 当前鼠标位置。
/// </summary>
public Vector2 runtimePointerPos { get; internal set; }
/// <summary>
/// the width of tooltip.
/// 提示框宽。
/// </summary>
public float runtimeWidth { get { return m_ContentRect.sizeDelta.x; } }
/// <summary>
/// the height of tooltip.
/// 提示框高。
/// </summary>
public float runtimeHeight { get { return m_ContentRect.sizeDelta.y; } }
/// <summary>
/// Whether the tooltip has been initialized.
/// 提示框是否已初始化。
/// </summary>
public bool runtimeInited { get { return m_GameObject != null; } }
/// <summary>
/// the gameObject of tooltip.
/// 提示框的gameObject。
/// </summary>
public GameObject runtimeGameObject { get { return m_GameObject; } }
/// <summary>
/// 当前指示的角度。
/// </summary>
public float runtimeAngle { get; internal set; }
/// <summary>
/// 当前指示的Grid索引。
/// </summary>
public int runtimeGridIndex { get; internal set; }
public int runtimePolarIndex { get; internal set; }
public static Tooltip defaultTooltip
{
get
{
var tooltip = new Tooltip
{
m_Show = true,
runtimeXValues = new float[2] { -1, -1 },
runtimeYValues = new float[2] { -1, -1 },
runtimeDataIndex = new List<int>() { -1, -1 },
lastDataIndex = new List<int>() { -1, -1 },
runtimeSerieIndex = new Dictionary<int, List<int>>()
};
return tooltip;
}
}
/// <summary>
/// 绑定提示框gameObject
/// </summary>
/// <param name="obj"></param>
public void SetObj(GameObject obj)
{
m_GameObject = obj;
m_GameObject.SetActive(false);
}
/// <summary>
/// 绑定提示框的文本框gameObject
/// </summary>
/// <param name="content"></param>
public void SetContentObj(GameObject content)
{
m_Content = content;
m_ContentRect = m_Content.GetComponent<RectTransform>();
m_ContentImage = m_Content.GetComponent<Image>();
m_ContentImage.raycastTarget = false;
m_ContentText = new ChartText(m_Content);
if (m_ContentText != null)
{
m_ContentTextRect = m_ContentText.gameObject.GetComponentInChildren<RectTransform>();
}
SetBackground(backgroundImage);
}
/// <summary>
/// Keep Tooltiop displayed at the top.
/// 保持Tooltiop显示在最顶上
/// </summary>
public void UpdateToTop()
{
if (m_GameObject == null) return;
int count = m_GameObject.transform.parent.childCount;
m_GameObject.GetComponent<RectTransform>().SetSiblingIndex(count - 1);
}
/// <summary>
/// 设置提示框文本背景色
/// </summary>
/// <param name="color"></param>
public void SetContentBackgroundColor(Color color)
{
if (m_ContentImage != null)
m_ContentImage.color = color;
}
/// <summary>
/// 设置提示框文本背景图片
/// </summary>
/// <param name="sprite"></param>
public void SetBackground(Sprite sprite)
{
if (m_ContentImage != null)
{
m_ContentImage.type = Image.Type.Sliced;
m_ContentImage.sprite = sprite;
}
}
/// <summary>
/// 设置提示框文本字体颜色
/// </summary>
/// <param name="color"></param>
public void SetContentTextColor(Color color)
{
if (m_ContentText != null)
{
m_ContentText.SetColor(color);
}
}
/// <summary>
/// 设置提示框文本内容
/// </summary>
/// <param name="txt"></param>
public void UpdateContentText(string txt)
{
if (m_ContentText != null)
{
m_ContentText.SetText(txt);
float wid, hig;
if (m_FixedWidth > 0) wid = m_FixedWidth;
else if (m_MinWidth > 0 && m_ContentText.GetPreferredWidth() < m_MinWidth) wid = m_MinWidth;
else wid = m_ContentText.GetPreferredWidth() + m_PaddingLeftRight * 2;
if (m_FixedHeight > 0) hig = m_FixedHeight;
else if (m_MinHeight > 0 && m_ContentText.GetPreferredHeight() < m_MinHeight) hig = m_MinHeight;
else hig = m_ContentText.GetPreferredHeight() + m_PaddingTopBottom * 2;
if (m_ContentRect != null) m_ContentRect.sizeDelta = new Vector2(wid, hig);
if (m_ContentTextRect != null)
{
m_ContentTextRect.anchoredPosition = new Vector3(m_PaddingLeftRight, -m_PaddingTopBottom);
}
}
}
/// <summary>
/// 清除提示框指示数据
/// </summary>
internal void ClearValue()
{
for (int i = 0; i < runtimeDataIndex.Count; i++) runtimeDataIndex[i] = -1;
for (int i = 0; i < runtimeXValues.Length; i++) runtimeXValues[i] = -1;
for (int i = 0; i < runtimeYValues.Length; i++) runtimeYValues[i] = -1;
}
/// <summary>
/// 提示框是否显示
/// </summary>
/// <returns></returns>
public bool IsActive()
{
return m_GameObject != null && m_GameObject.activeInHierarchy;
}
/// <summary>
/// 设置提示框是否显示
/// </summary>
/// <param name="flag"></param>
public void SetActive(bool flag)
{
if (!flag && m_AlwayShow) return;
lastDataIndex[0] = lastDataIndex[1] = -1;
if (m_GameObject && m_GameObject.activeInHierarchy != flag)
m_GameObject.SetActive(flag);
}
/// <summary>
/// 更新文本框位置
/// </summary>
/// <param name="pos"></param>
public void UpdateContentPos(Vector2 pos)
{
if (m_Content)
m_Content.transform.localPosition = pos;
}
/// <summary>
/// 获得当前提示框的位置
/// </summary>
/// <returns></returns>
public Vector3 GetContentPos()
{
if (m_Content)
return m_Content.transform.localPosition;
else
return Vector3.zero;
}
/// <summary>
/// Whether the data item indicated by tooltip has changed.
/// 提示框所指示的数据项是否发生变化。
/// </summary>
/// <returns></returns>
public bool IsDataIndexChanged()
{
return runtimeDataIndex[0] != lastDataIndex[0] ||
runtimeDataIndex[1] != lastDataIndex[1];
}
/// <summary>
/// 当前索引缓存
/// </summary>
internal void UpdateLastDataIndex()
{
lastDataIndex[0] = runtimeDataIndex[0];
if (runtimeDataIndex.Count > 1)
lastDataIndex[1] = runtimeDataIndex[1];
}
/// <summary>
/// 当前提示框是否选中数据项
/// </summary>
/// <returns></returns>
public bool IsSelected()
{
foreach (var index in runtimeDataIndex)
if (index >= 0) return true;
return false;
}
/// <summary>
/// 指定索引的数据项是否被提示框选中
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public bool IsSelected(int index)
{
foreach (var temp in runtimeDataIndex)
if (temp == index) return true;
return false;
}
public void ClearSerieDataIndex()
{
foreach (var kv in runtimeSerieIndex)
{
kv.Value.Clear();
}
}
public void AddSerieDataIndex(int serieIndex, int dataIndex)
{
if (!runtimeSerieIndex.ContainsKey(serieIndex))
{
runtimeSerieIndex[serieIndex] = new List<int>();
}
runtimeSerieIndex[serieIndex].Add(dataIndex);
}
public bool isAnySerieDataIndex()
{
foreach (var kv in runtimeSerieIndex)
{
if (kv.Value.Count > 0) return true;
}
return false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c75ff9b455a74482db10158ca81afe89
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,196 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Vessel component for liquid chart. There can be multiple vessels in a Chart, which can be matched by vesselIndex in Serie.
/// <para>
/// 容器组件。
/// 一般用于LiquidChart。一个Chart中可以有多个Vessel,Serie中用vesselIndex来对应。
/// </para>
/// </summary>
[Serializable]
public class Vessel : MainComponent
{
public enum Shape
{
/// <summary>
/// 圆形
/// </summary>
Circle,
/// <summary>
/// 正方形。
/// </summary>
Rect,
/// <summary>
/// 三角形。
/// </summary>
Triangle,
/// <summary>
/// 菱形。
/// </summary>
Diamond,
/// <summary>
/// 不显示标记。
/// </summary>
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Shape m_Shape = Shape.Circle;
[SerializeField] private float m_ShapeWidth = 5f;
[SerializeField] private float m_Gap = 10f;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private bool m_AutoColor = true;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private float m_Radius = 0.5f;
[SerializeField] [Range(0.5f, 10f)] private float m_Smoothness = 1f;
/// <summary>
/// Whether to show the vessel.
/// 是否显示容器组件。
/// [defaut: true]
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The shape of vessel.
/// 容器形状。
/// [default: Shape.Circle]
/// </summary>
public Shape shape
{
get { return m_Shape; }
set { if (PropertyUtil.SetStruct(ref m_Shape, value)) SetVerticesDirty(); }
}
/// <summary>
/// Thickness of vessel.
/// 容器厚度。
/// [defaut: 5f]
/// </summary>
public float shapeWidth
{
get { return m_ShapeWidth; }
set { if (PropertyUtil.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The gap between the vessel and the liquid.
/// 间隙。容器和液体的间隙。
/// [defaut: 10f]
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
/// <summary>
/// The center of vesselß. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 中心点。数组的第一项是横坐标,第二项是纵坐标。
/// 当值为0-1之间时表示百分比,设置成百分比时表示图表宽高最小值的百分比。
/// [default:[0.5f,0.45f]]
/// </summary>
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
/// The radius of vessel.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 半径。
/// [default: 0.35f]
/// </summary>
public float radius
{
get { return m_Radius; }
set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); }
}
/// <summary>
/// The smoothness of wave.
/// 水波平滑度。
/// [default: 1f]
/// </summary>
public float smoothness
{
get { return m_Smoothness; }
set { if (PropertyUtil.SetStruct(ref m_Smoothness, value)) SetAllDirty(); }
}
/// <summary>
/// Background color of polar, which is transparent by default.
/// 背景色,默认透明。
/// [default: `Color.clear`]
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Vessel color. The default is consistent with Serie.
/// 容器颜色。默认和serie一致。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether automatic color. If true, the color matches serie.
/// 是否自动颜色。为true时颜色会和serie一致。
/// [default: true]
/// </summary>
public bool autoColor
{
get { return m_AutoColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); }
}
public int index { get; internal set; }
/// <summary>
/// the runtime center position of vessel.
/// 运行时中心点。
/// </summary>
public Vector3 runtimeCenterPos { get; internal set; }
/// <summary>
/// the runtime radius of vessel.
/// 运行时半径。
/// </summary>
public float runtimeRadius { get; internal set; }
/// <summary>
/// The actual radius after deducting shapeWidth and gap.
/// 运行时内半径。扣除厚度和间隙后的实际半径。
/// </summary>
public float runtimeInnerRadius { get; internal set; }
public static Vessel defaultVessel
{
get
{
var vessel = new Vessel
{
m_Show = true,
m_Shape = Shape.Circle,
m_ShapeWidth = 5,
m_Gap = 10,
m_Radius = 0.35f,
m_AutoColor = true,
m_Color = new Color32(70, 70, 240, 255),
m_Smoothness = 1
};
vessel.center[0] = 0.5f;
vessel.center[1] = 0.45f;
return vessel;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04afad352c62a405691c66f18c3f9db7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,579 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// VisualMap component. Mapping data to visual elements such as colors.
/// 视觉映射组件。用于进行『视觉编码』,也就是将数据映射到视觉元素(视觉通道)。
/// </summary>
[System.Serializable]
public class VisualMap : MainComponent
{
/// <summary>
/// 类型。分为连续型和分段型。
/// </summary>
public enum Type
{
/// <summary>
/// 连续型。
/// </summary>
Continuous,
/// <summary>
/// 分段型。
/// </summary>
Piecewise
}
/// <summary>
/// 方向。X轴还是Y轴。
/// </summary>
public enum Direction
{
/// <summary>
/// 默认方向。
/// </summary>
Default,
/// <summary>
/// X轴方向。
/// </summary>
X,
/// <summary>
/// Y轴方向。
/// </summary>
Y
}
/// <summary>
/// 选择模式
/// </summary>
public enum SelectedMode
{
/// <summary>
/// 多选。
/// </summary>
Multiple,
/// <summary>
/// 单选。
/// </summary>
Single
}
[SerializeField] private bool m_Enable = false;
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Continuous;
[SerializeField] private Direction m_Direction = Direction.Default;
[SerializeField] private SelectedMode m_SelectedMode = SelectedMode.Multiple;
[SerializeField] private float m_Min = 0;
[SerializeField] private float m_Max = 100f;
[SerializeField] private float[] m_Range = new float[2] { 0, 100f };
[SerializeField] private string[] m_Text = new string[2] { "", "" };
[SerializeField] private float[] m_TextGap = new float[2] { 10f, 10f };
[SerializeField] private int m_SplitNumber = 5;
[SerializeField] private bool m_Calculable = false;
[SerializeField] private bool m_Realtime = true;
[SerializeField] private float m_ItemWidth = 20f;
[SerializeField] private float m_ItemHeight = 140f;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private int m_Dimension = -1;
[SerializeField] private bool m_HoverLink = true;
[SerializeField] private bool m_AutoMinMax = true;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultLeft;
[SerializeField] private List<Color32> m_InRange = new List<Color32>();
[SerializeField] private List<Color32> m_OutOfRange = new List<Color32>();
/// <summary>
/// Whether enable visualMap component.
///
/// 是否开启组件功能。
///
/// [default: false]
/// </summary>
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to display components. If set to false, it will not show up, but the data mapping function still exists.
///
/// 是否显示组件。如果设置为 false,不会显示,但是数据映射的功能还存在。
///
/// [default: true]
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of visualmap component.
/// 组件类型。
/// </summary>
public Type type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// 映射方向。
/// </summary>
public Direction direction
{
get { return m_Direction; }
set { if (PropertyUtil.SetStruct(ref m_Direction, value)) SetVerticesDirty(); }
}
/// <summary>
/// the selected mode for Piecewise visualMap.
/// 选择模式。
/// </summary>
public SelectedMode selectedMode
{
get { return m_SelectedMode; }
set { if (PropertyUtil.SetStruct(ref m_SelectedMode, value)) SetVerticesDirty(); }
}
/// <summary>
/// The minimum allowed. 'min' must be user specified. [visualmap.min, visualmap.max] forms the "domain" of the visualMap.
///
/// 允许的最小值。`autoMinMax`为`false`时必须指定。[visualMap.min, visualMap.max] 形成了视觉映射的『定义域』。
/// </summary>
public float min
{
get { return m_Min; }
set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
}
/// <summary>
/// The maximum allowed. 'max' must be user specified. [visualmap.min, visualmap.max] forms the "domain" of the visualMap.
///
/// 允许的最大值。`autoMinMax`为`false`时必须指定。[visualMap.min, visualMax.max] 形成了视觉映射的『定义域』。
/// </summary>
public float max
{
get { return m_Max; }
set { m_Max = (value < min ? min + 1 : value); SetVerticesDirty(); }
}
/// <summary>
/// Specifies the position of the numeric value corresponding to the handle. Range should be within the range of [min,max].
///
/// 指定手柄对应数值的位置。range 应在[min,max]范围内。
/// </summary>
public float[] range { get { return m_Range; } }
/// <summary>
/// Text on both ends.
/// 两端的文本,如 ['High', 'Low']。
/// </summary>
public string[] text { get { return m_Text; } }
/// <summary>
/// The distance between the two text bodies.
/// 两端文字主体之间的距离,单位为px。
/// </summary>
public float[] textGap { get { return m_TextGap; } }
/// <summary>
/// For continuous data, it is automatically evenly divided into several segments
/// and automatically matches the size of inRange color list when the default is 0.
///
/// 对于连续型数据,自动平均切分成几段,默认为0时自动匹配inRange颜色列表大小。
/// </summary>
/// <value></value>
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether the handle used for dragging is displayed (the handle can be dragged to adjust the selected range).
///
/// 是否显示拖拽用的手柄(手柄能拖拽调整选中范围)。
/// </summary>
public bool calculable
{
get { return m_Calculable; }
set { if (PropertyUtil.SetStruct(ref m_Calculable, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to update in real time while dragging.
///
/// 拖拽时,是否实时更新。
/// </summary>
public bool realtime
{
get { return m_Realtime; }
set { if (PropertyUtil.SetStruct(ref m_Realtime, value)) SetVerticesDirty(); }
}
/// <summary>
/// The width of the figure, that is, the width of the color bar.
///
/// 图形的宽度,即颜色条的宽度。
/// </summary>
public float itemWidth
{
get { return m_ItemWidth; }
set { if (PropertyUtil.SetStruct(ref m_ItemWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of the figure, that is, the height of the color bar.
///
/// 图形的高度,即颜色条的高度。
/// </summary>
public float itemHeight
{
get { return m_ItemHeight; }
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetVerticesDirty(); }
}
/// <summary>
/// Border line width.
///
/// 边框线宽,单位px。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specifies "which dimension" of the data to map to the visual element. "Data" is series.data.
/// Starting at 1, the default is 0 to take the last dimension in data.
///
/// 指定用数据的『哪个维度』,映射到视觉元素上。『数据』即 series.data。从1开始,默认为0取 data 中最后一个维度。
/// </summary>
public int dimension
{
get { return m_Dimension; }
set { if (PropertyUtil.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); }
}
/// <summary>
/// When the hoverLink function is turned on, when the mouse hovers over the visualMap component,
/// the corresponding value of the mouse position is highlighted in the corresponding graphic element in the diagram.
/// Conversely, when the mouse hovers over a graphic element in a diagram,
/// the corresponding value of the visualMap component is triangulated in the corresponding position.
///
/// 打开 hoverLink 功能时,鼠标悬浮到 visualMap 组件上时,鼠标位置对应的数值 在 图表中对应的图形元素,会高亮。
/// 反之,鼠标悬浮到图表中的图形元素上时,在 visualMap 组件的相应位置会有三角提示其所对应的数值。
/// </summary>
/// <value></value>
public bool hoverLink
{
get { return m_HoverLink; }
set { if (PropertyUtil.SetStruct(ref m_HoverLink, value)) SetVerticesDirty(); }
}
/// <summary>
/// Automatically set min, Max value
/// 自动设置min,max的值
/// </summary>
public bool autoMinMax
{
get { return m_AutoMinMax; }
set { if (PropertyUtil.SetStruct(ref m_AutoMinMax, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify whether the layout of component is horizontal or vertical.
///
/// 布局方式是横还是竖。
/// </summary>
public Orient orient
{
get { return m_Orient; }
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
}
/// <summary>
/// The location of component.
/// 组件显示的位置。
/// </summary>
public Location location
{
get { return m_Location; }
set { if (PropertyUtil.SetClass(ref m_Location, value)) SetVerticesDirty(); }
}
/// <summary>
/// Defines the visual color in the selected range.
/// 定义 在选中范围中 的视觉颜色。
/// </summary>
public List<Color32> inRange
{
get { return m_InRange; }
set { if (value != null) { m_InRange = value; SetVerticesDirty(); } }
}
/// <summary>
/// Defines a visual color outside of the selected range.
/// 定义 在选中范围外 的视觉颜色。
/// </summary>
public List<Color32> outOfRange
{
get { return m_OutOfRange; }
set { if (value != null) { m_OutOfRange = value; SetVerticesDirty(); } }
}
public override bool vertsDirty { get { return m_VertsDirty || location.anyDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
location.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
}
/// <summary>
/// 鼠标悬停选中的index
/// </summary>
/// <value></value>
public int runtimeSelectedIndex { get; internal set; }
public float runtimeSelectedValue { get; internal set; }
/// <summary>
/// the current pointer position.
/// 当前鼠标位置。
/// </summary>
public Vector2 runtimePointerPos { get; internal set; }
public bool runtimeIsVertical { get { return orient == Orient.Vertical; } }
public float rangeMin
{
get
{
if (m_Range[0] < min || m_Range[0] > max) return min;
else return m_Range[0];
}
set
{
if (value >= min && value <= m_Range[1]) m_Range[0] = value;
}
}
public float rangeMax
{
get
{
if (m_Range[1] >= m_Range[0] && m_Range[1] < max) return m_Range[1];
else return max;
}
set
{
if (value >= m_Range[0] && value <= max) m_Range[1] = value;
}
}
public int runtimeSplitNumber
{
get
{
if (splitNumber > 0 && splitNumber <= m_InRange.Count) return splitNumber;
else return m_InRange.Count;
}
}
public float runtimeRangeMinHeight { get { return (rangeMin - min) / (max - min) * itemHeight; } }
public float runtimeRangeMaxHeight { get { return (rangeMax - min) / (max - min) * itemHeight; } }
private List<Color32> m_RtInRange = new List<Color32>();
public List<Color32> runtimeInRange
{
get
{
if (splitNumber == 0 || m_InRange.Count >= splitNumber || m_InRange.Count < 1 || IsPiecewise())
{
return m_InRange;
}
else
{
if (m_RtInRange.Count != runtimeSplitNumber)
{
m_RtInRange.Clear();
var total = max - min;
var diff1 = total / (m_InRange.Count - 1);
var diff2 = total / splitNumber;
var inCount = 0;
var inValue = min;
var rtValue = min;
for (int i = 0; i < splitNumber; i++)
{
rtValue += diff2;
if (rtValue > inValue + diff1)
{
inValue += diff1;
inCount++;
}
if (i == splitNumber - 1)
{
m_RtInRange.Add(m_InRange[m_InRange.Count - 1]);
}
else
{
var rate = (rtValue - inValue) / diff1;
m_RtInRange.Add(Color32.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate));
}
}
}
return m_RtInRange;
}
}
}
public Color32 GetColor(float value)
{
if (value < m_Min || value > m_Max)
{
if (m_OutOfRange.Count > 0) return m_OutOfRange[0];
else return ChartConst.clearColor32;
}
int splitNumber = runtimeInRange.Count;
if (splitNumber <= 0) return ChartConst.clearColor32;
var index = GetIndex(value);
if (m_Type == VisualMap.Type.Piecewise)
{
if (index >= 0 && index < runtimeInRange.Count)
return runtimeInRange[index];
else return ChartConst.clearColor32;
}
else
{
var diff = (m_Max - m_Min) / (splitNumber - 1);
var nowMin = m_Min + index * diff;
var rate = (value - nowMin) / diff;
if (index == splitNumber - 1) return runtimeInRange[index];
else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], rate);
}
}
public int GetIndex(float value)
{
int splitNumber = runtimeInRange.Count;
if (splitNumber <= 0) return -1;
value = Mathf.Clamp(value, m_Min, m_Max);
var diff = (m_Max - m_Min) / (splitNumber - 1);
var index = -1;
for (int i = 0; i < splitNumber; i++)
{
if (value <= m_Min + (i + 1) * diff)
{
index = i;
break;
}
}
return index;
}
public bool IsPiecewise()
{
return m_Type == VisualMap.Type.Piecewise;
}
public bool IsInSelectedValue(float value)
{
if (runtimeSelectedIndex < 0) return true;
else
{
return runtimeSelectedIndex == GetIndex(value);
}
}
public float GetValue(Vector3 pos, Rect chartRect)
{
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
var pos1 = centerPos + (runtimeIsVertical ? Vector3.down : Vector3.left) * itemHeight / 2;
var pos2 = centerPos + (runtimeIsVertical ? Vector3.up : Vector3.right) * itemHeight / 2;
if (runtimeIsVertical)
{
if (pos.y < pos1.y) return min;
else if (pos.y > pos2.y) return max;
else return min + (pos.y - pos1.y) / (pos2.y - pos1.y) * (max - min);
}
else
{
if (pos.x < pos1.x) return min;
else if (pos.x > pos2.x) return max;
else return min + (pos.x - pos1.x) / (pos2.x - pos1.x) * (max - min);
}
}
public bool IsInRect(Vector3 local, Rect chartRect, float triangleLen = 20)
{
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
var diff = calculable ? triangleLen : 0;
if (local.x >= centerPos.x - itemWidth / 2 - diff && local.x <= centerPos.x + itemWidth / 2 + diff &&
local.y >= centerPos.y - itemHeight / 2 - diff && local.y <= centerPos.y + itemHeight / 2 + diff)
{
return true;
}
else
{
return false;
}
}
public bool IsInRangeRect(Vector3 local, Rect chartRect)
{
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
if (orient == Orient.Vertical)
{
var pos1 = centerPos + Vector3.down * itemHeight / 2;
return local.x >= centerPos.x - itemWidth / 2 && local.x <= centerPos.x + itemWidth / 2 &&
local.y >= pos1.y + runtimeRangeMinHeight && local.y <= pos1.y + runtimeRangeMaxHeight;
}
else
{
var pos1 = centerPos + Vector3.left * itemHeight / 2;
return local.x >= pos1.x + runtimeRangeMinHeight && local.x <= pos1.x + runtimeRangeMaxHeight &&
local.y >= centerPos.y - itemWidth / 2 && local.y <= centerPos.y + itemWidth / 2;
}
}
public bool IsInRangeMinRect(Vector3 local, Rect chartRect, float triangleLen)
{
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
if (orient == Orient.Vertical)
{
var radius = triangleLen / 2;
var pos1 = centerPos + Vector3.down * itemHeight / 2;
var cpos = new Vector3(pos1.x + itemWidth / 2 + radius, pos1.y + runtimeRangeMinHeight - radius);
return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
local.y >= cpos.y - radius && local.y <= cpos.y + radius;
}
else
{
var radius = triangleLen / 2;
var pos1 = centerPos + Vector3.left * itemHeight / 2;
var cpos = new Vector3(pos1.x + runtimeRangeMinHeight, pos1.y + itemWidth / 2 + radius);
return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
local.y >= cpos.y - radius && local.y <= cpos.y + radius;
}
}
public bool IsInRangeMaxRect(Vector3 local, Rect chartRect, float triangleLen)
{
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
if (orient == Orient.Vertical)
{
var radius = triangleLen / 2;
var pos1 = centerPos + Vector3.down * itemHeight / 2;
var cpos = new Vector3(pos1.x + itemWidth / 2 + radius, pos1.y + runtimeRangeMaxHeight + radius);
return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
local.y >= cpos.y - radius && local.y <= cpos.y + radius;
}
else
{
var radius = triangleLen / 2;
var pos1 = centerPos + Vector3.left * itemHeight / 2;
var cpos = new Vector3(pos1.x + runtimeRangeMaxHeight + radius, pos1.y + itemWidth / 2 + radius);
return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
local.y >= cpos.y - radius && local.y <= cpos.y + radius;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2df2ffc144e3347828462bb972eec23a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,122 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Grid component.
/// Drawing grid in rectangular coordinate. In a single grid, at most two X and Y axes each is allowed.
/// Line chart, bar chart, and scatter chart can be drawn in grid.
/// There is only one single grid component at most in a single echarts instance.
/// <para>
/// 网格组件。
/// 直角坐标系内绘图网格,单个 grid 内最多可以放置上下两个 X 轴,左右两个 Y 轴。可以在网格上绘制折线图,柱状图,散点图。
/// 单个xcharts实例中只能存在一个grid组件。
/// </para>
/// </summary>
[Serializable]
public class Grid : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Left;
[SerializeField] private float m_Right;
[SerializeField] private float m_Top;
[SerializeField] private float m_Bottom;
[SerializeField] private Color m_BackgroundColor;
/// <summary>
/// Whether to show the grid in rectangular coordinate.
/// 是否显示直角坐标系网格。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Distance between grid component and the left side of the container.
/// grid 组件离容器左侧的距离。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between grid component and the right side of the container.
/// grid 组件离容器右侧的距离。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between grid component and the top side of the container.
/// grid 组件离容器上侧的距离。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between grid component and the bottom side of the container.
/// grid 组件离容器下侧的距离。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
}
/// <summary>
/// Background color of grid, which is transparent by default.
/// 网格背景色,默认透明。
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
public int index { get; internal set; }
public float runtimeX { get; private set; }
public float runtimeY { get; private set; }
public float runtimeWidth { get; private set; }
public float runtimeHeight { get; private set; }
internal void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
{
var runtimeLeft = left <= 1 ? left * chartWidth : left;
var runtimeBottom = bottom <= 1 ? bottom * chartHeight : bottom;
var runtimeTop = top <= 1 ? top * chartHeight : top;
var runtimeRight = right <= 1 ? right * chartWidth : right;
runtimeX = chartX + runtimeLeft;
runtimeY = chartY + runtimeBottom;
runtimeWidth = chartWidth - runtimeLeft - runtimeRight;
runtimeHeight = chartHeight - runtimeTop - runtimeBottom;
}
public static Grid defaultGrid
{
get
{
var grid = new Grid
{
m_Show = true,
m_Left = 50,
m_Right = 30,
m_Top = 50,
m_Bottom = 30
};
return grid;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17af60587e8a04a44a1e166cff567af8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 20d31ade0390641698e6b846b4294b74
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,160 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 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 Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity;
[SerializeField] private bool m_TooltipHighlight;
[SerializeField] private Color32 m_HighlightColor;
[SerializeField] private Color32 m_HighlightToColor;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the origin of area.
/// 区域填充的起始位置。
/// </summary>
public AreaOrigin origin
{
get { return m_Origin; }
set { if (PropertyUtil.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 区域填充的颜色,如果toColor不是默认值,则表示渐变色的起点颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 鼠标悬浮时是否高亮之前的区域
/// </summary>
public bool tooltipHighlight
{
get { return m_TooltipHighlight; }
set { if (PropertyUtil.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 高亮时区域填充的颜色,如果highlightToColor不是默认值,则表示渐变色的起点颜色。
/// </summary>
public Color32 highlightColor
{
get { return m_HighlightColor; }
set { if (PropertyUtil.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start highlightColor to highlightToColor.
/// 高亮时渐变色的终点颜色。
/// </summary>
public Color32 highlightToColor
{
get { return m_HighlightToColor; }
set { if (PropertyUtil.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); }
}
public static AreaStyle defaultAreaStyle
{
get
{
var area = new AreaStyle
{
m_Show = false,
m_Color = Color.clear,
m_ToColor = Color.clear,
m_Opacity = 0.6f
};
return area;
}
}
public Color32 GetColor()
{
if (m_Opacity == 1) return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
return color;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec0d95a9298bb4c159dcae36020beec9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,97 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// </summary>
[Serializable]
public class Arrow : SubComponent
{
[SerializeField] private float m_Width = 10;
[SerializeField] private float m_Height = 15;
[SerializeField] private float m_Offset = 0;
[SerializeField] private float m_Dent = 3;
[SerializeField] private Color32 m_Color = Color.clear;
/// <summary>
/// The widht of arrow.
/// 箭头宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of arrow.
/// 箭头高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// The offset of arrow.
/// 箭头偏移。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// The dent of arrow.
/// 箭头的凹度。
/// </summary>
public float dent
{
get { return m_Dent; }
set { if (PropertyUtil.SetStruct(ref m_Dent, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of arrow.
/// 箭头颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
public Arrow Clone()
{
var arrow = new Arrow();
arrow.width = width;
arrow.height = height;
arrow.offset = offset;
arrow.dent = dent;
arrow.color = color;
return arrow;
}
public void Copy(Arrow arrow)
{
width = arrow.width;
height = arrow.height;
offset = arrow.offset;
dent = arrow.dent;
color = arrow.color;
}
public Color32 GetColor(Color32 defaultColor)
{
if (ChartHelper.IsClearColor(color)) return defaultColor;
else return color;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf0a2263a511d4348a256df8e732bb1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,243 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
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_Margin;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_ShowAsPositiveNumber = false;
[SerializeField] private bool m_OnZero = false;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Set this to false to prevent the axis label from appearing.
/// 是否显示刻度标签。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// The display interval of the axis label.
/// 坐标轴刻度标签的显示间隔,在类目轴中有效。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。
/// </summary>
public int interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetComponentDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
/// 刻度标签是否朝内,默认朝外。
/// </summary>
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
}
/// <summary>
/// The margin between the axis label and the axis line.
/// 刻度标签与轴线之间的距离。
/// </summary>
public float margin
{
get { return m_Margin; }
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetComponentDirty(); }
}
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {value}。
/// </summary>
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Standard numeric format strings.
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。
/// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Show negative number as positive number.
/// 将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。
/// </summary>
public bool showAsPositiveNumber
{
get { return m_ShowAsPositiveNumber; }
set { if (PropertyUtil.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); }
}
/// <summary>
/// 刻度标签显示在0刻度上。
/// </summary>
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本限制。
/// </summary>
public TextLimit textLimit
{
get { return m_TextLimit; }
set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } }
}
/// <summary>
/// The text style of axis name.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
textLimit.ClearComponentDirty();
}
public static AxisLabel defaultAxisLabel
{
get
{
return new AxisLabel()
{
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Margin = 8,
m_TextStyle = new TextStyle(),
};
}
}
public AxisLabel Clone()
{
var axisLable = new AxisLabel();
axisLable.show = show;
axisLable.formatter = formatter;
axisLable.interval = interval;
axisLable.inside = inside;
axisLable.margin = margin;
axisLable.numericFormatter = numericFormatter;
axisLable.textLimit = textLimit.Clone();
axisLable.textStyle.Copy(textStyle);
return axisLable;
}
public void Copy(AxisLabel axisLable)
{
show = axisLable.show;
formatter = axisLable.formatter;
interval = axisLable.interval;
inside = axisLable.inside;
margin = axisLable.margin;
numericFormatter = axisLable.numericFormatter;
textLimit.Copy(axisLable.textLimit);
textStyle.Copy(axisLable.textStyle);
}
public void SetRelatedText(ChartText txt, float labelWidth)
{
m_TextLimit.SetRelatedText(txt, labelWidth);
}
public string GetFormatterContent(string category)
{
if (string.IsNullOrEmpty(category)) return category;
if (string.IsNullOrEmpty(m_Formatter))
{
return m_TextLimit.GetLimitContent(category);
}
else
{
var content = m_Formatter;
FormatterHelper.ReplaceAxisLabelContent(ref content, category);
return m_TextLimit.GetLimitContent(content);
}
}
public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false)
{
if (showAsPositiveNumber && value < 0)
{
value = Mathf.Abs(value);
}
if (string.IsNullOrEmpty(m_Formatter))
{
if (isLog)
{
return ChartCached.NumberToStr(value, numericFormatter);
}
if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1)
{
int minAcc = ChartHelper.GetFloatAccuracy(minValue);
int maxAcc = ChartHelper.GetFloatAccuracy(maxValue);
int curAcc = ChartHelper.GetFloatAccuracy(value);
int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc);
return ChartCached.FloatToStr(value, numericFormatter, acc);
}
return ChartCached.NumberToStr(value, numericFormatter);
}
else
{
var content = m_Formatter;
FormatterHelper.ReplaceAxisLabelContent(ref content, numericFormatter, value);
return content;
}
}
public string GetFormatterDateTime(DateTime dateTime)
{
var format = string.IsNullOrEmpty(numericFormatter) ? "yyyy/M/d" : numericFormatter;
if (!string.IsNullOrEmpty(m_Formatter))
{
var content = m_Formatter;
FormatterHelper.ReplaceAxisLabelContent(ref content, dateTime.ToString(format));
return m_TextLimit.GetLimitContent(content);
}
else
{
var content = dateTime.ToString(format);
return m_TextLimit.GetLimitContent(content);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 867b1c4fd101c43f79a82de245e9c1d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,84 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to axis line.
/// 坐标轴轴线。
/// </summary>
[System.Serializable]
public class AxisLine : BaseLine
{
[SerializeField] private bool m_OnZero;
[SerializeField] private bool m_ShowArrow;
[SerializeField] private Arrow m_Arrow = new Arrow();
/// <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 { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the arrow symbol of axis.
/// 是否显示箭头。
/// </summary>
public bool showArrow
{
get { return m_ShowArrow; }
set { if (PropertyUtil.SetStruct(ref m_ShowArrow, value)) SetVerticesDirty(); }
}
/// <summary>
/// the arrow of line.
/// 轴线箭头。
/// </summary>
public Arrow arrow
{
get { return m_Arrow; }
set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); }
}
public static AxisLine defaultAxisLine
{
get
{
var axisLine = new AxisLine
{
m_Show = true,
m_OnZero = true,
m_ShowArrow = false,
m_Arrow = new Arrow(),
m_LineStyle = new LineStyle(LineStyle.Type.None),
};
return axisLine;
}
}
public AxisLine Clone()
{
var axisLine = new AxisLine();
axisLine.show = show;
axisLine.onZero = onZero;
axisLine.showArrow = showArrow;
axisLine.arrow = arrow.Clone();
return axisLine;
}
public void Copy(AxisLine axisLine)
{
base.Copy(axisLine);
onZero = axisLine.onZero;
showArrow = axisLine.showArrow;
arrow.Copy(axisLine.arrow);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dee861621714d43519f0f1581e027a57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,105 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 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 TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Whether to show axis name.
/// 是否显示坐标名称。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the name of axis.
/// 坐标轴名称。
/// </summary>
public string name
{
get { return m_Name; }
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); }
}
/// <summary>
/// Location of axis name.
/// 坐标轴名称显示位置。
/// </summary>
public Location location
{
get { return m_Location; }
set { if (PropertyUtil.SetStruct(ref m_Location, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of axis name.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
public static AxisName defaultAxisName
{
get
{
return new AxisName()
{
m_Show = false,
m_Name = "axisName",
m_Location = Location.End,
m_TextStyle = new TextStyle(),
};
}
}
public AxisName Clone()
{
var axisName = new AxisName();
axisName.show = show;
axisName.name = name;
axisName.location = location;
axisName.textStyle.Copy(textStyle);
return axisName;
}
public void Copy(AxisName axisName)
{
show = axisName.show;
name = axisName.name;
location = axisName.location;
textStyle.Copy(axisName.textStyle);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f354d1d9b4e841c1b0068bf656b28c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,87 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 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<Color32> m_Color;
/// <summary>
/// Set this to true to show the splitArea.
/// 是否显示分隔区域。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <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<Color32> color
{
get { return m_Color; }
set { if (value != null) { m_Color = value; SetVerticesDirty(); } }
}
public static AxisSplitArea defaultSplitArea
{
get
{
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color32>() { }
};
}
}
public AxisSplitArea Clone()
{
var axisSplitArea = new AxisSplitArea();
axisSplitArea.show = show;
axisSplitArea.color = new List<Color32>();
ChartHelper.CopyList(axisSplitArea.color, color);
return axisSplitArea;
}
public void Copy(AxisSplitArea splitArea)
{
show = splitArea.show;
color.Clear();
ChartHelper.CopyList(color, splitArea.color);
}
public Color32 GetColor(int index, BaseAxisTheme theme)
{
if (color.Count > 0)
{
var i = index % color.Count;
return color[i];
}
else
{
var i = index % theme.splitAreaColors.Count;
return theme.splitAreaColors[i];
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e3ad5d1729154c73b47342a46f0d3b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Split line of axis in grid area.
/// 坐标轴在 grid 区域中的分隔线。
/// </summary>
[Serializable]
public class AxisSplitLine : BaseLine
{
[SerializeField] private int m_Interval;
public int interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();
}
public static AxisSplitLine defaultSplitLine
{
get
{
return new AxisSplitLine()
{
m_Show = false,
};
}
}
public AxisSplitLine Clone()
{
var axisSplitLine = new AxisSplitLine();
axisSplitLine.show = show;
axisSplitLine.interval = interval;
axisSplitLine.lineStyle = lineStyle.Clone();
return axisSplitLine;
}
public void Copy(AxisSplitLine splitLine)
{
base.Copy(splitLine);
interval = splitLine.interval;
}
internal bool NeedShow(int index)
{
return show && (interval == 0 || index % (interval + 1) == 0);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62c6ea03f6ffe431a9c4730cce152c80
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,73 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to axis tick.
/// 坐标轴刻度相关设置。
/// </summary>
[System.Serializable]
public class AxisTick : BaseLine
{
[SerializeField] private bool m_AlignWithLabel;
[SerializeField] private bool m_Inside;
/// <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 { if (PropertyUtil.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
/// 坐标轴刻度是否朝内,默认朝外。
/// </summary>
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); }
}
public static AxisTick defaultTick
{
get
{
var tick = new AxisTick
{
m_Show = true,
m_AlignWithLabel = false,
m_Inside = false,
};
return tick;
}
}
public AxisTick Clone()
{
var axisTick = new AxisTick();
axisTick.show = show;
axisTick.alignWithLabel = alignWithLabel;
axisTick.inside = inside;
axisTick.lineStyle = lineStyle.Clone();
return axisTick;
}
public void Copy(AxisTick axisTick)
{
show = axisTick.show;
alignWithLabel = axisTick.alignWithLabel;
inside = axisTick.inside;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9cff8225584c4d9492c252c09977060
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,89 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to base line.
/// 线条基础配置。
/// </summary>
[System.Serializable]
public class BaseLine : SubComponent
{
[SerializeField] protected bool m_Show;
[SerializeField] protected LineStyle m_LineStyle = new LineStyle();
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } }
}
public static BaseLine defaultBaseLine
{
get
{
var axisLine = new BaseLine
{
m_Show = true,
m_LineStyle = new LineStyle()
};
return axisLine;
}
}
public BaseLine()
{
lineStyle = new LineStyle();
}
public BaseLine(bool show) : base()
{
m_Show = show;
}
public void Copy(BaseLine axisLine)
{
show = axisLine.show;
lineStyle.Copy(axisLine.lineStyle);
}
public LineStyle.Type GetType(LineStyle.Type themeType)
{
return lineStyle.GetType(themeType);
}
public float GetWidth(float themeWidth)
{
return lineStyle.GetWidth(themeWidth);
}
public float GetLength(float themeLength)
{
return lineStyle.GetLength(themeLength);
}
public Color32 GetColor(Color32 themeColor)
{
return lineStyle.GetColor(themeColor);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4c431b00ccffe4db4b61179b6df06eb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,72 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 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();
public void Reset()
{
m_Show = false;
m_Label.Reset();
m_ItemStyle.Reset();
}
/// <summary>
/// 是否启用高亮样式。
/// </summary>
public bool show
{
get { return m_Show; }
set { m_Show = value; }
}
/// <summary>
/// 图形文本标签。
/// </summary>
public SerieLabel label
{
get { return m_Label; }
set { if (PropertyUtil.SetClass(ref m_Label, value, true)) SetAllDirty(); }
}
/// <summary>
/// 图形样式。
/// </summary>
public ItemStyle itemStyle
{
get { return m_ItemStyle; }
set { if (PropertyUtil.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || label.vertsDirty || itemStyle.vertsDirty; } }
public override bool componentDirty { get { return m_ComponentDirty || label.componentDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
label.ClearVerticesDirty();
itemStyle.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
label.ClearComponentDirty();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e0b1690532674b24952a87e0aead6fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,168 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge axis line.
/// 仪表盘轴线相关设置。
/// </summary>
[System.Serializable]
public class GaugeAxis : SubComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private GaugeAxisLine m_AxisLine = new GaugeAxisLine(true);
[SerializeField] private GaugeAxisSplitLine m_SplitLine = new GaugeAxisSplitLine(true);
[SerializeField] private GaugeAxisTick m_AxisTick = new GaugeAxisTick(true);
[SerializeField] private SerieLabel m_AxisLabel = new SerieLabel();
[SerializeField] private List<string> m_AxisLabelText = new List<string>();
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// axis line style.
/// 仪表盘轴线样式。
/// </summary>
public GaugeAxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
/// <summary>
/// slit line style.
/// 分割线。
/// </summary>
public GaugeAxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
/// <summary>
/// axis tick style.
/// 刻度。
/// </summary>
public GaugeAxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
/// <summary>
/// axis label style.
/// 文本标签。
/// </summary>
public SerieLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
/// <summary>
/// Coordinate axis scale label custom content. When the content is empty,
/// `axisLabel` automatically displays the content according to the scale; otherwise,
/// the content is taken from the list definition.
///
/// 自定义Label的内容。
/// </summary>
public List<string> axisLabelText { get { return m_AxisLabelText; } set { m_AxisLabelText = value; } }
public List<float> runtimeStageAngle = new List<float>();
public List<Vector3> runtimeLabelPosition = new List<Vector3>();
private List<ChartLabel> m_RuntimeLabelList = new List<ChartLabel>();
internal Color32 GetAxisLineColor(ChartTheme theme, int index)
{
var color = !ChartHelper.IsClearColor(axisLine.barColor) ? axisLine.barColor : theme.GetColor(index);
ChartHelper.SetColorOpacity(ref color, axisLine.lineStyle.opacity);
return color;
}
internal Color32 GetAxisLineBackgroundColor(ChartTheme theme, int index)
{
var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor)
? axisLine.barBackgroundColor : ChartConst.greyColor32;
ChartHelper.SetColorOpacity(ref color, axisLine.lineStyle.opacity);
return color;
}
internal Color32 GetSplitLineColor(Color32 themeColor, int serieIndex, float angle)
{
Color32 color;
if (!ChartHelper.IsClearColor(splitLine.lineStyle.color))
{
color = splitLine.lineStyle.color;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
color = themeColor;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
internal Color32 GetAxisTickColor(Color32 themeColor, int serieIndex, float angle)
{
Color32 color;
if (!ChartHelper.IsClearColor(axisTick.lineStyle.color))
{
color = axisTick.lineStyle.color;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
color = themeColor;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
internal Color32 GetPointerColor(ChartTheme theme, int serieIndex, float angle, ItemStyle itemStyle)
{
Color32 color;
if (!ChartHelper.IsClearColor(itemStyle.color))
{
return itemStyle.GetColor();
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
color = theme.GetColor(serieIndex);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
public void ClearLabelObject()
{
m_RuntimeLabelList.Clear();
}
public void AddLabelObject(ChartLabel label)
{
m_RuntimeLabelList.Add(label);
}
public ChartLabel GetLabelObject(int index)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
return m_RuntimeLabelList[index];
}
return null;
}
public void SetLabelObjectPosition(int index, Vector3 pos)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
m_RuntimeLabelList[index].SetPosition(pos);
}
}
public void SetLabelObjectText(int index, string text)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
m_RuntimeLabelList[index].SetText(text);
}
}
public void SetLabelObjectActive(bool flag)
{
foreach (var label in m_RuntimeLabelList)
{
label.SetActive(flag);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67cba46d89b9b478fa6dcf067e7b49b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,63 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color32 m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
public float percent { get { return m_Percent; } set { m_Percent = value; } }
/// <summary>
/// 颜色。
/// </summary>
public Color32 color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color32 color)
{
m_Percent = percent;
m_Color = color;
}
}
[System.Serializable]
public class GaugeAxisLine : BaseLine
{
[SerializeField] private Color32 m_BarColor;
[SerializeField] private Color32 m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
/// <summary>
/// 进度条颜色。
/// </summary>
public Color32 barColor { get { return m_BarColor; } set { m_BarColor = value; } }
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
public GaugeAxisLine(bool show) : base(show)
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c35880091e5a4382876c47bd843a99f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
namespace XCharts
{
/// <summary>
/// 分割线
/// </summary>
[System.Serializable]
public class GaugeAxisSplitLine : BaseLine
{
public GaugeAxisSplitLine(bool show) : base(show)
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27a5f68720fa741ddbd50217b585a9e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// 刻度
/// </summary>
[System.Serializable]
public class GaugeAxisTick : BaseLine
{
[SerializeField] private float m_SplitNumber = 5;
/// <summary>
/// 分割线之间的分割段数。
/// </summary>
public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
public GaugeAxisTick(bool show) : base(show)
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e9ace80811494ca5aad05b59c61a74f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge pointer.
/// 仪表盘指针相关设置。
/// </summary>
[System.Serializable]
public class GaugePointer : SubComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 0.8f;
[SerializeField] private float m_Width = 15;
/// <summary>
/// Whether to display a pointer.
/// 是否显示指针。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Pointer length. It can be an absolute value, or it can be a percentage relative to the radius (0-1).
/// 指针长度。可以是绝对值,也可以是相对于半径的百分比(0-1的浮点数)。
/// </summary>
public float length
{
get { return m_Length; }
set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <summary>
/// Pointer width.
/// 指针宽度。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55e453b57f6514da09e98571439d4dcc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,75 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// 系列数据项的图标
/// </summary>
[System.Serializable]
public class IconStyle : SubComponent
{
public enum Layer
{
UnderLabel,
AboveLabel
}
[SerializeField] private bool m_Show;
[SerializeField] private Layer m_Layer;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 40;
[SerializeField] private float m_Height = 40;
[SerializeField] private Vector3 m_Offset;
public void Reset()
{
m_Show = false;
m_Layer = Layer.UnderLabel;
m_Sprite = null;
m_Color = Color.white;
m_Width = 40;
m_Height = 40;
m_Offset = Vector3.zero;
}
/// <summary>
/// Whether the data icon is show.
/// 是否显示图标。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 显示在上层还是在下层。
/// </summary>
public Layer layer { get { return m_Layer; } set { m_Layer = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
/// <summary>
/// 图标偏移。
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82c4d360f7b5b4ee7845e9bbe611c8a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,311 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
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 Color32 m_Color;
[SerializeField] private Color32 m_Color0;
[SerializeField] private Color32 m_ToColor;
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth;
[SerializeField] private Color32 m_CenterColor;
[SerializeField] private float m_CenterGap;
[SerializeField] private Type m_BorderType = Type.Solid;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color32 m_BorderColor;
[SerializeField] private Color32 m_BorderColor0;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField] private string m_TooltipFormatter;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
public void Reset()
{
m_Show = false;
m_Color = Color.clear;
m_Color0 = Color.clear;
m_ToColor = Color.clear;
m_ToColor2 = Color.clear;
m_BackgroundColor = Color.clear;
m_BackgroundWidth = 0;
m_CenterColor = Color.clear;
m_CenterGap = 0;
m_BorderType = Type.Solid;
m_BorderWidth = 0;
m_BorderColor = Color.clear;
m_BorderColor0 = Color.clear;
m_Opacity = 1;
m_TooltipFormatter = null;
m_NumericFormatter = "";
if (m_CornerRadius == null)
{
m_CornerRadius = new float[] { 0, 0, 0, 0 };
}
else
{
for (int i = 0; i < m_CornerRadius.Length; i++)
m_CornerRadius[i] = 0;
}
}
/// <summary>
/// 是否启用。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项颜色。
/// </summary>
public Color32 color0
{
get { return m_Color0; }
set { if (PropertyUtil.SetColor(ref m_Color0, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color1.
/// 渐变色的颜色1。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color2.Only valid in line diagrams.
/// 渐变色的颜色2。只在折线图中有效。
/// </summary>
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景颜色。
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域颜色。
/// </summary>
public Color32 centerColor
{
get { return m_CenterColor; }
set { if (PropertyUtil.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域间隙。
/// </summary>
public float centerGap
{
get { return m_CenterGap; }
set { if (PropertyUtil.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景宽度。
/// </summary>
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的类型。
/// </summary>
public Type borderType
{
get { return m_BorderType; }
set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
/// </summary>
public Color32 borderColor0
{
get { return m_BorderColor0; }
set { if (PropertyUtil.SetColor(ref m_BorderColor0, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框宽。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 提示框单项的字符串模版格式器。具体配置参考`Tooltip`的`formatter`
/// </summary>
public string tooltipFormatter
{
get { return m_TooltipFormatter; }
set { if (PropertyUtil.SetClass(ref m_TooltipFormatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// Standard numeric format strings.
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。
/// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
/// 圆角半径。用数组分别指定4个圆角半径(顺时针左上,右上,右下,左下)。
/// </summary>
public float[] cornerRadius
{
get { return m_CornerRadius; }
set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 实际边框宽。边框不显示时为0。
/// </summary>
public float runtimeBorderWidth { get { return NeedShowBorder() ? borderWidth : 0; } }
/// <summary>
/// 是否需要显示边框。
/// </summary>
public bool NeedShowBorder()
{
return borderWidth != 0 && !ChartHelper.IsClearColor(borderColor);
}
public Color32 GetColor()
{
if (m_Opacity == 1 || m_Color.a == 0) return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0()
{
if (m_Opacity == 1 || m_Color0.a == 0) return m_Color0;
var color = m_Color0;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
if (m_Opacity == 1 || color.a == 0) return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_Color0) ? defaultColor : m_Color0;
if (m_Opacity == 1 || color.a == 0) return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetBorderColor(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_BorderColor) ? defaultColor : m_BorderColor;
if (m_Opacity == 1 || color.a == 0) return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetBorderColor0(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_BorderColor0) ? defaultColor : m_BorderColor0;
if (m_Opacity == 1 || color.a == 0) return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public bool IsNeedGradient()
{
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
}
public Color32 GetGradientColor(float value, Color32 defaultColor)
{
if (!IsNeedGradient()) return ChartConst.clearColor32;
value = Mathf.Clamp01(value);
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
Color32 color;
if (!ChartHelper.IsClearColor(m_ToColor2))
{
if (value <= 0.5f) color = Color32.Lerp(startColor, m_ToColor, 2 * value);
else color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
}
else
{
color = Color32.Lerp(startColor, m_ToColor, value);
}
if (m_Opacity != 1)
{
color.a = (byte)(color.a * m_Opacity);
}
return color;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ca9b30f9779c4a16b60cc21334828b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 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 Arrow m_Arrow = new Arrow()
{
width = 10,
height = 15,
offset = 0,
dent = 3
};
/// <summary>
/// Whether to show the arrow.
/// 是否显示箭头。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The position of arrow.
/// 箭头位置。
/// </summary>
public Position position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// the arrow of line.
/// 箭头。
/// </summary>
public Arrow arrow
{
get { return m_Arrow; }
set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); }
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f2455acb3ba34409896bf03ddba593e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,239 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of line.
/// 线条样式。
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color,线条颜色默认也会取该颜色。
/// toColor,toColor2可设置水平方向的渐变,如需要设置垂直方向的渐变,可使用VisualMap。
/// </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,
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Length = 0;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// Whether show line.
/// 是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of line.
/// 线的类型。
/// </summary>
public Type type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of line, default use serie color.
/// 线的颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// the middle color of line, default use serie color.
/// 线的渐变颜色(需要水平方向渐变时)。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the end color of line, default use serie color.
/// 线的渐变颜色2(需要水平方向三个渐变色的渐变时)。
/// </summary>
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of line.
/// 线宽。
/// /// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// the length of line.
/// 线长。
/// /// </summary>
public float length
{
get { return m_Length; }
set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
public LineStyle()
{
}
public LineStyle(float width)
{
this.width = width;
}
public LineStyle(LineStyle.Type type)
{
this.type = type;
}
public LineStyle(LineStyle.Type type, float width)
{
this.type = type;
this.width = width;
}
public LineStyle Clone()
{
var lineStyle = new LineStyle();
lineStyle.show = show;
lineStyle.type = type;
lineStyle.color = color;
lineStyle.toColor = toColor;
lineStyle.toColor2 = toColor2;
lineStyle.width = width;
lineStyle.opacity = opacity;
return lineStyle;
}
public void Copy(LineStyle lineStyle)
{
show = lineStyle.show;
type = lineStyle.type;
color = lineStyle.color;
toColor = lineStyle.toColor;
toColor2 = lineStyle.toColor2;
width = lineStyle.width;
opacity = lineStyle.opacity;
}
public Color32 GetColor()
{
if (m_Opacity == 1) return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public bool IsNeedGradient()
{
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
}
public Color32 GetGradientColor(float value, Color32 defaultColor)
{
var color = ChartConst.clearColor32;
if (!IsNeedGradient()) return color;
value = Mathf.Clamp01(value);
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
if (!ChartHelper.IsClearColor(m_ToColor2))
{
if (value <= 0.5f) color = Color32.Lerp(startColor, m_ToColor, 2 * value);
else color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
}
else
{
color = Color32.Lerp(startColor, m_ToColor, value);
}
if (m_Opacity != 1)
{
color.a = (byte)(color.a * m_Opacity);
}
return color;
}
public Type GetType(Type themeType)
{
return type == Type.None ? themeType : type;
}
public float GetWidth(float themeWidth)
{
return width == 0 ? themeWidth : width;
}
public float GetLength(float themeLength)
{
return length == 0 ? themeLength : length;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
return color;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 092f08a2daa4b4013a72ffc3c9a18f85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,318 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
/// <summary>
/// Location type. Quick to set the general location.
/// 位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置。
/// </summary>
[Serializable]
public class Location : SubComponent, IPropertyChanged
{
/// <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_TextAlignment;
#if dUI_TextMeshPro
private TextAlignmentOptions m_TMPTextAlignment;
#endif
private Vector2 m_AnchorMin;
private Vector2 m_AnchorMax;
private Vector2 m_Pivot;
/// <summary>
/// 对齐方式。
/// </summary>
public Align align
{
get { return m_Align; }
set { if (PropertyUtil.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器左侧的距离。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器右侧的距离。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器上侧的距离。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器下侧的距离。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// the anchor of text.
/// Location对应的Anchor锚点
/// </summary>
/// <value></value>
public TextAnchor runtimeTextAlignment { get { return m_TextAlignment; } }
#if dUI_TextMeshPro
public TextAlignmentOptions runtimeTMPTextAlignment { get { return m_TMPTextAlignment; } }
#endif
/// <summary>
/// the minimum achor.
/// Location对应的anchorMin。
/// </summary>
/// <value></value>
public Vector2 runtimeAnchorMin { get { return m_AnchorMin; } }
/// <summary>
/// the maximun achor.
/// Location对应的anchorMax.
/// </summary>
/// <value></value>
public Vector2 runtimeAnchorMax { get { return m_AnchorMax; } }
/// <summary>
/// the povot.
/// Loation对应的中心点。
/// </summary>
/// <value></value>
public Vector2 runtimePivot { 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_TextAlignment = TextAnchor.LowerCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Bottom;
#endif
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_TextAlignment = TextAnchor.LowerLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.BottomLeft;
#endif
m_AnchorMin = new Vector2(0, 0);
m_AnchorMax = new Vector2(0, 0);
m_Pivot = new Vector2(0, 0);
break;
case Align.BottomRight:
m_TextAlignment = TextAnchor.LowerRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.BottomRight;
#endif
m_AnchorMin = new Vector2(1, 0);
m_AnchorMax = new Vector2(1, 0);
m_Pivot = new Vector2(1, 0);
break;
case Align.Center:
m_TextAlignment = TextAnchor.MiddleCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Center;
#endif
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_TextAlignment = TextAnchor.MiddleLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Left;
#endif
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_TextAlignment = TextAnchor.MiddleRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Right;
#endif
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_TextAlignment = TextAnchor.UpperCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Top;
#endif
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_TextAlignment = TextAnchor.UpperLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.TopLeft;
#endif
m_AnchorMin = new Vector2(0, 1);
m_AnchorMax = new Vector2(0, 1);
m_Pivot = new Vector2(0, 1);
break;
case Align.TopRight:
m_TextAlignment = TextAnchor.UpperRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.TopRight;
#endif
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;
}
}
/// <summary>
/// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
/// </summary>
public void OnChanged()
{
UpdateAlign();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7922ce86a6b0f4813a7f34e004b92e9a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,513 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
using System;
namespace XCharts
{
public delegate float CustomAnimationDelay(int dataIndex);
public delegate float CustomAnimationDuration(int dataIndex);
/// <summary>
/// the animation of serie.
/// 动画表现。
/// </summary>
[System.Serializable]
public class SerieAnimation : SubComponent
{
public enum Easing
{
Linear,
}
[SerializeField] private bool m_Enable = true;
[SerializeField] private Easing m_Easting;
[SerializeField] private int m_Threshold = 2000;
[SerializeField] private float m_FadeInDuration = 1000;
[SerializeField] private float m_FadeInDelay = 0;
[SerializeField] private float m_FadeOutDuration = 1000f;
[SerializeField] private float m_FadeOutDelay = 0;
[SerializeField] private bool m_DataChangeEnable = true;
[SerializeField] private float m_DataChangeDuration = 500;
[SerializeField] private float m_ActualDuration;
/// <summary>
/// 自定义渐入动画延时函数。返回ms值。
/// </summary>
public CustomAnimationDelay customFadeInDelay;
/// <summary>
/// 自定义渐入动画时长函数。返回ms值。
/// </summary>
public CustomAnimationDuration customFadeInDuration;
/// <summary>
/// 自定义渐出动画延时函数。返回ms值。
/// </summary>
public CustomAnimationDelay customFadeOutDelay;
/// <summary>
/// 自定义渐出动画时长函数。返回ms值。
/// </summary>
public CustomAnimationDuration customFadeOutDuration;
/// <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>
//public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
/// <summary>
/// The milliseconds duration of the fadeIn animation.
/// 设定的渐入动画时长(毫秒)。如果要设置单个数据项的渐入时长,可以用代码定制:customFadeInDuration。
/// </summary>
public float fadeInDuration { get { return m_FadeInDuration; } set { m_FadeInDuration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds duration of the fadeOut animation.
/// 设定的渐出动画时长(毫秒)。如果要设置单个数据项的渐出时长,可以用代码定制:customFadeOutDuration。
/// </summary>
public float fadeOutDuration { get { return m_FadeOutDuration; } set { m_FadeOutDuration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。
/// </summary>
public float 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>
public int threshold { get { return m_Threshold; } set { m_Threshold = value; } }
/// <summary>
/// The milliseconds delay before updating the first animation.
/// 渐入动画延时(毫秒)。如果要设置单个数据项的延时,可以用代码定制:customFadeInDelay。
/// </summary>
public float fadeInDelay { get { return m_FadeInDelay; } set { m_FadeInDelay = value < 0 ? 0 : value; } }
/// <summary>
/// 渐出动画延时(毫秒)。如果要设置单个数据项的延时,可以用代码定制:customFadeOutDelay。
/// </summary>
public float fadeOutDelay { get { return m_FadeOutDelay; } set { m_FadeInDelay = value < 0 ? 0 : value; } }
/// <summary>
/// 是否开启数据变更动画。
/// </summary>
public bool dataChangeEnable { get { return m_DataChangeEnable; } set { m_DataChangeEnable = value; } }
/// <summary>
/// The milliseconds duration of the data change animation.
/// 数据变更的动画时长(毫秒)。
/// </summary>
public float dataChangeDuration { get { return m_DataChangeDuration; } set { m_DataChangeDuration = value < 0 ? 0 : value; } }
/// <summary>
/// 渐入动画完成回调
/// </summary>
public Action fadeInFinishCallback { get; set; }
/// <summary>
/// 渐出动画完成回调
/// </summary>
public Action fadeOutFinishCallback { get; set; }
private Dictionary<int, float> m_DataCurrProgress = new Dictionary<int, float>();
private Dictionary<int, float> m_DataDestProgress = new Dictionary<int, float>();
private bool m_FadeIn = false;
private bool m_IsEnd = true;
private bool m_IsPause = false;
private bool m_FadeOut = false;
private bool m_FadeOuted = false;
private bool m_IsInit = 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 FadeIn()
{
if (m_FadeOut) return;
if (m_IsPause)
{
m_IsPause = false;
return;
}
if (m_FadeIn) return;
startTime = Time.time;
m_FadeIn = true;
m_IsEnd = false;
m_IsInit = false;
m_IsPause = false;
m_FadeOuted = false;
m_CurrDataProgress = 1;
m_DestDataProgress = 1;
m_CurrDetailProgress = 0;
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_DataCurrProgress.Clear();
m_DataDestProgress.Clear();
}
public void Restart()
{
Reset();
FadeIn();
}
public void FadeOut()
{
if (m_IsPause)
{
m_IsPause = false;
return;
}
m_FadeOut = true;
startTime = Time.time;
m_FadeIn = true;
m_IsEnd = false;
m_IsInit = false;
m_IsPause = false;
m_CurrDataProgress = 0;
m_DestDataProgress = 0;
m_CurrDetailProgress = 0;
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_DataCurrProgress.Clear();
m_DataDestProgress.Clear();
}
public void Pause()
{
if (!m_IsPause)
{
m_IsPause = true;
}
}
public void Resume()
{
if (m_IsPause)
{
m_IsPause = false;
}
}
private void End()
{
if (m_IsEnd) return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - (m_FadeOut ? fadeOutDelay : fadeInDelay);
m_CurrDataProgress = m_DestDataProgress + (m_FadeOut ? -1 : 1);
m_IsEnd = true;
m_IsInit = false;
if (m_FadeIn)
{
m_FadeIn = false;
if (fadeInFinishCallback != null)
{
fadeInFinishCallback();
}
}
if (m_FadeOut)
{
m_FadeOut = false;
m_FadeOuted = true;
if (fadeOutFinishCallback != null)
{
fadeOutFinishCallback();
}
}
}
public void Reset()
{
m_FadeIn = false;
m_IsEnd = true;
m_IsInit = false;
m_IsPause = false;
m_FadeOut = false;
m_FadeOuted = false;
m_DataCurrProgress.Clear();
}
public void InitProgress(int data, float curr, float dest)
{
if (m_IsInit || m_IsEnd) return;
if (curr > dest) return;
m_IsInit = true;
m_DestDataProgress = data;
if (m_FadeOut)
{
m_CurrDetailProgress = dest;
m_DestDetailProgress = curr;
}
else
{
m_CurrDetailProgress = curr;
m_DestDetailProgress = dest;
}
}
public void SetDataFinish(int dataIndex)
{
if (m_IsEnd) return;
m_CurrDataProgress = dataIndex + (m_FadeOut ? -1 : 1);
}
private void SetDataCurrProgress(int index, float state)
{
m_DataCurrProgress[index] = state;
}
private float GetDataCurrProgress(int index, float initValue, float destValue, out bool isBarEnd)
{
if (IsInDelay())
{
isBarEnd = false;
return initValue;
}
var c1 = !m_DataCurrProgress.ContainsKey(index);
var c2 = !m_DataDestProgress.ContainsKey(index);
if (c1 || c2)
{
if (c1) m_DataCurrProgress.Add(index, initValue);
if (c2) m_DataDestProgress.Add(index, destValue);
isBarEnd = false;
}
else
{
isBarEnd = m_DataCurrProgress[index] == m_DataDestProgress[index];
}
return m_DataCurrProgress[index];
}
public bool IsFinish()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return true;
#endif
return !m_Enable || m_IsEnd || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress);
}
public bool IsInFadeOut()
{
return m_FadeOut;
}
public bool IsInDelay()
{
if (m_FadeOut) return (fadeOutDelay > 0 && Time.time - startTime < fadeOutDelay / 1000);
return (fadeInDelay > 0 && Time.time - startTime < fadeInDelay / 1000);
}
public float GetDataDelay(int dataIndex)
{
if (m_FadeOut && customFadeOutDelay != null) return customFadeOutDelay(dataIndex);
if (m_FadeIn && customFadeInDelay != null) return customFadeInDelay(dataIndex);
return 0;
}
public bool IsInDataDelay(int dataIndex)
{
return Time.time - startTime < GetDataDelay(dataIndex) / 1000f;
}
public bool IsAllOutDelay(int dataCount)
{
var nowTime = Time.time - startTime;
for (int i = 0; i < dataCount; i++)
{
if (nowTime < GetDataDelay(i) / 1000) return false;
}
return true;
}
public bool IsAllDataFinishProgress(int dataCount)
{
for (int i = 0; i < dataCount; i++)
{
if (m_DataDestProgress.ContainsKey(i) && m_DataCurrProgress.ContainsKey(i))
{
if (m_DataCurrProgress[i] != m_DataDestProgress[i]) return false;
}
else
{
return false;
}
}
return true;
}
public bool CheckDetailBreak(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;
if (m_FadeOut) return dataIndex > 0;
else return dataIndex <= m_CurrDataProgress;
}
internal void CheckProgress(float total)
{
if (IsFinish()) return;
if (!m_IsInit || m_IsPause || m_IsEnd) return;
if (IsInDelay()) return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - fadeInDelay;
var duration = GetCurrAnimationDuration();
var delta = total / duration * Time.deltaTime;
if (m_FadeOut)
{
m_CurrDetailProgress -= delta;
if (m_CurrDetailProgress <= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
}
else
{
m_CurrDetailProgress += delta;
if (m_CurrDetailProgress >= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
}
}
internal float GetCurrAnimationDuration(int dataIndex = -1)
{
if (dataIndex >= 0)
{
if (m_FadeOut && customFadeOutDuration != null) return customFadeOutDuration(dataIndex) / 1000f;
if (m_FadeIn && customFadeInDuration != null) return customFadeInDuration(dataIndex) / 1000f;
}
if (m_FadeOut) return m_FadeOutDuration > 0 ? m_FadeOutDuration / 1000 : 1f;
else return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1f;
}
internal float CheckBarProgress(int dataIndex, float barHig, int dataCount, out bool isBarEnd)
{
isBarEnd = false;
var initHig = m_FadeOut ? barHig : 0;
var destHig = m_FadeOut ? 0 : barHig;
var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, out isBarEnd);
if (isBarEnd || IsFinish())
{
return m_FadeOuted ? 0 : barHig;
}
else if (IsInDelay() || IsInDataDelay(dataIndex))
{
return m_FadeOut ? barHig : 0;
}
else if (m_IsPause)
{
return currHig;
}
else
{
var duration = GetCurrAnimationDuration(dataIndex);
var delta = barHig / duration * Time.deltaTime;
currHig = currHig + (m_FadeOut ? -delta : delta);
if (m_FadeOut)
{
if ((initHig > 0 && currHig <= 0) || (initHig < 0 && currHig >= 0))
{
currHig = 0;
isBarEnd = true;
}
}
else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
{
currHig = barHig;
isBarEnd = true;
}
SetDataCurrProgress(dataIndex, currHig);
return currHig;
}
}
internal void AllBarEnd()
{
End();
}
internal void CheckSymbol(float dest)
{
if (!enable || m_IsEnd || m_IsPause || !m_IsInit) return;
if (IsInDelay()) return;
var duration = GetCurrAnimationDuration();
var delta = dest / duration * Time.deltaTime;
if (m_FadeOut)
{
m_CurrSymbolProgress -= delta;
if (m_CurrSymbolProgress < 0) m_CurrSymbolProgress = 0;
}
else
{
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) return dest;
if (m_IsEnd) return m_FadeOut ? 0 : 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;
}
public float GetUpdateAnimationDuration()
{
if (m_Enable && m_DataChangeEnable && IsFinish()) return m_DataChangeDuration;
else return 0;
}
public bool HasFadeOut()
{
return enable && m_FadeOuted && m_IsEnd;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6560100f155244fba80a175e6a28139
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,364 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
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 IconStyle m_IconStyle = new IconStyle();
[SerializeField] private bool m_EnableLabel = false;
[SerializeField] private SerieLabel m_Label = new SerieLabel();
[SerializeField] private bool m_EnableItemStyle = false;
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
[SerializeField] private bool m_EnableEmphasis = false;
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
[SerializeField] private bool m_EnableSymbol = false;
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
[SerializeField] private List<float> m_Data = new List<float>();
public ChartLabel labelObject { get; set; }
private bool m_Show = true;
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>
/// the icon of data.
/// 数据项图标样式。
/// </summary>
public IconStyle iconStyle { get { return m_IconStyle; } set { m_IconStyle = value; } }
/// <summary>
/// 是否启用单个数据项的标签设置。
/// </summary>
public bool enableLabel { get { return m_EnableLabel; } set { m_EnableLabel = value; } }
/// <summary>
/// 单个数据项的标签设置。
/// </summary>
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
/// <summary>
/// 是否启用单个数据项的样式。
/// </summary>
public bool enableItemStyle { get { return m_EnableItemStyle; } set { m_EnableItemStyle = value; } }
/// <summary>
/// 单个数据项的样式设置。
/// </summary>
public ItemStyle itemStyle { get { return m_ItemStyle; } set { m_ItemStyle = value; } }
/// <summary>
/// 是否启用单个数据项的高亮样式。
/// </summary>
public bool enableEmphasis { get { return m_EnableEmphasis; } set { m_EnableEmphasis = value; } }
/// <summary>
/// 单个数据项的高亮样式设置。
/// </summary>
public Emphasis emphasis { get { return m_Emphasis; } set { m_Emphasis = value; } }
/// <summary>
/// 是否启用单个数据项的标记设置。
/// </summary>
public bool enableSymbol { get { return m_EnableSymbol; } set { m_EnableSymbol = value; } }
/// <summary>
/// 单个数据项的标记设置。
/// </summary>
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = 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; }
public Vector3 labelPosition { get; set; }
private 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
{
if (m_Data.Count == 0) return 0;
float temp = float.MinValue;
for (int i = 0; i < m_Data.Count; i++)
{
if (m_Data[i] > temp) temp = m_Data[i];
}
return temp;
}
}
/// <summary>
/// the mininum value.
/// 最小值。
/// </summary>
public float min
{
get
{
if (m_Data.Count == 0) return 0;
float temp = float.MaxValue;
for (int i = 0; i < m_Data.Count; i++)
{
if (m_Data[i] < temp) temp = m_Data[i];
}
return temp;
}
}
/// <summary>
/// 饼图数据项的开始角度(运行时自动计算)
/// </summary>
public float runtimePieStartAngle { get; internal set; }
/// <summary>
/// 饼图数据项的结束角度(运行时自动计算)
/// </summary>
public float runtimePieToAngle { get; internal set; }
/// <summary>
/// 饼图数据项的一半时的角度(运行时自动计算)
/// </summary>
public float runtimePieHalfAngle { get; internal set; }
/// <summary>
/// 饼图数据项的当前角度(运行时自动计算)
/// </summary>
public float runtimePieCurrAngle { get; internal set; }
/// <summary>
/// 饼图数据项的内半径
/// </summary>
public float runtimePieInsideRadius { get; internal set; }
/// <summary>
/// 饼图数据项的外半径
/// </summary>
public float runtimePieOutsideRadius
{
get
{
if (radius > 0) return radius;
else return m_RtPieOutsideRadius;
}
internal set
{
m_RtPieOutsideRadius = value;
}
}
/// <summary>
/// 饼图数据项的偏移半径
/// </summary>
public float runtimePieOffsetRadius { get; internal set; }
public Vector3 runtimePosition { get; internal set; }
/// <summary>
/// 绘制区域。
/// </summary>
public Rect runtimeRect { get; internal set; }
public float runtimeAngle { get; internal set; }
public Vector3 runtiemPieOffsetCenter { get; internal set; }
public float runtimeStackHig { get; internal set; }
private List<float> m_PreviousData = new List<float>();
private List<float> m_DataUpdateTime = new List<float>();
private List<bool> m_DataUpdateFlag = new List<bool>();
public void Reset()
{
index = 0;
labelObject = null;
highlighted = false;
m_Name = string.Empty;
m_Show = true;
m_Selected = false;
m_CanShowLabel = true;
m_EnableSymbol = false;
m_EnableLabel = false;
m_EnableEmphasis = false;
m_EnableItemStyle = false;
m_Radius = 0;
m_Data.Clear();
m_PreviousData.Clear();
m_DataUpdateTime.Clear();
m_DataUpdateFlag.Clear();
m_IconStyle.Reset();
m_Label.Reset();
m_ItemStyle.Reset();
m_Emphasis.Reset();
}
public float GetData(int index, bool inverse = false)
{
if (index >= 0 && index < m_Data.Count)
{
return inverse ? -m_Data[index] : m_Data[index];
}
else return 0;
}
public float GetPreviousData(int index, bool inverse = false)
{
if (index >= 0 && index < m_PreviousData.Count)
{
return inverse ? -m_PreviousData[index] : m_PreviousData[index];
}
else return 0;
}
public float GetFirstData(float animationDuration = 500f)
{
if (m_Data.Count > 0) return GetCurrData(0, animationDuration);
return 0;
}
public float GetLastData()
{
if (m_Data.Count > 0) return m_Data[m_Data.Count - 1];
return 0;
}
public float GetCurrData(int index, float animationDuration = 500f, bool inverse = false)
{
return GetCurrData(index, animationDuration, inverse, 0, 0);
}
public float GetCurrData(int index, float animationDuration, bool inverse, float min, float max)
{
if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0)
{
var time = Time.time - m_DataUpdateTime[index];
var total = animationDuration / 1000;
var rate = time / total;
if (rate > 1) rate = 1;
if (rate < 1)
{
CheckLastData();
var curr = Mathf.Lerp(GetPreviousData(index), GetData(index), rate);
if (min != 0 || max != 0)
{
if (inverse)
{
var temp = min;
min = -max;
max = -temp;
}
var pre = m_PreviousData[index];
if (pre < min)
{
m_PreviousData[index] = min;
curr = min;
}
else if (pre > max)
{
m_PreviousData[index] = max;
curr = max;
}
}
curr = inverse ? -curr : curr;
return curr;
}
else
{
m_DataUpdateFlag[index] = false;
return GetData(index, inverse);
}
}
else
{
return GetData(index, inverse);
}
}
public bool UpdateData(int dimension, float value, bool updateAnimation, float animationDuration = 500f)
{
if (dimension >= 0 && dimension < data.Count)
{
CheckLastData();
m_PreviousData[dimension] = GetCurrData(dimension, animationDuration);
//m_PreviousData[dimension] = data[dimension];;
m_DataUpdateTime[dimension] = Time.time;
m_DataUpdateFlag[dimension] = updateAnimation;
data[dimension] = value;
return true;
}
return false;
}
private void CheckLastData()
{
if (m_PreviousData.Count != m_Data.Count)
{
m_PreviousData.Clear();
m_DataUpdateTime.Clear();
m_DataUpdateFlag.Clear();
for (int i = 0; i < m_Data.Count; i++)
{
m_PreviousData.Add(m_Data[i]);
m_DataUpdateTime.Add(Time.time);
m_DataUpdateFlag.Add(false);
}
}
}
public bool IsDataChanged()
{
foreach (var b in m_DataUpdateFlag)
if (b) return true;
return false;
}
public float GetLabelWidth()
{
if (labelObject != null) return labelObject.GetLabelWidth();
else return 0;
}
public float GetLabelHeight()
{
if (labelObject != null) return labelObject.GetLabelHeight();
return 0;
}
public void SetLabelActive(bool flag)
{
if (labelObject != null) labelObject.SetLabelActive(flag);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fce2a5796a5ab4817a4a91d0f7af39ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,329 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
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 = Position.Outside;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private float m_Margin;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_PaddingLeftRight = 2f;
[SerializeField] private float m_PaddingTopBottom = 2f;
[SerializeField] private float m_BackgroundWidth = 0;
[SerializeField] private float m_BackgroundHeight = 0;
[SerializeField] private bool m_Line = true;
[SerializeField] private LineType m_LineType = LineType.BrokenLine;
[SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
[SerializeField] private float m_LineWidth = 1.0f;
[SerializeField] private float m_LineLength1 = 25f;
[SerializeField] private float m_LineLength2 = 15f;
[SerializeField] private bool m_Border = false;
[SerializeField] private float m_BorderWidth = 0.5f;
[SerializeField] private Color32 m_BorderColor = ChartConst.greyColor32;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_AutoOffset = false;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
public void Reset()
{
m_Show = false;
m_Position = Position.Outside;
m_Offset = Vector3.zero;
m_Margin = 0;
m_PaddingLeftRight = 2f;
m_PaddingTopBottom = 2f;
m_BackgroundWidth = 0;
m_BackgroundHeight = 0;
m_Line = true;
m_LineType = LineType.BrokenLine;
m_LineColor = Color.clear;
m_LineWidth = 1.0f;
m_LineLength1 = 25f;
m_LineLength2 = 15f;
m_Border = false;
m_BorderWidth = 0.5f;
m_BorderColor = Color.grey;
m_NumericFormatter = "";
m_AutoOffset = false;
}
/// <summary>
/// Whether the label is showed.
/// 是否显示文本标签。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// The position of label.
/// 标签的位置。
/// </summary>
public Position position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <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 { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// offset to the host graphic element.
/// 距离图形元素的偏移
/// </summary>
public Vector3 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// 距离轴线的距离。
/// </summary>
public float margin
{
get { return m_Margin; }
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of left and right. defaut:2.
/// 左右边距。
/// </summary>
public float paddingLeftRight
{
get { return m_PaddingLeftRight; }
set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of top and bottom. defaut:2.
/// 上下边距。
/// </summary>
public float paddingTopBottom
{
get { return m_PaddingTopBottom; }
set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
}
/// <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 { if (PropertyUtil.SetStruct(ref m_Line, value)) SetComponentDirty(); }
}
/// <summary>
/// the type of visual guide line.
/// 视觉引导线类型。
/// </summary>
public LineType lineType
{
get { return m_LineType; }
set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of visual guild line.
/// 视觉引导线颜色。默认和serie一致取自调色板。
/// </summary>
public Color32 lineColor
{
get { return m_LineColor; }
set { if (PropertyUtil.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of visual guild line.
/// 视觉引导线的宽度。
/// </summary>
public float lineWidth
{
get { return m_LineWidth; }
set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the first segment of visual guide line.
/// 视觉引导线第一段的长度。
/// </summary>
public float lineLength1
{
get { return m_LineLength1; }
set { if (PropertyUtil.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the second segment of visual guide line.
/// 视觉引导线第二段的长度。
/// </summary>
public float lineLength2
{
get { return m_LineLength2; }
set { if (PropertyUtil.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show border.
/// 是否显示边框。
/// </summary>
public bool border
{
get { return m_Border; }
set { if (PropertyUtil.SetStruct(ref m_Border, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of border.
/// 边框宽度。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of border.
/// 边框颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Standard numeric format strings.
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。
/// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
/// </summary>
public bool autoOffset
{
get { return m_AutoOffset; }
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
}
/// <summary>
/// the sytle of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c595e94871c8a4c12a5bc5d5dc533652
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,310 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 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>
/// 正方形。可通过设置`itemStyle`的`cornerRadius`变成圆角矩形。
/// </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 bool m_Show = true;
[SerializeField] private SerieSymbolType m_Type = SerieSymbolType.EmptyCircle;
[SerializeField] private SerieSymbolSizeType m_SizeType = SerieSymbolSizeType.Custom;
[SerializeField] private float m_Size = 0f;
[SerializeField] private float m_SelectedSize = 0f;
[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 int m_StartIndex;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
[SerializeField] private float m_Gap = 0;
public void Reset()
{
m_Show = false;
m_Type = SerieSymbolType.EmptyCircle;
m_SizeType = SerieSymbolSizeType.Custom;
m_Size = 0f;
m_SelectedSize = 0f;
m_DataIndex = 1;
m_DataScale = 1;
m_SelectedDataScale = 1.5f;
m_SizeCallback = null;
m_SelectedSizeCallback = null;
m_StartIndex = 0;
m_Interval = 0;
m_ForceShowLast = false;
m_Gap = 0;
}
/// <summary>
/// Whether the symbol is showed.
/// 是否显示标记。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of symbol.
/// 标记类型。
/// </summary>
public SerieSymbolType type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of symbol size.
/// 标记图形的大小获取方式。
/// </summary>
public SerieSymbolSizeType sizeType
{
get { return m_SizeType; }
set { if (PropertyUtil.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of symbol.
/// 标记的大小。
/// </summary>
public float size
{
get { return m_Size; }
set { if (PropertyUtil.SetStruct(ref m_Size, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of selected symbol.
/// 被选中的标记的大小。
/// </summary>
public float selectedSize
{
get { return m_SelectedSize; }
set { if (PropertyUtil.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// whitch data index is when the sizeType assined as FromData.
/// 当sizeType指定为FromData时,指定的数据源索引。
/// </summary>
public int dataIndex
{
get { return m_DataIndex; }
set { if (PropertyUtil.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of data when sizeType assined as FromData.
/// 当sizeType指定为FromData时,指定的倍数系数。
/// </summary>
public float dataScale
{
get { return m_DataScale; }
set { if (PropertyUtil.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of selected data when sizeType assined as FromData.
/// 当sizeType指定为FromData时,指定的高亮倍数系数。
/// </summary>
public float selectedDataScale
{
get { return m_SelectedDataScale; }
set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时,指定的回调函数。
/// </summary>
public SymbolSizeCallback sizeCallback
{
get { return m_SizeCallback; }
set { if (PropertyUtil.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时,指定的高亮回调函数。
/// </summary>
public SymbolSizeCallback selectedSizeCallback
{
get { return m_SelectedSizeCallback; }
set { if (PropertyUtil.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
/// 开始显示图形标记的索引。
/// </summary>
public int startIndex
{
get { return m_StartIndex; }
set { if (PropertyUtil.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the interval of show symbol.
/// 显示图形标记的间隔。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。
/// </summary>
public int interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// whether to show the last symbol.
/// 是否强制显示最后一个图形标记。
/// </summary>
public bool forceShowLast
{
get { return m_ForceShowLast; }
set { if (PropertyUtil.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); }
}
/// <summary>
/// the gap of symbol and line segment.
/// 图形标记和线条的间隙距离。
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
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, float themeSize)
{
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
return size == 0 ? themeSize : size;
case SerieSymbolSizeType.FromData:
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return data[dataIndex] * m_DataScale;
}
else
{
return size == 0 ? themeSize : size;
}
case SerieSymbolSizeType.Callback:
if (data != null && sizeCallback != null) return sizeCallback(data);
else return size == 0 ? themeSize : size;
default: return size == 0 ? themeSize : size;
}
}
/// <summary>
/// 根据sizeType获得高亮时的标记大小
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSelectedSize(List<float> data, float themeSelectedSize)
{
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
return selectedSize == 0 ? themeSelectedSize : selectedSize;
case SerieSymbolSizeType.FromData:
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return data[dataIndex] * m_SelectedDataScale;
}
else
{
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
case SerieSymbolSizeType.Callback:
if (data != null && selectedSizeCallback != null) return selectedSizeCallback(data);
else return selectedSize == 0 ? themeSelectedSize : selectedSize;
default: return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
}
public bool ShowSymbol(int dataIndex, int dataCount)
{
if (!show) 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;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a1f0c7348b7f54d4bbccc777a74c1d77
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,152 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// Text character limitation and adaptation component. When the length of the text exceeds the set length,
/// it is cropped and suffixes are appended to the end.Only valid in the category axis.
/// 文本字符限制和自适应。当文本长度超过设定的长度时进行裁剪,并将后缀附加在最后。
/// 只在类目轴中有效。
/// </summary>
[Serializable]
public class TextLimit : SubComponent
{
[SerializeField] private bool m_Enable = true;
[SerializeField] private float m_MaxWidth = 0;
[SerializeField] private float m_Gap = 1;
[SerializeField] private string m_Suffix = "...";
/// <summary>
/// Whether to enable text limit.
/// 是否启用文本自适应。
/// [default:true]
/// </summary>
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetComponentDirty(); }
}
/// <summary>
/// Set the maximum width. A default of 0 indicates automatic fetch; otherwise, custom.
/// Clipping occurs when the width of the text is greater than this value.
/// 设定最大宽度。默认为0表示自动获取,否则表示自定义。当文本的宽度大于该值进行裁剪。
/// </summary>
public float maxWidth
{
get { return m_MaxWidth; }
set { if (PropertyUtil.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// White pixel distance at both ends.
/// 两边留白像素距离。
/// [default:10f]
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetComponentDirty(); }
}
/// <summary>
/// Suffixes when the length exceeds.
/// 长度超出时的后缀。
/// [default: "..."]
/// </summary>
public string suffix
{
get { return m_Suffix; }
set { if (PropertyUtil.SetClass(ref m_Suffix, value)) SetComponentDirty(); }
}
private ChartText m_RelatedText;
private float m_RelatedTextWidth = 0;
public TextLimit Clone()
{
var textLimit = new TextLimit();
textLimit.enable = enable;
textLimit.maxWidth = maxWidth;
textLimit.gap = gap;
textLimit.suffix = suffix;
return textLimit;
}
public void Copy(TextLimit textLimit)
{
enable = textLimit.enable;
maxWidth = textLimit.maxWidth;
gap = textLimit.gap;
suffix = textLimit.suffix;
}
public void SetRelatedText(ChartText txt, float labelWidth)
{
m_RelatedText = txt;
m_RelatedTextWidth = labelWidth;
}
public string GetLimitContent(string content)
{
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
if (m_RelatedText == null || checkWidth <= 0) return content;
else
{
if (m_Enable)
{
float len = m_RelatedText.GetPreferredWidth(content);
float suffixLen = m_RelatedText.GetPreferredWidth(suffix);
if (len >= checkWidth - m_Gap * 2)
{
return content.Substring(0, GetAdaptLength(content, suffixLen)) + suffix;
}
else
{
return content;
}
}
else
{
return content;
}
}
}
private int GetAdaptLength(string content, float suffixLen)
{
int start = 0;
int middle = content.Length / 2;
int end = content.Length;
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
float limit = checkWidth - m_Gap * 2 - suffixLen;
if (limit < 0) return 0;
float len = 0;
while (len != limit && middle != start)
{
len = m_RelatedText.GetPreferredWidth(content.Substring(0, middle));
if (len < limit)
{
start = middle;
}
else if (len > limit)
{
end = middle;
}
else
{
break;
}
middle = (start + end) / 2;
}
return middle;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f49509a5de044535b1dd3f192f7008c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,217 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
/// <summary>
/// Settings related to text.
/// 文本的相关设置。
/// </summary>
[Serializable]
public class TextStyle : SubComponent
{
[SerializeField] private Font m_Font;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 0;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private float m_LineSpacing = 1f;
[SerializeField] private TextAnchor m_Alignment = TextAnchor.MiddleCenter;
#if dUI_TextMeshPro
[SerializeField] private TMP_FontAsset m_TMPFont;
[SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal;
[SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left;
#endif
/// <summary>
/// Rotation of text.
/// 文本的旋转。
/// [default: `0f`]
/// </summary>
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of position.
/// 坐标偏移。
/// [Default: `Vector2.zero`]
/// </summary>
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
/// <summary>
/// the color of text.
/// 文本的颜色。
/// [default: `Color.clear`]
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本的背景颜色。
/// [default: `Color.clear`]
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font of text. When `null`, the theme's font is used by default.
/// 文本字体。
/// [default: null]
/// </summary>
public Font font
{
get { return m_Font; }
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文本字体大小。
/// [default: 18]
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
/// 文本字体的风格。
/// [default: FontStyle.Normal]
/// </summary>
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtil.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// text line spacing.
/// 行间距。
/// [default: 1f]
/// </summary>
public float lineSpacing
{
get { return m_LineSpacing; }
set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
}
/// <summary>
/// 对齐方式。
/// </summary>
public TextAnchor alignment
{
get { return m_Alignment; }
set { if (PropertyUtil.SetStruct(ref m_Alignment, value)) SetComponentDirty(); }
}
#if dUI_TextMeshPro
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
}
public FontStyles tmpFontStyle
{
get { return m_TMPFontStyle; }
set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); }
}
public TextAlignmentOptions tmpAlignment
{
get { return m_TMPAlignment; }
set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); }
}
#endif
public TextStyle()
{
}
public TextStyle(int fontSize)
{
this.fontSize = fontSize;
}
public TextStyle(int fontSize, FontStyle fontStyle)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
}
public TextStyle(int fontSize, FontStyle fontStyle, Color color)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.color = color;
}
public TextStyle(int fontSize, FontStyle fontStyle, Color color, int rorate)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.color = color;
this.rotate = rotate;
}
public void Copy(TextStyle textStyle)
{
font = textStyle.font;
rotate = textStyle.rotate;
offset = textStyle.offset;
color = textStyle.color;
backgroundColor = textStyle.backgroundColor;
fontSize = textStyle.fontSize;
fontStyle = textStyle.fontStyle;
lineSpacing = textStyle.lineSpacing;
alignment = textStyle.alignment;
#if dUI_TextMeshPro
m_TMPFont = textStyle.tmpFont;
m_TMPAlignment = textStyle.tmpAlignment;
m_TMPFontStyle = textStyle.tmpFontStyle;
#endif
}
public void UpdateAlignmentByLocation(Location location)
{
#if dUI_TextMeshPro
m_TMPAlignment = location.runtimeTMPTextAlignment;
#else
m_Alignment = location.runtimeTextAlignment;
#endif
}
public Color GetColor(Color defaultColor)
{
if (ChartHelper.IsClearColor(color)) return defaultColor;
else return color;
}
public int GetFontSize(ComponentTheme defaultTheme)
{
if(fontSize == 0) return defaultTheme.fontSize;
else return fontSize;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8f6b652968894ab195666501dda672c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,97 @@
/*
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
namespace XCharts
{
/// <summary>
/// the title of serie.
/// 标题相关设置。
/// </summary>
[Serializable]
public class TitleStyle : SubComponent
{
[SerializeField] private bool m_Show;
[FormerlySerializedAs("m_textStyle")]
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Whether to show title.
/// 是否显示标题。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本的颜色。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
}
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
public ChartText runtimeText { get; set; }
public bool IsInited()
{
return runtimeText != null;
}
public void SetActive(bool active)
{
if (runtimeText != null)
{
runtimeText.SetActive(active);
}
}
public void UpdatePosition(Vector3 pos)
{
if (runtimeText != null)
{
runtimeText.SetLocalPosition(pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y));
}
}
public void SetText(string text)
{
if (runtimeText == null) return;
var oldText = runtimeText.GetText();
if (oldText != null && !oldText.Equals(text))
{
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.SetColor(textStyle.color);
runtimeText.SetText(text);
}
}
public void SetColor(Color color)
{
if (runtimeText != null)
{
runtimeText.SetColor(color);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f3865dea73ae403581fe83cfeca13f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cf2fdcbe222404d7b869946ef6fee032
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,255 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
[Serializable]
public class BaseAxisTheme : ComponentTheme
{
[SerializeField] protected LineStyle.Type m_LineType = LineStyle.Type.Solid;
[SerializeField] protected float m_LineWidth = 1f;
[SerializeField] protected float m_LineLength = 0f;
[SerializeField] protected Color32 m_LineColor;
[SerializeField] protected LineStyle.Type m_SplitLineType = LineStyle.Type.Dashed;
[SerializeField] protected float m_SplitLineWidth = 1f;
[SerializeField] protected float m_SplitLineLength = 0f;
[SerializeField] protected Color32 m_SplitLineColor;
[SerializeField] protected float m_TickWidth = 1f;
[SerializeField] protected float m_TickLength = 5f;
[SerializeField] protected Color32 m_TickColor;
[SerializeField] protected List<Color32> m_SplitAreaColors = new List<Color32>();
/// <summary>
/// the type of line.
/// 坐标轴线类型。
/// </summary>
public LineStyle.Type lineType
{
get { return m_LineType; }
set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of line.
/// 坐标轴线宽。
/// </summary>
public float lineWidth
{
get { return m_LineWidth; }
set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the length of line.
/// 坐标轴线长。
/// </summary>
public float lineLength
{
get { return m_LineLength; }
set { if (PropertyUtil.SetStruct(ref m_LineLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of line.
/// 坐标轴线颜色。
/// </summary>
public Color32 lineColor
{
get { return m_LineColor; }
set { if (PropertyUtil.SetColor(ref m_LineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of split line.
/// 分割线线类型。
/// </summary>
public LineStyle.Type splitLineType
{
get { return m_SplitLineType; }
set { if (PropertyUtil.SetStruct(ref m_SplitLineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of split line.
/// 分割线线宽。
/// </summary>
public float splitLineWidth
{
get { return m_SplitLineWidth; }
set { if (PropertyUtil.SetStruct(ref m_SplitLineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the length of split line.
/// 分割线线长。
/// </summary>
public float splitLineLength
{
get { return m_SplitLineLength; }
set { if (PropertyUtil.SetStruct(ref m_SplitLineLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of line.
/// 分割线线颜色。
/// </summary>
public Color32 splitLineColor
{
get { return m_SplitLineColor; }
set { if (PropertyUtil.SetColor(ref m_SplitLineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the length of tick.
/// 刻度线线长。
/// </summary>
public float tickLength
{
get { return m_TickLength; }
set { if (PropertyUtil.SetStruct(ref m_TickLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of tick.
/// 刻度线线宽。
/// </summary>
public float tickWidth
{
get { return m_TickWidth; }
set { if (PropertyUtil.SetStruct(ref m_TickWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of tick.
/// 坐标轴线颜色。
/// </summary>
public Color32 tickColor
{
get { return m_TickColor; }
set { if (PropertyUtil.SetColor(ref m_TickColor, value)) SetVerticesDirty(); }
}
public List<Color32> splitAreaColors
{
get { return m_SplitAreaColors; }
set { if (value != null) { m_SplitAreaColors = value; SetVerticesDirty(); } }
}
public BaseAxisTheme(Theme theme) : base(theme)
{
m_FontSize = XChartsSettings.fontSizeLv4;
m_LineType = XChartsSettings.axisLineType;
m_LineWidth = XChartsSettings.axisLineWidth;
m_LineLength = 0;
m_SplitLineType = XChartsSettings.axisSplitLineType;
m_SplitLineWidth = XChartsSettings.axisSplitLineWidth;
m_SplitLineLength = 0;
m_TickWidth = XChartsSettings.axisTickWidth;
m_TickLength = XChartsSettings.axisTickLength;
switch (theme)
{
case Theme.Default:
m_LineColor = ColorUtil.GetColor("#514D4D");
m_TickColor = ColorUtil.GetColor("#514D4D");
m_SplitLineColor = ColorUtil.GetColor("#51515120");
m_SplitAreaColors = new List<Color32>{
new Color32(250,250,250,77),
new Color32(200,200,200,77)
};
break;
case Theme.Light:
m_LineColor = ColorUtil.GetColor("#514D4D");
m_TickColor = ColorUtil.GetColor("#514D4D");
m_SplitLineColor = ColorUtil.GetColor("#51515120");
m_SplitAreaColors = new List<Color32>{
new Color32(250,250,250,77),
new Color32(200,200,200,77)
};
break;
case Theme.Dark:
m_LineColor = ColorUtil.GetColor("#B9B8CE");
m_TickColor = ColorUtil.GetColor("#B9B8CE");
m_SplitLineColor = ColorUtil.GetColor("#484753");
m_SplitAreaColors = new List<Color32>{
new Color32(255,255,255,(byte)(0.02f * 255)),
new Color32(255,255,255,(byte)(0.05f * 255))
};
break;
}
}
public void Copy(BaseAxisTheme theme)
{
base.Copy(theme);
m_LineType = theme.lineType;
m_LineWidth = theme.lineWidth;
m_LineLength = theme.lineLength;
m_LineColor = theme.lineColor;
m_SplitLineType = theme.splitLineType;
m_SplitLineWidth = theme.splitLineWidth;
m_SplitLineLength = theme.splitLineLength;
m_SplitLineColor = theme.splitLineColor;
m_TickWidth = theme.tickWidth;
m_TickLength = theme.tickLength;
m_TickColor = theme.tickColor;
ChartHelper.CopyList(m_SplitAreaColors, theme.splitAreaColors);
}
}
[Serializable]
public class AxisTheme : BaseAxisTheme
{
public AxisTheme(Theme theme) : base(theme)
{
}
}
[Serializable]
public class RadiusAxisTheme : BaseAxisTheme
{
public RadiusAxisTheme(Theme theme) : base(theme)
{
}
}
[Serializable]
public class AngleAxisTheme : BaseAxisTheme
{
public AngleAxisTheme(Theme theme) : base(theme)
{
}
}
[Serializable]
public class PolarAxisTheme : BaseAxisTheme
{
public PolarAxisTheme(Theme theme) : base(theme)
{
}
}
[Serializable]
public class RadarAxisTheme : BaseAxisTheme
{
public RadarAxisTheme(Theme theme) : base(theme)
{
m_SplitAreaColors.Clear();
switch (theme)
{
case Theme.Dark:
m_SplitAreaColors.Add(ChartTheme.GetColor("#6f6f6f"));
m_SplitAreaColors.Add(ChartTheme.GetColor("#606060"));
break;
case Theme.Default:
m_SplitAreaColors.Add(ChartTheme.GetColor("#f6f6f6"));
m_SplitAreaColors.Add(ChartTheme.GetColor("#e7e7e7"));
break;
case Theme.Light:
m_SplitAreaColors.Add(ChartTheme.GetColor("#f6f6f6"));
m_SplitAreaColors.Add(ChartTheme.GetColor("#e7e7e7"));
break;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aefd22e76a6f642c9985b1a29e389858
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,541 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
/// <summary>
/// 主题
/// </summary>
public enum Theme
{
/// <summary>
/// 默认主题。
/// </summary>
Default,
/// <summary>
/// 亮主题。
/// </summary>
Light,
/// <summary>
/// 暗主题。
/// </summary>
Dark,
/// <summary>
/// 自定义主题。
/// </summary>
Custom,
}
[Serializable]
/// <summary>
/// Theme.
/// 主题相关配置。
/// </summary>
public class ChartTheme : ScriptableObject
{
[SerializeField] private Theme m_Theme = Theme.Default;
[SerializeField] private string m_ThemeName = Theme.Default.ToString();
[SerializeField] private Font m_Font;
#if dUI_TextMeshPro
[SerializeField] private TMP_FontAsset m_TMPFont;
#endif
[SerializeField] private Color32 m_ContrastColor;
[SerializeField] private Color32 m_BackgroundColor;
#if UNITY_2020_2
[NonReorderable]
#endif
[SerializeField] private List<Color32> m_ColorPalette = new List<Color32>(13);
[SerializeField] private ComponentTheme m_Common;
[SerializeField] private TitleTheme m_Title;
[SerializeField] private SubTitleTheme m_SubTitle;
[SerializeField] private LegendTheme m_Legend;
[SerializeField] private AxisTheme m_Axis;
[SerializeField] private RadiusAxisTheme m_RadiusAxis;
[SerializeField] private AngleAxisTheme m_AngleAxis;
[SerializeField] private PolarAxisTheme m_Polar;
[SerializeField] private GaugeAxisTheme m_Gauge;
[SerializeField] private RadarAxisTheme m_Radar;
[SerializeField] private TooltipTheme m_Tooltip;
[SerializeField] private DataZoomTheme m_DataZoom;
[SerializeField] private VisualMapTheme m_VisualMap;
[SerializeField] private SerieTheme m_Serie;
/// <summary>
/// the theme of chart.
/// 主题类型。
/// </summary>
public Theme theme
{
get { return m_Theme; }
set { if (PropertyUtil.SetStruct(ref m_Theme, value)) SetComponentDirty(); }
}
public string themeName
{
get { return m_ThemeName; }
set { if (PropertyUtil.SetClass(ref m_ThemeName, value)) SetComponentDirty(); }
}
/// <summary>
/// the contrast color of chart.
/// 对比色。
/// </summary>
public Color32 contrastColor
{
get { return m_ContrastColor; }
set { if (PropertyUtil.SetColor(ref m_ContrastColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the background color of chart.
/// 背景颜色。
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
/// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。
/// </summary>
public List<Color32> colorPalette { get { return m_ColorPalette; } set { m_ColorPalette = value; SetVerticesDirty(); } }
public ComponentTheme common { get { return m_Common; } set { m_Common = value; SetComponentDirty(); } }
public TitleTheme title { get { return m_Title; } set { m_Title = value; SetComponentDirty(); } }
public SubTitleTheme subTitle { get { return m_SubTitle; } set { m_SubTitle = value; SetComponentDirty(); } }
public LegendTheme legend { get { return m_Legend; } set { m_Legend = value; SetComponentDirty(); } }
public AxisTheme axis { get { return m_Axis; } set { m_Axis = value; SetAllDirty(); } }
public RadiusAxisTheme radiusAxis { get { return m_RadiusAxis; } set { m_RadiusAxis = value; SetAllDirty(); } }
public AngleAxisTheme angleAxis { get { return m_AngleAxis; } set { m_AngleAxis = value; SetAllDirty(); } }
public PolarAxisTheme polar { get { return m_Polar; } set { m_Polar = value; SetAllDirty(); } }
public GaugeAxisTheme gauge { get { return m_Gauge; } set { m_Gauge = value; SetAllDirty(); } }
public RadarAxisTheme radar { get { return m_Radar; } set { m_Radar = value; SetAllDirty(); } }
public TooltipTheme tooltip { get { return m_Tooltip; } set { m_Tooltip = value; SetAllDirty(); } }
public DataZoomTheme dataZoom { get { return m_DataZoom; } set { m_DataZoom = value; SetAllDirty(); } }
public VisualMapTheme visualMap { get { return m_VisualMap; } set { m_VisualMap = value; SetAllDirty(); } }
public SerieTheme serie { get { return m_Serie; } set { m_Serie = value; SetVerticesDirty(); } }
#if dUI_TextMeshPro
/// <summary>
/// the font of chart text。
/// 字体。
/// </summary>
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set
{
if (PropertyUtil.SetClass(ref m_TMPFont, value))
{
SetComponentDirty();
SyncTMPFontToSubComponent();
}
}
}
#endif
/// <summary>
/// the font of chart text。
/// 字体。
/// </summary>
public Font font
{
get { return m_Font; }
set
{
if (PropertyUtil.SetClass(ref m_Font, value))
{
SetComponentDirty();
SyncFontToSubComponent();
}
}
}
[NonSerialized] protected bool m_VertsDirty;
[NonSerialized] protected bool m_ComponentDirty;
public virtual bool vertsDirty { get { return m_VertsDirty; } }
public virtual bool componentDirty { get { return m_ComponentDirty; } }
public bool anyDirty { get { return vertsDirty || componentDirty; } }
public void SetDefaultFont()
{
#if dUI_TextMeshPro
tmpFont = XChartsSettings.tmpFont;
SyncTMPFontToSubComponent();
#else
font = XChartsSettings.font;
SyncFontToSubComponent();
#endif
}
/// <summary>
/// Gets the color of the specified index from the palette.
/// 获得调色盘对应系列索引的颜色值。
/// </summary>
/// <param name="index">编号索引</param>
/// <returns>the color,or Color.clear when failed.颜色值,失败时返回Color.clear</returns>
public Color32 GetColor(int index)
{
if (index < 0) index = 0;
var newIndex = index < m_ColorPalette.Count ? index : index % m_ColorPalette.Count;
if (newIndex < m_ColorPalette.Count)
return m_ColorPalette[newIndex];
else return Color.clear;
}
public void CheckWarning(StringBuilder sb)
{
#if dUI_TextMeshPro
if (m_TMPFont == null)
{
sb.AppendFormat("warning:theme->tmpFont is null\n");
}
#else
if (m_Font == null)
{
sb.AppendFormat("warning:theme->font is null\n");
}
#endif
if (m_ColorPalette.Count == 0)
{
sb.AppendFormat("warning:theme->colorPalette is empty\n");
}
for (int i = 0; i < m_ColorPalette.Count; i++)
{
if (!ChartHelper.IsClearColor(m_ColorPalette[i]) && m_ColorPalette[i].a == 0)
sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i);
}
}
Dictionary<int, string> _colorDic = new Dictionary<int, string>();
/// <summary>
/// Gets the hexadecimal color string of the specified index from the palette.
/// 获得指定索引的十六进制颜色值字符串。
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public string GetColorStr(int index)
{
if (index < 0)
{
index = 0;
}
index = index % m_ColorPalette.Count;
if (_colorDic.ContainsKey(index)) return _colorDic[index];
else
{
_colorDic[index] = ColorUtility.ToHtmlStringRGBA(GetColor(index));
return _colorDic[index];
}
}
public void CopyTheme(Theme theme)
{
switch (theme)
{
case Theme.Dark:
CopyTheme(ChartTheme.Dark);
break;
case Theme.Default:
CopyTheme(ChartTheme.Default);
break;
case Theme.Light:
CopyTheme(ChartTheme.Light);
break;
}
}
/// <summary>
/// copy all configurations from theme.
/// 复制主题的所有配置。
/// </summary>
/// <param name="theme"></param>
public void CopyTheme(ChartTheme theme)
{
m_Theme = theme.theme;
m_ThemeName = theme.themeName;
#if dUI_TextMeshPro
m_TMPFont = theme.tmpFont;
#endif
m_Font = theme.m_Font;
m_ContrastColor = theme.contrastColor;
m_BackgroundColor = theme.m_BackgroundColor;
m_Common.Copy(theme.common);
m_Legend.Copy(theme.m_Legend);
m_Title.Copy(theme.m_Title);
m_SubTitle.Copy(theme.m_SubTitle);
m_Axis.Copy(theme.axis);
m_RadiusAxis.Copy(theme.radiusAxis);
m_AngleAxis.Copy(theme.angleAxis);
m_Polar.Copy(theme.polar);
m_Gauge.Copy(theme.gauge);
m_Tooltip.Copy(theme.tooltip);
m_DataZoom.Copy(theme.dataZoom);
m_VisualMap.Copy(theme.visualMap);
m_Serie.Copy(theme.serie);
ChartHelper.CopyList(m_ColorPalette, theme.colorPalette);
SetAllDirty();
}
/// <summary>
/// Clear all custom configurations.
/// 重置,清除所有自定义配置。
/// </summary>
public void ResetTheme()
{
switch (m_Theme)
{
case Theme.Default: CopyTheme(Default); break;
case Theme.Light: CopyTheme(Light); break;
case Theme.Dark: CopyTheme(Dark); break;
}
}
/// <summary>
/// 克隆主题。
/// </summary>
/// <returns></returns>
public ChartTheme CloneTheme()
{
var theme = ScriptableObject.CreateInstance<ChartTheme>();
InitChartComponentTheme(theme);
theme.CopyTheme(this);
return theme;
}
/// <summary>
/// default theme.
/// 默认主题。
/// </summary>
/// <value></value>
public static ChartTheme Default
{
get
{
var theme = ScriptableObject.CreateInstance<ChartTheme>();
theme.theme = Theme.Default;
theme.themeName = Theme.Default.ToString();
theme.contrastColor = ColorUtil.GetColor("#514D4D");
theme.backgroundColor = new Color32(255, 255, 255, 255);
theme.colorPalette = new List<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)
};
InitChartComponentTheme(theme);
return theme;
}
}
/// <summary>
/// light theme.
/// 亮主题。
/// </summary>
/// <value></value>
public static ChartTheme Light
{
get
{
var theme = ScriptableObject.CreateInstance<ChartTheme>();
theme.theme = Theme.Light;
theme.themeName = Theme.Light.ToString();
theme.contrastColor = ColorUtil.GetColor("#514D4D");
theme.backgroundColor = new Color32(255, 255, 255, 255);
theme.colorPalette = new List<Color32>
{
ColorUtil.GetColor("#37A2DA"),
ColorUtil.GetColor("#32C5E9"),
ColorUtil.GetColor("#67E0E3"),
ColorUtil.GetColor("#9FE6B8"),
ColorUtil.GetColor("#FFDB5C"),
ColorUtil.GetColor("#ff9f7f"),
ColorUtil.GetColor("#fb7293"),
ColorUtil.GetColor("#E062AE"),
ColorUtil.GetColor("#E690D1"),
ColorUtil.GetColor("#e7bcf3"),
ColorUtil.GetColor("#9d96f5"),
ColorUtil.GetColor("#8378EA"),
ColorUtil.GetColor("#96BFFF"),
};
InitChartComponentTheme(theme);
return theme;
}
}
/// <summary>
/// dark theme.
/// 暗主题。
/// </summary>
/// <value></value>
public static ChartTheme Dark
{
get
{
var theme = ScriptableObject.CreateInstance<ChartTheme>();
theme.name = Theme.Dark.ToString();
theme.theme = Theme.Dark;
theme.themeName = Theme.Dark.ToString();
theme.contrastColor = ColorUtil.GetColor("#B9B8CE");
theme.backgroundColor = ColorUtil.GetColor("#100C2A");
theme.colorPalette = new List<Color32>
{
ColorUtil.GetColor("#4992ff"),
ColorUtil.GetColor("#7cffb2"),
ColorUtil.GetColor("#fddd60"),
ColorUtil.GetColor("#ff6e76"),
ColorUtil.GetColor("#58d9f9"),
ColorUtil.GetColor("#05c091"),
ColorUtil.GetColor("#ff8a45"),
ColorUtil.GetColor("#8d48e3"),
ColorUtil.GetColor("#dd79ff"),
};
InitChartComponentTheme(theme);
return theme;
}
}
public static ChartTheme EmptyTheme
{
get
{
var theme = ScriptableObject.CreateInstance<ChartTheme>();
theme.name = Theme.Custom.ToString();
theme.theme = Theme.Custom;
theme.themeName = Theme.Custom.ToString();
theme.contrastColor = Color.clear;
theme.backgroundColor = Color.clear;
theme.colorPalette = new List<Color32>();
InitChartComponentTheme(theme);
return theme;
}
}
public void SyncFontToSubComponent()
{
common.font = font;
title.font = font;
subTitle.font = font;
legend.font = font;
axis.font = font;
radiusAxis.font = font;
angleAxis.font = font;
polar.font = font;
gauge.font = font;
radar.font = font;
tooltip.font = font;
dataZoom.font = font;
visualMap.font = font;
}
#if dUI_TextMeshPro
public void SyncTMPFontToSubComponent()
{
common.tmpFont = tmpFont;
title.tmpFont = tmpFont;
subTitle.tmpFont = tmpFont;
legend.tmpFont = tmpFont;
axis.tmpFont = tmpFont;
radiusAxis.tmpFont = tmpFont;
angleAxis.tmpFont = tmpFont;
polar.tmpFont = tmpFont;
gauge.tmpFont = tmpFont;
radar.tmpFont = tmpFont;
tooltip.tmpFont = tmpFont;
dataZoom.tmpFont = tmpFont;
visualMap.tmpFont = tmpFont;
}
#endif
private static void InitChartComponentTheme(ChartTheme theme)
{
theme.common = new ComponentTheme(theme.theme);
theme.title = new TitleTheme(theme.theme);
theme.subTitle = new SubTitleTheme(theme.theme);
theme.legend = new LegendTheme(theme.theme);
theme.axis = new AxisTheme(theme.theme);
theme.radiusAxis = new RadiusAxisTheme(theme.theme);
theme.angleAxis = new AngleAxisTheme(theme.theme);
theme.polar = new PolarAxisTheme(theme.theme);
theme.gauge = new GaugeAxisTheme(theme.theme);
theme.radar = new RadarAxisTheme(theme.theme);
theme.tooltip = new TooltipTheme(theme.theme);
theme.dataZoom = new DataZoomTheme(theme.theme);
theme.visualMap = new VisualMapTheme(theme.theme);
theme.serie = new SerieTheme(theme.theme);
theme.SetDefaultFont();
}
/// <summary>
/// Convert the html string to color.
/// 将字符串颜色值转成Color。
/// </summary>
/// <param name="hexColorStr"></param>
/// <returns></returns>
public static Color32 GetColor(string hexColorStr)
{
Color color;
ColorUtility.TryParseHtmlString(hexColorStr, out color);
return (Color32)color;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
internal virtual void SetVerticesDirty()
{
m_VertsDirty = true;
}
internal virtual void ClearVerticesDirty()
{
m_VertsDirty = false;
}
internal virtual void SetComponentDirty()
{
m_ComponentDirty = true;
}
internal virtual void ClearComponentDirty()
{
m_ComponentDirty = false;
}
public virtual void ClearDirty()
{
ClearVerticesDirty();
ClearComponentDirty();
}
public virtual void SetAllDirty()
{
SetVerticesDirty();
SetComponentDirty();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f28c6b3fb24d49afbe348cfadd0e1c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,109 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
[Serializable]
public class ComponentTheme : MainComponent
{
[SerializeField] protected Font m_Font;
[SerializeField] protected Color m_TextColor;
[SerializeField] protected Color m_TextBackgroundColor;
[SerializeField] protected int m_FontSize = 18;
#if dUI_TextMeshPro
[SerializeField] protected TMP_FontAsset m_TMPFont;
#endif
/// <summary>
/// the font of text。
/// 字体。
/// </summary>
public Font font
{
get { return m_Font; }
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本颜色。
/// </summary>
public Color textColor
{
get { return m_TextColor; }
set { if (PropertyUtil.SetColor(ref m_TextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本颜色。
/// </summary>
public Color textBackgroundColor
{
get { return m_TextBackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_TextBackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font size of text.
/// 文本字体大小。
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
#if dUI_TextMeshPro
/// <summary>
/// the font of chart text。
/// 字体。
/// </summary>
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
}
#endif
public ComponentTheme(Theme theme)
{
m_FontSize = XChartsSettings.fontSizeLv3;
switch (theme)
{
case Theme.Default:
m_TextColor = ColorUtil.GetColor("#514D4D");
break;
case Theme.Light:
m_TextColor = ColorUtil.GetColor("#514D4D");
break;
case Theme.Dark:
m_TextColor = ColorUtil.GetColor("#B9B8CE");
break;
}
}
public virtual void Copy(ComponentTheme theme)
{
m_Font = theme.font;
m_FontSize = theme.fontSize;
m_TextColor = theme.textColor;
m_TextBackgroundColor = theme.textBackgroundColor;
#if dUI_TextMeshPro
m_TMPFont = theme.tmpFont;
#endif
}
public virtual void Reset(ComponentTheme defaultTheme)
{
Copy(defaultTheme);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e78d1c80572324fc0b5cc5c935a2e34c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,132 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
[Serializable]
public class DataZoomTheme : ComponentTheme
{
[SerializeField] protected float m_BorderWidth;
[SerializeField] protected float m_DataLineWidth;
[SerializeField] protected Color32 m_FillerColor;
[SerializeField] protected Color32 m_BorderColor;
[SerializeField] protected Color32 m_DataLineColor;
[SerializeField] protected Color32 m_DataAreaColor;
[SerializeField] protected Color32 m_BackgroundColor;
/// <summary>
/// the width of border line.
/// 边框线宽。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of data line.
/// 数据阴影线宽。
/// </summary>
public float dataLineWidth
{
get { return m_DataLineWidth; }
set { if (PropertyUtil.SetStruct(ref m_DataLineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of dataZoom data area.
/// 数据区域颜色。
/// </summary>
public Color32 fillerColor
{
get { return m_FillerColor; }
set { if (PropertyUtil.SetColor(ref m_FillerColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of dataZoom border.
/// 边框颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of data area line.
/// 数据阴影的线条颜色。
/// </summary>
public Color32 dataLineColor
{
get { return m_DataLineColor; }
set { if (PropertyUtil.SetColor(ref m_DataLineColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of data area line.
/// 数据阴影的填充颜色。
/// </summary>
public Color32 dataAreaColor
{
get { return m_DataAreaColor; }
set { if (PropertyUtil.SetColor(ref m_DataAreaColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the background color of datazoom.
/// 背景颜色。
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
}
public DataZoomTheme(Theme theme) : base(theme)
{
m_BorderWidth = XChartsSettings.dataZoomBorderWidth;
m_DataLineWidth = XChartsSettings.dataZoomDataLineWidth;
m_BackgroundColor = Color.clear;
switch (theme)
{
case Theme.Default:
m_TextColor = ColorUtil.GetColor("#333");
m_FillerColor = new Color32(167, 183, 204, 110);
m_BorderColor = ColorUtil.GetColor("#ddd");
m_DataLineColor = ColorUtil.GetColor("#2f4554");
m_DataAreaColor = new Color32(47, 69, 84, 85);
break;
case Theme.Light:
m_TextColor = ColorUtil.GetColor("#333");
m_FillerColor = new Color32(167, 183, 204, 110);
m_BorderColor = ColorUtil.GetColor("#ddd");
m_DataLineColor = ColorUtil.GetColor("#2f4554");
m_DataAreaColor = new Color32(47, 69, 84, 85);
break;
case Theme.Dark:
m_TextColor = ColorUtil.GetColor("#B9B8CE");
m_FillerColor = new Color32(135, 163, 206, (byte)(0.2f * 255));
m_BorderColor = ColorUtil.GetColor("#71708A");
m_DataLineColor = ColorUtil.GetColor("#71708A");
m_DataAreaColor = ColorUtil.GetColor("#71708A");
break;
}
}
public void Copy(DataZoomTheme theme)
{
base.Copy(theme);
m_BorderWidth = theme.borderWidth;
m_DataLineWidth = theme.dataLineWidth;
m_FillerColor = theme.fillerColor;
m_BorderColor = theme.borderColor;
m_DataLineColor = theme.dataLineColor;
m_DataAreaColor = theme.dataAreaColor;
m_BackgroundColor = theme.backgroundColor;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ba535ef75742b4825b3cc2be4df6716f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,83 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
[Serializable]
public class GaugeAxisTheme : BaseAxisTheme
{
[SerializeField] private Color32 m_BarBackgroundColor;
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
public GaugeAxisTheme(Theme theme) : base(theme)
{
m_LineWidth = XChartsSettings.gaugeAxisLineWidth;
m_LineLength = 0;
m_SplitLineWidth = XChartsSettings.gaugeAxisSplitLineWidth;
m_SplitLineLength = XChartsSettings.gaugeAxisSplitLineLength;
m_TickWidth = XChartsSettings.gaugeAxisTickWidth;
m_TickLength = XChartsSettings.gaugeAxisTickLength;
m_SplitLineColor = Color.white;
m_TickColor = Color.white;
switch (theme)
{
case Theme.Default:
m_BarBackgroundColor = new Color32(200, 200, 200, 255);
m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
break;
case Theme.Light:
m_BarBackgroundColor = new Color32(200, 200, 200, 255);
m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
break;
case Theme.Dark:
m_BarBackgroundColor = new Color32(200, 200, 200, 255);
m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
break;
}
}
public void Copy(GaugeAxisTheme theme)
{
base.Copy(theme);
m_BarBackgroundColor = theme.barBackgroundColor;
ChartHelper.CopyList(m_StageColor, theme.stageColor);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b38e4b45ec20b4c65a6dc82891c5c39a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
[Serializable]
public class LegendTheme : ComponentTheme
{
[SerializeField] protected Color m_UnableColor;
/// <summary>
/// the color of text.
/// 文本颜色。
/// </summary>
public Color unableColor
{
get { return m_UnableColor; }
set { if (PropertyUtil.SetColor(ref m_UnableColor, value)) SetComponentDirty(); }
}
public void Copy(LegendTheme theme)
{
base.Copy(theme);
m_UnableColor = theme.unableColor;
}
public LegendTheme(Theme theme) : base(theme)
{
m_UnableColor = ColorUtil.GetColor("#cccccc");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a86fb06a6b71c4735b87769ee0708293
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,166 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
[Serializable]
public class SerieTheme : MainComponent
{
[SerializeField] protected float m_LineWidth;
[SerializeField] protected float m_LineSymbolSize;
[SerializeField] protected float m_LineSymbolSelectedSize;
[SerializeField] protected float m_ScatterSymbolSize;
[SerializeField] protected float m_ScatterSymbolSelectedSize;
[SerializeField] protected float m_PieTooltipExtraRadius;
[SerializeField] protected float m_PieSelectedOffset;
[SerializeField] protected Color32 m_CandlestickColor = new Color32(194, 53, 49, 255);
[SerializeField] protected Color32 m_CandlestickColor0 = new Color32(49, 70, 86, 255);
[SerializeField] protected float m_CandlestickBorderWidth = 1;
[SerializeField] protected Color32 m_CandlestickBorderColor = new Color32(194, 53, 49, 255);
[SerializeField] protected Color32 m_CandlestickBorderColor0 = new Color32(49, 70, 86, 255);
/// <summary>
/// the color of text.
/// 文本颜色。
/// </summary>
public float lineWidth
{
get { return m_LineWidth; }
set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
}
public float lineSymbolSize
{
get { return m_LineSymbolSize; }
set { if (PropertyUtil.SetStruct(ref m_LineSymbolSize, value)) SetVerticesDirty(); }
}
public float lineSymbolSelectedSize
{
get { return m_LineSymbolSelectedSize; }
set { if (PropertyUtil.SetStruct(ref m_LineSymbolSelectedSize, value)) SetVerticesDirty(); }
}
public float scatterSymbolSize
{
get { return m_ScatterSymbolSize; }
set { if (PropertyUtil.SetStruct(ref m_ScatterSymbolSize, value)) SetVerticesDirty(); }
}
public float scatterSymbolSelectedSize
{
get { return m_ScatterSymbolSelectedSize; }
set { if (PropertyUtil.SetStruct(ref m_ScatterSymbolSelectedSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// 饼图鼠标移到高亮时的额外半径
/// </summary>
public float pieTooltipExtraRadius
{
get { return m_PieTooltipExtraRadius; }
set { if (PropertyUtil.SetStruct(ref m_PieTooltipExtraRadius, value < 0 ? 0f : value)) SetVerticesDirty(); }
}
/// <summary>
/// 饼图选中时的中心点偏移
/// </summary>
public float pieSelectedOffset
{
get { return m_PieSelectedOffset; }
set { if (PropertyUtil.SetStruct(ref m_PieSelectedOffset, value < 0 ? 0f : value)) SetVerticesDirty(); }
}
/// <summary>
/// K线图阳线(涨)填充色
/// </summary>
public Color32 candlestickColor
{
get { return m_CandlestickColor; }
set { if (PropertyUtil.SetColor(ref m_CandlestickColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// K线图阴线(跌)填充色
/// </summary>
public Color32 candlestickColor0
{
get { return m_CandlestickColor0; }
set { if (PropertyUtil.SetColor(ref m_CandlestickColor0, value)) SetVerticesDirty(); }
}
/// <summary>
/// K线图阳线(跌)边框色
/// </summary>
public Color32 candlestickBorderColor
{
get { return m_CandlestickBorderColor; }
set { if (PropertyUtil.SetColor(ref m_CandlestickBorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// K线图阴线(跌)边框色
/// </summary>
public Color32 candlestickBorderColor0
{
get { return m_CandlestickBorderColor0; }
set { if (PropertyUtil.SetColor(ref m_CandlestickBorderColor0, value)) SetVerticesDirty(); }
}
/// <summary>
/// K线图边框宽度
/// </summary>
public float candlestickBorderWidth
{
get { return m_CandlestickBorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_CandlestickBorderWidth, value < 0 ? 0f : value)) SetVerticesDirty(); }
}
public void Copy(SerieTheme theme)
{
m_LineWidth = theme.lineWidth;
m_LineSymbolSize = theme.lineSymbolSize;
m_LineSymbolSelectedSize = theme.lineSymbolSelectedSize;
m_ScatterSymbolSize = theme.scatterSymbolSize;
m_ScatterSymbolSelectedSize = theme.scatterSymbolSelectedSize;
m_PieTooltipExtraRadius = theme.pieTooltipExtraRadius;
m_PieSelectedOffset = theme.pieSelectedOffset;
m_CandlestickColor = theme.candlestickColor;
m_CandlestickColor0 = theme.candlestickColor0;
m_CandlestickBorderColor = theme.candlestickBorderColor;
m_CandlestickBorderColor0 = theme.candlestickBorderColor0;
m_CandlestickBorderWidth = theme.candlestickBorderWidth;
}
public SerieTheme(Theme theme)
{
m_LineWidth = XChartsSettings.serieLineWidth;
m_LineSymbolSize = XChartsSettings.serieLineSymbolSize;
m_LineSymbolSelectedSize = XChartsSettings.serieLineSymbolSelectedSize;
m_ScatterSymbolSize = XChartsSettings.serieScatterSymbolSize;
m_ScatterSymbolSelectedSize = XChartsSettings.serieScatterSymbolSelectedSize;
m_PieTooltipExtraRadius = XChartsSettings.pieTooltipExtraRadius;
m_PieSelectedOffset = XChartsSettings.pieSelectedOffset;
m_CandlestickBorderWidth = XChartsSettings.serieCandlestickBorderWidth;
switch (theme)
{
case Theme.Default:
m_CandlestickColor = ColorUtil.GetColor("#c23531");
m_CandlestickColor0 = ColorUtil.GetColor("#314656");
m_CandlestickBorderColor = ColorUtil.GetColor("#c23531");
m_CandlestickBorderColor0 = ColorUtil.GetColor("#314656");
break;
case Theme.Light:
m_CandlestickColor = ColorUtil.GetColor("#c23531");
m_CandlestickColor0 = ColorUtil.GetColor("#314656");
m_CandlestickBorderColor = ColorUtil.GetColor("#c23531");
m_CandlestickBorderColor0 = ColorUtil.GetColor("#314656");
break;
case Theme.Dark:
m_CandlestickColor = ColorUtil.GetColor("#c23531");
m_CandlestickColor0 = ColorUtil.GetColor("#314656");
m_CandlestickBorderColor = ColorUtil.GetColor("#c23531");
m_CandlestickBorderColor0 = ColorUtil.GetColor("#314656");
break;
}
}
}
}
Loaded 100 of 521 files, more files were not shown because too many files have changed in this diff. Show more