增加LegendPositions可自定义图例的位置

This commit is contained in:
monitor1394
2023-03-04 21:09:50 +08:00
parent 64c9b97eb9
commit bf152a3a71
7 changed files with 28 additions and 4 deletions

View File

@@ -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

View File

@@ -1,5 +1,5 @@
---
sidebar_position: 31
sidebar_position: 41
slug: /api
---

View File

@@ -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`委托

View File

@@ -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

View File

@@ -24,6 +24,7 @@ namespace XCharts.Editor
PropertyField("m_Padding");
PropertyListField("m_Icons");
PropertyListField("m_Colors");
PropertyListField("m_Positions");
PropertyListField("m_Data");
--EditorGUI.indentLevel;
}

View File

@@ -86,6 +86,7 @@ namespace XCharts.Runtime
[SerializeField] private List<Color> m_Colors = new List<Color>();
[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<Vector3> m_Positions = new List<Vector3>();
public LegendContext context = new LegendContext();
@@ -257,6 +258,15 @@ namespace XCharts.Runtime
set { if (value != null) { m_Colors = value; SetAllDirty(); } }
}
/// <summary>
/// the custom positions of legend item.
/// |图例标记的自定义位置列表。
/// </summary>
public List<Vector3> positions
{
get { return m_Positions; }
set { if (value != null) { m_Positions = value; SetAllDirty(); } }
}
/// <summary>
/// 图表是否需要刷新(图例组件不需要刷新图表)
/// </summary>
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;
}
/// <summary>
/// Callback handling when parameters change.
/// |参数变更时的回调处理。

View File

@@ -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;
}
}