AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
CoordinateChart_DrawScatter.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 
11 namespace XCharts
12 {
13  public partial class CoordinateChart
14  {
15  protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
16  {
17  if (serie.animation.HasFadeOut()) return;
18  if (!serie.show) return;
19  DataZoom xDataZoom, yDataZoom;
20  DataZoomHelper.GetSerieRelatedDataZoom(serie, dataZooms, out xDataZoom, out yDataZoom);
21  var yAxis = m_YAxes[serie.yAxisIndex];
22  var xAxis = m_XAxes[serie.xAxisIndex];
23  var grid = GetSerieGridOrDefault(serie);
24  int maxCount = serie.maxShow > 0 ?
25  (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
26  : serie.dataCount;
27  serie.animation.InitProgress(1, 0, 1);
28  var rate = serie.animation.GetCurrRate();
29  var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
30  var dataChanging = false;
31  var dataList = serie.GetDataList(xDataZoom);
32  foreach (var serieData in dataList)
33  {
34  var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
35  if (!symbol.ShowSymbol(serieData.index, maxCount)) continue;
36  var highlight = serie.highlighted || serieData.highlighted;
37  var color = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
38  var toColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
39  var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, colorIndex, highlight, false);
40  var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
41  var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
42  double xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
43  double yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
44  if (serieData.IsDataChanged()) dataChanging = true;
45  float pX = grid.runtimeX + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
46  float pY = grid.runtimeY + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
47  float xDataHig = GetDataHig(xAxis, xValue, grid.runtimeWidth);
48  float yDataHig = GetDataHig(yAxis, yValue, grid.runtimeHeight);
49  var pos = new Vector3(pX + xDataHig, pY + yDataHig);
50  if (!IsInGrid(grid, pos)) continue;
51  serie.dataPoints.Add(pos);
52  serieData.runtimePosition = pos;
53  var datas = serieData.data;
54  float symbolSize = 0;
55  if (serie.highlighted || serieData.highlighted)
56  {
57  symbolSize = symbol.GetSelectedSize(datas, m_Theme.serie.scatterSymbolSelectedSize);
58  }
59  else
60  {
61  symbolSize = symbol.GetSize(datas, m_Theme.serie.scatterSymbolSize);
62  }
63  symbolSize *= rate;
64  if (symbolSize > 100) symbolSize = 100;
65  if (serie.type == SerieType.EffectScatter)
66  {
67  for (int count = 0; count < symbol.animationSize.Count; count++)
68  {
69  var nowSize = symbol.animationSize[count];
70  color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
71  DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, backgroundColor, symbol.gap, cornerRadius);
72  }
73  RefreshPainter(serie);
74  }
75  else
76  {
77  DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, color, toColor, backgroundColor, symbol.gap, cornerRadius);
78  }
79  }
80  if (!serie.animation.IsFinish())
81  {
82  serie.animation.CheckProgress(1);
83  m_IsPlayingAnimation = true;
84  RefreshPainter(serie);
85  }
86  if (dataChanging)
87  {
88  RefreshPainter(serie);
89  }
90  }
91 
92  private float GetDataHig(Axis axis, double value, float totalWidth)
93  {
94  if (axis.IsLog())
95  {
96  int minIndex = axis.runtimeMinLogIndex;
97  float nowIndex = axis.GetLogValue(value);
98  return (nowIndex - minIndex) / axis.splitNumber * totalWidth;
99  }
100  else
101  {
102  return (float)((value - axis.runtimeMinValue) / axis.runtimeMinMaxRange * totalWidth);
103  }
104  }
105  }
106 }
XCharts.SerieType
SerieType
the type of serie. 系列类型。
Definition: Serie.cs:19
XCharts
Definition: RewardChart.cs:14
XCharts.CoordinateChart.IsInGrid
bool IsInGrid(Grid grid, Vector2 local)
坐标是否在坐标轴内。
Definition: CoordinateChart_API.cs:254
XCharts.CoordinateChart.grid
Grid? grid
grid component. 网格组件。
Definition: CoordinateChart_API.cs:24