优化LineChart折线图的区域填充渐变效果

This commit is contained in:
monitor1394
2020-04-19 23:17:35 +08:00
parent 839e1fe9d1
commit a66b8a576c
4 changed files with 27 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.04.19) 优化`LineChart`折线图的区域填充渐变效果
* (2020.04.19) 增加`AxisLabel``onZero`参数可将`Label`显示在`0`刻度上
* (2020.04.19) 增加`Serie``AxisLabel``showAsPositiveNumber`参数将负数数值显示为正数
* (2020.04.18) 增加`Covert XY Axis`互换XY轴配置

View File

@@ -1813,6 +1813,18 @@ namespace XCharts
p2 = ClampInChart(p2);
ChartDrawer.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color);
}
protected Color GetXLerpColor(Color areaColor, Color areaToColor, Vector3 pos)
{
if (areaColor == areaToColor) return areaColor;
return Color.Lerp(areaToColor, areaColor, (pos.y - coordinateY) / coordinateHeight);
}
protected Color GetYLerpColor(Color areaColor, Color areaToColor, Vector3 pos)
{
if (areaColor == areaToColor) return areaColor;
return Color.Lerp(areaToColor, areaColor, (pos.x - coordinateX) / coordinateWidth);
}
}
}

View File

@@ -243,8 +243,6 @@ namespace XCharts
break;
case LineType.Smooth:
case LineType.SmoothDash:
//llp = i > 1 ? serie.dataPoints[i - 2] : firstLastPos;
//nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : lastNextPos;
llp = GetLLPos(serie.dataPoints, i, firstLastPos);
nnp = GetNNPos(serie.dataPoints, i, lastNextPos);
isFinish = DrawSmoothLine(vh, serie, xAxis, lp, np, llp, nnp, i,
@@ -253,7 +251,6 @@ namespace XCharts
case LineType.StepStart:
case LineType.StepMiddle:
case LineType.StepEnd:
//nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
nnp = GetNNPos(serie.dataPoints, i, np);
isFinish = DrawStepLine(vh, serie, xAxis, lp, np, nnp, i, lineColor,
areaColor, areaToColor, zeroPos);
@@ -1006,6 +1003,7 @@ namespace XCharts
{
var isLessthan0 = (sp.x < zeroPos.x || ep.x < zeroPos.x);
diff = isLessthan0 ? -axis.axisLine.width : axis.axisLine.width;
areaColor = GetYLerpColor(areaColor, areaToColor, sp);
if (isLessthan0) areaDiff = -areaDiff;
CheckClipAndDrawPolygon(vh, new Vector3(zeroPos.x + diff, sp.y), new Vector3(zeroPos.x + diff, ep.y),
ep + areaDiff, sp + areaDiff, areaToColor, areaColor, clip);
@@ -1014,6 +1012,7 @@ namespace XCharts
{
var isLessthan0 = (sp.y < zeroPos.y || ep.y < zeroPos.y);
diff = isLessthan0 ? -axis.axisLine.width : axis.axisLine.width;
areaColor = GetXLerpColor(areaColor, areaToColor, sp);
if (isLessthan0) areaDiff = -areaDiff;
if (isLessthan0)
{
@@ -1118,6 +1117,7 @@ namespace XCharts
smoothPoints.Add(startUp);
smoothDownPoints.Add(startDn);
}
var sourAreaColor = areaColor;
for (int k = 1; k < bezierPoints.Count; k++)
{
to = bezierPoints[k];
@@ -1154,12 +1154,14 @@ namespace XCharts
{
tnp = new Vector3(zeroPos.x + xAxis.axisLine.width, toDn.y);
tlp = new Vector3(zeroPos.x + xAxis.axisLine.width, startDn.y);
areaColor = GetYLerpColor(sourAreaColor, areaToColor, start);
CheckClipAndDrawPolygon(vh, startDn, toDn, tnp, tlp, areaColor, areaToColor, serie.clip);
}
else if (start.x < zeroPos.x && to.x < zeroPos.x)
{
tnp = new Vector3(zeroPos.x - xAxis.axisLine.width, toUp.y);
tlp = new Vector3(zeroPos.x - xAxis.axisLine.width, startUp.y);
areaColor = GetYLerpColor(sourAreaColor, areaToColor, start);
CheckClipAndDrawPolygon(vh, tnp, tlp, startUp, toUp, areaToColor, areaColor, serie.clip);
}
}
@@ -1169,12 +1171,14 @@ namespace XCharts
{
tnp = new Vector3(toDn.x, zeroPos.y + xAxis.axisLine.width);
tlp = new Vector3(startDn.x, zeroPos.y + xAxis.axisLine.width);
areaColor = GetXLerpColor(sourAreaColor, areaToColor, start);
CheckClipAndDrawPolygon(vh, startDn, toDn, tnp, tlp, areaColor, areaToColor, serie.clip);
}
else if (start.y < zeroPos.y && to.y < zeroPos.y)
{
tnp = new Vector3(toUp.x, zeroPos.y - xAxis.axisLine.width);
tlp = new Vector3(startUp.x, zeroPos.y - xAxis.axisLine.width);
areaColor = GetXLerpColor(sourAreaColor, areaToColor, start);
CheckClipAndDrawPolygon(vh, tlp, tnp, toUp, startUp, areaToColor, areaColor, serie.clip);
}
}
@@ -1206,11 +1210,14 @@ namespace XCharts
var lastCount = 1;
start = smoothPoints[0];
var sourAreaColor = areaColor;
for (int k = 1; k < smoothPoints.Count; k++)
{
to = smoothPoints[k];
if (serie.animation.CheckDetailBreak(to, isYAxis)) break;
Vector3 tnp, tlp;
if (isYAxis) areaColor = GetYLerpColor(sourAreaColor, areaToColor, to);
else areaColor = GetXLerpColor(sourAreaColor, areaToColor, to);
if (k == smoothPoints.Count - 1)
{
if (k < lastSmoothPoints.Count - 1)

View File

@@ -346,28 +346,28 @@ namespace XCharts
if (brLt > 0)
{
roundLt = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt);
DrawSector(vh, roundLt, brLt, color, color, 270, 360);
DrawSector(vh, roundLt, brLt, color, color, 270, 360, 1);
ltIn = roundLt + brLt * Vector3.left;
ltIn2 = roundLt + brLt * Vector3.up;
}
if (brRt > 0)
{
roundRt = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt);
DrawSector(vh, roundRt, brRt, color, color, 0, 90);
DrawSector(vh, roundRt, brRt, color, color, 0, 90, 1);
rtIn = roundRt + brRt * Vector3.up;
rtIn2 = roundRt + brRt * Vector3.right;
}
if (brRb > 0)
{
roundRb = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb);
DrawSector(vh, roundRb, brRb, color, color, 90, 180);
DrawSector(vh, roundRb, brRb, color, color, 90, 180, 1);
rbIn = roundRb + brRb * Vector3.right;
rbIn2 = roundRb + brRb * Vector3.down;
}
if (brLb > 0)
{
roundLb = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb);
DrawSector(vh, roundLb, brLb, color, color, 180, 270);
DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1);
lbIn = roundLb + brLb * Vector3.left;
lbIn2 = roundLb + brLb * Vector3.down;
}