diff --git a/Editor/Series/SerieEditor.cs b/Editor/Series/SerieEditor.cs index 82cfa37d..e251d810 100644 --- a/Editor/Series/SerieEditor.cs +++ b/Editor/Series/SerieEditor.cs @@ -204,15 +204,15 @@ namespace XCharts.Editor } serieDataMenus.Clear(); - if (serie.GetType().IsDefined(typeof(SerieDataExtraComponentAttribute), false)) + if (serie.GetType().IsDefined(typeof(SerieDataComponentAttribute), false)) { - var attribute = serie.GetType().GetAttribute(); + var attribute = serie.GetType().GetAttribute(); foreach (var type in attribute.types) { var size = serieData.FindPropertyRelative(SerieData.extraComponentMap[type]).arraySize; serieDataMenus.Add(new HeaderMenuInfo("Add " + type.Name, () => { - serie.GetSerieData(index).GetOrAddComponent(type); + serie.GetSerieData(index).EnsureComponent(type); EditorUtility.SetDirty(chart); }, size == 0)); } diff --git a/Editor/Series/SerieListEditor.cs b/Editor/Series/SerieListEditor.cs index 4ad75d3f..406845b0 100644 --- a/Editor/Series/SerieListEditor.cs +++ b/Editor/Series/SerieListEditor.cs @@ -176,15 +176,15 @@ namespace XCharts.Editor ConvertSerie(editor.serie, type); })); } - if (editor.serie.GetType().IsDefined(typeof(SerieExtraComponentAttribute), false)) + if (editor.serie.GetType().IsDefined(typeof(SerieComponentAttribute), false)) { - var attribute = editor.serie.GetType().GetAttribute(); + var attribute = editor.serie.GetType().GetAttribute(); foreach (var type in attribute.types) { var size = editor.FindProperty(Serie.extraComponentMap[type]).arraySize; editor.menus.Add(new HeaderMenuInfo("Add " + type.Name, () => { - editor.serie.AddExtraComponent(type); + editor.serie.EnsureComponent(type); RefreshEditors(); chart.RefreshAllComponent(); EditorUtility.SetDirty(chart); @@ -195,7 +195,7 @@ namespace XCharts.Editor var size = editor.FindProperty(Serie.extraComponentMap[type]).arraySize; editor.menus.Add(new HeaderMenuInfo("Remove " + type.Name, () => { - editor.serie.RemoveExtraComponent(type); + editor.serie.RemoveComponent(type); RefreshEditors(); chart.RefreshAllComponent(); EditorUtility.SetDirty(chart); diff --git a/Examples/Example00_CheatSheet.cs b/Examples/Example00_CheatSheet.cs index 4492c94b..0b22b89b 100644 --- a/Examples/Example00_CheatSheet.cs +++ b/Examples/Example00_CheatSheet.cs @@ -45,10 +45,10 @@ namespace XCharts.Example chart = gameObject.GetComponent(); if (chart == null) gameObject.AddComponent(); - chart.GetOrAddChartComponent().show = true; + chart.EnsureChartComponent<Title>().show = true; chart.EnsureChartComponent<Title>().text = "术语解析-组件"; - var grid = chart.GetOrAddChartComponent<GridCoord>(); + var grid = chart.EnsureChartComponent<GridCoord>(); grid.bottom = 30; grid.right = 30; grid.left = 50; @@ -197,7 +197,7 @@ namespace XCharts.Example var grid = chart.EnsureChartComponent<GridCoord>(); grid.bottom = 70; - var dataZoom = chart.GetOrAddChartComponent<DataZoom>(); + var dataZoom = chart.EnsureChartComponent<DataZoom>(); dataZoom.enable = true; dataZoom.supportInside = true; dataZoom.supportSlider = true; @@ -258,7 +258,7 @@ namespace XCharts.Example { chart.EnsureChartComponent<Title>().subText = "VisualMap 视觉映射:可从全局上配置图表的颜色、字体等效果,支持默认主题切换"; - var visualMap = chart.GetOrAddChartComponent<VisualMap>(); + var visualMap = chart.EnsureChartComponent<VisualMap>(); visualMap.show = true; visualMap.showUI = true; visualMap.orient = Orient.Vertical; diff --git a/Examples/Example04_DataZoom.cs b/Examples/Example04_DataZoom.cs index 8f18c272..b555b299 100644 --- a/Examples/Example04_DataZoom.cs +++ b/Examples/Example04_DataZoom.cs @@ -38,11 +38,11 @@ namespace XCharts.Example { if (dataZoom.IsInMarqueeArea(serieData)) { - serieData.GetOrAddComponent<ItemStyle>().color = Color.red; + serieData.EnsureComponent<ItemStyle>().color = Color.red; } else { - serieData.GetOrAddComponent<ItemStyle>().color = Color.clear; + serieData.EnsureComponent<ItemStyle>().color = Color.clear; } } } diff --git a/Examples/Example10_LineChart.cs b/Examples/Example10_LineChart.cs index c319751b..2dabb5fb 100644 --- a/Examples/Example10_LineChart.cs +++ b/Examples/Example10_LineChart.cs @@ -107,7 +107,7 @@ namespace XCharts.Example { chart.GetChartComponent<Title>().subText = "AreaStyle 面积图"; - serie.AddExtraComponent<AreaStyle>(); + serie.EnsureComponent<AreaStyle>(); serie.areaStyle.show = true; chart.RefreshChart(); yield return new WaitForSeconds(1f); @@ -136,7 +136,7 @@ namespace XCharts.Example IEnumerator LineArrowSettings() { chart.GetChartComponent<Title>().subText = "LineArrow 头部箭头"; - chart.GetSerie(0).AddExtraComponent<LineArrow>(); + chart.GetSerie(0).EnsureComponent<LineArrow>(); serie.lineArrow.show = true; serie.lineArrow.position = LineArrow.Position.Start; chart.RefreshChart(); @@ -198,7 +198,7 @@ namespace XCharts.Example IEnumerator LineLabelSettings() { chart.GetChartComponent<Title>().subText = "SerieLabel 文本标签"; - serie.AddExtraComponent<LabelStyle>(); + serie.EnsureComponent<LabelStyle>(); chart.RefreshChart(); while (serie.label.offset[1] < 20) { diff --git a/Examples/Example13_LineSimple.cs b/Examples/Example13_LineSimple.cs index 0e0649f4..72d8ebe4 100644 --- a/Examples/Example13_LineSimple.cs +++ b/Examples/Example13_LineSimple.cs @@ -32,14 +32,14 @@ namespace XCharts.Example chart.Init(); chart.SetSize(580, 300); } - chart.GetOrAddChartComponent<Title>().show = true; - chart.GetOrAddChartComponent<Title>().text = "Line Simple"; + chart.EnsureChartComponent<Title>().show = true; + chart.EnsureChartComponent<Title>().text = "Line Simple"; - chart.GetOrAddChartComponent<Tooltip>().show = true; - chart.GetOrAddChartComponent<Legend>().show = false; + chart.EnsureChartComponent<Tooltip>().show = true; + chart.EnsureChartComponent<Legend>().show = false; - var xAxis = chart.GetOrAddChartComponent<XAxis>(); - var yAxis = chart.GetOrAddChartComponent<YAxis>(); + var xAxis = chart.EnsureChartComponent<XAxis>(); + var yAxis = chart.EnsureChartComponent<YAxis>(); xAxis.show = true; yAxis.show = true; xAxis.type = Axis.AxisType.Category; diff --git a/Examples/Example20_BarChart.cs b/Examples/Example20_BarChart.cs index 5dcede4f..70149d6a 100644 --- a/Examples/Example20_BarChart.cs +++ b/Examples/Example20_BarChart.cs @@ -130,7 +130,7 @@ namespace XCharts.Example serie.barPercentStack = true; if (null == serie.label) { - serie.AddExtraComponent<LabelStyle>(); + serie.EnsureComponent<LabelStyle>(); } serie.label.show = true; serie.label.position = LabelStyle.Position.Center; @@ -139,7 +139,7 @@ namespace XCharts.Example if (null == serie2.label) { - serie2.AddExtraComponent<LabelStyle>(); + serie2.EnsureComponent<LabelStyle>(); } serie2.label.show = true; serie2.label.position = LabelStyle.Position.Center; diff --git a/Examples/Example30_PieChart.cs b/Examples/Example30_PieChart.cs index c7b563d3..e6e5f912 100644 --- a/Examples/Example30_PieChart.cs +++ b/Examples/Example30_PieChart.cs @@ -75,7 +75,7 @@ namespace XCharts.Example { chart.EnsureChartComponent<Title>().subText = "显示文本标签"; - serie.AddExtraComponent<LabelStyle>(); + serie.EnsureComponent<LabelStyle>(); serie.label.show = true; chart.RefreshChart(); yield return new WaitForSeconds(1); @@ -139,11 +139,11 @@ namespace XCharts.Example } if (null == serie.label) { - serie.AddExtraComponent<LabelStyle>(); + serie.EnsureComponent<LabelStyle>(); } if (null == serie1.label) { - serie1.AddExtraComponent<LabelStyle>(); + serie1.EnsureComponent<LabelStyle>(); } serie1.label.show = true; serie1.label.position = LabelStyle.Position.Inside; diff --git a/Examples/Example31_PieUpdateName.cs b/Examples/Example31_PieUpdateName.cs index 8cf1e61e..2c79e5d9 100644 --- a/Examples/Example31_PieUpdateName.cs +++ b/Examples/Example31_PieUpdateName.cs @@ -21,7 +21,7 @@ namespace XCharts.Example var serieIndex = 0; var serie = chart.GetSerie(serieIndex); if (serie == null) return; - serie.AddExtraComponent<LabelStyle>(); + serie.EnsureComponent<LabelStyle>(); serie.label.show = true; serie.label.position = LabelStyle.Position.Outside; } diff --git a/Examples/Example60_Heatmap.cs b/Examples/Example60_Heatmap.cs index 2e89d4c3..263b6382 100644 --- a/Examples/Example60_Heatmap.cs +++ b/Examples/Example60_Heatmap.cs @@ -47,7 +47,7 @@ namespace XCharts.Example serie.itemStyle.borderColor = Color.clear; //设置高亮样式 - var emphasisStyle = serie.AddExtraComponent<EmphasisStyle>(); + var emphasisStyle = serie.EnsureComponent<EmphasisStyle>(); emphasisStyle.itemStyle.show = true; emphasisStyle.itemStyle.borderWidth = 1; emphasisStyle.itemStyle.borderColor = Color.black; diff --git a/Examples/Example80_Polar.cs b/Examples/Example80_Polar.cs index a468fe09..e5e202c5 100644 --- a/Examples/Example80_Polar.cs +++ b/Examples/Example80_Polar.cs @@ -19,7 +19,7 @@ namespace XCharts.Example { chart = gameObject.AddComponent<BaseChart>(); } - chart.GetOrAddChartComponent<PolarCoord>(); + chart.EnsureChartComponent<PolarCoord>(); } void Update() diff --git a/Examples/Example_AddChart.cs b/Examples/Example_AddChart.cs index 145eb63f..143e03c7 100644 --- a/Examples/Example_AddChart.cs +++ b/Examples/Example_AddChart.cs @@ -33,22 +33,22 @@ namespace XCharts.Example chart.Init(); chart.SetSize(1200, 600); } - var title = chart.GetOrAddChartComponent<Title>(); + var title = chart.EnsureChartComponent<Title>(); title.text = "Simple LineChart"; title.subText = "normal line"; - var tooltip = chart.GetOrAddChartComponent<Tooltip>(); + var tooltip = chart.EnsureChartComponent<Tooltip>(); tooltip.show = true; - var legend = chart.GetOrAddChartComponent<Legend>(); + var legend = chart.EnsureChartComponent<Legend>(); legend.show = false; - var xAxis = chart.GetOrAddChartComponent<XAxis>(); + var xAxis = chart.EnsureChartComponent<XAxis>(); xAxis.splitNumber = 10; xAxis.boundaryGap = true; xAxis.type = Axis.AxisType.Category; - var yAxis = chart.GetOrAddChartComponent<YAxis>(); + var yAxis = chart.EnsureChartComponent<YAxis>(); yAxis.type = Axis.AxisType.Value; chart.RemoveData(); diff --git a/Examples/Example_Component.cs b/Examples/Example_Component.cs index 9847c970..d6a68a03 100644 --- a/Examples/Example_Component.cs +++ b/Examples/Example_Component.cs @@ -15,20 +15,20 @@ namespace XCharts.Example void ModifyComponent() { - var title = chart.GetOrAddChartComponent<Title>(); + var title = chart.EnsureChartComponent<Title>(); title.text = "Simple LineChart"; title.subText = "normal line"; var serie1 = chart.AddSerie<Line>(); //var serie2 = chart.GetSerie<Line>(); - serie1.AddExtraComponent<AreaStyle>(); - var label = serie1.AddExtraComponent<LabelStyle>(); + serie1.EnsureComponent<AreaStyle>(); + var label = serie1.EnsureComponent<LabelStyle>(); label.offset = new Vector3(0, 20, 0); var serieData = chart.AddData(0, 20); serieData.radius = 10; - var itemStyle = serieData.GetOrAddComponent<ItemStyle>(); + var itemStyle = serieData.EnsureComponent<ItemStyle>(); itemStyle.color = Color.blue; } } diff --git a/Examples/Example_Dynamic.cs b/Examples/Example_Dynamic.cs index b6a09a0d..260f490b 100644 --- a/Examples/Example_Dynamic.cs +++ b/Examples/Example_Dynamic.cs @@ -28,7 +28,7 @@ namespace XCharts.Example serie.symbol.show = false; serie.maxCache = maxCacheDataNumber; - var xAxis = chart.GetOrAddChartComponent<XAxis>(); + var xAxis = chart.EnsureChartComponent<XAxis>(); xAxis.maxCache = maxCacheDataNumber; timeNow = DateTime.Now; timeNow = timeNow.AddSeconds(-maxCacheDataNumber); diff --git a/Examples/Example_DynamicChart.cs b/Examples/Example_DynamicChart.cs index 2a999d9a..24b9f26a 100644 --- a/Examples/Example_DynamicChart.cs +++ b/Examples/Example_DynamicChart.cs @@ -45,11 +45,11 @@ namespace XCharts.Example chart.Init(); chart.SetSize(580, 300); - chart.GetOrAddChartComponent<Title>().show = true; - chart.GetOrAddChartComponent<Title>().text = chartName; + chart.EnsureChartComponent<Title>().show = true; + chart.EnsureChartComponent<Title>().text = chartName; - chart.GetOrAddChartComponent<Tooltip>().show = true; - chart.GetOrAddChartComponent<Legend>().show = true; + chart.EnsureChartComponent<Tooltip>().show = true; + chart.EnsureChartComponent<Legend>().show = true; chart.RemoveData(); chart.AddSerie<Pie>(); @@ -67,16 +67,16 @@ namespace XCharts.Example chart.Init(); chart.SetSize(580, 300); - chart.GetOrAddChartComponent<Title>().show = true; - chart.GetOrAddChartComponent<Title>().text = chartName; + chart.EnsureChartComponent<Title>().show = true; + chart.EnsureChartComponent<Title>().text = chartName; - chart.GetOrAddChartComponent<Legend>().show = false; + chart.EnsureChartComponent<Legend>().show = false; - var tooltip = chart.GetOrAddChartComponent<Tooltip>(); + var tooltip = chart.EnsureChartComponent<Tooltip>(); tooltip.trigger = Tooltip.Trigger.Axis; - var xAxis = chart.GetOrAddChartComponent<XAxis>(); - var yAxis = chart.GetOrAddChartComponent<YAxis>(); + var xAxis = chart.EnsureChartComponent<XAxis>(); + var yAxis = chart.EnsureChartComponent<YAxis>(); xAxis.splitNumber = 10; xAxis.boundaryGap = true; xAxis.show = true; diff --git a/Runtime/Chart/BarChart.cs b/Runtime/Chart/BarChart.cs index 65cb0d73..a8284f86 100644 --- a/Runtime/Chart/BarChart.cs +++ b/Runtime/Chart/BarChart.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime AddChartComponentWhenNoExist<XAxis>(); AddChartComponentWhenNoExist<YAxis>(); - var tooltip = GetOrAddChartComponent<Tooltip>(); + var tooltip = EnsureChartComponent<Tooltip>(); tooltip.type = Tooltip.Type.Shadow; tooltip.trigger = Tooltip.Trigger.Axis; diff --git a/Runtime/Chart/CandlestickChart.cs b/Runtime/Chart/CandlestickChart.cs index be7e0263..62bf4666 100644 --- a/Runtime/Chart/CandlestickChart.cs +++ b/Runtime/Chart/CandlestickChart.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime AddChartComponentWhenNoExist<XAxis>(); AddChartComponentWhenNoExist<YAxis>(); - var tooltip = GetOrAddChartComponent<Tooltip>(); + var tooltip = EnsureChartComponent<Tooltip>(); tooltip.type = Tooltip.Type.Shadow; tooltip.trigger = Tooltip.Trigger.Axis; diff --git a/Runtime/Chart/HeatmapChart.cs b/Runtime/Chart/HeatmapChart.cs index f1df5f11..3bdcda09 100644 --- a/Runtime/Chart/HeatmapChart.cs +++ b/Runtime/Chart/HeatmapChart.cs @@ -15,15 +15,15 @@ namespace XCharts.Runtime tooltip.type = Tooltip.Type.None; tooltip.trigger = Tooltip.Trigger.Axis; - var grid = GetOrAddChartComponent<GridCoord>(); + var grid = EnsureChartComponent<GridCoord>(); grid.left = 0.12f; - var xAxis = GetOrAddChartComponent<XAxis>(); + var xAxis = EnsureChartComponent<XAxis>(); xAxis.type = Axis.AxisType.Category; xAxis.boundaryGap = true; xAxis.splitNumber = 10; - var yAxis = GetOrAddChartComponent<YAxis>(); + var yAxis = EnsureChartComponent<YAxis>(); yAxis.type = Axis.AxisType.Category; yAxis.boundaryGap = true; yAxis.splitNumber = 10; @@ -35,7 +35,7 @@ namespace XCharts.Runtime Heatmap.AddDefaultSerie(this, GenerateDefaultSerieName()); - var visualMap = GetOrAddChartComponent<VisualMap>(); + var visualMap = EnsureChartComponent<VisualMap>(); visualMap.autoMinMax = true; visualMap.orient = Orient.Vertical; visualMap.calculable = true; diff --git a/Runtime/Chart/LineChart.cs b/Runtime/Chart/LineChart.cs index c5317f5c..bc1dc084 100644 --- a/Runtime/Chart/LineChart.cs +++ b/Runtime/Chart/LineChart.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime AddChartComponentWhenNoExist<XAxis>(); AddChartComponentWhenNoExist<YAxis>(); - var tooltip = GetOrAddChartComponent<Tooltip>(); + var tooltip = EnsureChartComponent<Tooltip>(); tooltip.type = Tooltip.Type.Line; tooltip.trigger = Tooltip.Trigger.Axis; diff --git a/Runtime/Chart/PieChart.cs b/Runtime/Chart/PieChart.cs index f6ef9d32..0cee6a3a 100644 --- a/Runtime/Chart/PieChart.cs +++ b/Runtime/Chart/PieChart.cs @@ -10,7 +10,7 @@ namespace XCharts.Runtime { protected override void DefaultChart() { - var legend = GetOrAddChartComponent<Legend>(); + var legend = EnsureChartComponent<Legend>(); legend.show = true; RemoveData(); diff --git a/Runtime/Chart/ScatterChart.cs b/Runtime/Chart/ScatterChart.cs index a6ce4d97..9f44c902 100644 --- a/Runtime/Chart/ScatterChart.cs +++ b/Runtime/Chart/ScatterChart.cs @@ -12,15 +12,15 @@ namespace XCharts.Runtime { AddChartComponentWhenNoExist<GridCoord>(); - var tooltip = GetOrAddChartComponent<Tooltip>(); + var tooltip = EnsureChartComponent<Tooltip>(); tooltip.type = Tooltip.Type.None; tooltip.trigger = Tooltip.Trigger.Item; - var xAxis = GetOrAddChartComponent<XAxis>(); + var xAxis = EnsureChartComponent<XAxis>(); xAxis.type = Axis.AxisType.Value; xAxis.boundaryGap = false; - var yAxis = GetOrAddChartComponent<YAxis>(); + var yAxis = EnsureChartComponent<YAxis>(); yAxis.type = Axis.AxisType.Value; yAxis.boundaryGap = false; diff --git a/Runtime/Component/Child/AreaStyle.cs b/Runtime/Component/Child/AreaStyle.cs index ddfcc5ce..783555ac 100644 --- a/Runtime/Component/Child/AreaStyle.cs +++ b/Runtime/Component/Child/AreaStyle.cs @@ -7,7 +7,7 @@ namespace XCharts.Runtime /// |区域填充样式。 /// </summary> [System.Serializable] - public class AreaStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent + public class AreaStyle : ChildComponent, ISerieComponent, ISerieDataComponent { /// <summary> /// Origin position of area. diff --git a/Runtime/Component/Child/ImageStyle.cs b/Runtime/Component/Child/ImageStyle.cs index d37b3921..d48582fb 100644 --- a/Runtime/Component/Child/ImageStyle.cs +++ b/Runtime/Component/Child/ImageStyle.cs @@ -4,7 +4,7 @@ using UnityEngine.UI; namespace XCharts.Runtime { [System.Serializable] - public class ImageStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent + public class ImageStyle : ChildComponent, ISerieComponent, ISerieDataComponent { [SerializeField] private bool m_Show = true; [SerializeField] private Sprite m_Sprite; diff --git a/Runtime/Component/Child/LineArrow.cs b/Runtime/Component/Child/LineArrow.cs index 8b45aa84..ed45a0e2 100644 --- a/Runtime/Component/Child/LineArrow.cs +++ b/Runtime/Component/Child/LineArrow.cs @@ -6,7 +6,7 @@ namespace XCharts.Runtime /// <summary> /// </summary> [Serializable] - public class LineArrow : ChildComponent, ISerieExtraComponent + public class LineArrow : ChildComponent, ISerieComponent { public enum Position { diff --git a/Runtime/Component/Label/LabelLine.cs b/Runtime/Component/Label/LabelLine.cs index 87ae5854..3f48c53f 100644 --- a/Runtime/Component/Label/LabelLine.cs +++ b/Runtime/Component/Label/LabelLine.cs @@ -7,7 +7,7 @@ namespace XCharts.Runtime /// 标签的引导线 /// </summary> [System.Serializable] - public class LabelLine : ChildComponent, ISerieExtraComponent, ISerieDataComponent + public class LabelLine : ChildComponent, ISerieComponent, ISerieDataComponent { /// <summary> /// 标签视觉引导线类型 diff --git a/Runtime/Component/Label/LabelStyle.cs b/Runtime/Component/Label/LabelStyle.cs index 030a0cd5..06a8cf69 100644 --- a/Runtime/Component/Label/LabelStyle.cs +++ b/Runtime/Component/Label/LabelStyle.cs @@ -8,7 +8,7 @@ namespace XCharts.Runtime /// |图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。 /// </summary> [System.Serializable] - public class LabelStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent + public class LabelStyle : ChildComponent, ISerieComponent, ISerieDataComponent { /// <summary> /// The position of label. diff --git a/Runtime/Component/State/BlurStyle.cs b/Runtime/Component/State/BlurStyle.cs index 75c0de29..8f67f5e9 100644 --- a/Runtime/Component/State/BlurStyle.cs +++ b/Runtime/Component/State/BlurStyle.cs @@ -8,6 +8,6 @@ namespace XCharts.Runtime /// </summary> [System.Serializable] [Since("v3.2.0")] - public class BlurStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent + public class BlurStyle : StateStyle, ISerieComponent, ISerieDataComponent { } } \ No newline at end of file diff --git a/Runtime/Component/State/EmphasisStyle.cs b/Runtime/Component/State/EmphasisStyle.cs index e3602d20..9719ae47 100644 --- a/Runtime/Component/State/EmphasisStyle.cs +++ b/Runtime/Component/State/EmphasisStyle.cs @@ -8,7 +8,7 @@ namespace XCharts.Runtime /// </summary> [System.Serializable] [Since("v3.2.0")] - public class EmphasisStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent + public class EmphasisStyle : StateStyle, ISerieComponent, ISerieDataComponent { /// <summary> /// focus type. diff --git a/Runtime/Component/State/SelectStyle.cs b/Runtime/Component/State/SelectStyle.cs index 093274ac..7357a216 100644 --- a/Runtime/Component/State/SelectStyle.cs +++ b/Runtime/Component/State/SelectStyle.cs @@ -8,6 +8,6 @@ namespace XCharts.Runtime /// </summary> [System.Serializable] [Since("v3.2.0")] - public class SelectStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent + public class SelectStyle : StateStyle, ISerieComponent, ISerieDataComponent { } } \ No newline at end of file diff --git a/Runtime/Component/Title/TitleStyle.cs b/Runtime/Component/Title/TitleStyle.cs index 2befc2da..647eb517 100644 --- a/Runtime/Component/Title/TitleStyle.cs +++ b/Runtime/Component/Title/TitleStyle.cs @@ -8,7 +8,7 @@ namespace XCharts.Runtime /// |标题相关设置。 /// </summary> [Serializable] - public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieExtraComponent + public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieComponent { } diff --git a/Runtime/Internal/Attributes/SerieExtraComponentAttribute.cs b/Runtime/Internal/Attributes/SerieComponentAttribute.cs similarity index 63% rename from Runtime/Internal/Attributes/SerieExtraComponentAttribute.cs rename to Runtime/Internal/Attributes/SerieComponentAttribute.cs index f4cb9cea..13de0284 100644 --- a/Runtime/Internal/Attributes/SerieExtraComponentAttribute.cs +++ b/Runtime/Internal/Attributes/SerieComponentAttribute.cs @@ -3,36 +3,40 @@ using System.Collections.Generic; namespace XCharts.Runtime { + /// <summary> + /// The attribute for serie component. + /// |可添加到Serie的组件。 + /// </summary> [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public sealed class SerieExtraComponentAttribute : Attribute + public sealed class SerieComponentAttribute : Attribute { public readonly List<Type> types = new List<Type>(); - public SerieExtraComponentAttribute() + public SerieComponentAttribute() { } - public SerieExtraComponentAttribute(Type type1) + public SerieComponentAttribute(Type type1) { AddType(type1); } - public SerieExtraComponentAttribute(Type type1, Type type2) + public SerieComponentAttribute(Type type1, Type type2) { AddType(type1); AddType(type2); } - public SerieExtraComponentAttribute(Type type1, Type type2, Type type3) + public SerieComponentAttribute(Type type1, Type type2, Type type3) { AddType(type1); AddType(type2); AddType(type3); } - public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4) + public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4) { AddType(type1); AddType(type2); AddType(type3); AddType(type4); } - public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5) + public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5) { AddType(type1); AddType(type2); @@ -40,7 +44,7 @@ namespace XCharts.Runtime AddType(type4); AddType(type5); } - public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6) + public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6) { AddType(type1); AddType(type2); @@ -49,7 +53,7 @@ namespace XCharts.Runtime AddType(type5); AddType(type6); } - public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7) + public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7) { AddType(type1); AddType(type2); @@ -67,7 +71,7 @@ namespace XCharts.Runtime types.Add(type); } - public bool Contains<T>() where T : ISerieExtraComponent + public bool Contains<T>() where T : ISerieComponent { return Contains(typeof(T)); } diff --git a/Runtime/Internal/Attributes/SerieExtraComponentAttribute.cs.meta b/Runtime/Internal/Attributes/SerieComponentAttribute.cs.meta similarity index 100% rename from Runtime/Internal/Attributes/SerieExtraComponentAttribute.cs.meta rename to Runtime/Internal/Attributes/SerieComponentAttribute.cs.meta diff --git a/Runtime/Internal/Attributes/SerieConvertAttribute.cs b/Runtime/Internal/Attributes/SerieConvertAttribute.cs index 15861197..6e888f96 100644 --- a/Runtime/Internal/Attributes/SerieConvertAttribute.cs +++ b/Runtime/Internal/Attributes/SerieConvertAttribute.cs @@ -2,10 +2,11 @@ using System; namespace XCharts.Runtime { - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] /// <summary> - /// What serie can convert to me + /// The attribute for which serie types can be converted to. + /// |可转化为哪些Serie类型。 /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class SerieConvertAttribute : Attribute { public readonly Type type0; diff --git a/Runtime/Internal/Attributes/SerieDataExtraComponentAttribute.cs b/Runtime/Internal/Attributes/SerieDataComponentAttribute.cs similarity index 61% rename from Runtime/Internal/Attributes/SerieDataExtraComponentAttribute.cs rename to Runtime/Internal/Attributes/SerieDataComponentAttribute.cs index cd163795..a5b82cbb 100644 --- a/Runtime/Internal/Attributes/SerieDataExtraComponentAttribute.cs +++ b/Runtime/Internal/Attributes/SerieDataComponentAttribute.cs @@ -3,36 +3,41 @@ using System.Collections.Generic; namespace XCharts.Runtime { + /// <summary> + /// The attribute for serie data component. + /// |可添加到SerieData的组件。 + /// </summary> [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public sealed class SerieDataExtraComponentAttribute : Attribute + public sealed class SerieDataComponentAttribute : Attribute { public readonly List<Type> types = new List<Type>(); - public SerieDataExtraComponentAttribute() - { } - public SerieDataExtraComponentAttribute(Type type1) + public SerieDataComponentAttribute() + { + } + public SerieDataComponentAttribute(Type type1) { AddType(type1); } - public SerieDataExtraComponentAttribute(Type type1, Type type2) + public SerieDataComponentAttribute(Type type1, Type type2) { AddType(type1); AddType(type2); } - public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3) + public SerieDataComponentAttribute(Type type1, Type type2, Type type3) { AddType(type1); AddType(type2); AddType(type3); } - public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4) + public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4) { AddType(type1); AddType(type2); AddType(type3); AddType(type4); } - public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5) + public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5) { AddType(type1); AddType(type2); @@ -40,7 +45,7 @@ namespace XCharts.Runtime AddType(type4); AddType(type5); } - public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6) + public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6) { AddType(type1); AddType(type2); @@ -49,7 +54,7 @@ namespace XCharts.Runtime AddType(type5); AddType(type6); } - public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7) + public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7) { AddType(type1); AddType(type2); @@ -67,7 +72,7 @@ namespace XCharts.Runtime types.Add(type); } - public bool Contains<T>() where T : ISerieExtraComponent + public bool Contains<T>() where T : ISerieComponent { return Contains(typeof(T)); } diff --git a/Runtime/Internal/Attributes/SerieDataExtraComponentAttribute.cs.meta b/Runtime/Internal/Attributes/SerieDataComponentAttribute.cs.meta similarity index 100% rename from Runtime/Internal/Attributes/SerieDataExtraComponentAttribute.cs.meta rename to Runtime/Internal/Attributes/SerieDataComponentAttribute.cs.meta diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index c30e3fee..76c8c953 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -69,7 +69,15 @@ namespace XCharts.Runtime /// </summary> public Vector3 chartPosition { get { return m_ChartPosition; } } public Rect chartRect { get { return m_ChartRect; } } + /// <summary> + /// The callback function of chart init. + /// |图表的初始化完成回调。 + /// </summary> public Action onInit { set { m_OnInit = value; } } + /// <summary> + /// The callback function of chart update. + /// |图表的Update回调。 + /// </summary> public Action onUpdate { set { m_OnUpdate = value; } } /// <summary> /// 自定义绘制回调。在绘制Serie前调用。 diff --git a/Runtime/Internal/BaseChart.Component.cs b/Runtime/Internal/BaseChart.Component.cs index 62dab6a7..dd57e897 100644 --- a/Runtime/Internal/BaseChart.Component.cs +++ b/Runtime/Internal/BaseChart.Component.cs @@ -41,7 +41,7 @@ namespace XCharts.Runtime public T AddChartComponent<T>() where T : MainComponent { - return (T) AddChartComponent(typeof(T)); + return (T)AddChartComponent(typeof(T)); } public T AddChartComponentWhenNoExist<T>() where T : MainComponent @@ -118,7 +118,7 @@ namespace XCharts.Runtime if (attrubte.handler == null) return; - var handler = (MainComponentHandler) Activator.CreateInstance(attrubte.handler); + var handler = (MainComponentHandler)Activator.CreateInstance(attrubte.handler); handler.attribute = attrubte; handler.chart = this; handler.SetComponent(component); @@ -221,9 +221,9 @@ namespace XCharts.Runtime return GetChartComponentNum(typeof(T)); } + private static List<MainComponent> list; public int GetChartComponentNum(Type type) { - List<MainComponent> list; if (m_ComponentMaps.TryGetValue(type, out list)) return list.Count; else @@ -245,6 +245,7 @@ namespace XCharts.Runtime return m_ComponentMaps[typeof(T)]; } + [Obsolete("'GetOrAddChartComponent' is obsolete, Use 'EnsureChartComponent' instead.")] public T GetOrAddChartComponent<T>() where T : MainComponent { var component = GetChartComponent<T>(); @@ -253,6 +254,15 @@ namespace XCharts.Runtime else return component; } + + /// <summary> + /// Ensure the chart has the component, if not, add it. + /// Note: it may fail to add. + /// |确保图表有该组件,如果没有则添加。注意:有可能添加不成功。 + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns>component, or null if add failed.</returns> + [Since("v3.6.0")] public T EnsureChartComponent<T>() where T : MainComponent { var component = GetChartComponent<T>(); @@ -261,7 +271,7 @@ namespace XCharts.Runtime else return component; } - + public bool TryGetChartComponent<T>(out T component, int index = 0) where T : MainComponent { @@ -270,7 +280,7 @@ namespace XCharts.Runtime { if (com is T && com.index == index) { - component = (T) com; + component = (T)com; return true; } } @@ -425,11 +435,11 @@ namespace XCharts.Runtime var yAxis = GetChartComponent<YAxis>(); if (yAxis.IsCategory()) { - return yAxis.GetData((int) yAxis.context.pointerValue, dataZoom); + return yAxis.GetData((int)yAxis.context.pointerValue, dataZoom); } else if (xAxis.IsCategory()) { - return xAxis.GetData((int) xAxis.context.pointerValue, dataZoom); + return xAxis.GetData((int)xAxis.context.pointerValue, dataZoom); } return null; } @@ -439,11 +449,11 @@ namespace XCharts.Runtime var yAxis = GetChartComponent<YAxis>(serie.yAxisIndex); if (yAxis.IsCategory()) { - return yAxis.GetData((int) yAxis.context.pointerValue, dataZoom); + return yAxis.GetData((int)yAxis.context.pointerValue, dataZoom); } else if (xAxis.IsCategory()) { - return xAxis.GetData((int) xAxis.context.pointerValue, dataZoom); + return xAxis.GetData((int)xAxis.context.pointerValue, dataZoom); } return null; } diff --git a/Runtime/Internal/Misc/ISerieComponent.cs b/Runtime/Internal/Misc/ISerieComponent.cs new file mode 100644 index 00000000..9a863d4d --- /dev/null +++ b/Runtime/Internal/Misc/ISerieComponent.cs @@ -0,0 +1,11 @@ +namespace XCharts.Runtime +{ + /// <summary> + /// The interface for serie component. + /// |可用于Serie的组件。 + /// </summary> + public interface ISerieComponent + { + bool show { get; set; } + } +} \ No newline at end of file diff --git a/Runtime/Internal/Misc/ISerieExtraComponent.cs.meta b/Runtime/Internal/Misc/ISerieComponent.cs.meta similarity index 100% rename from Runtime/Internal/Misc/ISerieExtraComponent.cs.meta rename to Runtime/Internal/Misc/ISerieComponent.cs.meta diff --git a/Runtime/Internal/Misc/ISerieContainer.cs b/Runtime/Internal/Misc/ISerieContainer.cs index 5e09dc4c..53300a57 100644 --- a/Runtime/Internal/Misc/ISerieContainer.cs +++ b/Runtime/Internal/Misc/ISerieContainer.cs @@ -2,7 +2,6 @@ namespace XCharts.Runtime { public interface ISerieContainer { - //bool runtimeIsPointerEnter { get; } int index { get; } bool IsPointerEnter(); } diff --git a/Runtime/Internal/Misc/ISerieDataComponent.cs b/Runtime/Internal/Misc/ISerieDataComponent.cs index 0187300c..278c5903 100644 --- a/Runtime/Internal/Misc/ISerieDataComponent.cs +++ b/Runtime/Internal/Misc/ISerieDataComponent.cs @@ -1,9 +1,10 @@ -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - namespace XCharts.Runtime { + /// <summary> + /// The interface for serie data component. + /// |可用于SerieData的组件。 + /// </summary> public interface ISerieDataComponent - { } + { + } } \ No newline at end of file diff --git a/Runtime/Internal/Misc/ISerieExtraComponent.cs b/Runtime/Internal/Misc/ISerieExtraComponent.cs deleted file mode 100644 index dda88d4c..00000000 --- a/Runtime/Internal/Misc/ISerieExtraComponent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - -namespace XCharts.Runtime -{ - public interface ISerieExtraComponent - { - bool show { get; set; } - } -} \ No newline at end of file diff --git a/Runtime/Serie/Bar/Bar.cs b/Runtime/Serie/Bar/Bar.cs index 0074102d..21066d66 100644 --- a/Runtime/Serie/Bar/Bar.cs +++ b/Runtime/Serie/Bar/Bar.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [SerieConvert(typeof(Line), typeof(Pie))] [CoordOptions(typeof(GridCoord), typeof(PolarCoord))] [DefaultAnimation(AnimationType.BottomToTop)] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Ignore")] public class Bar : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Bar/SimplifiedBar.cs b/Runtime/Serie/Bar/SimplifiedBar.cs index 8a6c2a0b..0e9703f9 100644 --- a/Runtime/Serie/Bar/SimplifiedBar.cs +++ b/Runtime/Serie/Bar/SimplifiedBar.cs @@ -8,8 +8,8 @@ namespace XCharts.Runtime [SerieConvert(typeof(SimplifiedLine), typeof(Bar))] [CoordOptions(typeof(GridCoord))] [DefaultAnimation(AnimationType.LeftToRight)] - [SerieExtraComponent()] - [SerieDataExtraComponent()] + [SerieComponent()] + [SerieDataComponent()] [SerieDataExtraField()] public class SimplifiedBar : Serie, INeedSerieContainer, ISimplifiedSerie { diff --git a/Runtime/Serie/Candlestick/Candlestick.cs b/Runtime/Serie/Candlestick/Candlestick.cs index 08ff439c..092ec99d 100644 --- a/Runtime/Serie/Candlestick/Candlestick.cs +++ b/Runtime/Serie/Candlestick/Candlestick.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(CandlestickHandler), true)] [DefaultAnimation(AnimationType.LeftToRight)] - [SerieExtraComponent()] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent()] + [SerieDataComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Candlestick : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs index 8bddbe28..003c72fe 100644 --- a/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs +++ b/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(SimplifiedCandlestickHandler), true)] [DefaultAnimation(AnimationType.LeftToRight)] - [SerieExtraComponent()] - [SerieDataExtraComponent()] + [SerieComponent()] + [SerieDataComponent()] [SerieDataExtraField()] public class SimplifiedCandlestick : Serie, INeedSerieContainer, ISimplifiedSerie { diff --git a/Runtime/Serie/Heatmap/Heatmap.cs b/Runtime/Serie/Heatmap/Heatmap.cs index 54a50e98..6897e5ec 100644 --- a/Runtime/Serie/Heatmap/Heatmap.cs +++ b/Runtime/Serie/Heatmap/Heatmap.cs @@ -25,8 +25,8 @@ namespace XCharts.Runtime [DefaultAnimation(AnimationType.LeftToRight)] [RequireChartComponent(typeof(VisualMap))] [CoordOptions(typeof(GridCoord), typeof(PolarCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Heatmap : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Line/Line.cs b/Runtime/Serie/Line/Line.cs index a86c32e0..68176cd6 100644 --- a/Runtime/Serie/Line/Line.cs +++ b/Runtime/Serie/Line/Line.cs @@ -7,7 +7,7 @@ namespace XCharts.Runtime [SerieConvert(typeof(Bar), typeof(Pie))] [CoordOptions(typeof(GridCoord), typeof(PolarCoord))] [DefaultAnimation(AnimationType.LeftToRight)] - [SerieExtraComponent( + [SerieComponent( typeof(LabelStyle), typeof(EndLabelStyle), typeof(LineArrow), @@ -15,7 +15,7 @@ namespace XCharts.Runtime typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent( + [SerieDataComponent( typeof(ItemStyle), typeof(LabelStyle), typeof(SerieSymbol), diff --git a/Runtime/Serie/Line/SimplifiedLine.cs b/Runtime/Serie/Line/SimplifiedLine.cs index 3401218c..c1a3b041 100644 --- a/Runtime/Serie/Line/SimplifiedLine.cs +++ b/Runtime/Serie/Line/SimplifiedLine.cs @@ -8,8 +8,8 @@ namespace XCharts.Runtime [SerieConvert(typeof(SimplifiedBar), typeof(Line))] [CoordOptions(typeof(GridCoord))] [DefaultAnimation(AnimationType.LeftToRight)] - [SerieExtraComponent(typeof(AreaStyle))] - [SerieDataExtraComponent()] + [SerieComponent(typeof(AreaStyle))] + [SerieDataComponent()] [SerieDataExtraField()] public class SimplifiedLine : Serie, INeedSerieContainer, ISimplifiedSerie { diff --git a/Runtime/Serie/Parallel/Parallel.cs b/Runtime/Serie/Parallel/Parallel.cs index 09b65279..0062b50c 100644 --- a/Runtime/Serie/Parallel/Parallel.cs +++ b/Runtime/Serie/Parallel/Parallel.cs @@ -6,8 +6,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(ParallelHandler), true)] [RequireChartComponent(typeof(ParallelCoord))] - [SerieExtraComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Parallel : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Pie/Pie.cs b/Runtime/Serie/Pie/Pie.cs index 5d89a5dc..9d173270 100644 --- a/Runtime/Serie/Pie/Pie.cs +++ b/Runtime/Serie/Pie/Pie.cs @@ -4,8 +4,8 @@ namespace XCharts.Runtime [SerieConvert(typeof(Line), typeof(Bar))] [SerieHandler(typeof(PieHandler), true)] [DefaultAnimation(AnimationType.Clockwise)] - [SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")] public class Pie : Serie { diff --git a/Runtime/Serie/Radar/Radar.cs b/Runtime/Serie/Radar/Radar.cs index a0524271..626465e9 100644 --- a/Runtime/Serie/Radar/Radar.cs +++ b/Runtime/Serie/Radar/Radar.cs @@ -6,8 +6,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(RadarHandler), true)] [RequireChartComponent(typeof(RadarCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Radar : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Ring/Ring.cs b/Runtime/Serie/Ring/Ring.cs index 6610cdd2..ebd9b660 100644 --- a/Runtime/Serie/Ring/Ring.cs +++ b/Runtime/Serie/Ring/Ring.cs @@ -4,8 +4,8 @@ namespace XCharts.Runtime { [System.Serializable] [SerieHandler(typeof(RingHandler), true)] - [SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Ring : Serie { @@ -17,14 +17,14 @@ namespace XCharts.Runtime serie.gap = 10; serie.radius = new float[] { 0.3f, 0.35f }; - var label = serie.AddExtraComponent<LabelStyle>(); + var label = serie.EnsureComponent<LabelStyle>(); label.show = true; label.position = LabelStyle.Position.Center; label.formatter = "{d:f0}%"; label.textStyle.autoColor = true; label.textStyle.fontSize = 28; - var titleStyle = serie.AddExtraComponent<TitleStyle>(); + var titleStyle = serie.EnsureComponent<TitleStyle>(); titleStyle.show = false; titleStyle.offset = new Vector2(0, 30); diff --git a/Runtime/Serie/Scatter/EffectScatter.cs b/Runtime/Serie/Scatter/EffectScatter.cs index 55696652..ca10028e 100644 --- a/Runtime/Serie/Scatter/EffectScatter.cs +++ b/Runtime/Serie/Scatter/EffectScatter.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(EffectScatterHandler), true)] [CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Radius")] public class EffectScatter : BaseScatter { diff --git a/Runtime/Serie/Scatter/Scatter.cs b/Runtime/Serie/Scatter/Scatter.cs index daf2ee56..a6367539 100644 --- a/Runtime/Serie/Scatter/Scatter.cs +++ b/Runtime/Serie/Scatter/Scatter.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(ScatterHandler), true)] [CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Radius")] public class Scatter : BaseScatter { diff --git a/Runtime/Serie/Serie.ExtraComponent.cs b/Runtime/Serie/Serie.ExtraComponent.cs index 06eb4726..ac7d546a 100644 --- a/Runtime/Serie/Serie.ExtraComponent.cs +++ b/Runtime/Serie/Serie.ExtraComponent.cs @@ -8,7 +8,8 @@ namespace XCharts.Runtime public partial class Serie { public static Dictionary<Type, string> extraComponentMap = new Dictionary<Type, string> - { { typeof(LabelStyle), "m_Labels" }, + { + { typeof(LabelStyle), "m_Labels" }, { typeof(LabelLine), "m_LabelLines" }, { typeof(EndLabelStyle), "m_EndLabels" }, { typeof(LineArrow), "m_LineArrows" }, @@ -71,7 +72,11 @@ namespace XCharts.Runtime /// </summary> public SelectStyle selectStyle { get { return m_SelectStyles.Count > 0 ? m_SelectStyles[0] : null; } } - public void RemoveAllExtraComponent() + /// <summary> + /// Remove all extra components. + /// |移除所有额外组件。 + /// </summary> + public void RemoveAllComponents() { var serieType = GetType(); foreach (var kv in extraComponentMap) @@ -81,16 +86,72 @@ namespace XCharts.Runtime SetAllDirty(); } - public T AddExtraComponent<T>() where T : ChildComponent, ISerieExtraComponent + [Obsolete("Use EnsureComponent<T>() instead.")] + public T AddExtraComponent<T>() where T : ChildComponent, ISerieComponent { - return AddExtraComponent(typeof(T)) as T; + return EnsureComponent<T>(); } - public ISerieExtraComponent AddExtraComponent(Type type) + public T GetComponent<T>() where T : ChildComponent, ISerieComponent { - if (GetType().IsDefined(typeof(SerieExtraComponentAttribute), false)) + return GetComponent(typeof(T)) as T; + } + + /// <summary> + /// Ensure the serie has the component. If not, add it. + /// |确保系列有该组件。如果没有,则添加。 + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns>component or null</returns> + public T EnsureComponent<T>() where T : ChildComponent, ISerieComponent + { + return EnsureComponent(typeof(T)) as T; + } + + public bool CanAddComponent<T>() where T : ChildComponent, ISerieComponent + { + return CanAddComponent(typeof(T)); + } + + public bool CanAddComponent(Type type) + { + if (GetType().IsDefined(typeof(SerieComponentAttribute), false)) { - var attr = GetType().GetAttribute<SerieExtraComponentAttribute>(); + var attr = GetType().GetAttribute<SerieComponentAttribute>(); + if (attr.Contains(type)) + { + return true; + } + } + return false; + } + + public ISerieComponent GetComponent(Type type) + { + if (GetType().IsDefined(typeof(SerieComponentAttribute), false)) + { + var attr = GetType().GetAttribute<SerieComponentAttribute>(); + if (attr.Contains(type)) + { + var fieldName = string.Empty; + if (extraComponentMap.TryGetValue(type, out fieldName)) + { + var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic); + if (ReflectionUtil.InvokeListCount(this, field) > 0) + { + return ReflectionUtil.InvokeListGet<ISerieComponent>(this, field, 0); + } + } + } + } + return null; + } + + public ISerieComponent EnsureComponent(Type type) + { + if (GetType().IsDefined(typeof(SerieComponentAttribute), false)) + { + var attr = GetType().GetAttribute<SerieComponentAttribute>(); if (attr.Contains(type)) { var fieldName = string.Empty; @@ -99,32 +160,32 @@ namespace XCharts.Runtime var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic); if (ReflectionUtil.InvokeListCount(this, field) <= 0) { - var extraComponent = Activator.CreateInstance(type) as ISerieExtraComponent; + var extraComponent = Activator.CreateInstance(type) as ISerieComponent; ReflectionUtil.InvokeListAdd(this, field, extraComponent); SetAllDirty(); return extraComponent; } else { - return ReflectionUtil.InvokeListGet<ISerieExtraComponent>(this, field, 0); + return ReflectionUtil.InvokeListGet<ISerieComponent>(this, field, 0); } } } } - throw new System.Exception(string.Format("Serie {0} not support extra component: {1}", + throw new System.Exception(string.Format("Serie {0} not support component: {1}", GetType().Name, type.Name)); } - public void RemoveExtraComponent<T>() where T : ISerieExtraComponent + public void RemoveComponent<T>() where T : ISerieComponent { - RemoveExtraComponent(typeof(T)); + RemoveComponent(typeof(T)); } - public void RemoveExtraComponent(Type type) + public void RemoveComponent(Type type) { - if (GetType().IsDefined(typeof(SerieExtraComponentAttribute), false)) + if (GetType().IsDefined(typeof(SerieComponentAttribute), false)) { - var attr = GetType().GetAttribute<SerieExtraComponentAttribute>(); + var attr = GetType().GetAttribute<SerieComponentAttribute>(); if (attr.Contains(type)) { var fieldName = string.Empty; @@ -137,17 +198,6 @@ namespace XCharts.Runtime } } } - throw new System.Exception(string.Format("Serie {0} not support extra component: {1}", - GetType().Name, type.Name)); - } - - private void RemoveExtraComponentList<T>(List<T> list) where T : ISerieExtraComponent - { - if (list.Count > 0) - { - list.Clear(); - SetAllDirty(); - } } } } \ No newline at end of file diff --git a/Runtime/Serie/SerieData.cs b/Runtime/Serie/SerieData.cs index 081cf9b2..226ee361 100644 --- a/Runtime/Serie/SerieData.cs +++ b/Runtime/Serie/SerieData.cs @@ -234,71 +234,157 @@ namespace XCharts.Runtime m_SelectStyles.Clear(); } + [Obsolete("GetOrAddComponent is obsolete. Use EnsureComponent instead.")] public T GetOrAddComponent<T>() where T : ChildComponent, ISerieDataComponent { - return GetOrAddComponent(typeof(T)) as T; + return EnsureComponent<T>(); } - public ISerieDataComponent GetOrAddComponent(Type type) + /// <summary> + /// Get the component of the serie data. return null if not exist. + /// |获取数据项的指定类型的组件,如果不存在则返回null。 + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public T GetComponent<T>() where T : ChildComponent, ISerieDataComponent + { + return GetComponentInternal(typeof(T), false) as T; + } + + /// <summary> + /// Ensure the serie data has the component, if not, add it. + /// |确保数据项有指定类型的组件,如果没有则添加。 + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + [Since("v3.6.0")] + public T EnsureComponent<T>() where T : ChildComponent, ISerieDataComponent + { + return GetComponentInternal(typeof(T), true) as T; + } + + /// <summary> + /// Ensure the serie data has the component, if not, add it. + /// |确保数据项有指定类型的组件,如果没有则添加。 + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + [Since("v3.6.0")] + public ISerieDataComponent EnsureComponent(Type type) + { + return GetComponentInternal(type, true); + } + + private ISerieDataComponent GetComponentInternal(Type type, bool addIfNotExist) { if (type == typeof(ItemStyle)) { if (m_ItemStyles.Count == 0) - m_ItemStyles.Add(new ItemStyle() { show = true }); + { + if (addIfNotExist) + m_ItemStyles.Add(new ItemStyle() { show = true }); + else + return null; + } return m_ItemStyles[0]; } else if (type == typeof(LabelStyle)) { if (m_Labels.Count == 0) - m_Labels.Add(new LabelStyle() { show = true }); + { + if (addIfNotExist) + m_Labels.Add(new LabelStyle() { show = true }); + else + return null; + } return m_Labels[0]; } else if (type == typeof(LabelLine)) { if (m_LabelLines.Count == 0) - m_LabelLines.Add(new LabelLine() { show = true }); + { + if (addIfNotExist) + m_LabelLines.Add(new LabelLine() { show = true }); + else + return null; + } return m_LabelLines[0]; } else if (type == typeof(EmphasisStyle)) { if (m_EmphasisStyles.Count == 0) - m_EmphasisStyles.Add(new EmphasisStyle() { show = true }); + { + if (addIfNotExist) + m_EmphasisStyles.Add(new EmphasisStyle() { show = true }); + else + return null; + } return m_EmphasisStyles[0]; } else if (type == typeof(BlurStyle)) { if (m_BlurStyles.Count == 0) - m_BlurStyles.Add(new BlurStyle() { show = true }); + { + if (addIfNotExist) + m_BlurStyles.Add(new BlurStyle() { show = true }); + else + return null; + } return m_BlurStyles[0]; } else if (type == typeof(SelectStyle)) { if (m_SelectStyles.Count == 0) - m_SelectStyles.Add(new SelectStyle() { show = true }); + { + if (addIfNotExist) + m_SelectStyles.Add(new SelectStyle() { show = true }); + else + return null; + } return m_SelectStyles[0]; } else if (type == typeof(SerieSymbol)) { if (m_Symbols.Count == 0) - m_Symbols.Add(new SerieSymbol() { show = true }); + { + if (addIfNotExist) + m_Symbols.Add(new SerieSymbol() { show = true }); + else + return null; + } return m_Symbols[0]; } else if (type == typeof(LineStyle)) { if (m_LineStyles.Count == 0) - m_LineStyles.Add(new LineStyle() { show = true }); + { + if (addIfNotExist) + m_LineStyles.Add(new LineStyle() { show = true }); + else + return null; + } return m_LineStyles[0]; } else if (type == typeof(AreaStyle)) { if (m_AreaStyles.Count == 0) - m_AreaStyles.Add(new AreaStyle() { show = true }); + { + if (addIfNotExist) + m_AreaStyles.Add(new AreaStyle() { show = true }); + else + return null; + } return m_AreaStyles[0]; } else if (type == typeof(TitleStyle)) { if (m_TitleStyles.Count == 0) - m_TitleStyles.Add(new TitleStyle() { show = true }); + { + if (addIfNotExist) + m_TitleStyles.Add(new TitleStyle() { show = true }); + else + return null; + } return m_TitleStyles[0]; } else