diff --git a/Assets/XCharts/CHANGELOG-EN.md b/Assets/XCharts/CHANGELOG-EN.md
index addccb43..cbf3368c 100644
--- a/Assets/XCharts/CHANGELOG-EN.md
+++ b/Assets/XCharts/CHANGELOG-EN.md
@@ -39,6 +39,7 @@
## master
+* (2021.07.29) Improved `BarChart`'s `Zebra` gradient support
* (2021.07.26) Fixed issue where `XCharts` path could not be found when `TextMeshPro Enable` (#160)
## v2.3.0
diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md
index a1301ac2..58818ed5 100644
--- a/Assets/XCharts/CHANGELOG.md
+++ b/Assets/XCharts/CHANGELOG.md
@@ -39,6 +39,7 @@
## master
+* (2021.07.29) 完善`BarChart`的`Zebra`斑马柱图渐变支持
* (2021.07.26) 修复`TextMeshPro Enable`时找不到`XCharts`路径的问题 (#160)
## v2.3.0
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart.cs
index 94f589b0..b1f4f20e 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart.cs
@@ -1689,11 +1689,11 @@ namespace XCharts
}
public void Internal_CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth,
- float zebraGap, Color32 color, bool clip, Grid grid)
+ float zebraGap, Color32 color,Color32 toColor, bool clip, Grid grid)
{
ClampInChart(ref p1);
ClampInChart(ref p2);
- UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color);
+ UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color, toColor);
}
protected Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos, Grid grid)
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs
index daa7c17d..49931504 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs
@@ -376,21 +376,22 @@ namespace XCharts
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis, Grid grid)
{
- var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
+ var barColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
+ var barToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid);
if (isYAxis)
{
plt = (plb + plt) / 2;
prt = (prt + prb) / 2;
Internal_CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
- areaColor, serie.clip, grid);
+ barColor, barToColor, serie.clip, grid);
}
else
{
plb = (prb + plb) / 2;
plt = (plt + prt) / 2;
Internal_CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
- areaColor, serie.clip, grid);
+ barColor, barToColor, serie.clip, grid);
}
}
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawLine.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawLine.cs
index 112a6771..d9a3d6fc 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawLine.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawLine.cs
@@ -635,11 +635,11 @@ namespace XCharts
areaColor, areaToColor, zeroPos);
break;
case LineType.Dash:
- UGL.DrawDashLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor);
+ UGL.DrawDashLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, lineColor);
isFinish = true;
break;
case LineType.Dot:
- UGL.DrawDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor);
+ UGL.DrawDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, lineColor);
isFinish = true;
break;
case LineType.DashDot:
@@ -1172,10 +1172,10 @@ namespace XCharts
switch (serie.lineType)
{
case LineType.Dash:
- UGL.DrawDashLine(vh, lp, np, lineWidth, lineColor, 0, 0, posList);
+ UGL.DrawDashLine(vh, lp, np, lineWidth, lineColor, lineColor, 0, 0, posList);
break;
case LineType.Dot:
- UGL.DrawDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, posList);
+ UGL.DrawDotLine(vh, lp, np, lineWidth, lineColor, lineColor, 0, 0, posList);
break;
case LineType.DashDot:
UGL.DrawDashDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, 0, posList);
diff --git a/Assets/XCharts/Runtime/Internal/Utility/ChartDrawer.cs b/Assets/XCharts/Runtime/Internal/Utility/ChartDrawer.cs
index 4432e65c..bb06afb2 100644
--- a/Assets/XCharts/Runtime/Internal/Utility/ChartDrawer.cs
+++ b/Assets/XCharts/Runtime/Internal/Utility/ChartDrawer.cs
@@ -104,10 +104,10 @@ namespace XCharts
switch (lineType)
{
case LineStyle.Type.Dashed:
- UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color);
+ UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color, color);
break;
case LineStyle.Type.Dotted:
- UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color);
+ UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color, color);
break;
case LineStyle.Type.Solid:
UGL.DrawLine(vh, startPos, endPos, lineWidth, color);
diff --git a/Assets/XCharts/Runtime/XUGL/UGL.cs b/Assets/XCharts/Runtime/XUGL/UGL.cs
index e37eb178..4f170065 100644
--- a/Assets/XCharts/Runtime/XUGL/UGL.cs
+++ b/Assets/XCharts/Runtime/XUGL/UGL.cs
@@ -119,12 +119,13 @@ namespace XUGL
/// 起始点
/// 结束点
/// 线宽
- /// 颜色
+ /// 起始颜色
+ /// 结束颜色
/// 实线部分长度,默认为线宽的12倍
/// 间隙部分长度,默认为线宽的3倍
/// 可选,输出的关键点
public static void DrawDashLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
- Color32 color, float lineLength = 0f, float gapLength = 0f, List posList = null)
+ Color32 color, Color32 toColor, float lineLength = 0f, float gapLength = 0f, List posList = null)
{
float dist = Vector3.Distance(startPoint, endPoint);
if (dist < 0.1f) return;
@@ -133,17 +134,18 @@ namespace XUGL
int segment = Mathf.CeilToInt(dist / (lineLength + gapLength));
Vector3 dir = (endPoint - startPoint).normalized;
Vector3 sp = startPoint, np;
+ var isGradient = !color.Equals(toColor);
if (posList != null) posList.Clear();
for (int i = 1; i <= segment; i++)
{
if (posList != null) posList.Add(sp);
np = startPoint + dir * dist * i / segment;
var dashep = np - dir * gapLength;
- DrawLine(vh, sp, dashep, width, color);
+ DrawLine(vh, sp, dashep, width, isGradient ? Color32.Lerp(color, toColor, i * 1.0f / segment) : color);
sp = np;
}
if (posList != null) posList.Add(endPoint);
- DrawLine(vh, sp, endPoint, width, color);
+ DrawLine(vh, sp, endPoint, width, toColor);
}
///
@@ -153,31 +155,34 @@ namespace XUGL
/// 起始点
/// 结束点
/// 线宽
- /// 颜色
+ /// 起始颜色
+ /// 结束颜色
/// 实线部分长度,默认为线宽的3倍
/// 间隙部分长度,默认为线宽的3倍
/// 可选,输出的关键点
public static void DrawDotLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
- Color32 color, float lineLength = 0f, float gapLength = 0f, List posList = null)
+ Color32 color, Color32 toColor, float lineLength = 0f, float gapLength = 0f, List posList = null)
{
- float dist = Vector3.Distance(startPoint, endPoint);
+ var dist = Vector3.Distance(startPoint, endPoint);
if (dist < 0.1f) return;
if (lineLength == 0) lineLength = 3 * width;
if (gapLength == 0) gapLength = 3 * width;
- int segment = Mathf.CeilToInt(dist / (lineLength + gapLength));
- Vector3 dir = (endPoint - startPoint).normalized;
- Vector3 sp = startPoint, np;
+ var segment = Mathf.CeilToInt(dist / (lineLength + gapLength));
+ var dir = (endPoint - startPoint).normalized;
+ var sp = startPoint;
+ var np = Vector3.zero;
+ var isGradient = !color.Equals(toColor);
if (posList != null) posList.Clear();
for (int i = 1; i <= segment; i++)
{
if (posList != null) posList.Add(sp);
np = startPoint + dir * dist * i / segment;
var dashep = np - dir * gapLength;
- DrawLine(vh, sp, dashep, width, color);
+ DrawLine(vh, sp, dashep, width, isGradient ? Color32.Lerp(color, toColor, i * 1.0f / segment) : color);
sp = np;
}
if (posList != null) posList.Add(endPoint);
- DrawLine(vh, sp, endPoint, width, color);
+ DrawLine(vh, sp, endPoint, width, toColor);
}
///
@@ -277,11 +282,12 @@ namespace XUGL
/// 线宽
/// 斑马条纹宽
/// 间隙宽
- /// 颜色
+ /// 起始颜色
+ /// 结束颜色
public static void DrawZebraLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
- float zebraWidth, float zebraGap, Color32 color)
+ float zebraWidth, float zebraGap, Color32 color, Color32 toColor)
{
- DrawDotLine(vh, startPoint, endPoint, width, color, zebraWidth, zebraGap);
+ DrawDotLine(vh, startPoint, endPoint, width, color, toColor, zebraWidth, zebraGap);
}
///