mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 20:28:46 +00:00
优化PieChart文本堆叠和引线效果#85
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
* (2020.08.08) Optimize the rendering performance of `LineChart` dense data
|
* (2020.08.11) Optimize `PieChart` text stack and lead line effects#85
|
||||||
|
* (2020.08.08) Optimize `LineChart` the rendering performance of dense data
|
||||||
* (2020.07.30) Added `LineChart` to configure gradient through `VisualMap` or `ItemStyle`#78
|
* (2020.07.30) Added `LineChart` to configure gradient through `VisualMap` or `ItemStyle`#78
|
||||||
* (2020.07.25) Fixed a problem with `LineChart` emerging abnormal in animation drawing#79
|
* (2020.07.25) Fixed a problem with `LineChart` emerging abnormal in animation drawing#79
|
||||||
* (2020.07.25) Fixed a problem with gradual discoloration on `LiquidChart` at `100%`#80
|
* (2020.07.25) Fixed a problem with gradual discoloration on `LiquidChart` at `100%`#80
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
* (2020.08.08) 优化`LineChart`密集数据的绘制表现
|
* (2020.08.11) 优化`PieChart`文本堆叠和引线效果#85
|
||||||
|
* (2020.08.08) 优化`LineChart`密集数据的绘制表现效果
|
||||||
* (2020.07.30) 增加`LineChart`可通过`VisualMap`或`ItemStyle`配置渐变#78
|
* (2020.07.30) 增加`LineChart`可通过`VisualMap`或`ItemStyle`配置渐变#78
|
||||||
* (2020.07.25) 修复`LineChart`渐出动画绘制异常的问题#79
|
* (2020.07.25) 修复`LineChart`渐出动画绘制异常的问题#79
|
||||||
* (2020.07.25) 修复`LiquidChart`在`100%`时渐变色会失效的问题#80
|
* (2020.07.25) 修复`LiquidChart`在`100%`时渐变色会失效的问题#80
|
||||||
|
|||||||
@@ -744,7 +744,11 @@ namespace XCharts
|
|||||||
&& serie.type == SerieType.Line
|
&& serie.type == SerieType.Line
|
||||||
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
||||||
&& !serie.areaStyle.show;
|
&& !serie.areaStyle.show;
|
||||||
var centerPos = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
|
var centerPos = Vector3.zero;
|
||||||
|
if (serie.type == SerieType.Pie)
|
||||||
|
centerPos = SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel);
|
||||||
|
else
|
||||||
|
centerPos = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
|
||||||
var labelHalfWid = serieData.labelObject.GetLabelWidth() / 2;
|
var labelHalfWid = serieData.labelObject.GetLabelWidth() / 2;
|
||||||
var labelHalfHig = serieData.GetLabelHeight() / 2;
|
var labelHalfHig = serieData.GetLabelHeight() / 2;
|
||||||
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
|
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
|
||||||
@@ -767,6 +771,7 @@ namespace XCharts
|
|||||||
ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
|
ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
|
||||||
serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
|
serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
|
||||||
}
|
}
|
||||||
|
ChartDrawer.DrawPolygon(vh, serieData.labelPosition, 0.3f, Color.red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,7 +258,6 @@ namespace XCharts
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (splitCount <= 0) return;
|
|
||||||
for (int n = 0; n < splitCount; n++)
|
for (int n = 0; n < splitCount; n++)
|
||||||
{
|
{
|
||||||
var serieData = data[n];
|
var serieData = data[n];
|
||||||
|
|||||||
@@ -49,6 +49,38 @@ namespace XCharts
|
|||||||
vh.AddUIVertexQuad(vertex);
|
vh.AddUIVertexQuad(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DrawLine(VertexHelper vh, Vector3 start, Vector3 middle, Vector3 end, float size, Color32 color)
|
||||||
|
{
|
||||||
|
var dir1 = (middle - start).normalized;
|
||||||
|
var dir2 = (end - middle).normalized;
|
||||||
|
var dir1v = Vector3.Cross(dir1, Vector3.forward).normalized;
|
||||||
|
var dir2v = Vector3.Cross(dir2, Vector3.forward).normalized;
|
||||||
|
var dir3 = (dir1 + dir2).normalized;
|
||||||
|
var isDown = Vector3.Cross(dir1, dir2).z <= 0;
|
||||||
|
var angle = (180 - Vector3.Angle(dir1, dir2)) * Mathf.Deg2Rad / 2;
|
||||||
|
var diff = size / Mathf.Sin(angle);
|
||||||
|
var dirDp = Vector3.Cross(dir3, Vector3.forward).normalized;
|
||||||
|
var dnPos = middle + (isDown ? dirDp : -dirDp) * diff;
|
||||||
|
var upPos1 = middle + (isDown ? -dir1v : dir1v) * size;
|
||||||
|
var upPos2 = middle + (isDown ? -dir2v : dir2v) * size;
|
||||||
|
var startUp = start - dir1v * size;
|
||||||
|
var startDn = start + dir1v * size;
|
||||||
|
var endUp = end - dir2v * size;
|
||||||
|
var endDn = end + dir2v * size;
|
||||||
|
if (isDown)
|
||||||
|
{
|
||||||
|
DrawPolygon(vh, startDn, startUp, upPos1, dnPos, color);
|
||||||
|
DrawPolygon(vh, dnPos, upPos2, endUp, endDn, color);
|
||||||
|
DrawTriangle(vh, dnPos, upPos1, upPos2, color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawPolygon(vh, startDn, startUp, dnPos, upPos1, color);
|
||||||
|
DrawPolygon(vh, upPos2, dnPos, endUp, endDn, color);
|
||||||
|
DrawTriangle(vh, dnPos, upPos1, upPos2, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void DrawDashLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color,
|
public static void DrawDashLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color,
|
||||||
float dashLen = 15f, float blankLen = 7f, List<Vector3> posList = null)
|
float dashLen = 15f, float blankLen = 7f, List<Vector3> posList = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ namespace XCharts
|
|||||||
int serieNameCount = -1;
|
int serieNameCount = -1;
|
||||||
bool isClickOffset = false;
|
bool isClickOffset = false;
|
||||||
bool isDataHighlight = false;
|
bool isDataHighlight = false;
|
||||||
|
|
||||||
|
DrawLabelLine(vh);
|
||||||
for (int i = 0; i < m_Series.Count; i++)
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
{
|
{
|
||||||
var serie = m_Series.list[i];
|
var serie = m_Series.list[i];
|
||||||
@@ -185,7 +187,6 @@ namespace XCharts
|
|||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawLabelLine(vh);
|
|
||||||
DrawLabelBackground(vh);
|
DrawLabelBackground(vh);
|
||||||
raycastTarget = isClickOffset && isDataHighlight;
|
raycastTarget = isClickOffset && isDataHighlight;
|
||||||
}
|
}
|
||||||
@@ -222,6 +223,7 @@ namespace XCharts
|
|||||||
foreach (var serie in m_Series.list)
|
foreach (var serie in m_Series.list)
|
||||||
{
|
{
|
||||||
if (serie.type != SerieType.Pie) continue;
|
if (serie.type != SerieType.Pie) continue;
|
||||||
|
if (serie.avoidLabelOverlap) continue;
|
||||||
foreach (var serieData in serie.data)
|
foreach (var serieData in serie.data)
|
||||||
{
|
{
|
||||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||||
@@ -263,14 +265,13 @@ namespace XCharts
|
|||||||
pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
|
pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
|
||||||
}
|
}
|
||||||
float tx, ty;
|
float tx, ty;
|
||||||
Vector3 pos3, pos4, pos6;
|
Vector3 pos4, pos6;
|
||||||
var horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
|
var horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
|
||||||
var lineCircleDiff = horizontalLineCircleRadius - 0.3f;
|
var lineCircleDiff = horizontalLineCircleRadius - 0.3f;
|
||||||
if (currAngle < 90)
|
if (currAngle < 90)
|
||||||
{
|
{
|
||||||
ty = serieLabel.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
|
ty = serieLabel.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
|
||||||
tx = serieLabel.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
|
tx = serieLabel.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
|
||||||
pos3 = new Vector3(pos2.x - tx, pos2.y + ty - serieLabel.lineWidth);
|
|
||||||
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
||||||
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
||||||
pos6 = pos0 + Vector3.right * lineCircleDiff;
|
pos6 = pos0 + Vector3.right * lineCircleDiff;
|
||||||
@@ -280,7 +281,6 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
ty = serieLabel.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
|
ty = serieLabel.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
|
||||||
tx = serieLabel.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
|
tx = serieLabel.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
|
||||||
pos3 = new Vector3(pos2.x - tx, pos2.y - ty + serieLabel.lineWidth);
|
|
||||||
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
||||||
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
||||||
pos6 = pos0 + Vector3.right * lineCircleDiff;
|
pos6 = pos0 + Vector3.right * lineCircleDiff;
|
||||||
@@ -292,7 +292,6 @@ namespace XCharts
|
|||||||
tx = serieLabel.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
|
tx = serieLabel.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
|
||||||
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
||||||
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
||||||
pos3 = new Vector3(pos2.x + tx, pos2.y - ty + serieLabel.lineWidth);
|
|
||||||
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
|
||||||
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
||||||
pos6 = pos0 + Vector3.left * lineCircleDiff;
|
pos6 = pos0 + Vector3.left * lineCircleDiff;
|
||||||
@@ -302,7 +301,6 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
ty = serieLabel.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
|
ty = serieLabel.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
|
||||||
tx = serieLabel.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
|
tx = serieLabel.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
|
||||||
pos3 = new Vector3(pos2.x + tx, pos2.y + ty - serieLabel.lineWidth);
|
|
||||||
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
||||||
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
||||||
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
|
||||||
@@ -310,12 +308,11 @@ namespace XCharts
|
|||||||
pos6 = pos0 + Vector3.left * lineCircleDiff;
|
pos6 = pos0 + Vector3.left * lineCircleDiff;
|
||||||
pos4 = pos6 + Vector3.left * r4;
|
pos4 = pos6 + Vector3.left * r4;
|
||||||
}
|
}
|
||||||
var pos5 = new Vector3(currAngle > 180 ? pos3.x - serieLabel.lineLength2 : pos3.x + serieLabel.lineLength2, pos3.y);
|
var pos5 = new Vector3(currAngle > 180 ? pos2.x - serieLabel.lineLength2 : pos2.x + serieLabel.lineLength2, pos2.y);
|
||||||
switch (serieLabel.lineType)
|
switch (serieLabel.lineType)
|
||||||
{
|
{
|
||||||
case SerieLabel.LineType.BrokenLine:
|
case SerieLabel.LineType.BrokenLine:
|
||||||
ChartDrawer.DrawLine(vh, pos1, pos2, serieLabel.lineWidth, color);
|
ChartDrawer.DrawLine(vh, pos1, pos2, pos5, serieLabel.lineWidth, color);
|
||||||
ChartDrawer.DrawLine(vh, pos3, pos5, serieLabel.lineWidth, color);
|
|
||||||
break;
|
break;
|
||||||
case SerieLabel.LineType.Curves:
|
case SerieLabel.LineType.Curves:
|
||||||
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, m_Settings.lineSmoothness);
|
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, m_Settings.lineSmoothness);
|
||||||
|
|||||||
Reference in New Issue
Block a user