mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 02:10:16 +00:00
Added Legend's textAutoColor to set the text color match with Serie color (#163)
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.08.14) Added `Legend`'s `textAutoColor` to set the text color match with `Serie` color (#163)
|
||||||
* (2021.08.12) Optimize `BarChart` setting `Corner` when the positive and negative columns are fillet symmetric
|
* (2021.08.12) Optimize `BarChart` setting `Corner` when the positive and negative columns are fillet symmetric
|
||||||
* (2021.08.03) Fixed y axis not displaying when all data is 0
|
* (2021.08.03) Fixed y axis not displaying when all data is 0
|
||||||
* (2021.07.29) Fixed ignored data will also participate in calculations when `ignore` is enabled (#161)
|
* (2021.07.29) Fixed ignored data will also participate in calculations when `ignore` is enabled (#161)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.08.14) 增加`Legend`的`textAutoColor`设置文本颜色和`Serie`一致
|
||||||
* (2021.08.12) 优化`BarChart`设置`Corner`时正负柱条圆角对称
|
* (2021.08.12) 优化`BarChart`设置`Corner`时正负柱条圆角对称
|
||||||
* (2021.08.03) 优化`Serie`的数据全为0时Y轴不显示的问题
|
* (2021.08.03) 优化`Serie`的数据全为0时Y轴不显示的问题
|
||||||
* (2021.07.29) 修复`Serie`开启`ignore`时被忽略的数据还会参与计算的问题 (#161)
|
* (2021.07.29) 修复`Serie`开启`ignore`时被忽略的数据还会参与计算的问题 (#161)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace XCharts
|
|||||||
PropertyField(prop, "m_ItemHeight");
|
PropertyField(prop, "m_ItemHeight");
|
||||||
PropertyField(prop, "m_ItemGap");
|
PropertyField(prop, "m_ItemGap");
|
||||||
PropertyField(prop, "m_ItemAutoColor");
|
PropertyField(prop, "m_ItemAutoColor");
|
||||||
|
PropertyField(prop, "m_TextAutoColor");
|
||||||
PropertyField(prop, "m_SelectedMode");
|
PropertyField(prop, "m_SelectedMode");
|
||||||
PropertyField(prop, "m_Orient");
|
PropertyField(prop, "m_Orient");
|
||||||
PropertyField(prop, "m_Location");
|
PropertyField(prop, "m_Location");
|
||||||
|
|||||||
@@ -543,7 +543,7 @@ namespace XCharts
|
|||||||
foreach (var legend in m_Legends)
|
foreach (var legend in m_Legends)
|
||||||
{
|
{
|
||||||
var iconColor = LegendHelper.GetIconColor(this, legendIndex, legendName, active);
|
var iconColor = LegendHelper.GetIconColor(this, legendIndex, legendName, active);
|
||||||
var contentColor = LegendHelper.GetContentColor(legend, m_Theme, active);
|
var contentColor = LegendHelper.GetContentColor(legendIndex, legend, m_Theme, active);
|
||||||
legend.UpdateButtonColor(legendName, iconColor);
|
legend.UpdateButtonColor(legendName, iconColor);
|
||||||
legend.UpdateContentColor(legendName, contentColor);
|
legend.UpdateContentColor(legendName, contentColor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ namespace XCharts
|
|||||||
[SerializeField] private float m_ItemHeight = 12.0f;
|
[SerializeField] private float m_ItemHeight = 12.0f;
|
||||||
[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 bool m_TextAutoColor = false;
|
||||||
[SerializeField] private string m_Formatter;
|
[SerializeField] private string m_Formatter;
|
||||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||||
[SerializeField] private List<string> m_Data = new List<string>();
|
[SerializeField] private List<string> m_Data = new List<string>();
|
||||||
@@ -176,6 +177,16 @@ namespace XCharts
|
|||||||
set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Whether the legend text matches the color automatically.
|
||||||
|
/// 图例标记的文本是否自动匹配颜色。
|
||||||
|
/// [default:false]
|
||||||
|
/// </summary>
|
||||||
|
public bool textAutoColor
|
||||||
|
{
|
||||||
|
get { return m_TextAutoColor; }
|
||||||
|
set { if (PropertyUtil.SetStruct(ref m_TextAutoColor, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}.
|
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}.
|
||||||
/// 图例内容字符串模版格式器。支持用 \n 换行。
|
/// 图例内容字符串模版格式器。支持用 \n 换行。
|
||||||
/// 模板变量为图例名称 {name}。
|
/// 模板变量为图例名称 {name}。
|
||||||
|
|||||||
@@ -11,10 +11,14 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
public static class LegendHelper
|
public static class LegendHelper
|
||||||
{
|
{
|
||||||
public static Color GetContentColor(Legend legend, ChartTheme theme, bool active)
|
public static Color GetContentColor(int legendIndex, Legend legend, ChartTheme theme, bool active)
|
||||||
{
|
{
|
||||||
var textStyle = legend.textStyle;
|
var textStyle = legend.textStyle;
|
||||||
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
if (active)
|
||||||
|
{
|
||||||
|
if (legend.textAutoColor) return theme.GetColor(legendIndex);
|
||||||
|
else return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
||||||
|
}
|
||||||
else return theme.legend.unableColor;
|
else return theme.legend.unableColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +38,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
|
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
|
||||||
ChartTheme theme, string content, Color itemColor, bool active)
|
ChartTheme theme, string content, Color itemColor, bool active, int legendIndex)
|
||||||
{
|
{
|
||||||
var objName = i + "_" + legendName;
|
var objName = i + "_" + legendName;
|
||||||
var anchorMin = new Vector2(0, 0.5f);
|
var anchorMin = new Vector2(0, 0.5f);
|
||||||
@@ -43,7 +47,7 @@ namespace XCharts
|
|||||||
var sizeDelta = new Vector2(100, 30);
|
var sizeDelta = new Vector2(100, 30);
|
||||||
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
|
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
|
||||||
var textStyle = legend.textStyle;
|
var textStyle = legend.textStyle;
|
||||||
var contentColor = GetContentColor(legend, theme, active);
|
var contentColor = GetContentColor(legendIndex, legend, theme, active);
|
||||||
|
|
||||||
var objAnchorMin = new Vector2(0, 1);
|
var objAnchorMin = new Vector2(0, 1);
|
||||||
var objAnchorMax = new Vector2(0, 1);
|
var objAnchorMax = new Vector2(0, 1);
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ namespace XCharts
|
|||||||
var active = IsActiveByLegend(datas[i]);
|
var active = IsActiveByLegend(datas[i]);
|
||||||
var bgColor = LegendHelper.GetIconColor(this, readIndex, datas[i], active);
|
var bgColor = LegendHelper.GetIconColor(this, readIndex, datas[i], active);
|
||||||
var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, m_Theme,
|
var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, m_Theme,
|
||||||
legendName, bgColor, active);
|
legendName, bgColor, active,readIndex);
|
||||||
legend.SetButton(legendName, item, totalLegend);
|
legend.SetButton(legendName, item, totalLegend);
|
||||||
ChartHelper.ClearEventListener(item.button.gameObject);
|
ChartHelper.ClearEventListener(item.button.gameObject);
|
||||||
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
|
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user