AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
ItemStyle.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System;
9 using System.Collections.Generic;
10 using UnityEngine;
11 
12 namespace XCharts
13 {
17  [System.Serializable]
18  public class ItemStyle : SubComponent
19  {
23  public enum Type
24  {
28  Solid,
32  Dashed,
36  Dotted
37  }
38  [SerializeField] private bool m_Show = false;
39  [SerializeField] private Color32 m_Color;
40  [SerializeField] private Color32 m_Color0;
41  [SerializeField] private Color32 m_ToColor;
42  [SerializeField] private Color32 m_ToColor2;
43  [SerializeField] private Color32 m_BackgroundColor;
44  [SerializeField] private float m_BackgroundWidth;
45  [SerializeField] private Color32 m_CenterColor;
46  [SerializeField] private float m_CenterGap;
47  [SerializeField] private Type m_BorderType = Type.Solid;
48  [SerializeField] private float m_BorderWidth = 0;
49  [SerializeField] private Color32 m_BorderColor;
50  [SerializeField] private Color32 m_BorderColor0;
51  [SerializeField] private Color32 m_BorderToColor;
52  [SerializeField] [Range(0, 1)] private float m_Opacity = 1;
53  [SerializeField] private string m_TooltipFormatter;
54  [SerializeField] private string m_NumericFormatter = "";
55  [SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
56 
57  public void Reset()
58  {
59  m_Show = false;
60  m_Color = Color.clear;
61  m_Color0 = Color.clear;
62  m_ToColor = Color.clear;
63  m_ToColor2 = Color.clear;
64  m_BackgroundColor = Color.clear;
65  m_BackgroundWidth = 0;
66  m_CenterColor = Color.clear;
67  m_CenterGap = 0;
68  m_BorderType = Type.Solid;
69  m_BorderWidth = 0;
70  m_BorderColor = Color.clear;
71  m_BorderColor0 = Color.clear;
72  m_BorderToColor = Color.clear;
73  m_Opacity = 1;
74  m_TooltipFormatter = null;
75  m_NumericFormatter = "";
76  if (m_CornerRadius == null)
77  {
78  m_CornerRadius = new float[] { 0, 0, 0, 0 };
79  }
80  else
81  {
82  for (int i = 0; i < m_CornerRadius.Length; i++)
83  m_CornerRadius[i] = 0;
84  }
85  }
86 
90  public bool show
91  {
92  get { return m_Show; }
93  set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
94  }
98  public Color32 color
99  {
100  get { return m_Color; }
101  set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
102  }
106  public Color32 color0
107  {
108  get { return m_Color0; }
109  set { if (PropertyUtil.SetColor(ref m_Color0, value)) SetVerticesDirty(); }
110  }
115  public Color32 toColor
116  {
117  get { return m_ToColor; }
118  set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
119  }
124  public Color32 toColor2
125  {
126  get { return m_ToColor2; }
127  set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
128  }
132  public Color32 backgroundColor
133  {
134  get { return m_BackgroundColor; }
135  set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
136  }
140  public Color32 centerColor
141  {
142  get { return m_CenterColor; }
143  set { if (PropertyUtil.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
144  }
148  public float centerGap
149  {
150  get { return m_CenterGap; }
151  set { if (PropertyUtil.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
152  }
156  public float backgroundWidth
157  {
158  get { return m_BackgroundWidth; }
159  set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
160  }
164  public Type borderType
165  {
166  get { return m_BorderType; }
167  set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
168  }
172  public Color32 borderColor
173  {
174  get { return m_BorderColor; }
175  set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
176  }
180  public Color32 borderColor0
181  {
182  get { return m_BorderColor0; }
183  set { if (PropertyUtil.SetColor(ref m_BorderColor0, value)) SetVerticesDirty(); }
184  }
188  public Color32 borderToColor
189  {
190  get { return m_BorderToColor; }
191  set { if (PropertyUtil.SetColor(ref m_BorderToColor, value)) SetVerticesDirty(); }
192  }
196  public float borderWidth
197  {
198  get { return m_BorderWidth; }
199  set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
200  }
204  public float opacity
205  {
206  get { return m_Opacity; }
207  set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
208  }
212  public string tooltipFormatter
213  {
214  get { return m_TooltipFormatter; }
215  set { if (PropertyUtil.SetClass(ref m_TooltipFormatter, value)) SetVerticesDirty(); }
216  }
224  public string numericFormatter
225  {
226  get { return m_NumericFormatter; }
227  set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
228  }
233  public float[] cornerRadius
234  {
235  get { return m_CornerRadius; }
236  set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); }
237  }
241  public float runtimeBorderWidth { get { return NeedShowBorder() ? borderWidth : 0; } }
242 
246  public bool NeedShowBorder()
247  {
248  return borderWidth != 0 && !ChartHelper.IsClearColor(borderColor);
249  }
250 
251  public Color32 GetColor()
252  {
253  if (m_Opacity == 1 || m_Color.a == 0) return m_Color;
254  var color = m_Color;
255  color.a = (byte)(color.a * m_Opacity);
256  return color;
257  }
258  public Color32 GetColor0()
259  {
260  if (m_Opacity == 1 || m_Color0.a == 0) return m_Color0;
261  var color = m_Color0;
262  color.a = (byte)(color.a * m_Opacity);
263  return color;
264  }
265  public Color32 GetColor(Color32 defaultColor)
266  {
267  var color = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
268  if (m_Opacity == 1 || color.a == 0) return color;
269  color.a = (byte)(color.a * m_Opacity);
270  return color;
271  }
272  public Color32 GetColor0(Color32 defaultColor)
273  {
274  var color = ChartHelper.IsClearColor(m_Color0) ? defaultColor : m_Color0;
275  if (m_Opacity == 1 || color.a == 0) return color;
276  color.a = (byte)(color.a * m_Opacity);
277  return color;
278  }
279  public Color32 GetBorderColor(Color32 defaultColor)
280  {
281  var color = ChartHelper.IsClearColor(m_BorderColor) ? defaultColor : m_BorderColor;
282  if (m_Opacity == 1 || color.a == 0) return color;
283  color.a = (byte)(color.a * m_Opacity);
284  return color;
285  }
286  public Color32 GetBorderColor0(Color32 defaultColor)
287  {
288  var color = ChartHelper.IsClearColor(m_BorderColor0) ? defaultColor : m_BorderColor0;
289  if (m_Opacity == 1 || color.a == 0) return color;
290  color.a = (byte)(color.a * m_Opacity);
291  return color;
292  }
293 
294  public bool IsNeedGradient()
295  {
296  return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
297  }
298 
299  public Color32 GetGradientColor(float value, Color32 defaultColor)
300  {
301  if (!IsNeedGradient()) return ChartConst.clearColor32;
302  value = Mathf.Clamp01(value);
303  var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
304  Color32 color;
305  if (!ChartHelper.IsClearColor(m_ToColor2))
306  {
307  if (value <= 0.5f) color = Color32.Lerp(startColor, m_ToColor, 2 * value);
308  else color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
309  }
310  else
311  {
312  color = Color32.Lerp(startColor, m_ToColor, value);
313  }
314  if (m_Opacity != 1)
315  {
316  color.a = (byte)(color.a * m_Opacity);
317  }
318  return color;
319  }
320  }
321 }
XCharts.ItemStyle.borderColor0
Color32 borderColor0
边框的颜色。
Definition: ItemStyle.cs:181
XCharts.ItemStyle.Type
Type
线的类型。
Definition: ItemStyle.cs:23
XCharts.ItemStyle.color
Color32 color
数据项颜色。
Definition: ItemStyle.cs:99
XCharts.ItemStyle.toColor
Color32 toColor
Gradient color1. 渐变色的颜色1。
Definition: ItemStyle.cs:116
XCharts.ItemStyle.color0
Color32 color0
数据项颜色。
Definition: ItemStyle.cs:107
XCharts.ItemStyle.borderColor
Color32 borderColor
边框的颜色。
Definition: ItemStyle.cs:173
XCharts.ItemStyle.borderType
Type borderType
边框的类型。
Definition: ItemStyle.cs:165
XCharts.ItemStyle.NeedShowBorder
bool NeedShowBorder()
是否需要显示边框。
Definition: ItemStyle.cs:246
XCharts.ItemStyle.centerColor
Color32 centerColor
中心区域颜色。
Definition: ItemStyle.cs:141
XCharts.SubComponent
Definition: ChartComponent.cs:71
XCharts.ItemStyle.show
bool show
是否启用。
Definition: ItemStyle.cs:91
XCharts
Definition: RewardChart.cs:14
XCharts.ItemStyle.backgroundColor
Color32 backgroundColor
数据项背景颜色。
Definition: ItemStyle.cs:133
XCharts.ItemStyle.centerGap
float centerGap
中心区域间隙。
Definition: ItemStyle.cs:149
XCharts.ItemStyle.borderWidth
float borderWidth
边框宽。
Definition: ItemStyle.cs:197
XCharts.ItemStyle.opacity
float opacity
透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
Definition: ItemStyle.cs:205
XCharts.ItemStyle.numericFormatter
string numericFormatter
Standard numeric format strings. 标准数字格式字符串。用于将数值格式化显示为字符串。 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G...
Definition: ItemStyle.cs:225
XCharts.ItemStyle.toColor2
Color32 toColor2
Gradient color2.Only valid in line diagrams. 渐变色的颜色2。只在折线图中有效。
Definition: ItemStyle.cs:125
XCharts.ItemStyle.borderToColor
Color32 borderToColor
边框的渐变色。
Definition: ItemStyle.cs:189
XCharts.ItemStyle
图形样式。
Definition: ItemStyle.cs:18
XCharts.ItemStyle.backgroundWidth
float backgroundWidth
数据项背景宽度。
Definition: ItemStyle.cs:157
XCharts.ItemStyle.runtimeBorderWidth
float? runtimeBorderWidth
实际边框宽。边框不显示时为0。
Definition: ItemStyle.cs:241
XCharts.ItemStyle.cornerRadius
float[] cornerRadius
The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses...
Definition: ItemStyle.cs:234
XCharts.ItemStyle.tooltipFormatter
string tooltipFormatter
提示框单项的字符串模版格式器。具体配置参考Tooltip的formatter
Definition: ItemStyle.cs:213