mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 06:50:18 +00:00
增加SerieLabel的autoOffset参数设置是否自动判断上下偏移
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2020.06.04) 增加`SerieLabel`的`autoOffset`参数设置是否自动判断上下偏移
|
||||
* (2020.06.04) 增加`Tooltip`的`alwayShow`参数设置触发后一直显示
|
||||
* (2020.06.04) 优化`Tooltip`的`formatter`支持`{.1}`通配符
|
||||
* (2020.06.04) 优化`Legend`数量过多时自动换行显示
|
||||
|
||||
@@ -854,6 +854,7 @@
|
||||
* `formatter`:标签内容字符串模版格式器。支持用 `\n` 换行。模板变量有:`{a}`:系列名;`{b}`:数据名;`{c}`:数据值;`{d}`:百分比。示例:`{b}:{c}`。
|
||||
* `numericFormatter`:标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式:`A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`。
|
||||
* `offset`:距离图形元素的偏移。
|
||||
* `autoOffset`:是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
|
||||
* `color`:自定义文字颜色,默认和系列的颜色一致。
|
||||
* `backgroundColor`:标签的背景色,默认无颜色。
|
||||
* `backgroundWidth`:标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace XCharts
|
||||
SerializedProperty m_BorderWidth = prop.FindPropertyRelative("m_BorderWidth");
|
||||
SerializedProperty m_BorderColor = prop.FindPropertyRelative("m_BorderColor");
|
||||
SerializedProperty m_NumericFormatter = prop.FindPropertyRelative("m_NumericFormatter");
|
||||
SerializedProperty m_AutoOffset = prop.FindPropertyRelative("m_AutoOffset");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieLabelToggle, prop, null, show, false);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
@@ -56,6 +57,8 @@ namespace XCharts
|
||||
EditorGUI.PropertyField(drawRect, m_Offset);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
|
||||
|
||||
EditorGUI.PropertyField(drawRect, m_AutoOffset);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Margin);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Formatter);
|
||||
@@ -107,7 +110,7 @@ namespace XCharts
|
||||
float height = 0;
|
||||
if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop))
|
||||
{
|
||||
height += 23 * EditorGUIUtility.singleLineHeight + 22 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += 24 * EditorGUIUtility.singleLineHeight + 23 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -102,6 +102,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_BorderWidth = 0.5f;
|
||||
[SerializeField] private Color m_BorderColor = Color.grey;
|
||||
[SerializeField] private string m_NumericFormatter = "";
|
||||
[SerializeField] private bool m_AutoOffset = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the label is showed.
|
||||
@@ -332,5 +333,13 @@ namespace XCharts
|
||||
get { return m_NumericFormatter; }
|
||||
set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
|
||||
/// </summary>
|
||||
public bool autoOffset
|
||||
{
|
||||
get { return m_AutoOffset; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,7 +816,8 @@ namespace XCharts
|
||||
if (serieData == null || serieData.labelObject == null) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (!serieLabel.show) return;
|
||||
var invert = serie.type == SerieType.Line
|
||||
var invert = serieLabel.autoOffset
|
||||
&& serie.type == SerieType.Line
|
||||
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
||||
&& !serie.areaStyle.show;
|
||||
var centerPos = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
|
||||
|
||||
@@ -1511,7 +1511,10 @@ namespace XCharts
|
||||
content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, serieLabel);
|
||||
}
|
||||
serieData.SetLabelActive(value != 0 && serieData.labelPosition != Vector3.zero);
|
||||
var invert = serie.type == SerieType.Line && SerieHelper.IsDownPoint(serie, j) && !serie.areaStyle.show;
|
||||
var invert = serieLabel.autoOffset
|
||||
&& serie.type == SerieType.Line
|
||||
&& SerieHelper.IsDownPoint(serie, j)
|
||||
&& !serie.areaStyle.show;
|
||||
serieData.labelObject.SetLabelPosition(invert ? -serieLabel.offset : serieLabel.offset);
|
||||
if (serieData.labelObject.SetText(content)) RefreshChart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user