暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AreaStyle.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using UnityEngine;
  2. namespace XCharts.Runtime
  3. {
  4. /// <summary>
  5. /// The style of area.
  6. /// |区域填充样式。
  7. /// </summary>
  8. [System.Serializable]
  9. public class AreaStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
  10. {
  11. /// <summary>
  12. /// Origin position of area.
  13. /// |图形区域的起始位置。默认情况下,图形会从坐标轴轴线到数据间进行填充。如果需要填充的区域是坐标轴最大值到数据间,或者坐标轴最小值到数据间,则可以通过这个配置项进行设置。
  14. /// </summary>
  15. public enum AreaOrigin
  16. {
  17. /// <summary>
  18. /// to fill between axis line to data.
  19. /// |填充坐标轴轴线到数据间的区域。
  20. /// </summary>
  21. Auto,
  22. /// <summary>
  23. /// to fill between min axis value (when not inverse) to data.
  24. /// |填充坐标轴底部到数据间的区域。
  25. /// </summary>
  26. Start,
  27. /// <summary>
  28. /// to fill between max axis value (when not inverse) to data.
  29. /// |填充坐标轴顶部到数据间的区域。
  30. /// </summary>
  31. End
  32. }
  33. [SerializeField] private bool m_Show = true;
  34. [SerializeField] private AreaStyle.AreaOrigin m_Origin;
  35. [SerializeField] private Color32 m_Color;
  36. [SerializeField] private Color32 m_ToColor;
  37. [SerializeField][Range(0, 1)] private float m_Opacity = 0.6f;
  38. [SerializeField][Since("v3.2.0")] private bool m_InnerFill;
  39. [SerializeField][Since("v3.6.0")] private bool m_ToTop = true;
  40. /// <summary>
  41. /// Set this to false to prevent the areafrom showing.
  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 origin of area.
  51. /// |区域填充的起始位置。
  52. /// </summary>
  53. public AreaOrigin origin
  54. {
  55. get { return m_Origin; }
  56. set { if (PropertyUtil.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
  57. }
  58. /// <summary>
  59. /// the color of area,default use serie color.
  60. /// |区域填充的颜色,如果toColor不是默认值,则表示渐变色的起点颜色。
  61. /// </summary>
  62. public Color32 color
  63. {
  64. get { return m_Color; }
  65. set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
  66. }
  67. /// <summary>
  68. /// Gradient color, start color to toColor.
  69. /// |渐变色的终点颜色。
  70. /// </summary>
  71. public Color32 toColor
  72. {
  73. get { return m_ToColor; }
  74. set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
  75. }
  76. /// <summary>
  77. /// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
  78. /// |图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
  79. /// </summary>
  80. public float opacity
  81. {
  82. get { return m_Opacity; }
  83. set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
  84. }
  85. /// <summary>
  86. /// Whether to fill only polygonal areas. Currently, only convex polygons are supported.
  87. /// |是否只填充多边形区域。目前只支持凸多边形。
  88. /// </summary>
  89. public bool innerFill
  90. {
  91. get { return m_InnerFill; }
  92. set { if (PropertyUtil.SetStruct(ref m_InnerFill, value)) SetVerticesDirty(); }
  93. }
  94. /// <summary>
  95. /// Whether to fill the gradient color to the top. The default is true, which means that the gradient color is filled to the top.
  96. /// If it is false, the gradient color is filled to the actual position.
  97. /// |渐变色是到顶部还是到实际位置。默认为true到顶部。
  98. /// </summary>
  99. public bool toTop
  100. {
  101. get { return m_ToTop; }
  102. set { if (PropertyUtil.SetStruct(ref m_ToTop, value)) SetVerticesDirty(); }
  103. }
  104. public Color32 GetColor()
  105. {
  106. if (m_Opacity == 1)
  107. return m_Color;
  108. var color = m_Color;
  109. color.a = (byte) (color.a * m_Opacity);
  110. return color;
  111. }
  112. public Color32 GetColor(Color32 themeColor)
  113. {
  114. if (!ChartHelper.IsClearColor(color))
  115. {
  116. return GetColor();
  117. }
  118. else
  119. {
  120. var color = themeColor;
  121. color.a = (byte) (color.a * opacity);
  122. return color;
  123. }
  124. }
  125. }
  126. }