CoordinateChart_DrawHeatmap.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /************************************************/
  2. /* */
  3. /* Copyright (c) 2018 - 2021 monitor1394 */
  4. /* https://github.com/monitor1394 */
  5. /* */
  6. /************************************************/
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using XUGL;
  10. namespace XCharts
  11. {
  12. public partial class CoordinateChart
  13. {
  14. protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
  15. {
  16. if (serie.animation.HasFadeOut()) return;
  17. var yAxis = m_YAxes[serie.yAxisIndex];
  18. var xAxis = m_XAxes[serie.xAxisIndex];
  19. xAxis.boundaryGap = true;
  20. yAxis.boundaryGap = true;
  21. var grid = GetSerieGridOrDefault(serie);
  22. var xCount = xAxis.data.Count;
  23. var yCount = yAxis.data.Count;
  24. var xWidth = grid.runtimeWidth / xCount;
  25. var yWidth = grid.runtimeHeight / yCount;
  26. var zeroX = grid.runtimeX;
  27. var zeroY = grid.runtimeY;
  28. var dataList = serie.GetDataList();
  29. var rangeMin = visualMap.rangeMin;
  30. var rangeMax = visualMap.rangeMax;
  31. var color = m_Theme.GetColor(serie.index);
  32. var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
  33. var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;
  34. borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
  35. var borderToColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderToColor : ChartConst.clearColor32;
  36. borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity);
  37. serie.dataPoints.Clear();
  38. serie.animation.InitProgress(1, 0, xCount);
  39. var animationIndex = serie.animation.GetCurrIndex();
  40. var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
  41. var dataChanging = false;
  42. for (int i = 0; i < xCount; i++)
  43. {
  44. for (int j = 0; j < yCount; j++)
  45. {
  46. var dataIndex = i * yCount + j;
  47. if (dataIndex >= dataList.Count) continue;
  48. var serieData = dataList[dataIndex];
  49. var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
  50. if (serie.IsIgnoreIndex(dataIndex, dimension))
  51. {
  52. serie.dataPoints.Add(Vector3.zero);
  53. continue;
  54. }
  55. var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse,
  56. yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
  57. if (serieData.IsDataChanged()) dataChanging = true;
  58. var pos = new Vector3(zeroX + (i + (xAxis.boundaryGap ? 0.5f : 0)) * xWidth,
  59. zeroY + (j + (yAxis.boundaryGap ? 0.5f : 0)) * yWidth);
  60. serie.dataPoints.Add(pos);
  61. serieData.canShowLabel = false;
  62. if (value == 0) continue;
  63. if (visualMap.enable)
  64. {
  65. if ((value < rangeMin && rangeMin != visualMap.min)
  66. || (value > rangeMax && rangeMax != visualMap.max))
  67. {
  68. continue;
  69. }
  70. if (!visualMap.IsInSelectedValue(value)) continue;
  71. color = visualMap.GetColor(value);
  72. }
  73. if (animationIndex >= 0 && i > animationIndex) continue;
  74. serieData.canShowLabel = true;
  75. var emphasis = (tooltip.show
  76. && i == (int)tooltip.runtimeXValues[0]
  77. && j == (int)tooltip.runtimeYValues[0])
  78. || visualMap.runtimeSelectedIndex > 0;
  79. var rectWid = xWidth - 2 * borderWidth;
  80. var rectHig = yWidth - 2 * borderWidth;
  81. UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
  82. if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
  83. {
  84. UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor);
  85. }
  86. if (visualMap.hoverLink && emphasis && serie.emphasis.show
  87. && serie.emphasis.itemStyle.borderWidth > 0)
  88. {
  89. var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
  90. var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0
  91. ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
  92. var emphasisBorderToColor = serie.emphasis.itemStyle.opacity > 0
  93. ? serie.emphasis.itemStyle.borderToColor : ChartConst.clearColor32;
  94. UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor,
  95. emphasisBorderToColor);
  96. }
  97. }
  98. }
  99. if (!serie.animation.IsFinish())
  100. {
  101. serie.animation.CheckProgress(xCount);
  102. m_IsPlayingAnimation = true;
  103. RefreshPainter(serie);
  104. }
  105. if (dataChanging)
  106. {
  107. RefreshPainter(serie);
  108. }
  109. }
  110. }
  111. }