AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Legend.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 {
19  [System.Serializable]
21  {
22  public enum Type
23  {
27  Auto,
31  Custom,
39  Circle,
43  Rect,
47  Triangle,
51  Diamond,
52  }
57  public enum SelectedMode
58  {
62  Multiple,
66  Single,
70  None
71  }
72  [SerializeField] private bool m_Show = true;
73  [SerializeField] private Type m_IconType;
74  [SerializeField] private SelectedMode m_SelectedMode;
75  [SerializeField] private Orient m_Orient = Orient.Horizonal;
76  [SerializeField] private Location m_Location = Location.defaultRight;
77  [SerializeField] private float m_ItemWidth = 25.0f;
78  [SerializeField] private float m_ItemHeight = 12.0f;
79  [SerializeField] private float m_ItemGap = 10f;
80  [SerializeField] private bool m_ItemAutoColor = true;
81  [SerializeField] private bool m_TextAutoColor = false;
82  [SerializeField] private string m_Formatter;
83  [SerializeField] private TextStyle m_TextStyle = new TextStyle();
84  [SerializeField] private List<string> m_Data = new List<string>();
85  [SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
86 
87  private Dictionary<string, LegendItem> m_DataBtnList = new Dictionary<string, LegendItem>();
88  private Dictionary<int, float> m_RuntimeEachWidth = new Dictionary<int, float>();
89 
94  public bool show
95  {
96  get { return m_Show; }
97  set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
98  }
104  public Type iconType
105  {
106  get { return m_IconType; }
107  set { if (PropertyUtil.SetStruct(ref m_IconType, value)) SetAllDirty(); }
108  }
115  {
116  get { return m_SelectedMode; }
117  set { if (PropertyUtil.SetStruct(ref m_SelectedMode, value)) SetComponentDirty(); }
118  }
124  public Orient orient
125  {
126  get { return m_Orient; }
127  set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetComponentDirty(); }
128  }
134  public Location location
135  {
136  get { return m_Location; }
137  set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); }
138  }
144  public float itemWidth
145  {
146  get { return m_ItemWidth; }
147  set { if (PropertyUtil.SetStruct(ref m_ItemWidth, value)) SetComponentDirty(); }
148  }
154  public float itemHeight
155  {
156  get { return m_ItemHeight; }
157  set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
158  }
164  public float itemGap
165  {
166  get { return m_ItemGap; }
167  set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); }
168  }
174  public bool itemAutoColor
175  {
176  get { return m_ItemAutoColor; }
177  set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
178  }
184  public bool textAutoColor
185  {
186  get { return m_TextAutoColor; }
187  set { if (PropertyUtil.SetStruct(ref m_TextAutoColor, value)) SetComponentDirty(); }
188  }
195  public string formatter
196  {
197  get { return m_Formatter; }
198  set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
199  }
204  public TextStyle textStyle
205  {
206  get { return m_TextStyle; }
207  set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
208  }
216  public List<string> data
217  {
218  get { return m_Data; }
219  set { if (value != null) { m_Data = value; SetComponentDirty(); } }
220  }
224  public List<Sprite> icons
225  {
226  get { return m_Icons; }
227  set { if (value != null) { m_Icons = value; SetComponentDirty(); } }
228  }
229  public int index { get; internal set; }
233  public override bool vertsDirty { get { return false; } }
237  public override bool componentDirty
238  {
239  get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty; }
240  }
241 
242  public override void ClearComponentDirty()
243  {
244  base.ClearComponentDirty();
245  location.ClearComponentDirty();
246  textStyle.ClearComponentDirty();
247  }
248 
254  public Dictionary<string, LegendItem> buttonList { get { return m_DataBtnList; } }
258  public float runtimeWidth { get; internal set; }
262  public float runtimeHeight { get; internal set; }
266  public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; } }
270  public float runtimeEachHeight { get; internal set; }
271 
275  public static Legend defaultLegend
276  {
277  get
278  {
279  var legend = new Legend
280  {
281  m_IconType = Type.Auto,
282  m_Show = false,
283  m_SelectedMode = SelectedMode.Multiple,
284  m_Orient = Orient.Horizonal,
285  m_Location = Location.defaultTop,
286  m_ItemWidth = 25.0f,
287  m_ItemHeight = 12.0f,
288  m_ItemGap = 10f,
289  };
290  legend.location.top = 35;
291  legend.textStyle.offset = new Vector2(2, 0);
292  legend.textStyle.fontSize = 0;
293  return legend;
294  }
295  }
296 
301  public void ClearData()
302  {
303  m_Data.Clear();
304  SetComponentDirty();
305  }
306 
313  public bool ContainsData(string name)
314  {
315  return m_Data.Contains(name);
316  }
317 
323  public void RemoveData(string name)
324  {
325  if (m_Data.Contains(name))
326  {
327  m_Data.Remove(name);
328  SetComponentDirty();
329  }
330  }
331 
337  public void AddData(string name)
338  {
339  if (!m_Data.Contains(name) && !string.IsNullOrEmpty(name))
340  {
341  m_Data.Add(name);
342  SetComponentDirty();
343  }
344  }
345 
352  public string GetData(int index)
353  {
354  if (index >= 0 && index < m_Data.Count)
355  {
356  return m_Data[index];
357  }
358  return null;
359  }
360 
367  public int GetIndex(string legendName)
368  {
369  return m_Data.IndexOf(legendName);
370  }
371 
376  public void RemoveButton()
377  {
378  m_DataBtnList.Clear();
379  }
380 
388  public void SetButton(string name, LegendItem item, int total)
389  {
390  m_DataBtnList[name] = item;
391  int index = m_DataBtnList.Values.Count;
392  item.SetIconActive(iconType == Type.Custom);
393  item.SetActive(show);
394  }
395 
402  public void UpdateButtonColor(string name, Color color)
403  {
404  if (m_DataBtnList.ContainsKey(name))
405  {
406  m_DataBtnList[name].SetIconColor(color);
407  }
408  }
409 
416  public void UpdateContentColor(string name, Color color)
417  {
418  if (m_DataBtnList.ContainsKey(name))
419  {
420  m_DataBtnList[name].SetContentColor(color);
421  }
422  }
423 
430  public Sprite GetIcon(int index)
431  {
432  if (index >= 0 && index < m_Icons.Count)
433  {
434  return m_Icons[index];
435  }
436  else
437  {
438  return null;
439  }
440  }
441 
446  public void OnChanged()
447  {
448  m_Location.OnChanged();
449  }
450 
456  public string GetFormatterContent(string category)
457  {
458  if (string.IsNullOrEmpty(m_Formatter))
459  return category;
460  else
461  {
462  var content = m_Formatter.Replace("{name}", category);
463  content = content.Replace("\\n", "\n");
464  content = content.Replace("<br/>", "\n");
465  return content;
466  }
467  }
468  }
469 }
XCharts.Orient
Orient
the layout is horizontal or vertical. 垂直还是水平布局方式。
Definition: BaseChart.cs:22
XCharts.Legend.icons
List< Sprite > icons
自定义的图例标记图形。
Definition: Legend.cs:225
XCharts.RadarType.Single
@ Single
单圈雷达图。此时一个雷达只能绘制一个圈,多个serieData组成一个圈,数据取自data[1]。
XCharts.Legend.SelectedMode
SelectedMode
Selected mode of legend, which controls whether series can be toggled displaying by clicking legends....
Definition: Legend.cs:57
XCharts.SerieType.Custom
@ Custom
自定义。
XCharts.Legend.data
List< string > data
Data array of legend. An array item is usually a name representing string. (If it is a pie chart,...
Definition: Legend.cs:217
XCharts.RadarType.Multiple
@ Multiple
多圈雷达图。此时可一个雷达里绘制多个圈,一个serieData就可组成一个圈(多维数据)。
XCharts.Legend.GetData
string GetData(int index)
Gets the legend for the specified index. 获得指定索引的图例。
Definition: Legend.cs:352
XCharts.Legend.UpdateButtonColor
void UpdateButtonColor(string name, Color color)
Update the legend button color. 更新图例按钮颜色。
Definition: Legend.cs:402
XCharts.IPropertyChanged
属性变更接口
Definition: IPropertyChanged.cs:13
XCharts.Legend.runtimeEachWidth
Dictionary< int, float > runtimeEachWidth
多列时每列的宽度
Definition: Legend.cs:266
XCharts.LegendItem
Definition: LegendItem.cs:13
XCharts.Legend.componentDirty
override bool componentDirty
组件是否需要刷新
Definition: Legend.cs:238
XCharts.Legend.runtimeWidth
float runtimeWidth
运行时图例的总宽度
Definition: Legend.cs:258
XCharts.Location
Location type. Quick to set the general location. 位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置...
Definition: Location.cs:21
XCharts.Legend.Type
Type
Definition: Legend.cs:22
XCharts.SerieSymbolType.Circle
@ Circle
圆形。
XCharts.Legend.GetFormatterContent
string GetFormatterContent(string category)
获得图例格式化后的显示内容。
Definition: Legend.cs:456
XCharts.Legend.ClearData
void ClearData()
Clear legend data. 清空。
Definition: Legend.cs:301
XCharts.Legend.itemGap
float itemGap
The distance between each legend, horizontal distance in horizontal layout, and vertical distance in ...
Definition: Legend.cs:165
XCharts.MainComponent
Definition: ChartComponent.cs:67
XCharts.Legend.ContainsData
bool ContainsData(string name)
Whether include in legend data by the specified name. 是否包括由指定名字的图例
Definition: Legend.cs:313
XCharts.TextStyle
Settings related to text. 文本的相关设置。
Definition: TextStyle.cs:21
XCharts.Legend.textAutoColor
bool textAutoColor
Whether the legend text matches the color automatically. 图例标记的文本是否自动匹配颜色。 [default:false]
Definition: Legend.cs:185
XCharts.RoseType.None
@ None
Don't show as Nightingale chart.不展示成南丁格尔玫瑰图
XCharts.ChartComponent.componentDirty
virtual bool componentDirty
组件重新初始化标记。
Definition: ChartComponent.cs:25
XCharts.Legend
Legend component.The legend component shows different sets of tags, colors, and names....
Definition: Legend.cs:20
XCharts
Definition: RewardChart.cs:14
XCharts.Legend.AddData
void AddData(string name)
Add legend data. 添加图例。
Definition: Legend.cs:337
XCharts.Legend.selectedMode
SelectedMode selectedMode
Selected mode of legend, which controls whether series can be toggled displaying by clicking legends....
Definition: Legend.cs:115
XCharts.Legend.show
bool show
Whether to show legend component. 是否显示图例组件。
Definition: Legend.cs:95
XCharts.Legend.location
Location location
The location of legend. 图例显示的位置。 [default:Location.defaultTop]
Definition: Legend.cs:135
XCharts.SerieSymbolType.Diamond
@ Diamond
菱形。
XCharts.Location.top
float top
Distance between component and the left side of the container. 离容器上侧的距离。
Definition: Location.cs:84
XCharts.Legend.orient
Orient orient
Specify whether the layout of legend component is horizontal or vertical. 布局方式是横还是竖。 [default:Orient....
Definition: Legend.cs:125
XCharts.Legend.defaultLegend
static Legend defaultLegend
一个在顶部居中显示的默认图例。
Definition: Legend.cs:276
XCharts.Location.OnChanged
void OnChanged()
属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
Definition: Location.cs:313
XCharts.Legend.buttonList
Dictionary< string, LegendItem > buttonList
the button list of legend. 图例按钮列表。
Definition: Legend.cs:254
XCharts.Legend.formatter
string formatter
Legend content string template formatter. Support for wrapping lines with . Template:{name}....
Definition: Legend.cs:196
XCharts.Legend.itemHeight
float itemHeight
Image height of legend symbol. 图例标记的图形高度。 [default:12f]
Definition: Legend.cs:155
XCharts.SerieSymbolType.Triangle
@ Triangle
三角形。
XCharts.Legend.OnChanged
void OnChanged()
Callback handling when parameters change. 参数变更时的回调处理。
Definition: Legend.cs:446
XCharts.Legend.runtimeHeight
float runtimeHeight
运行时图例的总高度
Definition: Legend.cs:262
XCharts.SerieSymbolType.Rect
@ Rect
正方形。可通过设置itemStyle的cornerRadius变成圆角矩形。
XCharts.Legend.itemAutoColor
bool itemAutoColor
Whether the legend symbol matches the color automatically. 图例标记的图形是否自动匹配颜色。 [default:true]
Definition: Legend.cs:175
XCharts.Legend.RemoveData
void RemoveData(string name)
Removes the legend with the specified name. 移除指定名字的图例。
Definition: Legend.cs:323
XCharts.Legend.SetButton
void SetButton(string name, LegendItem item, int total)
Bind buttons to legends. 给图例绑定按钮。
Definition: Legend.cs:388
XCharts.SerieSymbolType.EmptyCircle
@ EmptyCircle
空心圆。
XCharts.Legend.RemoveButton
void RemoveButton()
Remove all legend buttons. 移除所有图例按钮。
Definition: Legend.cs:376
XCharts.Legend.GetIndex
int GetIndex(string legendName)
Gets the index of the specified legend. 获得指定图例的索引。
Definition: Legend.cs:367
XCharts.Legend.UpdateContentColor
void UpdateContentColor(string name, Color color)
Update the text color of legend. 更新图例文字颜色。
Definition: Legend.cs:416
XCharts.Legend.iconType
Type iconType
Type of legend. 图例类型。 [default:Type.Auto]
Definition: Legend.cs:105
XCharts.Legend.GetIcon
Sprite GetIcon(int index)
Gets the legend button for the specified index. 获得指定索引的图例按钮。
Definition: Legend.cs:430
XCharts.Legend.runtimeEachHeight
float runtimeEachHeight
单列高度
Definition: Legend.cs:270
XCharts.Legend.itemWidth
float itemWidth
Image width of legend symbol. 图例标记的图形宽度。 [default:24f]
Definition: Legend.cs:145
XCharts.Legend.textStyle
TextStyle textStyle
the style of text. 文本样式。
Definition: Legend.cs:205
XCharts.Legend.vertsDirty
override bool vertsDirty
图表是否需要刷新(图例组件不需要刷新图表)
Definition: Legend.cs:233