mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-29 20:58:47 +00:00
优化Tooltip的对齐方式
This commit is contained in:
@@ -79,6 +79,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2025.02.18) 优化`Tooltip`的对齐方式
|
||||||
* (2025.02.09) 修复`SaveAsImage`保存图片时不支持透明度的问题 (#337)
|
* (2025.02.09) 修复`SaveAsImage`保存图片时不支持透明度的问题 (#337)
|
||||||
* (2025.02.05) 增加`GraphChart`可单独设置`data`样式的支持
|
* (2025.02.05) 增加`GraphChart`可单独设置`data`样式的支持
|
||||||
* (2025.02.05) 重构`SerieSymbol`的`sizeFunction`参数
|
* (2025.02.05) 重构`SerieSymbol`的`sizeFunction`参数
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private List<LabelStyle> m_ContentLabelStyles = new List<LabelStyle>()
|
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, 5, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleCenter } },
|
||||||
new LabelStyle() { textPadding = new TextPadding(0, 20, 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 } }
|
new LabelStyle() { textPadding = new TextPadding(0, 0, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight } }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace XCharts.Runtime
|
|||||||
item.gameObject.SetActive(true);
|
item.gameObject.SetActive(true);
|
||||||
for (int j = 0; j < param.columns.Count; j++)
|
for (int j = 0; j < param.columns.Count; j++)
|
||||||
{
|
{
|
||||||
var column = GetItemColumn(item, j);
|
var column = GetItemColumn(item, j, j == 0 && IsSecondaryMark(param, param.columns[j]));
|
||||||
column.SetActive(true);
|
column.SetActive(true);
|
||||||
column.SetText(param.columns[j]);
|
column.SetText(param.columns[j]);
|
||||||
|
|
||||||
@@ -117,6 +117,11 @@ namespace XCharts.Runtime
|
|||||||
tooltip.gameObject.transform.SetAsLastSibling();
|
tooltip.gameObject.transform.SetAsLastSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsSecondaryMark(SerieParams sp, string mark)
|
||||||
|
{
|
||||||
|
return sp.isSecondaryMark && mark == sp.marker;
|
||||||
|
}
|
||||||
|
|
||||||
private void ResetSize()
|
private void ResetSize()
|
||||||
{
|
{
|
||||||
var maxHig = 0f;
|
var maxHig = 0f;
|
||||||
@@ -158,8 +163,10 @@ namespace XCharts.Runtime
|
|||||||
var xPos = 0f;
|
var xPos = 0f;
|
||||||
for (int j = 0; j < m_ColumnMaxWidth.Count; j++)
|
for (int j = 0; j < m_ColumnMaxWidth.Count; j++)
|
||||||
{
|
{
|
||||||
|
if(j >= item.columns.Count) break;
|
||||||
var deltaX = j == m_ColumnMaxWidth.Count - 1 ? maxWid - xPos : m_ColumnMaxWidth[j];
|
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].text.SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
|
||||||
|
item.columns[j].SetSize(deltaX, tooltip.itemHeight);
|
||||||
item.columns[j].SetRectPosition(new Vector3(xPos, 0));
|
item.columns[j].SetRectPosition(new Vector3(xPos, 0));
|
||||||
xPos += m_ColumnMaxWidth[j];
|
xPos += m_ColumnMaxWidth[j];
|
||||||
}
|
}
|
||||||
@@ -192,19 +199,24 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChartLabel GetItemColumn(TooltipViewItem item, int i)
|
private ChartLabel GetItemColumn(TooltipViewItem item, int i, bool isSecondaryMark = false)
|
||||||
{
|
{
|
||||||
if (i < 0) i = 0;
|
if (i < 0) i = 0;
|
||||||
|
ChartLabel column;
|
||||||
if (i < item.columns.Count)
|
if (i < item.columns.Count)
|
||||||
{
|
{
|
||||||
return item.columns[i];
|
column = item.columns[i];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var column = CreateViewItemColumn(i, item.gameObject.transform, tooltip, theme);
|
column = CreateViewItemColumn(i, item.gameObject.transform, tooltip, theme);
|
||||||
item.columns.Add(column);
|
item.columns.Add(column);
|
||||||
return column;
|
|
||||||
}
|
}
|
||||||
|
if (isSecondaryMark)
|
||||||
|
{
|
||||||
|
column.text.text.fontSize = (int)(tooltip.GetContentLabelStyle(i).textStyle.fontSize * 0.6f);
|
||||||
|
}
|
||||||
|
return column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TooltipView CreateView(Tooltip tooltip, ThemeStyle theme, Transform parent)
|
public static TooltipView CreateView(Tooltip tooltip, ThemeStyle theme, Transform parent)
|
||||||
@@ -266,8 +278,9 @@ namespace XCharts.Runtime
|
|||||||
private static ChartLabel CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme)
|
private static ChartLabel CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme)
|
||||||
{
|
{
|
||||||
var labelStyle = tooltip.GetContentLabelStyle(i);
|
var labelStyle = tooltip.GetContentLabelStyle(i);
|
||||||
|
labelStyle.textStyle.autoAlign = false;
|
||||||
var label = ChartHelper.AddChartLabel("column" + i, parent, labelStyle, theme,
|
var label = ChartHelper.AddChartLabel("column" + i, parent, labelStyle, theme,
|
||||||
"", Color.clear, TextAnchor.MiddleLeft);
|
"", Color.clear, TextAnchor.MiddleLeft, true);
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ namespace XCharts.Runtime
|
|||||||
serie.index = i;
|
serie.index = i;
|
||||||
SetPainterActive(i, true);
|
SetPainterActive(i, true);
|
||||||
}
|
}
|
||||||
if (transform.childCount - 3 != m_PainterTop.transform.GetSiblingIndex())
|
if (m_PainterTop != null && transform.childCount - 3 != m_PainterTop.transform.GetSiblingIndex())
|
||||||
{
|
{
|
||||||
m_PainterTop.transform.SetSiblingIndex(transform.childCount - 3);
|
m_PainterTop.transform.SetSiblingIndex(transform.childCount - 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
if (!s_ColorDotStr.ContainsKey(color))
|
if (!s_ColorDotStr.ContainsKey(color))
|
||||||
{
|
{
|
||||||
s_ColorDotStr[color] = "<color=#" + ColorToStr(color) + ">● </color>";
|
s_ColorDotStr[color] = "<color=#" + ColorToStr(color) + ">●</color>";
|
||||||
}
|
}
|
||||||
return s_ColorDotStr[color];
|
return s_ColorDotStr[color];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -468,16 +468,21 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ChartLabel AddChartLabel(string name, Transform parent, LabelStyle labelStyle,
|
public static ChartLabel AddChartLabel(string name, Transform parent, LabelStyle labelStyle,
|
||||||
ComponentTheme theme, string content, Color autoColor, TextAnchor autoAlignment = TextAnchor.MiddleCenter)
|
ComponentTheme theme, string content, Color autoColor, TextAnchor autoAlignment = TextAnchor.MiddleCenter,
|
||||||
|
bool isObjectAnchor = false)
|
||||||
{
|
{
|
||||||
Vector2 anchorMin, anchorMax, pivot;
|
Vector2 anchorMin, anchorMax, pivot;
|
||||||
var sizeDelta = new Vector2(labelStyle.width, labelStyle.height);
|
var sizeDelta = new Vector2(labelStyle.width, labelStyle.height);
|
||||||
var textStyle = labelStyle.textStyle;
|
var textStyle = labelStyle.textStyle;
|
||||||
var alignment = textStyle.GetAlignment(autoAlignment);
|
var alignment = isObjectAnchor ? autoAlignment : textStyle.GetAlignment(autoAlignment);
|
||||||
UpdateAnchorAndPivotByTextAlignment(alignment, out anchorMin, out anchorMax, out pivot);
|
UpdateAnchorAndPivotByTextAlignment(alignment, out anchorMin, out anchorMax, out pivot);
|
||||||
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||||
//ChartHelper.RemoveComponent<Text>(labelObj);
|
//ChartHelper.RemoveComponent<Text>(labelObj);
|
||||||
var label = EnsureComponent<ChartLabel>(labelObj);
|
var label = EnsureComponent<ChartLabel>(labelObj);
|
||||||
|
if(isObjectAnchor)
|
||||||
|
{
|
||||||
|
UpdateAnchorAndPivotByTextAlignment(textStyle.GetAlignment(autoAlignment), out anchorMin, out anchorMax, out pivot);
|
||||||
|
}
|
||||||
label.text = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot,
|
label.text = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot,
|
||||||
sizeDelta, textStyle, theme, autoColor, autoAlignment, label.text);
|
sizeDelta, textStyle, theme, autoColor, autoAlignment, label.text);
|
||||||
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, labelStyle.icon);
|
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, labelStyle.icon);
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ namespace XCharts.Runtime
|
|||||||
var newMarker = SerieHelper.GetItemMarker(serie, serieData, marker);
|
var newMarker = SerieHelper.GetItemMarker(serie, serieData, marker);
|
||||||
var newItemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter);
|
var newItemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter);
|
||||||
var newNumericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter);
|
var newNumericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter);
|
||||||
|
var isEmptyItemFormatter = string.IsNullOrEmpty(newItemFormatter);
|
||||||
|
|
||||||
|
if (isEmptyItemFormatter)
|
||||||
|
{
|
||||||
var param = serie.context.param;
|
var param = serie.context.param;
|
||||||
param.serieName = serie.serieName;
|
param.serieName = serie.serieName;
|
||||||
param.serieIndex = serie.index;
|
param.serieIndex = serie.index;
|
||||||
@@ -68,6 +71,7 @@ namespace XCharts.Runtime
|
|||||||
param.marker = newMarker;
|
param.marker = newMarker;
|
||||||
param.itemFormatter = newItemFormatter;
|
param.itemFormatter = newItemFormatter;
|
||||||
param.numericFormatter = newNumericFormatter;
|
param.numericFormatter = newNumericFormatter;
|
||||||
|
param.isSecondaryMark = true;
|
||||||
param.columns.Clear();
|
param.columns.Clear();
|
||||||
|
|
||||||
param.columns.Add(param.marker);
|
param.columns.Add(param.marker);
|
||||||
@@ -77,6 +81,30 @@ namespace XCharts.Runtime
|
|||||||
paramList.Add(param);
|
paramList.Add(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newItemFormatter = newItemFormatter.Replace("\\n", "\n");
|
||||||
|
var temp = newItemFormatter.Split('\n');
|
||||||
|
foreach (var str in temp)
|
||||||
|
{
|
||||||
|
var param = new SerieParams();
|
||||||
|
param.serieName = serie.serieName;
|
||||||
|
param.serieIndex = serie.index;
|
||||||
|
param.category = category;
|
||||||
|
param.serieData = serieData;
|
||||||
|
param.dataCount = serie.dataCount;
|
||||||
|
param.value = 0;
|
||||||
|
param.total = 0;
|
||||||
|
param.color = color;
|
||||||
|
param.marker = newMarker;
|
||||||
|
param.itemFormatter = str;
|
||||||
|
param.numericFormatter = newNumericFormatter;
|
||||||
|
param.isSecondaryMark = false;
|
||||||
|
param.columns.Clear();
|
||||||
|
paramList.Add(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie)
|
private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace XCharts.Runtime
|
|||||||
public int serieIndex;
|
public int serieIndex;
|
||||||
public string serieName;
|
public string serieName;
|
||||||
public string marker = "●";
|
public string marker = "●";
|
||||||
|
public bool isSecondaryMark;
|
||||||
public string category;
|
public string category;
|
||||||
public int dimension;
|
public int dimension;
|
||||||
public SerieData serieData;
|
public SerieData serieData;
|
||||||
|
|||||||
Reference in New Issue
Block a user