mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
增加LineStyle的toColor和toColor2设置LineChart的水平渐变,取消通过ItemStyle设置LineChart的水平渐变。
This commit is contained in:
@@ -236,15 +236,21 @@ namespace XCharts
|
||||
if (!IsNeedGradient()) return ChartConst.clearColor32;
|
||||
value = Mathf.Clamp01(value);
|
||||
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
|
||||
Color32 color;
|
||||
if (!ChartHelper.IsClearColor(m_ToColor2))
|
||||
{
|
||||
if (value <= 0.5f) return Color32.Lerp(startColor, m_ToColor, 2 * value);
|
||||
else return Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
|
||||
if (value <= 0.5f) color = Color32.Lerp(startColor, m_ToColor, 2 * value);
|
||||
else color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color32.Lerp(startColor, m_ToColor, value);
|
||||
color = Color32.Lerp(startColor, m_ToColor, value);
|
||||
}
|
||||
if (m_Opacity != 1)
|
||||
{
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// The style of line.
|
||||
/// 线条样式。
|
||||
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color,线条颜色默认也会取改颜色。
|
||||
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color,线条颜色默认也会取该颜色。
|
||||
/// toColor,toColor2可设置水平方向的渐变,如需要设置垂直方向的渐变,可使用VisualMap。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class LineStyle : SubComponent
|
||||
@@ -47,6 +48,8 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Type m_Type = Type.Solid;
|
||||
[SerializeField] private Color32 m_Color;
|
||||
[SerializeField] private Color32 m_ToColor;
|
||||
[SerializeField] private Color32 m_ToColor2;
|
||||
[SerializeField] private float m_Width = 0.8f;
|
||||
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
|
||||
|
||||
@@ -78,6 +81,24 @@ namespace XCharts
|
||||
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the middle color of line, default use serie color.
|
||||
/// 线的渐变颜色(需要水平方向渐变时)。
|
||||
/// </summary>
|
||||
public Color32 toColor
|
||||
{
|
||||
get { return m_ToColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the end color of line, default use serie color.
|
||||
/// 线的渐变颜色2(需要水平方向三个渐变色的渐变时)。
|
||||
/// </summary>
|
||||
public Color32 toColor2
|
||||
{
|
||||
get { return m_ToColor2; }
|
||||
set { if (PropertyUtility.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the width of line.
|
||||
/// 线宽。
|
||||
/// /// </summary>
|
||||
@@ -117,6 +138,8 @@ namespace XCharts
|
||||
lineStyle.show = show;
|
||||
lineStyle.type = type;
|
||||
lineStyle.color = color;
|
||||
lineStyle.toColor = toColor;
|
||||
lineStyle.toColor2 = toColor2;
|
||||
lineStyle.width = width;
|
||||
lineStyle.opacity = opacity;
|
||||
return lineStyle;
|
||||
@@ -127,6 +150,8 @@ namespace XCharts
|
||||
show = lineStyle.show;
|
||||
type = lineStyle.type;
|
||||
color = lineStyle.color;
|
||||
toColor = lineStyle.toColor;
|
||||
toColor2 = lineStyle.toColor2;
|
||||
width = lineStyle.width;
|
||||
opacity = lineStyle.opacity;
|
||||
}
|
||||
@@ -138,5 +163,32 @@ namespace XCharts
|
||||
color.a *= (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
|
||||
public bool IsNeedGradient()
|
||||
{
|
||||
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
|
||||
}
|
||||
|
||||
public Color32 GetGradientColor(float value, Color32 defaultColor)
|
||||
{
|
||||
var color = ChartConst.clearColor32;
|
||||
if (!IsNeedGradient()) return color;
|
||||
value = Mathf.Clamp01(value);
|
||||
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
|
||||
if (!ChartHelper.IsClearColor(m_ToColor2))
|
||||
{
|
||||
if (value <= 0.5f) color = Color32.Lerp(startColor, m_ToColor, 2 * value);
|
||||
else color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
color = Color32.Lerp(startColor, m_ToColor, value);
|
||||
}
|
||||
if (m_Opacity != 1)
|
||||
{
|
||||
color.a *= (byte)(color.a * m_Opacity);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user