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