[feature][symbol] support symbol settings for StateStyle

This commit is contained in:
monitor1394
2022-07-27 08:00:57 +08:00
parent b3b0c0b3aa
commit 5b2b2d4059
16 changed files with 216 additions and 258 deletions

View File

@@ -34,12 +34,9 @@ namespace XCharts.Runtime
public class SerieSymbol : SymbolStyle, ISerieDataComponent
{
[SerializeField] private SymbolSizeType m_SizeType = SymbolSizeType.Custom;
[SerializeField] private float m_SelectedSize = 0f;
[SerializeField] private int m_DataIndex = 1;
[SerializeField] private float m_DataScale = 1;
[SerializeField] private float m_SelectedDataScale = 1.5f;
[SerializeField] private SymbolSizeFunction m_SizeFunction;
[SerializeField] private SymbolSizeFunction m_SelectedSizeFunction;
[SerializeField] private int m_StartIndex;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
@@ -49,12 +46,9 @@ namespace XCharts.Runtime
{
base.Reset();
m_SizeType = SymbolSizeType.Custom;
m_SelectedSize = 0f;
m_DataIndex = 1;
m_DataScale = 1;
m_SelectedDataScale = 1.5f;
m_SizeFunction = null;
m_SelectedSizeFunction = null;
m_StartIndex = 0;
m_Interval = 0;
m_ForceShowLast = false;
@@ -71,15 +65,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of selected symbol.
/// |被选中的标记的大小。
/// </summary>
public float selectedSize
{
get { return m_SelectedSize; }
set { if (PropertyUtil.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// whitch data index is when the sizeType assined as FromData.
/// |当sizeType指定为FromData时指定的数据源索引。
/// </summary>
@@ -98,15 +83,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of selected data when sizeType assined as FromData.
/// |当sizeType指定为FromData时指定的高亮倍数系数。
/// </summary>
public float selectedDataScale
{
get { return m_SelectedDataScale; }
set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the function of size when sizeType assined as Function.
/// |当sizeType指定为Function时指定的委托函数。
/// </summary>
@@ -116,15 +92,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_SizeFunction, value)) SetVerticesDirty(); }
}
/// <summary>
/// the function of size when sizeType assined as Function.
/// |当sizeType指定为Function时指定的高亮委托函数。
/// </summary>
public SymbolSizeFunction selectedSizeFunction
{
get { return m_SelectedSizeFunction; }
set { if (PropertyUtil.SetClass(ref m_SelectedSizeFunction, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
/// |开始显示图形标记的索引。
/// </summary>
@@ -187,42 +154,6 @@ namespace XCharts.Runtime
}
}
/// <summary>
/// 根据sizeType获得高亮时的标记大小
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSelectedSize(List<double> data, float themeSelectedSize)
{
switch (m_SizeType)
{
case SymbolSizeType.Custom:
return selectedSize == 0 ? themeSelectedSize : selectedSize;
case SymbolSizeType.FromData:
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return (float) data[dataIndex] * m_SelectedDataScale;
}
else
{
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
case SymbolSizeType.Function:
if (data != null && selectedSizeFunction != null)
return selectedSizeFunction(data);
else
return selectedSize == 0 ? themeSelectedSize : selectedSize;
default:
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
}
public bool ShowSymbol(int dataIndex, int dataCount)
{
if (!show)

View File

@@ -242,9 +242,10 @@ namespace XCharts.Runtime
private void DrawMarkLineSymbol(VertexHelper vh, SymbolStyle symbol, Serie serie, GridCoord grid, ThemeStyle theme,
Vector3 pos, Vector3 startPos, Color32 lineColor)
{
var tickness = SerieHelper.GetSymbolBorder(serie, null, theme);
var borderColor = SerieHelper.GetSymbolBorderColor(serie, null, theme);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, null);
float tickness = 0f;
float[] cornerRadius = null;
Color32 borderColor;
SerieHelper.GetSymbolInfo(out borderColor, out tickness, out cornerRadius, serie, null, chart.theme);
chart.DrawClipSymbol(vh, symbol.type, symbol.size, tickness, pos, lineColor, lineColor,
ColorUtil.clearColor32, borderColor, symbol.gap, true, cornerRadius, grid, startPos);
}

View File

@@ -16,6 +16,7 @@ namespace XCharts.Runtime
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
[SerializeField] private AreaStyle m_AreaStyle = new AreaStyle();
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
public void Reset()
{
@@ -23,6 +24,7 @@ namespace XCharts.Runtime
m_Label.Reset();
m_LabelLine.Reset();
m_ItemStyle.Reset();
m_Symbol.Reset();
}
/// <summary>
@@ -73,6 +75,14 @@ namespace XCharts.Runtime
get { return m_AreaStyle; }
set { if (PropertyUtil.SetClass(ref m_AreaStyle, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 标记样式。
/// </summary>
public SerieSymbol symbol
{
get { return m_Symbol; }
set { if (PropertyUtil.SetClass(ref m_Symbol, value, true)) SetVerticesDirty(); }
}
public override bool vertsDirty
{
@@ -82,7 +92,8 @@ namespace XCharts.Runtime
m_Label.vertsDirty ||
m_ItemStyle.vertsDirty ||
m_LineStyle.vertsDirty ||
m_AreaStyle.vertsDirty;
m_AreaStyle.vertsDirty ||
m_Symbol.vertsDirty;
}
}
@@ -102,12 +113,14 @@ namespace XCharts.Runtime
m_ItemStyle.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();
m_AreaStyle.ClearVerticesDirty();
m_Symbol.ClearVerticesDirty();
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
m_Label.ClearComponentDirty();
m_Symbol.ClearComponentDirty();
}
}
}