diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md
index 55a98e70..be5422e2 100644
--- a/CHANGELOG-EN.md
+++ b/CHANGELOG-EN.md
@@ -42,6 +42,8 @@
## branch-2.0
+* (2022.01.06) Improved `Zebra` bar chart
+
## v2.6.0
* (2021.12.30) Release `v2.6.0` version
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 19eb4069..6c5788f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,8 @@
## branch-2.0
+* (2022.01.06) 优化`Zebra`斑马柱图
+
## v2.6.0
* (2021.12.30) 发布`v2.6.0`版本
diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs
index b05c4f4a..5e7c10bc 100644
--- a/Runtime/Internal/CoordinateChart.cs
+++ b/Runtime/Internal/CoordinateChart.cs
@@ -1696,11 +1696,11 @@ namespace XCharts
}
public void Internal_CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth,
- float zebraGap, Color32 color, Color32 toColor, bool clip, Grid grid)
+ float zebraGap, Color32 color, Color32 toColor, bool clip, Grid grid, float maxDistance)
{
ClampInChart(ref p1);
ClampInChart(ref p2);
- UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color, toColor);
+ UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color, toColor,maxDistance);
}
protected Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos, Grid grid)
diff --git a/Runtime/Internal/CoordinateChart_DrawBar.cs b/Runtime/Internal/CoordinateChart_DrawBar.cs
index 512db0d5..4dd2898f 100644
--- a/Runtime/Internal/CoordinateChart_DrawBar.cs
+++ b/Runtime/Internal/CoordinateChart_DrawBar.cs
@@ -386,14 +386,14 @@ namespace XCharts
plt = (plb + plt) / 2;
prt = (prt + prb) / 2;
Internal_CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
- barColor, barToColor, serie.clip, grid);
+ barColor, barToColor, serie.clip, grid, grid.runtimeWidth);
}
else
{
plb = (prb + plb) / 2;
plt = (plt + prt) / 2;
Internal_CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
- barColor, barToColor, serie.clip, grid);
+ barColor, barToColor, serie.clip, grid, grid.runtimeHeight);
}
}
diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs
index 30a02ed9..6fd44889 100644
--- a/Runtime/XUGL/UGL.cs
+++ b/Runtime/XUGL/UGL.cs
@@ -299,9 +299,25 @@ namespace XUGL
/// 起始颜色
/// 结束颜色
public static void DrawZebraLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
- float zebraWidth, float zebraGap, Color32 color, Color32 toColor)
+ float zebraWidth, float zebraGap, Color32 color, Color32 toColor, float maxDistance)
{
- DrawDotLine(vh, startPoint, endPoint, width, color, toColor, zebraWidth, zebraGap);
+ var dist = Vector3.Distance(startPoint, endPoint);
+ if (dist < 0.1f) return;
+ if (zebraWidth == 0) zebraWidth = 3 * width;
+ if (zebraGap == 0) zebraGap = 3 * width;
+ var allSegment = Mathf.CeilToInt(maxDistance / (zebraWidth + zebraGap));
+ var segment = Mathf.CeilToInt(dist / maxDistance * allSegment);
+ var dir = (endPoint - startPoint).normalized;
+ var sp = startPoint;
+ var np = Vector3.zero;
+ var isGradient = !color.Equals(toColor);
+ for (int i = 1; i <= segment; i++)
+ {
+ np = startPoint + dir * maxDistance * i / allSegment;
+ var dashep = np - dir * zebraGap;
+ DrawLine(vh, sp, dashep, width, isGradient ? Color32.Lerp(color, toColor, i * 1.0f / allSegment) : color);
+ sp = np;
+ }
}
///