diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index b92fada9..9bf7e99f 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -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`参数控制是否超出坐标系外裁剪(只适用于折线图、柱状图、散点图) diff --git a/Assets/XCharts/Documentation/XCharts配置项手册.md b/Assets/XCharts/Documentation/XCharts配置项手册.md index 253e70b0..20ce7445 100644 --- a/Assets/XCharts/Documentation/XCharts配置项手册.md +++ b/Assets/XCharts/Documentation/XCharts配置项手册.md @@ -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时才采用科学计数法。 diff --git a/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs index 3403b001..138055b8 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs @@ -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; diff --git a/Assets/XCharts/Runtime/Component/Main/Tooltip.cs b/Assets/XCharts/Runtime/Component/Main/Tooltip.cs index 131a0bbb..062229ee 100644 --- a/Assets/XCharts/Runtime/Component/Main/Tooltip.cs +++ b/Assets/XCharts/Runtime/Component/Main/Tooltip.cs @@ -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 lastDataIndex { get; set; } /// @@ -116,7 +119,7 @@ namespace XCharts /// 示例:"{a}:{c}","{a}:{c:f1}" /// public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } } - + /// /// 固定宽度。比 minWidth 优先。 /// @@ -148,6 +151,16 @@ namespace XCharts /// public bool forceENotation { get { return m_ForceENotation; } set { m_ForceENotation = value; } } /// + /// the text padding of left and right. defaut:5. + /// 左右边距。 + /// + public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } } + /// + /// the text padding of top and bottom. defaut:5. + /// 上下边距。 + /// + public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } } + /// /// 指示线样式。 /// 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(); m_ContentText = m_Content.GetComponentInChildren(); + if (m_ContentText != null) + { + m_ContentTextRect = m_ContentText.gameObject.GetComponentInChildren(); + } } /// @@ -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)) {