mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 08:50:10 +00:00
优化性能,优化折线图和柱状图的大数据绘制,重构代码
This commit is contained in:
@@ -271,6 +271,8 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Ignore = false;
|
||||
[SerializeField] private float m_IgnoreValue = 0;
|
||||
[SerializeField] private bool m_ShowAsPositiveNumber = false;
|
||||
[SerializeField] private bool m_Large = true;
|
||||
[SerializeField] private int m_LargeThreshold = 200;
|
||||
[SerializeField] private RadarType m_RadarType = RadarType.Multiple;
|
||||
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
@@ -753,6 +755,38 @@ namespace XCharts
|
||||
set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否开启大数据量优化,在数据图形特别多而出现卡顿时候可以开启。
|
||||
/// 开启后配合 largeThreshold 在数据量大于指定阈值的时候对绘制进行优化。
|
||||
/// 缺点:优化后不能自定义设置单个数据项的样式,不能显示Label。
|
||||
/// </summary>
|
||||
public bool large
|
||||
{
|
||||
get { return m_Large; }
|
||||
set
|
||||
{
|
||||
if (PropertyUtility.SetStruct(ref m_Large, value))
|
||||
{
|
||||
SetAllDirty();
|
||||
label.SetComponentDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 开启大数量优化的阈值。
|
||||
/// </summary>
|
||||
public int largeThreshold
|
||||
{
|
||||
get { return m_LargeThreshold; }
|
||||
set
|
||||
{
|
||||
if (PropertyUtility.SetStruct(ref m_LargeThreshold, value))
|
||||
{
|
||||
SetAllDirty();
|
||||
label.SetComponentDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
|
||||
/// </summary>
|
||||
public List<SerieData> data { get { return m_Data; } }
|
||||
@@ -869,7 +903,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<Vector3>(size);
|
||||
var list = ListPool<Vector3>.Get();
|
||||
m_UpSmoothPoints[dataIndex] = list;
|
||||
return list;
|
||||
}
|
||||
@@ -883,7 +917,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<Vector3>(size);
|
||||
var list = ListPool<Vector3>.Get();
|
||||
m_DownSmoothPoints[dataIndex] = list;
|
||||
return list;
|
||||
}
|
||||
@@ -1016,9 +1050,9 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void ClearData()
|
||||
{
|
||||
foreach (var serieData in m_Data)
|
||||
while (m_Data.Count > 0)
|
||||
{
|
||||
SerieDataPool.Release(serieData);
|
||||
RemoveData(0);
|
||||
}
|
||||
m_Data.Clear();
|
||||
SetVerticesDirty();
|
||||
@@ -1037,6 +1071,22 @@ namespace XCharts
|
||||
SetNameDirty();
|
||||
}
|
||||
SetVerticesDirty();
|
||||
var serieData = m_Data[index];
|
||||
SerieDataPool.Release(serieData);
|
||||
if (serieData.labelObject != null)
|
||||
{
|
||||
SerieLabelPool.Release(serieData.labelObject.gameObject);
|
||||
}
|
||||
if (m_UpSmoothPoints.ContainsKey(serieData.index))
|
||||
{
|
||||
ListPool<Vector3>.Release(m_UpSmoothPoints[serieData.index]);
|
||||
m_UpSmoothPoints.Remove(serieData.index);
|
||||
}
|
||||
if (m_DownSmoothPoints.ContainsKey(serieData.index))
|
||||
{
|
||||
ListPool<Vector3>.Release(m_DownSmoothPoints[serieData.index]);
|
||||
m_DownSmoothPoints.Remove(serieData.index);
|
||||
}
|
||||
m_Data.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
@@ -1048,15 +1098,7 @@ namespace XCharts
|
||||
/// <param name="dataName"></param>
|
||||
public SerieData AddYData(float value, string dataName = null)
|
||||
{
|
||||
if (m_MaxCache > 0)
|
||||
{
|
||||
while (m_Data.Count > m_MaxCache)
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
SerieDataPool.Release(m_Data[0]);
|
||||
m_Data.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
CheckMaxCache();
|
||||
int xValue = m_Data.Count;
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.data.Add(xValue);
|
||||
@@ -1146,8 +1188,7 @@ namespace XCharts
|
||||
while (m_Data.Count > m_MaxCache)
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
SerieDataPool.Release(m_Data[0]);
|
||||
m_Data.RemoveAt(0);
|
||||
RemoveData(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1431,9 +1472,9 @@ namespace XCharts
|
||||
var serieData = m_Data[index];
|
||||
serieData.name = name;
|
||||
SetNameDirty();
|
||||
if (serieData.labelText != null)
|
||||
if (serieData.labelObject != null)
|
||||
{
|
||||
serieData.labelText.text = name == null ? "" : name;
|
||||
serieData.labelObject.SetText(name == null ? "" : name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1572,7 +1613,16 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否为性能模式。只有折线图和柱状图才有性能模式。性能模式下不绘制Symbol,不刷新Label,不单独设置数据项配置。
|
||||
/// </summary>
|
||||
public bool IsPerformanceMode()
|
||||
{
|
||||
if (m_Type == SerieType.Line || m_Type == SerieType.Bar)
|
||||
return m_Large && m_Data.Count > m_LargeThreshold;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标的尺寸
|
||||
|
||||
@@ -120,6 +120,12 @@ namespace XCharts
|
||||
SetLabelDirty();
|
||||
}
|
||||
|
||||
public override void ClearDirty()
|
||||
{
|
||||
base.ClearDirty();
|
||||
ClearLabelDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有系列的数据
|
||||
/// </summary>
|
||||
@@ -242,7 +248,9 @@ namespace XCharts
|
||||
{
|
||||
if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack))
|
||||
{
|
||||
if (serie.areaStyle.color != serie.areaStyle.toColor && serie.areaStyle.toColor != Color.clear) return true;
|
||||
if (serie.areaStyle.color != serie.areaStyle.toColor
|
||||
&& !ChartHelper.IsClearColor(serie.areaStyle.toColor))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 backgroundColor
|
||||
{
|
||||
get { return m_CustomBackgroundColor != Color.clear ? m_CustomBackgroundColor : m_BackgroundColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomBackgroundColor) ? m_CustomBackgroundColor : m_BackgroundColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomBackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -116,7 +116,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 titleTextColor
|
||||
{
|
||||
get { return m_CustomTitleTextColor != Color.clear ? m_CustomTitleTextColor : m_TitleTextColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTitleTextColor) ? m_CustomTitleTextColor : m_TitleTextColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTitleTextColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -125,7 +125,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 titleSubTextColor
|
||||
{
|
||||
get { return m_CustomTitleSubTextColor != Color.clear ? m_CustomTitleSubTextColor : m_TitleSubTextColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTitleSubTextColor) ? m_CustomTitleSubTextColor : m_TitleSubTextColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTitleSubTextColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -134,7 +134,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 legendTextColor
|
||||
{
|
||||
get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomLegendTextColor) ? m_CustomLegendTextColor : m_LegendTextColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomLegendTextColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -143,7 +143,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 legendUnableColor
|
||||
{
|
||||
get { return m_CustomLegendUnableColor != Color.clear ? m_CustomLegendUnableColor : m_LegendUnableColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomLegendUnableColor) ? m_CustomLegendUnableColor : m_LegendUnableColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomLegendUnableColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -152,7 +152,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 axisTextColor
|
||||
{
|
||||
get { return m_CustomAxisTextColor != Color.clear ? m_CustomAxisTextColor : m_AxisTextColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomAxisTextColor) ? m_CustomAxisTextColor : m_AxisTextColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomAxisTextColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -161,7 +161,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 axisLineColor
|
||||
{
|
||||
get { return m_CustomAxisLineColor != Color.clear ? m_CustomAxisLineColor : m_AxisLineColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomAxisLineColor) ? m_CustomAxisLineColor : m_AxisLineColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomAxisLineColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -170,7 +170,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 axisSplitLineColor
|
||||
{
|
||||
get { return m_CustomAxisSplitLineColor != Color.clear ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomAxisSplitLineColor) ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomAxisSplitLineColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -179,7 +179,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 tooltipBackgroundColor
|
||||
{
|
||||
get { return m_CustomTooltipBackgroundColor != Color.clear ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTooltipBackgroundColor) ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTooltipBackgroundColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -188,7 +188,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 tooltipFlagAreaColor
|
||||
{
|
||||
get { return m_CustomTooltipFlagAreaColor != Color.clear ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTooltipFlagAreaColor) ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTooltipFlagAreaColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -197,7 +197,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 tooltipTextColor
|
||||
{
|
||||
get { return m_CustomTooltipTextColor != Color.clear ? m_CustomTooltipTextColor : m_TooltipTextColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTooltipTextColor) ? m_CustomTooltipTextColor : m_TooltipTextColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTooltipTextColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -206,7 +206,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 tooltipLabelColor
|
||||
{
|
||||
get { return m_CustomTooltipLabelColor != Color.clear ? m_CustomTooltipLabelColor : m_TooltipLabelColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTooltipLabelColor) ? m_CustomTooltipLabelColor : m_TooltipLabelColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTooltipLabelColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -215,7 +215,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 tooltipLineColor
|
||||
{
|
||||
get { return m_CustomTooltipLineColor != Color.clear ? m_CustomTooltipLineColor : m_TooltipLineColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomTooltipLineColor) ? m_CustomTooltipLineColor : m_TooltipLineColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomTooltipLineColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -224,7 +224,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 dataZoomTextColor
|
||||
{
|
||||
get { return m_CustomDataZoomTextColor != Color.clear ? m_CustomDataZoomTextColor : m_DataZoomTextColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomDataZoomTextColor) ? m_CustomDataZoomTextColor : m_DataZoomTextColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomDataZoomTextColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -233,7 +233,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 dataZoomLineColor
|
||||
{
|
||||
get { return m_CustomDataZoomLineColor != Color.clear ? m_CustomDataZoomLineColor : m_DataZoomLineColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomDataZoomLineColor) ? m_CustomDataZoomLineColor : m_DataZoomLineColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomDataZoomLineColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
@@ -242,7 +242,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 dataZoomSelectedColor
|
||||
{
|
||||
get { return m_CustomDataZoomSelectedColor != Color.clear ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomDataZoomSelectedColor) ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomDataZoomSelectedColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 visualMapBackgroundColor
|
||||
{
|
||||
get { return m_CustomVisualMapBackgroundColor != Color.clear ? m_CustomVisualMapBackgroundColor : m_VisualMapBackgroundColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomVisualMapBackgroundColor) ? m_CustomVisualMapBackgroundColor : m_VisualMapBackgroundColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomVisualMapBackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 visualMapBorderColor
|
||||
{
|
||||
get { return m_CustomVisualMapBorderColor != Color.clear ? m_CustomVisualMapBorderColor : m_VisualMapBorderColor; }
|
||||
get { return !ChartHelper.IsClearColor(m_CustomVisualMapBorderColor) ? m_CustomVisualMapBorderColor : m_VisualMapBorderColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_CustomVisualMapBorderColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
@@ -282,7 +282,8 @@ namespace XCharts
|
||||
if (m_CustomColorPalette.Count > 0)
|
||||
{
|
||||
var customIndex = index < m_CustomColorPalette.Count ? index : index % m_CustomColorPalette.Count;
|
||||
if (customIndex < m_CustomColorPalette.Count && m_CustomColorPalette[customIndex] != Color.clear)
|
||||
if (customIndex < m_CustomColorPalette.Count
|
||||
&& !ChartHelper.IsClearColor(m_CustomColorPalette[customIndex]))
|
||||
{
|
||||
return m_CustomColorPalette[customIndex];
|
||||
}
|
||||
@@ -305,12 +306,12 @@ namespace XCharts
|
||||
}
|
||||
for (int i = 0; i < m_ColorPalette.Length; i++)
|
||||
{
|
||||
if (m_ColorPalette[i] != Color.clear && m_ColorPalette[i].a == 0)
|
||||
if (!ChartHelper.IsClearColor(m_ColorPalette[i]) && m_ColorPalette[i].a == 0)
|
||||
sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i);
|
||||
}
|
||||
for (int i = 0; i < m_CustomColorPalette.Count; i++)
|
||||
{
|
||||
if (m_CustomColorPalette[i] != Color.clear && m_CustomColorPalette[i].a == 0)
|
||||
if (!ChartHelper.IsClearColor(m_CustomColorPalette[i]) && m_CustomColorPalette[i].a == 0)
|
||||
sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace XCharts
|
||||
|
||||
internal Color GetColor(ThemeInfo theme)
|
||||
{
|
||||
if (lineStyle.color != Color.clear)
|
||||
if (!ChartHelper.IsClearColor(lineStyle.color))
|
||||
{
|
||||
var color = lineStyle.color;
|
||||
color.a *= lineStyle.opacity;
|
||||
|
||||
@@ -177,14 +177,14 @@ namespace XCharts
|
||||
|
||||
internal Color GetAxisLineColor(ThemeInfo theme, int index)
|
||||
{
|
||||
var color = axisLine.barColor != Color.clear ? axisLine.barColor : (Color)theme.GetColor(index);
|
||||
var color = !ChartHelper.IsClearColor(axisLine.barColor) ? axisLine.barColor : (Color)theme.GetColor(index);
|
||||
color.a *= axisLine.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
internal Color GetAxisLineBackgroundColor(ThemeInfo theme, int index)
|
||||
{
|
||||
var color = axisLine.barBackgroundColor != Color.clear ? axisLine.barBackgroundColor : Color.grey;
|
||||
var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor) ? axisLine.barBackgroundColor : Color.grey;
|
||||
color.a *= axisLine.opacity;
|
||||
return color;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ namespace XCharts
|
||||
internal Color GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
|
||||
{
|
||||
Color color;
|
||||
if (splitLine.lineStyle.color != Color.clear)
|
||||
if (!ChartHelper.IsClearColor(splitLine.lineStyle.color))
|
||||
{
|
||||
color = splitLine.lineStyle.color;
|
||||
color.a *= splitLine.lineStyle.opacity;
|
||||
@@ -215,7 +215,7 @@ namespace XCharts
|
||||
internal Color GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
|
||||
{
|
||||
Color color;
|
||||
if (axisTick.lineStyle.color != Color.clear)
|
||||
if (!ChartHelper.IsClearColor(axisTick.lineStyle.color))
|
||||
{
|
||||
color = axisTick.lineStyle.color;
|
||||
color.a *= axisTick.lineStyle.opacity;
|
||||
@@ -238,7 +238,7 @@ namespace XCharts
|
||||
internal Color GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
|
||||
{
|
||||
Color color;
|
||||
if (itemStyle.color != Color.clear)
|
||||
if (!ChartHelper.IsClearColor(itemStyle.color))
|
||||
{
|
||||
color = itemStyle.color;
|
||||
color.a *= itemStyle.opacity;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace XCharts
|
||||
/// Whether the data icon is show.
|
||||
/// 是否显示图标。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; UpdateIcon(); } }
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 显示在上层还是在下层。
|
||||
/// </summary>
|
||||
@@ -59,47 +59,5 @@ namespace XCharts
|
||||
/// 图标偏移。
|
||||
/// </summary>
|
||||
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
public Image image { get; private set; }
|
||||
public RectTransform rect { get; private set; }
|
||||
|
||||
public void SetImage(Image image)
|
||||
{
|
||||
this.image = image;
|
||||
if (image)
|
||||
{
|
||||
rect = image.GetComponent<RectTransform>();
|
||||
if (m_Layer == Layer.UnderLabel)
|
||||
rect.SetSiblingIndex(0);
|
||||
else
|
||||
rect.SetSiblingIndex(image.transform.childCount - 1);
|
||||
UpdateIcon();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
if (image)
|
||||
{
|
||||
ChartHelper.SetActive(image.gameObject, flag);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateIcon()
|
||||
{
|
||||
if (image == null) return;
|
||||
if (show)
|
||||
{
|
||||
ChartHelper.SetActive(image.gameObject, true);
|
||||
image.sprite = m_Sprite;
|
||||
image.color = m_Color;
|
||||
rect.sizeDelta = new Vector2(m_Width, m_Height);
|
||||
image.transform.localPosition = m_Offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.SetActive(image.gameObject, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,11 +178,12 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public bool NeedShowBorder()
|
||||
{
|
||||
return borderWidth != 0 && borderColor != Color.clear;
|
||||
return borderWidth != 0 && !ChartHelper.IsClearColor(borderColor);
|
||||
}
|
||||
|
||||
public Color GetColor()
|
||||
{
|
||||
if (m_Opacity == 1) return m_Color;
|
||||
var color = m_Color;
|
||||
color.a *= m_Opacity;
|
||||
return color;
|
||||
|
||||
@@ -32,10 +32,9 @@ namespace XCharts
|
||||
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
|
||||
[SerializeField] private List<float> m_Data = new List<float>();
|
||||
|
||||
public LabelObject labelObject { get; set; }
|
||||
|
||||
private bool m_Show = true;
|
||||
private bool m_LabelAutoSize;
|
||||
private float m_LabelPaddingLeftRight;
|
||||
private float m_LabelPaddingTopBottom;
|
||||
private float m_RtPieOutsideRadius;
|
||||
|
||||
public int index { get; set; }
|
||||
@@ -102,15 +101,6 @@ namespace XCharts
|
||||
/// 该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||
/// </summary>
|
||||
public bool highlighted { get; set; }
|
||||
/// <summary>
|
||||
/// the label of data item.
|
||||
/// 该数据项的文本标签。
|
||||
/// </summary>
|
||||
public Text labelText { get; private set; }
|
||||
public RectTransform labelRect { get; private set; }
|
||||
/// <summary>
|
||||
/// 标志位置。
|
||||
/// </summary>
|
||||
public Vector3 labelPosition { get; set; }
|
||||
private bool m_CanShowLabel = true;
|
||||
/// <summary>
|
||||
@@ -127,11 +117,6 @@ namespace XCharts
|
||||
/// 最小值。
|
||||
/// </summary>
|
||||
public float min { get { return m_Data.Min(); } }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的gameObject
|
||||
/// </summary>
|
||||
public GameObject gameObject { get; private set; }
|
||||
/// <summary>
|
||||
/// 饼图数据项的开始角度(运行时自动计算)
|
||||
/// </summary>
|
||||
@@ -279,93 +264,21 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||
{
|
||||
gameObject = labelObj;
|
||||
m_LabelAutoSize = autoSize;
|
||||
m_LabelPaddingLeftRight = paddingLeftRight;
|
||||
m_LabelPaddingTopBottom = paddingTopBottom;
|
||||
labelText = labelObj.GetComponentInChildren<Text>();
|
||||
labelRect = labelText.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void SetLabelActive(bool active)
|
||||
{
|
||||
if (labelRect)
|
||||
{
|
||||
ChartHelper.SetActive(labelRect, active);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetLabelText(string text)
|
||||
{
|
||||
if (labelText && !labelText.text.Equals(text))
|
||||
{
|
||||
labelText.text = text;
|
||||
if (m_LabelAutoSize)
|
||||
{
|
||||
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
|
||||
new Vector2(labelText.preferredWidth + m_LabelPaddingLeftRight * 2,
|
||||
labelText.preferredHeight + m_LabelPaddingTopBottom * 2);
|
||||
var sizeChange = newSize.x != labelRect.sizeDelta.x || newSize.y != labelRect.sizeDelta.y;
|
||||
if (sizeChange) labelRect.sizeDelta = newSize;
|
||||
return sizeChange;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetLabelColor(Color color)
|
||||
{
|
||||
if (labelText)
|
||||
{
|
||||
labelText.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLabelWidth()
|
||||
{
|
||||
if (labelRect) return labelRect.sizeDelta.x;
|
||||
if (labelObject != null) return labelObject.GetLabelWidth();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetLabelHeight()
|
||||
{
|
||||
if (labelRect) return labelRect.sizeDelta.y;
|
||||
if (labelObject != null) return labelObject.GetLabelHeight();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void SetGameObjectPosition(Vector3 position)
|
||||
public void SetLabelActive(bool flag)
|
||||
{
|
||||
if (gameObject)
|
||||
{
|
||||
gameObject.transform.localPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelPosition(Vector3 position)
|
||||
{
|
||||
if (labelRect) labelRect.localPosition = position;
|
||||
}
|
||||
|
||||
[Obsolete("Use SerieData.SetIconImage() instead.", true)]
|
||||
public void SetIconObj(GameObject iconObj) { }
|
||||
|
||||
public void SetIconImage(Image image)
|
||||
{
|
||||
if (iconStyle == null) return;
|
||||
iconStyle.SetImage(image);
|
||||
}
|
||||
|
||||
public void UpdateIcon()
|
||||
{
|
||||
if (iconStyle == null) return;
|
||||
iconStyle.UpdateIcon();
|
||||
}
|
||||
|
||||
public bool IsInitLabel()
|
||||
{
|
||||
return labelText != null;
|
||||
if (labelObject != null) labelObject.SetLabelActive(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace XCharts
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The position of label.
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace XCharts
|
||||
{
|
||||
if (runtimeText && !runtimeText.text.Equals(text))
|
||||
{
|
||||
if (textStyle.color != Color.clear) runtimeText.color = textStyle.color;
|
||||
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.color = textStyle.color;
|
||||
runtimeText.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user