From e00fd46bdfa1a62f10d47fcf140d1dd98b759063 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 10 Jun 2020 13:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSerieData=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E6=97=B6=E9=83=A8=E5=88=86=E9=85=8D=E7=BD=AE=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/Runtime/Example31_PieUpdateName.cs | 21 +++++++++++---- Runtime/Component/Sub/Emphasis.cs | 8 ++++++ Runtime/Component/Sub/IconStyle.cs | 12 +++++++++ Runtime/Component/Sub/ItemStyle.cs | 21 +++++++++++++++ Runtime/Component/Sub/SerieData.cs | 9 ++++++- Runtime/Component/Sub/SerieLabel.cs | 29 ++++++++++++++++++++- Runtime/Internal/Pools/SerieDataPool.cs | 2 +- 7 files changed, 94 insertions(+), 8 deletions(-) diff --git a/Examples/Runtime/Example31_PieUpdateName.cs b/Examples/Runtime/Example31_PieUpdateName.cs index 159b40e8..e8e49edc 100644 --- a/Examples/Runtime/Example31_PieUpdateName.cs +++ b/Examples/Runtime/Example31_PieUpdateName.cs @@ -15,7 +15,6 @@ namespace XCharts.Examples public class Example31_PieUpdateName : MonoBehaviour { PieChart chart; - int count = 0; void Awake() { @@ -35,9 +34,9 @@ namespace XCharts.Examples { if (Input.GetKeyDown(KeyCode.Space)) { - if (count % 2 == 0) ResetSameName(); - else UpdateDataName(); - count++; + ClearAndAddData(); + //UpdateDataName(); + //UpdateDataName(); } } @@ -63,7 +62,19 @@ namespace XCharts.Examples { chart.UpdateDataName(serieIndex, i, "piename"); } - chart.themeInfo.SetAllDirty(); + } + + void ClearAndAddData() + { + var serieIndex = 0; + var serie = chart.series.GetSerie(serieIndex); + if (serie == null) return; + int count = serie.dataCount; + serie.ClearData(); + for (int i = 0; i < count; i++) + { + chart.AddData(0, Random.Range(0, 100), "pie" + i); + } } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/Emphasis.cs b/Runtime/Component/Sub/Emphasis.cs index 49d5938d..0b734981 100644 --- a/Runtime/Component/Sub/Emphasis.cs +++ b/Runtime/Component/Sub/Emphasis.cs @@ -19,6 +19,14 @@ namespace XCharts [SerializeField] private bool m_Show; [SerializeField] private SerieLabel m_Label = new SerieLabel(); [SerializeField] private ItemStyle m_ItemStyle = new ItemStyle(); + + public void Reset() + { + m_Show = false; + m_Label.Reset(); + m_ItemStyle.Reset(); + } + /// /// 是否启用高亮样式。 /// diff --git a/Runtime/Component/Sub/IconStyle.cs b/Runtime/Component/Sub/IconStyle.cs index 73ed4a6c..9c5a7730 100644 --- a/Runtime/Component/Sub/IconStyle.cs +++ b/Runtime/Component/Sub/IconStyle.cs @@ -29,6 +29,16 @@ namespace XCharts [SerializeField] private float m_Height = 40; [SerializeField] private Vector3 m_Offset; + public void Reset() + { + m_Show = false; + m_Layer = Layer.UnderLabel; + m_Sprite = null; + m_Color = Color.white; + m_Width = 40; + m_Height = 40; + m_Offset = Vector3.zero; + } /// /// Whether the data icon is show. /// 是否显示图标。 @@ -59,5 +69,7 @@ namespace XCharts /// 图标偏移。 /// public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } } + + } } diff --git a/Runtime/Component/Sub/ItemStyle.cs b/Runtime/Component/Sub/ItemStyle.cs index 10d3b99a..f2bd51ce 100644 --- a/Runtime/Component/Sub/ItemStyle.cs +++ b/Runtime/Component/Sub/ItemStyle.cs @@ -50,6 +50,27 @@ namespace XCharts [SerializeField] private string m_NumericFormatter = ""; [SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 }; + public void Reset() + { + m_Show = false; + m_Color = Color.clear; + m_ToColor = Color.clear; + m_BackgroundColor = Color.clear; + m_BackgroundWidth = 0; + m_CenterColor = Color.clear; + m_CenterGap = 0; + m_BorderType = Type.Solid; + m_BorderWidth = 0; + m_BorderColor = Color.clear; + m_Opacity = 1; + m_TooltipFormatter = null; + m_NumericFormatter = ""; + m_CornerRadius[0] = 0; + m_CornerRadius[1] = 0; + m_CornerRadius[2] = 0; + m_CornerRadius[3] = 0; + } + /// /// 是否启用。 /// diff --git a/Runtime/Component/Sub/SerieData.cs b/Runtime/Component/Sub/SerieData.cs index d9c3747a..f080be7e 100644 --- a/Runtime/Component/Sub/SerieData.cs +++ b/Runtime/Component/Sub/SerieData.cs @@ -162,15 +162,22 @@ namespace XCharts private List m_DataUpdateTime = new List(); private List m_DataUpdateFlag = new List(); - public void Clear() + public void Reset() { + index = 0; + labelObject = null; m_Name = string.Empty; m_Selected = false; + m_CanShowLabel = false; m_Radius = 0; m_Data.Clear(); m_PreviousData.Clear(); m_DataUpdateTime.Clear(); m_DataUpdateFlag.Clear(); + m_IconStyle.Reset(); + m_Label.Reset(); + m_ItemStyle.Reset(); + m_Emphasis.Reset(); } public float GetData(int index, bool inverse = false) diff --git a/Runtime/Component/Sub/SerieLabel.cs b/Runtime/Component/Sub/SerieLabel.cs index 66e80d14..9cb4a032 100644 --- a/Runtime/Component/Sub/SerieLabel.cs +++ b/Runtime/Component/Sub/SerieLabel.cs @@ -79,7 +79,7 @@ namespace XCharts HorizontalLine } [SerializeField] private bool m_Show = false; - [SerializeField] Position m_Position; + [SerializeField] Position m_Position = Position.Outside; [SerializeField] private Vector3 m_Offset; [SerializeField] private float m_Margin; [SerializeField] private string m_Formatter; @@ -104,6 +104,33 @@ namespace XCharts [SerializeField] private string m_NumericFormatter = ""; [SerializeField] private bool m_AutoOffset = false; + public void Reset() + { + m_Show = false; + m_Position = Position.Outside; + m_Offset = Vector3.zero; + m_Margin = 0; + m_PaddingLeftRight = 2f; + m_PaddingTopBottom = 2f; + m_Color = Color.clear; + m_BackgroundColor = Color.clear; + m_BackgroundWidth = 0; + m_BackgroundHeight = 0; + m_FontSize = 18; + m_FontStyle = FontStyle.Normal; + m_Line = true; + m_LineType = LineType.BrokenLine; + m_LineColor = Color.clear; + m_LineWidth = 1.0f; + m_LineLength1 = 25f; + m_LineLength2 = 15f; + m_Border = false; + m_BorderWidth = 0.5f; + m_BorderColor = Color.grey; + m_NumericFormatter = ""; + m_AutoOffset = false; + } + /// /// Whether the label is showed. /// 是否显示文本标签。 diff --git a/Runtime/Internal/Pools/SerieDataPool.cs b/Runtime/Internal/Pools/SerieDataPool.cs index f176f624..1328429f 100644 --- a/Runtime/Internal/Pools/SerieDataPool.cs +++ b/Runtime/Internal/Pools/SerieDataPool.cs @@ -19,7 +19,7 @@ namespace XCharts static void OnClear(SerieData serieData) { - serieData.Clear(); + serieData.Reset(); } public static SerieData Get()