增加BarChart可用ItemStylebackgroundColor设置柱条背景颜色

This commit is contained in:
monitor1394
2020-03-17 09:13:55 +08:00
parent b6c206c299
commit 2a3d8dc5b2
3 changed files with 31 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.03.17) 增加`BarChart`可用`ItemStyle``backgroundColor`设置数据项背景颜色
* (2020.03.17) 增加`SerieData``ItemStyle``Emphasis`可单独配置数据项样式的支持
* (2020.03.15) 重构`EmptyCricle`类型的`Symbol`边宽取自`ItemStyle``borderWidth`
* (2020.03.15) 重构`SerieSymbol`,去掉`color``opacity`参数,用`ItemStyle`参数代替

View File

@@ -11,7 +11,7 @@ namespace XCharts
{
internal static class SerieHelper
{
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight, bool useDefault = true)
{
var itemStyle = GetItemStyle(serie, serieData);
var color = Color.clear;
@@ -32,13 +32,14 @@ namespace XCharts
color.a *= itemStyle.opacity;
return color;
}
else
else if (useDefault)
{
color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a = 0.2f;
return color;
}
return Color.clear;
}
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)

View File

@@ -98,9 +98,9 @@ namespace XCharts
p4 = ClampInCoordinate(p4);
top = ClampInCoordinate(top);
serie.dataPoints.Add(top);
if (serie.show)
{
DrawBarBackground(vh, serie, serieData, colorIndex, highlight, pX, pY, space, barWidth, true);
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
if (serie.barType == BarType.Zebra)
@@ -231,6 +231,7 @@ namespace XCharts
{
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, colorIndex, highlight, pX, pY, space, barWidth, false);
if (serie.barType == BarType.Zebra)
{
p1 = (p4 + p1) / 2;
@@ -262,6 +263,31 @@ namespace XCharts
}
}
private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, int colorIndex, bool highlight,
float pX, float pY, float space, float barWidth, bool isYAxis)
{
Color color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false);
if (color != Color.clear)
{
if (isYAxis)
{
Vector3 p1 = new Vector3(coordinateX, pY + space + barWidth);
Vector3 p2 = new Vector3(coordinateX + coordinateWidth, pY + space + barWidth);
Vector3 p3 = new Vector3(coordinateX + coordinateWidth, pY + space);
Vector3 p4 = new Vector3(coordinateX, pY + space);
CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, color, color, serie.clip);
}
else
{
Vector3 p1 = new Vector3(pX + space, coordinateY);
Vector3 p2 = new Vector3(pX + space, coordinateY + coordinateHeight);
Vector3 p3 = new Vector3(pX + space + barWidth, coordinateY + coordinateHeight);
Vector3 p4 = new Vector3(pX + space + barWidth, coordinateY);
CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, color, color, serie.clip);
}
}
}
private float GetBarGap()
{
float gap = 0.3f;