2022-03-29 22:06:10 +08:00
|
|
|
|
using UnityEngine;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
|
2022-02-19 22:37:57 +08:00
|
|
|
|
namespace XCharts.Runtime
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Text label of chart, to explain some data information about graphic item like value, name and so on.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
[System.Serializable]
|
2021-12-28 08:18:24 +08:00
|
|
|
|
public class LabelStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// The position of label.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |标签的位置。
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum Position
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Outside of sectors of pie chart, which relates to corresponding sector through visual guide line.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |饼图扇区外侧,通过视觉引导线连到相应的扇区。
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
Outside,
|
|
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// Inside the sectors of pie chart.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |饼图扇区内部。
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
Inside,
|
|
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// In the center of pie chart.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |在饼图中心位置。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2019-07-29 00:25:10 +08:00
|
|
|
|
Center,
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// top of symbol.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |图形标志的顶部。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2019-07-29 00:25:10 +08:00
|
|
|
|
Top,
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2021-05-29 22:07:09 +08:00
|
|
|
|
/// the bottom of symbol.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |图形标志的底部。
|
2021-05-29 22:07:09 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
Bottom,
|
|
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// the left of symbol.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |图形标志的左边。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2021-05-29 22:07:09 +08:00
|
|
|
|
Left,
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the right of symbol.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |图形标志的右边。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2021-05-29 22:07:09 +08:00
|
|
|
|
Right,
|
2021-07-15 21:18:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the start of line.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |线的起始点。
|
2021-07-15 21:18:23 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
Start,
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the middle of line.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |线的中点。
|
2021-07-15 21:18:23 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
Middle,
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the end of line.
|
2022-03-24 21:48:53 +08:00
|
|
|
|
/// |线的结束点。
|
2021-07-15 21:18:23 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
End
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
2019-10-05 18:23:06 +08:00
|
|
|
|
|
2021-12-31 13:00:17 +08:00
|
|
|
|
[SerializeField] private bool m_Show = true;
|
2020-06-10 13:10:24 +08:00
|
|
|
|
[SerializeField] Position m_Position = Position.Outside;
|
2019-09-25 09:44:53 +08:00
|
|
|
|
[SerializeField] private Vector3 m_Offset;
|
2022-02-19 17:35:22 +08:00
|
|
|
|
[SerializeField] private float m_Distance;
|
2019-09-20 12:38:45 +08:00
|
|
|
|
[SerializeField] private string m_Formatter;
|
2019-08-20 09:40:19 +08:00
|
|
|
|
[SerializeField] private float m_PaddingLeftRight = 2f;
|
|
|
|
|
|
[SerializeField] private float m_PaddingTopBottom = 2f;
|
|
|
|
|
|
[SerializeField] private float m_BackgroundWidth = 0;
|
|
|
|
|
|
[SerializeField] private float m_BackgroundHeight = 0;
|
2020-05-04 13:29:56 +08:00
|
|
|
|
[SerializeField] private string m_NumericFormatter = "";
|
2020-06-04 12:33:25 +08:00
|
|
|
|
[SerializeField] private bool m_AutoOffset = false;
|
2022-03-29 22:06:10 +08:00
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
|
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
2022-03-04 22:17:32 +08:00
|
|
|
|
private SerieLabelFormatterFunction m_FormatterFunction;
|
2020-03-05 20:25:19 +08:00
|
|
|
|
|
2020-06-10 13:10:24 +08:00
|
|
|
|
public void Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_Show = false;
|
|
|
|
|
|
m_Position = Position.Outside;
|
|
|
|
|
|
m_Offset = Vector3.zero;
|
2022-02-19 17:35:22 +08:00
|
|
|
|
m_Distance = 0;
|
2020-06-10 13:10:24 +08:00
|
|
|
|
m_PaddingLeftRight = 2f;
|
|
|
|
|
|
m_PaddingTopBottom = 2f;
|
|
|
|
|
|
m_BackgroundWidth = 0;
|
|
|
|
|
|
m_BackgroundHeight = 0;
|
|
|
|
|
|
m_NumericFormatter = "";
|
|
|
|
|
|
m_AutoOffset = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// Whether the label is showed.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |是否显示文本标签。
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public bool show
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Show; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// The position of label.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |标签的位置。
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public Position position
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Position; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// <summary>
|
2019-09-20 12:38:45 +08:00
|
|
|
|
/// 标签内容字符串模版格式器。支持用 \n 换行。
|
|
|
|
|
|
/// 模板变量有:
|
|
|
|
|
|
/// <list type="bullet">
|
|
|
|
|
|
/// <item><description>{a}:系列名。</description></item>
|
|
|
|
|
|
/// <item><description>{b}:数据名。</description></item>
|
|
|
|
|
|
/// <item><description>{c}:数据值。</description></item>
|
2019-09-23 09:23:51 +08:00
|
|
|
|
/// <item><description>{d}:百分比。</description></item>
|
2019-09-20 12:38:45 +08:00
|
|
|
|
/// </list>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <example>
|
|
|
|
|
|
/// 示例:“{b}:{c}”
|
|
|
|
|
|
/// </example>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public string formatter
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Formatter; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-09-20 12:38:45 +08:00
|
|
|
|
/// <summary>
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// offset to the host graphic element.
|
|
|
|
|
|
/// |距离图形元素的偏移
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public Vector3 offset
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Offset; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// <summary>
|
2019-11-30 21:24:04 +08:00
|
|
|
|
/// 距离轴线的距离。
|
|
|
|
|
|
/// </summary>
|
2022-02-19 17:35:22 +08:00
|
|
|
|
public float distance
|
2020-03-05 20:25:19 +08:00
|
|
|
|
{
|
2022-02-19 17:35:22 +08:00
|
|
|
|
get { return m_Distance; }
|
|
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Distance, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// <summary>
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// the width of background. If set as default value 0, it means than the background width auto set as the text width.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value></value>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float backgroundWidth
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_BackgroundWidth; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the height of background. If set as default value 0, it means than the background height auto set as the text height.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |标签的背景高度。一般不用指定,不指定时则自动是文字的高度。
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value></value>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float backgroundHeight
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_BackgroundHeight; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
/// <summary>
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// the text padding of left and right. defaut:2.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |左右边距。
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float paddingLeftRight
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_PaddingLeftRight; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the text padding of top and bottom. defaut:2.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |上下边距。
|
2019-08-20 09:40:19 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float paddingTopBottom
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_PaddingTopBottom; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2020-05-04 13:29:56 +08:00
|
|
|
|
/// Standard numeric format strings.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |标准数字格式字符串。用于将数值格式化显示为字符串。
|
2020-05-04 13:29:56 +08:00
|
|
|
|
/// 使用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
|
2019-10-26 05:02:32 +08:00
|
|
|
|
/// </summary>
|
2020-05-04 13:29:56 +08:00
|
|
|
|
/// <value></value>
|
|
|
|
|
|
public string numericFormatter
|
2019-09-20 12:38:45 +08:00
|
|
|
|
{
|
2020-05-04 13:29:56 +08:00
|
|
|
|
get { return m_NumericFormatter; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
|
2019-09-20 12:38:45 +08:00
|
|
|
|
}
|
2020-06-04 12:33:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool autoOffset
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_AutoOffset; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2022-03-29 22:06:10 +08:00
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the sytle of text.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |文本样式。
|
2021-01-11 08:54:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public TextStyle textStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_TextStyle; }
|
|
|
|
|
|
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
|
2020-06-04 12:33:25 +08:00
|
|
|
|
}
|
2021-05-29 22:07:09 +08:00
|
|
|
|
|
2022-03-04 22:17:32 +08:00
|
|
|
|
public SerieLabelFormatterFunction formatterFunction
|
2021-06-27 12:26:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
get { return m_FormatterFunction; }
|
|
|
|
|
|
set { m_FormatterFunction = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-29 22:07:09 +08:00
|
|
|
|
public bool IsInside()
|
|
|
|
|
|
{
|
|
|
|
|
|
return position == Position.Inside || position == Position.Center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-19 17:35:22 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-29 22:07:09 +08:00
|
|
|
|
public Color GetColor(Color defaultColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ChartHelper.IsClearColor(textStyle.color))
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsInside() ? Color.black : defaultColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return textStyle.color;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TextAnchor GetAutoAlignment()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (textStyle.autoAlign) return textStyle.alignment;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (position)
|
|
|
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
|
case LabelStyle.Position.Inside:
|
|
|
|
|
|
case LabelStyle.Position.Center:
|
|
|
|
|
|
case LabelStyle.Position.Top:
|
|
|
|
|
|
case LabelStyle.Position.Bottom:
|
2021-05-29 22:07:09 +08:00
|
|
|
|
return TextAnchor.MiddleCenter;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
case LabelStyle.Position.Outside:
|
|
|
|
|
|
case LabelStyle.Position.Right:
|
2021-05-29 22:07:09 +08:00
|
|
|
|
return TextAnchor.MiddleLeft;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
case LabelStyle.Position.Left:
|
2021-05-29 22:07:09 +08:00
|
|
|
|
return TextAnchor.MiddleRight;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return TextAnchor.MiddleCenter;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
2021-12-28 08:18:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|