diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index 193f0b19..82391778 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -820,6 +820,7 @@ Legend component.The legend component shows different sets of tags, colors, and |colors|||the colors of legend item. |background||v3.1.0|the sytle of background. [ImageStyle](#imagestyle)| |padding||v3.1.0|the paddinng of item and background. [Padding](#padding)| +|positions||v3.6.0|the custom positions of legend item. ## LegendTheme diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index dfe8204b..5a9f3078 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -1,5 +1,5 @@ --- -sidebar_position: 31 +sidebar_position: 41 slug: /api --- diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index c003c30f..694e2d9d 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -65,6 +65,7 @@ slug: /changelog ## master +* (2023.03.04) 增加`Legend`的`Positions`可自定义图例的位置 * (2023.03.03) 修复`Animation`变更动画可能无效的问题 * (2023.02.28) 修复`Legend`点击时`Serie`的`Label`不刷新的问题 * (2023.02.26) 增加`DataZoom`的`startEndFunction`委托 diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index df5e296b..667d912c 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -1,5 +1,5 @@ --- -sidebar_position: 21 +sidebar_position: 31 slug: /configuration --- @@ -820,6 +820,7 @@ Inherits or Implemented: [MainComponent](#maincomponent),[IPropertyChanged](#ipr |colors|||图例标记的颜色列表。 |background||v3.1.0|背景图样式。 [ImageStyle](#imagestyle)| |padding||v3.1.0|图例标记和背景的间距。 [Padding](#padding)| +|positions||v3.6.0|图例标记的自定义位置列表。 ## LegendTheme diff --git a/Editor/MainComponents/LegendEditor.cs b/Editor/MainComponents/LegendEditor.cs index db3d8063..340b567b 100644 --- a/Editor/MainComponents/LegendEditor.cs +++ b/Editor/MainComponents/LegendEditor.cs @@ -24,6 +24,7 @@ namespace XCharts.Editor PropertyField("m_Padding"); PropertyListField("m_Icons"); PropertyListField("m_Colors"); + PropertyListField("m_Positions"); PropertyListField("m_Data"); --EditorGUI.indentLevel; } diff --git a/Runtime/Component/Legend/Legend.cs b/Runtime/Component/Legend/Legend.cs index 9b8e53b4..283110fa 100644 --- a/Runtime/Component/Legend/Legend.cs +++ b/Runtime/Component/Legend/Legend.cs @@ -86,6 +86,7 @@ namespace XCharts.Runtime [SerializeField] private List m_Colors = new List(); [SerializeField][Since("v3.1.0")] protected ImageStyle m_Background = new ImageStyle() { show = false }; [SerializeField][Since("v3.1.0")] protected Padding m_Padding = new Padding(); + [SerializeField][Since("v3.6.0")] private List m_Positions = new List(); public LegendContext context = new LegendContext(); @@ -257,6 +258,15 @@ namespace XCharts.Runtime set { if (value != null) { m_Colors = value; SetAllDirty(); } } } /// + /// the custom positions of legend item. + /// |图例标记的自定义位置列表。 + /// + public List positions + { + get { return m_Positions; } + set { if (value != null) { m_Positions = value; SetAllDirty(); } } + } + /// /// 图表是否需要刷新(图例组件不需要刷新图表) /// public override bool vertsDirty { get { return false; } } @@ -428,6 +438,14 @@ namespace XCharts.Runtime return Color.white; } + public Vector3 GetPosition(int index, Vector3 defaultPos) + { + if (index >= 0 && index < m_Positions.Count) + return m_Positions[index]; + else + return defaultPos; + } + /// /// Callback handling when parameters change. /// |参数变更时的回调处理。 diff --git a/Runtime/Component/Legend/LegendHelper.cs b/Runtime/Component/Legend/LegendHelper.cs index 3ca396a4..352c8a78 100644 --- a/Runtime/Component/Legend/LegendHelper.cs +++ b/Runtime/Component/Legend/LegendHelper.cs @@ -156,6 +156,7 @@ namespace XCharts.Runtime var currHeight = 0f; var offsetX = 0f; var row = 0; + var index = 0; foreach (var kv in legend.context.buttonList) { var item = kv.Value; @@ -165,7 +166,7 @@ namespace XCharts.Runtime offsetX += legend.context.eachWidthDict[row]; row++; } - item.SetPosition(new Vector3(startX + offsetX, startY - currHeight)); + item.SetPosition(legend.GetPosition(index++, new Vector3(startX + offsetX, startY - currHeight))); currHeight += item.height + legend.itemGap; } } @@ -173,6 +174,7 @@ namespace XCharts.Runtime { var currWidth = 0f; var offsetY = 0f; + var index = 0; foreach (var kv in legend.context.buttonList) { var item = kv.Value; @@ -181,7 +183,7 @@ namespace XCharts.Runtime currWidth = 0; offsetY += legend.context.eachHeight; } - item.SetPosition(new Vector3(startX + currWidth, startY - offsetY)); + item.SetPosition(legend.GetPosition(index++, new Vector3(startX + currWidth, startY - offsetY))); currWidth += item.width + legend.itemGap; } }