mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 17:30:10 +00:00
增加SerieLabel的背景宽高、文字边距、文字旋转的配置
This commit is contained in:
@@ -295,7 +295,6 @@ namespace XCharts
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.series[i];
|
||||
if (serie.type != SerieType.Pie && serie.type != SerieType.Line) continue;
|
||||
if (serie.type != SerieType.Pie && !serie.label.show) continue;
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
@@ -313,11 +312,11 @@ namespace XCharts
|
||||
(Color)m_ThemeInfo.GetColor(i);
|
||||
}
|
||||
var backgroundColor = serie.label.backgroundColor;
|
||||
var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font, color, backgroundColor,
|
||||
serie.label.fontSize, serie.label.fontStyle);
|
||||
serieData.label = labelObj.GetComponentInChildren<Text>();
|
||||
serieData.labelImage = labelObj.GetComponent<Image>();
|
||||
serieData.labelRect = labelObj.GetComponent<RectTransform>();
|
||||
var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font,
|
||||
color, backgroundColor, serie.label.fontSize, serie.label.fontStyle, serie.label.rotate,
|
||||
serie.label.backgroundWidth,serie.label.backgroundHeight);
|
||||
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
||||
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.SetLabelText(serieData.name);
|
||||
count++;
|
||||
|
||||
@@ -17,6 +17,10 @@ namespace XCharts
|
||||
[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;
|
||||
|
||||
/// <summary>
|
||||
/// the name of data item.
|
||||
@@ -47,9 +51,9 @@ namespace XCharts
|
||||
/// the label of data item.
|
||||
/// 该数据项的文本标签。
|
||||
/// </summary>
|
||||
public Text label { get; set; }
|
||||
public RectTransform labelRect { get; set; }
|
||||
public Image labelImage { get; set; }
|
||||
public Text labelText { get; private set; }
|
||||
public RectTransform labelRect { get; private set; }
|
||||
public Image labelImage { get; private set; }
|
||||
/// <summary>
|
||||
/// the maxinum value.
|
||||
/// 最大值。
|
||||
@@ -67,29 +71,44 @@ namespace XCharts
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||
{
|
||||
m_Label = labelObj;
|
||||
m_LabelAutoSize = autoSize;
|
||||
m_LabelPaddingLeftRight = paddingLeftRight;
|
||||
m_LabelPaddingTopBottom = paddingTopBottom;
|
||||
labelText = labelObj.GetComponentInChildren<Text>();
|
||||
labelImage = labelObj.GetComponent<Image>();
|
||||
labelRect = labelObj.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void SetLabelActive(bool active)
|
||||
{
|
||||
if (labelImage)
|
||||
if (m_Label)
|
||||
{
|
||||
ChartHelper.SetActive(labelImage.gameObject, active);
|
||||
ChartHelper.SetActive(m_Label, active);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelText(string text)
|
||||
{
|
||||
if (label)
|
||||
if (labelText)
|
||||
{
|
||||
label.text = text;
|
||||
labelRect.sizeDelta = new Vector2(label.preferredWidth + 4,
|
||||
label.preferredHeight + 4);
|
||||
labelText.text = text;
|
||||
if (m_LabelAutoSize)
|
||||
{
|
||||
labelRect.sizeDelta = new Vector2(labelText.preferredWidth + m_LabelPaddingLeftRight * 2,
|
||||
labelText.preferredHeight + m_LabelPaddingTopBottom * 2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelPosition(Vector3 position)
|
||||
{
|
||||
if (labelImage)
|
||||
if (m_Label)
|
||||
{
|
||||
labelImage.transform.localPosition = position;
|
||||
m_Label.transform.localPosition = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ namespace XCharts
|
||||
/// the left of symbol.
|
||||
/// 图形标志的左边。
|
||||
/// </summary>
|
||||
Left,
|
||||
//Left,
|
||||
/// <summary>
|
||||
/// the right of symbol.
|
||||
/// 图形标志的右边。
|
||||
/// </summary>
|
||||
Right,
|
||||
//Right,
|
||||
/// <summary>
|
||||
/// the bottom of symbol.
|
||||
/// 图形标志的底部。
|
||||
@@ -53,10 +53,14 @@ namespace XCharts
|
||||
}
|
||||
[SerializeField] private bool m_Show = false;
|
||||
[SerializeField] Position m_Position;
|
||||
[SerializeField] private float m_Distance;
|
||||
[SerializeField] private float m_Rotate;
|
||||
[SerializeField] private float m_Distance = 0;
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private float m_PaddingLeftRight = 2f;
|
||||
[SerializeField] private float m_PaddingTopBottom = 2f;
|
||||
[SerializeField] private Color m_Color;
|
||||
[SerializeField] private Color m_BackgroundColor;
|
||||
[SerializeField] private float m_BackgroundWidth = 0;
|
||||
[SerializeField] private float m_BackgroundHeight = 0;
|
||||
[SerializeField] private int m_FontSize = 18;
|
||||
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
|
||||
[SerializeField] private bool m_Line = true;
|
||||
@@ -83,13 +87,39 @@ namespace XCharts
|
||||
/// 自定义文字颜色,默认和系列的颜色一致。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// the background color. If set as default, it means than don't show background.
|
||||
/// 标签的背景色,默认无颜色。
|
||||
/// </summary>
|
||||
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
|
||||
/// <summary>
|
||||
/// the width of background. If set as default value 0, it means than the background width auto set as the text width.
|
||||
/// 标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float backgroundWidth { get { return m_BackgroundWidth; } set { m_BackgroundWidth = value; } }
|
||||
/// <summary>
|
||||
/// the height of background. If set as default value 0, it means than the background height auto set as the text height.
|
||||
/// 标签的背景高度。一般不用指定,不指定时则自动是文字的高度。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float backgroundHeight { get { return m_BackgroundHeight; } set { m_BackgroundHeight = value; } }
|
||||
/// <summary>
|
||||
/// Rotate label.
|
||||
/// 标签旋转。
|
||||
/// </summary>
|
||||
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||
/// <summary>
|
||||
/// the text padding of left and right. defaut:2.
|
||||
/// 左右边距。
|
||||
/// </summary>
|
||||
public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
|
||||
/// <summary>
|
||||
/// the text padding of top and bottom. defaut:2.
|
||||
/// 上下边距。
|
||||
/// </summary>
|
||||
public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } }
|
||||
/// <summary>
|
||||
/// font size.
|
||||
/// 文字的字体大小。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user