SingleAxisHandler.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace XCharts.Runtime
  4. {
  5. [UnityEngine.Scripting.Preserve]
  6. internal sealed class SingleAxisHander : AxisHandler<SingleAxis>
  7. {
  8. protected override Orient orient { get { return component.orient; } }
  9. public override void InitComponent()
  10. {
  11. InitXAxis(component);
  12. }
  13. public override void Update()
  14. {
  15. UpdateAxisMinMaxValue(component.index, component);
  16. UpdatePointerValue(component);
  17. }
  18. public override void DrawBase(VertexHelper vh)
  19. {
  20. DrawSingleAxisSplit(vh, component);
  21. DrawSingleAxisLine(vh, component);
  22. DrawSingleAxisTick(vh, component);
  23. }
  24. private void InitXAxis(SingleAxis axis)
  25. {
  26. var theme = chart.theme;
  27. var xAxisIndex = axis.index;
  28. axis.painter = chart.painter;
  29. axis.refreshComponent = delegate()
  30. {
  31. axis.UpdateRuntimeData(chart);
  32. InitAxis(null,
  33. axis.orient,
  34. axis.context.x,
  35. axis.context.y,
  36. axis.context.width,
  37. axis.context.height);
  38. };
  39. axis.refreshComponent();
  40. }
  41. internal override void UpdateAxisLabelText(Axis axis)
  42. {
  43. base.UpdateAxisLabelText(axis);
  44. if (axis.IsTime() || axis.IsValue())
  45. {
  46. for (int i = 0; i < axis.context.labelObjectList.Count; i++)
  47. {
  48. var label = axis.context.labelObjectList[i];
  49. if (label != null)
  50. {
  51. var pos = GetLabelPosition(0, i);
  52. label.SetPosition(pos);
  53. CheckValueLabelActive(component, i, label, pos);
  54. }
  55. }
  56. }
  57. }
  58. protected override Vector3 GetLabelPosition(float scaleWid, int i)
  59. {
  60. return GetLabelPosition(i, component.orient, component, null,
  61. chart.theme.axis,
  62. scaleWid,
  63. component.context.x,
  64. component.context.y,
  65. component.context.width,
  66. component.context.height);
  67. }
  68. private void DrawSingleAxisSplit(VertexHelper vh, SingleAxis axis)
  69. {
  70. if (AxisHelper.NeedShowSplit(axis))
  71. {
  72. var dataZoom = chart.GetDataZoomOfAxis(axis);
  73. DrawAxisSplit(vh, chart.theme.axis, dataZoom,
  74. axis.orient,
  75. axis.context.x,
  76. axis.context.y,
  77. axis.context.width,
  78. axis.context.height);
  79. }
  80. }
  81. private void DrawSingleAxisTick(VertexHelper vh, SingleAxis axis)
  82. {
  83. if (AxisHelper.NeedShowSplit(axis))
  84. {
  85. var dataZoom = chart.GetDataZoomOfAxis(axis);
  86. DrawAxisTick(vh, axis, chart.theme.axis, dataZoom,
  87. axis.orient,
  88. axis.context.x,
  89. axis.context.y,
  90. axis.context.width);
  91. }
  92. }
  93. private void DrawSingleAxisLine(VertexHelper vh, SingleAxis axis)
  94. {
  95. if (axis.show && axis.axisLine.show)
  96. {
  97. DrawAxisLine(vh, axis,
  98. chart.theme.axis,
  99. axis.orient,
  100. axis.context.x,
  101. GetAxisLineXOrY(),
  102. axis.context.width);
  103. }
  104. }
  105. internal override float GetAxisLineXOrY()
  106. {
  107. return component.context.y + component.offset;
  108. }
  109. }
  110. }