mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
v3.0.0-preivew8
This commit is contained in:
@@ -91,13 +91,18 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private float m_ItemHeight = 25f;
|
||||
[SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
|
||||
[SerializeField] private TextStyle m_LabelTextStyle = new TextStyle();
|
||||
[SerializeField] private TextStyle m_TitleTextStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft };
|
||||
[SerializeField] private LabelStyle m_IndicatorLabelStyle = new LabelStyle();
|
||||
[SerializeField]
|
||||
private List<TextStyle> m_ColumnsTextStyle = new List<TextStyle>() {
|
||||
new TextStyle() { alignment = TextAnchor.MiddleLeft, extraWidth = 5 },
|
||||
new TextStyle() { alignment = TextAnchor.MiddleLeft, extraWidth = 20 },
|
||||
new TextStyle() { alignment = TextAnchor.MiddleRight, extraWidth = 5 }
|
||||
private LabelStyle m_TitleLabelStyle = new LabelStyle()
|
||||
{
|
||||
textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }
|
||||
};
|
||||
[SerializeField]
|
||||
private List<LabelStyle> m_ContentLabelStyles = new List<LabelStyle>()
|
||||
{
|
||||
new LabelStyle(){ textPadding = new TextPadding(0,5,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }},
|
||||
new LabelStyle(){ textPadding = new TextPadding(0,20,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }},
|
||||
new LabelStyle(){ textPadding = new TextPadding(0,0,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight }}
|
||||
};
|
||||
|
||||
public TooltipContext context = new TooltipContext();
|
||||
@@ -305,27 +310,27 @@ namespace XCharts.Runtime
|
||||
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the text style of content.
|
||||
/// |提示框标签的文本样式。
|
||||
/// the label style of tooltip axis indicator label.
|
||||
/// |提示框的坐标轴指示器文本的样式。
|
||||
/// </summary>
|
||||
public TextStyle labelTextStyle
|
||||
public LabelStyle indicatorLabelStyle
|
||||
{
|
||||
get { return m_LabelTextStyle; }
|
||||
set { if (value != null) { m_LabelTextStyle = value; SetComponentDirty(); } }
|
||||
get { return m_IndicatorLabelStyle; }
|
||||
set { if (value != null) { m_IndicatorLabelStyle = value; SetComponentDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// 标题的文本样式。
|
||||
/// </summary>
|
||||
public TextStyle titleTextStyle
|
||||
public LabelStyle titleLabelStyle
|
||||
{
|
||||
get { return m_TitleTextStyle; }
|
||||
set { if (value != null) { m_TitleTextStyle = value; SetComponentDirty(); } }
|
||||
get { return m_TitleLabelStyle; }
|
||||
set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } }
|
||||
}
|
||||
|
||||
public List<TextStyle> columnsTextStyle
|
||||
public List<LabelStyle> contentLabelStyles
|
||||
{
|
||||
get { return m_ColumnsTextStyle; }
|
||||
set { if (value != null) { m_ColumnsTextStyle = value; SetComponentDirty(); } }
|
||||
get { return m_ContentLabelStyles; }
|
||||
set { if (value != null) { m_ContentLabelStyles = value; SetComponentDirty(); } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -343,14 +348,14 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public override bool componentDirty
|
||||
{
|
||||
get { return m_ComponentDirty || lineStyle.componentDirty || labelTextStyle.componentDirty; }
|
||||
get { return m_ComponentDirty || lineStyle.componentDirty || indicatorLabelStyle.componentDirty; }
|
||||
}
|
||||
|
||||
public override void ClearComponentDirty()
|
||||
{
|
||||
base.ClearComponentDirty();
|
||||
lineStyle.ClearComponentDirty();
|
||||
labelTextStyle.ClearComponentDirty();
|
||||
indicatorLabelStyle.ClearComponentDirty();
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前提示框所指示的Serie索引(目前只对散点图有效)。
|
||||
@@ -429,7 +434,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
|
||||
view.SetActive(alwayShowContent ? true : flag);
|
||||
}
|
||||
|
||||
@@ -492,17 +497,17 @@ namespace XCharts.Runtime
|
||||
return trigger == Trigger.Axis;
|
||||
}
|
||||
|
||||
public TextStyle GetColumnTextStyle(int index)
|
||||
public LabelStyle GetContentLabelStyle(int index)
|
||||
{
|
||||
if (m_ColumnsTextStyle.Count == 0)
|
||||
if (m_ContentLabelStyles.Count == 0)
|
||||
return null;
|
||||
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
else if (index > m_ColumnsTextStyle.Count - 1)
|
||||
index = m_ColumnsTextStyle.Count - 1;
|
||||
else if (index > m_ContentLabelStyles.Count - 1)
|
||||
index = m_ContentLabelStyles.Count - 1;
|
||||
|
||||
return m_ColumnsTextStyle[index];
|
||||
return m_ContentLabelStyles[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,8 @@ namespace XCharts.Runtime
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var labelName = "label_" + i;
|
||||
var item = ChartHelper.AddTooltipLabel(component, labelName, m_LabelRoot.transform, chart.theme, new Vector2(0.5f, 0.5f));
|
||||
var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
|
||||
chart.theme, TextAnchor.MiddleCenter);
|
||||
item.SetActive(false);
|
||||
m_IndicatorLabels.Add(item);
|
||||
}
|
||||
@@ -71,7 +72,8 @@ namespace XCharts.Runtime
|
||||
else
|
||||
{
|
||||
var labelName = "label_" + index;
|
||||
var item = ChartHelper.AddTooltipLabel(component, labelName, m_LabelRoot.transform, chart.theme, new Vector2(0.5f, 0.5f));
|
||||
var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
|
||||
chart.theme, TextAnchor.MiddleCenter);
|
||||
m_IndicatorLabels.Add(item);
|
||||
return item;
|
||||
}
|
||||
@@ -150,7 +152,7 @@ namespace XCharts.Runtime
|
||||
if (axis.gridIndex == grid.index)
|
||||
{
|
||||
var label = GetIndicatorLabel(labelCount++);
|
||||
SetTooltipIndicatorLabel(axis, label);
|
||||
SetTooltipIndicatorLabel(tooltip, axis, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +169,7 @@ namespace XCharts.Runtime
|
||||
if (axis.polarIndex == polar.index)
|
||||
{
|
||||
var label = GetIndicatorLabel(labelCount++);
|
||||
SetTooltipIndicatorLabel(axis, label);
|
||||
SetTooltipIndicatorLabel(tooltip, axis, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,19 +178,22 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTooltipIndicatorLabel(Axis axis, ChartLabel label)
|
||||
private void SetTooltipIndicatorLabel(Tooltip tooltip, Axis axis, ChartLabel label)
|
||||
{
|
||||
if (label == null) return;
|
||||
if (double.IsPositiveInfinity(axis.context.pointerValue)) return;
|
||||
label.SetActive(true);
|
||||
label.SetLabelActive(true);
|
||||
label.SetTextActive(true);
|
||||
label.SetPosition(axis.context.pointerLabelPosition);
|
||||
if (axis.IsCategory())
|
||||
label.SetText(axis.GetData((int)axis.context.pointerValue));
|
||||
else
|
||||
label.SetText(axis.context.pointerValue.ToString("f2"));
|
||||
var textColor = axis.axisLabel.textStyle.GetColor(chart.theme.axis.textColor);
|
||||
label.labelBackground.color = textColor;
|
||||
if (ChartHelper.IsClearColor(tooltip.indicatorLabelStyle.background.color))
|
||||
label.color = textColor;
|
||||
else
|
||||
label.color = tooltip.indicatorLabelStyle.background.color;
|
||||
label.SetTextColor(Color.white);
|
||||
}
|
||||
|
||||
@@ -415,7 +420,8 @@ namespace XCharts.Runtime
|
||||
if (tooltip.context.data.param.Count > 0)
|
||||
{
|
||||
tooltip.SetActive(true);
|
||||
tooltip.view.Refresh();
|
||||
if (tooltip.view != null)
|
||||
tooltip.view.Refresh();
|
||||
TooltipHelper.LimitInRect(tooltip, chart.chartRect);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace XCharts.Runtime
|
||||
public class TooltipViewItem
|
||||
{
|
||||
public GameObject gameObject;
|
||||
public List<ChartText> columns = new List<ChartText>();
|
||||
public List<ChartLabel> columns = new List<ChartLabel>();
|
||||
}
|
||||
public class TooltipView
|
||||
{
|
||||
@@ -26,7 +26,7 @@ namespace XCharts.Runtime
|
||||
public Image background;
|
||||
public Outline border;
|
||||
public VerticalLayoutGroup layout;
|
||||
public ChartText title;
|
||||
public ChartLabel title;
|
||||
private List<TooltipViewItem> m_Items = new List<TooltipViewItem>();
|
||||
private List<float> m_ColumnMaxWidth = new List<float>();
|
||||
private bool m_Active = false;
|
||||
@@ -89,12 +89,12 @@ namespace XCharts.Runtime
|
||||
column.SetText(param.columns[j]);
|
||||
|
||||
if (j == 0)
|
||||
column.SetColor(param.color);
|
||||
column.text.SetColor(param.color);
|
||||
|
||||
if (j >= m_ColumnMaxWidth.Count)
|
||||
m_ColumnMaxWidth.Add(0);
|
||||
|
||||
var columnWidth = column.GetPreferredWidth();
|
||||
var columnWidth = column.GetWidth();
|
||||
if (m_ColumnMaxWidth[j] < columnWidth)
|
||||
m_ColumnMaxWidth[j] = columnWidth;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace XCharts.Runtime
|
||||
else
|
||||
{
|
||||
maxWid = TotalMaxWidth();
|
||||
var titleWid = title.GetPreferredWidth();
|
||||
var titleWid = title.GetTextWidth();
|
||||
if (maxWid < titleWid)
|
||||
maxWid = titleWid;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(title.GetText()))
|
||||
if (!string.IsNullOrEmpty(title.text.GetText()))
|
||||
maxHig += tooltip.titleHeight;
|
||||
maxHig += tooltip.itemHeight * tooltip.context.data.param.Count;
|
||||
maxHig += tooltip.paddingTopBottom * 2;
|
||||
@@ -159,7 +159,7 @@ namespace XCharts.Runtime
|
||||
for (int j = 0; j < m_ColumnMaxWidth.Count; j++)
|
||||
{
|
||||
var deltaX = j == m_ColumnMaxWidth.Count - 1 ? maxWid - xPos : m_ColumnMaxWidth[j];
|
||||
item.columns[j].SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
|
||||
item.columns[j].text.SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
|
||||
item.columns[j].SetRectPosition(new Vector3(xPos, 0));
|
||||
xPos += m_ColumnMaxWidth[j];
|
||||
}
|
||||
@@ -192,7 +192,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
private ChartText GetItemColumn(TooltipViewItem item, int i)
|
||||
private ChartLabel GetItemColumn(TooltipViewItem item, int i)
|
||||
{
|
||||
if (i < 0) i = 0;
|
||||
if (i < item.columns.Count)
|
||||
@@ -236,10 +236,8 @@ namespace XCharts.Runtime
|
||||
tooltip.paddingTopBottom,
|
||||
tooltip.paddingTopBottom);
|
||||
|
||||
view.title = ChartHelper.AddTextObject("title", view.gameObject.transform, anchorMin, anchorMax, v2_0_05,
|
||||
new Vector2(10, tooltip.titleHeight), tooltip.titleTextStyle, theme.tooltip);
|
||||
view.title.SetText("");
|
||||
view.title.SetLocalPosition(new Vector2(3, -3));
|
||||
view.title = ChartHelper.AddChartLabel("title", view.gameObject.transform, tooltip.titleLabelStyle, theme.tooltip,
|
||||
"", Color.clear, TextAnchor.MiddleLeft);
|
||||
|
||||
var item = CreateViewItem(0, view.gameObject.transform, tooltip, theme.tooltip);
|
||||
view.m_Items.Add(item);
|
||||
@@ -261,14 +259,12 @@ namespace XCharts.Runtime
|
||||
return item;
|
||||
}
|
||||
|
||||
private static ChartText CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme)
|
||||
private static ChartLabel CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme)
|
||||
{
|
||||
var value = ChartHelper.AddTextObject("column" + i, parent,
|
||||
v2_0_05, v2_0_05, v2_0_05, new Vector2(100, tooltip.itemHeight),
|
||||
tooltip.GetColumnTextStyle(i), theme);
|
||||
value.SetRectPosition(new Vector3(0, 0));
|
||||
value.SetText("");
|
||||
return value;
|
||||
var labelStyle = tooltip.GetContentLabelStyle(i);
|
||||
var label = ChartHelper.AddChartLabel("column" + i, parent, labelStyle, theme,
|
||||
"", Color.clear, TextAnchor.MiddleLeft);
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user