增加TooltippaddingLeftRightpaddingTopBottom参数配置文字和边框的间距

This commit is contained in:
monitor1394
2020-02-11 21:01:01 +08:00
parent 695c2fe311
commit c73e1d6e3f
4 changed files with 37 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.02.11) 增加`Tooltip``paddingLeftRight``paddingTopBottom`参数配置文字和边框的间距
* (2020.02.11) 增加`Tooltip``lineStyle`参数配置指示线样式
* (2020.02.11) 增加`Axis``splitLine`参数控制分割线,去掉`showSplitLine``splitLineType`参数(更新时需要重新设置分割线相关设置)
* (2020.02.10) 增加`Serie``clip`参数控制是否超出坐标系外裁剪(只适用于折线图、柱状图、散点图)

View File

@@ -194,6 +194,8 @@
* `fixedHeight`:固定高度。当同时设置 `fixedHeight``minHeight` 时,`fixedHeight``minHeight` 优先级高。
* `minWidth`:最小宽度。当同时设置 `fixedWidth``minWidth` 时,`fixedWidth``minWidth` 优先级高。
* `minHeight`:最小高度。当同时设置 f`ixedHeight``minHeight` 时,`fixedHeight``minHeight` 优先级高。
* `paddingLeftRight`:文字和边框的左右边距。
* `paddingTopBottom`:文字和边框的上下边距。
* `fontSize`:文字的字体大小。
* `fontStyle`:文字的字体风格。
* `forceENotation`是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。

View File

@@ -31,6 +31,8 @@ namespace XCharts
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation");
SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight");
SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show);
@@ -54,6 +56,10 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MinHeight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_PaddingLeftRight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_PaddingTopBottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
@@ -69,7 +75,7 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (m_TooltipModuleToggle)
return 12 * EditorGUIUtility.singleLineHeight + 11 * EditorGUIUtility.standardVerticalSpacing +
return 14 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing +
EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
else
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

View File

@@ -58,12 +58,15 @@ namespace XCharts
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_ForceENotation = false;
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid,0.7f);
[SerializeField] private float m_PaddingLeftRight = 5f;
[SerializeField] private float m_PaddingTopBottom = 5f;
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid, 0.7f);
private GameObject m_GameObject;
private GameObject m_Content;
private Text m_ContentText;
private RectTransform m_ContentRect;
private RectTransform m_ContentTextRect;
private List<int> lastDataIndex { get; set; }
/// <summary>
@@ -116,7 +119,7 @@ namespace XCharts
/// 示例:"{a}:{c}","{a}:{c:f1}"
/// </summary>
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
/// <summary>
/// 固定宽度。比 minWidth 优先。
/// </summary>
@@ -148,6 +151,16 @@ namespace XCharts
/// </summary>
public bool forceENotation { get { return m_ForceENotation; } set { m_ForceENotation = value; } }
/// <summary>
/// the text padding of left and right. defaut:5.
/// 左右边距。
/// </summary>
public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
/// <summary>
/// the text padding of top and bottom. defaut:5.
/// 上下边距。
/// </summary>
public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } }
/// <summary>
/// 指示线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { if (value != null) m_LineStyle = value; } }
@@ -228,6 +241,10 @@ namespace XCharts
m_Content = content;
m_ContentRect = m_Content.GetComponent<RectTransform>();
m_ContentText = m_Content.GetComponentInChildren<Text>();
if (m_ContentText != null)
{
m_ContentTextRect = m_ContentText.gameObject.GetComponentInChildren<RectTransform>();
}
}
/// <summary>
@@ -274,11 +291,15 @@ namespace XCharts
float wid, hig;
if (m_FixedWidth > 0) wid = m_FixedWidth;
else if (m_MinWidth > 0 && m_ContentText.preferredWidth < m_MinWidth) wid = m_MinWidth;
else wid = m_ContentText.preferredWidth + 8;
else wid = m_ContentText.preferredWidth + m_PaddingLeftRight * 2;
if (m_FixedHeight > 0) hig = m_FixedHeight;
else if (m_MinHeight > 0 && m_ContentText.preferredHeight < m_MinHeight) hig = m_MinHeight;
else hig = m_ContentText.preferredHeight + 8;
m_ContentRect.sizeDelta = new Vector2(wid, hig);
else hig = m_ContentText.preferredHeight + m_PaddingTopBottom * 2;
if (m_ContentRect != null) m_ContentRect.sizeDelta = new Vector2(wid, hig);
if (m_ContentTextRect != null)
{
m_ContentTextRect.anchoredPosition = new Vector3(m_PaddingLeftRight, -m_PaddingTopBottom);
}
}
}
@@ -378,7 +399,7 @@ namespace XCharts
return string.IsNullOrEmpty(m_Formatter) && string.IsNullOrEmpty(m_ItemFormatter);
}
internal string GetFormatterContent(int dataIndex, Series series, string category,ThemeInfo themeInfo = null, DataZoom dataZoom = null)
internal string GetFormatterContent(int dataIndex, Series series, string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null)
{
if (string.IsNullOrEmpty(m_Formatter))
{