diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md index 5183e0ef..0ad36aef 100644 --- a/Documentation~/en/api.md +++ b/Documentation~/en/api.md @@ -2342,6 +2342,9 @@ Configurations of select state. |IsIgnoreValue()||public bool IsIgnoreValue(SerieData serieData, double value)| |IsIgnoreValue()||public bool IsIgnoreValue(SerieData serieData, int dimension = 1)| |IsLegendName()||public bool IsLegendName(string legendName)| +|IsMinShowLabelValue()||public bool IsMinShowLabelValue(double value)| +|IsMinShowLabelValue()||public bool IsMinShowLabelValue(int index, int dimension = 1)| +|IsMinShowLabelValue()||public bool IsMinShowLabelValue(SerieData serieData, int dimension = 1)| |IsPerformanceMode()||public bool IsPerformanceMode()
是否为性能模式。性能模式下不绘制Symbol,不刷新Label,不单独设置数据项配置。 | |IsSerie<T>()||public bool IsSerie<T>() where T : Serie| |IsSerieDataLegendName()||public bool IsSerieDataLegendName(string legendName)| diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index d8e107d3..4621dcd1 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -1303,6 +1303,7 @@ Legend component.The legend component shows different sets of tags, colors, and |itemOpacity|1||the opacity of item color. |formatter|||No longer used, the use of LabelStyle.formatter instead. |labelStyle|||the style of text. [LabelStyle](#labelstyle)| +|textLimit||v3.10.0|the limit of text. [TextLimit](#textlimit)| |data|||Data array of legend. An array item is usually a name representing string. (If it is a pie chart, it could also be the name of a single data in the pie chart) of a series. If data is not specified, it will be auto collected from series. |icons|||自定义的图例标记图形。 |colors|||the colors of legend item. @@ -1816,6 +1817,8 @@ Configurations of select state. |center|||the center of chart. |radius|||the radius of chart. |minRadius|0f|v3.8.0|the min radius of chart. It can be used to limit the minimum radius of the rose chart. +|minShowLabel|false|v3.10.0|Whether the label is not displayed when the enabled value is less than the specified value. +|minShowLabelValue|0|v3.10.0|When 'minShowLabel' is enabled, labels are not displayed if the value is less than this value. |showDataDimension|||数据项里的数据维数。 |showDataName|||在Editor的inpsector上是否显示name参数 |clip|false||If clip the overflow on the coordinate system. diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index f77cf17c..f3e18830 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -2342,6 +2342,9 @@ Radar coordinate conponnet for radar charts. 雷达图坐标系组件,只适 |IsIgnoreValue()||public bool IsIgnoreValue(SerieData serieData, double value)| |IsIgnoreValue()||public bool IsIgnoreValue(SerieData serieData, int dimension = 1)| |IsLegendName()||public bool IsLegendName(string legendName)| +|IsMinShowLabelValue()||public bool IsMinShowLabelValue(double value)| +|IsMinShowLabelValue()||public bool IsMinShowLabelValue(int index, int dimension = 1)| +|IsMinShowLabelValue()||public bool IsMinShowLabelValue(SerieData serieData, int dimension = 1)| |IsPerformanceMode()||public bool IsPerformanceMode()
是否为性能模式。性能模式下不绘制Symbol,不刷新Label,不单独设置数据项配置。 | |IsSerie<T>()||public bool IsSerie<T>() where T : Serie| |IsSerieDataLegendName()||public bool IsSerieDataLegendName(string legendName)| diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 9112d20c..abefd9f4 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -70,6 +70,7 @@ slug: /changelog ## master +* (2023.12.12) 增加`Legend`的`TextLimit`可限制图例显示文本的长度 * (2023.12.11) 修复`Serie`添加`double.MaxValue`时坐标绘制失败的问题 * (2023.12.10) 增加`Serie`的`minShowLabel`可隐藏小于指定值的`label` * (2023.12.09) 增加`LevelStyle`的`LineStyle`和`depth`支持 diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index b9ed2f37..bbb8f2c4 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -1266,6 +1266,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart |itemOpacity|1||图例标记的图形的颜色透明度。 |formatter|||不再使用,使用LabelStyle.formatter代替。 |labelStyle|||文本样式。 [LabelStyle](#labelstyle)| +|textLimit||v3.10.0|文本限制。 [TextLimit](#textlimit)| |data|||图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 name(如果是饼图,也可以是饼图单个数据的 name)。 如果 data 没有被指定,会自动从当前系列中获取。指定data时里面的数据项和serie匹配时才会生效。 |icons|||自定义的图例标记图形。 |colors|||图例标记的颜色列表。 @@ -1761,6 +1762,8 @@ Radar coordinate conponnet for radar charts. 雷达图坐标系组件,只适 |center|||中心点。 |radius|||半径。radius[0]表示内径,radius[1]表示外径。 |minRadius|0f|v3.8.0|最小半径。可用于限制玫瑰图的最小半径。 +|minShowLabel|false|v3.10.0|是否开启值小于指定值`minShowLabelValue`时不显示标签。 +|minShowLabelValue|0|v3.10.0|当开启`minShowLabel`时,值小于该值时不显示标签。 |showDataDimension|||数据项里的数据维数。 |showDataName|||在Editor的inpsector上是否显示name参数 |clip|false||是否裁剪超出坐标系部分的图形。 diff --git a/Editor/MainComponents/LegendEditor.cs b/Editor/MainComponents/LegendEditor.cs index 64623f5a..e65bad00 100644 --- a/Editor/MainComponents/LegendEditor.cs +++ b/Editor/MainComponents/LegendEditor.cs @@ -19,6 +19,7 @@ namespace XCharts.Editor PropertyField("m_Orient"); PropertyField("m_Location"); PropertyField("m_LabelStyle"); + PropertyField("m_TextLimit"); PropertyField("m_Background"); PropertyField("m_Padding"); PropertyListField("m_Icons"); diff --git a/Runtime/Component/Legend/Legend.cs b/Runtime/Component/Legend/Legend.cs index 7549885a..5e34113a 100644 --- a/Runtime/Component/Legend/Legend.cs +++ b/Runtime/Component/Legend/Legend.cs @@ -81,6 +81,7 @@ namespace XCharts.Runtime [SerializeField] private float m_ItemOpacity = 1; [SerializeField] private string m_Formatter; [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); + [SerializeField][Since("v3.10.0")] private TextLimit m_TextLimit = new TextLimit(); [SerializeField] private List m_Data = new List(); [SerializeField] private List m_Icons = new List(); [SerializeField] private List m_Colors = new List(); @@ -184,7 +185,7 @@ namespace XCharts.Runtime /// No longer used, the use of LabelStyle.formatter instead. /// ||不再使用,使用LabelStyle.formatter代替。 /// - [Obsolete("Use LabelStyle.formatter instead.", false)] + [Obsolete("Use LabelStyle.formatter instead.", false)] public string formatter { get { return m_Formatter; } @@ -200,6 +201,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); } } /// + /// the limit of text. + /// ||文本限制。 + /// + public TextLimit textLimit + { + get { return m_TextLimit; } + set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } } + } + /// /// the sytle of background. /// ||背景图样式。 /// @@ -264,7 +274,7 @@ namespace XCharts.Runtime /// public override bool componentDirty { - get { return m_ComponentDirty || location.componentDirty || labelStyle.componentDirty; } + get { return m_ComponentDirty || location.componentDirty || labelStyle.componentDirty || textLimit.componentDirty; } } public override void ClearComponentDirty() @@ -272,6 +282,7 @@ namespace XCharts.Runtime base.ClearComponentDirty(); location.ClearComponentDirty(); labelStyle.ClearComponentDirty(); + textLimit.ClearComponentDirty(); } /// diff --git a/Runtime/Component/Legend/LegendHandler.cs b/Runtime/Component/Legend/LegendHandler.cs index 478689a5..b40cac5f 100644 --- a/Runtime/Component/Legend/LegendHandler.cs +++ b/Runtime/Component/Legend/LegendHandler.cs @@ -86,18 +86,26 @@ namespace XCharts.Runtime legend.RemoveButton(); ChartHelper.HideAllObject(legendObject); if (!legend.show) return; + var textLimitInitFlag = false; for (int i = 0; i < datas.Count; i++) { if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; string legendName = datas[i]; var legendContent = GetFormatterContent(legend, i, datas[i]); + if (legend.textLimit.enable) + legendContent = legend.textLimit.GetLimitContent(legendContent); var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]); var active = chart.IsActiveByLegend(datas[i]); var bgColor = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active); bgColor.a = legend.itemOpacity; - var item = LegendHelper.AddLegendItem(chart, legend, i, datas[i], legendObject.transform, chart.theme, + var item = LegendHelper.AddLegendItem(chart, legend, i, legendName, legendObject.transform, chart.theme, legendContent, bgColor, active, readIndex); legend.SetButton(legendName, item, totalLegend); + if (!textLimitInitFlag && legend.textLimit.enable) + { + textLimitInitFlag = true; + legend.textLimit.SetRelatedText(item.text, legend.itemWidth); + } ChartHelper.ClearEventListener(item.button.gameObject); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) => { diff --git a/Runtime/Internal/Object/LegendItem.cs b/Runtime/Internal/Object/LegendItem.cs index 95194bb6..cd0c8754 100644 --- a/Runtime/Internal/Object/LegendItem.cs +++ b/Runtime/Internal/Object/LegendItem.cs @@ -29,6 +29,8 @@ namespace XCharts.Runtime public string legendName { get { return m_LegendName; } set { m_LegendName = value; } } public GameObject gameObject { get { return m_GameObject; } } public Button button { get { return m_Button; } } + public ChartText text { get { return m_Text; } } + public float width { get