mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 02:40:13 +00:00
优化SerieData的自定义图标不与SerieLabel关联,可单独控制是否显示
This commit is contained in:
48755
Demo/demo_xchart.unity
48755
Demo/demo_xchart.unity
File diff suppressed because it is too large
Load Diff
@@ -303,9 +303,9 @@ namespace XCharts
|
|||||||
var tempWidth = (drawRect.width - startX + 72) / 2;
|
var tempWidth = (drawRect.width - startX + 72) / 2;
|
||||||
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
|
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
|
||||||
var centerYRect = new Rect(centerXRect.x + tempWidth - 58, drawRect.y, tempWidth, drawRect.height);
|
var centerYRect = new Rect(centerXRect.x + tempWidth - 58, drawRect.y, tempWidth, drawRect.height);
|
||||||
var x = EditorGUI.FloatField(centerXRect, m_IconOffset.vector2Value.x);
|
var x = EditorGUI.FloatField(centerXRect, m_IconOffset.vector3Value.x);
|
||||||
var y = EditorGUI.FloatField(centerYRect, m_IconOffset.vector2Value.y);
|
var y = EditorGUI.FloatField(centerYRect, m_IconOffset.vector3Value.y);
|
||||||
m_IconOffset.vector2Value = new Vector2(x, y);
|
m_IconOffset.vector3Value = new Vector3(x, y);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace XCharts
|
|||||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||||
SerializedProperty m_Position = prop.FindPropertyRelative("m_Position");
|
SerializedProperty m_Position = prop.FindPropertyRelative("m_Position");
|
||||||
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
|
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
|
||||||
SerializedProperty m_Distance = prop.FindPropertyRelative("m_Distance");
|
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
|
||||||
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
|
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
|
||||||
SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight");
|
SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight");
|
||||||
SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom");
|
SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom");
|
||||||
@@ -41,10 +41,20 @@ namespace XCharts
|
|||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
EditorGUI.PropertyField(drawRect, m_Position);
|
EditorGUI.PropertyField(drawRect, m_Position);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
|
||||||
|
EditorGUI.LabelField(drawRect, "Offset");
|
||||||
|
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
|
||||||
|
var tempWidth = (drawRect.width - startX + 52) / 2;
|
||||||
|
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
|
||||||
|
var centerYRect = new Rect(centerXRect.x + tempWidth - 38, drawRect.y, tempWidth, drawRect.height);
|
||||||
|
var x = EditorGUI.FloatField(centerXRect, m_Offset.vector3Value.x);
|
||||||
|
var y = EditorGUI.FloatField(centerYRect, m_Offset.vector3Value.y);
|
||||||
|
m_Offset.vector3Value = new Vector3(x, y);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
|
||||||
EditorGUI.PropertyField(drawRect, m_Formatter);
|
EditorGUI.PropertyField(drawRect, m_Formatter);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_Distance);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_Color);
|
EditorGUI.PropertyField(drawRect, m_Color);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
|
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the normal line chart,
|
/// the normal line chart,
|
||||||
/// 所有扇区圆心角相同,仅通过半径展现数据大小。
|
/// 普通折线图。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Normal,
|
Normal,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -903,6 +903,15 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsNeedShowDataIcon()
|
||||||
|
{
|
||||||
|
foreach (var data in m_Data)
|
||||||
|
{
|
||||||
|
if (data.showIcon) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置指定index的数据图标的尺寸
|
/// 设置指定index的数据图标的尺寸
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// the origin of area.
|
||||||
/// 图形区域的起始位置。
|
/// 区域填充的起始位置。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AreaOrigin origin { get { return m_Origin; } set { m_Origin = value; } }
|
public AreaOrigin origin { get { return m_Origin; } set { m_Origin = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -654,7 +654,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
var labelHalfWid = serieData.GetLabelWidth() / 2;
|
var labelHalfWid = serieData.GetLabelWidth() / 2;
|
||||||
var labelHalfHig = serieData.GetLabelHeight() / 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 p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
|
||||||
var p2 = 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);
|
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++)
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
{
|
{
|
||||||
var serieData = serie.data[j];
|
var serieData = serie.data[j];
|
||||||
if (serie.label.show)
|
if (serie.label.show || serieData.showIcon)
|
||||||
{
|
{
|
||||||
var pos = serie.dataPoints[j];
|
var pos = serie.dataPoints[j];
|
||||||
var value = serieData.data[1];
|
var value = serieData.data[1];
|
||||||
@@ -1146,10 +1146,8 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var centerPos = isYAxis ? new Vector3(pos.x + (value >= 0 ? 1 : -1) * serie.label.distance, pos.y) :
|
serieData.labelPosition = pos;
|
||||||
new Vector3(pos.x, pos.y + (value >= 0 ? 1 : -1) * serie.label.distance);
|
if (serie.label.show) DrawLabelBackground(vh, serie, serieData);
|
||||||
serieData.labelPosition = centerPos;
|
|
||||||
DrawLabelBackground(vh, serie, serieData);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1169,16 +1167,18 @@ namespace XCharts
|
|||||||
var total = serie.yTotal;
|
var total = serie.yTotal;
|
||||||
for (int j = 0; j < serie.data.Count; j++)
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
{
|
{
|
||||||
|
if (j >= serie.dataPoints.Count) break;
|
||||||
var serieData = serie.data[j];
|
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 value = serieData.data[1];
|
||||||
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
||||||
serieData.SetLabelActive(true);
|
serieData.SetLabelActive(true);
|
||||||
|
serieData.SetLabelPosition(serie.label.offset);
|
||||||
if (serieData.SetLabelText(content)) RefreshChart();
|
if (serieData.SetLabelText(content)) RefreshChart();
|
||||||
serieData.SetLabelPosition(serieData.labelPosition);
|
|
||||||
serieData.UpdateIcon();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ namespace XCharts
|
|||||||
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
|
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set this to false to prevent the areafrom showing.
|
/// Whether show line.
|
||||||
/// 是否显示区域填充。
|
/// 是否显示线条。在折线图中无效。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -19,12 +19,11 @@ namespace XCharts
|
|||||||
[SerializeField] private Color m_IconColor = Color.white;
|
[SerializeField] private Color m_IconColor = Color.white;
|
||||||
[SerializeField] private float m_IconWidth = 40;
|
[SerializeField] private float m_IconWidth = 40;
|
||||||
[SerializeField] private float m_IconHeight = 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>();
|
[SerializeField] private List<float> m_Data = new List<float>();
|
||||||
|
|
||||||
private bool m_Show = true;
|
private bool m_Show = true;
|
||||||
private GameObject m_Label;
|
|
||||||
private bool m_LabelAutoSize;
|
private bool m_LabelAutoSize;
|
||||||
private float m_LabelPaddingLeftRight;
|
private float m_LabelPaddingLeftRight;
|
||||||
private float m_LabelPaddingTopBottom;
|
private float m_LabelPaddingTopBottom;
|
||||||
@@ -64,7 +63,7 @@ namespace XCharts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 图标偏移。
|
/// 图标偏移。
|
||||||
/// </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>
|
/// <summary>
|
||||||
/// An arbitrary dimension data list of data item.
|
/// An arbitrary dimension data list of data item.
|
||||||
@@ -107,6 +106,10 @@ namespace XCharts
|
|||||||
public float min { get { return m_Data.Min(); } }
|
public float min { get { return m_Data.Min(); } }
|
||||||
public Image icon { get; private set; }
|
public Image icon { get; private set; }
|
||||||
public RectTransform iconRect { get; private set; }
|
public RectTransform iconRect { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 关联的gameObject
|
||||||
|
/// </summary>
|
||||||
|
public GameObject gameObject { get; private set; }
|
||||||
|
|
||||||
public float GetData(int index)
|
public float GetData(int index)
|
||||||
{
|
{
|
||||||
@@ -116,20 +119,19 @@ namespace XCharts
|
|||||||
|
|
||||||
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||||
{
|
{
|
||||||
m_Label = labelObj;
|
gameObject = labelObj;
|
||||||
m_LabelAutoSize = autoSize;
|
m_LabelAutoSize = autoSize;
|
||||||
m_LabelPaddingLeftRight = paddingLeftRight;
|
m_LabelPaddingLeftRight = paddingLeftRight;
|
||||||
m_LabelPaddingTopBottom = paddingTopBottom;
|
m_LabelPaddingTopBottom = paddingTopBottom;
|
||||||
labelText = labelObj.GetComponentInChildren<Text>();
|
labelText = labelObj.GetComponentInChildren<Text>();
|
||||||
//labelImage = labelObj.GetComponent<Image>();
|
labelRect = labelText.GetComponent<RectTransform>();
|
||||||
labelRect = labelObj.GetComponent<RectTransform>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetLabelActive(bool active)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetGameObjectPosition(Vector3 position)
|
||||||
|
{
|
||||||
|
if (gameObject)
|
||||||
|
{
|
||||||
|
gameObject.transform.localPosition = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetLabelPosition(Vector3 position)
|
public void SetLabelPosition(Vector3 position)
|
||||||
{
|
{
|
||||||
if (m_Label)
|
if (labelRect) labelRect.localPosition = position;
|
||||||
{
|
|
||||||
m_Label.transform.localPosition = position;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetIconObj(GameObject iconObj)
|
public void SetIconObj(GameObject iconObj)
|
||||||
@@ -179,9 +186,10 @@ namespace XCharts
|
|||||||
|
|
||||||
public void UpdateIcon()
|
public void UpdateIcon()
|
||||||
{
|
{
|
||||||
|
if (icon == null) return;
|
||||||
if (m_ShowIcon)
|
if (m_ShowIcon)
|
||||||
{
|
{
|
||||||
icon.gameObject.SetActive(true);
|
ChartHelper.SetActive(icon.gameObject, true);
|
||||||
icon.sprite = m_IconImage;
|
icon.sprite = m_IconImage;
|
||||||
icon.color = m_IconColor;
|
icon.color = m_IconColor;
|
||||||
iconRect.sizeDelta = new Vector2(m_IconWidth, m_IconHeight);
|
iconRect.sizeDelta = new Vector2(m_IconWidth, m_IconHeight);
|
||||||
@@ -189,7 +197,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
icon.gameObject.SetActive(false);
|
ChartHelper.SetActive(icon.gameObject, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
[SerializeField] private bool m_Show = false;
|
[SerializeField] private bool m_Show = false;
|
||||||
[SerializeField] Position m_Position;
|
[SerializeField] Position m_Position;
|
||||||
[SerializeField] private float m_Distance = 0;
|
[SerializeField] private Vector3 m_Offset;
|
||||||
[SerializeField] private string m_Formatter;
|
[SerializeField] private string m_Formatter;
|
||||||
[SerializeField] private float m_Rotate = 0;
|
[SerializeField] private float m_Rotate = 0;
|
||||||
[SerializeField] private float m_PaddingLeftRight = 2f;
|
[SerializeField] private float m_PaddingLeftRight = 2f;
|
||||||
@@ -96,10 +96,10 @@ namespace XCharts
|
|||||||
/// </example>
|
/// </example>
|
||||||
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
|
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Distance to the host graphic element. Works when position is Top,Left,Right,Bottom.
|
/// offset to the host graphic element.
|
||||||
/// 距离图形元素的距离,当position为Top,Left,Right,Bottom时有效。
|
/// 距离图形元素的偏移
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float distance { get { return m_Distance; } set { m_Distance = value; } }
|
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Text color,If set as default ,the color will assigned as series color.
|
/// Text color,If set as default ,the color will assigned as series color.
|
||||||
/// 自定义文字颜色,默认和系列的颜色一致。
|
/// 自定义文字颜色,默认和系列的颜色一致。
|
||||||
|
|||||||
@@ -390,9 +390,10 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (serieData.labelText == null) return;
|
if (serieData.labelText == null) return;
|
||||||
var isHighlight = (serieData.highlighted && serie.highlightLabel.show);
|
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;
|
float rotate = 0;
|
||||||
bool isInsidePosition = serie.label.position == SerieLabel.Position.Inside;
|
bool isInsidePosition = serie.label.position == SerieLabel.Position.Inside;
|
||||||
if (serie.label.rotate > 0 && isInsidePosition)
|
if (serie.label.rotate > 0 && isInsidePosition)
|
||||||
@@ -456,12 +457,14 @@ namespace XCharts
|
|||||||
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
||||||
if (serieData.SetLabelText(content)) RefreshChart();
|
if (serieData.SetLabelText(content)) RefreshChart();
|
||||||
}
|
}
|
||||||
serieData.SetLabelPosition(serieData.labelPosition);
|
serieData.SetGameObjectPosition(serieData.labelPosition);
|
||||||
|
if(showLabel) serieData.SetLabelPosition(serie.label.offset);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
serieData.SetLabelActive(false);
|
serieData.SetLabelActive(false);
|
||||||
}
|
}
|
||||||
|
serieData.UpdateIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLegendButtonClick(int index, string legendName, bool show)
|
protected override void OnLegendButtonClick(int index, string legendName, bool show)
|
||||||
|
|||||||
Reference in New Issue
Block a user