MarkLine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// 标线类型
  7. /// </summary>
  8. public enum MarkLineType
  9. {
  10. None,
  11. /// <summary>
  12. /// 最小值。
  13. /// </summary>
  14. Min,
  15. /// <summary>
  16. /// 最大值。
  17. /// </summary>
  18. Max,
  19. /// <summary>
  20. /// 平均值。
  21. /// </summary>
  22. Average,
  23. /// <summary>
  24. /// 中位数。
  25. /// </summary>
  26. Median
  27. }
  28. /// <summary>
  29. /// Use a line in the chart to illustrate.
  30. /// ||图表标线。
  31. /// </summary>
  32. [System.Serializable]
  33. [ComponentHandler(typeof(MarkLineHandler), true)]
  34. public class MarkLine : MainComponent
  35. {
  36. [SerializeField] private bool m_Show = true;
  37. [SerializeField] private int m_SerieIndex = 0;
  38. [SerializeField][Since("v3.9.0")] private bool m_OnTop = true;
  39. [SerializeField] private AnimationStyle m_Animation = new AnimationStyle();
  40. [SerializeField] private List<MarkLineData> m_Data = new List<MarkLineData>();
  41. /// <summary>
  42. /// Whether to display the marking line.
  43. /// ||是否显示标线。
  44. /// </summary>
  45. public bool show
  46. {
  47. get { return m_Show; }
  48. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
  49. }
  50. /// <summary>
  51. /// The serie index of markLine.
  52. /// ||标线影响的Serie索引。
  53. /// </summary>
  54. public int serieIndex
  55. {
  56. get { return m_SerieIndex; }
  57. set { if (PropertyUtil.SetStruct(ref m_SerieIndex, value)) SetVerticesDirty(); }
  58. }
  59. /// <summary>
  60. /// whether the markline is on top.
  61. /// ||是否在最上层。
  62. /// </summary>
  63. public bool onTop
  64. {
  65. get { return m_OnTop; }
  66. set { if (PropertyUtil.SetStruct(ref m_OnTop, value)) SetVerticesDirty(); }
  67. }
  68. /// <summary>
  69. /// The animation of markline.
  70. /// ||标线的动画样式。
  71. /// </summary>
  72. public AnimationStyle animation
  73. {
  74. get { return m_Animation; }
  75. set { if (PropertyUtil.SetClass(ref m_Animation, value)) SetVerticesDirty(); }
  76. }
  77. /// <summary>
  78. /// A list of marked data. When the group of data item is 0, each data item represents a line;
  79. /// When the group is not 0, two data items of the same group represent the starting point and
  80. /// the ending point of the line respectively to form a line. In this case, the relevant style
  81. /// parameters of the line are the parameters of the starting point.
  82. /// ||标线的数据列表。当数据项的group为0时,每个数据项表示一条标线;当group不为0时,相同group的两个数据项分别表
  83. /// 示标线的起始点和终止点来组成一条标线,此时标线的相关样式参数取起始点的参数。
  84. /// </summary>
  85. public List<MarkLineData> data
  86. {
  87. get { return m_Data; }
  88. set { if (PropertyUtil.SetClass(ref m_Data, value)) SetVerticesDirty(); }
  89. }
  90. public override void SetDefaultValue()
  91. {
  92. data.Clear();
  93. var item = new MarkLineData();
  94. item.name = "average";
  95. item.type = MarkLineType.Average;
  96. item.lineStyle.type = LineStyle.Type.Dashed;
  97. item.lineStyle.color = Color.clear;
  98. item.startSymbol.show = true;
  99. item.startSymbol.type = SymbolType.Circle;
  100. item.startSymbol.size = 4;
  101. item.endSymbol.show = true;
  102. item.endSymbol.type = SymbolType.Arrow;
  103. item.endSymbol.size = 5;
  104. item.label.show = true;
  105. item.label.numericFormatter = "f1";
  106. item.label.formatter = "{c}";
  107. data.Add(item);
  108. }
  109. }
  110. /// <summary>
  111. /// Data of marking line.
  112. /// ||图表标线的数据。
  113. /// </summary>
  114. [System.Serializable]
  115. public class MarkLineData : ChildComponent
  116. {
  117. [SerializeField] private MarkLineType m_Type = MarkLineType.None;
  118. [SerializeField] private string m_Name;
  119. [SerializeField] private int m_Dimension = 1;
  120. [SerializeField] private float m_XPosition;
  121. [SerializeField] private float m_YPosition;
  122. [SerializeField] private double m_XValue;
  123. [SerializeField] private double m_YValue;
  124. [SerializeField] private int m_Group = 0;
  125. [SerializeField] private bool m_ZeroPosition = false;
  126. [SerializeField] private SymbolStyle m_StartSymbol = new SymbolStyle();
  127. [SerializeField] private SymbolStyle m_EndSymbol = new SymbolStyle();
  128. [SerializeField] private LineStyle m_LineStyle = new LineStyle();
  129. [SerializeField] private LabelStyle m_Label = new LabelStyle();
  130. //[SerializeField] private Emphasis m_Emphasis = new Emphasis();
  131. public Vector3 runtimeStartPosition { get; internal set; }
  132. public Vector3 runtimeEndPosition { get; internal set; }
  133. public Vector3 runtimeCurrentEndPosition { get; internal set; }
  134. public ChartLabel runtimeLabel { get; internal set; }
  135. public double runtimeValue { get; internal set; }
  136. public bool runtimeInGrid { get; internal set; }
  137. /// <summary>
  138. /// Name of the marker, which will display as a label.
  139. /// ||标线名称,将会作为文字显示。label的formatter可通过{b}显示名称,通过{c}显示数值。
  140. /// </summary>
  141. public string name
  142. {
  143. get { return m_Name; }
  144. set { if (PropertyUtil.SetClass(ref m_Name, value)) SetVerticesDirty(); }
  145. }
  146. /// <summary>
  147. /// Special label types, are used to label maximum value, minimum value and so on.
  148. /// ||特殊的标线类型,用于标注最大值最小值等。
  149. /// </summary>
  150. public MarkLineType type
  151. {
  152. get { return m_Type; }
  153. set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
  154. }
  155. /// <summary>
  156. /// From which dimension of data to calculate the maximum and minimum value and so on.
  157. /// ||从哪个维度的数据计算最大最小值等。
  158. /// </summary>
  159. public int dimension
  160. {
  161. get { return m_Dimension; }
  162. set { if (PropertyUtil.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); }
  163. }
  164. /// <summary>
  165. /// The x coordinate relative to the origin, in pixels.
  166. /// ||相对原点的 x 坐标,单位像素。当type为None时有效。
  167. /// </summary>
  168. public float xPosition
  169. {
  170. get { return m_XPosition; }
  171. set { if (PropertyUtil.SetStruct(ref m_XPosition, value)) SetVerticesDirty(); }
  172. }
  173. /// <summary>
  174. /// The y coordinate relative to the origin, in pixels.
  175. /// ||相对原点的 y 坐标,单位像素。当type为None时有效。
  176. /// </summary>
  177. public float yPosition
  178. {
  179. get { return m_YPosition; }
  180. set { if (PropertyUtil.SetStruct(ref m_YPosition, value)) SetVerticesDirty(); }
  181. }
  182. /// <summary>
  183. /// The value specified on the X-axis. A value specified when the X-axis is the category axis represents the index of the category axis data, otherwise a specific value.
  184. /// ||X轴上的指定值。当X轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
  185. /// </summary>
  186. public double xValue
  187. {
  188. get { return m_XValue; }
  189. set { if (PropertyUtil.SetStruct(ref m_XValue, value)) SetVerticesDirty(); }
  190. }
  191. /// <summary>
  192. /// That's the value on the Y-axis. The value specified when the Y axis is the category axis represents the index of the category axis data, otherwise the specific value.
  193. /// ||Y轴上的指定值。当Y轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
  194. /// </summary>
  195. public double yValue
  196. {
  197. get { return m_YValue; }
  198. set { if (PropertyUtil.SetStruct(ref m_YValue, value)) SetVerticesDirty(); }
  199. }
  200. /// <summary>
  201. /// Grouping. When the group is not 0, it means that this data is the starting point or end point of the marking line. Data consistent with the group form a marking line.
  202. /// ||分组。当group不为0时,表示这个data是标线的起点或终点,group一致的data组成一条标线。
  203. /// </summary>
  204. public int group
  205. {
  206. get { return m_Group; }
  207. set { if (PropertyUtil.SetStruct(ref m_Group, value)) SetVerticesDirty(); }
  208. }
  209. /// <summary>
  210. /// Is the origin of the coordinate system.
  211. /// ||是否为坐标系原点。
  212. /// </summary>
  213. public bool zeroPosition
  214. {
  215. get { return m_ZeroPosition; }
  216. set { if (PropertyUtil.SetStruct(ref m_ZeroPosition, value)) SetVerticesDirty(); }
  217. }
  218. /// <summary>
  219. /// The symbol of the start point of markline.
  220. /// ||起始点的图形标记。
  221. /// </summary>
  222. public SymbolStyle startSymbol
  223. {
  224. get { return m_StartSymbol; }
  225. set { if (PropertyUtil.SetClass(ref m_StartSymbol, value)) SetVerticesDirty(); }
  226. }
  227. /// <summary>
  228. /// The symbol of the end point of markline.
  229. /// ||结束点的图形标记。
  230. /// </summary>
  231. public SymbolStyle endSymbol
  232. {
  233. get { return m_EndSymbol; }
  234. set { if (PropertyUtil.SetClass(ref m_EndSymbol, value)) SetVerticesDirty(); }
  235. }
  236. /// <summary>
  237. /// The line style of markline.
  238. /// ||标线样式。
  239. /// </summary>
  240. public LineStyle lineStyle
  241. {
  242. get { return m_LineStyle; }
  243. set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetVerticesDirty(); }
  244. }
  245. /// <summary>
  246. /// Text styles of label. You can set position to Start, Middle, and End to display text in different locations.
  247. /// ||文本样式。可设置position为Start、Middle和End在不同的位置显示文本。
  248. /// </summary>
  249. public LabelStyle label
  250. {
  251. get { return m_Label; }
  252. set { if (PropertyUtil.SetClass(ref m_Label, value)) SetVerticesDirty(); }
  253. }
  254. // public Emphasis emphasis
  255. // {
  256. // get { return m_Emphasis; }
  257. // set { if (PropertyUtil.SetClass(ref m_Emphasis, value)) SetVerticesDirty(); }
  258. // }
  259. }
  260. }