mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 10:50:08 +00:00
v3.0.0-preivew8
This commit is contained in:
@@ -10,10 +10,7 @@ namespace XCharts.Runtime
|
||||
[SerieConvert(typeof(Line), typeof(Pie))]
|
||||
[RequireChartComponent(typeof(GridCoord))]
|
||||
[DefaultAnimation(AnimationType.BottomToTop)]
|
||||
[SerieExtraComponent(
|
||||
typeof(LabelStyle),
|
||||
typeof(IconStyle),
|
||||
typeof(Emphasis))]
|
||||
[SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))]
|
||||
public class Bar : Serie, INeedSerieContainer
|
||||
{
|
||||
public int containerIndex { get; internal set; }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
@@ -14,7 +13,6 @@ namespace XCharts.Runtime
|
||||
typeof(EndLabelStyle),
|
||||
typeof(LineArrow),
|
||||
typeof(AreaStyle),
|
||||
typeof(IconStyle),
|
||||
typeof(Emphasis))]
|
||||
public class Line : Serie, INeedSerieContainer
|
||||
{
|
||||
|
||||
@@ -71,12 +71,14 @@ namespace XCharts.Runtime
|
||||
|
||||
endLabelList.Sort(delegate (ChartLabel a, ChartLabel b)
|
||||
{
|
||||
if (a == null || b == null) return 1;
|
||||
return b.transform.position.y.CompareTo(a.transform.position.y);
|
||||
});
|
||||
var lastY = float.NaN;
|
||||
for (int i = 0; i < endLabelList.Count; i++)
|
||||
{
|
||||
var label = endLabelList[i];
|
||||
if (label == null) continue;
|
||||
if (!label.isAnimationEnd) continue;
|
||||
var labelPosition = label.transform.localPosition;
|
||||
if (float.IsNaN(lastY))
|
||||
@@ -85,7 +87,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
else
|
||||
{
|
||||
var labelHeight = label.GetLabelHeight();
|
||||
var labelHeight = label.GetTextHeight();
|
||||
if (labelPosition.y + labelHeight > lastY)
|
||||
{
|
||||
label.SetPosition(new Vector3(labelPosition.x, lastY - labelHeight, labelPosition.z));
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace XCharts.Runtime
|
||||
[SerieConvert(typeof(Line), typeof(Bar))]
|
||||
[SerieHandler(typeof(PieHandler), true)]
|
||||
[DefaultAnimation(AnimationType.Clockwise)]
|
||||
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(IconStyle), typeof(Emphasis))]
|
||||
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(Emphasis))]
|
||||
public class Pie : Serie
|
||||
{
|
||||
public override bool useDataNameForColor { get { return true; } }
|
||||
|
||||
@@ -406,7 +406,8 @@ namespace XCharts.Runtime
|
||||
var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData);
|
||||
if (serieLabel != null && serieLabel.show
|
||||
&& labelLine != null && labelLine.show
|
||||
&& serieLabel.position == LabelStyle.Position.Outside)
|
||||
&& (serieLabel.position == LabelStyle.Position.Outside
|
||||
|| serieLabel.position == LabelStyle.Position.Default))
|
||||
{
|
||||
var insideRadius = serieData.context.insideRadius;
|
||||
var outSideRadius = serieData.context.outsideRadius;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace XCharts.Runtime
|
||||
|
||||
var titleStyle = serie.AddExtraComponent<TitleStyle>();
|
||||
titleStyle.show = false;
|
||||
titleStyle.textStyle.offset = new Vector2(0, 30);
|
||||
titleStyle.offset = new Vector2(0, 30);
|
||||
|
||||
var value = Random.Range(30, 90);
|
||||
var max = 100;
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace XCharts.Runtime
|
||||
{typeof(EndLabelStyle), "m_EndLabels"},
|
||||
{typeof(LineArrow), "m_LineArrows"},
|
||||
{typeof(AreaStyle), "m_AreaStyles"},
|
||||
{typeof(IconStyle), "m_IconStyles"},
|
||||
{typeof(Emphasis), "m_Emphases"},
|
||||
{typeof(TitleStyle), "m_TitleStyles"},
|
||||
};
|
||||
@@ -24,7 +23,6 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private List<EndLabelStyle> m_EndLabels = new List<EndLabelStyle>();
|
||||
[SerializeField] private List<LineArrow> m_LineArrows = new List<LineArrow>();
|
||||
[SerializeField] private List<AreaStyle> m_AreaStyles = new List<AreaStyle>();
|
||||
[SerializeField] private List<IconStyle> m_IconStyles = new List<IconStyle>();
|
||||
[SerializeField] private List<TitleStyle> m_TitleStyles = new List<TitleStyle>();
|
||||
[SerializeField] private List<Emphasis> m_Emphases = new List<Emphasis>();
|
||||
|
||||
@@ -55,11 +53,6 @@ namespace XCharts.Runtime
|
||||
public Emphasis emphasis { get { return m_Emphases.Count > 0 ? m_Emphases[0] : null; } }
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// |数据项图标样式。
|
||||
/// </summary>
|
||||
public IconStyle iconStyle { get { return m_IconStyles.Count > 0 ? m_IconStyles[0] : null; } }
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// |数据项标题样式。
|
||||
/// </summary>
|
||||
public TitleStyle titleStyle { get { return m_TitleStyles.Count > 0 ? m_TitleStyles[0] : null; } }
|
||||
|
||||
@@ -844,8 +844,6 @@ namespace XCharts.Runtime
|
||||
symbol.ClearVerticesDirty();
|
||||
lineStyle.ClearVerticesDirty();
|
||||
itemStyle.ClearVerticesDirty();
|
||||
if (iconStyle != null)
|
||||
iconStyle.ClearVerticesDirty();
|
||||
if (areaStyle != null)
|
||||
areaStyle.ClearVerticesDirty();
|
||||
if (label != null)
|
||||
@@ -864,8 +862,6 @@ namespace XCharts.Runtime
|
||||
symbol.ClearComponentDirty();
|
||||
lineStyle.ClearComponentDirty();
|
||||
itemStyle.ClearComponentDirty();
|
||||
if (iconStyle != null)
|
||||
iconStyle.ClearComponentDirty();
|
||||
if (areaStyle != null)
|
||||
areaStyle.ClearComponentDirty();
|
||||
if (label != null)
|
||||
@@ -1635,36 +1631,6 @@ namespace XCharts.Runtime
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标的尺寸
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetDataIconSize(int dataIndex, float width, float height)
|
||||
{
|
||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||
{
|
||||
var data = m_Data[dataIndex];
|
||||
data.iconStyle.width = width;
|
||||
data.iconStyle.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标的颜色
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="color"></param>
|
||||
public void SetDataIconColor(int dataIndex, Color color)
|
||||
{
|
||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||
{
|
||||
var data = m_Data[dataIndex];
|
||||
data.iconStyle.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用或取消初始动画
|
||||
/// </summary>
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private List<LabelLine> m_LabelLines = new List<LabelLine>();
|
||||
[SerializeField] private List<Emphasis> m_Emphases = new List<Emphasis>();
|
||||
[SerializeField] private List<SymbolStyle> m_Symbols = new List<SymbolStyle>();
|
||||
[SerializeField] private List<IconStyle> m_IconStyles = new List<IconStyle>();
|
||||
[SerializeField] private List<LineStyle> m_LineStyles = new List<LineStyle>();
|
||||
[SerializeField] private List<AreaStyle> m_AreaStyles = new List<AreaStyle>();
|
||||
[SerializeField] private List<TitleStyle> m_TitleStyles = new List<TitleStyle>();
|
||||
@@ -63,14 +62,9 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// |数据项图标样式。
|
||||
/// </summary>
|
||||
public IconStyle iconStyle { get { return m_IconStyles.Count > 0 ? m_IconStyles[0] : null; } }
|
||||
/// <summary>
|
||||
/// 单个数据项的标签设置。
|
||||
/// </summary>
|
||||
public LabelStyle label { get { return m_Labels.Count > 0 ? m_Labels[0] : null; } }
|
||||
public LabelStyle labelStyle { get { return m_Labels.Count > 0 ? m_Labels[0] : null; } }
|
||||
public LabelLine labelLine { get { return m_LabelLines.Count > 0 ? m_LabelLines[0] : null; } }
|
||||
/// <summary>
|
||||
/// 单个数据项的样式设置。
|
||||
@@ -127,7 +121,6 @@ namespace XCharts.Runtime
|
||||
m_PreviousData.Clear();
|
||||
m_DataUpdateTime.Clear();
|
||||
m_DataUpdateFlag.Clear();
|
||||
m_IconStyles.Clear();
|
||||
m_Labels.Clear();
|
||||
m_LabelLines.Clear();
|
||||
m_ItemStyles.Clear();
|
||||
@@ -147,12 +140,6 @@ namespace XCharts.Runtime
|
||||
m_ItemStyles.Add(new ItemStyle() { show = true });
|
||||
return m_ItemStyles[0] as T;
|
||||
}
|
||||
else if (type == typeof(IconStyle))
|
||||
{
|
||||
if (m_IconStyles.Count == 0)
|
||||
m_IconStyles.Add(new IconStyle() { show = true });
|
||||
return m_IconStyles[0] as T;
|
||||
}
|
||||
else if (type == typeof(LabelStyle))
|
||||
{
|
||||
if (m_Labels.Count == 0)
|
||||
@@ -204,7 +191,6 @@ namespace XCharts.Runtime
|
||||
public void RemoveAllComponent()
|
||||
{
|
||||
m_ItemStyles.Clear();
|
||||
m_IconStyles.Clear();
|
||||
m_Labels.Clear();
|
||||
m_LabelLines.Clear();
|
||||
m_Symbols.Clear();
|
||||
@@ -219,8 +205,6 @@ namespace XCharts.Runtime
|
||||
var type = typeof(T);
|
||||
if (type == typeof(ItemStyle))
|
||||
m_ItemStyles.Clear();
|
||||
else if (type == typeof(IconStyle))
|
||||
m_IconStyles.Clear();
|
||||
else if (type == typeof(LabelStyle))
|
||||
m_Labels.Clear();
|
||||
else if (type == typeof(LabelLine))
|
||||
@@ -415,23 +399,23 @@ namespace XCharts.Runtime
|
||||
|
||||
public float GetLabelWidth()
|
||||
{
|
||||
if (labelObject != null) return labelObject.GetLabelWidth();
|
||||
if (labelObject != null) return labelObject.GetTextWidth();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetLabelHeight()
|
||||
{
|
||||
if (labelObject != null) return labelObject.GetLabelHeight();
|
||||
if (labelObject != null) return labelObject.GetTextHeight();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void SetLabelActive(bool flag)
|
||||
{
|
||||
if (labelObject != null) labelObject.SetLabelActive(flag);
|
||||
if (labelObject != null) labelObject.SetActive(flag);
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
if (labelObject != null) labelObject.SetIconActive(flag);
|
||||
if (labelObject != null) labelObject.SetActive(flag);
|
||||
}
|
||||
|
||||
public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
|
||||
|
||||
@@ -236,32 +236,17 @@ namespace XCharts.Runtime
|
||||
return false;
|
||||
|
||||
var serieEmphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
|
||||
if (!serieLabel.show
|
||||
&& (serieEmphasisLabel == null || !serieEmphasisLabel.show)
|
||||
&& (iconStyle == null || !iconStyle.show))
|
||||
&& (serieEmphasisLabel == null || !serieEmphasisLabel.show))
|
||||
return false;
|
||||
|
||||
var dataAutoColor = (Color)chart.theme.GetColor(serieData.index);
|
||||
|
||||
var dataAutoColor = (Color)chart.theme.GetColor(serie.useDataNameForColor ? serieData.index : serie.index);
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
|
||||
var color = serieLabel.textStyle.autoColor ? dataAutoColor : chart.theme.common.textColor;
|
||||
var iconWidth = iconStyle != null ? iconStyle.width : 20;
|
||||
var iconHeight = iconStyle != null ? iconStyle.height : 20;
|
||||
var labelObj = SerieLabelPool.Get(textName, serieLabelRoot.transform, serieLabel, color,
|
||||
iconWidth, iconHeight, chart.theme);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
var item = ChartHelper.GetOrAddComponent<ChartLabel>(labelObj);
|
||||
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
item.SetIcon(iconImage);
|
||||
item.SetIconActive(iconStyle != null && iconStyle.show);
|
||||
if (serieLabel.textStyle.autoBackgroundColor)
|
||||
item.color = dataAutoColor;
|
||||
else
|
||||
item.color = serieLabel.textStyle.backgroundColor;
|
||||
serieData.labelObject = item;
|
||||
var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common,
|
||||
"", dataAutoColor, TextAnchor.MiddleCenter);
|
||||
label.SetActive(serieLabel.show);
|
||||
serieData.labelObject = label;
|
||||
|
||||
if (serieData.context.children.Count > 0)
|
||||
{
|
||||
@@ -287,30 +272,10 @@ namespace XCharts.Runtime
|
||||
}
|
||||
if (m_SerieRoot == null)
|
||||
InitRoot();
|
||||
var serieLabel = serie.endLabel;
|
||||
var textStyle = serieLabel.textStyle;
|
||||
var dataAutoColor = (Color)chart.theme.GetColor(serie.index);
|
||||
|
||||
var color = serieLabel.textStyle.autoColor ? dataAutoColor : chart.theme.common.textColor;
|
||||
|
||||
var anchorMin = new Vector2(0f, 0.5f);
|
||||
var anchorMax = new Vector2(0f, 0.5f);
|
||||
var pivot = new Vector2(0f, 0.5f);
|
||||
var sizeDelta = new Vector2(50, textStyle.GetFontSize(chart.theme.common) + 2);
|
||||
var labelObj = ChartHelper.AddObject(s_SerieEndLabelObjectName, m_SerieRoot.transform, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var txt = ChartHelper.AddTextObject("Text", labelObj.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle,
|
||||
chart.theme.common);
|
||||
txt.SetColor(color);
|
||||
txt.SetAlignment(textStyle.alignment);
|
||||
txt.SetText("Text");
|
||||
txt.SetLocalPosition(new Vector2(0, 0));
|
||||
txt.SetLocalEulerAngles(Vector3.zero);
|
||||
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
m_EndLabel = ChartHelper.GetOrAddComponent<ChartLabel>(labelObj);
|
||||
m_EndLabel.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
m_EndLabel.SetIconActive(false);
|
||||
m_EndLabel.SetActive(true);
|
||||
m_EndLabel = ChartHelper.AddChartLabel(s_SerieEndLabelObjectName, m_SerieRoot.transform, serie.endLabel,
|
||||
chart.theme.common, "", dataAutoColor, TextAnchor.MiddleLeft);
|
||||
m_EndLabel.SetActive(serie.endLabel.show);
|
||||
RefreshEndLabelInternal();
|
||||
}
|
||||
|
||||
@@ -325,28 +290,20 @@ namespace XCharts.Runtime
|
||||
ChartHelper.RemoveComponent<Text>(serieTitleRoot);
|
||||
|
||||
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
||||
var anchorMin = new Vector2(0.5f, 0.5f);
|
||||
var anchorMax = new Vector2(0.5f, 0.5f);
|
||||
var pivot = new Vector2(0.5f, 0.5f);
|
||||
var fontSize = 10;
|
||||
var sizeDelta = new Vector2(50, fontSize + 2);
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
var titleStyle = SerieHelper.GetTitleStyle(serie, serieData);
|
||||
if (titleStyle == null) continue;
|
||||
var color = chart.GetLegendRealShowNameColor(serieData.name);
|
||||
var label = ChartHelper.AddDefaultChartLabel("title_" + i, serieTitleRoot.transform, anchorMin, anchorMax,
|
||||
pivot, sizeDelta, titleStyle.textStyle, chart.theme.common, serieData.name);
|
||||
|
||||
var label = ChartHelper.AddChartLabel("title_" + i, serieTitleRoot.transform, titleStyle, chart.theme.common,
|
||||
serieData.name, color, TextAnchor.MiddleCenter);
|
||||
serieData.titleObject = label;
|
||||
label.SetActive(titleStyle.show);
|
||||
var labelPosition = GetSerieDataTitlePosition(serieData, titleStyle);
|
||||
var offset = titleStyle.GetOffset(serie.context.insideRadius);
|
||||
label.SetPosition(labelPosition + offset);
|
||||
if (titleStyle.textStyle.autoBackgroundColor)
|
||||
label.color = color;
|
||||
else
|
||||
label.color = titleStyle.textStyle.backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,10 +323,8 @@ namespace XCharts.Runtime
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var emphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData);
|
||||
var isHighlight = (serieData.context.highlight && emphasisLabel != null && emphasisLabel.show);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension);
|
||||
var currLabel = isHighlight && emphasisLabel != null ? emphasisLabel : serieLabel;
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show
|
||||
&& currLabel != null
|
||||
&& (currLabel.show || isHighlight)
|
||||
@@ -382,28 +337,28 @@ namespace XCharts.Runtime
|
||||
? ChartCached.NumberToStr(value, serieLabel.numericFormatter)
|
||||
: SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
|
||||
currLabel, chart.theme.GetColor(colorIndex));
|
||||
var isInsidePosition = currLabel.position == LabelStyle.Position.Inside;
|
||||
|
||||
//text color
|
||||
var textColor = chart.theme.common.textColor;
|
||||
if (!ChartHelper.IsClearColor(currLabel.textStyle.color))
|
||||
textColor = currLabel.textStyle.color;
|
||||
else if (isInsidePosition)
|
||||
textColor = Color.white;
|
||||
if (currLabel.textStyle.autoColor && serie.useDataNameForColor)
|
||||
textColor = chart.theme.GetColor(serieData.index);
|
||||
//text rotate
|
||||
var rotate = currLabel.textStyle.rotate;
|
||||
if (currLabel.textStyle.rotate > 0 && isInsidePosition)
|
||||
{
|
||||
var currAngle = serieData.context.halfAngle;
|
||||
if (currAngle > 0)
|
||||
{
|
||||
if (currAngle > 180) rotate += 270 - currAngle;
|
||||
else rotate += -(currAngle - 90);
|
||||
}
|
||||
}
|
||||
SerieLabelHelper.ResetLabel(serieData.labelObject.label, currLabel, chart.theme, textColor, rotate);
|
||||
// var isInsidePosition = currLabel.position == LabelStyle.Position.Inside;
|
||||
// //text color
|
||||
// var textColor = chart.theme.common.textColor;
|
||||
// if (!ChartHelper.IsClearColor(currLabel.textStyle.color))
|
||||
// textColor = currLabel.textStyle.color;
|
||||
// else if (isInsidePosition)
|
||||
// textColor = Color.white;
|
||||
// if (currLabel.textStyle.autoColor && serie.useDataNameForColor)
|
||||
// textColor = chart.theme.GetColor(serieData.index);
|
||||
// //text rotate
|
||||
// var rotate = currLabel.textStyle.rotate;
|
||||
// if (currLabel.textStyle.rotate > 0 && isInsidePosition)
|
||||
// {
|
||||
// var currAngle = serieData.context.halfAngle;
|
||||
// if (currAngle > 0)
|
||||
// {
|
||||
// if (currAngle > 180) rotate += 270 - currAngle;
|
||||
// else rotate += -(currAngle - 90);
|
||||
// }
|
||||
// }
|
||||
// SerieLabelHelper.ResetLabel(serieData.labelObject.text, currLabel, chart.theme, textColor, rotate);
|
||||
serieData.SetLabelActive(!isIgnore);
|
||||
|
||||
serieData.labelObject.SetText(content);
|
||||
|
||||
Reference in New Issue
Block a user