AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
HeatmapChart.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System.Collections.Generic;
9 using UnityEngine;
10 
11 namespace XCharts
12 {
13  [AddComponentMenu("XCharts/HeatmapChart", 18)]
14  [ExecuteInEditMode]
15  [RequireComponent(typeof(RectTransform))]
16  [DisallowMultipleComponent]
18  {
19 
20 #if UNITY_EDITOR
21  protected override void Reset()
22  {
23  base.Reset();
24  title.text = "HeatmapChart";
25  tooltip.type = Tooltip.Type.None;
26  grid.left = 100;
27  grid.right = 60;
28  grid.bottom = 60;
29 
30  m_XAxes[0].type = Axis.AxisType.Category;
31  m_XAxes[0].boundaryGap = true;
32  m_YAxes[0].type = Axis.AxisType.Category;
33  m_YAxes[0].boundaryGap = true;
34  m_XAxes[0].splitNumber = 10;
35  m_YAxes[0].splitNumber = 10;
36  RemoveData();
37  var heatmapGridWid = 10f;
38  int xSplitNumber = (int)(grid.runtimeWidth / heatmapGridWid);
39  int ySplitNumber = (int)(grid.runtimeHeight / heatmapGridWid);
40 
41  SerieTemplate.AddDefaultHeatmapSerie(this, "serie1");
42 
43  visualMap.enable = true;
44  visualMap.max = 10;
45  visualMap.range[0] = 0f;
46  visualMap.range[1] = 10f;
47  visualMap.orient = Orient.Vertical;
48  visualMap.calculable = true;
49  visualMap.location.align = Location.Align.BottomLeft;
50  visualMap.location.bottom = 100;
51  visualMap.location.left = 30;
52  var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
53  "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
54  visualMap.inRange.Clear();
55  foreach (var str in colors)
56  {
57  visualMap.inRange.Add(ChartTheme.GetColor(str));
58  }
59  for (int i = 0; i < xSplitNumber; i++)
60  {
61  m_XAxes[0].data.Add((i + 1).ToString());
62  }
63  for (int i = 0; i < ySplitNumber; i++)
64  {
65  m_YAxes[0].data.Add((i + 1).ToString());
66  }
67  for (int i = 0; i < xSplitNumber; i++)
68  {
69  for (int j = 0; j < ySplitNumber; j++)
70  {
71  var value = 0f;
72  var rate = Random.Range(0, 101);
73  if (rate > 70) value = Random.Range(8f, 10f);
74  else value = Random.Range(1f, 8f);
75  var list = new List<double> { i, j, value };
76  AddData(0, list);
77  }
78  }
79  }
80 #endif
81 
82  protected override void UpdateTooltip()
83  {
84  var xData = tooltip.runtimeXValues[0];
85  var yData = tooltip.runtimeYValues[0];
86  if (IsCategory() && (xData < 0 || yData < 0)) return;
87  sb.Length = 0;
88  for (int i = 0; i < m_Series.Count; i++)
89  {
90  var serie = m_Series.GetSerie(i);
91  var xAxis = m_XAxes[serie.xAxisIndex];
92  var yAxis = m_YAxes[serie.yAxisIndex];
93  var xCount = xAxis.data.Count;
94  var yCount = yAxis.data.Count;
95  if (serie.show && serie.type == SerieType.Heatmap)
96  {
97  if (IsCategory())
98  {
99  string key = serie.name;
100  var serieData = serie.data[(int)xData * yCount + (int)yData];
101  var value = serieData.data[2];
102  var color = visualMap.enable ? visualMap.GetColor(value) :
103  m_Theme.GetColor(serie.index);
104  sb.Append("\n")
105  .Append(key).Append(!string.IsNullOrEmpty(key) ? "\n" : "")
106  .Append("<color=#").Append(ChartCached.ColorToStr(color)).Append(">● </color>")
107  .Append(xAxis.data[(int)xData]).Append(": ")
108  .Append(ChartCached.FloatToStr(value, string.Empty));
109  }
110  }
111  }
112  TooltipHelper.SetContentAndPosition(tooltip, sb.ToString().Trim(), chartRect);
113  tooltip.SetActive(true);
114 
115  for (int i = 0; i < m_XAxes.Count; i++)
116  {
117  UpdateAxisTooltipLabel(i, m_XAxes[i]);
118  }
119  for (int i = 0; i < m_YAxes.Count; i++)
120  {
121  UpdateAxisTooltipLabel(i, m_YAxes[i]);
122  }
123  }
124  }
125 }
XCharts.Orient
Orient
the layout is horizontal or vertical. 垂直还是水平布局方式。
Definition: BaseChart.cs:22
XCharts.Tooltip.Type
Type
Indicator type. 指示器类型。
Definition: Tooltip.cs:25
XCharts.Tooltip
Tooltip component. 提示框组件。
Definition: Tooltip.cs:19
XCharts.Location.Align
Align
对齐方式
Definition: Location.cs:26
XCharts.Location
Location type. Quick to set the general location. 位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置...
Definition: Location.cs:21
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.HeatmapChart
Definition: HeatmapChart.cs:17
XCharts.ChartTheme.GetColor
Color32 GetColor(int index)
Gets the color of the specified index from the palette. 获得调色盘对应系列索引的颜色值。
Definition: ChartTheme.cs:221
XCharts.Grid.bottom
float bottom
Distance between grid component and the bottom side of the container. grid 组件离容器下侧的距离。
Definition: XGrid.cs:75
XCharts
Definition: RewardChart.cs:14
XCharts.Axis
The axis in rectangular coordinate. 直角坐标系的坐标轴组件。
Definition: Axis.cs:20
XCharts.Grid.left
float left
Distance between grid component and the left side of the container. grid 组件离容器左侧的距离。
Definition: XGrid.cs:48
XCharts.Grid.right
float right
Distance between grid component and the right side of the container. grid 组件离容器右侧的距离。
Definition: XGrid.cs:57
XCharts.ChartTheme
Theme. 主题相关配置。
Definition: ChartTheme.cs:46
XCharts.CoordinateChart.IsCategory
bool IsCategory()
纯类目轴。
Definition: CoordinateChart_API.cs:238
XCharts.Axis.AxisType
AxisType
the type of axis. 坐标轴类型。
Definition: Axis.cs:26
XCharts.CoordinateChart.grid
Grid? grid
grid component. 网格组件。
Definition: CoordinateChart_API.cs:24
XCharts.CoordinateChart
The basic class of rectangular coordinate chart,such as LineChart,BarChart and ScatterChart....
Definition: CoordinateChart_API.cs:18