diff --git a/Demo/Scripts/Demo_Dynamic.cs b/Demo/Scripts/Demo_Dynamic.cs index 5e1b2ef9..3c556b44 100644 --- a/Demo/Scripts/Demo_Dynamic.cs +++ b/Demo/Scripts/Demo_Dynamic.cs @@ -21,7 +21,7 @@ public class Demo_Dynamic : MonoBehaviour void Awake() { chart = gameObject.GetComponentInChildren(); - //chart.RemoveData(); + chart.RemoveData(); var serie = chart.AddSerie(SerieType.Line); serie.symbol.type = SerieSymbolType.None; serie.maxCache = maxCacheDataNumber; diff --git a/Scripts/Editor/PropertyDrawers/SerieSymbolDrawer.cs b/Scripts/Editor/PropertyDrawers/SerieSymbolDrawer.cs index e8f8f185..8564eb53 100644 --- a/Scripts/Editor/PropertyDrawers/SerieSymbolDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/SerieSymbolDrawer.cs @@ -22,6 +22,9 @@ namespace XCharts SerializedProperty m_SelectedDataScale = prop.FindPropertyRelative("m_SelectedDataScale"); SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity"); + SerializedProperty m_StartIndex = prop.FindPropertyRelative("m_StartIndex"); + SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval"); + SerializedProperty m_ForceShowLast = prop.FindPropertyRelative("m_ForceShowLast"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieSymbolToggle, prop, null, m_Type, false); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -55,6 +58,12 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Opacity); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_StartIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_Interval); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_ForceShowLast); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; --EditorGUI.indentLevel; } } @@ -68,13 +77,13 @@ namespace XCharts switch (sizeType) { case SerieSymbolSizeType.Custom: - return 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; + return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; case SerieSymbolSizeType.FromData: - return 7 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; + return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing; case SerieSymbolSizeType.Callback: - return 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; + return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; } - return 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; + return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; } else { diff --git a/Scripts/UI/Component/Series.cs b/Scripts/UI/Component/Series.cs index 5a1665c0..20f3a3ca 100644 --- a/Scripts/UI/Component/Series.cs +++ b/Scripts/UI/Component/Series.cs @@ -80,8 +80,16 @@ namespace XCharts { for (int i = 0; i < m_Series.Count; i++) { - if ((string.IsNullOrEmpty(name) && string.IsNullOrEmpty(m_Series[i].name)) - || name.Equals(m_Series[i].name)) + bool match = false; + if (string.IsNullOrEmpty(name)) + { + if (string.IsNullOrEmpty(m_Series[i].name)) match = true; + } + else if (name.Equals(m_Series[i].name)) + { + match = true; + } + if (match) { m_Series[i].index = i; return m_Series[i]; diff --git a/Scripts/UI/Internal/CoordinateChart_DrawLine.cs b/Scripts/UI/Internal/CoordinateChart_DrawLine.cs index cb790bc0..7f9bef6c 100644 --- a/Scripts/UI/Internal/CoordinateChart_DrawLine.cs +++ b/Scripts/UI/Internal/CoordinateChart_DrawLine.cs @@ -19,6 +19,7 @@ namespace XCharts var count = serie.dataPoints.Count; for (int i = 0; i < count; i++) { + if (!serie.symbol.ShowSymbol(i, count)) continue; if (serie.lineArrow.show) { if (serie.lineArrow.position == LineArrow.Position.Start && i == 0) continue; diff --git a/Scripts/UI/Internal/SerieSymbol.cs b/Scripts/UI/Internal/SerieSymbol.cs index 4928c3ad..6144b518 100644 --- a/Scripts/UI/Internal/SerieSymbol.cs +++ b/Scripts/UI/Internal/SerieSymbol.cs @@ -82,79 +82,85 @@ namespace XCharts [SerializeField] private SymbolSizeCallback m_SelectedSizeCallback; [SerializeField] private Color m_Color; [SerializeField] [Range(0, 1)] private float m_Opacity = 1; + [SerializeField] private int m_StartIndex; + [SerializeField] private int m_Interval; + [SerializeField] private bool m_ForceShowLast = false; /// /// the type of symbol. /// 标记类型。 /// - /// public SerieSymbolType type { get { return m_Type; } set { m_Type = value; } } /// /// the type of symbol size. /// 标记图形的大小获取方式。 /// - /// public SerieSymbolSizeType sizeType { get { return m_SizeType; } set { m_SizeType = value; } } /// /// the size of symbol. /// 标记的大小。 /// - /// public float size { get { return m_Size; } set { m_Size = value; } } /// /// the size of selected symbol. /// 被选中的标记的大小。 /// - /// public float selectedSize { get { return m_SelectedSize; } set { m_SelectedSize = value; } } /// /// whitch data index is when the sizeType assined as FromData. /// 当sizeType指定为FromData时,指定的数据源索引。 /// - /// public int dataIndex { get { return m_DataIndex; } set { m_DataIndex = value; } } /// /// the scale of data when sizeType assined as FromData. /// 当sizeType指定为FromData时,指定的倍数系数。 /// - /// public float dataScale { get { return m_DataScale; } set { m_DataScale = value; } } /// /// the scale of selected data when sizeType assined as FromData. /// 当sizeType指定为FromData时,指定的高亮倍数系数。 /// - /// public float selectedDataScale { get { return m_SelectedDataScale; } set { m_SelectedDataScale = value; } } /// /// the callback of size when sizeType assined as Callback. /// 当sizeType指定为Callback时,指定的回调函数。 /// - /// public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } } /// /// the callback of size when sizeType assined as Callback. /// 当sizeType指定为Callback时,指定的高亮回调函数。 /// - /// public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } } /// /// the color of symbol,default from serie. /// 标记图形的颜色,默认和系列一致。 /// - /// public Color color { get { return m_Color; } set { m_Color = value; } } /// /// the opacity of color. /// 图形标记的透明度。 /// - /// public float opacity { get { return m_Opacity; } set { m_Opacity = value; } } + /// + /// the index start to show symbol. + /// 开始显示图形标记的索引。 + /// + public int startIndex { get { return m_StartIndex; } set { m_StartIndex = value; } } + /// + /// the interval of show symbol. + /// 显示图形标记的间隔。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。 + /// + public int interval { get { return m_Interval; } set { m_Interval = value; } } + /// + /// whether to show the last symbol. + /// 是否强制显示最后一个图形标记。 + /// + public bool forceShowLast { get { return m_ForceShowLast; } set { m_ForceShowLast = value; } } private List m_AnimationSize = new List() { 0, 5, 10 }; /// /// the setting for effect scatter. /// 带有涟漪特效动画的散点图的动画参数。 /// - /// public List animationSize { get { return m_AnimationSize; } } /// @@ -212,5 +218,14 @@ namespace XCharts default: return selectedSize; } } + + public bool ShowSymbol(int dataIndex, int dataCount) + { + if (type == SerieSymbolType.None) return false; + if (dataIndex < startIndex) return false; + if (m_Interval <= 0) return true; + if (m_ForceShowLast && dataIndex == dataCount - 1) return true; + return (dataIndex - startIndex) % (m_Interval + 1) == 0; + } } } diff --git a/Scripts/UI/RadarChart.cs b/Scripts/UI/RadarChart.cs index 3e497b49..20e9fb76 100644 --- a/Scripts/UI/RadarChart.cs +++ b/Scripts/UI/RadarChart.cs @@ -293,7 +293,7 @@ namespace XCharts { ChartHelper.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor); } - if (serie.symbol.type != SerieSymbolType.None) + if (serie.symbol.type != SerieSymbolType.None ) { var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size); float symbolRadius = symbolSize - serie.lineStyle.width * 2;