优化Legend的颜色可自动匹配ItemStyle的自定义颜色#89

This commit is contained in:
monitor1394
2020-09-08 09:28:19 +08:00
parent f18dd10f0d
commit cd519f021f
6 changed files with 44 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.09.08) Optimize the color of `Legend` to automatically match the custom color of `ItemStyle`
* (2020.09.05) Optimize `LineChart` to display `XAxis1` without using `XAxis1`.
* (2020.08.29) Added `toColor` and `toColor2` of `LineStyle` to set the horizontal gradient of `LineChart`. Cancel `ItemStyle` to set the horizontal gradient of `LineChart`.
* (2020.08.29) Added the `onPointerClickPie` of `PieChart`, a callback function of click pie area.

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.09.08) 优化`Legend`的颜色可自动匹配`ItemStyle`的自定义颜色#89
* (2020.09.05) 优化`LineChart`在不使用`XAxis1`时也能显示`XAxis1`
* (2020.08.29) 增加`LineStyle``toColor``toColor2`设置`LineChart`的水平渐变,取消通过`ItemStyle`设置`LineChart`的水平渐变
* (2020.08.29) 增加`PieChart``onPointerClickPie`点击扇形图扇区回调

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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>