增加LegenditemInactiveOpacity可设置非激活状态时的颜色透明度 (#343)

This commit is contained in:
monitor1394
2025-03-27 22:35:02 +08:00
parent 546ff1f61a
commit 85b92ca2cc
12 changed files with 108 additions and 33 deletions

View File

@@ -808,6 +808,14 @@ class in XCharts.Runtime / Inherits from: [MainComponent](#maincomponent) / Subc
The axis in rectangular coordinate. The axis in rectangular coordinate.
### Axis.onLabelClick
public Action<int, string> onLabelClick
> Since `v3.15.0`
Callback function when click on the label. Parameters: labelIndex, labelName.
### Axis.AddData ### Axis.AddData
public void AddData(string category) public void AddData(string category)
@@ -1078,6 +1086,14 @@ class in XCharts / Inherits from: [MainComponentHandler](#maincomponenthandler)
public T component public T component
### AxisHandler<T>.DrawTop
// public override void DrawTop(VertexHelper vh)
### AxisHandler<T>.OnPointerClick
public override void OnPointerClick(PointerEventData eventData)
## AxisHelper ## AxisHelper
class in XCharts.Runtime class in XCharts.Runtime
@@ -3197,6 +3213,10 @@ public float GetTextWidth()
public float GetWidth() public float GetWidth()
### ChartLabel.InRect
public bool InRect(Vector2 local)
### ChartLabel.IsActiveByScale ### ChartLabel.IsActiveByScale
public bool IsActiveByScale() public bool IsActiveByScale()
@@ -5824,15 +5844,15 @@ public double runtimeValue
class in XCharts.Runtime class in XCharts.Runtime
标线类型 Mark line type.
Options: Options:
- `None`: 标线类型 - `Custom`: Custom. You can customize the xy coordinates or values.
- `Min`: 最小值。 - `Min`: Minimum value.
- `Max`: 最大值。 - `Max`: Maximum value.
- `Average`: 平均值。 - `Average`: Average value.
- `Median`: 中位数。 - `Median`: Median.
## MarqueeStyle ## MarqueeStyle

View File

@@ -2661,6 +2661,12 @@ The distance between each legend, horizontal distance in horizontal layout, and
Image height of legend symbol. Image height of legend symbol.
### Legend.itemInactiveOpacity
`float` `1` `v3.15.0`
the opacity of item color when item is inactive.
### Legend.itemOpacity ### Legend.itemOpacity
`float` `1` `float` `1`
@@ -2736,11 +2742,11 @@ the limit of text.
class in XCharts.Runtime / Inherits from: [ComponentTheme](#componenttheme) class in XCharts.Runtime / Inherits from: [ComponentTheme](#componenttheme)
### LegendTheme.unableColor ### LegendTheme.inactiveColor
`Color` `Color`
the color of text. the color when the component is inactive.
## Level ## Level
@@ -3156,11 +3162,11 @@ Special label types, are used to label maximum value, minimum value and so on.
Options: Options:
- `None`: 标线类型 - `Custom`: Custom. You can customize the xy coordinates or values.
- `Min`: 最小值。 - `Min`: Minimum value.
- `Max`: 最大值。 - `Max`: Maximum value.
- `Average`: 平均值。 - `Average`: Average value.
- `Median`: 中位数。 - `Median`: Median.
### MarkLineData.xPosition ### MarkLineData.xPosition

View File

@@ -808,6 +808,14 @@ class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent) / 子类:
直角坐标系的坐标轴组件。 直角坐标系的坐标轴组件。
### Axis.onLabelClick
public Action<int, string> onLabelClick
> 从 `v3.15.0` 开始支持
点击文本标签回调函数。参数labelIndex, labelName。
### Axis.AddData ### Axis.AddData
public void AddData(string category) public void AddData(string category)
@@ -1078,6 +1086,14 @@ class in XCharts / 继承自: [MainComponentHandler](#maincomponenthandler)
public T component public T component
### AxisHandler<T>.DrawTop
// public override void DrawTop(VertexHelper vh)
### AxisHandler<T>.OnPointerClick
public override void OnPointerClick(PointerEventData eventData)
## AxisHelper ## AxisHelper
class in XCharts.Runtime class in XCharts.Runtime
@@ -3197,6 +3213,10 @@ public float GetTextWidth()
public float GetWidth() public float GetWidth()
### ChartLabel.InRect
public bool InRect(Vector2 local)
### ChartLabel.IsActiveByScale ### ChartLabel.IsActiveByScale
public bool IsActiveByScale() public bool IsActiveByScale()
@@ -5828,7 +5848,7 @@ class in XCharts.Runtime
可选: 可选:
- `None`: 标线类型 - `Custom`: 自定义。可自定义xy坐标或数值。
- `Min`: 最小值。 - `Min`: 最小值。
- `Max`: 最大值。 - `Max`: 最大值。
- `Average`: 平均值。 - `Average`: 平均值。

View File

@@ -80,6 +80,7 @@ slug: /changelog
## master ## master
* (2025.03.27) 增加`Legend``itemInactiveOpacity`可设置非激活状态时的颜色透明度 (#343)
* (2025.03.27) 增加`Axis``onLabelClick`回调事件 * (2025.03.27) 增加`Axis``onLabelClick`回调事件
* (2025.03.26) 增加`Animation``Exchange`排序交换动画 * (2025.03.26) 增加`Animation``Exchange`排序交换动画
* (2025.03.22) 增加`Comment``layer`设置层级 * (2025.03.22) 增加`Comment``layer`设置层级

View File

@@ -2661,6 +2661,12 @@ class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent), [IPropert
图例标记的图形高度。 图例标记的图形高度。
### Legend.itemInactiveOpacity
`float` `1` `v3.15.0`
图例标记的图形在非激活状态下的颜色透明度。
### Legend.itemOpacity ### Legend.itemOpacity
`float` `1` `float` `1`
@@ -2736,11 +2742,11 @@ class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent), [IPropert
class in XCharts.Runtime / 继承自: [ComponentTheme](#componenttheme) class in XCharts.Runtime / 继承自: [ComponentTheme](#componenttheme)
### LegendTheme.unableColor ### LegendTheme.inactiveColor
`Color` `Color`
文本颜色。 非激活状态时的颜色。
## Level ## Level
@@ -3156,7 +3162,7 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent)
可选: 可选:
- `None`: 标线类型 - `Custom`: 自定义。可自定义xy坐标或数值。
- `Min`: 最小值。 - `Min`: 最小值。
- `Max`: 最大值。 - `Max`: 最大值。
- `Average`: 平均值。 - `Average`: 平均值。
@@ -3166,25 +3172,25 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent)
`float` `float`
相对原点的 x 坐标单位像素。当type为None时有效。 相对原点的 x 坐标单位像素。当type为Custom时有效。
### MarkLineData.xValue ### MarkLineData.xValue
`double` `double`
X轴上的指定值。当X轴为类目轴时指定值表示类目轴数据的索引否则为具体的值。当type为None时有效。 X轴上的指定值。当X轴为类目轴时指定值表示类目轴数据的索引否则为具体的值。当type为Custom时有效。
### MarkLineData.yPosition ### MarkLineData.yPosition
`float` `float`
相对原点的 y 坐标单位像素。当type为None时有效。 相对原点的 y 坐标单位像素。当type为Custom时有效。
### MarkLineData.yValue ### MarkLineData.yValue
`double` `double`
Y轴上的指定值。当Y轴为类目轴时指定值表示类目轴数据的索引否则为具体的值。当type为None时有效。 Y轴上的指定值。当Y轴为类目轴时指定值表示类目轴数据的索引否则为具体的值。当type为Custom时有效。
### MarkLineData.zeroPosition ### MarkLineData.zeroPosition

View File

@@ -102,7 +102,7 @@ namespace XCharts.Editor
protected override void DrawExtendeds(SerializedProperty prop) protected override void DrawExtendeds(SerializedProperty prop)
{ {
base.DrawExtendeds(prop); base.DrawExtendeds(prop);
PropertyField(prop, "m_UnableColor"); PropertyField(prop, "m_InactiveColor");
} }
} }

View File

@@ -15,6 +15,7 @@ namespace XCharts.Editor
PropertyField("m_ItemGap"); PropertyField("m_ItemGap");
PropertyField("m_ItemAutoColor"); PropertyField("m_ItemAutoColor");
PropertyField("m_ItemOpacity"); PropertyField("m_ItemOpacity");
PropertyField("m_ItemInactiveOpacity");
PropertyField("m_SelectedMode"); PropertyField("m_SelectedMode");
PropertyField("m_Orient"); PropertyField("m_Orient");
PropertyField("m_Location"); PropertyField("m_Location");

View File

@@ -79,6 +79,7 @@ namespace XCharts.Runtime
[SerializeField] private float m_ItemGap = 10f; [SerializeField] private float m_ItemGap = 10f;
[SerializeField] private bool m_ItemAutoColor = true; [SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private float m_ItemOpacity = 1; [SerializeField] private float m_ItemOpacity = 1;
[SerializeField][Since("v3.15.0")] private float m_ItemInactiveOpacity = 1;
[SerializeField] private string m_Formatter; [SerializeField] private string m_Formatter;
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField][Since("v3.10.0")] private TextLimit m_TextLimit = new TextLimit(); [SerializeField][Since("v3.10.0")] private TextLimit m_TextLimit = new TextLimit();
@@ -182,6 +183,15 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); } set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); }
} }
/// <summary> /// <summary>
/// the opacity of item color when item is inactive.
/// ||图例标记的图形在非激活状态下的颜色透明度。
/// </summary>
public float itemInactiveOpacity
{
get { return m_ItemInactiveOpacity; }
set { if (PropertyUtil.SetStruct(ref m_ItemInactiveOpacity, value)) SetComponentDirty(); }
}
/// <summary>
/// No longer used, the use of LabelStyle.formatter instead. /// No longer used, the use of LabelStyle.formatter instead.
/// ||不再使用使用LabelStyle.formatter代替。 /// ||不再使用使用LabelStyle.formatter代替。
/// </summary> /// </summary>

View File

@@ -100,7 +100,7 @@ namespace XCharts.Runtime
var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]); var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]);
var active = chart.IsActiveByLegend(datas[i]); var active = chart.IsActiveByLegend(datas[i]);
var bgColor = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active); var bgColor = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active);
bgColor.a = legend.itemOpacity; bgColor.a = active ? legend.itemOpacity : legend.itemInactiveOpacity;
var item = LegendHelper.AddLegendItem(chart, legend, i, legendName, legendObject.transform, chart.theme, var item = LegendHelper.AddLegendItem(chart, legend, i, legendName, legendObject.transform, chart.theme,
legendContent, bgColor, active, readIndex); legendContent, bgColor, active, readIndex);
legend.SetButton(legendName, item, totalLegend); legend.SetButton(legendName, item, totalLegend);

View File

@@ -16,7 +16,7 @@ namespace XCharts.Runtime
else else
return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor; return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
} }
else return theme.legend.unableColor; else return theme.legend.inactiveColor;
} }
public static Color GetIconColor(BaseChart chart, Legend legend, int readIndex, string legendName, bool active) public static Color GetIconColor(BaseChart chart, Legend legend, int readIndex, string legendName, bool active)
@@ -30,7 +30,7 @@ namespace XCharts.Runtime
else else
return legend.GetColor(readIndex); return legend.GetColor(readIndex);
} }
else return chart.theme.legend.unableColor; else return chart.theme.legend.inactiveColor;
} }
public static LegendItem AddLegendItem(BaseChart chart, Legend legend, int i, string legendName, Transform parent, public static LegendItem AddLegendItem(BaseChart chart, Legend legend, int i, string legendName, Transform parent,

View File

@@ -358,7 +358,7 @@ namespace XCharts.Runtime
{ {
var itemStyle = SerieHelper.GetItemStyle(serie, null); var itemStyle = SerieHelper.GetItemStyle(serie, null);
var fillColor = ChartHelper.IsClearColor(itemStyle.backgroundColor) ? var fillColor = ChartHelper.IsClearColor(itemStyle.backgroundColor) ?
(Color32)chart.theme.legend.unableColor : itemStyle.backgroundColor; (Color32)chart.theme.legend.inactiveColor : itemStyle.backgroundColor;
UGL.DrawDoughnut(vh, serie.context.center, serie.context.insideRadius, UGL.DrawDoughnut(vh, serie.context.center, serie.context.insideRadius,
serie.context.outsideRadius, fillColor, fillColor, Color.clear, 0, serie.context.outsideRadius, fillColor, fillColor, Color.clear, 0,
360, itemStyle.borderWidth, itemStyle.borderColor, serie.gap / 2, chart.settings.cicleSmoothness, 360, itemStyle.borderWidth, itemStyle.borderColor, serie.gap / 2, chart.settings.cicleSmoothness,

View File

@@ -1,5 +1,6 @@
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
#if dUI_TextMeshPro #if dUI_TextMeshPro
using TMPro; using TMPro;
#endif #endif
@@ -9,27 +10,37 @@ namespace XCharts.Runtime
[Serializable] [Serializable]
public class LegendTheme : ComponentTheme public class LegendTheme : ComponentTheme
{ {
[SerializeField] protected Color m_UnableColor; [SerializeField][FormerlySerializedAs("m_UnableColor")] protected Color m_InactiveColor;
/// <summary> /// <summary>
/// the color of text. /// the color of text.
/// ||文本颜色。 /// ||文本颜色。
/// </summary> /// </summary>
[Obsolete("Use inactiveColor instead.", true)]
public Color unableColor public Color unableColor
{ {
get { return m_UnableColor; } get { return m_InactiveColor; }
set { if (PropertyUtil.SetColor(ref m_UnableColor, value)) SetComponentDirty(); } set { if (PropertyUtil.SetColor(ref m_InactiveColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color when the component is inactive.
/// ||非激活状态时的颜色。
/// </summary>
public Color inactiveColor
{
get { return m_InactiveColor; }
set { if (PropertyUtil.SetColor(ref m_InactiveColor, value)) SetComponentDirty(); }
} }
public void Copy(LegendTheme theme) public void Copy(LegendTheme theme)
{ {
base.Copy(theme); base.Copy(theme);
m_UnableColor = theme.unableColor; m_InactiveColor = theme.inactiveColor;
} }
public LegendTheme(ThemeType theme) : base(theme) public LegendTheme(ThemeType theme) : base(theme)
{ {
m_UnableColor = ColorUtil.GetColor("#cccccc"); m_InactiveColor = ColorUtil.GetColor("#cccccc");
} }
} }