From 78923ede3a8d432b02c20d0f13ce17f1d5f2bac9 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 20 Jun 2021 20:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E6=96=B0Axis?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=92=8C=E5=9B=BE=E6=A0=87=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation/XChartsAPI.md | 8 +++- Runtime/API/CoordinateChart_API.cs | 63 ++++++++++++++++++++++++++++++ Runtime/Component/Main/Axis.cs | 32 +++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/Documentation/XChartsAPI.md b/Documentation/XChartsAPI.md index cf2fe4ae..f61b299f 100644 --- a/Documentation/XChartsAPI.md +++ b/Documentation/XChartsAPI.md @@ -84,8 +84,12 @@ * `CoordinateChart.ClearAxisData()`:清除所有x轴和y轴的类目数据。 * `CoordinateChart.AddXAxisData(string category, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。 * `CoordinateChart.AddYAxisData(string category, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。 -* `CoordinateChart.AddXAxisIcon(Sprite icon, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。 -* `CoordinateChart.AddYAxisIcon(Sprite icon, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。。 +* `CoordinateChart.AddXAxisIcon(Sprite icon, int xAxisIndex = 0)`:添加一个图标到指定的 `X` 轴。 +* `CoordinateChart.AddYAxisIcon(Sprite icon, int yAxisIndex = 0)`:添加一个图标到指定的 `Y` 轴。 +* `CoordinateChart.UpdateXAxisData(int index, string category, int xAxisIndex = 0)`:更新 `X` 轴的类目数据。 +* `CoordinateChart.UpdateYAxisData(int index, string category, int yAxisIndex = 0)`:更新 `Y` 轴的类目数据。 +* `CoordinateChart.UpdateXAxisIcon(int index, Sprite icon, int xAxisIndex = 0)`:更新 `X` 轴的图标。 +* `CoordinateChart.UpdateYAxisIcon(int index, Sprite icon, int yAxisIndex = 0)`:更新 `Y` 轴的图标。 * `CoordinateChart.IsValue()`:是否是纯数值坐标。 * `CoordinateChart.RefreshDataZoom()`:在下一帧刷新DataZoom组件。 diff --git a/Runtime/API/CoordinateChart_API.cs b/Runtime/API/CoordinateChart_API.cs index 64794a22..9e722170 100644 --- a/Runtime/API/CoordinateChart_API.cs +++ b/Runtime/API/CoordinateChart_API.cs @@ -107,6 +107,22 @@ namespace XCharts } } + /// + /// Update category data. + /// 更新X轴类目数据。 + /// + /// the index of category data + /// + /// which xAxis index to update to + public void UpdateXAxisData(int index, string category, int xAxisIndex = 0) + { + var xAxis = GetXAxis(xAxisIndex); + if (xAxis != null) + { + xAxis.UpdateData(index, category); + } + } + /// /// Add an icon to xAxis. /// 添加一个图标到指定的x轴。 @@ -122,6 +138,22 @@ namespace XCharts } } + /// + /// Update xAxis icon. + /// 更新X轴图标。 + /// + /// + /// + /// + public void UdpateXAxisIcon(int index, Sprite icon, int xAxisIndex = 0) + { + var xAxis = GetXAxis(xAxisIndex); + if (xAxis != null) + { + xAxis.UpdateIcon(index, icon); + } + } + /// /// Add a category data to yAxis. /// 添加一个类目数据到指定的y轴。 @@ -137,6 +169,22 @@ namespace XCharts } } + /// + /// Update category data. + /// 更新Y轴类目数据。 + /// + /// the index of category data + /// + /// which yAxis index to update to + public void UpdateYAxisData(int index, string category, int yAxisIndex = 0) + { + var yAxis = GetYAxis(yAxisIndex); + if (yAxis != null) + { + yAxis.UpdateData(index, category); + } + } + /// /// Add an icon to yAxis. /// 添加一个图标到指定的y轴。 @@ -152,6 +200,21 @@ namespace XCharts } } + /// + /// 更新Y轴图标。 + /// + /// + /// + /// + public void UpdateYAxisIcon(int index, Sprite icon, int yAxisIndex = 0) + { + var yAxis = GetYAxis(yAxisIndex); + if (yAxis != null) + { + yAxis.UpdateIcon(index, icon); + } + } + /// /// reutrn true when all the show axis is `Value` type. /// 纯数值坐标轴(数值轴或对数轴)。 diff --git a/Runtime/Component/Main/Axis.cs b/Runtime/Component/Main/Axis.cs index 59a9e197..07a7a348 100644 --- a/Runtime/Component/Main/Axis.cs +++ b/Runtime/Component/Main/Axis.cs @@ -586,6 +586,24 @@ namespace XCharts SetAllDirty(); } + /// + /// 更新类目数据 + /// + /// + /// + public void UpdateData(int index, string category) + { + if (index >= 0 && index < m_Data.Count) + { + m_Data[index] = category; + SetComponentDirty(); + } + } + + /// + /// 添加图标 + /// + /// public void AddIcon(Sprite icon) { if (maxCache > 0) @@ -600,6 +618,20 @@ namespace XCharts SetAllDirty(); } + /// + /// 更新图标 + /// + /// + /// + public void UpdateIcon(int index, Sprite icon) + { + if (index >= 0 && index < m_Icons.Count) + { + m_Icons[index] = icon; + SetComponentDirty(); + } + } + /// /// 获得指定索引的类目数据 ///