AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
ScatterChart.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using UnityEngine;
9 
10 namespace XCharts
11 {
12  [AddComponentMenu("XCharts/ScatterChart", 17)]
13  [ExecuteInEditMode]
14  [RequireComponent(typeof(RectTransform))]
15  [DisallowMultipleComponent]
17  {
18  private float m_EffectScatterSpeed = 15;
19  private float m_EffectScatterSize;
20  private float m_EffectScatterAplha;
21 
22 #if UNITY_EDITOR
23  protected override void Reset()
24  {
25  base.Reset();
26  title.text = "ScatterChart";
27  tooltip.type = Tooltip.Type.None;
28  m_XAxes[0].type = Axis.AxisType.Value;
29  m_XAxes[0].boundaryGap = false;
30  m_YAxes[1].type = Axis.AxisType.Value;
31  m_XAxes[1].boundaryGap = false;
32  RemoveData();
33  SerieTemplate.AddDefaultScatterSerie(this, "serie1");
34  }
35 #endif
36 
37  protected override void Update()
38  {
39  base.Update();
40  bool hasEffectScatter = false;
41  foreach (var serie in m_Series.list)
42  {
43  if (serie.type == SerieType.EffectScatter)
44  {
45  hasEffectScatter = true;
46  var symbolSize = serie.symbol.GetSize(null, m_Theme.serie.scatterSymbolSize);
47  for (int i = 0; i < serie.symbol.animationSize.Count; ++i)
48  {
49  serie.symbol.animationSize[i] += m_EffectScatterSpeed * Time.deltaTime;
50  if (serie.symbol.animationSize[i] > symbolSize)
51  {
52  serie.symbol.animationSize[i] = i * 5;
53  }
54  }
55  }
56  }
57  if (hasEffectScatter)
58  {
59  RefreshChart();
60  }
61  }
62 
63  protected override void CheckTootipArea(Vector2 local, bool isActivedOther)
64  {
65  base.CheckTootipArea(local, isActivedOther);
66  if (isActivedOther) return;
67  tooltip.ClearSerieDataIndex();
68  bool selected = false;
69  foreach (var serie in m_Series.list)
70  {
71  if (!serie.show) continue;
72  if (serie.type != SerieType.Scatter && serie.type != SerieType.EffectScatter) continue;
73  bool refresh = false;
74  var dataCount = serie.data.Count;
75  for (int j = 0; j < serie.data.Count; j++)
76  {
77  var serieData = serie.data[j];
78  var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
79  if (!symbol.ShowSymbol(j, dataCount)) continue;
80  var dist = Vector3.Distance(local, serieData.runtimePosition);
81  if (dist <= symbol.GetSize(serieData.data, m_Theme.serie.scatterSymbolSize))
82  {
83  serieData.selected = true;
84  tooltip.AddSerieDataIndex(serie.index, j);
85  selected = true;
86  }
87  else
88  {
89  serieData.selected = false;
90  }
91  }
92  if (refresh) RefreshChart();
93  }
94  if (selected)
95  {
96  tooltip.UpdateContentPos(local + tooltip.offset);
97  UpdateTooltip();
98  }
99  else if (tooltip.IsActive())
100  {
101  tooltip.SetActive(false);
102  RefreshChart();
103  }
104  }
105 
106  protected override void UpdateTooltip()
107  {
108  base.UpdateTooltip();
109  if (tooltip.isAnySerieDataIndex())
110  {
111  var content = TooltipHelper.GetFormatterContent(tooltip, 0, this);
112  TooltipHelper.SetContentAndPosition(tooltip, content, chartRect);
113  tooltip.SetActive(true);
114  }
115  else
116  {
117  tooltip.SetActive(false);
118  }
119  }
120  }
121 }
XCharts.Tooltip.Type
Type
Indicator type. 指示器类型。
Definition: Tooltip.cs:25
XCharts.Tooltip
Tooltip component. 提示框组件。
Definition: Tooltip.cs:19
XCharts.CoordinateChart.RemoveData
override void RemoveData()
Remove all data from series,legend and axis. The series list is also cleared. 清空所有图例,系列和坐标轴类目数据。系列的列表...
Definition: CoordinateChart_API.cs:71
XCharts.SerieType
SerieType
the type of serie. 系列类型。
Definition: Serie.cs:19
XCharts
Definition: RewardChart.cs:14
XCharts.Axis
The axis in rectangular coordinate. 直角坐标系的坐标轴组件。
Definition: Axis.cs:20
XCharts.ScatterChart
Definition: ScatterChart.cs:16
XCharts.Axis.AxisType
AxisType
the type of axis. 坐标轴类型。
Definition: Axis.cs:26
XCharts.CoordinateChart
The basic class of rectangular coordinate chart,such as LineChart,BarChart and ScatterChart....
Definition: CoordinateChart_API.cs:18