mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
v3.0.0-preivew8
This commit is contained in:
@@ -14,9 +14,9 @@ namespace XCharts.Runtime
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private string m_Text = "Chart Title";
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
[SerializeField] private string m_SubText = "";
|
||||
[SerializeField] private TextStyle m_SubTextStyle = new TextStyle();
|
||||
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
|
||||
[SerializeField] private LabelStyle m_SubLabelStyle = new LabelStyle();
|
||||
[SerializeField] private float m_ItemGap = 0;
|
||||
[SerializeField] private Location m_Location = Location.defaultTop;
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace XCharts.Runtime
|
||||
/// The text style of main title.
|
||||
/// |主标题文本样式。
|
||||
/// </summary>
|
||||
public TextStyle textStyle
|
||||
public LabelStyle labelStyle
|
||||
{
|
||||
get { return m_TextStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
|
||||
get { return m_LabelStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Subtitle text, supporting for \n for newlines.
|
||||
@@ -53,10 +53,10 @@ namespace XCharts.Runtime
|
||||
/// The text style of sub title.
|
||||
/// |副标题文本样式。
|
||||
/// </summary>
|
||||
public TextStyle subTextStyle
|
||||
public LabelStyle subLabelStyle
|
||||
{
|
||||
get { return m_SubTextStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); }
|
||||
get { return m_SubLabelStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_SubLabelStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// [default:8]
|
||||
@@ -85,8 +85,8 @@ namespace XCharts.Runtime
|
||||
{
|
||||
return m_ComponentDirty
|
||||
|| location.componentDirty
|
||||
|| textStyle.componentDirty
|
||||
|| subTextStyle.componentDirty;
|
||||
|| m_LabelStyle.componentDirty
|
||||
|| m_SubLabelStyle.componentDirty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ namespace XCharts.Runtime
|
||||
{
|
||||
base.ClearComponentDirty();
|
||||
location.ClearComponentDirty();
|
||||
textStyle.ClearComponentDirty();
|
||||
subTextStyle.ClearComponentDirty();
|
||||
m_LabelStyle.ClearComponentDirty();
|
||||
m_SubLabelStyle.ClearComponentDirty();
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
|
||||
@@ -27,30 +27,23 @@ namespace XCharts.Runtime
|
||||
anchorMin = title.location.runtimeAnchorMin;
|
||||
anchorMax = title.location.runtimeAnchorMax;
|
||||
pivot = title.location.runtimePivot;
|
||||
title.textStyle.UpdateAlignmentByLocation(title.location);
|
||||
title.subTextStyle.UpdateAlignmentByLocation(title.location);
|
||||
var fontSize = title.textStyle.GetFontSize(chart.theme.title);
|
||||
var fontSize = title.labelStyle.textStyle.GetFontSize(chart.theme.title);
|
||||
ChartHelper.UpdateRectTransform(titleObject, anchorMin, anchorMax, pivot, new Vector2(chart.chartWidth, chart.chartHeight));
|
||||
var titlePosition = chart.GetTitlePosition(title);
|
||||
var subTitlePosition = -new Vector3(0, fontSize + title.itemGap, 0);
|
||||
var titleWid = chart.chartWidth;
|
||||
|
||||
titleObject.transform.localPosition = titlePosition;
|
||||
titleObject.hideFlags = chart.chartHideFlags;
|
||||
ChartHelper.HideAllObject(titleObject);
|
||||
|
||||
var titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(titleWid, fontSize), title.textStyle, chart.theme.title);
|
||||
titleText.SetActive(title.show);
|
||||
titleText.SetLocalPosition(Vector3.zero + title.textStyle.offsetv3);
|
||||
titleText.SetText(title.text);
|
||||
var label = ChartHelper.AddChartLabel(s_TitleObjectName, titleObject.transform, title.labelStyle, chart.theme.title,
|
||||
title.text, Color.clear, title.location.runtimeTextAlignment);
|
||||
label.SetActive(title.show && title.labelStyle.show);
|
||||
|
||||
var subText = ChartHelper.AddTextObject(s_SubTitleObjectName, titleObject.transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(titleWid, title.subTextStyle.GetFontSize(chart.theme.subTitle)), title.subTextStyle,
|
||||
chart.theme.subTitle);
|
||||
subText.SetActive(title.show && !string.IsNullOrEmpty(title.subText));
|
||||
subText.SetLocalPosition(subTitlePosition + title.subTextStyle.offsetv3);
|
||||
subText.SetText(title.subText);
|
||||
var subLabel = ChartHelper.AddChartLabel(s_SubTitleObjectName, titleObject.transform, title.subLabelStyle, chart.theme.subTitle,
|
||||
title.subText, Color.clear, title.location.runtimeTextAlignment);
|
||||
subLabel.SetActive(title.show && title.subLabelStyle.show);
|
||||
subLabel.transform.localPosition = subTitlePosition + title.subLabelStyle.offset;
|
||||
};
|
||||
title.refreshComponent();
|
||||
}
|
||||
|
||||
@@ -9,54 +9,8 @@ namespace XCharts.Runtime
|
||||
/// |标题相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TitleStyle : ChildComponent, ISerieDataComponent, ISerieExtraComponent
|
||||
public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieExtraComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Vector2 m_OffsetCenter = new Vector2(0, -0.2f);
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show title.
|
||||
/// |是否显示标题。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The offset position relative to the center.
|
||||
/// |相对于中心的偏移位置。
|
||||
/// </summary>
|
||||
public Vector2 offsetCenter
|
||||
{
|
||||
get { return m_OffsetCenter; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_OffsetCenter, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// |文本的颜色。
|
||||
/// </summary>
|
||||
public TextStyle textStyle
|
||||
{
|
||||
get { return m_TextStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
|
||||
|
||||
public override void ClearComponentDirty()
|
||||
{
|
||||
base.ClearComponentDirty();
|
||||
textStyle.ClearComponentDirty();
|
||||
}
|
||||
|
||||
public Vector3 GetOffset(float radius)
|
||||
{
|
||||
var x = ChartHelper.GetActualValue(m_OffsetCenter.x, radius);
|
||||
var y = ChartHelper.GetActualValue(m_OffsetCenter.y, radius);
|
||||
return new Vector3(x, y, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user