No Description
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.

AxisTheme.cs 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. #if dUI_TextMeshPro
  5. using TMPro;
  6. #endif
  7. namespace XCharts.Runtime
  8. {
  9. [Serializable]
  10. public class BaseAxisTheme : ComponentTheme
  11. {
  12. [SerializeField] protected LineStyle.Type m_LineType = LineStyle.Type.Solid;
  13. [SerializeField] protected float m_LineWidth = 1f;
  14. [SerializeField] protected float m_LineLength = 0f;
  15. [SerializeField] protected Color32 m_LineColor;
  16. [SerializeField] protected LineStyle.Type m_SplitLineType = LineStyle.Type.Dashed;
  17. [SerializeField] protected float m_SplitLineWidth = 1f;
  18. [SerializeField] protected float m_SplitLineLength = 0f;
  19. [SerializeField] protected Color32 m_SplitLineColor;
  20. [SerializeField] protected Color32 m_MinorSplitLineColor;
  21. [SerializeField] protected float m_TickWidth = 1f;
  22. [SerializeField] protected float m_TickLength = 5f;
  23. [SerializeField] protected Color32 m_TickColor;
  24. [SerializeField] protected List<Color32> m_SplitAreaColors = new List<Color32>();
  25. /// <summary>
  26. /// the type of line.
  27. /// |坐标轴线类型。
  28. /// </summary>
  29. public LineStyle.Type lineType
  30. {
  31. get { return m_LineType; }
  32. set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
  33. }
  34. /// <summary>
  35. /// the width of line.
  36. /// |坐标轴线宽。
  37. /// </summary>
  38. public float lineWidth
  39. {
  40. get { return m_LineWidth; }
  41. set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
  42. }
  43. /// <summary>
  44. /// the length of line.
  45. /// |坐标轴线长。
  46. /// </summary>
  47. public float lineLength
  48. {
  49. get { return m_LineLength; }
  50. set { if (PropertyUtil.SetStruct(ref m_LineLength, value)) SetVerticesDirty(); }
  51. }
  52. /// <summary>
  53. /// the color of line.
  54. /// |坐标轴线颜色。
  55. /// </summary>
  56. public Color32 lineColor
  57. {
  58. get { return m_LineColor; }
  59. set { if (PropertyUtil.SetColor(ref m_LineColor, value)) SetVerticesDirty(); }
  60. }
  61. /// <summary>
  62. /// the type of split line.
  63. /// |分割线线类型。
  64. /// </summary>
  65. public LineStyle.Type splitLineType
  66. {
  67. get { return m_SplitLineType; }
  68. set { if (PropertyUtil.SetStruct(ref m_SplitLineType, value)) SetVerticesDirty(); }
  69. }
  70. /// <summary>
  71. /// the width of split line.
  72. /// |分割线线宽。
  73. /// </summary>
  74. public float splitLineWidth
  75. {
  76. get { return m_SplitLineWidth; }
  77. set { if (PropertyUtil.SetStruct(ref m_SplitLineWidth, value)) SetVerticesDirty(); }
  78. }
  79. /// <summary>
  80. /// the length of split line.
  81. /// |分割线线长。
  82. /// </summary>
  83. public float splitLineLength
  84. {
  85. get { return m_SplitLineLength; }
  86. set { if (PropertyUtil.SetStruct(ref m_SplitLineLength, value)) SetVerticesDirty(); }
  87. }
  88. /// <summary>
  89. /// the color of split line.
  90. /// |分割线线颜色。
  91. /// </summary>
  92. public Color32 splitLineColor
  93. {
  94. get { return m_SplitLineColor; }
  95. set { if (PropertyUtil.SetColor(ref m_SplitLineColor, value)) SetVerticesDirty(); }
  96. }
  97. /// <summary>
  98. /// the color of minor split line.
  99. /// |次分割线线颜色。
  100. /// </summary>
  101. public Color32 minorSplitLineColor
  102. {
  103. get { return ChartHelper.IsClearColor(m_MinorSplitLineColor) ? ColorUtil.GetColor("#F4F7FD") : m_MinorSplitLineColor; }
  104. set { if (PropertyUtil.SetColor(ref m_MinorSplitLineColor, value)) SetVerticesDirty(); }
  105. }
  106. /// <summary>
  107. /// the length of tick.
  108. /// |刻度线线长。
  109. /// </summary>
  110. public float tickLength
  111. {
  112. get { return m_TickLength; }
  113. set { if (PropertyUtil.SetStruct(ref m_TickLength, value)) SetVerticesDirty(); }
  114. }
  115. /// <summary>
  116. /// the width of tick.
  117. /// |刻度线线宽。
  118. /// </summary>
  119. public float tickWidth
  120. {
  121. get { return m_TickWidth; }
  122. set { if (PropertyUtil.SetStruct(ref m_TickWidth, value)) SetVerticesDirty(); }
  123. }
  124. /// <summary>
  125. /// the color of tick.
  126. /// |坐标轴线颜色。
  127. /// </summary>
  128. public Color32 tickColor
  129. {
  130. get { return m_TickColor; }
  131. set { if (PropertyUtil.SetColor(ref m_TickColor, value)) SetVerticesDirty(); }
  132. }
  133. /// <summary>
  134. /// the colors of split area.
  135. /// |坐标轴分隔区域的颜色。
  136. /// </summary>
  137. public List<Color32> splitAreaColors
  138. {
  139. get { return m_SplitAreaColors; }
  140. set { if (value != null) { m_SplitAreaColors = value; SetVerticesDirty(); } }
  141. }
  142. public BaseAxisTheme(ThemeType theme) : base(theme)
  143. {
  144. m_FontSize = XCSettings.fontSizeLv4;
  145. m_LineType = XCSettings.axisLineType;
  146. m_LineWidth = XCSettings.axisLineWidth;
  147. m_LineLength = 0;
  148. m_SplitLineType = XCSettings.axisSplitLineType;
  149. m_SplitLineWidth = XCSettings.axisSplitLineWidth;
  150. m_SplitLineLength = 0;
  151. m_TickWidth = XCSettings.axisTickWidth;
  152. m_TickLength = XCSettings.axisTickLength;
  153. switch (theme)
  154. {
  155. case ThemeType.Default:
  156. m_LineColor = ColorUtil.GetColor("#6E7079");
  157. m_TickColor = ColorUtil.GetColor("#6E7079");
  158. m_SplitLineColor = ColorUtil.GetColor("#E0E6F1");
  159. m_MinorSplitLineColor = ColorUtil.GetColor("#F4F7FD");
  160. m_SplitAreaColors = new List<Color32>
  161. {
  162. new Color32(250, 250, 250, 51),
  163. new Color32(210, 219, 238, 51)
  164. };
  165. break;
  166. case ThemeType.Light:
  167. m_LineColor = ColorUtil.GetColor("#6E7079");
  168. m_TickColor = ColorUtil.GetColor("#6E7079");
  169. m_SplitLineColor = ColorUtil.GetColor("#E0E6F1");
  170. m_MinorSplitLineColor = ColorUtil.GetColor("#F4F7FD");
  171. m_SplitAreaColors = new List<Color32>
  172. {
  173. new Color32(250, 250, 250, 51),
  174. new Color32(210, 219, 238, 51)
  175. };
  176. break;
  177. case ThemeType.Dark:
  178. m_LineColor = ColorUtil.GetColor("#6E7079");
  179. m_TickColor = ColorUtil.GetColor("#6E7079");
  180. m_SplitLineColor = ColorUtil.GetColor("#E0E6F1");
  181. m_MinorSplitLineColor = ColorUtil.GetColor("#F4F7FD");
  182. m_SplitAreaColors = new List<Color32>
  183. {
  184. new Color32(255, 255, 255, (byte) (0.02f * 255)),
  185. new Color32(210, 219, 238, (byte) (0.02f * 255))
  186. };
  187. break;
  188. }
  189. }
  190. public void Copy(BaseAxisTheme theme)
  191. {
  192. base.Copy(theme);
  193. m_LineType = theme.lineType;
  194. m_LineWidth = theme.lineWidth;
  195. m_LineLength = theme.lineLength;
  196. m_LineColor = theme.lineColor;
  197. m_SplitLineType = theme.splitLineType;
  198. m_SplitLineWidth = theme.splitLineWidth;
  199. m_SplitLineLength = theme.splitLineLength;
  200. m_SplitLineColor = theme.splitLineColor;
  201. m_TickWidth = theme.tickWidth;
  202. m_TickLength = theme.tickLength;
  203. m_TickColor = theme.tickColor;
  204. ChartHelper.CopyList(m_SplitAreaColors, theme.splitAreaColors);
  205. }
  206. }
  207. [Serializable]
  208. public class AxisTheme : BaseAxisTheme
  209. {
  210. public AxisTheme(ThemeType theme) : base(theme) { }
  211. }
  212. [Serializable]
  213. public class RadiusAxisTheme : BaseAxisTheme
  214. {
  215. public RadiusAxisTheme(ThemeType theme) : base(theme) { }
  216. }
  217. [Serializable]
  218. public class AngleAxisTheme : BaseAxisTheme
  219. {
  220. public AngleAxisTheme(ThemeType theme) : base(theme) { }
  221. }
  222. [Serializable]
  223. public class PolarAxisTheme : BaseAxisTheme
  224. {
  225. public PolarAxisTheme(ThemeType theme) : base(theme) { }
  226. }
  227. [Serializable]
  228. public class RadarAxisTheme : BaseAxisTheme
  229. {
  230. public RadarAxisTheme(ThemeType theme) : base(theme)
  231. {
  232. m_SplitAreaColors.Clear();
  233. switch (theme)
  234. {
  235. case ThemeType.Dark:
  236. m_SplitAreaColors.Add(ThemeStyle.GetColor("#6f6f6f"));
  237. m_SplitAreaColors.Add(ThemeStyle.GetColor("#606060"));
  238. break;
  239. case ThemeType.Default:
  240. m_SplitAreaColors.Add(ThemeStyle.GetColor("#f6f6f6"));
  241. m_SplitAreaColors.Add(ThemeStyle.GetColor("#e7e7e7"));
  242. break;
  243. case ThemeType.Light:
  244. m_SplitAreaColors.Add(ThemeStyle.GetColor("#f6f6f6"));
  245. m_SplitAreaColors.Add(ThemeStyle.GetColor("#e7e7e7"));
  246. break;
  247. }
  248. }
  249. }
  250. }