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

ParallelHandler.cs 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using XUGL;
  5. namespace XCharts.Runtime
  6. {
  7. [UnityEngine.Scripting.Preserve]
  8. internal sealed class ParallelHandler : SerieHandler<Parallel>
  9. {
  10. public override void Update()
  11. {
  12. base.Update();
  13. UpdateSerieContext();
  14. }
  15. public override void DrawSerie(VertexHelper vh)
  16. {
  17. DrawParallelSerie(vh, serie);
  18. }
  19. private void UpdateSerieContext() { }
  20. private void DrawParallelSerie(VertexHelper vh, Parallel serie)
  21. {
  22. if (!serie.show) return;
  23. if (serie.animation.HasFadeOut()) return;
  24. var parallel = chart.GetChartComponent<ParallelCoord>(serie.parallelIndex);
  25. if (parallel == null)
  26. return;
  27. var axisCount = parallel.context.parallelAxes.Count;
  28. if (axisCount <= 0)
  29. return;
  30. var animationIndex = serie.animation.GetCurrIndex();
  31. var isHorizonal = parallel.orient == Orient.Horizonal;
  32. var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
  33. float currDetailProgress = !isHorizonal ?
  34. parallel.context.x :
  35. parallel.context.y;
  36. float totalDetailProgress = !isHorizonal ?
  37. parallel.context.x + parallel.context.width :
  38. parallel.context.y + parallel.context.height;
  39. serie.animation.InitProgress(currDetailProgress, totalDetailProgress);
  40. serie.containerIndex = parallel.index;
  41. serie.containterInstanceId = parallel.instanceId;
  42. var currProgress = serie.animation.GetCurrDetail();
  43. var isSmooth = serie.lineType == LineType.Smooth;
  44. foreach (var serieData in serie.data)
  45. {
  46. var count = Mathf.Min(axisCount, serieData.data.Count);
  47. var lp = Vector3.zero;
  48. var colorIndex = serie.colorByData?serieData.index : serie.context.colorIndex;
  49. var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex);
  50. serieData.context.dataPoints.Clear();
  51. for (int i = 0; i < count; i++)
  52. {
  53. if (animationIndex >= 0 && i > animationIndex) continue;
  54. var pos = GetPos(parallel, i, serieData.data[i], isHorizonal);
  55. if (!isHorizonal)
  56. {
  57. if (isSmooth)
  58. {
  59. serieData.context.dataPoints.Add(pos);
  60. }
  61. else if (pos.x <= currProgress)
  62. {
  63. serieData.context.dataPoints.Add(pos);
  64. }
  65. else
  66. {
  67. var currProgressStart = new Vector3(currProgress, parallel.context.y - 50);
  68. var currProgressEnd = new Vector3(currProgress, parallel.context.y + parallel.context.height + 50);
  69. var intersectionPos = Vector3.zero;
  70. if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos))
  71. serieData.context.dataPoints.Add(intersectionPos);
  72. else
  73. serieData.context.dataPoints.Add(pos);
  74. break;
  75. }
  76. }
  77. else
  78. {
  79. if (isSmooth)
  80. {
  81. serieData.context.dataPoints.Add(pos);
  82. }
  83. else if (pos.y <= currProgress)
  84. {
  85. serieData.context.dataPoints.Add(pos);
  86. }
  87. else
  88. {
  89. var currProgressStart = new Vector3(parallel.context.x - 50, currProgress);
  90. var currProgressEnd = new Vector3(parallel.context.x + parallel.context.width + 50, currProgress);
  91. var intersectionPos = Vector3.zero;
  92. if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos))
  93. serieData.context.dataPoints.Add(intersectionPos);
  94. else
  95. serieData.context.dataPoints.Add(pos);
  96. break;
  97. }
  98. }
  99. lp = pos;
  100. }
  101. if (isSmooth)
  102. UGL.DrawCurves(vh, serieData.context.dataPoints, lineWidth, lineColor,
  103. chart.settings.lineSmoothStyle,
  104. chart.settings.lineSmoothness,
  105. UGL.Direction.XAxis, currProgress, isHorizonal);
  106. else
  107. UGL.DrawLine(vh, serieData.context.dataPoints, lineWidth, lineColor, isSmooth);
  108. }
  109. if (!serie.animation.IsFinish())
  110. {
  111. serie.animation.CheckProgress(totalDetailProgress - currDetailProgress);
  112. chart.RefreshPainter(serie);
  113. }
  114. }
  115. private static ParallelAxis GetAxis(ParallelCoord parallel, int index)
  116. {
  117. if (index >= 0 && index < parallel.context.parallelAxes.Count)
  118. return parallel.context.parallelAxes[index];
  119. else
  120. return null;
  121. }
  122. private static Vector3 GetPos(ParallelCoord parallel, int axisIndex, double dataValue, bool isHorizonal)
  123. {
  124. var axis = GetAxis(parallel, axisIndex);
  125. if (axis == null)
  126. return Vector3.zero;
  127. var sValueDist = axis.GetDistance(dataValue, axis.context.width);
  128. return new Vector3(
  129. isHorizonal ? axis.context.x + sValueDist : axis.context.x,
  130. isHorizonal ? axis.context.y : axis.context.y + sValueDist);
  131. }
  132. }
  133. }