[feature][serie] support the colorBy of serie

This commit is contained in:
monitor1394
2022-07-28 07:21:46 +08:00
parent 5b2b2d4059
commit cdf0bc81e1
13 changed files with 103 additions and 51 deletions

View File

@@ -57,11 +57,13 @@
## master ## master
* (2022.07.24) 增加`StateStyle``Symbol`用于配置状态下的标记样式 * (2022.07.28) 优化`Radar`雷达图效果
* (2022.07.24) 去掉`SerieSymbol``selectedSize`配置 * (2022.07.28) 增加`Serie``colorBy`参数配置取色策略
* (2022.07.27) 增加`StateStyle``Symbol`用于配置状态下的标记样式
* (2022.07.27) 去掉`SerieSymbol``selectedSize`参数
* (2022.07.24) 增加`Serie``SerieData``state`设置默认状态 * (2022.07.24) 增加`Serie``SerieData``state`设置默认状态
* (2022.07.22) 增加`Serie`的三种状态`EmphasisStyle`,`BlurStyle`,`SelectStyle` * (2022.07.22) 增加`Serie`的三种状态`EmphasisStyle`,`BlurStyle`,`SelectStyle`
* (2022.07.22) 去掉`AreaStyle``highlightColor``highlightToColor`配置 * (2022.07.22) 去掉`AreaStyle``highlightColor``highlightToColor`参数
* (2022.07.22) 去掉`Emphasis`,`EmphasisItemStyle`,`EmphasisLabelStyle`,`EmphasisLabelLine`组件 * (2022.07.22) 去掉`Emphasis`,`EmphasisItemStyle`,`EmphasisLabelStyle`,`EmphasisLabelLine`组件
* (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持 * (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持
* (2022.07.20) 修复`Axis``Value`轴时,`AxisLabel``showStartLabel``showEndLabel`参数设置不生效的问题 * (2022.07.20) 修复`Axis``Value`轴时,`AxisLabel``showStartLabel``showEndLabel`参数设置不生效的问题

View File

@@ -7,6 +7,7 @@ namespace XCharts.Editor
{ {
public override void OnCustomInspectorGUI() public override void OnCustomInspectorGUI()
{ {
PropertyField("m_ColorBy");
PropertyField("m_Stack"); PropertyField("m_Stack");
if (serie.IsUseCoord<PolarCoord>()) if (serie.IsUseCoord<PolarCoord>())
{ {

View File

@@ -7,6 +7,7 @@ namespace XCharts.Editor
{ {
public override void OnCustomInspectorGUI() public override void OnCustomInspectorGUI()
{ {
PropertyField("m_ColorBy");
PropertyField("m_RadarType"); PropertyField("m_RadarType");
PropertyField("m_RadarIndex"); PropertyField("m_RadarIndex");
PropertyField("m_Smooth"); PropertyField("m_Smooth");

View File

@@ -10,7 +10,8 @@ namespace XCharts.Runtime
{ {
public virtual bool vertsDirty { get { return m_VertsDirty; } } public virtual bool vertsDirty { get { return m_VertsDirty; } }
public virtual bool componentDirty { get { return m_ComponentDirty; } } public virtual bool componentDirty { get { return m_ComponentDirty; } }
public virtual bool useDataNameForColor { get { return false; } }
public virtual SerieColorBy defaultColorBy { get { return SerieColorBy.Serie; } }
public virtual bool titleJustForSerie { get { return false; } } public virtual bool titleJustForSerie { get { return false; } }
public virtual bool useSortData { get { return false; } } public virtual bool useSortData { get { return false; } }
public virtual bool multiDimensionLabel { get { return false; } } public virtual bool multiDimensionLabel { get { return false; } }
@@ -27,6 +28,8 @@ namespace XCharts.Runtime
public SerieHandler handler { get; set; } public SerieHandler handler { get; set; }
public static void ClearVerticesDirty(ChildComponent component) public static void ClearVerticesDirty(ChildComponent component)
{ {
if (component != null) if (component != null)

View File

@@ -836,7 +836,7 @@ namespace XCharts.Runtime
} }
} }
public static Color32 GetHighlightColor(Color32 color, float rate = 1.2f) public static Color32 GetHighlightColor(Color32 color, float rate = 0.8f)
{ {
var newColor = color; var newColor = color;
newColor.r = (byte) (color.r * rate); newColor.r = (byte) (color.r * rate);

View File

@@ -9,7 +9,7 @@ namespace XCharts.Runtime
[SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")] [SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")]
public class Pie : Serie public class Pie : Serie
{ {
public override bool useDataNameForColor { get { return true; } } public override SerieColorBy defaultColorBy { get { return SerieColorBy.Data; } }
public override bool titleJustForSerie { get { return true; } } public override bool titleJustForSerie { get { return true; } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) public static Serie AddDefaultSerie(BaseChart chart, string serieName)

View File

@@ -25,7 +25,7 @@ namespace XCharts.Runtime
public int containerIndex { get; internal set; } public int containerIndex { get; internal set; }
public int containterInstanceId { get; internal set; } public int containterInstanceId { get; internal set; }
public override bool useDataNameForColor { get { return radarType == RadarType.Multiple; } } public override SerieColorBy defaultColorBy { get { return radarType == RadarType.Multiple?SerieColorBy.Serie : SerieColorBy.Data; } }
public override bool multiDimensionLabel { get { return radarType == RadarType.Multiple; } } public override bool multiDimensionLabel { get { return radarType == RadarType.Multiple; } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) public static Serie AddDefaultSerie(BaseChart chart, string serieName)

View File

@@ -41,8 +41,9 @@ namespace XCharts.Runtime
if (serie.radarType == RadarType.Single) if (serie.radarType == RadarType.Single)
{ {
var colorIndex1 = serie.colorByData ? dataIndex : serie.context.colorIndex;
UpdateItemSerieParams(ref paramList, ref title, dataIndex, category, UpdateItemSerieParams(ref paramList, ref title, dataIndex, category,
marker, itemFormatter, numericFormatter); marker, itemFormatter, numericFormatter, 1, colorIndex1);
return; return;
} }
@@ -55,7 +56,8 @@ namespace XCharts.Runtime
return; return;
Color32 color, toColor; Color32 color, toColor;
SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, dataIndex, SerieState.Normal); var colorIndex = serie.colorByData ? chart.GetLegendRealShowNameIndex(serieData.legendName) : serie.context.colorIndex;
SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal);
title = serieData.name; title = serieData.name;
for (int i = 0; i < serieData.data.Count; i++) for (int i = 0; i < serieData.data.Count; i++)
{ {
@@ -101,6 +103,7 @@ namespace XCharts.Runtime
serie.context.pointerEnter = false; serie.context.pointerEnter = false;
serie.context.pointerItemDataIndex = -1; serie.context.pointerItemDataIndex = -1;
var areaStyle = serie.areaStyle; var areaStyle = serie.areaStyle;
var themeSymbolSize = chart.theme.serie.lineSymbolSize;
switch (serie.radarType) switch (serie.radarType)
{ {
case RadarType.Multiple: case RadarType.Multiple:
@@ -156,12 +159,13 @@ namespace XCharts.Runtime
{ {
var serieData = serie.data[i]; var serieData = serie.data[i];
serieData.index = i; serieData.index = i;
if (Vector3.Distance(chart.pointerPos, serieData.context.position) < serie.symbol.size * 2) var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize);
if (Vector3.Distance(chart.pointerPos, serieData.context.position) < size * 2)
{ {
serie.highlight = true; serie.highlight = true;
serie.context.pointerEnter = true; serie.context.pointerEnter = true;
serie.context.pointerItemDataIndex = i; serie.context.pointerItemDataIndex = i;
return; break;
} }
} }
if (!serie.context.pointerEnter && areaStyle != null) if (!serie.context.pointerEnter && areaStyle != null)
@@ -228,7 +232,7 @@ namespace XCharts.Runtime
var lineStyle = SerieHelper.GetLineStyle(serie, serieData); var lineStyle = SerieHelper.GetLineStyle(serie, serieData);
var symbol = SerieHelper.GetSerieSymbol(serie, serieData, serieState); var symbol = SerieHelper.GetSerieSymbol(serie, serieData, serieState);
var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); var colorIndex = serie.colorByData ? chart.GetLegendRealShowNameIndex(serieData.legendName) : serie.context.colorIndex;
var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex); var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex);
var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex); var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex);
var lineWidth = lineStyle.GetWidth(chart.theme.serie.lineWidth); var lineWidth = lineStyle.GetWidth(chart.theme.serie.lineWidth);
@@ -313,7 +317,8 @@ namespace XCharts.Runtime
serieData.interact.SetValue(ref interacting, symbolSize); serieData.interact.SetValue(ref interacting, symbolSize);
symbolSize = serie.animation.GetSysmbolSize(symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize);
} }
SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, j, serieState); colorIndex = serie.colorByData ? m : colorIndex;
SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, colorIndex, serieState);
SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, serieState); SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, serieState);
chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor, chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor,
symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius); symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius);
@@ -333,13 +338,13 @@ namespace XCharts.Runtime
private void DrawSingleRadar(VertexHelper vh) private void DrawSingleRadar(VertexHelper vh)
{ {
var radar = chart.GetChartComponent<RadarCoord>(serie.radarIndex); m_RadarCoord = chart.GetChartComponent<RadarCoord>(serie.radarIndex);
if (radar == null) if (m_RadarCoord == null)
return; return;
var indicatorNum = radar.indicatorList.Count; var indicatorNum = m_RadarCoord.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum; var angle = 2 * Mathf.PI / indicatorNum;
var centerPos = radar.context.center; var centerPos = m_RadarCoord.context.center;
serie.animation.InitProgress(0, 1); serie.animation.InitProgress(0, 1);
serie.context.dataPoints.Clear(); serie.context.dataPoints.Clear();
if (!serie.show || serie.animation.HasFadeOut()) if (!serie.show || serie.animation.HasFadeOut())
@@ -357,7 +362,7 @@ namespace XCharts.Runtime
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var startIndex = GetStartShowIndex(serie); var startIndex = GetStartShowIndex(serie);
var endIndex = GetEndShowIndex(serie); var endIndex = GetEndShowIndex(serie);
SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate); SerieHelper.UpdateMinMaxData(serie, 1, m_RadarCoord.ceilRate);
for (int j = 0; j < serie.data.Count; j++) for (int j = 0; j < serie.data.Count; j++)
{ {
var serieData = serie.data[j]; var serieData = serie.data[j];
@@ -371,25 +376,26 @@ namespace XCharts.Runtime
} }
var lineStyle = SerieHelper.GetLineStyle(serie, serieData); var lineStyle = SerieHelper.GetLineStyle(serie, serieData);
Color32 areaColor, areaToColor; Color32 areaColor, areaToColor;
var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, j); var colorIndex = serie.colorByData?j : serie.context.colorIndex;
var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, j); var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex);
int dataCount = radar.indicatorList.Count; var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex);
int dataCount = m_RadarCoord.indicatorList.Count;
var index = serieData.index; var index = serieData.index;
var p = radar.context.center; var p = m_RadarCoord.context.center;
var max = radar.GetIndicatorMax(index); var max = m_RadarCoord.GetIndicatorMax(index);
var value = serieData.GetCurrData(1, dataChangeDuration); var value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true; if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0) if (max == 0)
{ {
max = serie.context.dataMax; max = serie.context.dataMax;
} }
if (!radar.IsInIndicatorRange(j, serieData.GetData(1))) if (!m_RadarCoord.IsInIndicatorRange(j, serieData.GetData(1)))
{ {
lineColor = radar.outRangeColor; lineColor = m_RadarCoord.outRangeColor;
} }
var radius = (float) (max < 0 ? radar.context.dataRadius - radar.context.dataRadius * value / max : var radius = (float) (max < 0 ? m_RadarCoord.context.dataRadius - m_RadarCoord.context.dataRadius * value / max :
radar.context.dataRadius * value / max); m_RadarCoord.context.dataRadius * value / max);
var currAngle = (index + (radar.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle; var currAngle = (index + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate; radius *= rate;
if (index == startIndex) if (index == startIndex)
{ {
@@ -409,11 +415,11 @@ namespace XCharts.Runtime
} }
if (lineStyle.show && !serie.smooth) if (lineStyle.show && !serie.smooth)
{ {
if (radar.connectCenter) if (m_RadarCoord.connectCenter)
ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos, ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos,
chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor); chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, toPoint, chart.theme.serie.lineWidth, ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, toPoint, chart.theme.serie.lineWidth,
LineStyle.Type.Solid, radar.lineGradient ? lastColor : lineColor, lineColor); LineStyle.Type.Solid, m_RadarCoord.lineGradient ? lastColor : lineColor, lineColor);
} }
startPoint = toPoint; startPoint = toPoint;
lastColor = lineColor; lastColor = lineColor;
@@ -428,11 +434,11 @@ namespace XCharts.Runtime
} }
if (lineStyle.show && j == endIndex && !serie.smooth) if (lineStyle.show && j == endIndex && !serie.smooth)
{ {
if (radar.connectCenter) if (m_RadarCoord.connectCenter)
ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos, ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos,
chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor); chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, firstPoint, chart.theme.serie.lineWidth, ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, firstPoint, chart.theme.serie.lineWidth,
LineStyle.Type.Solid, lineColor, radar.lineGradient ? firstColor : lineColor); LineStyle.Type.Solid, lineColor, m_RadarCoord.lineGradient ? firstColor : lineColor);
} }
} }
if (serie.smooth) if (serie.smooth)
@@ -455,14 +461,14 @@ namespace XCharts.Runtime
var serieData = serie.data[j]; var serieData = serie.data[j];
if (!serieData.show) continue; if (!serieData.show) continue;
var state = SerieHelper.GetSerieState(serie, serieData); var state = SerieHelper.GetSerieState(serie, serieData);
var serieIndex = serieData.index;
var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state); var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state);
SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, serieIndex, state); var colorIndex = serie.colorByData ? serieData.index : serie.context.colorIndex;
SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, colorIndex, state);
SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state); SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state);
if (!radar.IsInIndicatorRange(j, serieData.GetData(1))) if (!m_RadarCoord.IsInIndicatorRange(j, serieData.GetData(1)))
{ {
symbolColor = radar.outRangeColor; symbolColor = m_RadarCoord.outRangeColor;
symbolToColor = radar.outRangeColor; symbolToColor = m_RadarCoord.outRangeColor;
} }
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.context.labelPosition, symbolColor, chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.context.labelPosition, symbolColor,
symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius); symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius);

View File

@@ -9,7 +9,7 @@ namespace XCharts.Runtime
[SerieDataExtraField()] [SerieDataExtraField()]
public class Ring : Serie public class Ring : Serie
{ {
public override bool useDataNameForColor { get { return true; } } public override SerieColorBy defaultColorBy { get { return SerieColorBy.Data; } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) public static Serie AddDefaultSerie(BaseChart chart, string serieName)
{ {
var serie = chart.AddSerie<Ring>(serieName); var serie = chart.AddSerie<Ring>(serieName);

View File

@@ -194,6 +194,29 @@ namespace XCharts.Runtime
Auto Auto
} }
/// <summary>
/// The policy to take color from theme.
/// |从主题中取色策略。
/// </summary>
public enum SerieColorBy
{
/// <summary>
/// Select state.
/// |默认策略。每种Serie都有自己的默认的取颜色策略。比如Line默认是Series策略Pie默认是Data策略
/// </summary>
Default,
/// <summary>
/// assigns the colors in the palette by serie, so that all data in the same series are in the same color;.
/// |按照系列分配调色盘中的颜色,同一系列中的所有数据都是用相同的颜色。
/// </summary>
Serie,
/// <summary>
/// assigns colors in the palette according to data items, with each data item using a different color..
/// |按照数据项分配调色盘中的颜色,每个数据项都使用不同的颜色。
/// </summary>
Data
}
/// <summary> /// <summary>
/// 系列。 /// 系列。
/// </summary> /// </summary>
@@ -206,6 +229,7 @@ namespace XCharts.Runtime
[SerializeField] private string m_SerieType = ""; [SerializeField] private string m_SerieType = "";
[SerializeField] private string m_SerieName; [SerializeField] private string m_SerieName;
[SerializeField][Since("v3.2.0")] private SerieState m_State = SerieState.Normal; [SerializeField][Since("v3.2.0")] private SerieState m_State = SerieState.Normal;
[SerializeField][Since("v3.2.0")] private SerieColorBy m_ColorBy = SerieColorBy.Default;
[SerializeField] private string m_Stack; [SerializeField] private string m_Stack;
[SerializeField] private int m_XAxisIndex = 0; [SerializeField] private int m_XAxisIndex = 0;
[SerializeField] private int m_YAxisIndex = 0; [SerializeField] private int m_YAxisIndex = 0;
@@ -339,6 +363,16 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_State, value)) { SetAllDirty(); } } set { if (PropertyUtil.SetStruct(ref m_State, value)) { SetAllDirty(); } }
} }
/// <summary> /// <summary>
/// The policy to take color from theme.
/// |从主题中取色的策略。
/// </summary>
public SerieColorBy colorBy
{
//get { return m_ColorBy; }
get { return m_ColorBy == SerieColorBy.Default?defaultColorBy : m_ColorBy; }
set { if (PropertyUtil.SetStruct(ref m_ColorBy, value)) { SetAllDirty(); } }
}
/// <summary>
/// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other. /// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other.
/// |数据堆叠同个类目轴上系列配置相同的stack值后后一个系列的值会在前一个系列的值上相加。 /// |数据堆叠同个类目轴上系列配置相同的stack值后后一个系列的值会在前一个系列的值上相加。
/// </summary> /// </summary>
@@ -860,7 +894,10 @@ namespace XCharts.Runtime
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。 /// 系列中的数据内容数组。SerieData可以设置1到n维数据。
/// </summary> /// </summary>
public List<SerieData> data { get { return m_Data; } } public List<SerieData> data { get { return m_Data; } }
/// <summary>
/// 取色策略是否为按数据项分配。
/// </summary>
public bool colorByData { get { return colorBy == SerieColorBy.Data; } }
public override bool vertsDirty public override bool vertsDirty
{ {
get get
@@ -1703,7 +1740,7 @@ namespace XCharts.Runtime
public bool IsLegendName(string legendName) public bool IsLegendName(string legendName)
{ {
if (useDataNameForColor) if (colorBy == SerieColorBy.Data)
{ {
return IsSerieDataLegendName(legendName) || IsSerieLegendName(legendName); return IsSerieDataLegendName(legendName) || IsSerieLegendName(legendName);
} }

View File

@@ -144,7 +144,7 @@ namespace XCharts.Runtime
public override void OnLegendButtonClick(int index, string legendName, bool show) public override void OnLegendButtonClick(int index, string legendName, bool show)
{ {
if (serie.useDataNameForColor && serie.IsSerieDataLegendName(legendName)) if (serie.colorByData && serie.IsSerieDataLegendName(legendName))
{ {
LegendHelper.CheckDataShow(serie, legendName, show); LegendHelper.CheckDataShow(serie, legendName, show);
chart.UpdateLegendColor(legendName, show); chart.UpdateLegendColor(legendName, show);
@@ -159,7 +159,7 @@ namespace XCharts.Runtime
public override void OnLegendButtonEnter(int index, string legendName) public override void OnLegendButtonEnter(int index, string legendName)
{ {
if (serie.useDataNameForColor && serie.IsSerieDataLegendName(legendName)) if (serie.colorByData && serie.IsSerieDataLegendName(legendName))
{ {
LegendHelper.CheckDataHighlighted(serie, legendName, true); LegendHelper.CheckDataHighlighted(serie, legendName, true);
chart.RefreshPainter(serie); chart.RefreshPainter(serie);
@@ -173,7 +173,7 @@ namespace XCharts.Runtime
public override void OnLegendButtonExit(int index, string legendName) public override void OnLegendButtonExit(int index, string legendName)
{ {
if (serie.useDataNameForColor && serie.IsSerieDataLegendName(legendName)) if (serie.colorByData && serie.IsSerieDataLegendName(legendName))
{ {
LegendHelper.CheckDataHighlighted(serie, legendName, false); LegendHelper.CheckDataHighlighted(serie, legendName, false);
chart.RefreshPainter(serie); chart.RefreshPainter(serie);
@@ -485,7 +485,7 @@ namespace XCharts.Runtime
public virtual Color GetSerieDataAutoColor(SerieData serieData) public virtual Color GetSerieDataAutoColor(SerieData serieData)
{ {
var colorIndex = serie.useDataNameForColor ? serieData.index : serie.index; var colorIndex = serie.colorByData ? serieData.index : serie.index;
Color32 color, toColor; Color32 color, toColor;
SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal, false); SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal, false);
return (Color) color; return (Color) color;
@@ -533,7 +533,7 @@ namespace XCharts.Runtime
protected void UpdateItemSerieParams(ref List<SerieParams> paramList, ref string title, protected void UpdateItemSerieParams(ref List<SerieParams> paramList, ref string title,
int dataIndex, string category, string marker, int dataIndex, string category, string marker,
string itemFormatter, string numericFormatter, int dimension = 1) string itemFormatter, string numericFormatter, int dimension = 1, int colorIndex = -1)
{ {
if (dataIndex < 0) if (dataIndex < 0)
dataIndex = serie.context.pointerItemDataIndex; dataIndex = serie.context.pointerItemDataIndex;
@@ -549,10 +549,11 @@ namespace XCharts.Runtime
if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter)) if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter))
return; return;
var colorIndex = chart.GetLegendRealShowNameIndex(serieData.name); if (colorIndex < 0)
colorIndex = serie.colorByData?dataIndex : chart.GetLegendRealShowNameIndex(serieData.name);
Color32 color, toColor; Color32 color, toColor;
SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal); SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal);
var param = serie.context.param; var param = serie.context.param;
param.serieName = serie.serieName; param.serieName = serie.serieName;
param.serieIndex = serie.index; param.serieIndex = serie.index;

View File

@@ -282,7 +282,8 @@ namespace XCharts.Runtime
public static void GetItemColor(out Color32 color, out Color32 toColor, public static void GetItemColor(out Color32 color, out Color32 toColor,
Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
{ {
GetItemColor(out color, out toColor, serie, serieData, theme, serie.context.colorIndex, state, true); var colorIndex = serie.colorByData? serieData.index : serie.context.colorIndex;
GetItemColor(out color, out toColor, serie, serieData, theme, colorIndex, state, true);
} }
public static void GetItemColor(out Color32 color, out Color32 toColor, public static void GetItemColor(out Color32 color, out Color32 toColor,

View File

@@ -24,7 +24,7 @@ namespace XCharts.Runtime
{ {
var serie = series[n]; var serie = series[n];
if (serie.placeHolder) continue; if (serie.placeHolder) continue;
if (serie.useDataNameForColor) if (serie.colorByData)
{ {
for (int i = 0; i < serie.data.Count; i++) for (int i = 0; i < serie.data.Count; i++)
{ {
@@ -53,7 +53,7 @@ namespace XCharts.Runtime
{ {
var serie = chart.series[n]; var serie = chart.series[n];
if (serie.placeHolder) continue; if (serie.placeHolder) continue;
if (serie.useDataNameForColor) if (serie.colorByData)
{ {
for (int i = 0; i < serie.data.Count; i++) for (int i = 0; i < serie.data.Count; i++)
{ {
@@ -84,7 +84,7 @@ namespace XCharts.Runtime
{ {
var serie = series[n]; var serie = series[n];
if (serie.placeHolder) continue; if (serie.placeHolder) continue;
if (serie.useDataNameForColor) if (serie.colorByData)
{ {
bool found = false; bool found = false;
for (int i = 0; i < serie.data.Count; i++) for (int i = 0; i < serie.data.Count; i++)