説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SingleAxisHandler.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.chartX,
  32. chart.chartY,
  33. chart.chartWidth,
  34. chart.chartHeight);
  35. InitAxis(null,
  36. axis.orient,
  37. axis.context.x,
  38. axis.context.y,
  39. axis.context.width,
  40. axis.context.height);
  41. };
  42. axis.refreshComponent();
  43. }
  44. internal override void UpdateAxisLabelText(Axis axis)
  45. {
  46. base.UpdateAxisLabelText(axis);
  47. if (axis.IsTime() || axis.IsValue())
  48. {
  49. for (int i = 0; i < axis.context.labelObjectList.Count; i++)
  50. {
  51. var label = axis.context.labelObjectList[i];
  52. if (label != null)
  53. {
  54. var pos = GetLabelPosition(0, i);
  55. label.SetPosition(pos);
  56. CheckValueLabelActive(component, i, label, pos);
  57. }
  58. }
  59. }
  60. }
  61. protected override Vector3 GetLabelPosition(float scaleWid, int i)
  62. {
  63. return GetLabelPosition(i, component.orient, component, null,
  64. chart.theme.axis,
  65. scaleWid,
  66. component.context.x,
  67. component.context.y,
  68. component.context.width,
  69. component.context.height);
  70. }
  71. private void DrawSingleAxisSplit(VertexHelper vh, SingleAxis axis)
  72. {
  73. if (AxisHelper.NeedShowSplit(axis))
  74. {
  75. var dataZoom = chart.GetDataZoomOfAxis(axis);
  76. DrawAxisSplit(vh, chart.theme.axis, dataZoom,
  77. axis.orient,
  78. axis.context.x,
  79. axis.context.y,
  80. axis.context.width,
  81. axis.context.height);
  82. }
  83. }
  84. private void DrawSingleAxisTick(VertexHelper vh, SingleAxis axis)
  85. {
  86. if (AxisHelper.NeedShowSplit(axis))
  87. {
  88. var dataZoom = chart.GetDataZoomOfAxis(axis);
  89. DrawAxisTick(vh, axis, chart.theme.axis, dataZoom,
  90. axis.orient,
  91. axis.context.x,
  92. axis.context.y,
  93. axis.context.width);
  94. }
  95. }
  96. private void DrawSingleAxisLine(VertexHelper vh, SingleAxis axis)
  97. {
  98. if (axis.show && axis.axisLine.show)
  99. {
  100. DrawAxisLine(vh, axis,
  101. chart.theme.axis,
  102. axis.orient,
  103. axis.context.x,
  104. GetAxisLineXOrY(),
  105. axis.context.width);
  106. }
  107. }
  108. internal override float GetAxisLineXOrY()
  109. {
  110. return component.context.y + component.offset;
  111. }
  112. }
  113. }