AxisContext.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace XCharts.Runtime
  5. {
  6. public class AxisContext : MainComponentContext
  7. {
  8. public Orient orient;
  9. /// <summary>
  10. /// 坐标轴的起点X
  11. /// </summary>
  12. public float x;
  13. /// <summary>
  14. /// 坐标轴的起点Y
  15. /// </summary>
  16. public float y;
  17. /// <summary>
  18. /// 坐标轴原点X
  19. /// </summary>
  20. public float zeroX;
  21. /// <summary>
  22. /// 坐标轴原点Y
  23. /// </summary>
  24. public float zeroY;
  25. public float width;
  26. public float height;
  27. public Vector3 position;
  28. public float left;
  29. public float right;
  30. public float bottom;
  31. public float top;
  32. /// <summary>
  33. /// the current minimun value.
  34. /// ||当前最小值。
  35. /// </summary>
  36. public double minValue;
  37. public double lastMinValue { get; internal set; }
  38. public double destMinValue { get; internal set; }
  39. /// <summary>
  40. /// the current maximum value.
  41. /// ||当前最大值。
  42. /// </summary>
  43. public double maxValue;
  44. public double lastMaxValue { get; internal set; }
  45. public double destMaxValue { get; internal set; }
  46. public bool needAnimation { get; internal set; }
  47. /// <summary>
  48. /// the offset of zero position.
  49. /// ||坐标轴原点在坐标轴的偏移。
  50. /// </summary>
  51. public float offset;
  52. public double minMaxRange;
  53. /// <summary>
  54. /// the tick value of value axis.
  55. /// ||数值轴时每个tick的数值。
  56. /// </summary>
  57. public double tickValue;
  58. public float scaleWidth;
  59. public float startAngle;
  60. public double pointerValue;
  61. public Vector3 pointerLabelPosition;
  62. public double axisTooltipValue;
  63. public TextAnchor aligment;
  64. public List<string> runtimeData { get { return m_RuntimeData; } }
  65. public List<double> labelValueList { get { return m_LabelValueList; } }
  66. public List<ChartLabel> labelObjectList { get { return m_AxisLabelList; } }
  67. public int dataZoomStartIndex;
  68. /// <summary>
  69. /// 添加过的历史数据总数
  70. /// </summary>
  71. public int addedDataCount;
  72. internal List<string> filterData;
  73. internal bool lastCheckInverse;
  74. internal bool isNeedUpdateFilterData;
  75. private int filterStart;
  76. private int filterEnd;
  77. private int filterMinShow;
  78. private List<ChartLabel> m_AxisLabelList = new List<ChartLabel>();
  79. private List<double> m_LabelValueList = new List<double>();
  80. private List<string> m_RuntimeData = new List<string>();
  81. internal void Clear()
  82. {
  83. addedDataCount = 0;
  84. m_RuntimeData.Clear();
  85. }
  86. private List<string> m_EmptyFliter = new List<string>();
  87. /// <summary>
  88. /// 更新dataZoom对应的类目数据列表
  89. /// </summary>
  90. /// <param name="dataZoom"></param>
  91. internal void UpdateFilterData(List<string> data, DataZoom dataZoom)
  92. {
  93. int start = 0, end = 0;
  94. var range = Mathf.RoundToInt(data.Count * (dataZoom.end - dataZoom.start) / 100);
  95. if (range <= 0)
  96. range = 1;
  97. if (dataZoom.context.invert)
  98. {
  99. end = Mathf.RoundToInt(data.Count * dataZoom.end / 100);
  100. start = end - range;
  101. if (start < 0) start = 0;
  102. }
  103. else
  104. {
  105. start = Mathf.RoundToInt(data.Count * dataZoom.start / 100);
  106. end = start + range;
  107. if (end > data.Count) end = data.Count;
  108. }
  109. if (start != filterStart ||
  110. end != filterEnd ||
  111. dataZoom.minShowNum != filterMinShow ||
  112. isNeedUpdateFilterData)
  113. {
  114. filterStart = start;
  115. filterEnd = end;
  116. filterMinShow = dataZoom.minShowNum;
  117. isNeedUpdateFilterData = false;
  118. if (data.Count > 0)
  119. {
  120. if (range < dataZoom.minShowNum)
  121. {
  122. if (dataZoom.minShowNum > data.Count)
  123. range = data.Count;
  124. else
  125. range = dataZoom.minShowNum;
  126. }
  127. if (range > data.Count - start)
  128. start = data.Count - range;
  129. if (start >= 0)
  130. {
  131. dataZoomStartIndex = start;
  132. filterData = data.GetRange(start, range);
  133. }
  134. else
  135. {
  136. dataZoomStartIndex = 0;
  137. filterData = data;
  138. }
  139. }
  140. else
  141. {
  142. dataZoomStartIndex = 0;
  143. filterData = data;
  144. }
  145. }
  146. else if (end == 0)
  147. {
  148. dataZoomStartIndex = 0;
  149. filterData = m_EmptyFliter;
  150. }
  151. }
  152. }
  153. }