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.

LineHandler.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. using XUGL;
  7. namespace XCharts.Runtime
  8. {
  9. /// <summary>
  10. /// For grid coord
  11. /// </summary>
  12. [UnityEngine.Scripting.Preserve]
  13. internal sealed partial class LineHandler : SerieHandler<Line>
  14. {
  15. public override void Update()
  16. {
  17. base.Update();
  18. if (serie.IsUseCoord<GridCoord>())
  19. UpdateSerieGridContext();
  20. else if (serie.IsUseCoord<PolarCoord>())
  21. UpdateSeriePolarContext();
  22. }
  23. public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category,
  24. string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent,
  25. ref List<SerieParams> paramList, ref string title)
  26. {
  27. UpdateCoordSerieParams(ref paramList, ref title, dataIndex, showCategory, category,
  28. marker, itemFormatter, numericFormatter, ignoreDataDefaultContent);
  29. }
  30. public override void DrawSerie(VertexHelper vh)
  31. {
  32. if (serie.IsUseCoord<PolarCoord>())
  33. {
  34. DrawPolarLine(vh, serie);
  35. DrawPolarLineSymbol(vh);
  36. DrawPolarLineArrow(vh, serie);
  37. }
  38. else if (serie.IsUseCoord<GridCoord>())
  39. {
  40. DrawLineSerie(vh, serie);
  41. if (!SeriesHelper.IsStack(chart.series))
  42. {
  43. DrawLinePoint(vh, serie);
  44. DrawLineArrow(vh, serie);
  45. }
  46. }
  47. }
  48. public override void DrawUpper(VertexHelper vh)
  49. {
  50. if (serie.IsUseCoord<GridCoord>())
  51. {
  52. if (SeriesHelper.IsStack(chart.series))
  53. {
  54. DrawLinePoint(vh, serie);
  55. DrawLineArrow(vh, serie);
  56. }
  57. }
  58. }
  59. public override void RefreshEndLabelInternal()
  60. {
  61. base.RefreshEndLabelInternal();
  62. if (m_SerieGrid == null) return;
  63. if (!serie.animation.IsFinish()) return;
  64. var endLabelList = m_SerieGrid.context.endLabelList;
  65. if (endLabelList.Count <= 1) return;
  66. endLabelList.Sort(delegate (ChartLabel a, ChartLabel b)
  67. {
  68. if (a == null || b == null) return 1;
  69. return b.transform.position.y.CompareTo(a.transform.position.y);
  70. });
  71. var lastY = float.NaN;
  72. for (int i = 0; i < endLabelList.Count; i++)
  73. {
  74. var label = endLabelList[i];
  75. if (label == null) continue;
  76. if (!label.isAnimationEnd) continue;
  77. var labelPosition = label.transform.localPosition;
  78. if (float.IsNaN(lastY))
  79. {
  80. lastY = labelPosition.y;
  81. }
  82. else
  83. {
  84. var labelHeight = label.GetTextHeight();
  85. if (labelPosition.y + labelHeight > lastY)
  86. {
  87. label.SetPosition(new Vector3(labelPosition.x, lastY - labelHeight, labelPosition.z));
  88. }
  89. lastY = label.transform.localPosition.y;
  90. }
  91. }
  92. }
  93. public override int GetPointerItemDataIndex()
  94. {
  95. var symbolSize = SerieHelper.GetSysmbolSize(serie, null, chart.theme, chart.theme.serie.lineSymbolSize) * 1.5f;
  96. var count = serie.context.dataPoints.Count;
  97. for (int i = 0; i < count; i++)
  98. {
  99. var index = serie.context.dataIndexs[i];
  100. var serieData = serie.GetSerieData(index);
  101. if (serieData == null)
  102. continue;
  103. if (serieData.context.isClip)
  104. continue;
  105. var pos = serie.context.dataPoints[i];
  106. if (Vector2.Distance(pos, chart.pointerPos) < symbolSize)
  107. {
  108. return i;
  109. }
  110. }
  111. return -1;
  112. }
  113. }
  114. }