AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
LineStyle.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 
9 using UnityEngine;
10 
11 namespace XCharts
12 {
19  [System.Serializable]
20  public class LineStyle : SubComponent
21  {
25  public enum Type
26  {
30  Solid,
34  Dashed,
38  Dotted,
42  DashDot,
46  DashDotDot,
47  None,
48  }
49  [SerializeField] private bool m_Show = true;
50  [SerializeField] private Type m_Type = Type.Solid;
51  [SerializeField] private Color32 m_Color;
52  [SerializeField] private Color32 m_ToColor;
53  [SerializeField] private Color32 m_ToColor2;
54  [SerializeField] private float m_Width = 0;
55  [SerializeField] private float m_Length = 0;
56  [SerializeField] [Range(0, 1)] private float m_Opacity = 1;
57 
62  public bool show
63  {
64  get { return m_Show; }
65  set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
66  }
71  public Type type
72  {
73  get { return m_Type; }
74  set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
75  }
80  public Color32 color
81  {
82  get { return m_Color; }
83  set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
84  }
89  public Color32 toColor
90  {
91  get { return m_ToColor; }
92  set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
93  }
98  public Color32 toColor2
99  {
100  get { return m_ToColor2; }
101  set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
102  }
107  public float width
108  {
109  get { return m_Width; }
110  set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
111  }
116  public float length
117  {
118  get { return m_Length; }
119  set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
120  }
125  public float opacity
126  {
127  get { return m_Opacity; }
128  set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
129  }
130 
131  public LineStyle()
132  {
133  }
134 
135  public LineStyle(float width)
136  {
137  this.width = width;
138  }
139 
140  public LineStyle(LineStyle.Type type)
141  {
142  this.type = type;
143  }
144 
145  public LineStyle(LineStyle.Type type, float width)
146  {
147  this.type = type;
148  this.width = width;
149  }
150 
151  public LineStyle Clone()
152  {
153  var lineStyle = new LineStyle();
154  lineStyle.show = show;
155  lineStyle.type = type;
156  lineStyle.color = color;
157  lineStyle.toColor = toColor;
158  lineStyle.toColor2 = toColor2;
159  lineStyle.width = width;
160  lineStyle.opacity = opacity;
161  return lineStyle;
162  }
163 
164  public void Copy(LineStyle lineStyle)
165  {
166  show = lineStyle.show;
167  type = lineStyle.type;
168  color = lineStyle.color;
169  toColor = lineStyle.toColor;
170  toColor2 = lineStyle.toColor2;
171  width = lineStyle.width;
172  opacity = lineStyle.opacity;
173  }
174 
175  public Color32 GetColor()
176  {
177  if (m_Opacity == 1) return m_Color;
178  var color = m_Color;
179  color.a = (byte)(color.a * m_Opacity);
180  return color;
181  }
182 
183  public bool IsNeedGradient()
184  {
185  return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
186  }
187 
188  public Color32 GetGradientColor(float value, Color32 defaultColor)
189  {
190  var color = ChartConst.clearColor32;
191  if (!IsNeedGradient()) return color;
192  value = Mathf.Clamp01(value);
193  var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
194  if (!ChartHelper.IsClearColor(m_ToColor2))
195  {
196  if (value <= 0.5f) color = Color32.Lerp(startColor, m_ToColor, 2 * value);
197  else color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
198  }
199  else
200  {
201  color = Color32.Lerp(startColor, m_ToColor, value);
202  }
203  if (m_Opacity != 1)
204  {
205  color.a = (byte)(color.a * m_Opacity);
206  }
207  return color;
208  }
209 
210  public Type GetType(Type themeType)
211  {
212  return type == Type.None ? themeType : type;
213  }
214 
215  public float GetWidth(float themeWidth)
216  {
217  return width == 0 ? themeWidth : width;
218  }
219 
220  public float GetLength(float themeLength)
221  {
222  return length == 0 ? themeLength : length;
223  }
224 
225  public Color32 GetColor(Color32 themeColor)
226  {
227  if (!ChartHelper.IsClearColor(color))
228  {
229  return GetColor();
230  }
231  else
232  {
233  var color = themeColor;
234  color.a = (byte)(color.a * opacity);
235  return color;
236  }
237  }
238  }
239 }
XCharts.LineStyle.opacity
float opacity
Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0....
Definition: LineStyle.cs:126
XCharts.LineStyle.toColor2
Color32 toColor2
the end color of line, default use serie color. 线的渐变颜色2(需要水平方向三个渐变色的渐变时)。
Definition: LineStyle.cs:99
XCharts.LineStyle.show
bool show
Whether show line. 是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
Definition: LineStyle.cs:63
XCharts.LineStyle.Type
Type
线的类型。
Definition: LineStyle.cs:25
XCharts.RoseType.None
@ None
Don't show as Nightingale chart.不展示成南丁格尔玫瑰图
XCharts.SubComponent
Definition: ChartComponent.cs:71
XCharts.LineType.DashDotDot
@ DashDotDot
双点划线
XCharts
Definition: RewardChart.cs:14
XCharts.LineStyle.width
float width
the width of line. 线宽。 ///
Definition: LineStyle.cs:108
XCharts.LineStyle
The style of line. 线条样式。 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle....
Definition: LineStyle.cs:20
XCharts.LineStyle.color
Color32 color
the color of line, default use serie color. 线的颜色。
Definition: LineStyle.cs:81
XCharts.LineType.DashDot
@ DashDot
点划线
XCharts.LineStyle.length
float length
the length of line. 线长。 ///
Definition: LineStyle.cs:117
XCharts.LineStyle.toColor
Color32 toColor
the middle color of line, default use serie color. 线的渐变颜色(需要水平方向渐变时)。
Definition: LineStyle.cs:90
XCharts.LineStyle.type
Type type
the type of line. 线的类型。
Definition: LineStyle.cs:72