AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
SerieLabel.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System;
9 using UnityEngine;
10 
11 namespace XCharts
12 {
17  [System.Serializable]
18  public class SerieLabel : SubComponent
19  {
24  public enum Position
25  {
30  Outside,
35  Inside,
40  Center,
45  Top,
50  Bottom,
55  Left,
60  Right,
65  Start,
70  Middle,
75  End
76  }
77 
81  public enum LineType
82  {
86  BrokenLine,
90  Curves,
94  HorizontalLine
95  }
96  [SerializeField] private bool m_Show = false;
97  [SerializeField] Position m_Position = Position.Outside;
98  [SerializeField] private Vector3 m_Offset;
99  [SerializeField] private float m_Margin;
100  [SerializeField] private string m_Formatter;
101  [SerializeField] private float m_PaddingLeftRight = 2f;
102  [SerializeField] private float m_PaddingTopBottom = 2f;
103  [SerializeField] private float m_BackgroundWidth = 0;
104  [SerializeField] private float m_BackgroundHeight = 0;
105  [SerializeField] private bool m_Line = true;
106  [SerializeField] private LineType m_LineType = LineType.BrokenLine;
107  [SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
108  [SerializeField] private float m_LineWidth = 1.0f;
109  [SerializeField] private float m_LineGap = 1.0f;
110  [SerializeField] private float m_LineLength1 = 25f;
111  [SerializeField] private float m_LineLength2 = 15f;
112  [SerializeField] private bool m_Border = false;
113  [SerializeField] private float m_BorderWidth = 0.5f;
114  [SerializeField] private Color32 m_BorderColor = ChartConst.greyColor32;
115  [SerializeField] private string m_NumericFormatter = "";
116  [SerializeField] private bool m_AutoOffset = false;
117  [SerializeField] private TextStyle m_TextStyle = new TextStyle();
118  private DelegateSerieLabelFormatter m_FormatterFunction;
119 
120  public void Reset()
121  {
122  m_Show = false;
123  m_Position = Position.Outside;
124  m_Offset = Vector3.zero;
125  m_Margin = 0;
126  m_PaddingLeftRight = 2f;
127  m_PaddingTopBottom = 2f;
128  m_BackgroundWidth = 0;
129  m_BackgroundHeight = 0;
130  m_Line = true;
131  m_LineType = LineType.BrokenLine;
132  m_LineColor = Color.clear;
133  m_LineWidth = 1.0f;
134  m_LineGap = 1.0f;
135  m_LineLength1 = 25f;
136  m_LineLength2 = 15f;
137  m_Border = false;
138  m_BorderWidth = 0.5f;
139  m_BorderColor = Color.grey;
140  m_NumericFormatter = "";
141  m_AutoOffset = false;
142  }
143 
148  public bool show
149  {
150  get { return m_Show; }
151  set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
152  }
157  public Position position
158  {
159  get { return m_Position; }
160  set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
161  }
175  public string formatter
176  {
177  get { return m_Formatter; }
178  set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
179  }
184  public Vector3 offset
185  {
186  get { return m_Offset; }
187  set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
188  }
192  public float margin
193  {
194  get { return m_Margin; }
195  set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
196  }
202  public float backgroundWidth
203  {
204  get { return m_BackgroundWidth; }
205  set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
206  }
212  public float backgroundHeight
213  {
214  get { return m_BackgroundHeight; }
215  set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
216  }
221  public float paddingLeftRight
222  {
223  get { return m_PaddingLeftRight; }
224  set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
225  }
230  public float paddingTopBottom
231  {
232  get { return m_PaddingTopBottom; }
233  set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
234  }
239  public bool line
240  {
241  get { return m_Line; }
242  set { if (PropertyUtil.SetStruct(ref m_Line, value)) SetComponentDirty(); }
243  }
248  public LineType lineType
249  {
250  get { return m_LineType; }
251  set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
252  }
257  public Color32 lineColor
258  {
259  get { return m_LineColor; }
260  set { if (PropertyUtil.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
261  }
266  public float lineWidth
267  {
268  get { return m_LineWidth; }
269  set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
270  }
275  public float lineGap
276  {
277  get { return m_LineGap; }
278  set { if (PropertyUtil.SetStruct(ref m_LineGap, value)) SetVerticesDirty(); }
279  }
284  public float lineLength1
285  {
286  get { return m_LineLength1; }
287  set { if (PropertyUtil.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
288  }
293  public float lineLength2
294  {
295  get { return m_LineLength2; }
296  set { if (PropertyUtil.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
297  }
302  public bool border
303  {
304  get { return m_Border; }
305  set { if (PropertyUtil.SetStruct(ref m_Border, value)) SetVerticesDirty(); }
306  }
311  public float borderWidth
312  {
313  get { return m_BorderWidth; }
314  set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
315  }
320  public Color32 borderColor
321  {
322  get { return m_BorderColor; }
323  set { if (PropertyUtil.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }
324  }
332  public string numericFormatter
333  {
334  get { return m_NumericFormatter; }
335  set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
336  }
340  public bool autoOffset
341  {
342  get { return m_AutoOffset; }
343  set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
344  }
345 
350  public TextStyle textStyle
351  {
352  get { return m_TextStyle; }
353  set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
354  }
355 
356  public DelegateSerieLabelFormatter formatterFunction
357  {
358  get { return m_FormatterFunction; }
359  set { m_FormatterFunction = value; }
360  }
361 
362  public bool IsInside()
363  {
364  return position == Position.Inside || position == Position.Center;
365  }
366 
367  public Color GetColor(Color defaultColor)
368  {
369  if (ChartHelper.IsClearColor(textStyle.color))
370  {
371  return IsInside() ? Color.black : defaultColor;
372  }
373  else
374  {
375  return textStyle.color;
376  }
377  }
378 
379  public TextAnchor GetAutoAlignment()
380  {
382  else
383  {
384  switch (position)
385  {
386  case SerieLabel.Position.Inside:
387  case SerieLabel.Position.Center:
388  case SerieLabel.Position.Top:
389  case SerieLabel.Position.Bottom:
390  return TextAnchor.MiddleCenter;
391  case SerieLabel.Position.Outside:
392  case SerieLabel.Position.Right:
393  return TextAnchor.MiddleLeft;
394  case SerieLabel.Position.Left:
395  return TextAnchor.MiddleRight;
396  default:
397  return TextAnchor.MiddleCenter;
398  }
399  }
400  }
401  }
402 }
XCharts.SerieLabel.position
Position position
The position of label. 标签的位置。
Definition: SerieLabel.cs:158
XCharts.SerieLabel.textStyle
TextStyle textStyle
the sytle of text. 文本样式。
Definition: SerieLabel.cs:351
XCharts.TextStyle
Settings related to text. 文本的相关设置。
Definition: TextStyle.cs:21
XCharts.SerieLabel.formatter
string formatter
标签内容字符串模版格式器。支持用 换行。 模板变量有: {a}:系列名。 {b}:数据名。 {c}:数据值。 {d}:百分比。
Definition: SerieLabel.cs:176
XCharts.SerieLabel.lineColor
Color32 lineColor
the color of visual guild line. 视觉引导线颜色。默认和serie一致取自调色板。
Definition: SerieLabel.cs:258
XCharts.LineType
LineType
the type of line chart. 折线图样式类型
Definition: Serie.cs:99
XCharts.SerieLabel.borderColor
Color32 borderColor
the color of border. 边框颜色。
Definition: SerieLabel.cs:321
XCharts.SubComponent
Definition: ChartComponent.cs:71
XCharts
Definition: RewardChart.cs:14
XCharts.SerieLabel.border
bool border
Whether to show border. 是否显示边框。
Definition: SerieLabel.cs:303
XCharts.SerieLabel.lineType
LineType lineType
the type of visual guide line. 视觉引导线类型。
Definition: SerieLabel.cs:249
XCharts.SerieLabel.borderWidth
float borderWidth
the width of border. 边框宽度。
Definition: SerieLabel.cs:312
XCharts.SerieLabel.lineWidth
float lineWidth
the width of visual guild line. 视觉引导线的宽度。
Definition: SerieLabel.cs:267
XCharts.DelegateSerieLabelFormatter
delegate string DelegateSerieLabelFormatter(int dataIndex, double value)
The delegate function for SerieLabel‘s formatter. SerieLabel的formatter自定义委托函数。
XCharts.SerieLabel.show
bool show
Whether the label is showed. 是否显示文本标签。
Definition: SerieLabel.cs:149
XCharts.SerieLabel.margin
float margin
距离轴线的距离。
Definition: SerieLabel.cs:193
XCharts.SerieLabel.offset
Vector3 offset
offset to the host graphic element. 距离图形元素的偏移
Definition: SerieLabel.cs:185
XCharts.SerieLabel.LineType
LineType
标签视觉引导线类型
Definition: SerieLabel.cs:81
XCharts.SerieLabel.paddingTopBottom
float paddingTopBottom
the text padding of top and bottom. defaut:2. 上下边距。
Definition: SerieLabel.cs:231
XCharts.SerieLabel
Text label of chart, to explain some data information about graphic item like value,...
Definition: SerieLabel.cs:18
XCharts.SerieLabel.autoOffset
bool autoOffset
是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
Definition: SerieLabel.cs:341
XCharts.SerieLabel.numericFormatter
string numericFormatter
Standard numeric format strings. 标准数字格式字符串。用于将数值格式化显示为字符串。 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G...
Definition: SerieLabel.cs:333
XCharts.SerieLabel.backgroundWidth
float backgroundWidth
the width of background. If set as default value 0, it means than the background width auto set as th...
Definition: SerieLabel.cs:203
XCharts.SerieLabel.lineLength1
float lineLength1
The length of the first segment of visual guide line. 视觉引导线第一段的长度。
Definition: SerieLabel.cs:285
XCharts.SerieLabel.backgroundHeight
float backgroundHeight
the height of background. If set as default value 0, it means than the background height auto set as ...
Definition: SerieLabel.cs:213
XCharts.TextStyle.color
Color color
the color of text. 文本的颜色。 [default: Color.clear]
Definition: TextStyle.cs:68
XCharts.SerieLabel.paddingLeftRight
float paddingLeftRight
the text padding of left and right. defaut:2. 左右边距。
Definition: SerieLabel.cs:222
XCharts.SerieLabel.lineGap
float lineGap
the gap of container and guild line. 视觉引导线和容器的间距。
Definition: SerieLabel.cs:276
XCharts.TextStyle.alignment
TextAnchor alignment
对齐方式。
Definition: TextStyle.cs:142
XCharts.TextStyle.autoAlign
bool autoAlign
文本是否让系统自动选对齐方式。为false时才会用alignment。
Definition: TextStyle.cs:134
XCharts.SerieLabel.Position
Position
The position of label. 标签的位置。
Definition: SerieLabel.cs:24
XCharts.SerieLabel.line
bool line
Whether to show visual guide line.Will show when label position is set as 'outside'....
Definition: SerieLabel.cs:240
XCharts.SerieLabel.lineLength2
float lineLength2
The length of the second segment of visual guide line. 视觉引导线第二段的长度。
Definition: SerieLabel.cs:294