mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 10:50:08 +00:00
增加BarChart可用ItemStyle的backgroundColor设置柱条背景颜色
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
* (2020.03.17) 增加`BarChart`可用`ItemStyle`的`backgroundColor`设置数据项背景颜色
|
||||||
* (2020.03.17) 增加`SerieData`的`ItemStyle`和`Emphasis`可单独配置数据项样式的支持
|
* (2020.03.17) 增加`SerieData`的`ItemStyle`和`Emphasis`可单独配置数据项样式的支持
|
||||||
* (2020.03.15) 重构`EmptyCricle`类型的`Symbol`边宽取自`ItemStyle`的`borderWidth`
|
* (2020.03.15) 重构`EmptyCricle`类型的`Symbol`边宽取自`ItemStyle`的`borderWidth`
|
||||||
* (2020.03.15) 重构`SerieSymbol`,去掉`color`和`opacity`参数,用`ItemStyle`参数代替
|
* (2020.03.15) 重构`SerieSymbol`,去掉`color`和`opacity`参数,用`ItemStyle`参数代替
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
internal static class SerieHelper
|
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 itemStyle = GetItemStyle(serie, serieData);
|
||||||
var color = Color.clear;
|
var color = Color.clear;
|
||||||
@@ -32,13 +32,14 @@ namespace XCharts
|
|||||||
color.a *= itemStyle.opacity;
|
color.a *= itemStyle.opacity;
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
else
|
else if (useDefault)
|
||||||
{
|
{
|
||||||
color = (Color)theme.GetColor(index);
|
color = (Color)theme.GetColor(index);
|
||||||
if (highlight) color *= color;
|
if (highlight) color *= color;
|
||||||
color.a = 0.2f;
|
color.a = 0.2f;
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
return Color.clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||||
|
|||||||
@@ -98,9 +98,9 @@ namespace XCharts
|
|||||||
p4 = ClampInCoordinate(p4);
|
p4 = ClampInCoordinate(p4);
|
||||||
top = ClampInCoordinate(top);
|
top = ClampInCoordinate(top);
|
||||||
serie.dataPoints.Add(top);
|
serie.dataPoints.Add(top);
|
||||||
|
|
||||||
if (serie.show)
|
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 areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
|
||||||
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
|
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
|
||||||
if (serie.barType == BarType.Zebra)
|
if (serie.barType == BarType.Zebra)
|
||||||
@@ -231,6 +231,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
|
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
|
||||||
Color areaToColor = SerieHelper.GetItemToColor(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)
|
if (serie.barType == BarType.Zebra)
|
||||||
{
|
{
|
||||||
p1 = (p4 + p1) / 2;
|
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()
|
private float GetBarGap()
|
||||||
{
|
{
|
||||||
float gap = 0.3f;
|
float gap = 0.3f;
|
||||||
|
|||||||
Reference in New Issue
Block a user