Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SingleAxis.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// Single axis.
  7. /// |单轴。
  8. /// </summary>
  9. [System.Serializable]
  10. [ComponentHandler(typeof(SingleAxisHander), true)]
  11. public class SingleAxis : Axis, IUpdateRuntimeData
  12. {
  13. [SerializeField] protected Orient m_Orient = Orient.Horizonal;
  14. [SerializeField] private float m_Left = 0.1f;
  15. [SerializeField] private float m_Right = 0.1f;
  16. [SerializeField] private float m_Top = 0f;
  17. [SerializeField] private float m_Bottom = 0.2f;
  18. [SerializeField] private float m_Width = 0;
  19. [SerializeField] private float m_Height = 50;
  20. /// <summary>
  21. /// Orientation of the axis. By default, it's 'Horizontal'. You can set it to be 'Vertical' to make a vertical axis.
  22. /// |坐标轴朝向。默认为水平朝向。
  23. /// </summary>
  24. public Orient orient
  25. {
  26. get { return m_Orient; }
  27. set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetAllDirty(); }
  28. }
  29. /// <summary>
  30. /// Distance between component and the left side of the container.
  31. /// |组件离容器左侧的距离。
  32. /// </summary>
  33. public float left
  34. {
  35. get { return m_Left; }
  36. set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
  37. }
  38. /// <summary>
  39. /// Distance between component and the right side of the container.
  40. /// |组件离容器右侧的距离。
  41. /// </summary>
  42. public float right
  43. {
  44. get { return m_Right; }
  45. set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
  46. }
  47. /// <summary>
  48. /// Distance between component and the top side of the container.
  49. /// |组件离容器上侧的距离。
  50. /// </summary>
  51. public float top
  52. {
  53. get { return m_Top; }
  54. set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
  55. }
  56. /// <summary>
  57. /// Distance between component and the bottom side of the container.
  58. /// |组件离容器下侧的距离。
  59. /// </summary>
  60. public float bottom
  61. {
  62. get { return m_Bottom; }
  63. set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
  64. }
  65. /// <summary>
  66. /// width of axis.
  67. /// |坐标轴宽。
  68. /// </summary>
  69. public float width
  70. {
  71. get { return m_Width; }
  72. set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
  73. }
  74. /// <summary>
  75. /// height of axis.
  76. /// |坐标轴高。
  77. /// </summary>
  78. public float height
  79. {
  80. get { return m_Height; }
  81. set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
  82. }
  83. public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
  84. {
  85. context.left = left <= 1 ? left * chartWidth : left;
  86. context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
  87. context.top = top <= 1 ? top * chartHeight : top;
  88. context.right = right <= 1 ? right * chartWidth : right;
  89. context.height = height <= 1 ? height * chartHeight : height;
  90. if (m_Orient == Orient.Horizonal)
  91. {
  92. context.width = width == 0 ?
  93. chartWidth - context.left - context.right :
  94. (width <= 1 ? chartWidth * width : width);
  95. }
  96. else
  97. {
  98. context.width = width == 0 ?
  99. chartHeight - context.top - context.bottom :
  100. (width <= 1 ? chartHeight * width : width);
  101. }
  102. if (context.left != 0 && context.right == 0)
  103. context.x = chartX + context.left;
  104. else if (context.left == 0 && context.right != 0)
  105. context.x = chartX + chartWidth - context.right - context.width;
  106. else
  107. context.x = chartX + context.left;
  108. if (context.bottom != 0 && context.top == 0)
  109. context.y = chartY + context.bottom;
  110. else if (context.bottom == 0 && context.top != 0)
  111. context.y = chartY + chartHeight - context.top - context.height;
  112. else
  113. context.y = chartY + context.bottom;
  114. context.position = new Vector3(context.x, context.y);
  115. }
  116. public override void SetDefaultValue()
  117. {
  118. m_Show = true;
  119. m_Type = AxisType.Category;
  120. m_Min = 0;
  121. m_Max = 0;
  122. m_SplitNumber = 0;
  123. m_BoundaryGap = true;
  124. m_Position = AxisPosition.Bottom;
  125. m_Offset = 0;
  126. m_Left = 0.1f;
  127. m_Right = 0.1f;
  128. m_Top = 0;
  129. m_Bottom = 0.2f;
  130. m_Width = 0;
  131. m_Height = 50;
  132. m_Data = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
  133. m_Icons = new List<Sprite>(5);
  134. splitLine.show = false;
  135. splitLine.lineStyle.type = LineStyle.Type.None;
  136. axisLabel.textLimit.enable = true;
  137. axisTick.showStartTick = true;
  138. axisTick.showEndTick = true;
  139. }
  140. }
  141. }