[improve][MarkLine] improve label

This commit is contained in:
monitor1394
2022-08-25 08:37:17 +08:00
parent 9e07fa1db3
commit 34dd3d1c4e
4 changed files with 14 additions and 7 deletions

View File

@@ -58,6 +58,9 @@
## master ## master
* (2022.08.24) 修复`ScatterChart``label`不刷新的问题
* (2022.08.24) 修复`MarkLine``label`某些情况下显示异常的问题
## v3.2.0 ## v3.2.0
### 版本要点 ### 版本要点

View File

@@ -35,8 +35,9 @@ namespace XCharts.Runtime
{ {
if (data.runtimeLabel != null) if (data.runtimeLabel != null)
{ {
data.runtimeLabel.SetActive(data.label.show); var pos = MarkLineHelper.GetLabelPosition(data);
data.runtimeLabel.SetPosition(MarkLineHelper.GetLabelPosition(data)); data.runtimeLabel.SetActive(data.label.show && pos != Vector3.zero);
data.runtimeLabel.SetPosition(pos);
data.runtimeLabel.SetText(MarkLineHelper.GetFormatterContent(serie, data)); data.runtimeLabel.SetText(MarkLineHelper.GetFormatterContent(serie, data));
} }
} }
@@ -76,10 +77,10 @@ namespace XCharts.Runtime
var content = MarkLineHelper.GetFormatterContent(serie, data); var content = MarkLineHelper.GetFormatterContent(serie, data);
var label = ChartHelper.AddChartLabel(textName, m_MarkLineLabelRoot.transform, data.label, chart.theme.axis, var label = ChartHelper.AddChartLabel(textName, m_MarkLineLabelRoot.transform, data.label, chart.theme.axis,
content, Color.clear, TextAnchor.MiddleCenter); content, Color.clear, TextAnchor.MiddleCenter);
var pos = MarkLineHelper.GetLabelPosition(data);
label.SetIconActive(false); label.SetIconActive(false);
label.SetActive(data.label.show); label.SetActive(data.label.show && pos != Vector3.zero);
label.SetPosition(MarkLineHelper.GetLabelPosition(data)); label.SetPosition(pos);
data.runtimeLabel = label; data.runtimeLabel = label;
}; };
data.refreshComponent(); data.refreshComponent();
@@ -202,8 +203,7 @@ namespace XCharts.Runtime
for (int i = 0; i < markLine.data.Count; i++) for (int i = 0; i < markLine.data.Count; i++)
{ {
var data = markLine.data[i]; var data = markLine.data[i];
// data.index = i; data.index = i;
data.index = markLine.index;
if (data.group == 0) continue; if (data.group == 0) continue;
if (!m_TempGroupData.ContainsKey(data.group)) if (!m_TempGroupData.ContainsKey(data.group))
{ {

View File

@@ -34,13 +34,16 @@ namespace XCharts.Runtime
switch (data.label.position) switch (data.label.position)
{ {
case LabelStyle.Position.Start: case LabelStyle.Position.Start:
if (data.runtimeStartPosition == Vector3.zero) return Vector3.zero;
if (horizontal) return data.runtimeStartPosition + data.label.offset + labelWidth / 2 * Vector3.left; if (horizontal) return data.runtimeStartPosition + data.label.offset + labelWidth / 2 * Vector3.left;
else return data.runtimeStartPosition + data.label.offset + labelHeight / 2 * Vector3.down; else return data.runtimeStartPosition + data.label.offset + labelHeight / 2 * Vector3.down;
case LabelStyle.Position.Middle: case LabelStyle.Position.Middle:
if (data.runtimeCurrentEndPosition == Vector3.zero) return Vector3.zero;
var center = (data.runtimeStartPosition + data.runtimeCurrentEndPosition) / 2; var center = (data.runtimeStartPosition + data.runtimeCurrentEndPosition) / 2;
if (horizontal) return center + data.label.offset + labelHeight / 2 * Vector3.up; if (horizontal) return center + data.label.offset + labelHeight / 2 * Vector3.up;
else return center + data.label.offset + labelWidth / 2 * Vector3.right; else return center + data.label.offset + labelWidth / 2 * Vector3.right;
default: default:
if (data.runtimeCurrentEndPosition == Vector3.zero) return Vector3.zero;
if (horizontal) return data.runtimeCurrentEndPosition + data.label.offset + labelWidth / 2 * Vector3.right; if (horizontal) return data.runtimeCurrentEndPosition + data.label.offset + labelWidth / 2 * Vector3.right;
else return data.runtimeCurrentEndPosition + data.label.offset + labelHeight / 2 * Vector3.up; else return data.runtimeCurrentEndPosition + data.label.offset + labelHeight / 2 * Vector3.up;
} }

View File

@@ -12,6 +12,7 @@ namespace XCharts.Runtime
public override void Update() public override void Update()
{ {
base.Update();
UpdateSerieContext(); UpdateSerieContext();
} }