mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
优化Legend的颜色可自动匹配ItemStyle的自定义颜色#89
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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`点击扇形图扇区回调
|
||||
|
||||
@@ -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