mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 22:40:10 +00:00
增加RingChart环形图
This commit is contained in:
@@ -36,6 +36,10 @@ namespace XCharts
|
||||
}
|
||||
[SerializeField] private bool m_Show = false;
|
||||
[SerializeField] private Color m_Color;
|
||||
[SerializeField] private Color m_BackgroundColor;
|
||||
[SerializeField] private float m_BackgroundWidth;
|
||||
[SerializeField] private Color m_CenterColor;
|
||||
[SerializeField] private float m_CenterGap;
|
||||
[SerializeField] private Type m_BorderType = Type.Solid;
|
||||
[SerializeField] private float m_BorderWidth = 0;
|
||||
[SerializeField] private Color m_BorderColor;
|
||||
@@ -58,6 +62,38 @@ namespace XCharts
|
||||
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据项背景颜色。
|
||||
/// </summary>
|
||||
public Color backgroundColor
|
||||
{
|
||||
get { return m_BackgroundColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 中心区域颜色。
|
||||
/// </summary>
|
||||
public Color centerColor
|
||||
{
|
||||
get { return m_CenterColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 中心区域间隙。
|
||||
/// </summary>
|
||||
public float centerGap
|
||||
{
|
||||
get { return m_CenterGap; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据项背景颜色。
|
||||
/// </summary>
|
||||
public float backgroundWidth
|
||||
{
|
||||
get { return m_BackgroundWidth; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 边框的类型。
|
||||
/// </summary>
|
||||
public Type borderType
|
||||
|
||||
@@ -237,7 +237,7 @@ namespace XCharts
|
||||
return (delay > 0 && Time.time - startTime < delay / 1000);
|
||||
}
|
||||
|
||||
public bool CheckDetailBreak(int dataIndex, float detail)
|
||||
public bool CheckDetailBreak(float detail)
|
||||
{
|
||||
return !IsFinish() && detail > m_CurrDetailProgress;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace XCharts
|
||||
public float runtimePieOffsetRadius { get; internal set; }
|
||||
public Vector3 runtiemPieOffsetCenter { get; internal set; }
|
||||
|
||||
private List<float> m_LastData = new List<float>();
|
||||
private List<float> m_PreviousData = new List<float>();
|
||||
private List<float> m_DataUpdateTime = new List<float>();
|
||||
private List<bool> m_DataUpdateFlag = new List<bool>();
|
||||
|
||||
@@ -166,15 +166,27 @@ namespace XCharts
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetLastData(int index)
|
||||
public float GetPreviousData(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_LastData.Count)
|
||||
if (index >= 0 && index < m_PreviousData.Count)
|
||||
{
|
||||
return m_LastData[index];
|
||||
return 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)
|
||||
{
|
||||
if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0)
|
||||
@@ -184,7 +196,7 @@ namespace XCharts
|
||||
if (time <= total)
|
||||
{
|
||||
CheckLastData();
|
||||
var curr = Mathf.Lerp(GetLastData(index), GetData(index), time / total);
|
||||
var curr = Mathf.Lerp(GetPreviousData(index), GetData(index), time / total);
|
||||
return curr;
|
||||
}
|
||||
else
|
||||
@@ -204,7 +216,7 @@ namespace XCharts
|
||||
if (dimension >= 0 && dimension < data.Count)
|
||||
{
|
||||
CheckLastData();
|
||||
m_LastData[dimension] = data[dimension];
|
||||
m_PreviousData[dimension] = data[dimension];
|
||||
m_DataUpdateTime[dimension] = Time.time;
|
||||
m_DataUpdateFlag[dimension] = true;
|
||||
data[dimension] = value;
|
||||
@@ -215,14 +227,14 @@ namespace XCharts
|
||||
|
||||
private void CheckLastData()
|
||||
{
|
||||
if (m_LastData.Count != m_Data.Count)
|
||||
if (m_PreviousData.Count != m_Data.Count)
|
||||
{
|
||||
m_LastData.Clear();
|
||||
m_PreviousData.Clear();
|
||||
m_DataUpdateTime.Clear();
|
||||
m_DataUpdateFlag.Clear();
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
m_LastData.Add(m_Data[i]);
|
||||
m_PreviousData.Add(m_Data[i]);
|
||||
m_DataUpdateTime.Add(Time.time);
|
||||
m_DataUpdateFlag.Add(false);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace XCharts
|
||||
public float backgroundHeight
|
||||
{
|
||||
get { return m_BackgroundHeight; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Rotate label.
|
||||
@@ -202,7 +202,7 @@ namespace XCharts
|
||||
public float rotate
|
||||
{
|
||||
get { return m_Rotate; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the text padding of left and right. defaut:2.
|
||||
@@ -211,7 +211,7 @@ namespace XCharts
|
||||
public float paddingLeftRight
|
||||
{
|
||||
get { return m_PaddingLeftRight; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtility.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the text padding of top and bottom. defaut:2.
|
||||
@@ -220,7 +220,7 @@ namespace XCharts
|
||||
public float paddingTopBottom
|
||||
{
|
||||
get { return m_PaddingTopBottom; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtility.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// font size.
|
||||
@@ -229,7 +229,7 @@ namespace XCharts
|
||||
public int fontSize
|
||||
{
|
||||
get { return m_FontSize; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetAllDirty(); }
|
||||
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// font style.
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace XCharts
|
||||
/// 文本的相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TextStyle : SubComponent, IEquatable<TextStyle>
|
||||
public class TextStyle : SubComponent
|
||||
{
|
||||
[SerializeField] private Font m_Font;
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
@@ -135,65 +135,5 @@ namespace XCharts
|
||||
this.color = color;
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
public void Copy(TextStyle style)
|
||||
{
|
||||
this.fontSize = style.fontSize;
|
||||
this.fontStyle = style.fontStyle;
|
||||
this.color = style.color;
|
||||
this.backgroundColor = style.backgroundColor;
|
||||
this.rotate = style.rotate;
|
||||
this.offset = style.offset;
|
||||
this.lineSpacing = style.lineSpacing;
|
||||
}
|
||||
|
||||
public TextStyle Clone()
|
||||
{
|
||||
var textStyle = new TextStyle();
|
||||
textStyle.rotate = rotate;
|
||||
textStyle.color = color;
|
||||
textStyle.backgroundColor = backgroundColor;
|
||||
textStyle.fontSize = fontSize;
|
||||
textStyle.fontStyle = fontStyle;
|
||||
textStyle.offset = offset;
|
||||
textStyle.lineSpacing = lineSpacing;
|
||||
return textStyle;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is TextStyle)
|
||||
{
|
||||
return Equals((TextStyle)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(TextStyle other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return rotate == other.rotate &&
|
||||
fontSize == other.fontSize &&
|
||||
fontStyle == other.fontStyle &&
|
||||
offset == other.offset &&
|
||||
lineSpacing == other.lineSpacing &&
|
||||
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.backgroundColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_Color, other.color);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -17,62 +18,42 @@ namespace XCharts
|
||||
/// 标题相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TitleStyle : SubComponent, IEquatable<TitleStyle>
|
||||
public class TitleStyle : SubComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private TextStyle m_textStyle = new TextStyle(18);
|
||||
[FormerlySerializedAs("m_textStyle")]
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18);
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show title.
|
||||
/// 是否显示标题。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// 文本的颜色。
|
||||
/// </summary>
|
||||
public TextStyle textStyle { get { return m_textStyle; } set { m_textStyle = value; } }
|
||||
public TextStyle textStyle
|
||||
{
|
||||
get { return m_TextStyle; }
|
||||
set { if (PropertyUtility.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 Text runtimeText { get; set; }
|
||||
|
||||
public TitleStyle Clone()
|
||||
{
|
||||
var title = new TitleStyle();
|
||||
title.show = show;
|
||||
title.textStyle = textStyle.Clone();
|
||||
return title;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is TitleStyle)
|
||||
{
|
||||
return Equals((TitleStyle)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(TitleStyle other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return textStyle.Equals(other.textStyle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public bool IsInited()
|
||||
{
|
||||
return runtimeText != null;
|
||||
@@ -90,13 +71,13 @@ namespace XCharts
|
||||
{
|
||||
if (runtimeText)
|
||||
{
|
||||
runtimeText.transform.localPosition = pos + new Vector3(m_textStyle.offset.x, m_textStyle.offset.y);
|
||||
runtimeText.transform.localPosition = pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
if (runtimeText)
|
||||
if (runtimeText && !runtimeText.text.Equals(text))
|
||||
{
|
||||
if (textStyle.color != Color.clear) runtimeText.color = textStyle.color;
|
||||
runtimeText.text = text;
|
||||
|
||||
Reference in New Issue
Block a user