mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 23:40:10 +00:00
3.0 - guage chart
This commit is contained in:
@@ -504,19 +504,19 @@ namespace XCharts
|
||||
return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1f;
|
||||
}
|
||||
|
||||
internal float CheckItemProgress(int dataIndex, float barHig, ref bool isEnd)
|
||||
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress = 0)
|
||||
{
|
||||
isEnd = false;
|
||||
var initHig = m_FadeOut ? barHig : 0;
|
||||
var destHig = m_FadeOut ? 0 : barHig;
|
||||
var initHig = m_FadeOut ? destProgress : startProgress;
|
||||
var destHig = m_FadeOut ? startProgress : destProgress;
|
||||
var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, ref isEnd);
|
||||
if (isEnd || IsFinish())
|
||||
{
|
||||
return m_FadeOuted ? 0 : barHig;
|
||||
return m_FadeOuted ? startProgress : destProgress;
|
||||
}
|
||||
else if (IsInDelay() || IsInIndexDelay(dataIndex))
|
||||
{
|
||||
return m_FadeOut ? barHig : 0;
|
||||
return m_FadeOut ? destProgress : startProgress;
|
||||
}
|
||||
else if (m_IsPause)
|
||||
{
|
||||
@@ -525,7 +525,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
var duration = GetCurrAnimationDuration(dataIndex);
|
||||
var delta = barHig / duration * Time.deltaTime;
|
||||
var delta = (destProgress - startProgress) / duration * Time.deltaTime;
|
||||
currHig = currHig + (m_FadeOut ? -delta : delta);
|
||||
if (m_FadeOut)
|
||||
{
|
||||
@@ -535,11 +535,12 @@ namespace XCharts
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
|
||||
else if (currHig - destProgress > 0)
|
||||
{
|
||||
currHig = barHig;
|
||||
currHig = destProgress;
|
||||
isEnd = true;
|
||||
}
|
||||
|
||||
SetDataCurrProgress(dataIndex, currHig);
|
||||
return currHig;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace XCharts
|
||||
public struct AnimationStyleContext
|
||||
{
|
||||
public AnimationType type;
|
||||
internal float currentPathDistance;
|
||||
internal bool isAllItemAnimationEnd;
|
||||
public float currentPathDistance;
|
||||
public bool isAllItemAnimationEnd;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace XCharts
|
||||
{
|
||||
public static class AnimationStyleHelper
|
||||
{
|
||||
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress)
|
||||
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0)
|
||||
{
|
||||
if (!serie.animation.IsItemAnimation())
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace XCharts
|
||||
return destProgress;
|
||||
}
|
||||
var isDataAnimationEnd = true;
|
||||
float currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd);
|
||||
float currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress);
|
||||
if (!isDataAnimationEnd)
|
||||
{
|
||||
serie.animation.context.isAllItemAnimationEnd = false;
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace XCharts
|
||||
var total = 360;
|
||||
var cenPos = polar.context.center;
|
||||
var txtHig = axis.axisLabel.textStyle.GetFontSize(chart.theme.axis) + 2;
|
||||
var margin = axis.axisLabel.margin + axis.axisTick.GetLength(chart.theme.axis.tickLength);
|
||||
var margin = axis.axisLabel.distance + axis.axisTick.GetLength(chart.theme.axis.tickLength);
|
||||
var isCategory = axis.IsCategory();
|
||||
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
|
||||
@@ -567,9 +567,9 @@ namespace XCharts
|
||||
axisStartY += relativedLength;
|
||||
|
||||
if ((inside && axis.IsBottom()) || (!inside && axis.IsTop()))
|
||||
current += axisStartY + axis.axisLabel.margin + fontSize / 2;
|
||||
current += axisStartY + axis.axisLabel.distance + fontSize / 2;
|
||||
else
|
||||
current += axisStartY - axis.axisLabel.margin - fontSize / 2;
|
||||
current += axisStartY - axis.axisLabel.distance - fontSize / 2;
|
||||
|
||||
return new Vector3(axisStartX + scaleWid, current) + axis.axisLabel.textStyle.offsetv3;
|
||||
}
|
||||
@@ -582,9 +582,9 @@ namespace XCharts
|
||||
axisStartX += relativedLength;
|
||||
|
||||
if ((inside && axis.IsLeft()) || (!inside && axis.IsRight()))
|
||||
current += axisStartX + axis.axisLabel.margin;
|
||||
current += axisStartX + axis.axisLabel.distance;
|
||||
else
|
||||
current += axisStartX - axis.axisLabel.margin;
|
||||
current += axisStartX - axis.axisLabel.distance;
|
||||
|
||||
return new Vector3(current, axisStartY + scaleWid) + axis.axisLabel.textStyle.offsetv3;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace XCharts
|
||||
[SerializeField] private string m_Formatter;
|
||||
[SerializeField] private int m_Interval = 0;
|
||||
[SerializeField] private bool m_Inside = false;
|
||||
[SerializeField] private float m_Margin;
|
||||
[SerializeField] private float m_Distance;
|
||||
[SerializeField] private string m_NumericFormatter = "";
|
||||
[SerializeField] private bool m_ShowAsPositiveNumber = false;
|
||||
[SerializeField] private bool m_OnZero = false;
|
||||
@@ -56,13 +56,13 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The margin between the axis label and the axis line.
|
||||
/// The distance between the axis label and the axis line.
|
||||
/// 刻度标签与轴线之间的距离。
|
||||
/// </summary>
|
||||
public float margin
|
||||
public float distance
|
||||
{
|
||||
get { return m_Margin; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetComponentDirty(); }
|
||||
get { return m_Distance; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Distance, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图例内容字符串模版格式器。支持用 \n 换行。
|
||||
@@ -179,7 +179,7 @@ namespace XCharts
|
||||
m_Show = true,
|
||||
m_Interval = 0,
|
||||
m_Inside = false,
|
||||
m_Margin = 8,
|
||||
m_Distance = 8,
|
||||
m_TextStyle = new TextStyle(),
|
||||
};
|
||||
}
|
||||
@@ -192,7 +192,7 @@ namespace XCharts
|
||||
axisLabel.formatter = formatter;
|
||||
axisLabel.interval = interval;
|
||||
axisLabel.inside = inside;
|
||||
axisLabel.margin = margin;
|
||||
axisLabel.distance = distance;
|
||||
axisLabel.numericFormatter = numericFormatter;
|
||||
axisLabel.width = width;
|
||||
axisLabel.height = height;
|
||||
@@ -209,7 +209,7 @@ namespace XCharts
|
||||
formatter = axisLabel.formatter;
|
||||
interval = axisLabel.interval;
|
||||
inside = axisLabel.inside;
|
||||
margin = axisLabel.margin;
|
||||
distance = axisLabel.distance;
|
||||
numericFormatter = axisLabel.numericFormatter;
|
||||
width = axisLabel.width;
|
||||
height = axisLabel.height;
|
||||
|
||||
@@ -12,6 +12,15 @@ namespace XCharts
|
||||
public class AxisSplitLine : BaseLine
|
||||
{
|
||||
[SerializeField] private int m_Interval;
|
||||
[SerializeField] private float m_Distance;
|
||||
[SerializeField] private bool m_AutoColor;
|
||||
|
||||
/// <summary>
|
||||
/// The distance between the split line and axis line.
|
||||
/// 刻度线与轴线的距离。
|
||||
/// </summary>
|
||||
public float distance { get { return m_Distance; } set { m_Distance = value; } }
|
||||
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
|
||||
|
||||
public int interval
|
||||
{
|
||||
|
||||
@@ -15,6 +15,15 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Inside;
|
||||
[SerializeField] private bool m_ShowStartTick;
|
||||
[SerializeField] private bool m_ShowEndTick;
|
||||
[SerializeField] private float m_Distance;
|
||||
[SerializeField] protected int m_SplitNumber = 0;
|
||||
[SerializeField] private bool m_AutoColor;
|
||||
|
||||
/// <summary>
|
||||
/// The distance between the tick line and axis line.
|
||||
/// 刻度线与轴线的距离。
|
||||
/// </summary>
|
||||
public float distance { get { return m_Distance; } set { m_Distance = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis.
|
||||
@@ -52,6 +61,16 @@ namespace XCharts
|
||||
get { return m_ShowEndTick; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowEndTick, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <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(); }
|
||||
}
|
||||
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
|
||||
|
||||
public static AxisTick defaultTick
|
||||
{
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace XCharts
|
||||
var dire = ChartHelper.GetDire(startAngle, true).normalized;
|
||||
var tickLength = axis.axisTick.GetLength(chart.theme.axis.tickLength);
|
||||
var tickVector = ChartHelper.GetVertialDire(dire)
|
||||
* (tickLength + axis.axisLabel.margin);
|
||||
* (tickLength + axis.axisLabel.distance);
|
||||
return ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVector;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,17 +73,15 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] Position m_Position = Position.Outside;
|
||||
[SerializeField] private Vector3 m_Offset;
|
||||
[SerializeField] private float m_Margin;
|
||||
[SerializeField] private float m_Distance;
|
||||
[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_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 bool m_AutoColor = false;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
private DelegateSerieLabelFormatter m_FormatterFunction;
|
||||
|
||||
@@ -92,16 +90,14 @@ namespace XCharts
|
||||
m_Show = false;
|
||||
m_Position = Position.Outside;
|
||||
m_Offset = Vector3.zero;
|
||||
m_Margin = 0;
|
||||
m_Distance = 0;
|
||||
m_PaddingLeftRight = 2f;
|
||||
m_PaddingTopBottom = 2f;
|
||||
m_BackgroundWidth = 0;
|
||||
m_BackgroundHeight = 0;
|
||||
m_Border = false;
|
||||
m_BorderWidth = 0.5f;
|
||||
m_BorderColor = Color.grey;
|
||||
m_NumericFormatter = "";
|
||||
m_AutoOffset = false;
|
||||
m_AutoColor = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -152,10 +148,10 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 距离轴线的距离。
|
||||
/// </summary>
|
||||
public float margin
|
||||
public float distance
|
||||
{
|
||||
get { return m_Margin; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
|
||||
get { return m_Distance; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Distance, 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.
|
||||
@@ -196,33 +192,6 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <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。
|
||||
@@ -242,6 +211,14 @@ namespace XCharts
|
||||
get { return m_AutoOffset; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否开启自动颜色。当开启时,会根据已支持的serie自动设置颜色。
|
||||
/// </summary>
|
||||
public bool autoColor
|
||||
{
|
||||
get { return m_AutoColor; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetAllDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the sytle of text.
|
||||
@@ -264,6 +241,14 @@ namespace XCharts
|
||||
return position == Position.Inside || position == Position.Center;
|
||||
}
|
||||
|
||||
public Vector3 GetOffset(float radius)
|
||||
{
|
||||
var x = ChartHelper.GetActualValue(m_Offset.x, radius);
|
||||
var y = ChartHelper.GetActualValue(m_Offset.y, radius);
|
||||
var z = ChartHelper.GetActualValue(m_Offset.z, radius);
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
public Color GetColor(Color defaultColor)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(textStyle.color))
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_ExtraWidth = 0;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
[SerializeField] private Color m_Color = Color.clear;
|
||||
[SerializeField] private bool m_AutoBackgroundColor = false;
|
||||
[SerializeField] private Color m_BackgroundColor = Color.clear;
|
||||
[SerializeField] private int m_FontSize = 0;
|
||||
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
|
||||
@@ -73,6 +74,11 @@ namespace XCharts
|
||||
get { return m_Color; }
|
||||
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
|
||||
}
|
||||
public bool autoBackgroundColor
|
||||
{
|
||||
get { return m_AutoBackgroundColor; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoBackgroundColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// 文本的背景颜色。
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -10,9 +9,10 @@ namespace XCharts
|
||||
/// 标题相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TitleStyle : ChildComponent
|
||||
public class TitleStyle : ChildComponent, ISerieDataComponent, ISerieExtraComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Vector2 m_OffsetCenter = new Vector2(0, -0.2f);
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
/// <summary>
|
||||
@@ -24,6 +24,15 @@ namespace XCharts
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The offset position relative to the center.
|
||||
/// 相对于中心的偏移位置。
|
||||
/// </summary>
|
||||
public Vector2 offsetCenter
|
||||
{
|
||||
get { return m_OffsetCenter; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_OffsetCenter, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
@@ -43,46 +52,11 @@ namespace XCharts
|
||||
textStyle.ClearComponentDirty();
|
||||
}
|
||||
|
||||
public ChartText runtimeText { get; set; }
|
||||
|
||||
public bool IsInited()
|
||||
public Vector3 GetOffset(float radius)
|
||||
{
|
||||
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);
|
||||
}
|
||||
var x = ChartHelper.GetActualValue(m_OffsetCenter.x, radius);
|
||||
var y = ChartHelper.GetActualValue(m_OffsetCenter.y, radius);
|
||||
return new Vector3(x, y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user