暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ParallelHandler.cs 6.0KB

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