diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f1b8834..d7afcae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,8 @@ ## master +* (2022.08.25) 增加`Tooltip`的`position`参数支持设置移动平台不同的显示位置 +* (2022.08.25) 删除`Tooltip`的`fixedXEnable`和`fixedYEnable`参数 * (2022.08.25) 优化`EmphasisStyle`对`label`的支持 * (2022.08.25) 增加`formatter`对`{d3}`指定维度数据百分比的支持 * (2022.08.24) 修复`ScatterChart`的`label`不刷新的问题 diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index ed930332..7a696b8a 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -1422,6 +1422,7 @@ Tooltip component. |`show`|true||Whether to show the tooltip component. |`type`|||Indicator type.
`Tooltip.Type`:
- `Line`: line indicator.
- `Shadow`: shadow crosshair indicator.
- `None`: no indicator displayed.
- `Corss`: crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
| |`trigger`|||Type of triggering.
`Tooltip.Trigger`:
- `Item`: Triggered by data item, which is mainly used for charts that don't have a category axis like scatter charts or pie charts.
- `Axis`: Triggered by axes, which is mainly used for charts that have category axes, like bar charts or line charts.
- `None`: Trigger nothing.
| +|`position`||v3.3.0|Type of position.
`Tooltip.Position`:
- `Auto`: Auto. The mobile platform is displayed at the top, and the non-mobile platform follows the mouse position.
- `Custom`: Custom. Fully customize display position (x,y).
- `FixedX`: Just fix the coordinate X. Y follows the mouse position.
- `FixedY`:
| |`itemFormatter`|||a string template formatter for a single Serie or data item content. Support for wrapping lines with \n. Template variables are {.}, {a}, {b}, {c}, {d}.
{.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.
{a} is the series name of the serie that is currently indicated or whose index is 0.
{b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
{c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
{d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
{e} is the name of the data item serieData that is currently indicated or whose index is 0.
{f} is sum of data.
{.1} represents a dot from serie corresponding color that specifies index as 1.
1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
{c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
{c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify).
{d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).
{d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).
Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"
|`titleFormatter`|||The string template formatter for the tooltip title content. Support for wrapping lines with \n. The placeholder {I} can be set separately to indicate that the title is ignored and not displayed. Template see itemFormatter. |`marker`|||the marker of serie. @@ -1441,10 +1442,8 @@ Tooltip component. |`backgroundType`|||The background type of tooltip. |`backgroundColor`|||The background color of tooltip. |`borderWidth`|2f||the width of tooltip border. -|`fixedXEnable`|false||enable fixedX. |`fixedX`|0f||the x positionn of fixedX. -|`fixedYEnable`|false||enable fixedY. -|`fixedY`|0f||the y position of fixedY. +|`fixedY`|0.7f||the y position of fixedY. |`titleHeight`|25f||height of title text. |`itemHeight`|25f||height of content text. |`borderColor`|Color32(230, 230, 230, 255)||the color of tooltip border. diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index fbeed47d..effc6b6b 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -1422,6 +1422,7 @@ Inherits or Implemented: [MainComponent](#MainComponent) |`show`|true||是否显示提示框组件。 |`type`|||提示框指示器类型。
`Tooltip.Type`:
- `Line`: 直线指示器
- `Shadow`: 阴影指示器
- `None`: 无指示器
- `Corss`: 十字准星指示器。坐标轴显示Label和交叉线。
| |`trigger`|||触发类型。
`Tooltip.Trigger`:
- `Item`: 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。
- `Axis`: 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
- `None`: 什么都不触发。
| +|`position`||v3.3.0|显示位置类型。
`Tooltip.Position`:
- `Auto`: 自适应。移动平台靠顶部显示,非移动平台跟随鼠标位置。
- `Custom`: 自定义。完全自定义显示位置(x,y)。
- `FixedX`: 只固定坐标X。Y跟随鼠标位置。
- `FixedY`:
| |`itemFormatter`|||提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。用 |`titleFormatter`|||提示框标题内容的字符串模版格式器。支持用 \n 换行。可以单独设置占位符{i}表示忽略不显示title。 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。
{.}为当前所指示或index为0的serie的对应颜色的圆点。
{a}为当前所指示或index为0的serie的系列名name。
{b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。
{c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。
{d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。
{e}为当前所指示或index为0的serie的数据项serieData的name。
{f}为数据总和。
{g}为数据总个数。
{.1}表示指定index为1的serie对应颜色的圆点。
{a1}、{b1}、{c1}中的1表示指定index为1的serie。
{c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。
{c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。
{d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。
{d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。
示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}" |`marker`|||serie的符号标志。 @@ -1441,10 +1442,8 @@ Inherits or Implemented: [MainComponent](#MainComponent) |`backgroundType`|||提示框的背景图片显示类型。 |`backgroundColor`|||提示框的背景颜色。 |`borderWidth`|2f||边框线宽。 -|`fixedXEnable`|false||是否固定X位置。 |`fixedX`|0f||固定X位置的坐标。 -|`fixedYEnable`|false||是否固定Y位置。 -|`fixedY`|0f||固定Y位置的坐标。 +|`fixedY`|0.7f||固定Y位置的坐标。 |`titleHeight`|25f||标题文本的高。 |`itemHeight`|25f||数据项文本的高。 |`borderColor`|Color32(230, 230, 230, 255)||边框颜色。 diff --git a/Editor/MainComponents/TooltipEditor.cs b/Editor/MainComponents/TooltipEditor.cs index af7b4344..c657d8fe 100644 --- a/Editor/MainComponents/TooltipEditor.cs +++ b/Editor/MainComponents/TooltipEditor.cs @@ -11,6 +11,10 @@ namespace XCharts.Editor ++EditorGUI.indentLevel; PropertyField("m_Type"); PropertyField("m_Trigger"); + PropertyField("m_Position"); + PropertyField("m_FixedX"); + PropertyField("m_FixedY"); + PropertyField("m_Offset"); PropertyField("m_ShowContent"); PropertyField("m_AlwayShowContent"); PropertyField("m_TitleFormatter"); @@ -33,11 +37,6 @@ namespace XCharts.Editor PropertyField("m_MinWidth"); PropertyField("m_MinHeight"); PropertyField("m_IgnoreDataDefaultContent"); - PropertyField("m_Offset"); - PropertyField("m_FixedXEnable"); - PropertyField("m_FixedX"); - PropertyField("m_FixedYEnable"); - PropertyField("m_FixedY"); }); PropertyField("m_LineStyle"); PropertyField("m_IndicatorLabelStyle"); diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs index 948e06f6..b882e057 100644 --- a/Runtime/Component/Tooltip/Tooltip.cs +++ b/Runtime/Component/Tooltip/Tooltip.cs @@ -42,6 +42,10 @@ namespace XCharts.Runtime Corss } + /// + /// Trigger strategy. + /// |触发类型。 + /// public enum Trigger { /// @@ -60,10 +64,37 @@ namespace XCharts.Runtime /// None } + /// + /// Position type. + /// |坐标类型。 + /// + public enum Position + { + /// + /// Auto. The mobile platform is displayed at the top, and the non-mobile platform follows the mouse position. + /// |自适应。移动平台靠顶部显示,非移动平台跟随鼠标位置。 + /// + Auto, + /// + /// Custom. Fully customize display position (x,y). + /// |自定义。完全自定义显示位置(x,y)。 + /// + Custom, + /// + /// Just fix the coordinate X. Y follows the mouse position. + /// |只固定坐标X。Y跟随鼠标位置。 + /// + FixedX, + /// + /// Just fix the coordinate Y. X follows the mouse position. + /// |只固定坐标Y。X跟随鼠标位置。 + FixedY + } [SerializeField] private bool m_Show = true; [SerializeField] private Type m_Type; [SerializeField] private Trigger m_Trigger = Trigger.Item; + [SerializeField][Since("v3.3.0")] private Position m_Position = Position.Auto; [SerializeField] private string m_ItemFormatter; [SerializeField] private string m_TitleFormatter; [SerializeField] private string m_Marker = "●"; @@ -83,10 +114,8 @@ namespace XCharts.Runtime [SerializeField] private Image.Type m_BackgroundType = Image.Type.Simple; [SerializeField] private Color m_BackgroundColor; [SerializeField] private float m_BorderWidth = 2f; - [SerializeField] private bool m_FixedXEnable = false; [SerializeField] private float m_FixedX = 0f; - [SerializeField] private bool m_FixedYEnable = false; - [SerializeField] private float m_FixedY = 0f; + [SerializeField] private float m_FixedY = 0.7f; [SerializeField] private float m_TitleHeight = 25f; [SerializeField] private float m_ItemHeight = 25f; [SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255); @@ -136,6 +165,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Trigger, value)) SetAllDirty(); } } /// + /// Type of position. + /// |显示位置类型。 + /// + public Position position + { + get { return m_Position; } + set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); } + } + /// /// The string template formatter for the tooltip title content. Support for wrapping lines with \n. /// The placeholder {I} can be set separately to indicate that the title is ignored and not displayed. /// Template see itemFormatter. @@ -304,15 +342,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); } } /// - /// enable fixedX. - /// |是否固定X位置。 - /// - public bool fixedXEnable - { - get { return m_FixedXEnable; } - set { if (PropertyUtil.SetStruct(ref m_FixedXEnable, value)) SetVerticesDirty(); } - } - /// /// the x positionn of fixedX. /// |固定X位置的坐标。 /// @@ -322,15 +351,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_FixedX, value)) SetVerticesDirty(); } } /// - /// enable fixedY. - /// |是否固定Y位置。 - /// - public bool fixedYEnable - { - get { return m_FixedYEnable; } - set { if (PropertyUtil.SetStruct(ref m_FixedYEnable, value)) SetVerticesDirty(); } - } - /// /// the y position of fixedY. /// |固定Y位置的坐标。 /// @@ -468,12 +488,29 @@ namespace XCharts.Runtime /// 更新文本框位置 /// /// - public void UpdateContentPos(Vector2 pos) + public void UpdateContentPos(Vector2 pos, float width, float height) { if (view != null) { - if (fixedXEnable) pos.x = fixedX; - if (fixedYEnable) pos.y = fixedY; + switch (m_Position) + { + case Position.Auto: +#if UNITY_ANDROID || UNITY_IOS + if (m_FixedY == 0) pos.y = ChartHelper.GetActualValue(0.7f, height); + else pos.y = ChartHelper.GetActualValue(m_FixedY, height); +#endif + break; + case Position.Custom: + pos.x = ChartHelper.GetActualValue(m_FixedX, width); + pos.y = ChartHelper.GetActualValue(m_FixedY, height); + break; + case Position.FixedX: + pos.x = ChartHelper.GetActualValue(m_FixedX, width); + break; + case Position.FixedY: + pos.y = ChartHelper.GetActualValue(m_FixedY, height); + break; + } view.UpdatePosition(pos); } } diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index f0dd53d6..8f9d729d 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -77,7 +77,7 @@ namespace XCharts.Runtime } if (pos.y > chartRect.y + chartRect.height) pos.y = chartRect.y + chartRect.height; - tooltip.UpdateContentPos(pos); + tooltip.UpdateContentPos(pos, chartRect.width / 2, chartRect.height / 2); } public static string GetItemNumericFormatter(Tooltip tooltip, Serie serie, SerieData serieData)