mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 22:10:11 +00:00
完善BarChart的Zebra斑马柱图渐变支持
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.07.29) 完善`BarChart`的`Zebra`斑马柱图渐变支持
|
||||
* (2021.07.26) 修复`TextMeshPro Enable`时找不到`XCharts`路径的问题 (#160)
|
||||
|
||||
## v2.3.0
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -119,12 +119,13 @@ namespace XUGL
|
||||
/// <param name="startPoint">起始点</param>
|
||||
/// <param name="endPoint">结束点</param>
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="color">起始颜色</param>
|
||||
/// <param name="toColor">结束颜色</param>
|
||||
/// <param name="lineLength">实线部分长度,默认为线宽的12倍</param>
|
||||
/// <param name="gapLength">间隙部分长度,默认为线宽的3倍</param>
|
||||
/// <param name="posList">可选,输出的关键点</param>
|
||||
public static void DrawDashLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
|
||||
Color32 color, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null)
|
||||
Color32 color, Color32 toColor, float lineLength = 0f, float gapLength = 0f, List<Vector3> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,31 +155,34 @@ namespace XUGL
|
||||
/// <param name="startPoint">起始点</param>
|
||||
/// <param name="endPoint">结束点</param>
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="color">起始颜色</param>
|
||||
/// <param name="toColor">结束颜色</param>
|
||||
/// <param name="lineLength">实线部分长度,默认为线宽的3倍</param>
|
||||
/// <param name="gapLength">间隙部分长度,默认为线宽的3倍</param>
|
||||
/// <param name="posList">可选,输出的关键点</param>
|
||||
public static void DrawDotLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
|
||||
Color32 color, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null)
|
||||
Color32 color, Color32 toColor, float lineLength = 0f, float gapLength = 0f, List<Vector3> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -277,11 +282,12 @@ namespace XUGL
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="zebraWidth">斑马条纹宽</param>
|
||||
/// <param name="zebraGap">间隙宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="color">起始颜色</param>
|
||||
/// <param name="toColor">结束颜色</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user