Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MarkLine.cs 10KB

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