2019-10-22 04:09:04 +08:00
|
|
|
|
|
2019-08-04 15:24:31 +08:00
|
|
|
|
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2022-02-19 22:37:57 +08:00
|
|
|
|
namespace XCharts.Runtime
|
2019-08-04 15:24:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The style of line.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线条样式。
|
2020-08-29 23:35:40 +08:00
|
|
|
|
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color,线条颜色默认也会取该颜色。
|
|
|
|
|
|
/// toColor,toColor2可设置水平方向的渐变,如需要设置垂直方向的渐变,可使用VisualMap。
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[System.Serializable]
|
2022-01-22 21:08:26 +08:00
|
|
|
|
public class LineStyle : ChildComponent, ISerieDataComponent
|
2019-08-04 15:24:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 线的类型。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum Type
|
|
|
|
|
|
{
|
2019-09-18 18:23:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 实线
|
|
|
|
|
|
/// </summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
Solid,
|
2019-09-18 18:23:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 虚线
|
|
|
|
|
|
/// </summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
Dashed,
|
2019-09-18 18:23:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 点线
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Dotted,
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 点划线
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
DashDot,
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 双点划线
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
DashDotDot,
|
2021-01-11 08:54:28 +08:00
|
|
|
|
None,
|
2019-08-04 15:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
[SerializeField] private bool m_Show = true;
|
|
|
|
|
|
[SerializeField] private Type m_Type = Type.Solid;
|
2020-08-23 14:31:26 +08:00
|
|
|
|
[SerializeField] private Color32 m_Color;
|
2020-08-29 23:35:40 +08:00
|
|
|
|
[SerializeField] private Color32 m_ToColor;
|
|
|
|
|
|
[SerializeField] private Color32 m_ToColor2;
|
2021-01-11 08:54:28 +08:00
|
|
|
|
[SerializeField] private float m_Width = 0;
|
|
|
|
|
|
[SerializeField] private float m_Length = 0;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-25 09:44:53 +08:00
|
|
|
|
/// Whether show line.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public bool show
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Show; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the type of line.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线的类型。
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public Type type
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Type; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the color of line, default use serie color.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线的颜色。
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// </summary>
|
2020-08-23 14:31:26 +08:00
|
|
|
|
public Color32 color
|
2020-03-05 20:25:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
get { return m_Color; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
2020-08-29 23:35:40 +08:00
|
|
|
|
/// the middle color of line, default use serie color.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线的渐变颜色(需要水平方向渐变时)。
|
2020-08-29 23:35:40 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Color32 toColor
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_ToColor; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
|
2020-08-29 23:35:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the end color of line, default use serie color.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线的渐变颜色2(需要水平方向三个渐变色的渐变时)。
|
2020-08-29 23:35:40 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Color32 toColor2
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_ToColor2; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
|
2020-08-29 23:35:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// the width of line.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线宽。
|
2020-03-05 20:25:19 +08:00
|
|
|
|
/// /// </summary>
|
|
|
|
|
|
public float width
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Width; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the length of line.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线长。
|
2021-01-11 08:54:28 +08:00
|
|
|
|
/// /// </summary>
|
|
|
|
|
|
public float length
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Length; }
|
|
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0.
|
2022-03-24 08:37:06 +08:00
|
|
|
|
/// |线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float opacity
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Opacity; }
|
2021-01-11 08:54:28 +08:00
|
|
|
|
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
|
2020-03-05 20:25:19 +08:00
|
|
|
|
}
|
2020-02-11 20:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
public LineStyle()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LineStyle(float width)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.width = width;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
|
public LineStyle(LineStyle.Type type)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.type = type;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-11 20:37:34 +08:00
|
|
|
|
public LineStyle(LineStyle.Type type, float width)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.type = type;
|
|
|
|
|
|
this.width = width;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-18 12:31:21 +08:00
|
|
|
|
public LineStyle Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
var lineStyle = new LineStyle();
|
|
|
|
|
|
lineStyle.show = show;
|
|
|
|
|
|
lineStyle.type = type;
|
|
|
|
|
|
lineStyle.color = color;
|
2020-08-29 23:35:40 +08:00
|
|
|
|
lineStyle.toColor = toColor;
|
|
|
|
|
|
lineStyle.toColor2 = toColor2;
|
2020-04-18 12:31:21 +08:00
|
|
|
|
lineStyle.width = width;
|
|
|
|
|
|
lineStyle.opacity = opacity;
|
|
|
|
|
|
return lineStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Copy(LineStyle lineStyle)
|
|
|
|
|
|
{
|
|
|
|
|
|
show = lineStyle.show;
|
|
|
|
|
|
type = lineStyle.type;
|
|
|
|
|
|
color = lineStyle.color;
|
2020-08-29 23:35:40 +08:00
|
|
|
|
toColor = lineStyle.toColor;
|
|
|
|
|
|
toColor2 = lineStyle.toColor2;
|
2020-04-18 12:31:21 +08:00
|
|
|
|
width = lineStyle.width;
|
|
|
|
|
|
opacity = lineStyle.opacity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-23 14:31:26 +08:00
|
|
|
|
public Color32 GetColor()
|
2020-02-11 20:37:34 +08:00
|
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
|
if (m_Opacity == 1)
|
|
|
|
|
|
return m_Color;
|
|
|
|
|
|
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var color = m_Color;
|
2020-09-13 20:32:41 +08:00
|
|
|
|
color.a = (byte)(color.a * m_Opacity);
|
2020-03-17 08:37:48 +08:00
|
|
|
|
return color;
|
2020-02-11 20:37:34 +08:00
|
|
|
|
}
|
2020-08-29 23:35:40 +08:00
|
|
|
|
|
|
|
|
|
|
public bool IsNeedGradient()
|
|
|
|
|
|
{
|
|
|
|
|
|
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Color32 GetGradientColor(float value, Color32 defaultColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
var color = ChartConst.clearColor32;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
if (!IsNeedGradient())
|
|
|
|
|
|
return color;
|
|
|
|
|
|
|
2020-08-29 23:35:40 +08:00
|
|
|
|
value = Mathf.Clamp01(value);
|
|
|
|
|
|
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
|
2020-08-29 23:35:40 +08:00
|
|
|
|
if (!ChartHelper.IsClearColor(m_ToColor2))
|
|
|
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
|
if (value <= 0.5f)
|
|
|
|
|
|
color = Color32.Lerp(startColor, m_ToColor, 2 * value);
|
|
|
|
|
|
else
|
|
|
|
|
|
color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
|
2020-08-29 23:35:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
color = Color32.Lerp(startColor, m_ToColor, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_Opacity != 1)
|
|
|
|
|
|
{
|
2020-09-13 20:32:41 +08:00
|
|
|
|
color.a = (byte)(color.a * m_Opacity);
|
2020-08-29 23:35:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
return color;
|
|
|
|
|
|
}
|
2021-01-11 08:54:28 +08:00
|
|
|
|
|
|
|
|
|
|
public Type GetType(Type themeType)
|
|
|
|
|
|
{
|
|
|
|
|
|
return type == Type.None ? themeType : type;
|
|
|
|
|
|
}
|
2021-11-23 13:20:07 +08:00
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
|
public float GetWidth(float themeWidth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return width == 0 ? themeWidth : width;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float GetLength(float themeLength)
|
|
|
|
|
|
{
|
|
|
|
|
|
return length == 0 ? themeLength : length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Color32 GetColor(Color32 themeColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ChartHelper.IsClearColor(color))
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetColor();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var color = themeColor;
|
|
|
|
|
|
color.a = (byte)(color.a * opacity);
|
|
|
|
|
|
return color;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|