mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 23:10:06 +00:00
增加Tooltip的columnGapWidths参数设置列文本间隙距离
This commit is contained in:
@@ -60,6 +60,7 @@ namespace XCharts.Runtime
|
||||
ChartHelper.SetActive(gameObject, m_Active);
|
||||
if (!flag)
|
||||
{
|
||||
m_ColumnMaxWidth.Clear();
|
||||
foreach (var item in m_Items)
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
@@ -75,8 +76,6 @@ namespace XCharts.Runtime
|
||||
ChartHelper.SetActive(title, titleActive);
|
||||
title.SetText(data.title);
|
||||
|
||||
m_ColumnMaxWidth.Clear();
|
||||
var contentLabelStyle0 = tooltip.GetContentLabelStyle(0);
|
||||
for (int i = 0; i < data.param.Count; i++)
|
||||
{
|
||||
var item = GetItem(i);
|
||||
@@ -93,13 +92,17 @@ namespace XCharts.Runtime
|
||||
column.SetActive(true);
|
||||
column.SetText(param.columns[j]);
|
||||
|
||||
if (j == 0 && contentLabelStyle0 != null && ChartHelper.IsClearColor(contentLabelStyle0.textStyle.color))
|
||||
column.text.SetColor(param.color);
|
||||
if (j == 0)
|
||||
{
|
||||
var labelStyle = tooltip.GetContentLabelStyle(j);
|
||||
if (labelStyle != null && ChartHelper.IsClearColor(labelStyle.textStyle.color))
|
||||
column.text.SetColor(param.color);
|
||||
}
|
||||
|
||||
if (j >= m_ColumnMaxWidth.Count)
|
||||
m_ColumnMaxWidth.Add(0);
|
||||
|
||||
var columnWidth = column.GetWidth();
|
||||
var columnWidth = column.text.GetPreferredWidth() + GetTooltipColumnGapWidth(tooltip, j);
|
||||
if (m_ColumnMaxWidth[j] < columnWidth)
|
||||
m_ColumnMaxWidth[j] = columnWidth;
|
||||
}
|
||||
@@ -117,6 +120,17 @@ namespace XCharts.Runtime
|
||||
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)
|
||||
{
|
||||
return sp.isSecondaryMark && mark == sp.marker;
|
||||
@@ -163,7 +177,7 @@ namespace XCharts.Runtime
|
||||
var xPos = 0f;
|
||||
for (int j = 0; j < m_ColumnMaxWidth.Count; j++)
|
||||
{
|
||||
if(j >= item.columns.Count) break;
|
||||
if (j >= item.columns.Count) break;
|
||||
var deltaX = j == m_ColumnMaxWidth.Count - 1 ? maxWid - xPos : m_ColumnMaxWidth[j];
|
||||
item.columns[j].text.SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
|
||||
item.columns[j].SetSize(deltaX, tooltip.itemHeight);
|
||||
|
||||
Reference in New Issue
Block a user