mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
修复PieChart的avoidLabelOverlap参数不生效的问题
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.07.05) Fixed `Piechart` `avoidLabelOverlap` parameter not working
|
||||
* (2021.07.04) Fixed incorrect mouse area indication after `PieChart` selected sector
|
||||
* (2021.07.04) Optimize when the `Label` of `PieChart` is `Inside`, the offset can be adjusted by the parameter `Margin`
|
||||
* (2021.07.01) Added `DataZoom` arguments to `supportInsideScroll` and `supportInsideDrag` to set whether scrolling and dragging are supported in the coordinate system
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.07.05) 修复`PieChart`的`avoidLabelOverlap`参数不生效的问题
|
||||
* (2021.07.04) 修复`PieChart`选中扇区后鼠标区域指示不准确的问题
|
||||
* (2021.07.04) 优化`PieChart`的`Label`为`Inside`时可通过参数`Margin`调节偏移
|
||||
* (2021.07.01) 增加`DataZoom`的`supportInsideScroll`和`supportInsideDrag`参数设置坐标系内是否支持滚动和拖拽
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static void AvoidLabelOverlap(Serie serie)
|
||||
public static void AvoidLabelOverlap(Serie serie, ComponentTheme theme)
|
||||
{
|
||||
if (!serie.avoidLabelOverlap) return;
|
||||
var lastCheckPos = Vector3.zero;
|
||||
@@ -253,18 +253,17 @@ namespace XCharts
|
||||
}
|
||||
for (int n = 0; n < splitCount; n++)
|
||||
{
|
||||
var serieData = data[n];
|
||||
CheckSerieDataLabel(serie, serieData, false, ref lastCheckPos);
|
||||
CheckSerieDataLabel(serie, data[n], false, theme, ref lastCheckPos);
|
||||
}
|
||||
lastCheckPos = Vector3.zero;
|
||||
for (int n = data.Count - 1; n >= splitCount; n--)
|
||||
{
|
||||
var serieData = data[n];
|
||||
CheckSerieDataLabel(serie, serieData, true, ref lastCheckPos);
|
||||
CheckSerieDataLabel(serie, data[n], true, theme, ref lastCheckPos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ref Vector3 lastCheckPos)
|
||||
private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ComponentTheme theme,
|
||||
ref Vector3 lastCheckPos)
|
||||
{
|
||||
if (!serieData.canShowLabel)
|
||||
{
|
||||
@@ -273,6 +272,7 @@ namespace XCharts
|
||||
}
|
||||
if (!serieData.show) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var fontSize = serieLabel.textStyle.GetFontSize(theme);
|
||||
if (!serieLabel.show) return;
|
||||
if (serieLabel.position != SerieLabel.Position.Outside) return;
|
||||
if (lastCheckPos == Vector3.zero)
|
||||
@@ -281,11 +281,10 @@ namespace XCharts
|
||||
}
|
||||
else if (serieData.labelPosition.x != 0)
|
||||
{
|
||||
float hig = serieLabel.textStyle.fontSize;
|
||||
if (lastCheckPos.y - serieData.labelPosition.y < hig)
|
||||
if (lastCheckPos.y - serieData.labelPosition.y < fontSize)
|
||||
{
|
||||
var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
||||
var y1 = lastCheckPos.y - hig;
|
||||
var y1 = lastCheckPos.y - fontSize;
|
||||
var cy = serie.runtimeCenterPos.y;
|
||||
var diff = Mathf.Abs(y1 - cy);
|
||||
var diffX = labelRadius * labelRadius - diff * diff;
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace XCharts
|
||||
startDegree = serieData.runtimePieToAngle;
|
||||
SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
|
||||
}
|
||||
SerieLabelHelper.AvoidLabelOverlap(serie);
|
||||
SerieLabelHelper.AvoidLabelOverlap(serie, chart.theme.common);
|
||||
}
|
||||
|
||||
private float GetTotalAngle(Serie serie, float dataTotal, ref float totalAngle)
|
||||
@@ -566,6 +566,8 @@ namespace XCharts
|
||||
{
|
||||
if (serie.type != SerieType.Pie) return -1;
|
||||
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
|
||||
var maxRadius = serie.runtimeOutsideRadius + 3 * chart.theme.serie.pieSelectedOffset;
|
||||
if (dist < serie.runtimeInsideRadius || dist > maxRadius) return -1;
|
||||
Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y);
|
||||
float angle = ChartHelper.GetAngle360(Vector2.up, dir);
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace XCharts
|
||||
chartText.text.raycastTarget = false;
|
||||
#endif
|
||||
chartText.SetColor(textStyle.GetColor(theme.textColor));
|
||||
chartText.SetFontSize(textStyle.fontSize > 0 ? textStyle.fontSize : theme.fontSize);
|
||||
chartText.SetFontSize(textStyle.GetFontSize(theme));
|
||||
chartText.SetText("Text");
|
||||
chartText.SetLineSpacing(textStyle.lineSpacing);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user