修复LineChart有数据为0时区域图绘制可能异常的问题

This commit is contained in:
monitor1394
2019-09-16 19:18:36 +08:00
parent f1d7041108
commit 1427e79c3d

View File

@@ -525,24 +525,19 @@ namespace XCharts
var points = ((isYAxis && lp.x < zeroPos.x) || (!isYAxis && lp.y < zeroPos.y)) ? smoothPoints : smoothDownPoints; var points = ((isYAxis && lp.x < zeroPos.x) || (!isYAxis && lp.y < zeroPos.y)) ? smoothPoints : smoothDownPoints;
Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + coordinateHig) : new Vector3(zeroPos.x + coordinateWid, zeroPos.y); Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + coordinateHig) : new Vector3(zeroPos.x + coordinateWid, zeroPos.y);
var cross = ChartHelper.GetIntersection(points[0], points[points.Count - 1], zeroPos, aep); var cross = ChartHelper.GetIntersection(points[0], points[points.Count - 1], zeroPos, aep);
var isZeroValue = (isYAxis && cross.x == zeroPos.x) || (!isYAxis && cross.y == zeroPos.y); if (cross == Vector3.zero || smoothDownPoints.Count <= 3)
if (cross == Vector3.zero || isZeroValue)
{ {
Vector3 sp = points[0]; Vector3 sp = points[0];
Vector3 ep; Vector3 ep;
for (int i = 1; i < points.Count; i++) for (int i = 1; i < points.Count; i++)
{ {
ep = points[i]; ep = points[i];
if(isZeroValue && i == 1){
sp = ep;
continue;
}
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break; if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero); DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep; sp = ep;
} }
} }
else if (smoothDownPoints.Count > 3) else
{ {
var sp1 = smoothDownPoints[1]; var sp1 = smoothDownPoints[1];
var ep1 = smoothDownPoints[smoothDownPoints.Count - 2]; var ep1 = smoothDownPoints[smoothDownPoints.Count - 2];
@@ -554,99 +549,114 @@ namespace XCharts
var ldPos = ChartHelper.GetIntersection(sp1, ep1, axisDownStart, axisDownEnd); var ldPos = ChartHelper.GetIntersection(sp1, ep1, axisDownStart, axisDownEnd);
sp1 = smoothPoints[1]; sp1 = smoothPoints[1];
ep1 = smoothPoints[smoothPoints.Count - 2]; ep1 = smoothPoints[smoothPoints.Count - 2];
var ruPos = ChartHelper.GetIntersection(sp1, ep1, axisUpStart, axisUpEnd); var ruPos = ChartHelper.GetIntersection(sp1, ep1, axisUpStart, axisUpEnd);
var rdPos = ChartHelper.GetIntersection(sp1, ep1, axisDownStart, axisDownEnd); var rdPos = ChartHelper.GetIntersection(sp1, ep1, axisDownStart, axisDownEnd);
Vector3 sp, ep; Vector3 sp, ep;
if ((isYAxis && lp.x >= zeroPos.x) || (!isYAxis && lp.y >= zeroPos.y)) if (luPos == Vector3.zero || ldPos == Vector3.zero || ruPos == Vector3.zero || rdPos == Vector3.zero)
{ {
sp = smoothDownPoints[0]; sp = points[0];
for (int i = 1; i < smoothDownPoints.Count; i++) for (int i = 1; i < points.Count; i++)
{ {
ep = smoothDownPoints[i]; ep = points[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break; if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
if (luPos == Vector3.zero)
{
sp = ep;
continue;
}
if ((isYAxis && ep.y > luPos.y) || (!isYAxis && ep.x > luPos.x))
{
var tp = isYAxis ? new Vector3(luPos.x, sp.y) : new Vector3(sp.x, luPos.y);
ChartHelper.DrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor);
break;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep;
}
sp = smoothPoints[0];
bool first = false;
for (int i = 1; i < smoothPoints.Count; i++)
{
ep = smoothPoints[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
if ((isYAxis && ep.y <= rdPos.y) || (!isYAxis && ep.x <= rdPos.x)) continue;
if (rdPos == Vector3.zero)
{
sp = ep;
continue;
}
if (!first)
{
first = true;
var tp = isYAxis ? new Vector3(rdPos.x, ep.y) : new Vector3(ep.x, rdPos.y);
ChartHelper.DrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor);
sp = ep;
continue;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero); DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep; sp = ep;
} }
} }
else else
{ {
sp = smoothPoints[0]; if ((isYAxis && lp.x >= zeroPos.x) || (!isYAxis && lp.y >= zeroPos.y))
for (int i = 1; i < smoothPoints.Count; i++)
{ {
ep = smoothPoints[i]; sp = smoothDownPoints[0];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break; for (int i = 1; i < smoothDownPoints.Count; i++)
if (rdPos == Vector3.zero)
{ {
sp = ep; ep = smoothDownPoints[i];
continue; if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
} if (luPos == Vector3.zero)
{
sp = ep;
continue;
}
if ((isYAxis && ep.y > rdPos.y) || (!isYAxis && ep.x > rdPos.x)) if ((isYAxis && ep.y > luPos.y) || (!isYAxis && ep.x > luPos.x))
{ {
var tp = isYAxis ? new Vector3(rdPos.x, sp.y) : new Vector3(sp.x, rdPos.y); var tp = isYAxis ? new Vector3(luPos.x, sp.y) : new Vector3(sp.x, luPos.y);
ChartHelper.DrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor); ChartHelper.DrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor);
break; break;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep;
}
sp = smoothPoints[0];
bool first = false;
for (int i = 1; i < smoothPoints.Count; i++)
{
ep = smoothPoints[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
if ((isYAxis && ep.y <= rdPos.y) || (!isYAxis && ep.x <= rdPos.x)) continue;
if (rdPos == Vector3.zero)
{
sp = ep;
continue;
}
if (!first)
{
first = true;
var tp = isYAxis ? new Vector3(rdPos.x, ep.y) : new Vector3(ep.x, rdPos.y);
ChartHelper.DrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor);
sp = ep;
continue;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep;
} }
if (rdPos != Vector3.zero) DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep;
} }
sp = smoothDownPoints[0]; else
bool first = false;
for (int i = 1; i < smoothDownPoints.Count; i++)
{ {
ep = smoothDownPoints[i]; sp = smoothPoints[0];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break; for (int i = 1; i < smoothPoints.Count; i++)
if ((isYAxis && ep.y < luPos.y) || (!isYAxis && ep.x < luPos.x)) continue;
if (luPos == Vector3.zero)
{ {
ep = smoothPoints[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
if (rdPos == Vector3.zero)
{
sp = ep;
continue;
}
if ((isYAxis && ep.y > rdPos.y) || (!isYAxis && ep.x > rdPos.x))
{
var tp = isYAxis ? new Vector3(rdPos.x, sp.y) : new Vector3(sp.x, rdPos.y);
ChartHelper.DrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor);
break;
}
if (rdPos != Vector3.zero) DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep; sp = ep;
continue;
} }
if (!first) sp = smoothDownPoints[0];
bool first = false;
for (int i = 1; i < smoothDownPoints.Count; i++)
{ {
first = true; ep = smoothDownPoints[i];
var tp = isYAxis ? new Vector3(luPos.x, ep.y) : new Vector3(ep.x, luPos.y); if (serie.animation.CheckDetailBreak(ep, isYAxis)) break;
ChartHelper.DrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor); if ((isYAxis && ep.y < luPos.y) || (!isYAxis && ep.x < luPos.x)) continue;
if (luPos == Vector3.zero)
{
sp = ep;
continue;
}
if (!first)
{
first = true;
var tp = isYAxis ? new Vector3(luPos.x, ep.y) : new Vector3(ep.x, luPos.y);
ChartHelper.DrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor);
sp = ep;
continue;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep; sp = ep;
continue;
} }
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
sp = ep;
} }
} }
} }