mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 09:20:08 +00:00
优化Legend的颜色可自动匹配ItemStyle的自定义颜色#89
This commit is contained in:
@@ -464,7 +464,7 @@ namespace XCharts
|
||||
var legendIndex = m_LegendRealShowName.IndexOf(legendName);
|
||||
if (legendIndex >= 0)
|
||||
{
|
||||
var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_ThemeInfo, active);
|
||||
var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_ThemeInfo, m_Series, legendName, active);
|
||||
var contentColor = LegendHelper.GetContentColor(legend, m_ThemeInfo, active);
|
||||
m_Legend.UpdateButtonColor(legendName, iconColor);
|
||||
m_Legend.UpdateContentColor(legendName, contentColor);
|
||||
|
||||
@@ -364,7 +364,7 @@ namespace XCharts
|
||||
string legendName = m_Legend.GetFormatterContent(datas[i]);
|
||||
var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
|
||||
var active = IsActiveByLegend(datas[i]);
|
||||
var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, active);
|
||||
var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, m_Series, datas[i], active);
|
||||
var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo,
|
||||
legendName, bgColor, active);
|
||||
m_Legend.SetButton(legendName, item, totalLegend);
|
||||
|
||||
@@ -18,12 +18,14 @@ namespace XCharts
|
||||
else return (Color)themeInfo.legendUnableColor;
|
||||
}
|
||||
|
||||
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, bool active)
|
||||
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, Series series, string legendName, bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
|
||||
return (Color)themeInfo.GetColor(readIndex);
|
||||
{
|
||||
return SeriesHelper.GetNameColor(series, readIndex, legendName, themeInfo);
|
||||
}
|
||||
else
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,42 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetNameColor(Series series, int index, string name, ThemeInfo theme)
|
||||
{
|
||||
Serie destSerie = null;
|
||||
SerieData destSerieData = null;
|
||||
|
||||
for (int n = 0; n < series.list.Count; n++)
|
||||
{
|
||||
var serie = series.GetSerie(n);
|
||||
if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
|
||||
{
|
||||
bool found = false;
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
if (name.Equals(serie.data[i].name))
|
||||
{
|
||||
destSerie = serie;
|
||||
destSerieData = serie.data[i];
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (name.Equals(serie.name))
|
||||
{
|
||||
destSerie = serie;
|
||||
destSerieData = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SerieHelper.GetItemColor(destSerie, destSerieData, theme, index, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同堆叠的serie是否有渐变色的。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user