优化SerieData的自定义图标不与SerieLabel关联,可单独控制是否显示

This commit is contained in:
monitor1394
2019-09-25 09:44:53 +08:00
parent e3ab20bcd2
commit f1199f2aad
11 changed files with 36293 additions and 12576 deletions

View File

@@ -44,8 +44,8 @@ namespace XCharts
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
///
/// 图形区域的起始位置。
/// the origin of area.
/// 区域填充的起始位置。
/// </summary>
public AreaOrigin origin { get { return m_Origin; } set { m_Origin = value; } }
/// <summary>

View File

@@ -654,7 +654,7 @@ namespace XCharts
{
var labelHalfWid = serieData.GetLabelWidth() / 2;
var labelHalfHig = serieData.GetLabelHeight() / 2;
var centerPos = serieData.labelPosition;
var centerPos = serieData.labelPosition + serie.label.offset;
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
var p2 = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
var p3 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);

View File

@@ -1123,7 +1123,7 @@ namespace XCharts
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (serie.label.show)
if (serie.label.show || serieData.showIcon)
{
var pos = serie.dataPoints[j];
var value = serieData.data[1];
@@ -1146,10 +1146,8 @@ namespace XCharts
}
break;
}
var centerPos = isYAxis ? new Vector3(pos.x + (value >= 0 ? 1 : -1) * serie.label.distance, pos.y) :
new Vector3(pos.x, pos.y + (value >= 0 ? 1 : -1) * serie.label.distance);
serieData.labelPosition = centerPos;
DrawLabelBackground(vh, serie, serieData);
serieData.labelPosition = pos;
if (serie.label.show) DrawLabelBackground(vh, serie, serieData);
}
else
{
@@ -1169,16 +1167,18 @@ namespace XCharts
var total = serie.yTotal;
for (int j = 0; j < serie.data.Count; j++)
{
if (j >= serie.dataPoints.Count) break;
var serieData = serie.data[j];
if (serie.show && serie.label.show && j < serie.dataPoints.Count)
var pos = serie.dataPoints[j];
serieData.SetGameObjectPosition(serieData.labelPosition);
serieData.UpdateIcon();
if (serie.show && serie.label.show)
{
var pos = serie.dataPoints[j];
var value = serieData.data[1];
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
serieData.SetLabelActive(true);
serieData.SetLabelPosition(serie.label.offset);
if (serieData.SetLabelText(content)) RefreshChart();
serieData.SetLabelPosition(serieData.labelPosition);
serieData.UpdateIcon();
}
else
{

View File

@@ -44,8 +44,8 @@ namespace XCharts
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充
/// Whether show line.
/// 是否显示线条。在折线图中无效
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>

View File

@@ -19,12 +19,11 @@ namespace XCharts
[SerializeField] private Color m_IconColor = Color.white;
[SerializeField] private float m_IconWidth = 40;
[SerializeField] private float m_IconHeight = 40;
[SerializeField] private Vector2 m_IconOffset;
[SerializeField] private Vector3 m_IconOffset;
[SerializeField] private List<float> m_Data = new List<float>();
private bool m_Show = true;
private GameObject m_Label;
private bool m_LabelAutoSize;
private float m_LabelPaddingLeftRight;
private float m_LabelPaddingTopBottom;
@@ -64,7 +63,7 @@ namespace XCharts
/// <summary>
/// 图标偏移。
/// </summary>
public Vector2 iconOffset { get { return m_IconOffset; } set { m_IconOffset = value; } }
public Vector3 iconOffset { get { return m_IconOffset; } set { m_IconOffset = value; } }
/// <summary>
/// An arbitrary dimension data list of data item.
@@ -107,6 +106,10 @@ namespace XCharts
public float min { get { return m_Data.Min(); } }
public Image icon { get; private set; }
public RectTransform iconRect { get; private set; }
/// <summary>
/// 关联的gameObject
/// </summary>
public GameObject gameObject { get; private set; }
public float GetData(int index)
{
@@ -116,20 +119,19 @@ namespace XCharts
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
{
m_Label = labelObj;
gameObject = labelObj;
m_LabelAutoSize = autoSize;
m_LabelPaddingLeftRight = paddingLeftRight;
m_LabelPaddingTopBottom = paddingTopBottom;
labelText = labelObj.GetComponentInChildren<Text>();
//labelImage = labelObj.GetComponent<Image>();
labelRect = labelObj.GetComponent<RectTransform>();
labelRect = labelText.GetComponent<RectTransform>();
}
public void SetLabelActive(bool active)
{
if (m_Label)
if (labelRect)
{
ChartHelper.SetActive(m_Label, active);
ChartHelper.SetActive(labelRect, active);
}
}
@@ -162,12 +164,17 @@ namespace XCharts
return 0;
}
public void SetGameObjectPosition(Vector3 position)
{
if (gameObject)
{
gameObject.transform.localPosition = position;
}
}
public void SetLabelPosition(Vector3 position)
{
if (m_Label)
{
m_Label.transform.localPosition = position;
}
if (labelRect) labelRect.localPosition = position;
}
public void SetIconObj(GameObject iconObj)
@@ -179,9 +186,10 @@ namespace XCharts
public void UpdateIcon()
{
if (icon == null) return;
if (m_ShowIcon)
{
icon.gameObject.SetActive(true);
ChartHelper.SetActive(icon.gameObject, true);
icon.sprite = m_IconImage;
icon.color = m_IconColor;
iconRect.sizeDelta = new Vector2(m_IconWidth, m_IconHeight);
@@ -189,7 +197,7 @@ namespace XCharts
}
else
{
icon.gameObject.SetActive(false);
ChartHelper.SetActive(icon.gameObject, false);
}
}
}

View File

@@ -53,7 +53,7 @@ namespace XCharts
}
[SerializeField] private bool m_Show = false;
[SerializeField] Position m_Position;
[SerializeField] private float m_Distance = 0;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_PaddingLeftRight = 2f;
@@ -96,10 +96,10 @@ namespace XCharts
/// </example>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <summary>
/// Distance to the host graphic element. Works when position is Top,Left,Right,Bottom.
/// 距离图形元素的距离当position为TopLeftRightBottom时有效。
/// offset to the host graphic element.
/// 距离图形元素的偏移
/// </summary>
public float distance { get { return m_Distance; } set { m_Distance = value; } }
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// Text color,If set as default ,the color will assigned as series color.
/// 自定义文字颜色,默认和系列的颜色一致。