mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 20:20:14 +00:00
增加Tooltip的columnGapWidths参数设置列文本间隙距离
This commit is contained in:
@@ -79,6 +79,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2025.03.02) 增加`Tooltip`的`columnGapWidths`参数设置列文本间隙距离
|
||||||
* (2025.03.01) 优化`Comment`的组件刷新
|
* (2025.03.01) 优化`Comment`的组件刷新
|
||||||
* (2025.02.23) 增加`Axis`的`Label`的`formatter`支持`{index}``{index-1}``{-index}``{-index-1}`通配符
|
* (2025.02.23) 增加`Axis`的`Label`的`formatter`支持`{index}``{index-1}``{-index}``{-index-1}`通配符
|
||||||
* (2025.02.23) 增加`Bar`的`realtimeSort`支持实时排序
|
* (2025.02.23) 增加`Bar`的`realtimeSort`支持实时排序
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ namespace XCharts.Editor
|
|||||||
});
|
});
|
||||||
PropertyField("m_LineStyle");
|
PropertyField("m_LineStyle");
|
||||||
PropertyField("m_TitleLabelStyle");
|
PropertyField("m_TitleLabelStyle");
|
||||||
|
PropertyListField("m_ColumnGapWidths");
|
||||||
PropertyListField("m_ContentLabelStyles");
|
PropertyListField("m_ContentLabelStyles");
|
||||||
--EditorGUI.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField] private float m_TitleHeight = 25f;
|
[SerializeField] private float m_TitleHeight = 25f;
|
||||||
[SerializeField] private float m_ItemHeight = 25f;
|
[SerializeField] private float m_ItemHeight = 25f;
|
||||||
[SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
|
[SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
|
||||||
|
[SerializeField][Since("v3.14.0")] private List<float> m_ColumnGapWidths = new List<float>{15};
|
||||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
|
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private LabelStyle m_TitleLabelStyle = new LabelStyle()
|
private LabelStyle m_TitleLabelStyle = new LabelStyle()
|
||||||
@@ -453,6 +454,15 @@ namespace XCharts.Runtime
|
|||||||
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// the column gap width of content. When there is only one column, it only represents the gap width of the second column.
|
||||||
|
/// ||内容部分的列间距。当只有一列时,只表示第二列的间距。
|
||||||
|
/// </summary>
|
||||||
|
public List<float> columnGapWidths
|
||||||
|
{
|
||||||
|
get { return m_ColumnGapWidths; }
|
||||||
|
set { if (value != null) { m_ColumnGapWidths = value; SetComponentDirty(); } }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// the textstyle of title.
|
/// the textstyle of title.
|
||||||
/// ||标题的文本样式。
|
/// ||标题的文本样式。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -462,8 +472,8 @@ namespace XCharts.Runtime
|
|||||||
set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } }
|
set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the textstyle list of content.
|
/// the column text style list of content. The first represents the text style of the first column, and so on.
|
||||||
/// ||内容部分的文本样式列表。和列一一对应。
|
/// ||内容部分的列文本样式列表。第一个表示第一列的文本样式,以此类推。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<LabelStyle> contentLabelStyles
|
public List<LabelStyle> contentLabelStyles
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ namespace XCharts.Runtime
|
|||||||
ChartHelper.SetActive(gameObject, m_Active);
|
ChartHelper.SetActive(gameObject, m_Active);
|
||||||
if (!flag)
|
if (!flag)
|
||||||
{
|
{
|
||||||
|
m_ColumnMaxWidth.Clear();
|
||||||
foreach (var item in m_Items)
|
foreach (var item in m_Items)
|
||||||
item.gameObject.SetActive(false);
|
item.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
@@ -75,8 +76,6 @@ namespace XCharts.Runtime
|
|||||||
ChartHelper.SetActive(title, titleActive);
|
ChartHelper.SetActive(title, titleActive);
|
||||||
title.SetText(data.title);
|
title.SetText(data.title);
|
||||||
|
|
||||||
m_ColumnMaxWidth.Clear();
|
|
||||||
var contentLabelStyle0 = tooltip.GetContentLabelStyle(0);
|
|
||||||
for (int i = 0; i < data.param.Count; i++)
|
for (int i = 0; i < data.param.Count; i++)
|
||||||
{
|
{
|
||||||
var item = GetItem(i);
|
var item = GetItem(i);
|
||||||
@@ -93,13 +92,17 @@ namespace XCharts.Runtime
|
|||||||
column.SetActive(true);
|
column.SetActive(true);
|
||||||
column.SetText(param.columns[j]);
|
column.SetText(param.columns[j]);
|
||||||
|
|
||||||
if (j == 0 && contentLabelStyle0 != null && ChartHelper.IsClearColor(contentLabelStyle0.textStyle.color))
|
if (j == 0)
|
||||||
|
{
|
||||||
|
var labelStyle = tooltip.GetContentLabelStyle(j);
|
||||||
|
if (labelStyle != null && ChartHelper.IsClearColor(labelStyle.textStyle.color))
|
||||||
column.text.SetColor(param.color);
|
column.text.SetColor(param.color);
|
||||||
|
}
|
||||||
|
|
||||||
if (j >= m_ColumnMaxWidth.Count)
|
if (j >= m_ColumnMaxWidth.Count)
|
||||||
m_ColumnMaxWidth.Add(0);
|
m_ColumnMaxWidth.Add(0);
|
||||||
|
|
||||||
var columnWidth = column.GetWidth();
|
var columnWidth = column.text.GetPreferredWidth() + GetTooltipColumnGapWidth(tooltip, j);
|
||||||
if (m_ColumnMaxWidth[j] < columnWidth)
|
if (m_ColumnMaxWidth[j] < columnWidth)
|
||||||
m_ColumnMaxWidth[j] = columnWidth;
|
m_ColumnMaxWidth[j] = columnWidth;
|
||||||
}
|
}
|
||||||
@@ -117,6 +120,17 @@ namespace XCharts.Runtime
|
|||||||
tooltip.gameObject.transform.SetAsLastSibling();
|
tooltip.gameObject.transform.SetAsLastSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static float GetTooltipColumnGapWidth(Tooltip tooltip, int index)
|
||||||
|
{
|
||||||
|
if (tooltip == null || tooltip.columnGapWidths.Count == 0) return 0;
|
||||||
|
if (tooltip.columnGapWidths.Count == 1) return index == 1 ? tooltip.columnGapWidths[0] : 0;
|
||||||
|
if (index < tooltip.columnGapWidths.Count)
|
||||||
|
{
|
||||||
|
return tooltip.columnGapWidths[index];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool IsSecondaryMark(SerieParams sp, string mark)
|
private static bool IsSecondaryMark(SerieParams sp, string mark)
|
||||||
{
|
{
|
||||||
return sp.isSecondaryMark && mark == sp.marker;
|
return sp.isSecondaryMark && mark == sp.marker;
|
||||||
|
|||||||
Reference in New Issue
Block a user