mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 08:50:10 +00:00
增加Serie的iconStyle统一配置图标
This commit is contained in:
@@ -540,8 +540,9 @@ namespace XCharts
|
||||
if (m_SerieLabelRoot == null) return;
|
||||
if (count == -1) count = serie.dataCount;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
if (serie.IsPerformanceMode()) return;
|
||||
if (!serieLabel.show) return;
|
||||
if (!serieLabel.show && !iconStyle.show) return;
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
@@ -555,13 +556,13 @@ namespace XCharts
|
||||
(Color)m_Theme.GetColor(serie.index);
|
||||
}
|
||||
var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, color,
|
||||
serieData.iconStyle.width, serieData.iconStyle.height, theme);
|
||||
iconStyle.width, iconStyle.height, theme);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
var item = new ChartLabel();
|
||||
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
item.SetIcon(iconImage);
|
||||
item.SetIconActive(false);
|
||||
item.SetIconActive(iconStyle.show);
|
||||
serieData.labelObject = item;
|
||||
}
|
||||
|
||||
|
||||
@@ -1471,7 +1471,7 @@ namespace XCharts
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
serieData.index = j;
|
||||
if ((serieLabel.show || serieData.iconStyle.show) && j < serie.dataPoints.Count)
|
||||
if (serieLabel.show && j < serie.dataPoints.Count)
|
||||
{
|
||||
var pos = serie.dataPoints[j];
|
||||
|
||||
@@ -1482,48 +1482,8 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, n);
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[j];
|
||||
switch (serieLabel.position)
|
||||
{
|
||||
case SerieLabel.Position.Center:
|
||||
|
||||
pos = isYAxis ? new Vector3(bottomPos.x + (pos.x - bottomPos.x) / 2, pos.y) :
|
||||
new Vector3(pos.x, bottomPos.y + (pos.y - bottomPos.y) / 2);
|
||||
break;
|
||||
case SerieLabel.Position.Bottom:
|
||||
pos = isYAxis ? new Vector3(bottomPos.x, pos.y) : new Vector3(pos.x, bottomPos.y);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Internal_RefreshLabelPosition(serie, serieData, serieLabel, pos, serie.type == SerieType.Bar, isYAxis);
|
||||
m_RefreshLabel = true;
|
||||
serieData.labelPosition = pos;
|
||||
if (serieLabel.show) DrawLabelBackground(vh, serie, serieData);
|
||||
}
|
||||
}
|
||||
@@ -1535,10 +1495,50 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void Internal_RefreshLabelPosition(Serie serie, SerieData serieData, SerieLabel serieLabel, Vector3 pos, bool IsNeedCheckPosition, bool isYAxis)
|
||||
{
|
||||
if (IsNeedCheckPosition)
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, serie.index);
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[serieData.index];
|
||||
switch (serieLabel.position)
|
||||
{
|
||||
case SerieLabel.Position.Center:
|
||||
|
||||
pos = isYAxis ? new Vector3(bottomPos.x + (pos.x - bottomPos.x) / 2, pos.y) :
|
||||
new Vector3(pos.x, bottomPos.y + (pos.y - bottomPos.y) / 2);
|
||||
break;
|
||||
case SerieLabel.Position.Bottom:
|
||||
pos = isYAxis ? new Vector3(bottomPos.x, pos.y) : new Vector3(pos.x, bottomPos.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
serieData.labelPosition = pos;
|
||||
}
|
||||
|
||||
protected override void OnRefreshLabel()
|
||||
{
|
||||
base.OnRefreshLabel();
|
||||
var isYAxis = IsAnyYAxisIsCategory();
|
||||
var anyPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
@@ -1546,7 +1546,6 @@ namespace XCharts
|
||||
if (!serie.IsCoordinateSerie()) continue;
|
||||
var total = serie.yTotal;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
@@ -1554,14 +1553,17 @@ namespace XCharts
|
||||
if (j >= serie.dataPoints.Count)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.SetIconActive(false);
|
||||
continue;
|
||||
}
|
||||
var pos = serie.dataPoints[j];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var dimension = 1;
|
||||
var isIgnore = serie.IsIgnoreIndex(j);
|
||||
Internal_RefreshLabelPosition(serie, serieData, serieLabel, pos, serie.type == SerieType.Bar, isYAxis);
|
||||
serieData.labelObject.SetPosition(serieData.labelPosition);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel && !isIgnore)
|
||||
{
|
||||
double value = 0;
|
||||
|
||||
@@ -499,9 +499,9 @@ namespace XCharts
|
||||
var currAngle = serieData.runtimePieHalfAngle;
|
||||
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
|
||||
|
||||
if (showLabel || serieData.iconStyle.show)
|
||||
if (showLabel)
|
||||
{
|
||||
serieData.SetLabelActive(showLabel);
|
||||
float rotate = 0;
|
||||
@@ -558,7 +558,7 @@ namespace XCharts
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
}
|
||||
|
||||
protected int GetPiePosIndex(Serie serie, Vector2 local)
|
||||
|
||||
@@ -88,13 +88,14 @@ namespace XCharts
|
||||
var serieData = serie.data[n];
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var labelPos = serieData.labelPosition;
|
||||
if (serieLabel.margin != 0)
|
||||
{
|
||||
labelPos += serieLabel.margin * (labelPos - center).normalized;
|
||||
}
|
||||
serieData.labelObject.SetPosition(labelPos);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel)
|
||||
{
|
||||
var value = serieData.GetCurrData(1);
|
||||
|
||||
Reference in New Issue
Block a user