mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
增加Legend的Positions可自定义图例的位置
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 31
|
||||
sidebar_position: 41
|
||||
slug: /api
|
||||
---
|
||||
|
||||
|
||||
@@ -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`委托
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace XCharts.Editor
|
||||
PropertyField("m_Padding");
|
||||
PropertyListField("m_Icons");
|
||||
PropertyListField("m_Colors");
|
||||
PropertyListField("m_Positions");
|
||||
PropertyListField("m_Data");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
/// |参数变更时的回调处理。
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user