diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md index dd4ccd19..4d333b91 100644 --- a/Documentation~/en/api.md +++ b/Documentation~/en/api.md @@ -1362,6 +1362,11 @@ class in XCharts.Runtime / Inherits from: [MainComponent](#maincomponent) Background component. +### Background.rect + +public Rect rect +the rect of background. + ### Background.SetDefaultValue public override void SetDefaultValue() @@ -2353,6 +2358,10 @@ class in XCharts.Runtime / Inherits from: [MaskableGraphic](https://docs.unity3d public virtual HideFlags chartHideFlags +### BaseGraph.childrenNodeNames + +public List<string> childrenNodeNames + ### BaseGraph.clickPos public Vector2 clickPos @@ -2411,6 +2420,10 @@ The x of graph. public float graphY The y of graph. +### BaseGraph.isDragingClick + +public bool isDragingClick + ### BaseGraph.isPointerClick public bool isPointerClick @@ -2759,6 +2772,10 @@ public float GetRuntimeBorderWidth() public float[] GetRuntimeCornerRadius() +### BorderStyle.IsCricle + +public bool IsCricle() + ## CalendarCoord class in XCharts.Runtime / Inherits from: [CoordSystem](#coordsystem),[IUpdateRuntimeData](#iupdateruntimedata),[ISerieContainer](#iseriecontainer) @@ -2893,7 +2910,8 @@ public static void DestoryGameObject(GameObject go) ### ChartHelper.DestoryGameObjectByMatch -public static void DestoryGameObjectByMatch(Transform parent, string containString) +public static void DestoryGameObjectByMatch(Transform parent, List<string> children) + ### ChartHelper.DestroyAllChildren @@ -2940,7 +2958,8 @@ public static Vector3 GetLastValue(List<Vector3> list) ### ChartHelper.GetMaxCeilRate -public static double GetMaxCeilRate(double value, double ceilRate) +public static float GetMaxCeilRate(float value, float ceilRate) + ### ChartHelper.GetMaxDivisibleValue @@ -2952,7 +2971,8 @@ public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE ### ChartHelper.GetMinCeilRate -public static double GetMinCeilRate(double value, double ceilRate) +public static float GetMinCeilRate(float value, float ceilRate) + ### ChartHelper.GetMinDivisibleValue @@ -5317,6 +5337,10 @@ public float runtimeTop public Vector3 GetPosition(float chartWidth, float chartHeight) 返回在坐标系中的具体位置 +### Location.GetRect + +public Rect GetRect(float graphX, float graphY, float graphWidth, float graphHeight, float rectWidth, float rectHeight) + ### Location.IsBottom public bool IsBottom() @@ -9087,6 +9111,11 @@ class in XCharts.Runtime UI帮助类。 +### UIHelper.DrawBackground + +public static void DrawBackground(VertexHelper vh, Background background, Color32 color, float smoothness = 2) + + ## ViewControl class in XCharts.Runtime / Inherits from: [ChildComponent](#childcomponent) diff --git a/Documentation~/en/changelog.md b/Documentation~/en/changelog.md index 4acc2e5c..46057a4c 100644 --- a/Documentation~/en/changelog.md +++ b/Documentation~/en/changelog.md @@ -6,6 +6,7 @@ slug: /changelog # Changelog [master](#master) +[v3.13.0](#v3130) [v3.12.1](#v3121) [v3.12.0](#v3120) [v3.11.2](#v3112) @@ -77,6 +78,33 @@ slug: /changelog ## master +## v3.13.0 + +Key Features: + +* Added the `UIText` extension component +* Added the `UIToggle` extension component +* Added the `UISlider` extension component +* Refactored the `UIProgress` extension component +* Added `borderWidth` and `emptyColor` configurations to `SymbolStyle` +* Added the `size2` parameter to `SymbolStyle` to support rectangular markers +* Other optimizations and bug fixes + +Detailed Changelog: + +* (2025.01.01) Released `v3.13.0` +* (2024.12.27) Added the `size2` parameter to `SymbolStyle` to support rectangular markers +* (2024.12.26) Optimized `Text` alignment in `TextMeshPro` for proper centering +* (2024.12.25) Added support for `{f0}` in the `Tooltip`'s `itemFormatter` setting +* (2024.12.25) Fixed an issue where some labels on the `YAxis` might not display during range refresh +* (2024.12.23) Added `borderWidth` and `emptyColor` configurations to `SymbolStyle` +* (2024.12.17) Added the `UISlider` extension component +* (2024.12.10) Added the `UIToggle` extension component +* (2024.12.09) Fixed an issue where the `UITable`'s `scrollbar` could not be dragged +* (2024.12.07) Fixed an issue where custom nodes could not be placed under the `Chart` node +* (2024.12.05) Added the `UIText` extension component +* (2024.12.04) Removed the unused `tmpAlignment` option from `TextStyle` + ## v3.12.1 Version Highlights: diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index 80e49047..3668730f 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -4366,12 +4366,24 @@ class in XCharts.Runtime / Inherits from: [ChildComponent](#childcomponent) / Su 系列数据项的标记的图形 +### SymbolStyle.borderWidth + +`float` `0f` `v3.13.0` + +the border width of symbol. + ### SymbolStyle.color `Color32` 图形的颜色。 +### SymbolStyle.emptyColor + +`Color32` `v3.13.0` + +the color of empty symbol. + ### SymbolStyle.gap `float` `0` @@ -4414,6 +4426,12 @@ Whether the symbol is showed. the size of symbol. +### SymbolStyle.size2 + +`float` `0f` `v3.13.0` + +the size of symbol. + ### SymbolStyle.type [SymbolType](#symboltype) @@ -4551,10 +4569,6 @@ Rotation of text. Settings related to text. -### TextStyle.tMPAlignment - -`TextAlignmentOptions` - ### TextStyle.tMPFont `TMP_FontAsset` diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index 5a7d7425..2afbafb9 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -1362,6 +1362,11 @@ class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent) 背景组件。 +### Background.rect + +public Rect rect +背景的矩形区域。 + ### Background.SetDefaultValue public override void SetDefaultValue() @@ -2353,6 +2358,10 @@ class in XCharts.Runtime / 继承自: [MaskableGraphic](https://docs.unity3d.com public virtual HideFlags chartHideFlags +### BaseGraph.childrenNodeNames + +public List<string> childrenNodeNames + ### BaseGraph.clickPos public Vector2 clickPos @@ -2411,6 +2420,10 @@ public float graphX public float graphY 图形的Y +### BaseGraph.isDragingClick + +public bool isDragingClick + ### BaseGraph.isPointerClick public bool isPointerClick @@ -2759,6 +2772,10 @@ public float GetRuntimeBorderWidth() public float[] GetRuntimeCornerRadius() +### BorderStyle.IsCricle + +public bool IsCricle() + ## CalendarCoord class in XCharts.Runtime / 继承自: [CoordSystem](#coordsystem),[IUpdateRuntimeData](#iupdateruntimedata),[ISerieContainer](#iseriecontainer) @@ -2893,7 +2910,8 @@ public static void DestoryGameObject(GameObject go) ### ChartHelper.DestoryGameObjectByMatch -public static void DestoryGameObjectByMatch(Transform parent, string containString) +public static void DestoryGameObjectByMatch(Transform parent, List<string> children) + ### ChartHelper.DestroyAllChildren @@ -2940,7 +2958,8 @@ public static Vector3 GetLastValue(List<Vector3> list) ### ChartHelper.GetMaxCeilRate -public static double GetMaxCeilRate(double value, double ceilRate) +public static float GetMaxCeilRate(float value, float ceilRate) + ### ChartHelper.GetMaxDivisibleValue @@ -2952,7 +2971,8 @@ public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE ### ChartHelper.GetMinCeilRate -public static double GetMinCeilRate(double value, double ceilRate) +public static float GetMinCeilRate(float value, float ceilRate) + ### ChartHelper.GetMinDivisibleValue @@ -5317,6 +5337,10 @@ public float runtimeTop public Vector3 GetPosition(float chartWidth, float chartHeight) 返回在坐标系中的具体位置 +### Location.GetRect + +public Rect GetRect(float graphX, float graphY, float graphWidth, float graphHeight, float rectWidth, float rectHeight) + ### Location.IsBottom public bool IsBottom() @@ -9087,6 +9111,11 @@ class in XCharts.Runtime UI帮助类。 +### UIHelper.DrawBackground + +public static void DrawBackground(VertexHelper vh, Background background, Color32 color, float smoothness = 2) + + ## ViewControl class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 8743b88d..4f4657a2 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -6,6 +6,7 @@ slug: /changelog # 更新日志 [master](#master) +[v3.13.0](#v3130) [v3.12.1](#v3121) [v3.12.0](#v3120) [v3.11.2](#v3112) @@ -78,6 +79,33 @@ slug: /changelog ## master +## v3.13.0 + +版本要点: + +* 新增`UIText`扩展组件 +* 新增`UIToggle`扩展组件 +* 新增`UISlider`扩展组件 +* 重构`UIProgress`扩展组件 +* 增加`SymbolStyle`的`borderWidth`和`emptyColor`配置 +* 增加`SymbolStyle`的`size2`参数支持长方形标记 +* 其他优化和问题修复 + +日志详情: + +* (2025.01.01) 发布`v3.13.0`版本 +* (2024.12.27) 增加`SymbolStyle`的`size2`参数支持长方形标记 +* (2024.12.26) 优化`Text`在`TextMeshPro`下的居中对齐方式 +* (2024.12.25) 增加`Tooltip`的`itemFormatter`设置`{f0}`支持 +* (2024.12.25) 修复`YAxis`在范围变更刷新时部分label可能不显示的问题 +* (2024.12.23) 增加`SymbolStyle`的`borderWidth`和`emptyColor`配置 +* (2024.12.17) 增加`UISlider`扩展组件 +* (2024.12.10) 增加`UIToggle`扩展组件 +* (2024.12.09) 修复`UITable`的`scrollbar`无法拖动的问题 +* (2024.12.07) 修复`Chart`节点下不能放自定义节点的问题 +* (2024.12.05) 增加`UIText`扩展组件 +* (2024.12.04) 删除`TextStyle`的无用配置项`tmpAlignment` + ## v3.12.1 版本要点: @@ -153,8 +181,6 @@ slug: /changelog 日志详情: - - * (2024.06.16) 发布`v3.11.0`版本 * (2024.06.15) 增加`Editor`下`Data`的添加、删除、上下移动操作按钮 * (2024.06.11) 修复`Axis`的`IndicatorLabel`可能会遮挡住`Tooltip`的问题 diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index 9514a70b..c0f85e72 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -4366,12 +4366,24 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent) / 子类 系列数据项的标记的图形 +### SymbolStyle.borderWidth + +`float` `0f` `v3.13.0` + +图形的边框宽度。 + ### SymbolStyle.color `Color32` 图形的颜色。 +### SymbolStyle.emptyColor + +`Color32` `v3.13.0` + +空心图形的颜色。 + ### SymbolStyle.gap `float` `0` @@ -4414,6 +4426,12 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent) / 子类 标记的大小。 +### SymbolStyle.size2 + +`float` `0f` `v3.13.0` + +标记的大小。当为Rect时,size2表示高度。 + ### SymbolStyle.type [SymbolType](#symboltype) @@ -4551,10 +4569,6 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent) 文本的相关设置。 -### TextStyle.tMPAlignment - -`TextAlignmentOptions` - ### TextStyle.tMPFont `TMP_FontAsset` diff --git a/Editor/ChildComponents/SymbolStyleDrawer.cs b/Editor/ChildComponents/SymbolStyleDrawer.cs index edd66978..0ea89711 100644 --- a/Editor/ChildComponents/SymbolStyleDrawer.cs +++ b/Editor/ChildComponents/SymbolStyleDrawer.cs @@ -27,7 +27,10 @@ namespace XCharts.Editor } PropertyField(prop, "m_Color"); PropertyField(prop, "m_Size"); + PropertyField(prop, "m_Size2"); PropertyField(prop, "m_Gap"); + PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_EmptyColor"); PropertyField(prop, "m_Offset"); --EditorGUI.indentLevel; } diff --git a/Editor/ChildComponents/TextStyleDrawer.cs b/Editor/ChildComponents/TextStyleDrawer.cs index 70f44b6f..d2239723 100644 --- a/Editor/ChildComponents/TextStyleDrawer.cs +++ b/Editor/ChildComponents/TextStyleDrawer.cs @@ -27,14 +27,13 @@ namespace XCharts.Editor PropertyField(prop, "m_Color"); PropertyField(prop, "m_FontSize"); PropertyField(prop, "m_LineSpacing"); + PropertyField(prop, "m_Alignment"); + PropertyField(prop, "m_AutoAlign"); #if dUI_TextMeshPro PropertyField(prop, "m_TMPFontStyle"); PropertyField(prop, "m_TMPSpriteAsset"); - PropertyField(prop, "m_TMPAlignment"); #else PropertyField(prop, "m_FontStyle"); - PropertyField(prop, "m_Alignment"); - PropertyField(prop, "m_AutoAlign"); PropertyField(prop, "m_AutoWrap"); #endif --EditorGUI.indentLevel; diff --git a/Editor/Utilities/ChartEditorHelper.cs b/Editor/Utilities/ChartEditorHelper.cs index afe48c66..27ffdafd 100644 --- a/Editor/Utilities/ChartEditorHelper.cs +++ b/Editor/Utilities/ChartEditorHelper.cs @@ -108,11 +108,11 @@ namespace XCharts.Editor { EditorGUI.LabelField(drawRect, name); var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH; - var diff = 13 + EditorGUI.indentLevel * 14; + var diff = 12 + EditorGUI.indentLevel * 14; var offset = diff - INDENT_WIDTH; var tempWidth = (rectWidth - startX + diff) / 2; var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height - 1); - var centerYRect = new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1); + var centerYRect = new Rect(centerXRect.x + tempWidth - offset + 3.4f, drawRect.y, tempWidth - 1, drawRect.height - 1); EditorGUI.PropertyField(centerXRect, prop1, GUIContent.none); EditorGUI.PropertyField(centerYRect, prop2, GUIContent.none); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -326,7 +326,13 @@ namespace XCharts.Editor var foldoutRect = drawRect; foldoutRect.xMax -= 10; bool flag = EditorGUI.Foldout(foldoutRect, foldout, listProp.displayName, true); - ChartEditorHelper.DrawMenu(drawRect, menus); + if (!flag) + { + var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH; + var sizeRect = new Rect(startX, drawRect.y + 1f, (EditorGUI.indentLevel + 1) * 15, drawRect.height - 1); + EditorGUI.IntField(sizeRect, GUIContent.none, listProp.arraySize); + DrawMenu(drawRect, menus); + } height += headerHeight; drawRect.y += headerHeight; drawRect.width = rawWidth; diff --git a/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs b/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs index 8818d016..ce8aa36e 100644 --- a/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs +++ b/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs @@ -67,7 +67,7 @@ namespace XCharts.Runtime string objName = component.GetType().Name + axis.index; var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show); axisObj.hideFlags = chart.chartHideFlags; diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index a36ec72b..23e69d47 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -372,6 +372,7 @@ namespace XCharts var axisLength = (axis.context.end - axis.context.start).magnitude; if (axisLength == 0) return; chart.InitAxisRuntimeData(axis); + UpdateAxisMinMaxValue(axis.index, axis, true); var objName = ChartCached.GetComponentObjectName(axis); var axisObj = ChartHelper.AddObject(objName, @@ -379,7 +380,7 @@ namespace XCharts chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, - chart.chartSizeDelta); + chart.chartSizeDelta, -1, chart.childrenNodeNames); axisObj.SetActive(axis.show); axisObj.hideFlags = chart.chartHideFlags; @@ -473,7 +474,6 @@ namespace XCharts break; } } - UpdateAxisMinMaxValue(axis.index, axis, true); } protected void InitAxis(Axis relativedAxis, Orient orient, @@ -481,6 +481,7 @@ namespace XCharts { Axis axis = component; chart.InitAxisRuntimeData(axis); + UpdateAxisMinMaxValue(axis.index, axis, true); var objName = ChartCached.GetComponentObjectName(axis); var axisObj = ChartHelper.AddObject(objName, @@ -488,7 +489,7 @@ namespace XCharts chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, - chart.chartSizeDelta); + chart.chartSizeDelta, -1, chart.childrenNodeNames); axisObj.SetActive(axis.show); axisObj.hideFlags = chart.chartHideFlags; @@ -637,7 +638,6 @@ namespace XCharts } } } - UpdateAxisMinMaxValue(axis.index, axis, true); } internal static Vector3 GetLabelPosition(int i, Orient orient, Axis axis, Axis relativedAxis, AxisTheme theme, diff --git a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs index 5a84d71f..6feca7f5 100644 --- a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs +++ b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs @@ -99,7 +99,7 @@ namespace XCharts.Runtime var radius = polar.context.outsideRadius - polar.context.insideRadius; var objName = component.GetType().Name + axis.index; var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chart.chartHideFlags; diff --git a/Runtime/Component/Background/Background.cs b/Runtime/Component/Background/Background.cs index bce23b29..c6ee38f7 100644 --- a/Runtime/Component/Background/Background.cs +++ b/Runtime/Component/Background/Background.cs @@ -100,6 +100,12 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetClass(ref m_BorderStyle, value)) SetComponentDirty(); } } + /// + /// the rect of background. + /// ||背景的矩形区域。 + /// + public Rect rect { get; set; } + public override void SetDefaultValue() { m_Show = true; diff --git a/Runtime/Component/Background/BackgroundHandler.cs b/Runtime/Component/Background/BackgroundHandler.cs index bb53f759..b79ccd60 100644 --- a/Runtime/Component/Background/BackgroundHandler.cs +++ b/Runtime/Component/Background/BackgroundHandler.cs @@ -15,7 +15,7 @@ namespace XCharts.Runtime component.refreshComponent = delegate () { var backgroundObj = ChartHelper.AddObject(s_BackgroundObjectName, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); component.gameObject = backgroundObj; backgroundObj.hideFlags = chart.chartHideFlags; diff --git a/Runtime/Component/Child/BorderStyle.cs b/Runtime/Component/Child/BorderStyle.cs index 6ef2124c..2a828ad5 100644 --- a/Runtime/Component/Child/BorderStyle.cs +++ b/Runtime/Component/Child/BorderStyle.cs @@ -82,5 +82,11 @@ namespace XCharts.Runtime { return m_Show && roundedCorner ? m_CornerRadius : null; } + + public bool IsCricle() + { + return roundedCorner && m_CornerRadius[0] == 1 && m_CornerRadius[1] == 1 && + m_CornerRadius[2] == 1 && m_CornerRadius[3] == 1; + } } } \ No newline at end of file diff --git a/Runtime/Component/Child/Location.cs b/Runtime/Component/Child/Location.cs index 0d49d6c7..ea010f2c 100644 --- a/Runtime/Component/Child/Location.cs +++ b/Runtime/Component/Child/Location.cs @@ -349,6 +349,69 @@ namespace XCharts.Runtime } } + public Rect GetRect(float graphX, float graphY, float graphWidth, float graphHeight, float rectWidth, float rectHeight) + { + UpdateRuntimeData(graphWidth, graphWidth); + + float x, y, width, height; + + width = rectWidth == 0 ? graphWidth - runtimeLeft - runtimeRight : rectWidth; + height = rectHeight == 0 ? graphHeight - runtimeBottom - runtimeTop : rectHeight; + + switch (align) + { + case Align.BottomCenter: + x = graphX + runtimeLeft + (graphWidth - runtimeLeft - runtimeRight - width) / 2; + y = graphY + runtimeBottom; + break; + + case Align.BottomLeft: + x = graphX + runtimeLeft; + y = graphY + runtimeBottom; + break; + + case Align.BottomRight: + x = graphX + graphWidth - runtimeRight - width; + y = graphY + runtimeBottom; + break; + + case Align.Center: + x = graphX + runtimeLeft + (graphWidth - runtimeLeft - runtimeRight - width) / 2; + y = graphY + runtimeBottom + (graphHeight - runtimeBottom - runtimeTop - height) / 2; + break; + + case Align.CenterLeft: + x = graphX + runtimeLeft; + y = graphY + runtimeBottom + (graphHeight - runtimeBottom - runtimeTop - height) / 2; + break; + + case Align.CenterRight: + x = graphX + graphWidth - runtimeRight - width; + y = graphY + runtimeBottom + (graphHeight - runtimeBottom - runtimeTop - height) / 2; + break; + + case Align.TopCenter: + x = graphX + runtimeLeft + (graphWidth - runtimeLeft - runtimeRight - width) / 2; + y = graphY + graphHeight - runtimeTop - height; + break; + + case Align.TopLeft: + x = graphX + runtimeLeft; + y = graphY + graphHeight - runtimeTop - height; + break; + + case Align.TopRight: + x = graphX + graphWidth - runtimeRight - width; + y = graphY + graphHeight - runtimeTop - height; + break; + + default: + return new Rect(0, 0, 0, 0); + } + return new Rect(x, y, width, height); + } + + /// /// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot /// diff --git a/Runtime/Component/Child/SymbolStyle.cs b/Runtime/Component/Child/SymbolStyle.cs index 98d62178..54e7a63f 100644 --- a/Runtime/Component/Child/SymbolStyle.cs +++ b/Runtime/Component/Child/SymbolStyle.cs @@ -84,12 +84,16 @@ namespace XCharts.Runtime [SerializeField] protected Sprite m_Image; [SerializeField] protected Image.Type m_ImageType; [SerializeField] protected Color32 m_Color; + [SerializeField][Since("v3.13.0")] protected float m_BorderWidth = 0f; + [SerializeField][Since("v3.13.0")] protected Color32 m_EmptyColor; + [SerializeField][Since("v3.13.0")] protected float m_Size2 = 0f; public virtual void Reset() { m_Show = false; m_Type = SymbolType.EmptyCircle; m_Size = 0f; + m_Size2 = 0f; m_Gap = 0; m_Width = 0f; m_Height = 0f; @@ -126,6 +130,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Size, value)) SetVerticesDirty(); } } /// + /// the size of symbol. + /// ||标记的大小。当为Rect时,size2表示高度。 + /// + public float size2 + { + get { return m_Size2; } + set { if (PropertyUtil.SetStruct(ref m_Size2, value)) SetVerticesDirty(); } + } + /// /// the gap of symbol and line segment. /// ||图形标记和线条的间隙距离。 /// @@ -183,6 +196,24 @@ namespace XCharts.Runtime get { return m_Color; } set { if (PropertyUtil.SetStruct(ref m_Color, value)) SetAllDirty(); } } + /// + /// the border width of symbol. + /// ||图形的边框宽度。 + /// + public float borderWidth + { + get { return m_BorderWidth; } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetAllDirty(); } + } + /// + /// the color of empty symbol. + /// ||空心图形的颜色。 + /// + public Color32 emptyColor + { + get { return m_EmptyColor; } + set { if (PropertyUtil.SetStruct(ref m_EmptyColor, value)) SetAllDirty(); } + } public Vector3 offset3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } } private List m_AnimationSize = new List() { 0, 5, 10 }; /// diff --git a/Runtime/Component/Child/TextStyle.cs b/Runtime/Component/Child/TextStyle.cs index 36c0489e..1f2c55ea 100644 --- a/Runtime/Component/Child/TextStyle.cs +++ b/Runtime/Component/Child/TextStyle.cs @@ -27,7 +27,6 @@ namespace XCharts.Runtime #if dUI_TextMeshPro [SerializeField] private TMP_FontAsset m_TMPFont; [SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal; - [SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left; [SerializeField][Since("v3.1.0")] private TMP_SpriteAsset m_TMPSpriteAsset; #endif public bool show @@ -147,15 +146,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); } } /// - /// the text alignment of TextMeshPro. - /// ||TextMeshPro字体对齐方式。 - /// - public TextAlignmentOptions tmpAlignment - { - get { return m_TMPAlignment; } - set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); } - } - /// /// the sprite asset of TextMeshPro. /// ||TextMeshPro的Sprite Asset。 /// @@ -214,11 +204,7 @@ namespace XCharts.Runtime public void UpdateAlignmentByLocation(Location location) { -#if dUI_TextMeshPro - m_TMPAlignment = location.runtimeTMPTextAlignment; -#else m_Alignment = location.runtimeTextAlignment; -#endif } public Color GetColor(Color defaultColor) diff --git a/Runtime/Component/Comment/CommentHander.cs b/Runtime/Component/Comment/CommentHander.cs index 1fc580e4..b0d06eb5 100644 --- a/Runtime/Component/Comment/CommentHander.cs +++ b/Runtime/Component/Comment/CommentHander.cs @@ -22,7 +22,7 @@ namespace XCharts.Runtime chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, - chart.chartSizeDelta); + chart.chartSizeDelta, -1, chart.childrenNodeNames); commentObj.SetActive(comment.show); commentObj.hideFlags = chart.chartHideFlags; diff --git a/Runtime/Component/DataZoom/DataZoomHandler.cs b/Runtime/Component/DataZoom/DataZoomHandler.cs index cfbeaf43..14b78906 100644 --- a/Runtime/Component/DataZoom/DataZoomHandler.cs +++ b/Runtime/Component/DataZoom/DataZoomHandler.cs @@ -27,7 +27,7 @@ namespace XCharts.Runtime dataZoom.refreshComponent = delegate () { var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom + dataZoom.index, chart.transform, - chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); dataZoom.gameObject = dataZoomObject; dataZoomObject.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(dataZoomObject); diff --git a/Runtime/Component/Debug/DebugInfo.cs b/Runtime/Component/Debug/DebugInfo.cs index 966d7a98..e7aa0849 100644 --- a/Runtime/Component/Debug/DebugInfo.cs +++ b/Runtime/Component/Debug/DebugInfo.cs @@ -75,7 +75,7 @@ namespace XCharts.Runtime public void Init(BaseChart chart) { m_Chart = chart; - m_Label = AddDebugInfoObject("debug", chart.transform, m_LabelStyle, chart.theme); + m_Label = AddDebugInfoObject("debug", chart.transform, m_LabelStyle, chart.theme, chart.childrenNodeNames); } public void Update() @@ -155,14 +155,14 @@ namespace XCharts.Runtime } private ChartLabel AddDebugInfoObject(string name, Transform parent, LabelStyle labelStyle, - ThemeStyle theme) + ThemeStyle theme, List childrenNodeNames) { var anchorMax = new Vector2(0, 1); var anchorMin = new Vector2(0, 1); var pivot = new Vector2(0, 1); var sizeDelta = new Vector2(100, 100); - var labelGameObject = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + var labelGameObject = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta, -1, childrenNodeNames); labelGameObject.transform.SetAsLastSibling(); labelGameObject.hideFlags = m_Chart.chartHideFlags; ChartHelper.SetActive(labelGameObject, m_ShowDebugInfo); diff --git a/Runtime/Component/Label/SerieLabelHelper.cs b/Runtime/Component/Label/SerieLabelHelper.cs index 2dc111e4..b05ffaae 100644 --- a/Runtime/Component/Label/SerieLabelHelper.cs +++ b/Runtime/Component/Label/SerieLabelHelper.cs @@ -45,7 +45,7 @@ namespace XCharts.Runtime { var content = serieLabel.formatter; FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue, - dataTotal, serieName, dataName, dataName, color, serieData, chart); + dataTotal, serieName, dataName, dataName, color, serieData, chart, serie.index); if (serieLabel.formatterFunction == null) return content; else diff --git a/Runtime/Component/Legend/LegendHandler.cs b/Runtime/Component/Legend/LegendHandler.cs index aa830414..f098c929 100644 --- a/Runtime/Component/Legend/LegendHandler.cs +++ b/Runtime/Component/Legend/LegendHandler.cs @@ -55,7 +55,7 @@ namespace XCharts.Runtime { legend.OnChanged(); var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); legend.gameObject = legendObject; legendObject.hideFlags = chart.chartHideFlags; //ChartHelper.DestoryGameObjectByMatch(legendObject.transform, "_"); diff --git a/Runtime/Component/Legend/LegendHelper.cs b/Runtime/Component/Legend/LegendHelper.cs index 1ee362e3..ffc55f36 100644 --- a/Runtime/Component/Legend/LegendHelper.cs +++ b/Runtime/Component/Legend/LegendHelper.cs @@ -48,7 +48,7 @@ namespace XCharts.Runtime var objAnchorMin = new Vector2(0, 1); var objAnchorMax = new Vector2(0, 1); var objPivot = new Vector2(0, 1); - var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta); + var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, -1, chart.childrenNodeNames); var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta); var img = ChartHelper.EnsureComponent(btnObj); img.color = Color.clear; diff --git a/Runtime/Component/Mark/MarkAreaHandler.cs b/Runtime/Component/Mark/MarkAreaHandler.cs index 98b9f6c9..df8eb1f9 100644 --- a/Runtime/Component/Mark/MarkAreaHandler.cs +++ b/Runtime/Component/Mark/MarkAreaHandler.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime public override void InitComponent() { m_MarkLineLabelRoot = ChartHelper.AddObject("markarea" + component.index, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); m_MarkLineLabelRoot.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(m_MarkLineLabelRoot); InitMarkArea(component); diff --git a/Runtime/Component/Mark/MarkLineHandler.cs b/Runtime/Component/Mark/MarkLineHandler.cs index fcdb7a3c..ccf6cf1b 100644 --- a/Runtime/Component/Mark/MarkLineHandler.cs +++ b/Runtime/Component/Mark/MarkLineHandler.cs @@ -13,7 +13,7 @@ namespace XCharts.Runtime public override void InitComponent() { m_MarkLineLabelRoot = ChartHelper.AddObject("markline", chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); m_MarkLineLabelRoot.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(m_MarkLineLabelRoot); InitMarkLine(component); diff --git a/Runtime/Component/Radar/RadarCoordHandler.cs b/Runtime/Component/Radar/RadarCoordHandler.cs index 15d3740b..3b820d39 100644 --- a/Runtime/Component/Radar/RadarCoordHandler.cs +++ b/Runtime/Component/Radar/RadarCoordHandler.cs @@ -41,7 +41,7 @@ namespace XCharts.Runtime { radar.UpdateRadarCenter(chart); var radarObject = ChartHelper.AddObject("Radar" + radar.index, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); radar.gameObject = radarObject; radar.gameObject.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(radarObject.transform, INDICATOR_TEXT); diff --git a/Runtime/Component/Title/TitleHandler.cs b/Runtime/Component/Title/TitleHandler.cs index d1556c83..9f789aba 100644 --- a/Runtime/Component/Title/TitleHandler.cs +++ b/Runtime/Component/Title/TitleHandler.cs @@ -22,7 +22,7 @@ namespace XCharts.Runtime var pivot = title.location.runtimePivot; var objName = ChartCached.GetComponentObjectName(title); var titleObject = ChartHelper.AddObject(objName, chart.transform, anchorMin, anchorMax, - pivot, chart.chartSizeDelta); + pivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); title.gameObject = titleObject; title.gameObject.transform.SetSiblingIndex(chart.m_PainterUpper.transform.GetSiblingIndex() + 1); anchorMin = title.location.runtimeAnchorMin; diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index 21787aa1..449b7991 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -53,7 +53,7 @@ namespace XCharts.Runtime { var objName = ChartCached.GetComponentObjectName(tooltip); tooltip.gameObject = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); var tooltipObject = tooltip.gameObject; tooltipObject.transform.localPosition = Vector3.zero; tooltipObject.hideFlags = chart.chartHideFlags; diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index 4b42b71d..467dce83 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -44,7 +44,8 @@ namespace XCharts.Runtime param.serieData.name, param.color, param.serieData, - chart); + chart, + param.serieIndex); foreach (var item in content.Split('|')) { param.columns.Add(item); diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index 6a9ac8ad..2ab5a4da 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -149,7 +149,7 @@ namespace XCharts.Runtime else if (p == 'c' || p == 'C' || p == 'd' || p == 'D' || p == 'f' || p == 'f') { var isPercent = p == 'd' || p == 'D'; - var isTotal = p == 'f' || p == 'f'; + var isTotal = p == 'f' || p == 'F'; var bIndex = dataIndex; var dimensionIndex = -1; if (argsCount >= 2) @@ -211,7 +211,7 @@ namespace XCharts.Runtime } public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, int dataCount, double value, double total, - string serieName, string category, string dataName, Color color, SerieData serieData, BaseChart chart = null) + string serieName, string category, string dataName, Color color, SerieData serieData, BaseChart chart = null, int serieIndex = 0) { var mc = s_RegexForSerieLabel.Matches(content); foreach (var m in mc) @@ -270,6 +270,14 @@ namespace XCharts.Runtime } else if (p == 'f' || p == 'f') { + if (pIndex != 1 && chart != null) + { + var serie = chart.GetSerie(serieIndex); + if (serie != null) + { + total = serie.GetDataTotal(pIndex, serieData); + } + } content = content.Replace(old, ChartCached.NumberToStr(total, numericFormatter)); } else if (p == 'g' || p == 'G') diff --git a/Runtime/Internal/BaseChart.Draw.cs b/Runtime/Internal/BaseChart.Draw.cs index f23303be..aef62386 100644 --- a/Runtime/Internal/BaseChart.Draw.cs +++ b/Runtime/Internal/BaseChart.Draw.cs @@ -54,8 +54,8 @@ namespace XCharts.Runtime p4 = ClampInGrid(grid, p4); } if (!clip || - (clip && (grid.Contains(p1) && grid.Contains(p2) && grid.Contains(p3) && - grid.Contains(p4)))) + (clip && grid.Contains(p1) && grid.Contains(p2) && grid.Contains(p3) && + grid.Contains(p4))) UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, startColor, toColor); } @@ -83,12 +83,12 @@ namespace XCharts.Runtime public void DrawClipSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness, Vector3 pos, Color32 color, Color32 toColor, Color32 emptyColor, Color32 borderColor, float gap, - bool clip, float[] cornerRadius, GridCoord grid, Vector3 startPos) + bool clip, float[] cornerRadius, GridCoord grid, Vector3 startPos, float symbolSize2 = 0) { if (!IsInChart(pos)) return; if (!clip || (clip && (grid.Contains(pos)))) DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, emptyColor, borderColor, - gap, cornerRadius, startPos); + gap, cornerRadius, startPos, symbolSize2); } public void DrawClipZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth, @@ -101,22 +101,22 @@ namespace XCharts.Runtime public void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness, Vector3 pos, Color32 color, Color32 toColor, Color32 emptyColor, Color32 borderColor, - float gap, float[] cornerRadius) + float gap, float[] cornerRadius, float symbolSize2 = 0) { DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, emptyColor, borderColor, - gap, cornerRadius, Vector3.zero); + gap, cornerRadius, Vector3.zero, symbolSize2); } public void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness, Vector3 pos, Color32 color, Color32 toColor, Color32 emptyColor, Color32 borderColor, - float gap, float[] cornerRadius, Vector3 startPos) + float gap, float[] cornerRadius, Vector3 startPos, float symbolSize2 = 0) { var backgroundColor = GetChartBackgroundColor(); if (ChartHelper.IsClearColor(emptyColor)) emptyColor = backgroundColor; var smoothness = settings.cicleSmoothness; ChartDrawer.DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap, - cornerRadius, emptyColor, backgroundColor, borderColor, smoothness, startPos); + cornerRadius, emptyColor, backgroundColor, borderColor, smoothness, startPos, symbolSize2); } public Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos, GridCoord grid) diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index e661013b..df21b6f9 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -394,7 +394,7 @@ namespace XCharts.Runtime { var index = settings.reversePainter ? settings.maxPainter - 1 - i : i; var painter = ChartHelper.AddPainterObject("painter_" + index, transform, m_GraphMinAnchor, - m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + index); + m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + index, m_ChildNodeNames); painter.index = m_PainterList.Count; painter.type = Painter.Type.Serie; painter.onPopulateMesh = OnDrawPainterSerie; @@ -404,7 +404,7 @@ namespace XCharts.Runtime m_PainterList.Add(painter); } m_PainterUpper = ChartHelper.AddPainterObject("painter_u", transform, m_GraphMinAnchor, - m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter); + m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter, m_ChildNodeNames); m_PainterUpper.type = Painter.Type.Top; m_PainterUpper.onPopulateMesh = OnDrawPainterUpper; m_PainterUpper.SetActive(true, m_DebugInfo.showAllChartObject); @@ -412,7 +412,7 @@ namespace XCharts.Runtime m_PainterUpper.transform.SetSiblingIndex(settings.maxPainter + 1); m_PainterTop = ChartHelper.AddPainterObject("painter_t", transform, m_GraphMinAnchor, - m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter); + m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter, m_ChildNodeNames); m_PainterTop.type = Painter.Type.Top; m_PainterTop.onPopulateMesh = OnDrawPainterTop; m_PainterTop.SetActive(true, m_DebugInfo.showAllChartObject); diff --git a/Runtime/Internal/BaseGraph.API.cs b/Runtime/Internal/BaseGraph.API.cs index 210d681e..90c9adce 100644 --- a/Runtime/Internal/BaseGraph.API.cs +++ b/Runtime/Internal/BaseGraph.API.cs @@ -158,8 +158,8 @@ namespace XCharts.Runtime /// public void RebuildChartObject() { - ChartHelper.DestroyAllChildren(transform); - SetAllComponentDirty(); + ChartHelper.DestoryGameObjectByMatch(transform, m_ChildNodeNames); + //SetAllComponentDirty(); } public bool ScreenPointToChartPoint(Vector2 screenPoint, out Vector2 chartPoint) diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index 2bf81ac1..8f0f7659 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -14,6 +15,7 @@ namespace XCharts.Runtime IDragHandler, IEndDragHandler, IScrollHandler { [SerializeField] protected bool m_EnableTextMeshPro = false; + [SerializeField] protected List m_ChildNodeNames = new List(); protected Painter m_Painter; protected int m_SiblingIndex; @@ -52,8 +54,11 @@ namespace XCharts.Runtime public virtual HideFlags chartHideFlags { get { return HideFlags.None; } } private ScrollRect m_ScrollRect; + private Vector2 m_PointerDownPos; public Painter painter { get { return m_Painter; } } + public List childrenNodeNames { get { return m_ChildNodeNames; } } + public bool isDragingClick { get; set; } protected virtual void InitComponent() { @@ -158,7 +163,7 @@ namespace XCharts.Runtime protected virtual void InitPainter() { m_Painter = ChartHelper.AddPainterObject("painter_b", transform, m_GraphMinAnchor, - m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1); + m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1, m_ChildNodeNames); m_Painter.type = Painter.Type.Base; m_Painter.onPopulateMesh = OnDrawPainterBase; m_Painter.transform.SetSiblingIndex(0); @@ -284,11 +289,13 @@ namespace XCharts.Runtime public virtual void OnPointerDown(PointerEventData eventData) { + m_PointerDownPos = eventData.position; if (m_OnPointerDown != null) m_OnPointerDown(eventData, this); } public virtual void OnPointerUp(PointerEventData eventData) { + isDragingClick = Vector2.Distance(eventData.position, m_PointerDownPos) > 6; if (m_OnPointerUp != null) m_OnPointerUp(eventData, this); } diff --git a/Runtime/Internal/Object/ChartText.cs b/Runtime/Internal/Object/ChartText.cs index fb52dca6..205a611f 100644 --- a/Runtime/Internal/Object/ChartText.cs +++ b/Runtime/Internal/Object/ChartText.cs @@ -187,13 +187,13 @@ namespace XCharts.Runtime m_TMPText.alignment = TextAlignmentOptions.BottomRight; break; case TextAnchor.MiddleCenter: - m_TMPText.alignment = TextAlignmentOptions.Center; + m_TMPText.alignment = TextAlignmentOptions.Midline; break; case TextAnchor.MiddleLeft: - m_TMPText.alignment = TextAlignmentOptions.Left; + m_TMPText.alignment = TextAlignmentOptions.MidlineLeft; break; case TextAnchor.MiddleRight: - m_TMPText.alignment = TextAlignmentOptions.Right; + m_TMPText.alignment = TextAlignmentOptions.MidlineRight; break; case TextAnchor.UpperCenter: m_TMPText.alignment = TextAlignmentOptions.Top; @@ -205,8 +205,7 @@ namespace XCharts.Runtime m_TMPText.alignment = TextAlignmentOptions.TopRight; break; default: - m_TMPText.alignment = TextAlignmentOptions.Center; - m_TextAlignment = TextAnchor.MiddleCenter; + m_TMPText.alignment = TextAlignmentOptions.Midline; break; } #else diff --git a/Runtime/Internal/UIComponent.cs b/Runtime/Internal/UIComponent.cs index ab3ab1dc..43916eeb 100644 --- a/Runtime/Internal/UIComponent.cs +++ b/Runtime/Internal/UIComponent.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime { [SerializeField] private bool m_DebugModel = false; [SerializeField] protected UIComponentTheme m_Theme = new UIComponentTheme(); - [SerializeField] private Background m_Background = new Background() { show = true }; + [SerializeField] protected Background m_Background = new Background() { show = true }; protected bool m_DataDirty; private ThemeType m_CheckTheme = 0; diff --git a/Runtime/Internal/Utilities/ChartDrawer.cs b/Runtime/Internal/Utilities/ChartDrawer.cs index c6cfbf9b..baffa0f3 100644 --- a/Runtime/Internal/Utilities/ChartDrawer.cs +++ b/Runtime/Internal/Utilities/ChartDrawer.cs @@ -9,7 +9,8 @@ namespace XCharts.Runtime { public static void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius, - Color32 emptyColor, Color32 backgroundColor, Color32 borderColor, float smoothness, Vector3 startPos) + Color32 emptyColor, Color32 backgroundColor, Color32 borderColor, float smoothness, + Vector3 startPos, float symbolSize2 = 0f) { switch (type) { @@ -22,13 +23,14 @@ namespace XCharts.Runtime } else { - if (tickness > 0) + if (tickness > 0 && !ChartHelper.IsClearColor(borderColor)) UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + tickness, borderColor, borderColor, color, smoothness); else UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness); } break; case SymbolType.EmptyCircle: + if (tickness == 0) tickness = 4f; if (gap > 0) { UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness); @@ -40,23 +42,31 @@ namespace XCharts.Runtime } break; case SymbolType.Rect: - if (gap > 0) + if (symbolSize2 > 0 && symbolSize2 != symbolSize) { - UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor); - UGL.DrawSquare(vh, pos, symbolSize, color, toColor); + UGL.DrawRectangle(vh, pos, symbolSize, symbolSize2, color, toColor); } else { - if (tickness > 0) + if (gap > 0) { - UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true); - UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius); + UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor); + UGL.DrawSquare(vh, pos, symbolSize, color, toColor); } else - UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true); + { + if (tickness > 0) + { + UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true); + UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius); + } + else + UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true); + } } break; case SymbolType.EmptyRect: + if (tickness == 0) tickness = 4f; if (gap > 0) { UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor); @@ -75,6 +85,7 @@ namespace XCharts.Runtime } if (type == SymbolType.EmptyTriangle) { + if (tickness == 0) tickness = 4f; UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f, tickness * 2f, color, emptyColor); } else @@ -92,6 +103,7 @@ namespace XCharts.Runtime } if (type == SymbolType.EmptyDiamond) { + if (tickness == 0) tickness = 4f; UGL.DrawEmptyDiamond(vh, pos, xRadius, yRadius, tickness, color, emptyColor); } else @@ -124,6 +136,7 @@ namespace XCharts.Runtime arrowOffset, arrowDent, color); if (type == SymbolType.EmptyArrow) { + if (tickness == 0) tickness = 4f; arrowWidth = (symbolSize - tickness) * 2; arrowHeight = arrowWidth * 1.5f; arrowOffset = 0; diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index fb67ad55..c0bef4fc 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -156,6 +156,21 @@ namespace XCharts.Runtime } } + public static void DestoryGameObjectByMatch(Transform parent, List children) + { + if (parent == null) return; + if (children == null || children.Count == 0) return; + var childCount = parent.childCount; + for (int i = childCount - 1; i >= 0; i--) + { + var go = parent.GetChild(i); + if (go != null && children.Contains(go.name)) + { + GameObject.DestroyImmediate(go.gameObject, true); + } + } + } + public static void DestoryGameObject(GameObject go) { if (go != null) GameObject.DestroyImmediate(go, true); @@ -233,7 +248,7 @@ namespace XCharts.Runtime } public static GameObject AddObject(string name, Transform parent, Vector2 anchorMin, - Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, int replaceIndex = -1) + Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, int replaceIndex = -1, List cacheNames = null) { GameObject obj; if (parent.Find(name)) @@ -267,6 +282,8 @@ namespace XCharts.Runtime rect.anchorMax = anchorMax; rect.pivot = pivot; rect.anchoredPosition3D = Vector3.zero; + + if (cacheNames != null && !cacheNames.Contains(name)) cacheNames.Add(name); return obj; } @@ -297,7 +314,11 @@ namespace XCharts.Runtime chartText.tmpText.fontStyle = textStyle.tmpFontStyle; chartText.tmpText.richText = true; chartText.tmpText.raycastTarget = false; +#if UNITY_2023_2_OR_NEWER + chartText.tmpText.textWrappingMode = textStyle.autoWrap ? TextWrappingModes.Normal : TextWrappingModes.NoWrap; +#else chartText.tmpText.enableWordWrapping = textStyle.autoWrap; +#endif #else chartText.text = EnsureComponent(txtObj); chartText.text.font = textStyle.font == null ? theme.font : textStyle.font; @@ -319,7 +340,7 @@ namespace XCharts.Runtime chartText.SetActive(textStyle.show); RectTransform rect = EnsureComponent(txtObj); - rect.localPosition = Vector3.zero; + rect.anchoredPosition3D = Vector3.zero; rect.sizeDelta = sizeDelta; rect.anchorMin = anchorMin; rect.anchorMax = anchorMax; @@ -328,9 +349,9 @@ namespace XCharts.Runtime } public static Painter AddPainterObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, - Vector2 pivot, Vector2 sizeDelta, HideFlags hideFlags, int siblingIndex) + Vector2 pivot, Vector2 sizeDelta, HideFlags hideFlags, int siblingIndex, List childNodeNames) { - var painterObj = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + var painterObj = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta, -1, childNodeNames); painterObj.hideFlags = hideFlags; painterObj.transform.SetSiblingIndex(siblingIndex); return ChartHelper.EnsureComponent(painterObj); @@ -492,7 +513,7 @@ namespace XCharts.Runtime return label; } - private static void UpdateAnchorAndPivotByTextAlignment(TextAnchor alignment, out Vector2 anchorMin, out Vector2 anchorMax, + public static void UpdateAnchorAndPivotByTextAlignment(TextAnchor alignment, out Vector2 anchorMin, out Vector2 anchorMax, out Vector2 pivot) { switch (alignment) @@ -770,6 +791,14 @@ namespace XCharts.Runtime return mod == 0 ? value : (value < 0 ? rate : rate + 1) * ceilRate; } + public static float GetMaxCeilRate(float value, float ceilRate) + { + if (ceilRate == 0) return value; + var mod = value % ceilRate; + int rate = (int)(value / ceilRate); + return mod == 0 ? value : (value < 0 ? rate : rate + 1) * ceilRate; + } + public static double GetMinCeilRate(double value, double ceilRate) { if (ceilRate == 0) return value; @@ -778,6 +807,14 @@ namespace XCharts.Runtime return mod == 0 ? value : (value < 0 ? rate - 1 : rate) * ceilRate; } + public static float GetMinCeilRate(float value, float ceilRate) + { + if (ceilRate == 0) return value; + var mod = value % ceilRate; + int rate = (int)(value / ceilRate); + return mod == 0 ? value : (value < 0 ? rate - 1 : rate) * ceilRate; + } + public static double GetMinDivisibleValue(double min, double ceilRate) { if (min == 0) return 0; diff --git a/Runtime/Internal/Utilities/UIHelper.cs b/Runtime/Internal/Utilities/UIHelper.cs index 54f9ff25..661d4130 100644 --- a/Runtime/Internal/Utilities/UIHelper.cs +++ b/Runtime/Internal/Utilities/UIHelper.cs @@ -11,43 +11,66 @@ namespace XCharts.Runtime /// public static class UIHelper { - internal static void DrawBackground(VertexHelper vh, UIComponent component) + public static void DrawBackground(VertexHelper vh, UIComponent component) { var background = component.background; + var rect = component.graphRect; + if (background.imageWidth > 0 || background.imageHeight > 0) + { + if (background.imageWidth > 0) + { + rect.width = background.imageWidth; + rect.x = component.graphX + (component.graphWidth - background.imageWidth) / 2; + } + if (background.imageHeight > 0) + { + rect.height = background.imageHeight; + rect.y = component.graphY + (component.graphHeight - background.imageHeight) / 2; + } + } + background.rect = rect; if (!background.show) return; if (background.image != null) return; - var backgroundColor = component.theme.GetBackgroundColor(background); + DrawBackground(vh, background, backgroundColor); + } + + public static void DrawBackground(VertexHelper vh, Background background, Color32 color, float smoothness = 2) + { + if (!background.show) + return; + if (background.image != null) + return; var borderWidth = background.borderStyle.GetRuntimeBorderWidth(); var borderColor = background.borderStyle.GetRuntimeBorderColor(); var cornerRadius = background.borderStyle.GetRuntimeCornerRadius(); - UGL.DrawRoundRectangleWithBorder(vh, component.graphRect, backgroundColor, backgroundColor, cornerRadius, - borderWidth, borderColor); + UGL.DrawRoundRectangleWithBorder(vh, background.rect, color, color, cornerRadius, + borderWidth, borderColor, 0, smoothness); } - internal static void InitBackground(UIComponent table) + internal static void InitBackground(UIComponent component) { - if (table.background.show == false || - (table.background.image == null && ChartHelper.IsClearColor(table.background.imageColor))) + if (component.background.show == false || + (component.background.image == null && ChartHelper.IsClearColor(component.background.imageColor))) { - ChartHelper.DestoryGameObject(table.transform, "Background"); + ChartHelper.DestoryGameObject(component.transform, "Background"); return; } - var sizeDelta = table.background.imageWidth > 0 && table.background.imageHeight > 0 ? - new Vector2(table.background.imageWidth, table.background.imageHeight) : - table.graphSizeDelta; - var backgroundObj = ChartHelper.AddObject("Background", table.transform, table.graphMinAnchor, - table.graphMaxAnchor, table.graphPivot, sizeDelta); - backgroundObj.hideFlags = table.chartHideFlags; + var sizeDelta = component.background.imageWidth > 0 && component.background.imageHeight > 0 ? + new Vector2(component.background.imageWidth, component.background.imageHeight) : + component.graphSizeDelta; + var backgroundObj = ChartHelper.AddObject("Background", component.transform, component.graphMinAnchor, + component.graphMaxAnchor, component.graphPivot, sizeDelta); + backgroundObj.hideFlags = component.chartHideFlags; var backgroundImage = ChartHelper.EnsureComponent(backgroundObj); - ChartHelper.UpdateRectTransform(backgroundObj, table.graphMinAnchor, - table.graphMaxAnchor, table.graphPivot, sizeDelta); - ChartHelper.SetBackground(backgroundImage, table.background); + ChartHelper.UpdateRectTransform(backgroundObj, component.graphMinAnchor, + component.graphMaxAnchor, component.graphPivot, sizeDelta); + ChartHelper.SetBackground(backgroundImage, component.background); backgroundObj.transform.SetSiblingIndex(0); - backgroundObj.SetActive(table.background.show && table.background.image != null); + backgroundObj.SetActive(component.background.show && component.background.image != null); } } } \ No newline at end of file diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index 98e73c7f..b3c62458 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -21,8 +21,8 @@ namespace XCharts.Runtime [ExecuteInEditMode] public static class XChartsMgr { - public static readonly string version = "3.12.1"; - public static readonly int versionDate = 20241201; + public static readonly string version = "3.13.0"; + public static readonly int versionDate = 20250101; public static string fullVersion { get { return version + "-" + versionDate; } } internal static List chartList = new List(); diff --git a/Runtime/Serie/Heatmap/HeatmapHandler.cs b/Runtime/Serie/Heatmap/HeatmapHandler.cs index 4bb2c784..45554e43 100644 --- a/Runtime/Serie/Heatmap/HeatmapHandler.cs +++ b/Runtime/Serie/Heatmap/HeatmapHandler.cs @@ -303,7 +303,7 @@ namespace XCharts.Runtime var emptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serie.context.colorIndex, state); serieData.context.rect = new Rect(pos.x - symbolSize / 2, pos.y - symbolSize / 2, symbolSize, symbolSize); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, - color, color, emptyColor, borderColor, symbol.gap, cornerRadius); + color, color, emptyColor, borderColor, symbol.gap, cornerRadius, symbol.size2); } if (visualMap.hoverLink && highlight && emphasisStyle != null && @@ -461,7 +461,7 @@ namespace XCharts.Runtime else { chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, - color, color, emptyColor, borderColor, symbol.gap, cornerRadius); + color, color, emptyColor, borderColor, symbol.gap, cornerRadius, symbol.size2); } if (visualMap.hoverLink && highlight && emphasisStyle != null && diff --git a/Runtime/Serie/Line/LineHandler.PolarCoord.cs b/Runtime/Serie/Line/LineHandler.PolarCoord.cs index e6e8b9cd..5a014c06 100644 --- a/Runtime/Serie/Line/LineHandler.PolarCoord.cs +++ b/Runtime/Serie/Line/LineHandler.PolarCoord.cs @@ -275,7 +275,7 @@ namespace XCharts.Runtime symbolSize = serie.animation.GetSysmbolSize(symbolSize); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serieData.context.position, - symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius); + symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius, symbol.size2); } } } diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index fbd56eb4..9d97512b 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -345,7 +345,7 @@ namespace XCharts.Runtime SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, colorIndex, serieState); SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, serieState); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor, - symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius); + symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius, symbol.size2); } } } @@ -495,7 +495,7 @@ namespace XCharts.Runtime symbolToColor = m_RadarCoord.outRangeColor; } chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.context.labelPosition, symbolColor, - symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius); + symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius, serie.symbol.size2); } } if (!serie.animation.IsFinish()) diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 52b57a1a..7c576fb2 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -314,7 +314,7 @@ namespace XCharts.Runtime } var objName = s_SerieRootObjectName + "_" + serie.index; m_SerieRoot = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor, - chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames); m_SerieRoot.hideFlags = chart.chartHideFlags; ChartHelper.SetActive(m_SerieRoot, true); ChartHelper.HideAllObject(m_SerieRoot); @@ -762,7 +762,7 @@ namespace XCharts.Runtime { var color = symbol.GetColor(defaultColor); chart.DrawSymbol(vh, symbol.type, symbol.size, 1, pos, - color, color, ColorUtil.clearColor32, color, symbol.gap, null); + color, color, ColorUtil.clearColor32, color, symbol.gap, null, symbol.size2); } public override void OnPointerDown(PointerEventData eventData) diff --git a/Runtime/Utilities/ColorUtil.cs b/Runtime/Utilities/ColorUtil.cs index 3e154b9c..99b9bdc9 100644 --- a/Runtime/Utilities/ColorUtil.cs +++ b/Runtime/Utilities/ColorUtil.cs @@ -7,6 +7,7 @@ namespace XCharts.Runtime { private static Dictionary s_ColorCached = new Dictionary(); public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0); + public static readonly Color32 white = new Color32(255, 255, 255, 255); public static readonly Vector2 zeroVector2 = Vector2.zero; /// diff --git a/package.json b/package.json index 8c498357..68b52142 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "displayName": "XCharts", "author": "monitor1394", "license": "MIT", - "version": "3.12.1", - "date": "20241201", - "checkdate": "20241201", + "version": "3.13.0", + "date": "20250101", + "checkdate": "20250101", "unity": "2018.3", "description": "A charting and data visualization library for Unity. Support line chart, bar chart, pie chart, radar chart, scatter chart, heatmap chart, ring chart, candlestick chart, polar chart and parallel coordinates.", "keywords": [