[feature][Tooltip] support position

This commit is contained in:
monitor1394
2022-08-26 07:50:48 +08:00
parent 442a51abc1
commit b2f1fd00b1
6 changed files with 72 additions and 36 deletions

View File

@@ -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`不刷新的问题

View File

@@ -1422,6 +1422,7 @@ Tooltip component.
|`show`|true||Whether to show the tooltip component.
|`type`|||Indicator type.</br>`Tooltip.Type`:</br>- `Line`: line indicator.</br>- `Shadow`: shadow crosshair indicator.</br>- `None`: no indicator displayed.</br>- `Corss`: crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.</br>|
|`trigger`|||Type of triggering.</br>`Tooltip.Trigger`:</br>- `Item`: Triggered by data item, which is mainly used for charts that don't have a category axis like scatter charts or pie charts.</br>- `Axis`: Triggered by axes, which is mainly used for charts that have category axes, like bar charts or line charts.</br>- `None`: Trigger nothing.</br>|
|`position`||v3.3.0|Type of position.</br>`Tooltip.Position`:</br>- `Auto`: Auto. The mobile platform is displayed at the top, and the non-mobile platform follows the mouse position.</br>- `Custom`: Custom. Fully customize display position (x,y).</br>- `FixedX`: Just fix the coordinate X. Y follows the mouse position.</br>- `FixedY`: </br>|
|`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}.</br> {.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.</br> {a} is the series name of the serie that is currently indicated or whose index is 0.</br> {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).</br> {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.</br> {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.</br> {e} is the name of the data item serieData that is currently indicated or whose index is 0.</br> {f} is sum of data.</br> {.1} represents a dot from serie corresponding color that specifies index as 1.</br> 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.</br> {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).</br> {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).</br> {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).</br> {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 ).</br> Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"</br>
|`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.

View File

@@ -1422,6 +1422,7 @@ Inherits or Implemented: [MainComponent](#MainComponent)
|`show`|true||是否显示提示框组件。
|`type`|||提示框指示器类型。</br>`Tooltip.Type`:</br>- `Line`: 直线指示器</br>- `Shadow`: 阴影指示器</br>- `None`: 无指示器</br>- `Corss`: 十字准星指示器。坐标轴显示Label和交叉线。</br>|
|`trigger`|||触发类型。</br>`Tooltip.Trigger`:</br>- `Item`: 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。</br>- `Axis`: 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。</br>- `None`: 什么都不触发。</br>|
|`position`||v3.3.0|显示位置类型。</br>`Tooltip.Position`:</br>- `Auto`: 自适应。移动平台靠顶部显示,非移动平台跟随鼠标位置。</br>- `Custom`: 自定义。完全自定义显示位置(x,y)。</br>- `FixedX`: 只固定坐标X。Y跟随鼠标位置。</br>- `FixedY`: </br>|
|`itemFormatter`|||提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。用
|`titleFormatter`|||提示框标题内容的字符串模版格式器。支持用 \n 换行。可以单独设置占位符{i}表示忽略不显示title。 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。</br> {.}为当前所指示或index为0的serie的对应颜色的圆点。</br> {a}为当前所指示或index为0的serie的系列名name。</br> {b}为当前所指示或index为0的serie的数据项serieData的name或者类目值如折线图的X轴。</br> {c}为当前所指示或index为0的serie的y维dimesion为1的数值。</br> {d}为当前所指示或index为0的serie的y维dimesion为1百分比值注意不带%号。</br> {e}为当前所指示或index为0的serie的数据项serieData的name。</br> {f}为数据总和。</br> {g}为数据总个数。</br> {.1}表示指定index为1的serie对应颜色的圆点。</br> {a1}、{b1}、{c1}中的1表示指定index为1的serie。</br> {c1:2}表示索引为1的serie的当前指示数据项的第3个数据一个数据项有多个数据index为2表示第3个数据。</br> {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据也就是要指定第几个数据项时必须要指定第几个数据。</br> {d1:2:f2}表示单独指定了数值的格式化字符串为f2不指定时用numericFormatter。</br> {d:0.##} 表示单独指定了数值的格式化字符串为 0.## 用于百分比保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。</br> 示例:"{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)||边框颜色。

View File

@@ -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");

View File

@@ -42,6 +42,10 @@ namespace XCharts.Runtime
Corss
}
/// <summary>
/// Trigger strategy.
/// |触发类型。
/// </summary>
public enum Trigger
{
/// <summary>
@@ -60,10 +64,37 @@ namespace XCharts.Runtime
/// </summary>
None
}
/// <summary>
/// Position type.
/// |坐标类型。
/// </summary>
public enum Position
{
/// <summary>
/// Auto. The mobile platform is displayed at the top, and the non-mobile platform follows the mouse position.
/// |自适应。移动平台靠顶部显示,非移动平台跟随鼠标位置。
/// </summary>
Auto,
/// <summary>
/// Custom. Fully customize display position (x,y).
/// |自定义。完全自定义显示位置(x,y)。
/// </summary>
Custom,
/// <summary>
/// Just fix the coordinate X. Y follows the mouse position.
/// |只固定坐标X。Y跟随鼠标位置。
/// </summary>
FixedX,
/// <summary>
/// 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(); }
}
/// <summary>
/// Type of position.
/// |显示位置类型。
/// </summary>
public Position position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); }
}
/// <summary>
/// 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(); }
}
/// <summary>
/// enable fixedX.
/// |是否固定X位置。
/// </summary>
public bool fixedXEnable
{
get { return m_FixedXEnable; }
set { if (PropertyUtil.SetStruct(ref m_FixedXEnable, value)) SetVerticesDirty(); }
}
/// <summary>
/// the x positionn of fixedX.
/// |固定X位置的坐标。
/// </summary>
@@ -322,15 +351,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_FixedX, value)) SetVerticesDirty(); }
}
/// <summary>
/// enable fixedY.
/// |是否固定Y位置。
/// </summary>
public bool fixedYEnable
{
get { return m_FixedYEnable; }
set { if (PropertyUtil.SetStruct(ref m_FixedYEnable, value)) SetVerticesDirty(); }
}
/// <summary>
/// the y position of fixedY.
/// |固定Y位置的坐标。
/// </summary>
@@ -468,12 +488,29 @@ namespace XCharts.Runtime
/// 更新文本框位置
/// </summary>
/// <param name="pos"></param>
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);
}
}

View File

@@ -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)