mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 05:50:09 +00:00
优化SerieData的自定义图标不与SerieLabel关联,可单独控制是否显示
This commit is contained in:
@@ -70,7 +70,7 @@ namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the normal line chart,
|
||||
/// 所有扇区圆心角相同,仅通过半径展现数据大小。
|
||||
/// 普通折线图。
|
||||
/// </summary>
|
||||
Normal,
|
||||
/// <summary>
|
||||
@@ -903,6 +903,15 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNeedShowDataIcon()
|
||||
{
|
||||
foreach (var data in m_Data)
|
||||
{
|
||||
if (data.showIcon) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标的尺寸
|
||||
/// </summary>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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为Top,Left,Right,Bottom时有效。
|
||||
/// 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.
|
||||
/// 自定义文字颜色,默认和系列的颜色一致。
|
||||
|
||||
@@ -390,9 +390,10 @@ namespace XCharts
|
||||
{
|
||||
if (serieData.labelText == null) return;
|
||||
var isHighlight = (serieData.highlighted && serie.highlightLabel.show);
|
||||
if ((serie.label.show || isHighlight) && serieData.canShowLabel)
|
||||
var showLabel = ((serie.label.show || isHighlight) && serieData.canShowLabel);
|
||||
if (showLabel || serieData.showIcon)
|
||||
{
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.SetLabelActive(showLabel);
|
||||
float rotate = 0;
|
||||
bool isInsidePosition = serie.label.position == SerieLabel.Position.Inside;
|
||||
if (serie.label.rotate > 0 && isInsidePosition)
|
||||
@@ -456,12 +457,14 @@ namespace XCharts
|
||||
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
||||
if (serieData.SetLabelText(content)) RefreshChart();
|
||||
}
|
||||
serieData.SetLabelPosition(serieData.labelPosition);
|
||||
serieData.SetGameObjectPosition(serieData.labelPosition);
|
||||
if(showLabel) serieData.SetLabelPosition(serie.label.offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
serieData.UpdateIcon();
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClick(int index, string legendName, bool show)
|
||||
|
||||
Reference in New Issue
Block a user