From 5745fea9a182aa4b27a96a26c915bd880de80002 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 4 Mar 2022 22:17:32 +0800 Subject: [PATCH] 3.0 - optimize code --- CHANGELOG-EN.md | 2 +- CHANGELOG.md | 2 +- Documentation/XCharts配置项手册.md | 2 +- Documentation/xcharts-configuration-EN.md | 4 +- Editor/Charts/BaseChartEditor.cs | 4 +- Editor/ChildComponents/AreaStyleDrawer.cs | 1 - Editor/ChildComponents/DebugInfoDrawer.cs | 2 +- Editor/ChildComponents/ItemStyleDrawer.cs | 1 - Editor/ChildComponents/LevelStyleDrawer.cs | 38 +++++ .../ChildComponents/LevelStyleDrawer.cs.meta | 11 ++ Editor/ChildComponents/SymbolStyleDrawer.cs | 2 +- Editor/Series/PieEditor.cs | 2 +- Editor/Series/RingEditor.cs | 2 +- Editor/Series/SerieEditor.cs | 14 +- Examples/Runtime/Example03_ChartAnimation.cs | 4 +- Examples/Runtime/Example12_CustomDrawing.cs | 8 +- Examples/Runtime/Example30_PieChart.cs | 4 +- Examples/Runtime/Example50_Scatter.cs | 4 +- Runtime/Component/Animation/AnimationStyle.cs | 27 ++-- Runtime/Component/Axis/AxisHandler.cs | 32 ++-- Runtime/Component/Axis/AxisHelper.cs | 2 + Runtime/Component/Axis/AxisLabel.cs | 4 +- Runtime/Component/Axis/XAxis/XAxisHander.cs | 4 +- Runtime/Component/Axis/YAxis/YAxisHander.cs | 5 +- Runtime/Component/Child/AreaStyle.cs | 9 -- Runtime/Component/Child/IconStyle.cs | 2 +- Runtime/Component/Child/ItemStyle.cs | 36 +---- Runtime/Component/Child/LabelStyle.cs | 4 +- Runtime/Component/Child/LevelStyle.cs | 33 +++++ Runtime/Component/Child/LevelStyle.cs.meta | 11 ++ Runtime/Component/Child/SymbolStyle.cs | 51 +++---- Runtime/Component/Debug/DebugInfo.cs | 4 +- Runtime/Component/Tooltip/TooltipHelper.cs | 1 - Runtime/Helper/SerieHelper.cs | 1 + Runtime/Internal/BaseChart.API.cs | 14 +- Runtime/Internal/BaseChart.Serie.cs | 42 +++--- Runtime/Internal/BaseChart.cs | 39 ++--- Runtime/Internal/BaseGraph.API.cs | 2 +- Runtime/Internal/BaseGraph.cs | 4 +- Runtime/Internal/Basic/BaseSerie.cs | 15 +- Runtime/Internal/Basic/ChildComponent.cs | 2 +- Runtime/Internal/Misc/DelegateFunction.cs | 16 +- Runtime/Internal/Utilities/ChartCached.cs | 10 -- Runtime/Internal/Utilities/ChartHelper.cs | 21 +-- Runtime/Internal/Utilities/ComponentHelper.cs | 27 +--- Runtime/Internal/XChartsMgr.cs | 2 +- Runtime/Serie/Bar/BarHandler.cs | 91 ++++++------ Runtime/Serie/Bar/SimplifiedBarHandler.cs | 46 +++--- .../Serie/Candlestick/CandlestickHandler.cs | 12 +- .../SimplifiedCandlestickHandler.cs | 12 +- Runtime/Serie/Pie/PieHandler.cs | 4 +- Runtime/Serie/Ring/Ring.cs | 1 + Runtime/Serie/Ring/RingHandler.cs | 2 +- Runtime/Serie/Serie.cs | 137 ++++++++---------- Runtime/Serie/SerieContext.cs | 1 + Runtime/Serie/SerieData.cs | 21 ++- Runtime/Serie/SerieDataContext.cs | 2 + Runtime/Serie/SerieHandler.cs | 33 +++-- Runtime/XUGL/UGL.cs | 28 ++-- 59 files changed, 482 insertions(+), 435 deletions(-) create mode 100644 Editor/ChildComponents/LevelStyleDrawer.cs create mode 100644 Editor/ChildComponents/LevelStyleDrawer.cs.meta create mode 100644 Runtime/Component/Child/LevelStyle.cs create mode 100644 Runtime/Component/Child/LevelStyle.cs.meta diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index 61145d06..18bab5a4 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -263,7 +263,7 @@ Since the data type is upgraded to `double`, the implicit conversion of `float` * (2020.05.30) 优化`PieChart`支持设置`ignoreValue`不显示指定数据 * (2020.05.30) 修复`RadarChart`为`Circle`时不绘制`SplitArea`的问题 * (2020.05.30) 优化`RadarChart`在设置`max`为`0`时可自动刷新最大值 -* (2020.05.29) 修复`PieChart`设置`space`时只有一个数据时绘制异常的问题 +* (2020.05.29) 修复`PieChart`设置`gap`时只有一个数据时绘制异常的问题 * (2020.05.27) 修复调用`UpdateDataName()`接口时不会自动刷新的问题 * (2020.05.27) 优化`柱状图`的渐变色效果 * (2020.05.24) 修复`Axis`同时设置`boundaryGap`和`alignWithLabel`时`Tick`绘制异常的问题 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ec80275..c5bd7eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -267,7 +267,7 @@ * (2020.05.30) 优化`PieChart`支持设置`ignoreValue`不显示指定数据 * (2020.05.30) 修复`RadarChart`为`Circle`时不绘制`SplitArea`的问题 * (2020.05.30) 优化`RadarChart`在设置`max`为`0`时可自动刷新最大值 -* (2020.05.29) 修复`PieChart`设置`space`时只有一个数据时绘制异常的问题 +* (2020.05.29) 修复`PieChart`设置`gap`时只有一个数据时绘制异常的问题 * (2020.05.27) 修复调用`UpdateDataName()`接口时不会自动刷新的问题 * (2020.05.27) 优化`柱状图`的渐变色效果 * (2020.05.24) 修复`Axis`同时设置`boundaryGap`和`alignWithLabel`时`Tick`绘制异常的问题 diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index ddd21a88..55afed4e 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -638,7 +638,7 @@ * `None`:不展示成南丁格尔玫瑰图。 * `Radius`:扇区圆心角展现数据的百分比,半径展现数据的大小。 * `Area`:所有扇区圆心角相同,仅通过半径展现数据大小。 -* `space`:扇区间隙。 +* `gap`:扇区间隙。 * `center`:中心点坐标。当值为`0-1`的浮点数时表示百分比。 * `radius`:半径。`radius[0]`为内径,`radius[1]`为外径。当内径大于0时即为圆环图。 * `minAngle`:最小的扇区角度(0-360)。用于防止某个值过小导致扇区太小影响交互。 diff --git a/Documentation/xcharts-configuration-EN.md b/Documentation/xcharts-configuration-EN.md index b7d59904..fb6245ed 100644 --- a/Documentation/xcharts-configuration-EN.md +++ b/Documentation/xcharts-configuration-EN.md @@ -212,7 +212,7 @@ The component of settings related to text. * `font`: the font of text. When `null`, the theme's font is used by default. [default: `null`]. * `fontSize`: the size of text. [default: `18`]. * `fontStyle`: the font style of text. [default: `FontStyle.Normal`]. -* `lineSpacing`: the space of text line. [default: `1f`]. +* `lineSpacing`: the gap of text line. [default: `1f`]. * `autoWrap`: Whether to wrap lines. * `autoAlign`: Whether to let the system automatically set alignment. If true, the system automatically selects alignment, and if false, use alignment. @@ -531,7 +531,7 @@ Line chart serie. * `None`: 不展示成南丁格尔玫瑰图。 * `Radius`: 扇区圆心角展现数据的百分比,半径展现数据的大小。 * `Area`: 所有扇区圆心角相同,仅通过半径展现数据大小。 -* `space`: 扇区间隙。 +* `gap`: 扇区间隙。 * `center`: 中心点坐标。当值为`0-1`的浮点数时表示百分比。 * `radius`: 半径。`radius[0]`为内径,`radius[1]`为外径。当内径大于0时即为圆环图。 * `minAngle`: The minimum angle of sector(0-360). It prevents some sector from being too small when value is small. diff --git a/Editor/Charts/BaseChartEditor.cs b/Editor/Charts/BaseChartEditor.cs index 7b152cf5..e087159d 100644 --- a/Editor/Charts/BaseChartEditor.cs +++ b/Editor/Charts/BaseChartEditor.cs @@ -167,7 +167,7 @@ namespace XCharts.Editor { sb.Length = 0; sb.AppendFormat("v{0}", XChartsMgr.fullVersion); - //if(m_EnableTextMeshPro.boolValue) + if(m_EnableTextMeshPro.boolValue) sb.Append("-tmp"); EditorGUILayout.HelpBox(sb.ToString(), MessageType.None); } @@ -265,7 +265,7 @@ namespace XCharts.Editor } if (GUILayout.Button("Reinit Component")) { - m_Chart.ReinitAllChartComponent(); + m_Chart.RemoveAndReinitChartObject(); } if (m_CheckWarning) { diff --git a/Editor/ChildComponents/AreaStyleDrawer.cs b/Editor/ChildComponents/AreaStyleDrawer.cs index 488d5cea..4aaa81e8 100644 --- a/Editor/ChildComponents/AreaStyleDrawer.cs +++ b/Editor/ChildComponents/AreaStyleDrawer.cs @@ -21,7 +21,6 @@ namespace XCharts.Editor PropertyField(prop, "m_HighlightColor"); PropertyField(prop, "m_HighlightToColor"); PropertyField(prop, "m_Opacity"); - PropertyField(prop, "m_TooltipHighlight"); --EditorGUI.indentLevel; } } diff --git a/Editor/ChildComponents/DebugInfoDrawer.cs b/Editor/ChildComponents/DebugInfoDrawer.cs index 0ddd25c6..b5a618a4 100644 --- a/Editor/ChildComponents/DebugInfoDrawer.cs +++ b/Editor/ChildComponents/DebugInfoDrawer.cs @@ -17,7 +17,7 @@ namespace XCharts.Editor ++EditorGUI.indentLevel; PropertyField(prop, "m_FoldSeries"); PropertyField(prop, "m_ShowDebugInfo"); - PropertyField(prop, "m_ShowAllChildObject"); + PropertyField(prop, "m_ShowAllChartObject"); PropertyField(prop, "m_DebugInfoTextStyle"); --EditorGUI.indentLevel; } diff --git a/Editor/ChildComponents/ItemStyleDrawer.cs b/Editor/ChildComponents/ItemStyleDrawer.cs index 84100a74..34eebabf 100644 --- a/Editor/ChildComponents/ItemStyleDrawer.cs +++ b/Editor/ChildComponents/ItemStyleDrawer.cs @@ -23,7 +23,6 @@ namespace XCharts.Editor PropertyField(prop, "m_BackgroundWidth"); PropertyField(prop, "m_CenterColor"); PropertyField(prop, "m_CenterGap"); - PropertyField(prop, "m_BorderType"); PropertyField(prop, "m_BorderWidth"); PropertyField(prop, "m_BorderColor"); PropertyField(prop, "m_BorderColor0"); diff --git a/Editor/ChildComponents/LevelStyleDrawer.cs b/Editor/ChildComponents/LevelStyleDrawer.cs new file mode 100644 index 00000000..acca8caf --- /dev/null +++ b/Editor/ChildComponents/LevelStyleDrawer.cs @@ -0,0 +1,38 @@ + +using UnityEditor; +using UnityEngine; +using XCharts.Runtime; + +namespace XCharts.Editor +{ + [CustomPropertyDrawer(typeof(LevelStyle), true)] + public class LevelStyleDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "LevelStyle"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeComponentFoldout(prop, "m_Show")) + { + ++EditorGUI.indentLevel; + PropertyListField(prop, "m_Levels"); + --EditorGUI.indentLevel; + } + } + } + + [CustomPropertyDrawer(typeof(Level), true)] + public class LevelDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "Level"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Label"); + PropertyField(prop, "m_UpperLabel"); + PropertyField(prop, "m_ItemStyle"); + --EditorGUI.indentLevel; + } + } +} \ No newline at end of file diff --git a/Editor/ChildComponents/LevelStyleDrawer.cs.meta b/Editor/ChildComponents/LevelStyleDrawer.cs.meta new file mode 100644 index 00000000..37b74c7a --- /dev/null +++ b/Editor/ChildComponents/LevelStyleDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a1ff119a53a44e5abe2ef6f57816aa6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ChildComponents/SymbolStyleDrawer.cs b/Editor/ChildComponents/SymbolStyleDrawer.cs index f7f15cec..fe1c1cdc 100644 --- a/Editor/ChildComponents/SymbolStyleDrawer.cs +++ b/Editor/ChildComponents/SymbolStyleDrawer.cs @@ -39,7 +39,7 @@ namespace XCharts.Editor PropertyField(prop, "m_DataScale"); PropertyField(prop, "m_SelectedDataScale"); break; - case SymbolSizeType.Callback: + case SymbolSizeType.Function: break; } PropertyField(prop, "m_StartIndex"); diff --git a/Editor/Series/PieEditor.cs b/Editor/Series/PieEditor.cs index 906e1ab3..393b85c5 100644 --- a/Editor/Series/PieEditor.cs +++ b/Editor/Series/PieEditor.cs @@ -8,7 +8,7 @@ namespace XCharts.Editor public override void OnCustomInspectorGUI() { PropertyField("m_RoseType"); - PropertyField("m_Space"); + PropertyField("m_Gap"); PropertyTwoFiled("m_Center"); PropertyTwoFiled("m_Radius"); diff --git a/Editor/Series/RingEditor.cs b/Editor/Series/RingEditor.cs index ade67210..71ec6db6 100644 --- a/Editor/Series/RingEditor.cs +++ b/Editor/Series/RingEditor.cs @@ -10,7 +10,7 @@ namespace XCharts.Editor PropertyTwoFiled("m_Center"); PropertyTwoFiled("m_Radius"); PropertyField("m_StartAngle"); - PropertyField("m_RingGap"); + PropertyField("m_Gap"); PropertyField("m_RoundCap"); PropertyField("m_Clockwise"); diff --git a/Editor/Series/SerieEditor.cs b/Editor/Series/SerieEditor.cs index ca912d0b..7d006c7d 100644 --- a/Editor/Series/SerieEditor.cs +++ b/Editor/Series/SerieEditor.cs @@ -75,7 +75,7 @@ namespace XCharts.Editor while (listSize > m_Datas.arraySize) m_Datas.arraySize++; while (listSize < m_Datas.arraySize) m_Datas.arraySize--; } - if (listSize > 30 && !XCSettings.editorShowAllListData) + if (listSize > 30)// && !XCSettings.editorShowAllListData) { int num = listSize > 10 ? 10 : listSize; for (int i = 0; i < num; i++) @@ -191,10 +191,10 @@ namespace XCharts.Editor { EditorGUI.indentLevel++; var serieData = m_Datas.GetArrayElementAtIndex(index); - var sereName = serieData.FindPropertyRelative("m_Name"); - var selected = serieData.FindPropertyRelative("m_Selected"); + var m_Name = serieData.FindPropertyRelative("m_Name"); + var m_Id = serieData.FindPropertyRelative("m_Id"); + var m_ParentId = serieData.FindPropertyRelative("m_ParentId"); - var m_Ignore = serieData.FindPropertyRelative("m_Ignore"); var m_IconStyle = serieData.FindPropertyRelative("m_IconStyles"); var m_Label = serieData.FindPropertyRelative("m_Labels"); var m_ItemStyle = serieData.FindPropertyRelative("m_ItemStyles"); @@ -204,9 +204,9 @@ namespace XCharts.Editor var m_AreaStyle = serieData.FindPropertyRelative("m_AreaStyles"); var m_TitleStyle = serieData.FindPropertyRelative("m_TitleStyles"); - PropertyField(sereName); - PropertyField(selected); - PropertyField(m_Ignore); + PropertyField(m_Name); + PropertyField(m_Id); + PropertyField(m_ParentId); var componentNum = m_IconStyle.arraySize + m_Label.arraySize + m_ItemStyle.arraySize + m_Emphasis.arraySize + m_Symbol.arraySize + m_LineStyle.arraySize + m_AreaStyle.arraySize; diff --git a/Examples/Runtime/Example03_ChartAnimation.cs b/Examples/Runtime/Example03_ChartAnimation.cs index 98206825..2ba253ee 100644 --- a/Examples/Runtime/Example03_ChartAnimation.cs +++ b/Examples/Runtime/Example03_ChartAnimation.cs @@ -20,9 +20,9 @@ namespace XCharts.Example var serie = chart.GetSerie(0); serie.animation.enable = true; //自定义每个数据项的渐入延时 - serie.animation.customFadeInDelay = CustomFadeInDelay; + serie.animation.fadeInDelayFunction = CustomFadeInDelay; //自定义每个数据项的渐入时长 - serie.animation.customFadeInDuration = CustomFadeInDuration; + serie.animation.fadeInDurationFunction = CustomFadeInDuration; } float CustomFadeInDelay(int dataIndex) diff --git a/Examples/Runtime/Example12_CustomDrawing.cs b/Examples/Runtime/Example12_CustomDrawing.cs index dbcf6505..3f19c62a 100644 --- a/Examples/Runtime/Example12_CustomDrawing.cs +++ b/Examples/Runtime/Example12_CustomDrawing.cs @@ -17,15 +17,15 @@ namespace XCharts.Example chart = gameObject.GetComponent(); if (chart == null) return; - chart.onCustomDraw = delegate (VertexHelper vh) + chart.onDraw = delegate (VertexHelper vh) { }; // or - chart.onCustomDrawBeforeSerie = delegate (VertexHelper vh, Serie serie) + chart.onDrawBeforeSerie = delegate (VertexHelper vh, Serie serie) { }; // or - chart.onCustomDrawAfterSerie = delegate (VertexHelper vh, Serie serie) + chart.onDrawAfterSerie = delegate (VertexHelper vh, Serie serie) { if (serie.index != 0) return; var dataPoints = serie.context.dataPoints; @@ -41,7 +41,7 @@ namespace XCharts.Example } }; // or - chart.onCustomDrawTop = delegate (VertexHelper vh) + chart.onDrawTop = delegate (VertexHelper vh) { }; } diff --git a/Examples/Runtime/Example30_PieChart.cs b/Examples/Runtime/Example30_PieChart.cs index c7d8981d..e6a9434d 100644 --- a/Examples/Runtime/Example30_PieChart.cs +++ b/Examples/Runtime/Example30_PieChart.cs @@ -114,7 +114,7 @@ namespace XCharts.Example chart.RefreshChart(); yield return null; } - serie.pieSpace = 1f; + serie.gap = 1f; chart.RefreshChart(); yield return new WaitForSeconds(1); @@ -122,7 +122,7 @@ namespace XCharts.Example chart.RefreshChart(); yield return new WaitForSeconds(1); - serie.pieSpace = 0f; + serie.gap = 0f; serie.data[0].selected = false; chart.RefreshChart(); yield return new WaitForSeconds(1); diff --git a/Examples/Runtime/Example50_Scatter.cs b/Examples/Runtime/Example50_Scatter.cs index 1894bdd9..f2ddb276 100644 --- a/Examples/Runtime/Example50_Scatter.cs +++ b/Examples/Runtime/Example50_Scatter.cs @@ -18,8 +18,8 @@ namespace XCharts.Example if (chart == null) return; foreach (var serie in chart.series) { - serie.symbol.sizeCallback = SymbolSize; - serie.symbol.selectedSizeCallback = SymbolSelectedSize; + serie.symbol.sizeFunction = SymbolSize; + serie.symbol.selectedSizeFunction = SymbolSelectedSize; } } diff --git a/Runtime/Component/Animation/AnimationStyle.cs b/Runtime/Component/Animation/AnimationStyle.cs index e568fdac..82e846cd 100644 --- a/Runtime/Component/Animation/AnimationStyle.cs +++ b/Runtime/Component/Animation/AnimationStyle.cs @@ -5,9 +5,6 @@ using System; namespace XCharts.Runtime { - public delegate float CustomAnimationDelay(int dataIndex); - public delegate float CustomAnimationDuration(int dataIndex); - public enum AnimationType { /// @@ -69,19 +66,19 @@ namespace XCharts.Runtime /// /// 自定义渐入动画延时函数。返回ms值。 /// - public CustomAnimationDelay customFadeInDelay; + public AnimationDelayFunction fadeInDelayFunction; /// /// 自定义渐入动画时长函数。返回ms值。 /// - public CustomAnimationDuration customFadeInDuration; + public AnimationDurationFunction fadeInDurationFunction; /// /// 自定义渐出动画延时函数。返回ms值。 /// - public CustomAnimationDelay customFadeOutDelay; + public AnimationDelayFunction fadeOutDelayFunction; /// /// 自定义渐出动画时长函数。返回ms值。 /// - public CustomAnimationDuration customFadeOutDuration; + public AnimationDurationFunction fadeOutDurationFunction; public AnimationStyleContext context = new AnimationStyleContext(); /// @@ -390,10 +387,10 @@ namespace XCharts.Runtime public float GetIndexDelay(int dataIndex) { - if (m_FadeOut && customFadeOutDelay != null) - return customFadeOutDelay(dataIndex); - else if (m_FadeIn && customFadeInDelay != null) - return customFadeInDelay(dataIndex); + if (m_FadeOut && fadeOutDelayFunction != null) + return fadeOutDelayFunction(dataIndex); + else if (m_FadeIn && fadeInDelayFunction != null) + return fadeInDelayFunction(dataIndex); else return 0; } @@ -492,10 +489,10 @@ namespace XCharts.Runtime { if (dataIndex >= 0) { - if (m_FadeOut && customFadeOutDuration != null) - return customFadeOutDuration(dataIndex) / 1000f; - if (m_FadeIn && customFadeInDuration != null) - return customFadeInDuration(dataIndex) / 1000f; + if (m_FadeOut && fadeOutDurationFunction != null) + return fadeOutDurationFunction(dataIndex) / 1000f; + if (m_FadeIn && fadeInDurationFunction != null) + return fadeInDurationFunction(dataIndex) / 1000f; } if (m_FadeOut) diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 018e5f6d..0a8a4ee8 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -57,8 +57,8 @@ namespace XCharts axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j); if (j != lastPointerValue) { - if (chart.onUpdateAxisPointer != null) - chart.onUpdateAxisPointer(axis, j); + if (chart.onAxisPointerValueChanged != null) + chart.onAxisPointerValueChanged(axis, j); } break; } @@ -74,8 +74,8 @@ namespace XCharts axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j); if (j != lastPointerValue) { - if (chart.onUpdateAxisPointer != null) - chart.onUpdateAxisPointer(axis, j); + if (chart.onAxisPointerValueChanged != null) + chart.onAxisPointerValueChanged(axis, j); } break; } @@ -97,8 +97,8 @@ namespace XCharts axis.context.pointerLabelPosition = new Vector3(labelX, chart.pointerPos.y); if (yValue != lastPointerValue) { - if (chart.onUpdateAxisPointer != null) - chart.onUpdateAxisPointer(axis, yValue); + if (chart.onAxisPointerValueChanged != null) + chart.onAxisPointerValueChanged(axis, yValue); } } else @@ -114,8 +114,8 @@ namespace XCharts axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY); if (xValue != lastPointerValue) { - if (chart.onUpdateAxisPointer != null) - chart.onUpdateAxisPointer(axis, xValue); + if (chart.onAxisPointerValueChanged != null) + chart.onAxisPointerValueChanged(axis, xValue); } } } @@ -750,7 +750,7 @@ namespace XCharts } internal static void DrawAxisSplit(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom, - Orient orient, float startX, float startY, float axisLength, float splitLength) + Orient orient, float startX, float startY, float axisLength, float splitLength, Axis relativedAxis = null) { var lineColor = axis.splitLine.GetColor(theme.splitLineColor); var lineWidth = axis.splitLine.GetWidth(theme.lineWidth); @@ -803,6 +803,7 @@ namespace XCharts { if (orient == Orient.Horizonal) { + if (relativedAxis == null || MathUtil.Approximately(current, relativedAxis.context.x)) ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, @@ -812,12 +813,13 @@ namespace XCharts } else { - ChartDrawer.DrawLineStyle(vh, - lineType, - lineWidth, - new Vector3(startX, current), - new Vector3(startX + splitLength, current), - lineColor); + if (relativedAxis == null || MathUtil.Approximately(current, relativedAxis.context.y)) + ChartDrawer.DrawLineStyle(vh, + lineType, + lineWidth, + new Vector3(startX, current), + new Vector3(startX + splitLength, current), + lineColor); } } diff --git a/Runtime/Component/Axis/AxisHelper.cs b/Runtime/Component/Axis/AxisHelper.cs index 1002a6b4..4bddf213 100644 --- a/Runtime/Component/Axis/AxisHelper.cs +++ b/Runtime/Component/Axis/AxisHelper.cs @@ -81,6 +81,8 @@ namespace XCharts.Runtime { if (dataCount < 1) dataCount = 1; + if (axis.IsValue()) + return dataCount > 1 ? coordinateWidth / (dataCount - 1) : coordinateWidth; var categoryCount = axis.GetDataCount(dataZoom); int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1); segment = segment <= 0 ? dataCount : segment; diff --git a/Runtime/Component/Axis/AxisLabel.cs b/Runtime/Component/Axis/AxisLabel.cs index d44c4b3a..6b4be14f 100644 --- a/Runtime/Component/Axis/AxisLabel.cs +++ b/Runtime/Component/Axis/AxisLabel.cs @@ -26,7 +26,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_ShowEndLabel = true; [SerializeField] private TextLimit m_TextLimit = new TextLimit(); [SerializeField] private TextStyle m_TextStyle = new TextStyle(); - private DelegateAxisLabelFormatter m_FormatterFunction; + private AxisLabelFormatterFunction m_FormatterFunction; /// /// Set this to false to prevent the axis label from appearing. @@ -158,7 +158,7 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } } - public DelegateAxisLabelFormatter formatterFunction + public AxisLabelFormatterFunction formatterFunction { set { m_FormatterFunction = value; } } diff --git a/Runtime/Component/Axis/XAxis/XAxisHander.cs b/Runtime/Component/Axis/XAxis/XAxisHander.cs index 46fb9b77..c259e118 100644 --- a/Runtime/Component/Axis/XAxis/XAxisHander.cs +++ b/Runtime/Component/Axis/XAxis/XAxisHander.cs @@ -92,6 +92,7 @@ namespace XCharts.Runtime if (grid == null) return; + var relativedAxis = chart.GetChartComponent(xAxis.gridIndex); var dataZoom = chart.GetDataZoomOfAxis(xAxis); DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom, @@ -99,7 +100,8 @@ namespace XCharts.Runtime grid.context.x, grid.context.y, grid.context.width, - grid.context.height); + grid.context.height, + relativedAxis); } } diff --git a/Runtime/Component/Axis/YAxis/YAxisHander.cs b/Runtime/Component/Axis/YAxis/YAxisHander.cs index b481c1d3..8ef389df 100644 --- a/Runtime/Component/Axis/YAxis/YAxisHander.cs +++ b/Runtime/Component/Axis/YAxis/YAxisHander.cs @@ -89,14 +89,15 @@ namespace XCharts.Runtime var grid = chart.GetChartComponent(yAxis.gridIndex); if (grid == null) return; - + var relativedAxis = chart.GetChartComponent(yAxis.gridIndex); var dataZoom = chart.GetDataZoomOfAxis(yAxis); DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom, Orient.Vertical, grid.context.x, grid.context.y, grid.context.height, - grid.context.width); + grid.context.width, + relativedAxis); } } diff --git a/Runtime/Component/Child/AreaStyle.cs b/Runtime/Component/Child/AreaStyle.cs index e47a1832..ecbb4492 100644 --- a/Runtime/Component/Child/AreaStyle.cs +++ b/Runtime/Component/Child/AreaStyle.cs @@ -38,7 +38,6 @@ namespace XCharts.Runtime [SerializeField] private Color32 m_Color; [SerializeField] private Color32 m_ToColor; [SerializeField] [Range(0, 1)] private float m_Opacity = 0.6f; - [SerializeField] private bool m_TooltipHighlight; [SerializeField] private Color32 m_HighlightColor; [SerializeField] private Color32 m_HighlightToColor; @@ -88,14 +87,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } /// - /// 鼠标悬浮时是否高亮之前的区域 - /// - public bool tooltipHighlight - { - get { return m_TooltipHighlight; } - set { if (PropertyUtil.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); } - } - /// /// the color of area,default use serie color. /// 高亮时区域填充的颜色,如果highlightToColor不是默认值,则表示渐变色的起点颜色。 /// diff --git a/Runtime/Component/Child/IconStyle.cs b/Runtime/Component/Child/IconStyle.cs index 7b7bfb2e..8eeec3c9 100644 --- a/Runtime/Component/Child/IconStyle.cs +++ b/Runtime/Component/Child/IconStyle.cs @@ -12,7 +12,7 @@ namespace XCharts.Runtime UnderLabel, AboveLabel } - [SerializeField] private bool m_Show; + [SerializeField] private bool m_Show = false; [SerializeField] private Layer m_Layer; [SerializeField] private Align m_Align = Align.Left; [SerializeField] private Sprite m_Sprite; diff --git a/Runtime/Component/Child/ItemStyle.cs b/Runtime/Component/Child/ItemStyle.cs index 07891f53..2079a9d1 100644 --- a/Runtime/Component/Child/ItemStyle.cs +++ b/Runtime/Component/Child/ItemStyle.cs @@ -1,6 +1,3 @@ - -using System; -using System.Collections.Generic; using UnityEngine; namespace XCharts.Runtime @@ -11,24 +8,6 @@ namespace XCharts.Runtime [System.Serializable] public class ItemStyle : ChildComponent, ISerieDataComponent { - /// - /// 线的类型。 - /// - public enum Type - { - /// - /// 实线 - /// - Solid, - /// - /// 虚线 - /// - Dashed, - /// - /// 点线 - /// - Dotted - } [SerializeField] private bool m_Show = true; [SerializeField] private Color32 m_Color; [SerializeField] private Color32 m_Color0; @@ -38,7 +17,6 @@ namespace XCharts.Runtime [SerializeField] private float m_BackgroundWidth; [SerializeField] private Color32 m_CenterColor; [SerializeField] private float m_CenterGap; - [SerializeField] private Type m_BorderType = Type.Solid; [SerializeField] private float m_BorderWidth = 0; [SerializeField] private Color32 m_BorderColor; [SerializeField] private Color32 m_BorderColor0; @@ -60,7 +38,6 @@ namespace XCharts.Runtime m_BackgroundWidth = 0; m_CenterColor = Color.clear; m_CenterGap = 0; - m_BorderType = Type.Solid; m_BorderWidth = 0; m_BorderColor = Color.clear; m_BorderColor0 = Color.clear; @@ -155,14 +132,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); } } /// - /// 边框的类型。 - /// - public Type borderType - { - get { return m_BorderType; } - set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); } - } - /// /// 边框的颜色。 /// public Color32 borderColor @@ -261,6 +230,7 @@ namespace XCharts.Runtime color.a = (byte)(color.a * m_Opacity); return color; } + public Color32 GetColor0() { if (m_Opacity == 1 || m_Color0.a == 0) @@ -270,6 +240,7 @@ namespace XCharts.Runtime color.a = (byte)(color.a * m_Opacity); return color; } + public Color32 GetColor(Color32 defaultColor) { var color = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color; @@ -280,6 +251,7 @@ namespace XCharts.Runtime color.a = (byte)(color.a * m_Opacity); return color; } + public Color32 GetColor0(Color32 defaultColor) { var color = ChartHelper.IsClearColor(m_Color0) ? defaultColor : m_Color0; @@ -290,6 +262,7 @@ namespace XCharts.Runtime color.a = (byte)(color.a * m_Opacity); return color; } + public Color32 GetBorderColor(Color32 defaultColor) { var color = ChartHelper.IsClearColor(m_BorderColor) ? defaultColor : m_BorderColor; @@ -300,6 +273,7 @@ namespace XCharts.Runtime color.a = (byte)(color.a * m_Opacity); return color; } + public Color32 GetBorderColor0(Color32 defaultColor) { var color = ChartHelper.IsClearColor(m_BorderColor0) ? defaultColor : m_BorderColor0; diff --git a/Runtime/Component/Child/LabelStyle.cs b/Runtime/Component/Child/LabelStyle.cs index c05dacaf..19c8b280 100644 --- a/Runtime/Component/Child/LabelStyle.cs +++ b/Runtime/Component/Child/LabelStyle.cs @@ -83,7 +83,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_AutoOffset = false; [SerializeField] private bool m_AutoColor = false; [SerializeField] private TextStyle m_TextStyle = new TextStyle(); - private DelegateSerieLabelFormatter m_FormatterFunction; + private SerieLabelFormatterFunction m_FormatterFunction; public void Reset() { @@ -230,7 +230,7 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); } } - public DelegateSerieLabelFormatter formatterFunction + public SerieLabelFormatterFunction formatterFunction { get { return m_FormatterFunction; } set { m_FormatterFunction = value; } diff --git a/Runtime/Component/Child/LevelStyle.cs b/Runtime/Component/Child/LevelStyle.cs new file mode 100644 index 00000000..cc4a4a29 --- /dev/null +++ b/Runtime/Component/Child/LevelStyle.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace XCharts.Runtime +{ + [System.Serializable] + public class Level : ChildComponent + { + [SerializeField] private LabelStyle m_Label = new LabelStyle(); + [SerializeField] private LabelStyle m_UpperLabel = new LabelStyle(); + [SerializeField] private ItemStyle m_ItemStyle = new ItemStyle(); + + public LabelStyle label { get { return m_Label; } } + public LabelStyle upperLabel { get { return m_UpperLabel; } } + public ItemStyle itemStyle { get { return m_ItemStyle; } } + } + + [System.Serializable] + public class LevelStyle : ChildComponent + { + [SerializeField] private bool m_Show = false; + [SerializeField] private List m_Levels = new List() { new Level() }; + + /// + /// 是否启用LevelStyle + /// + public bool show { get { return m_Show; } set { m_Show = value; } } + /// + /// 各层节点对应的配置。当enableLevels为true时生效,levels[0]对应的第一层的配置,levels[1]对应第二层,依次类推。当levels中没有对应层时用默认的设置。 + /// + public List levels { get { return m_Levels; } } + } +} \ No newline at end of file diff --git a/Runtime/Component/Child/LevelStyle.cs.meta b/Runtime/Component/Child/LevelStyle.cs.meta new file mode 100644 index 00000000..11939638 --- /dev/null +++ b/Runtime/Component/Child/LevelStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3760e89d324d7413d95a2ac1d434a546 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Child/SymbolStyle.cs b/Runtime/Component/Child/SymbolStyle.cs index fa98bf28..d3fbdb41 100644 --- a/Runtime/Component/Child/SymbolStyle.cs +++ b/Runtime/Component/Child/SymbolStyle.cs @@ -78,19 +78,12 @@ namespace XCharts.Runtime /// FromData, /// - /// Specify callback function for symbol size. - /// 通过回调函数获取。 + /// Specify function for symbol size. + /// 通过委托函数获取。 /// - Callback, + Function, } - /// - /// 获取标记大小的回调。 - /// - /// - /// - public delegate float SymbolSizeCallback(List data); - /// /// 系列数据项的标记的图形 /// @@ -105,8 +98,8 @@ namespace XCharts.Runtime [SerializeField] private int m_DataIndex = 1; [SerializeField] private float m_DataScale = 1; [SerializeField] private float m_SelectedDataScale = 1.5f; - [SerializeField] private SymbolSizeCallback m_SizeCallback; - [SerializeField] private SymbolSizeCallback m_SelectedSizeCallback; + [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; @@ -128,8 +121,8 @@ namespace XCharts.Runtime m_DataIndex = 1; m_DataScale = 1; m_SelectedDataScale = 1.5f; - m_SizeCallback = null; - m_SelectedSizeCallback = null; + m_SizeFunction = null; + m_SelectedSizeFunction = null; m_StartIndex = 0; m_Interval = 0; m_ForceShowLast = false; @@ -215,22 +208,22 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); } } /// - /// the callback of size when sizeType assined as Callback. - /// 当sizeType指定为Callback时,指定的回调函数。 + /// the function of size when sizeType assined as Function. + /// 当sizeType指定为Function时,指定的委托函数。 /// - public SymbolSizeCallback sizeCallback + public SymbolSizeFunction sizeFunction { - get { return m_SizeCallback; } - set { if (PropertyUtil.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); } + get { return m_SizeFunction; } + set { if (PropertyUtil.SetClass(ref m_SizeFunction, value)) SetVerticesDirty(); } } /// - /// the callback of size when sizeType assined as Callback. - /// 当sizeType指定为Callback时,指定的高亮回调函数。 + /// the function of size when sizeType assined as Function. + /// 当sizeType指定为Function时,指定的高亮委托函数。 /// - public SymbolSizeCallback selectedSizeCallback + public SymbolSizeFunction selectedSizeFunction { - get { return m_SelectedSizeCallback; } - set { if (PropertyUtil.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); } + get { return m_SelectedSizeFunction; } + set { if (PropertyUtil.SetClass(ref m_SelectedSizeFunction, value)) SetVerticesDirty(); } } /// /// the index start to show symbol. @@ -341,8 +334,8 @@ namespace XCharts.Runtime { return size == 0 ? themeSize : size; } - case SymbolSizeType.Callback: - if (data != null && sizeCallback != null) return sizeCallback(data); + case SymbolSizeType.Function: + if (data != null && sizeFunction != null) return sizeFunction(data); else return size == 0 ? themeSize : size; default: return size == 0 ? themeSize : size; } @@ -372,10 +365,10 @@ namespace XCharts.Runtime return selectedSize == 0 ? themeSelectedSize : selectedSize; } - case SymbolSizeType.Callback: + case SymbolSizeType.Function: - if (data != null && selectedSizeCallback != null) - return selectedSizeCallback(data); + if (data != null && selectedSizeFunction != null) + return selectedSizeFunction(data); else return selectedSize == 0 ? themeSelectedSize : selectedSize; diff --git a/Runtime/Component/Debug/DebugInfo.cs b/Runtime/Component/Debug/DebugInfo.cs index 9f160182..a822415f 100644 --- a/Runtime/Component/Debug/DebugInfo.cs +++ b/Runtime/Component/Debug/DebugInfo.cs @@ -10,7 +10,7 @@ namespace XCharts.Runtime public class DebugInfo { [SerializeField] private bool m_ShowDebugInfo = false; - [SerializeField] protected bool m_ShowAllChildObject = false; + [SerializeField] protected bool m_ShowAllChartObject = false; [SerializeField] protected bool m_FoldSeries = false; [SerializeField] private TextStyle m_DebugInfoTextStyle = new TextStyle() @@ -32,7 +32,7 @@ namespace XCharts.Runtime private ChartLabel m_Label; private List m_FpsList = new List(); - public bool showAllChildObject { get { return m_ShowAllChildObject; } } + public bool showAllChartObject { get { return m_ShowAllChartObject; } } public bool foldSeries { get { return m_FoldSeries; } set { m_FoldSeries = value; } } public float fps { get; private set; } public float avgFps { get; private set; } diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index 2719ef27..b28da61b 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -1,6 +1,5 @@ using System; -using System.Text; using UnityEngine; namespace XCharts.Runtime diff --git a/Runtime/Helper/SerieHelper.cs b/Runtime/Helper/SerieHelper.cs index 3718cf47..2c2785a0 100644 --- a/Runtime/Helper/SerieHelper.cs +++ b/Runtime/Helper/SerieHelper.cs @@ -412,6 +412,7 @@ namespace XCharts.Runtime public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false) { + if (serieData == null) return serie.label; if (highlight) { if (!serie.IsPerformanceMode() && serieData.emphasis != null && serieData.emphasis.show) diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 2dc9e197..1cf78f4e 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -72,23 +72,23 @@ namespace XCharts.Runtime /// /// 自定义绘制回调。在绘制Serie前调用。 /// - public Action onCustomDraw { set { m_OnCustomDrawBaseCallback = value; } } + public Action onDraw { set { m_OnDrawBase = value; } } /// /// 自定义Serie绘制回调。在每个Serie绘制完前调用。 /// - public Action onCustomDrawBeforeSerie { set { m_OnCustomDrawSerieBeforeCallback = value; } } + public Action onDrawBeforeSerie { set { m_OnDrawSerieBefore = value; } } /// /// 自定义Serie绘制回调。在每个Serie绘制完后调用。 /// - public Action onCustomDrawAfterSerie { set { m_OnCustomDrawSerieAfterCallback = value; } } + public Action onDrawAfterSerie { set { m_OnDrawSerieAfter = value; } } /// /// 自定义Top绘制回调。在绘制Tooltip前调用。 /// - public Action onCustomDrawTop { set { m_OnCustomDrawTopCallback = value; } } + public Action onDrawTop { set { m_OnDrawTop = value; } } /// - /// 自定义仪表盘指针绘制回调。参数:SerieIndex,SerieDataIndex,currAngle + /// 自定义仪表盘指针绘制委托。 /// - public Action onCustomDrawGagugePointer { set { m_OnCustomDrawGagugePointerCallback = value; } get { return m_OnCustomDrawGagugePointerCallback; } } + public CustomDrawGaugePointerFunction customDrawGaugePointerFunction { set { m_CustomDrawGaugePointerFunction = value; } get { return m_CustomDrawGaugePointerFunction; } } /// /// the callback function of click pie area. /// 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex @@ -102,7 +102,7 @@ namespace XCharts.Runtime /// /// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue /// - public Action onUpdateAxisPointer { set { m_OnUpdateAxisPointer = value; } get { return m_OnUpdateAxisPointer; } } + public Action onAxisPointerValueChanged { set { m_OnAxisPointerValueChanged = value; } get { return m_OnAxisPointerValueChanged; } } /// /// Redraw chart in next frame. /// 在下一帧刷新图表。 diff --git a/Runtime/Internal/BaseChart.Serie.cs b/Runtime/Internal/BaseChart.Serie.cs index 437ef1af..1e4a7245 100644 --- a/Runtime/Internal/BaseChart.Serie.cs +++ b/Runtime/Internal/BaseChart.Serie.cs @@ -190,7 +190,6 @@ namespace XCharts.Runtime return true; } - /// /// Add a data to serie. /// If serieName doesn't exist in legend,will be add to legend. @@ -199,13 +198,14 @@ namespace XCharts.Runtime /// the name of serie /// the data to add /// the name of data + /// the unique id of data /// Returns True on success - public SerieData AddData(string serieName, double data, string dataName = null) + public SerieData AddData(string serieName, double data, string dataName = null, string dataId = null) { var serie = GetSerie(serieName); if (serie != null) { - var serieData = serie.AddYData(data, dataName); + var serieData = serie.AddYData(data, dataName, dataId); RefreshPainter(serie.painter); return serieData; } @@ -219,13 +219,14 @@ namespace XCharts.Runtime /// the index of serie /// the data to add /// the name of data + /// the unique id of data /// Returns True on success - public SerieData AddData(int serieIndex, double data, string dataName = null) + public SerieData AddData(int serieIndex, double data, string dataName = null, string dataId = null) { var serie = GetSerie(serieIndex); if (serie != null) { - var serieData = serie.AddYData(data, dataName); + var serieData = serie.AddYData(data, dataName, dataId); RefreshPainter(serie.painter); return serieData; } @@ -239,13 +240,14 @@ namespace XCharts.Runtime /// the name of serie /// the (x,y,z,...) data /// the name of data + /// the unique id of data /// Returns True on success - public SerieData AddData(string serieName, List multidimensionalData, string dataName = null) + public SerieData AddData(string serieName, List multidimensionalData, string dataName = null, string dataId = null) { var serie = GetSerie(serieName); if (serie != null) { - var serieData = serie.AddData(multidimensionalData, dataName); + var serieData = serie.AddData(multidimensionalData, dataName, dataId); RefreshPainter(serie.painter); return serieData; } @@ -259,13 +261,14 @@ namespace XCharts.Runtime /// the index of serie,index starts at 0 /// the (x,y,z,...) data /// the name of data + /// the unique id of data /// Returns True on success - public SerieData AddData(int serieIndex, List multidimensionalData, string dataName = null) + public SerieData AddData(int serieIndex, List multidimensionalData, string dataName = null, string dataId = null) { var serie = GetSerie(serieIndex); if (serie != null) { - var serieData = serie.AddData(multidimensionalData, dataName); + var serieData = serie.AddData(multidimensionalData, dataName, dataId); RefreshPainter(serie.painter); return serieData; } @@ -280,13 +283,14 @@ namespace XCharts.Runtime /// x data /// y data /// the name of data + /// the unique id of data /// Returns True on success - public SerieData AddData(string serieName, double xValue, double yValue, string dataName = null) + public SerieData AddData(string serieName, double xValue, double yValue, string dataName = null, string dataId = null) { var serie = GetSerie(serieName); if (serie != null) { - var serieData = serie.AddXYData(xValue, yValue, dataName); + var serieData = serie.AddXYData(xValue, yValue, dataName, dataId); RefreshPainter(serie.painter); return serieData; } @@ -301,35 +305,36 @@ namespace XCharts.Runtime /// x data /// y data /// the name of data + /// the unique id of data /// Returns True on success - public SerieData AddData(int serieIndex, double xValue, double yValue, string dataName = null) + public SerieData AddData(int serieIndex, double xValue, double yValue, string dataName = null, string dataId = null) { var serie = GetSerie(serieIndex); if (serie != null) { - var serieData = serie.AddXYData(xValue, yValue, dataName); + var serieData = serie.AddXYData(xValue, yValue, dataName, dataId); RefreshPainter(serie.painter); return serieData; } return null; } - public SerieData AddData(int serieIndex, double open, double close, double lowest, double heighest, string dataName = null) + public SerieData AddData(int serieIndex, double open, double close, double lowest, double heighest, string dataName = null, string dataId = null) { var serie = GetSerie(serieIndex); if (serie != null) { - var serieData = serie.AddData(open, close, lowest, heighest, dataName); + var serieData = serie.AddData(open, close, lowest, heighest, dataName, dataId); RefreshPainter(serie.painter); return serieData; } return null; } - public SerieData AddData(string serieName, double open, double close, double lowest, double heighest, string dataName = null) + public SerieData AddData(string serieName, double open, double close, double lowest, double heighest, string dataName = null, string dataId = null) { var serie = GetSerie(serieName); if (serie != null) { - var serieData = serie.AddData(open, close, lowest, heighest, dataName); + var serieData = serie.AddData(open, close, lowest, heighest, dataName, dataId); RefreshPainter(serie.painter); return serieData; } @@ -853,8 +858,9 @@ namespace XCharts.Runtime } } - private void InternalAddSerie(Serie serie) + private void AddSerieAfterDeserialize(Serie serie) { + serie.OnAfterDeserialize(); m_Series.Add(serie); } diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index a462cfe0..afb7eb51 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -77,15 +77,17 @@ namespace XCharts.Runtime protected Vector2 m_ChartMaxAnchor; protected Vector2 m_ChartPivot; protected Vector2 m_ChartSizeDelta; + protected Rect m_ChartRect = new Rect(0, 0, 0, 0); - protected Action m_OnCustomDrawBaseCallback; - protected Action m_OnCustomDrawTopCallback; - protected Action m_OnCustomDrawSerieBeforeCallback; - protected Action m_OnCustomDrawSerieAfterCallback; - protected Action m_OnCustomDrawGagugePointerCallback; + protected Action m_OnDrawBase; + protected Action m_OnDrawTop; + protected Action m_OnDrawSerieBefore; + protected Action m_OnDrawSerieAfter; protected Action m_OnPointerClickPie; protected Action m_OnPointerClickBar; - protected Action m_OnUpdateAxisPointer; + protected Action m_OnAxisPointerValueChanged; + + protected CustomDrawGaugePointerFunction m_CustomDrawGaugePointerFunction; internal bool m_CheckAnimation = false; internal protected List m_LegendRealShowName = new List(); @@ -209,7 +211,7 @@ namespace XCharts.Runtime { var painter = GetPainter(index); if (painter == null) return; - painter.SetActive(flag, m_DebugInfo.showAllChildObject); + painter.SetActive(flag, m_DebugInfo.showAllChartObject); } protected virtual void CheckTheme() @@ -306,7 +308,7 @@ namespace XCharts.Runtime painter.index = m_PainterList.Count; painter.type = Painter.Type.Serie; painter.onPopulateMesh = OnDrawPainterSerie; - painter.SetActive(false, m_DebugInfo.showAllChildObject); + painter.SetActive(false, m_DebugInfo.showAllChartObject); painter.material = settings.seriePainterMaterial; painter.transform.SetSiblingIndex(index + 1); m_PainterList.Add(painter); @@ -315,7 +317,7 @@ namespace XCharts.Runtime m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter); m_PainterTop.type = Painter.Type.Top; m_PainterTop.onPopulateMesh = OnDrawPainterTop; - m_PainterTop.SetActive(true, m_DebugInfo.showAllChildObject); + m_PainterTop.SetActive(true, m_DebugInfo.showAllChartObject); m_PainterTop.material = settings.topPainterMaterial; m_PainterTop.transform.SetSiblingIndex(settings.maxPainter + 1); } @@ -513,9 +515,9 @@ namespace XCharts.Runtime DrawPainterBase(vh); foreach (var handler in m_ComponentHandlers) handler.DrawBase(vh); foreach (var handler in m_SerieHandlers) handler.DrawBase(vh); - if (m_OnCustomDrawBaseCallback != null) + if (m_OnDrawBase != null) { - m_OnCustomDrawBaseCallback(vh); + m_OnDrawBase(vh); } m_BasePainterVertCount = vh.currentVertCount; } @@ -535,9 +537,9 @@ namespace XCharts.Runtime serie.context.dataPoints.Clear(); serie.context.dataIgnores.Clear(); AnimationStyleHelper.UpdateSerieAnimation(serie); - if (m_OnCustomDrawSerieBeforeCallback != null) + if (m_OnDrawSerieBefore != null) { - m_OnCustomDrawSerieBeforeCallback.Invoke(vh, serie); + m_OnDrawSerieBefore.Invoke(vh, serie); } DrawPainterSerie(vh, serie); if (i >= 0 && i < m_SerieHandlers.Count) @@ -546,9 +548,9 @@ namespace XCharts.Runtime handler.DrawSerie(vh); handler.RefreshLabelNextFrame(); } - if (m_OnCustomDrawSerieAfterCallback != null) + if (m_OnDrawSerieAfter != null) { - m_OnCustomDrawSerieAfterCallback(vh, serie); + m_OnDrawSerieAfter(vh, serie); } serie.context.vertCount = vh.currentVertCount; } @@ -559,9 +561,9 @@ namespace XCharts.Runtime vh.Clear(); DrawPainterTop(vh); foreach (var draw in m_ComponentHandlers) draw.DrawTop(vh); - if (m_OnCustomDrawTopCallback != null) + if (m_OnDrawTop != null) { - m_OnCustomDrawTopCallback(vh); + m_OnDrawTop(vh); } m_TopPainterVertCount = vh.currentVertCount; } @@ -648,6 +650,7 @@ namespace XCharts.Runtime foreach (var serie in m_Series) { FieldInfo field; + serie.OnBeforeSerialize(); if (m_TypeListForSerie.TryGetValue(serie.GetType(), out field)) ReflectionUtil.InvokeListAdd(this, field, serie); else @@ -666,7 +669,7 @@ namespace XCharts.Runtime } foreach (var kv in m_TypeListForSerie) { - ReflectionUtil.InvokeListAddTo(this, kv.Value, InternalAddSerie); + ReflectionUtil.InvokeListAddTo(this, kv.Value, AddSerieAfterDeserialize); } m_Series.Sort(); m_Components.Sort(); diff --git a/Runtime/Internal/BaseGraph.API.cs b/Runtime/Internal/BaseGraph.API.cs index ad7545ab..48c23458 100644 --- a/Runtime/Internal/BaseGraph.API.cs +++ b/Runtime/Internal/BaseGraph.API.cs @@ -145,7 +145,7 @@ namespace XCharts.Runtime /// /// 移除并重新初始化所有组件。 /// - public void ReinitAllChartComponent() + public void RemoveAndReinitChartObject() { ChartHelper.DestroyAllChildren(transform); SetAllComponentDirty(); diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index 8d03098c..e4910dfc 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -49,7 +49,7 @@ namespace XCharts.Runtime protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } } protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } } protected Vector2 graphPivot { get { return m_GraphPivot; } } - public HideFlags chartHideFlags { get { return m_DebugInfo.showAllChildObject ? HideFlags.None : HideFlags.HideInHierarchy; } } + public HideFlags chartHideFlags { get { return m_DebugInfo.showAllChartObject ? HideFlags.None : HideFlags.HideInHierarchy; } } public DebugInfo debug { get { return m_DebugInfo; } } private ScrollRect m_ScrollRect; @@ -125,7 +125,7 @@ namespace XCharts.Runtime if (m_EnableTextMeshPro != enableTextMeshPro) { m_EnableTextMeshPro = enableTextMeshPro; - ReinitAllChartComponent(); + RemoveAndReinitChartObject(); } } diff --git a/Runtime/Internal/Basic/BaseSerie.cs b/Runtime/Internal/Basic/BaseSerie.cs index 1327ac80..ee07ce22 100644 --- a/Runtime/Internal/Basic/BaseSerie.cs +++ b/Runtime/Internal/Basic/BaseSerie.cs @@ -23,7 +23,7 @@ namespace XCharts.Runtime [NonSerialized] public SerieContext context = new SerieContext(); [NonSerialized] public InteractData interact = new InteractData(); - internal SerieHandler handler { get; set; } + public SerieHandler handler { get; set; } public virtual void SetVerticesDirty() @@ -68,6 +68,19 @@ namespace XCharts.Runtime handler.RemoveComponent(); } + public virtual void OnDataUpdate() + { + } + + public virtual void OnBeforeSerialize() + { + } + + public virtual void OnAfterDeserialize() + { + OnDataUpdate(); + } + public void RefreshLabel() { if (handler != null) diff --git a/Runtime/Internal/Basic/ChildComponent.cs b/Runtime/Internal/Basic/ChildComponent.cs index a4fbcd42..7bffde83 100644 --- a/Runtime/Internal/Basic/ChildComponent.cs +++ b/Runtime/Internal/Basic/ChildComponent.cs @@ -7,7 +7,7 @@ namespace XCharts.Runtime [System.Serializable] public class ChildComponent { - public int index { get; set; } + public virtual int index { get; set; } [NonSerialized] protected bool m_VertsDirty; [NonSerialized] protected bool m_ComponentDirty; [NonSerialized] protected Painter m_Painter; diff --git a/Runtime/Internal/Misc/DelegateFunction.cs b/Runtime/Internal/Misc/DelegateFunction.cs index 1adab98a..9883ecbb 100644 --- a/Runtime/Internal/Misc/DelegateFunction.cs +++ b/Runtime/Internal/Misc/DelegateFunction.cs @@ -1,5 +1,8 @@ +using System.Collections.Generic; +using UnityEngine.UI; + namespace XCharts.Runtime { /// @@ -10,7 +13,7 @@ namespace XCharts.Runtime /// 当前label对应的数值数据,Value轴或Time轴有效 /// 当前label对应的类目数据,Category轴有效 /// 最终显示的文本内容 - public delegate string DelegateAxisLabelFormatter(int labelIndex, double value, string category); + public delegate string AxisLabelFormatterFunction(int labelIndex, double value, string category); /// /// The delegate function for SerieLabel‘s formatter. /// SerieLabel的formatter自定义委托。 @@ -18,5 +21,14 @@ namespace XCharts.Runtime /// 数据索引 /// 数值 /// 最终显示的文本内容 - public delegate string DelegateSerieLabelFormatter(int dataIndex, double value); + public delegate string SerieLabelFormatterFunction(int dataIndex, double value); + public delegate float AnimationDelayFunction(int dataIndex); + public delegate float AnimationDurationFunction(int dataIndex); + /// + /// 获取标记大小的回调。 + /// + /// + /// + public delegate float SymbolSizeFunction(List data); + public delegate void CustomDrawGaugePointerFunction(VertexHelper vh, int serieIndex, int dataIndex, float currentAngle); } \ No newline at end of file diff --git a/Runtime/Internal/Utilities/ChartCached.cs b/Runtime/Internal/Utilities/ChartCached.cs index 5828ddff..2579d9ab 100644 --- a/Runtime/Internal/Utilities/ChartCached.cs +++ b/Runtime/Internal/Utilities/ChartCached.cs @@ -19,7 +19,6 @@ namespace XCharts.Runtime private static Dictionary s_ColorDotStr = new Dictionary(100); private static Dictionary> s_ComponentObjectName = new Dictionary>(); private static Dictionary s_AxisLabelName = new Dictionary(); - private static Dictionary s_AxisLabel = new Dictionary(); private static Dictionary s_TypeName = new Dictionary(); @@ -158,15 +157,6 @@ namespace XCharts.Runtime } } - internal static string GetAxisTooltipLabel(string axisName) - { - if (!s_AxisLabel.ContainsKey(axisName)) - { - s_AxisLabel[axisName] = axisName + "_label"; - } - return s_AxisLabel[axisName]; - } - internal static string GetTypeName() { return GetTypeName(typeof(T)); diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 3ed14290..64923765 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -794,9 +794,6 @@ namespace XCharts.Runtime } } - - - public static Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle) { Vector3 point = Quaternion.AngleAxis(angle, axis) * (position - center); @@ -857,23 +854,7 @@ namespace XCharts.Runtime } } - public static float GetRuntimeRelativeOrAbsoluteValue(float check, float total) - { - if (check <= 0) - { - return 0; - } - else if (check <= 1) - { - return total * check; - } - else - { - return check; - } - } - - public static Vector3 GetLastPoint(List list) + public static Vector3 GetLastValue(List list) { if (list.Count <= 0) return Vector3.zero; else return list[list.Count - 1]; diff --git a/Runtime/Internal/Utilities/ComponentHelper.cs b/Runtime/Internal/Utilities/ComponentHelper.cs index 0b9abca4..50981adf 100644 --- a/Runtime/Internal/Utilities/ComponentHelper.cs +++ b/Runtime/Internal/Utilities/ComponentHelper.cs @@ -19,6 +19,7 @@ namespace XCharts.Runtime } return null; } + public static RadiusAxis GetRadiusAxis(List components, int polarIndex) { foreach (var component in components) @@ -32,32 +33,6 @@ namespace XCharts.Runtime return null; } - public static YAxis GetYAxisRelatedWitchXAxis(List components, XAxis axis) - { - foreach (var component in components) - { - if (component is YAxis) - { - var yAxis = component as YAxis; - if (yAxis.gridIndex == axis.gridIndex) return yAxis; - } - } - return null; - } - - public static XAxis GetXAxisRelatedWithYAxis(List components, YAxis axis) - { - foreach (var component in components) - { - if (component is XAxis) - { - var xAxis = component as XAxis; - if (xAxis.gridIndex == axis.gridIndex) return xAxis; - } - } - return null; - } - public static float GetXAxisOnZeroOffset(List components, XAxis axis) { if (!axis.axisLine.onZero) return 0; diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index efc68c4e..8742be9a 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -122,7 +122,7 @@ namespace XCharts.Runtime foreach (var chart in chartList) { if (chart != null) - chart.ReinitAllChartComponent(); + chart.RemoveAndReinitChartObject(); } } diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index 554efa99..10f2ad39 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -163,7 +163,7 @@ namespace XCharts.Runtime float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) * 0.5f; float barGapWidth = barWidth + barWidth * barGap; - float space = serie.barGap == -1 ? offset : offset + chart.GetSerieIndexIfStack(serie) * barGapWidth; + float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieIndexIfStack(serie) * barGapWidth; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; @@ -209,7 +209,6 @@ namespace XCharts.Runtime var pX = 0f; var pY = 0f; UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, barWidth, isStack, value, ref pX, ref pY); - var barHig = 0f; if (isPercentStack) { @@ -223,7 +222,7 @@ namespace XCharts.Runtime float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; - UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, space, borderWidth, barWidth, currHig, + UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, gap, borderWidth, barWidth, currHig, out plb, out plt, out prt, out prb, out top); serieData.context.stackHeight = barHig; serieData.context.position = top; @@ -237,15 +236,15 @@ namespace XCharts.Runtime switch (serie.barType) { case BarType.Normal: - DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, + DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); break; case BarType.Zebra: - DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, + DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); break; case BarType.Capsule: - DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, + DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); break; } @@ -278,7 +277,11 @@ namespace XCharts.Runtime else { if (axis.context.minMaxRange <= 0) pY = grid.context.y; - else pY = grid.context.y + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth); + else + { + var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.height; + pY = grid.context.y + valueLen - categoryWidth * 0.5f; + } } pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0); if (isStack) @@ -296,7 +299,11 @@ namespace XCharts.Runtime else { if (axis.context.minMaxRange <= 0) pX = grid.context.x; - else pX = grid.context.x + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth); + else + { + var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.width; + pX = grid.context.x + valueLen - categoryWidth * 0.5f; + } } pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0); if (isStack) @@ -307,7 +314,7 @@ namespace XCharts.Runtime } } - private void UpdateRectPosition(GridCoord grid, bool isY, double yValue, float pX, float pY, float space, float borderWidth, + private void UpdateRectPosition(GridCoord grid, bool isY, double yValue, float pX, float pY, float gap, float borderWidth, float barWidth, float currHig, out Vector3 plb, out Vector3 plt, out Vector3 prt, out Vector3 prb, out Vector3 top) { @@ -315,37 +322,37 @@ namespace XCharts.Runtime { if (yValue < 0) { - plt = new Vector3(pX - borderWidth, pY + space + barWidth - borderWidth); - prt = new Vector3(pX + currHig + borderWidth, pY + space + barWidth - borderWidth); - prb = new Vector3(pX + currHig + borderWidth, pY + space + borderWidth); - plb = new Vector3(pX - borderWidth, pY + space + borderWidth); + plt = new Vector3(pX - borderWidth, pY + gap + barWidth - borderWidth); + prt = new Vector3(pX + currHig + borderWidth, pY + gap + barWidth - borderWidth); + prb = new Vector3(pX + currHig + borderWidth, pY + gap + borderWidth); + plb = new Vector3(pX - borderWidth, pY + gap + borderWidth); } else { - plt = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth); - prt = new Vector3(pX + currHig - borderWidth, pY + space + barWidth - borderWidth); - prb = new Vector3(pX + currHig - borderWidth, pY + space + borderWidth); - plb = new Vector3(pX + borderWidth, pY + space + borderWidth); + plt = new Vector3(pX + borderWidth, pY + gap + barWidth - borderWidth); + prt = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth - borderWidth); + prb = new Vector3(pX + currHig - borderWidth, pY + gap + borderWidth); + plb = new Vector3(pX + borderWidth, pY + gap + borderWidth); } - top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2); + top = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth / 2); } else { if (yValue < 0) { - plb = new Vector3(pX + space + borderWidth, pY - borderWidth); - plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + space + barWidth - borderWidth, pY - borderWidth); + plb = new Vector3(pX + gap + borderWidth, pY - borderWidth); + plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); + prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); + prb = new Vector3(pX + gap + barWidth - borderWidth, pY - borderWidth); } else { - plb = new Vector3(pX + space + borderWidth, pY + borderWidth); - plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth); + plb = new Vector3(pX + gap + borderWidth, pY + borderWidth); + plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); + prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); + prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth); } - top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); + top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth); } if (serie.clip) { @@ -358,10 +365,10 @@ namespace XCharts.Runtime } private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, + bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor) { - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid, axis); + DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, gap, barWidth, isYAxis, grid, axis); var borderWidth = itemStyle.runtimeBorderWidth; if (isYAxis) { @@ -423,10 +430,10 @@ namespace XCharts.Runtime } private void DrawZebraBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, + bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 barColor, Color32 barToColor) { - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid, axis); + DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, gap, barWidth, isYAxis, grid, axis); if (isYAxis) { plt = (plb + plt) / 2; @@ -444,10 +451,10 @@ namespace XCharts.Runtime } private void DrawCapsuleBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, + bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor) { - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid, axis); + DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, gap, barWidth, isYAxis, grid, axis); var borderWidth = itemStyle.runtimeBorderWidth; var radius = barWidth / 2 - borderWidth; var isGradient = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor); @@ -562,7 +569,7 @@ namespace XCharts.Runtime } private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, - int colorIndex, bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis, + int colorIndex, bool highlight, float pX, float pY, float gap, float barWidth, bool isYAxis, GridCoord grid, Axis axis) { var color = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false); @@ -570,10 +577,10 @@ namespace XCharts.Runtime if (isYAxis) { var axisWidth = axis.axisLine.GetWidth(chart.theme.axis.lineWidth); - Vector3 plt = new Vector3(grid.context.x + axisWidth, pY + space + barWidth); - Vector3 prt = new Vector3(grid.context.x + axisWidth + grid.context.width, pY + space + barWidth); - Vector3 prb = new Vector3(grid.context.x + axisWidth + grid.context.width, pY + space); - Vector3 plb = new Vector3(grid.context.x + axisWidth, pY + space); + Vector3 plt = new Vector3(grid.context.x + axisWidth, pY + gap + barWidth); + Vector3 prt = new Vector3(grid.context.x + axisWidth + grid.context.width, pY + gap + barWidth); + Vector3 prb = new Vector3(grid.context.x + axisWidth + grid.context.width, pY + gap); + Vector3 plb = new Vector3(grid.context.x + axisWidth, pY + gap); if (serie.barType == BarType.Capsule) { var radius = barWidth / 2; @@ -610,10 +617,10 @@ namespace XCharts.Runtime else { var axisWidth = axis.axisLine.GetWidth(chart.theme.axis.lineWidth); - Vector3 plb = new Vector3(pX + space, grid.context.y + axisWidth); - Vector3 plt = new Vector3(pX + space, grid.context.y + grid.context.height + axisWidth); - Vector3 prt = new Vector3(pX + space + barWidth, grid.context.y + grid.context.height + axisWidth); - Vector3 prb = new Vector3(pX + space + barWidth, grid.context.y + axisWidth); + Vector3 plb = new Vector3(pX + gap, grid.context.y + axisWidth); + Vector3 plt = new Vector3(pX + gap, grid.context.y + grid.context.height + axisWidth); + Vector3 prt = new Vector3(pX + gap + barWidth, grid.context.y + grid.context.height + axisWidth); + Vector3 prb = new Vector3(pX + gap + barWidth, grid.context.y + axisWidth); if (serie.barType == BarType.Capsule) { var radius = barWidth / 2; diff --git a/Runtime/Serie/Bar/SimplifiedBarHandler.cs b/Runtime/Serie/Bar/SimplifiedBarHandler.cs index 06196879..fe1820a4 100644 --- a/Runtime/Serie/Bar/SimplifiedBarHandler.cs +++ b/Runtime/Serie/Bar/SimplifiedBarHandler.cs @@ -144,7 +144,7 @@ namespace XCharts.Runtime float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) * 0.5f; float barGapWidth = barWidth + barWidth * barGap; - float space = serie.barGap == -1 ? offset : offset + serie.index * barGapWidth; + float gap = serie.barGap == -1 ? offset : offset + serie.index * barGapWidth; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; @@ -194,13 +194,13 @@ namespace XCharts.Runtime var currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; - UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, space, borderWidth, barWidth, currHig, + UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, gap, borderWidth, barWidth, currHig, out plb, out plt, out prt, out prb, out top); serieData.context.stackHeight = barHig; serieData.context.position = top; serieData.context.rect = Rect.MinMaxRect(plb.x, plb.y, prb.x, prt.y); serie.context.dataPoints.Add(top); - DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, + DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, false, m_SerieGrid, areaColor, areaToColor); if (serie.animation.CheckDetailBreak(top, isY)) @@ -250,7 +250,7 @@ namespace XCharts.Runtime } } - private void UpdateRectPosition(GridCoord grid, bool isY, double yValue, float pX, float pY, float space, float borderWidth, + private void UpdateRectPosition(GridCoord grid, bool isY, double yValue, float pX, float pY, float gap, float borderWidth, float barWidth, float currHig, out Vector3 plb, out Vector3 plt, out Vector3 prt, out Vector3 prb, out Vector3 top) { @@ -258,37 +258,37 @@ namespace XCharts.Runtime { if (yValue < 0) { - plt = new Vector3(pX - borderWidth, pY + space + barWidth - borderWidth); - prt = new Vector3(pX + currHig + borderWidth, pY + space + barWidth - borderWidth); - prb = new Vector3(pX + currHig + borderWidth, pY + space + borderWidth); - plb = new Vector3(pX - borderWidth, pY + space + borderWidth); + plt = new Vector3(pX - borderWidth, pY + gap + barWidth - borderWidth); + prt = new Vector3(pX + currHig + borderWidth, pY + gap + barWidth - borderWidth); + prb = new Vector3(pX + currHig + borderWidth, pY + gap + borderWidth); + plb = new Vector3(pX - borderWidth, pY + gap + borderWidth); } else { - plt = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth); - prt = new Vector3(pX + currHig - borderWidth, pY + space + barWidth - borderWidth); - prb = new Vector3(pX + currHig - borderWidth, pY + space + borderWidth); - plb = new Vector3(pX + borderWidth, pY + space + borderWidth); + plt = new Vector3(pX + borderWidth, pY + gap + barWidth - borderWidth); + prt = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth - borderWidth); + prb = new Vector3(pX + currHig - borderWidth, pY + gap + borderWidth); + plb = new Vector3(pX + borderWidth, pY + gap + borderWidth); } - top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2); + top = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth / 2); } else { if (yValue < 0) { - plb = new Vector3(pX + space + borderWidth, pY - borderWidth); - plt = new Vector3(pX + space + borderWidth, pY + currHig + borderWidth); - prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig + borderWidth); - prb = new Vector3(pX + space + barWidth - borderWidth, pY - borderWidth); + plb = new Vector3(pX + gap + borderWidth, pY - borderWidth); + plt = new Vector3(pX + gap + borderWidth, pY + currHig + borderWidth); + prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig + borderWidth); + prb = new Vector3(pX + gap + barWidth - borderWidth, pY - borderWidth); } else { - plb = new Vector3(pX + space + borderWidth, pY + borderWidth); - plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth); + plb = new Vector3(pX + gap + borderWidth, pY + borderWidth); + plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); + prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); + prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth); } - top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); + top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth); } if (serie.clip) { @@ -301,7 +301,7 @@ namespace XCharts.Runtime } private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, + bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Color32 areaColor, Color32 areaToColor) { diff --git a/Runtime/Serie/Candlestick/CandlestickHandler.cs b/Runtime/Serie/Candlestick/CandlestickHandler.cs index 171622be..3ffdd8c4 100644 --- a/Runtime/Serie/Candlestick/CandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/CandlestickHandler.cs @@ -93,7 +93,7 @@ namespace XCharts.Runtime var showData = serie.GetDataList(dataZoom); float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, showData.Count, dataZoom); float barWidth = serie.GetBarWidth(categoryWidth); - float space = (categoryWidth - barWidth) / 2; + float gap = (categoryWidth - barWidth) / 2; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; @@ -140,11 +140,11 @@ namespace XCharts.Runtime float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; - plb = new Vector3(pX + space + borderWidth, pY + borderWidth); - plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth); - top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); + plb = new Vector3(pX + gap + borderWidth, pY + borderWidth); + plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); + prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); + prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth); + top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth); if (serie.clip) { plb = chart.ClampInGrid(grid, plb); diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs index 699ed226..df9d7c9f 100644 --- a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs @@ -93,7 +93,7 @@ namespace XCharts.Runtime var showData = serie.GetDataList(dataZoom); float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, showData.Count, dataZoom); float barWidth = serie.GetBarWidth(categoryWidth); - float space = (categoryWidth - barWidth) / 2; + float gap = (categoryWidth - barWidth) / 2; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; @@ -140,11 +140,11 @@ namespace XCharts.Runtime float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; - plb = new Vector3(pX + space + borderWidth, pY + borderWidth); - plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth); - top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); + plb = new Vector3(pX + gap + borderWidth, pY + borderWidth); + plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); + prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); + prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth); + top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth); // if (serie.clip) // { // plb = chart.ClampInGrid(grid, plb); diff --git a/Runtime/Serie/Pie/PieHandler.cs b/Runtime/Serie/Pie/PieHandler.cs index 01596633..8f928f7b 100644 --- a/Runtime/Serie/Pie/PieHandler.cs +++ b/Runtime/Serie/Pie/PieHandler.cs @@ -330,7 +330,7 @@ namespace XCharts.Runtime var needRoundCap = serie.roundCap && insideRadius > 0; UGL.DrawDoughnut(vh, serieData.context.offsetCenter, insideRadius, outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, - drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness, + drawEndDegree, borderWidth, borderColor, serie.gap / 2, chart.settings.cicleSmoothness, needRoundCap, true); } else @@ -339,7 +339,7 @@ namespace XCharts.Runtime var needRoundCap = serie.roundCap && insideRadius > 0; UGL.DrawDoughnut(vh, serie.context.center, insideRadius, outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, - drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness, + drawEndDegree, borderWidth, borderColor, serie.gap / 2, chart.settings.cicleSmoothness, needRoundCap, true); DrawPieCenter(vh, serie, itemStyle, insideRadius); } diff --git a/Runtime/Serie/Ring/Ring.cs b/Runtime/Serie/Ring/Ring.cs index 7a8b80b3..326fbd72 100644 --- a/Runtime/Serie/Ring/Ring.cs +++ b/Runtime/Serie/Ring/Ring.cs @@ -13,6 +13,7 @@ namespace XCharts.Runtime { var serie = chart.AddSerie(serieName); serie.roundCap = true; + serie.gap = 10; serie.radius = new float[] { 0.3f, 0.35f }; serie.AddExtraComponent(); diff --git a/Runtime/Serie/Ring/RingHandler.cs b/Runtime/Serie/Ring/RingHandler.cs index d06e3214..c99ca773 100644 --- a/Runtime/Serie/Ring/RingHandler.cs +++ b/Runtime/Serie/Ring/RingHandler.cs @@ -132,7 +132,7 @@ namespace XCharts.Runtime var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight); var itemColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, j, serieData.context.highlight); var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, serieData.context.highlight); - var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.ringGap); + var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.gap); var insideRadius = outsideRadius - ringWidth; var centerRadius = (outsideRadius + insideRadius) / 2; var borderWidth = itemStyle.borderWidth; diff --git a/Runtime/Serie/Serie.cs b/Runtime/Serie/Serie.cs index eed0ef08..7418c72c 100644 --- a/Runtime/Serie/Serie.cs +++ b/Runtime/Serie/Serie.cs @@ -187,7 +187,6 @@ namespace XCharts.Runtime [SerializeField] private bool m_BarPercentStack = false; [SerializeField] private float m_BarWidth = 0.6f; [SerializeField] private float m_BarGap = 0.3f; // 30% - [SerializeField] private float m_BarCategoryGap = 0.2f; // 20% [SerializeField] private float m_BarZebraWidth = 4f; [SerializeField] private float m_BarZebraGap = 2f; @@ -200,11 +199,10 @@ namespace XCharts.Runtime [SerializeField] private float m_MinAngle; [SerializeField] private bool m_Clockwise = true; [SerializeField] private bool m_RoundCap; - [SerializeField] private float m_RingGap = 10f; [SerializeField] private int m_SplitNumber; [SerializeField] private bool m_ClickOffset = true; [SerializeField] private RoseType m_RoseType = RoseType.None; - [SerializeField] private float m_Space; + [SerializeField] private float m_Gap; [SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.48f }; [SerializeField] private float[] m_Radius = new float[2] { 0, 80 }; @@ -488,19 +486,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_BarGap, value)) SetVerticesDirty(); } } /// - /// The bar gap of a single series, defaults to be 20% of the category gap, can be set as a fixed value. - /// In a single coodinate system, this attribute is shared by multiple 'bar' series. - /// This attribute should be set on the last 'bar' series in the coodinate system, - /// then it will be adopted by all 'bar' series in the coordinate system. - /// 同一系列的柱间距离,默认为类目间距的20%,可设固定值。 - /// 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。 - /// - public float barCategoryGap - { - get { return m_BarCategoryGap; } - set { if (PropertyUtil.SetStruct(ref m_BarCategoryGap, value)) SetVerticesDirty(); } - } - /// /// 斑马线的粗细。 /// public float barZebraWidth @@ -536,18 +521,13 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_RoseType, value)) SetVerticesDirty(); } } /// - /// the space of pie chart item. - /// 饼图项间的空隙留白。 + /// gap of item. + /// 间距。 /// - public float pieSpace - { - get { return m_Space; } - set { if (PropertyUtil.SetStruct(ref m_Space, value)) SetVerticesDirty(); } - } public float gap { - get { return m_Space; } - set { if (PropertyUtil.SetStruct(ref m_Space, value)) SetVerticesDirty(); } + get { return m_Gap; } + set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); } } /// /// the center of chart. @@ -632,15 +612,6 @@ namespace XCharts.Runtime get { return m_Clockwise; } set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetVerticesDirty(); } } - - /// - /// 环形图的环间隙。 - /// - public float ringGap - { - get { return m_RingGap; } - set { if (PropertyUtil.SetStruct(ref m_RingGap, value)) SetVerticesDirty(); } - } /// /// 刻度分割段数。最大可设置36。 /// @@ -742,15 +713,7 @@ namespace XCharts.Runtime public bool large { get { return m_Large; } - set - { - if (PropertyUtil.SetStruct(ref m_Large, value)) - { - SetAllDirty(); - if (label != null) - label.SetComponentDirty(); - } - } + set { if (PropertyUtil.SetStruct(ref m_Large, value)) SetAllDirty(); } } /// /// 开启大数量优化的阈值。只有当开启了large并且数据量大于该阀值时才进入性能模式。 @@ -758,15 +721,7 @@ namespace XCharts.Runtime public int largeThreshold { get { return m_LargeThreshold; } - set - { - if (PropertyUtil.SetStruct(ref m_LargeThreshold, value)) - { - SetAllDirty(); - if (label != null) - label.SetComponentDirty(); - } - } + set { if (PropertyUtil.SetStruct(ref m_LargeThreshold, value)) SetAllDirty(); } } /// /// 在饼图且标签外部显示的情况下,是否启用防止标签重叠策略,默认关闭,在标签拥挤重叠的情况下会挪动各个标签的位置,防止标签间的重叠。 @@ -942,6 +897,7 @@ namespace XCharts.Runtime public bool nameDirty { get { return m_NameDirty; } } public bool labelDirty { get; set; } public bool titleDirty { get; set; } + public bool dataDirty { get; set; } private void SetSerieNameDirty() { @@ -1080,6 +1036,7 @@ namespace XCharts.Runtime } m_Data.Clear(); m_NeedUpdateFilterData = true; + dataDirty = true; SetVerticesDirty(); } @@ -1105,6 +1062,7 @@ namespace XCharts.Runtime m_Data.RemoveAt(index); m_NeedUpdateFilterData = true; labelDirty = true; + dataDirty = true; } } @@ -1113,7 +1071,8 @@ namespace XCharts.Runtime /// /// /// - public SerieData AddYData(double value, string dataName = null) + /// the unique id of data + public SerieData AddYData(double value, string dataName = null, string dataId = null) { CheckMaxCache(); int xValue = m_Data.Count; @@ -1122,11 +1081,13 @@ namespace XCharts.Runtime serieData.data.Add(value); serieData.name = dataName; serieData.index = xValue; + serieData.id = dataId; AddSerieData(serieData); m_ShowDataDimension = 1; SetVerticesDirty(); CheckDataName(dataName); labelDirty = true; + dataDirty = true; return serieData; } @@ -1136,6 +1097,8 @@ namespace XCharts.Runtime m_Data.Insert(0, serieData); else m_Data.Add(serieData); + SetVerticesDirty(); + dataDirty = true; m_NeedUpdateFilterData = true; } @@ -1153,8 +1116,8 @@ namespace XCharts.Runtime /// /// /// - /// - public SerieData AddXYData(double xValue, double yValue, string dataName = null) + /// the unique id of data + public SerieData AddXYData(double xValue, double yValue, string dataName = null, string dataId = null) { CheckMaxCache(); var serieData = SerieDataPool.Get(); @@ -1163,6 +1126,7 @@ namespace XCharts.Runtime serieData.data.Add(yValue); serieData.name = dataName; serieData.index = m_Data.Count; + serieData.id = dataId; AddSerieData(serieData); m_ShowDataDimension = 2; SetVerticesDirty(); @@ -1179,8 +1143,9 @@ namespace XCharts.Runtime /// /// /// + /// the unique id of data /// - public SerieData AddData(double open, double close, double lowest, double heighest, string dataName = null) + public SerieData AddData(double open, double close, double lowest, double heighest, string dataName = null, string dataId = null) { CheckMaxCache(); var serieData = SerieDataPool.Get(); @@ -1191,6 +1156,7 @@ namespace XCharts.Runtime serieData.data.Add(heighest); serieData.name = dataName; serieData.index = m_Data.Count; + serieData.id = dataId; AddSerieData(serieData); m_ShowDataDimension = 4; SetVerticesDirty(); @@ -1205,14 +1171,14 @@ namespace XCharts.Runtime /// /// /// - /// - public SerieData AddData(List valueList, string dataName = null) + /// the unique id of data + public SerieData AddData(List valueList, string dataName = null, string dataId = null) { if (valueList == null || valueList.Count == 0) return null; if (valueList.Count == 1) - return AddYData(valueList[0], dataName); + return AddYData(valueList[0], dataName, dataId); else if (valueList.Count == 2) - return AddXYData(valueList[0], valueList[1], dataName); + return AddXYData(valueList[0], valueList[1], dataName, dataId); else { CheckMaxCache(); @@ -1220,6 +1186,7 @@ namespace XCharts.Runtime var serieData = SerieDataPool.Get(); serieData.name = dataName; serieData.index = m_Data.Count; + serieData.id = dataId; for (int i = 0; i < valueList.Count; i++) { serieData.data.Add(valueList[i]); @@ -1232,29 +1199,42 @@ namespace XCharts.Runtime } } - public SerieData AddChildData(SerieData parent, double value, string name = null) + public SerieData AddChildData(SerieData parent, double value, string name, string id) { var serieData = new SerieData(); serieData.name = name; serieData.index = m_Data.Count; - serieData.data = new List() { parent.children.Count, value }; - serieData.context.parent = parent; - AddSerieData(serieData); - parent.children.Add(serieData.index); + serieData.id = id; + serieData.data = new List() { m_Data.Count, value }; + AddChildData(parent, serieData); return serieData; } - public SerieData AddChildData(SerieData parent, List value, string name = null) + + public SerieData AddChildData(SerieData parent, List value, string name, string id) { var serieData = new SerieData(); serieData.name = name; serieData.index = m_Data.Count; + serieData.id = id; serieData.data = new List(value); - serieData.context.parent = parent; - AddSerieData(serieData); - parent.children.Add(serieData.index); + AddChildData(parent, serieData); return serieData; } + public void AddChildData(SerieData parent, SerieData serieData) + { + serieData.parentId = parent.id; + serieData.context.parent = parent; + + if (!m_Data.Contains(serieData)) + AddSerieData(serieData); + + if (!parent.context.children.Contains(serieData)) + { + parent.context.children.Add(serieData); + } + } + private void CheckMaxCache() { if (m_MaxCache <= 0) return; @@ -1360,23 +1340,23 @@ namespace XCharts.Runtime return null; } - public SerieData GetSerieData(string uuid, DataZoom dataZoom = null) + public SerieData GetSerieData(string id, DataZoom dataZoom = null) { var data = GetDataList(dataZoom); foreach (var serieData in data) { - var target = GetSerieData(serieData, uuid); + var target = GetSerieData(serieData, id); if (target != null) return target; } return null; } - public SerieData GetSerieData(SerieData parent, string uuid) + public SerieData GetSerieData(SerieData parent, string id) { - if (uuid.Equals(parent.uuid)) return parent; - foreach (var child in parent.children) + if (id.Equals(parent.id)) return parent; + foreach (var child in parent.context.children) { - var data = GetSerieData(GetSerieData(child), uuid); + var data = GetSerieData(child, id); if (data != null) { return data; @@ -1480,7 +1460,11 @@ namespace XCharts.Runtime var animationOpen = animation.enable; var animationDuration = animation.GetUpdateAnimationDuration(); var flag = m_Data[index].UpdateData(dimension, value, animationOpen, animationDuration); - if (flag) SetVerticesDirty(); + if (flag) + { + SetVerticesDirty(); + dataDirty = true; + } return flag; } else @@ -1504,6 +1488,7 @@ namespace XCharts.Runtime for (int i = 0; i < values.Count; i++) serieData.UpdateData(i, values[i], animationOpen, animationDuration); SetVerticesDirty(); + dataDirty = true; return true; } return false; diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs index c9076082..9cff4860 100644 --- a/Runtime/Serie/SerieContext.cs +++ b/Runtime/Serie/SerieContext.cs @@ -89,6 +89,7 @@ namespace XCharts.Runtime /// 排序后的数据 /// public List sortedData = new List(); + public List rootData = new List(); /// /// theme的颜色索引 /// diff --git a/Runtime/Serie/SerieData.cs b/Runtime/Serie/SerieData.cs index e922ff38..fa4b3478 100644 --- a/Runtime/Serie/SerieData.cs +++ b/Runtime/Serie/SerieData.cs @@ -12,11 +12,10 @@ namespace XCharts.Runtime [System.Serializable] public class SerieData : ChildComponent { + [SerializeField] private int m_Index; [SerializeField] private string m_Name; - [SerializeField] private string m_Uuid; - [SerializeField] private bool m_Selected; - [SerializeField] private bool m_Ignore = false; - [SerializeField] private float m_Radius; + [SerializeField] private string m_Id; + [SerializeField] private string m_ParentId; [SerializeField] private List m_ItemStyles = new List(); [SerializeField] private List m_Labels = new List(); [SerializeField] private List m_LabelLines = new List(); @@ -27,15 +26,18 @@ namespace XCharts.Runtime [SerializeField] private List m_AreaStyles = new List(); [SerializeField] private List m_TitleStyles = new List(); [SerializeField] private List m_Data = new List(); - [SerializeField] private List m_Children = new List(); [NonSerialized] public SerieDataContext context = new SerieDataContext(); [NonSerialized] public InteractData interact = new InteractData(); + [NonSerialized] private bool m_Ignore = false; + [NonSerialized] private bool m_Selected; + [NonSerialized] private float m_Radius; public ChartLabel labelObject { get; set; } public ChartLabel titleObject { get; set; } private bool m_Show = true; + public override int index { get { return m_Index; } set { m_Index = value; } } /// /// the name of data item. /// 数据项名称。 @@ -44,7 +46,8 @@ namespace XCharts.Runtime /// /// 数据项的唯一id。唯一id不是必须设置的。 /// - public string uuid { get { return m_Uuid; } set { m_Uuid = value; } } + public string id { get { return m_Id; } set { m_Id = value; } } + public string parentId { get { return m_ParentId; } set { m_ParentId = value; } } /// /// 数据项图例名称。当数据项名称不为空时,图例名称即为系列名称;反之则为索引index。 /// @@ -97,8 +100,6 @@ namespace XCharts.Runtime /// 可指定任意维数的数值列表。 /// public List data { get { return m_Data; } set { m_Data = value; } } - - public List children { get { return m_Children; } set { m_Children = value; } } /// /// [default:true] Whether the data item is showed. /// 该数据项是否要显示。 @@ -113,12 +114,16 @@ namespace XCharts.Runtime public void Reset() { index = 0; + m_Id = null; + m_ParentId = null; labelObject = null; m_Name = string.Empty; m_Show = true; m_Selected = false; context.canShowLabel = true; context.highlight = false; + context.children.Clear(); + context.dataPoints.Clear(); m_Radius = 0; interact.Reset(); m_Data.Clear(); diff --git a/Runtime/Serie/SerieDataContext.cs b/Runtime/Serie/SerieDataContext.cs index 2b170f78..7ec257a6 100644 --- a/Runtime/Serie/SerieDataContext.cs +++ b/Runtime/Serie/SerieDataContext.cs @@ -35,6 +35,8 @@ namespace XCharts.Runtime public float outsideRadius { get; set; } public Vector3 position { get; set; } public List dataPoints = new List(); + public List children = new List(); + /// /// 绘制区域。 /// diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 451b4975..cdf56dba 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -48,6 +48,7 @@ namespace XCharts.Runtime private static readonly string s_SerieTitleObjectName = "title"; private static readonly string s_SerieRootObjectName = "serie"; protected GameObject m_SerieRoot; + protected GameObject m_SerieLabelRoot; protected bool m_InitedLabel; protected bool m_NeedInitComponent; protected bool m_RefreshLabel; @@ -56,6 +57,7 @@ namespace XCharts.Runtime protected int m_LegendEnterIndex; public T serie { get; internal set; } + public GameObject labelObject { get { return m_SerieLabelRoot; } } internal override void SetSerie(Serie serie) { @@ -77,6 +79,11 @@ namespace XCharts.Runtime if (m_InitedLabel) RefreshLabelInternal(); } + if (serie.dataDirty) + { + serie.OnDataUpdate(); + serie.dataDirty = false; + } if (serie.label != null && (serie.labelDirty || serie.label.componentDirty)) { serie.labelDirty = false; @@ -182,10 +189,11 @@ namespace XCharts.Runtime { if (m_SerieRoot == null) InitRoot(); - var serieLabelRoot = ChartHelper.AddObject(s_SerieLabelObjectName, m_SerieRoot.transform, + m_SerieLabelRoot = ChartHelper.AddObject(s_SerieLabelObjectName, m_SerieRoot.transform, chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); - serieLabelRoot.hideFlags = chart.chartHideFlags; - SerieLabelPool.ReleaseAll(serieLabelRoot.transform); + m_SerieLabelRoot.hideFlags = chart.chartHideFlags; + //SerieLabelPool.ReleaseAll(m_SerieLabelRoot.transform); + ChartHelper.DestroyAllChildren(m_SerieLabelRoot.transform); int count = 0; SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); for (int j = 0; j < serie.data.Count; j++) @@ -193,7 +201,7 @@ namespace XCharts.Runtime var serieData = serie.data[j]; serieData.index = count; serieData.labelObject = null; - if (AddSerieLabel(serieLabelRoot, serie, serieData, ref count)) + if (AddSerieLabel(m_SerieLabelRoot, serie, serieData, ref count)) { m_InitedLabel = true; count++; @@ -204,6 +212,8 @@ namespace XCharts.Runtime protected bool AddSerieLabel(GameObject serieLabelRoot, Serie serie, SerieData serieData, ref int count) { + if (serieData == null) + return false; if (serieLabelRoot == null) return false; if (serie.IsPerformanceMode()) @@ -217,8 +227,9 @@ namespace XCharts.Runtime var serieEmphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData); var iconStyle = SerieHelper.GetIconStyle(serie, serieData); - if (!serieLabel.show && (serieEmphasisLabel == null || !serieEmphasisLabel.show) - && (iconStyle != null && !iconStyle.show)) + if (!serieLabel.show + && (serieEmphasisLabel == null || !serieEmphasisLabel.show) + && (iconStyle == null || !iconStyle.show)) return false; var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index); @@ -239,12 +250,14 @@ namespace XCharts.Runtime item.color = serieLabel.textStyle.backgroundColor; serieData.labelObject = item; - foreach (var data in serieData.children) + if (serieData.context.children.Count > 0) { - AddSerieLabel(serieLabelRoot, serie, serie.GetSerieData(data), ref count); - count++; + foreach (var childSerieData in serieData.context.children) + { + AddSerieLabel(serieLabelRoot, serie, childSerieData, ref count); + count++; + } } - return true; } diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 68b65b9b..feaebda5 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -1266,16 +1266,16 @@ namespace XUGL /// 结束角度 /// 边框宽度 /// 边框颜色 - /// 边距 + /// 边距 /// 光滑度 /// 渐变类型,0:向圆形渐变,1:水平或垂直渐变,2:开始角度向结束角度渐变 /// 水平渐变还是垂直渐变,gradientType为1时生效 public static void DrawSector(VertexHelper vh, Vector3 center, float radius, Color32 color, Color32 toColor, - float startDegree, float toDegree, float borderWidth, Color32 borderColor, float space, + float startDegree, float toDegree, float borderWidth, Color32 borderColor, float gap, float smoothness, int gradientType = 0, bool isYAxis = false) { if (radius == 0) return; - if (space > 0 && Mathf.Abs(toDegree - startDegree) >= 360) space = 0; + if (gap > 0 && Mathf.Abs(toDegree - startDegree) >= 360) gap = 0; radius -= borderWidth; smoothness = (smoothness < 0 ? 2f : smoothness); int segments = (int)((2 * Mathf.PI * radius) * (Mathf.Abs(toDegree - startDegree) / 360) / smoothness); @@ -1296,7 +1296,7 @@ namespace XUGL var lastP4 = center; var lastColor = color; var needBorder = borderWidth != 0; - var needSpace = space != 0; + var needSpace = gap != 0; var borderLineWidth = needSpace ? borderWidth : borderWidth / 2; var lastPos = Vector3.zero; var middleDire = UGLHelper.GetDire(startAngle + halfAngle); @@ -1306,10 +1306,10 @@ namespace XUGL float borderDiff = 0f; if (needSpace) { - spaceDiff = space / Mathf.Sin(halfAngle); + spaceDiff = gap / Mathf.Sin(halfAngle); spaceCenter = center + spaceDiff * middleDire; realCenter = spaceCenter; - spaceAngle = 2 * Mathf.Asin(space / (2 * radius)); + spaceAngle = 2 * Mathf.Asin(gap / (2 * radius)); realStartAngle = startAngle + spaceAngle; realToAngle = toAngle - spaceAngle; if (realToAngle < realStartAngle) realToAngle = realStartAngle; @@ -1452,14 +1452,14 @@ namespace XUGL public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, Color32 color, Color32 toColor, Color32 emptyColor, float startDegree, float toDegree, float borderWidth, - Color32 borderColor, float space, float smoothness, bool roundCap = false, bool clockwise = true) + Color32 borderColor, float gap, float smoothness, bool roundCap = false, bool clockwise = true) { if (toDegree - startDegree == 0) return; - if (space > 0 && Mathf.Abs(toDegree - startDegree) >= 360) space = 0; + if (gap > 0 && Mathf.Abs(toDegree - startDegree) >= 360) gap = 0; if (insideRadius <= 0) { DrawSector(vh, center, outsideRadius, color, toColor, startDegree, toDegree, borderWidth, borderColor, - space, smoothness); + gap, smoothness); return; } outsideRadius -= borderWidth; @@ -1467,7 +1467,7 @@ namespace XUGL smoothness = smoothness < 0 ? 2f : smoothness; Vector3 p1, p2, p3, p4, e1, e2; var needBorder = borderWidth != 0; - var needSpace = space != 0; + var needSpace = gap != 0; var diffAngle = Mathf.Abs(toDegree - startDegree) * Mathf.Deg2Rad; int segments = (int)((2 * Mathf.PI * outsideRadius) * (diffAngle * Mathf.Rad2Deg / 360) / smoothness); @@ -1506,12 +1506,12 @@ namespace XUGL { if (needSpace) { - var spaceDiff = space / Mathf.Sin(halfAngle); + var spaceDiff = gap / Mathf.Sin(halfAngle); spaceCenter = center + Mathf.Abs(spaceDiff) * middleDire; realCenter = spaceCenter; - spaceAngle = 2 * Mathf.Asin(space / (2 * outsideRadius)); - spaceInAngle = 2 * Mathf.Asin(space / (2 * insideRadius)); - spaceHalfAngle = 2 * Mathf.Asin(space / (2 * (insideRadius + (outsideRadius - insideRadius) / 2))); + spaceAngle = 2 * Mathf.Asin(gap / (2 * outsideRadius)); + spaceInAngle = 2 * Mathf.Asin(gap / (2 * insideRadius)); + spaceHalfAngle = 2 * Mathf.Asin(gap / (2 * (insideRadius + (outsideRadius - insideRadius) / 2))); if (clockwise) { p1 = UGLHelper.GetPos(center, insideRadius, startAngle + spaceInAngle, false);