diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md
index 725b0bba..0424493e 100644
--- a/Documentation~/en/api.md
+++ b/Documentation~/en/api.md
@@ -31,6 +31,7 @@ slug: /api
- [DataZoomHelper](#datazoomhelper)
- [DateTimeUtil](#datetimeutil)
- [DefaultAnimationAttribute](#defaultanimationattribute)
+- [DefaultTooltipAttribute](#defaulttooltipattribute)
- [DefineSymbolsUtil](#definesymbolsutil)
- [FormatterHelper](#formatterhelper)
- [GridCoordContext](#gridcoordcontext)
@@ -609,6 +610,14 @@ slug: /api
|DefaultAnimationAttribute()||public DefaultAnimationAttribute(AnimationType handler)|
|DefaultAnimationAttribute()||public DefaultAnimationAttribute(AnimationType handler, bool enableSerieDataAddedAnimation)|
+## DefaultTooltipAttribute
+
+> XCharts.Runtime.DefaultTooltipAttribute : [Attribute](https://docs.unity3d.com/ScriptReference/30_search.html?q=attribute)
+
+|public method|since|description|
+|--|--|--|
+|DefaultTooltipAttribute()||public DefaultTooltipAttribute(Tooltip.Type type, Tooltip.Trigger trigger)|
+
## DefineSymbolsUtil
> XCharts.Runtime.DefineSymbolsUtil
diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md
index cf255867..807a7430 100644
--- a/Documentation~/en/configuration.md
+++ b/Documentation~/en/configuration.md
@@ -2196,8 +2196,8 @@ Tooltip component.
|field|default|since|comment|
|--|--|--|--|
|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.
|
+|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.
- `Auto`: Auto select indicator according to serie type.
|
+|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.
- `Auto`: Auto select trigger according to serie type.
|
|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.
diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md
index 9797359d..c89e9ef7 100644
--- a/Documentation~/zh/api.md
+++ b/Documentation~/zh/api.md
@@ -31,6 +31,7 @@ slug: /api
- [DataZoomHelper](#datazoomhelper)
- [DateTimeUtil](#datetimeutil)
- [DefaultAnimationAttribute](#defaultanimationattribute)
+- [DefaultTooltipAttribute](#defaulttooltipattribute)
- [DefineSymbolsUtil](#definesymbolsutil)
- [FormatterHelper](#formatterhelper)
- [GridCoordContext](#gridcoordcontext)
@@ -609,6 +610,14 @@ slug: /api
|DefaultAnimationAttribute()||public DefaultAnimationAttribute(AnimationType handler)|
|DefaultAnimationAttribute()||public DefaultAnimationAttribute(AnimationType handler, bool enableSerieDataAddedAnimation)|
+## DefaultTooltipAttribute
+
+> XCharts.Runtime.DefaultTooltipAttribute : [Attribute](https://docs.unity3d.com/ScriptReference/30_search.html?q=attribute)
+
+|public method|since|description|
+|--|--|--|
+|DefaultTooltipAttribute()||public DefaultTooltipAttribute(Tooltip.Type type, Tooltip.Trigger trigger)|
+
## DefineSymbolsUtil
> XCharts.Runtime.DefineSymbolsUtil
diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md
index 3023c79a..fd6aa2ef 100644
--- a/Documentation~/zh/changelog.md
+++ b/Documentation~/zh/changelog.md
@@ -79,6 +79,7 @@ slug: /changelog
日志详情:
+* (2023.09.01) 增加`Tooltip`的`Auto`自动设置显示类型和触发类型
* (2023.08.29) 增加`Ring`的`gridIndex`支持设置指定网格
* (2023.08.29) 增加`Radar`的`gridIndex`支持设置指定网格
* (2023.08.29) 增加`Pie`的`gridIndex`支持设置指定网格
diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md
index ffd95ff1..69c6ccf9 100644
--- a/Documentation~/zh/configuration.md
+++ b/Documentation~/zh/configuration.md
@@ -2196,8 +2196,8 @@ Serie的状态样式。Serie的状态有正常,高亮,淡出,选中四种
|field|default|since|comment|
|--|--|--|--|
|show|true||是否显示提示框组件。
-|type|||提示框指示器类型。
`Tooltip.Type`:
- `Line`: 直线指示器
- `Shadow`: 阴影指示器
- `None`: 无指示器
- `Corss`: 十字准星指示器。坐标轴显示Label和交叉线。
|
-|trigger|||触发类型。
`Tooltip.Trigger`:
- `Item`: 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。
- `Axis`: 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
- `None`: 什么都不触发。
|
+|type|||提示框指示器类型。
`Tooltip.Type`:
- `Line`: 直线指示器
- `Shadow`: 阴影指示器
- `None`: 无指示器
- `Corss`: 十字准星指示器。坐标轴显示Label和交叉线。
- `Auto`: 根据serie的类型自动选择显示指示器。
|
+|trigger|||触发类型。
`Tooltip.Trigger`:
- `Item`: 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。
- `Axis`: 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
- `None`: 什么都不触发。
- `Auto`: 根据serie的类型自动选择触发类型。
|
|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。
{h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。
{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}"
diff --git a/Runtime/Chart/BarChart.cs b/Runtime/Chart/BarChart.cs
index 77a6aa67..f27f9964 100644
--- a/Runtime/Chart/BarChart.cs
+++ b/Runtime/Chart/BarChart.cs
@@ -11,13 +11,9 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- var tooltip = EnsureChartComponent();
- tooltip.type = Tooltip.Type.Shadow;
- tooltip.trigger = Tooltip.Trigger.Axis;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
RemoveData();
Bar.AddDefaultSerie(this, GenerateDefaultSerieName());
diff --git a/Runtime/Chart/CandlestickChart.cs b/Runtime/Chart/CandlestickChart.cs
index 34672fc8..d136b28d 100644
--- a/Runtime/Chart/CandlestickChart.cs
+++ b/Runtime/Chart/CandlestickChart.cs
@@ -11,13 +11,9 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- var tooltip = EnsureChartComponent();
- tooltip.type = Tooltip.Type.Shadow;
- tooltip.trigger = Tooltip.Trigger.Axis;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
RemoveData();
var serie = Candlestick.AddDefaultSerie(this, GenerateDefaultSerieName());
diff --git a/Runtime/Chart/HeatmapChart.cs b/Runtime/Chart/HeatmapChart.cs
index d7e4533e..5f4e39fe 100644
--- a/Runtime/Chart/HeatmapChart.cs
+++ b/Runtime/Chart/HeatmapChart.cs
@@ -12,10 +12,6 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- var tooltip = GetChartComponent();
- tooltip.type = Tooltip.Type.None;
- tooltip.trigger = Tooltip.Trigger.Axis;
-
var grid = EnsureChartComponent();
grid.left = 0.12f;
diff --git a/Runtime/Chart/LineChart.cs b/Runtime/Chart/LineChart.cs
index d1185871..e09b6e62 100644
--- a/Runtime/Chart/LineChart.cs
+++ b/Runtime/Chart/LineChart.cs
@@ -11,13 +11,9 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- var tooltip = EnsureChartComponent();
- tooltip.type = Tooltip.Type.Line;
- tooltip.trigger = Tooltip.Trigger.Axis;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
RemoveData();
Line.AddDefaultSerie(this, GenerateDefaultSerieName());
diff --git a/Runtime/Chart/PolarChart.cs b/Runtime/Chart/PolarChart.cs
index 95b268b2..82d1cd7f 100644
--- a/Runtime/Chart/PolarChart.cs
+++ b/Runtime/Chart/PolarChart.cs
@@ -11,11 +11,11 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
- var tooltip = GetChartComponent();
+ var tooltip = EnsureChartComponent();
tooltip.type = Tooltip.Type.Corss;
tooltip.trigger = Tooltip.Trigger.Axis;
diff --git a/Runtime/Chart/ScatterChart.cs b/Runtime/Chart/ScatterChart.cs
index de04423e..1087fbda 100644
--- a/Runtime/Chart/ScatterChart.cs
+++ b/Runtime/Chart/ScatterChart.cs
@@ -11,11 +11,7 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
-
- var tooltip = EnsureChartComponent();
- tooltip.type = Tooltip.Type.None;
- tooltip.trigger = Tooltip.Trigger.Item;
+ EnsureChartComponent();
var xAxis = EnsureChartComponent();
xAxis.type = Axis.AxisType.Value;
diff --git a/Runtime/Chart/SimplifiedBarChart.cs b/Runtime/Chart/SimplifiedBarChart.cs
index 0fef9ccd..c5d676d8 100644
--- a/Runtime/Chart/SimplifiedBarChart.cs
+++ b/Runtime/Chart/SimplifiedBarChart.cs
@@ -11,13 +11,9 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- var tooltip = GetChartComponent();
- tooltip.type = Tooltip.Type.Line;
- tooltip.trigger = Tooltip.Trigger.Axis;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
RemoveData();
SimplifiedBar.AddDefaultSerie(this, GenerateDefaultSerieName());
diff --git a/Runtime/Chart/SimplifiedCandlestickChart.cs b/Runtime/Chart/SimplifiedCandlestickChart.cs
index e8d90aa1..ec11d10f 100644
--- a/Runtime/Chart/SimplifiedCandlestickChart.cs
+++ b/Runtime/Chart/SimplifiedCandlestickChart.cs
@@ -11,13 +11,9 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- var tooltip = GetChartComponent();
- tooltip.type = Tooltip.Type.Shadow;
- tooltip.trigger = Tooltip.Trigger.Axis;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
RemoveData();
SimplifiedCandlestick.AddDefaultSerie(this, GenerateDefaultSerieName());
diff --git a/Runtime/Chart/SimplifiedLineChart.cs b/Runtime/Chart/SimplifiedLineChart.cs
index bf023dc6..f6b7a76b 100644
--- a/Runtime/Chart/SimplifiedLineChart.cs
+++ b/Runtime/Chart/SimplifiedLineChart.cs
@@ -11,13 +11,9 @@ namespace XCharts.Runtime
{
protected override void DefaultChart()
{
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- var tooltip = GetChartComponent();
- tooltip.type = Tooltip.Type.Line;
- tooltip.trigger = Tooltip.Trigger.Axis;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent();
RemoveData();
SimplifiedLine.AddDefaultSerie(this, GenerateDefaultSerieName());
diff --git a/Runtime/Component/Radar/RadarCoord.cs b/Runtime/Component/Radar/RadarCoord.cs
index cb107240..72ff346f 100644
--- a/Runtime/Component/Radar/RadarCoord.cs
+++ b/Runtime/Component/Radar/RadarCoord.cs
@@ -357,7 +357,7 @@ namespace XCharts.Runtime
if (center.Length < 2) return;
var chartPosition = chart.chartPosition;
var chartWidth = chart.chartWidth;
- var chartHeight = chart.chartWidth;
+ var chartHeight = chart.chartHeight;
if (gridIndex >= 0)
{
var layout = chart.GetChartComponent(0);
diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs
index 9a823d71..eea09674 100644
--- a/Runtime/Component/Tooltip/Tooltip.cs
+++ b/Runtime/Component/Tooltip/Tooltip.cs
@@ -1,8 +1,6 @@
using System.Collections.Generic;
-using System.Text;
using UnityEngine;
using UnityEngine.UI;
-using XUGL;
namespace XCharts.Runtime
{
@@ -39,7 +37,12 @@ namespace XCharts.Runtime
/// crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
/// |十字准星指示器。坐标轴显示Label和交叉线。
///
- Corss
+ Corss,
+ ///
+ /// Auto select indicator according to serie type.
+ /// |根据serie的类型自动选择显示指示器。
+ ///
+ Auto
}
///
@@ -62,7 +65,12 @@ namespace XCharts.Runtime
/// Trigger nothing.
/// |什么都不触发。
///
- None
+ None,
+ ///
+ /// Auto select trigger according to serie type.
+ /// |根据serie的类型自动选择触发类型。
+ ///
+ Auto
}
///
/// Position type.
@@ -92,8 +100,8 @@ namespace XCharts.Runtime
}
[SerializeField] private bool m_Show = true;
- [SerializeField] private Type m_Type;
- [SerializeField] private Trigger m_Trigger = Trigger.Item;
+ [SerializeField] private Type m_Type = Type.Auto;
+ [SerializeField] private Trigger m_Trigger = Trigger.Auto;
[SerializeField][Since("v3.3.0")] private Position m_Position = Position.Auto;
[SerializeField] private string m_ItemFormatter;
[SerializeField] private string m_TitleFormatter;
@@ -429,7 +437,7 @@ namespace XCharts.Runtime
/// |当前提示框所指示的数据项索引。
///
public List runtimeDataIndex { get { return m_RuntimeDateIndex; } internal set { m_RuntimeDateIndex = value; } }
- private List m_RuntimeDateIndex = new List() {-1, -1 };
+ private List m_RuntimeDateIndex = new List() { -1, -1 };
///
/// Keep Tooltiop displayed at the top.
@@ -569,12 +577,12 @@ namespace XCharts.Runtime
public bool IsTriggerItem()
{
- return trigger == Trigger.Item;
+ return trigger == Trigger.Auto ? context.trigger == Trigger.Item : trigger == Trigger.Item;
}
public bool IsTriggerAxis()
{
- return trigger == Trigger.Axis;
+ return trigger == Trigger.Auto ? context.trigger == Trigger.Axis : trigger == Trigger.Axis;
}
public LabelStyle GetContentLabelStyle(int index)
diff --git a/Runtime/Component/Tooltip/TooltipContext.cs b/Runtime/Component/Tooltip/TooltipContext.cs
index f00c7d0b..e0674e3a 100644
--- a/Runtime/Component/Tooltip/TooltipContext.cs
+++ b/Runtime/Component/Tooltip/TooltipContext.cs
@@ -19,6 +19,8 @@ namespace XCharts.Runtime
public float width;
public float height;
public float angle;
+ public Tooltip.Type type;
+ public Tooltip.Trigger trigger;
public TooltipData data = new TooltipData();
}
}
\ No newline at end of file
diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs
index 2515d194..2aaa016e 100644
--- a/Runtime/Component/Tooltip/TooltipHandler.cs
+++ b/Runtime/Component/Tooltip/TooltipHandler.cs
@@ -113,7 +113,7 @@ namespace XCharts.Runtime
}
}
var containerSeries = ListPool.Get();
- m_PointerContainer = GetPointerContainerAndSeries(tooltip, containerSeries);
+ UpdatePointerContainerAndSeriesAndTooltip(tooltip, ref containerSeries);
if (containerSeries.Count > 0)
{
if (SetSerieTooltip(tooltip, containerSeries))
@@ -122,7 +122,7 @@ namespace XCharts.Runtime
ListPool.Release(containerSeries);
if (!showTooltip)
{
- if (tooltip.type == Tooltip.Type.Corss && m_PointerContainer != null && m_PointerContainer.IsPointerEnter())
+ if (tooltip.context.type == Tooltip.Type.Corss && m_PointerContainer != null && m_PointerContainer.IsPointerEnter())
{
tooltip.SetActive(true);
tooltip.SetContentActive(false);
@@ -138,13 +138,17 @@ namespace XCharts.Runtime
}
}
+ private void UpdateTooltipTypeAndTrigger(Tooltip tootip)
+ {
+ }
+
private void UpdateTooltipIndicatorLabelText(Tooltip tooltip)
{
if (!tooltip.show) return;
- if (tooltip.type == Tooltip.Type.None) return;
+ if (tooltip.context.type == Tooltip.Type.None) return;
if (m_PointerContainer != null)
{
- if (tooltip.type == Tooltip.Type.Corss)
+ if (tooltip.context.type == Tooltip.Type.Corss)
{
if (m_PointerContainer is GridCoord)
{
@@ -218,10 +222,11 @@ namespace XCharts.Runtime
label.SetTextColor(axis.indicatorLabel.textStyle.color);
}
- private ISerieContainer GetPointerContainerAndSeries(Tooltip tooltip, List list)
+ private void UpdatePointerContainerAndSeriesAndTooltip(Tooltip tooltip, ref List list)
{
list.Clear();
- ISerieContainer target = null;
+ m_PointerContainer = null;
+ var updateTooltipTypeAndTrigger = false;
for (int i = chart.components.Count - 1; i >= 0; i--)
{
var component = chart.components[i];
@@ -236,6 +241,14 @@ namespace XCharts.Runtime
(serie as INeedSerieContainer).containterInstanceId == component.instanceId &&
!serie.placeHolder)
{
+ if (!updateTooltipTypeAndTrigger)
+ {
+ updateTooltipTypeAndTrigger = true;
+ tooltip.context.type = tooltip.type == Tooltip.Type.Auto ?
+ serie.context.tooltipType : tooltip.type;
+ tooltip.context.trigger = tooltip.trigger == Tooltip.Trigger.Auto ?
+ serie.context.tooltipTrigger : tooltip.trigger;
+ }
var isTriggerAxis = tooltip.IsTriggerAxis();
if (container is GridCoord)
{
@@ -253,16 +266,16 @@ namespace XCharts.Runtime
chart.RefreshTopPainter();
}
}
- target = container;
+ m_PointerContainer = container;
}
}
}
- return target;
}
private void UpdateAxisPointerDataIndex(Serie serie, XAxis xAxis, YAxis yAxis, GridCoord grid, bool isTriggerAxis)
{
serie.context.pointerAxisDataIndexs.Clear();
+ if (xAxis == null || yAxis == null) return;
if (serie is Heatmap)
{
GetSerieDataByXYAxis(serie, xAxis, yAxis);
@@ -419,9 +432,10 @@ namespace XCharts.Runtime
private bool SetSerieTooltip(Tooltip tooltip, Serie serie)
{
- if (tooltip.trigger == Tooltip.Trigger.None) return false;
if (serie.context.pointerItemDataIndex < 0) return false;
-
+ tooltip.context.type = tooltip.type == Tooltip.Type.Auto ? serie.context.tooltipType : tooltip.type;
+ tooltip.context.trigger = tooltip.trigger == Tooltip.Trigger.Auto ? serie.context.tooltipTrigger : tooltip.trigger;
+ if (tooltip.context.trigger == Tooltip.Trigger.None) return false;
tooltip.context.data.param.Clear();
tooltip.context.data.title = serie.serieName;
tooltip.context.pointer = chart.pointerPos;
@@ -440,7 +454,7 @@ namespace XCharts.Runtime
private bool SetSerieTooltip(Tooltip tooltip, List series)
{
- if (tooltip.trigger == Tooltip.Trigger.None)
+ if (tooltip.context.trigger == Tooltip.Trigger.None)
return false;
if (series.Count <= 0)
@@ -456,7 +470,7 @@ namespace XCharts.Runtime
if (m_PointerContainer is GridCoord)
{
GetAxisCategory(m_PointerContainer.index, ref dataIndex, ref category);
- if (tooltip.trigger == Tooltip.Trigger.Axis)
+ if (tooltip.context.trigger == Tooltip.Trigger.Axis)
{
isTriggerByAxis = true;
if (series.Count <= 1)
@@ -467,7 +481,7 @@ namespace XCharts.Runtime
else
tooltip.context.data.title = category;
}
- else if (tooltip.trigger == Tooltip.Trigger.Item)
+ else if (tooltip.context.trigger == Tooltip.Trigger.Item)
{
isTriggerByItem = true;
showCategory = series.Count <= 1;
@@ -523,7 +537,7 @@ namespace XCharts.Runtime
private void DrawTooltipIndicator(VertexHelper vh, Tooltip tooltip)
{
if (!tooltip.show) return;
- if (tooltip.type == Tooltip.Type.None) return;
+ if (tooltip.context.type == Tooltip.Type.None) return;
if (!IsAnySerieNeedTooltip()) return;
if (m_PointerContainer is GridCoord)
{
@@ -566,7 +580,7 @@ namespace XCharts.Runtime
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
int dataCount = chart.series.Count > 0 ? chart.series[0].GetDataList(dataZoom).Count : 0;
float splitWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, dataCount, dataZoom);
- switch (tooltip.type)
+ switch (tooltip.context.type)
{
case Tooltip.Type.Corss:
case Tooltip.Type.Line:
@@ -580,7 +594,7 @@ namespace XCharts.Runtime
Vector2 ep = new Vector2(pX, grid.context.y + grid.context.height);
var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme.tooltip.lineColor);
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
- if (tooltip.type == Tooltip.Type.Corss)
+ if (tooltip.context.type == Tooltip.Type.Corss)
{
sp = new Vector2(grid.context.x, chart.pointerPos.y);
ep = new Vector2(grid.context.x + grid.context.width, chart.pointerPos.y);
@@ -632,7 +646,7 @@ namespace XCharts.Runtime
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
int dataCount = chart.series.Count > 0 ? chart.series[0].GetDataList(dataZoom).Count : 0;
float splitWidth = AxisHelper.GetDataWidth(yAxis, grid.context.height, dataCount, dataZoom);
- switch (tooltip.type)
+ switch (tooltip.context.type)
{
case Tooltip.Type.Corss:
case Tooltip.Type.Line:
@@ -644,7 +658,7 @@ namespace XCharts.Runtime
Vector2 ep = new Vector2(grid.context.x + grid.context.width, pY);
var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme.tooltip.lineColor);
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
- if (tooltip.type == Tooltip.Type.Corss)
+ if (tooltip.context.type == Tooltip.Type.Corss)
{
sp = new Vector2(chart.pointerPos.x, grid.context.y);
ep = new Vector2(chart.pointerPos.x, grid.context.y + grid.context.height);
@@ -687,7 +701,7 @@ namespace XCharts.Runtime
var sp = ChartHelper.GetPos(m_Polar.context.center, m_Polar.context.insideRadius, tooltipAngle, true);
var ep = ChartHelper.GetPos(m_Polar.context.center, m_Polar.context.outsideRadius, tooltipAngle, true);
- switch (tooltip.type)
+ switch (tooltip.context.type)
{
case Tooltip.Type.Corss:
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
diff --git a/Runtime/Internal/Attributes/DefaultTooltipAttribute.cs b/Runtime/Internal/Attributes/DefaultTooltipAttribute.cs
new file mode 100644
index 00000000..c5eaff30
--- /dev/null
+++ b/Runtime/Internal/Attributes/DefaultTooltipAttribute.cs
@@ -0,0 +1,17 @@
+using System;
+
+namespace XCharts.Runtime
+{
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
+ public sealed class DefaultTooltipAttribute : Attribute
+ {
+ public readonly Tooltip.Type type;
+ public readonly Tooltip.Trigger trigger;
+
+ public DefaultTooltipAttribute(Tooltip.Type type, Tooltip.Trigger trigger)
+ {
+ this.type = type;
+ this.trigger = trigger;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Internal/Attributes/DefaultTooltipAttribute.cs.meta b/Runtime/Internal/Attributes/DefaultTooltipAttribute.cs.meta
new file mode 100644
index 00000000..0aa04329
--- /dev/null
+++ b/Runtime/Internal/Attributes/DefaultTooltipAttribute.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a994dc47021bb4031ba6cf23eaf82e7e
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/Internal/BaseChart.Serie.cs b/Runtime/Internal/BaseChart.Serie.cs
index b0416170..2f6bf388 100644
--- a/Runtime/Internal/BaseChart.Serie.cs
+++ b/Runtime/Internal/BaseChart.Serie.cs
@@ -976,6 +976,15 @@ namespace XCharts.Runtime
if (serie == null)
throw new ArgumentNullException("serie is null");
+ if (serie.GetType().IsDefined(typeof(DefaultTooltipAttribute), false))
+ {
+ var attribute1 = serie.GetType().GetAttribute();
+ if (attribute1 != null)
+ {
+ serie.context.tooltipTrigger = attribute1.trigger;
+ serie.context.tooltipType = attribute1.type;
+ }
+ }
if (!serie.GetType().IsDefined(typeof(SerieHandlerAttribute), false))
{
Debug.LogError("Serie no Handler:" + serie.GetType());
diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs
index ede2c124..e991ceb9 100644
--- a/Runtime/Internal/BaseChart.cs
+++ b/Runtime/Internal/BaseChart.cs
@@ -146,10 +146,9 @@ namespace XCharts.Runtime
{
RemoveAllChartComponent();
OnBeforeSerialize();
- AddChartComponentWhenNoExist();
- AddChartComponentWhenNoExist();
-
- GetChartComponent().text = GetType().Name;
+ EnsureChartComponent();
+ EnsureChartComponent();
+ EnsureChartComponent().text = GetType().Name;
if (m_Theme.sharedTheme != null)
m_Theme.sharedTheme.CopyTheme(ThemeType.Default);
diff --git a/Runtime/Serie/Bar/Bar.cs b/Runtime/Serie/Bar/Bar.cs
index 21066d66..5ad093e3 100644
--- a/Runtime/Serie/Bar/Bar.cs
+++ b/Runtime/Serie/Bar/Bar.cs
@@ -5,6 +5,7 @@ namespace XCharts.Runtime
[SerieConvert(typeof(Line), typeof(Pie))]
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
[DefaultAnimation(AnimationType.BottomToTop)]
+ [DefaultTooltip(Tooltip.Type.Shadow, Tooltip.Trigger.Axis)]
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataExtraField("m_Ignore")]
diff --git a/Runtime/Serie/Bar/SimplifiedBar.cs b/Runtime/Serie/Bar/SimplifiedBar.cs
index 9ec993e8..a99218cb 100644
--- a/Runtime/Serie/Bar/SimplifiedBar.cs
+++ b/Runtime/Serie/Bar/SimplifiedBar.cs
@@ -8,6 +8,7 @@ namespace XCharts.Runtime
[SerieConvert(typeof(SimplifiedLine), typeof(Bar))]
[CoordOptions(typeof(GridCoord))]
[DefaultAnimation(AnimationType.LeftToRight, false)]
+ [DefaultTooltip(Tooltip.Type.Shadow, Tooltip.Trigger.Axis)]
[SerieComponent()]
[SerieDataComponent()]
[SerieDataExtraField()]
diff --git a/Runtime/Serie/Candlestick/Candlestick.cs b/Runtime/Serie/Candlestick/Candlestick.cs
index 8ee6f85a..26583938 100644
--- a/Runtime/Serie/Candlestick/Candlestick.cs
+++ b/Runtime/Serie/Candlestick/Candlestick.cs
@@ -5,6 +5,7 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(CandlestickHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight, false)]
+ [DefaultTooltip(Tooltip.Type.Shadow, Tooltip.Trigger.Axis)]
[SerieComponent()]
[SerieDataComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataExtraField()]
diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs
index 53cce62f..911f6eb2 100644
--- a/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs
+++ b/Runtime/Serie/Candlestick/SimplifiedCandlestick.cs
@@ -5,6 +5,7 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(SimplifiedCandlestickHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight, false)]
+ [DefaultTooltip(Tooltip.Type.Shadow, Tooltip.Trigger.Axis)]
[SerieComponent()]
[SerieDataComponent()]
[SerieDataExtraField()]
diff --git a/Runtime/Serie/Heatmap/Heatmap.cs b/Runtime/Serie/Heatmap/Heatmap.cs
index 7abf041d..0f62e11f 100644
--- a/Runtime/Serie/Heatmap/Heatmap.cs
+++ b/Runtime/Serie/Heatmap/Heatmap.cs
@@ -23,6 +23,7 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(HeatmapHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight, false)]
+ [DefaultTooltip(Tooltip.Type.None, Tooltip.Trigger.Axis)]
[RequireChartComponent(typeof(VisualMap))]
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
diff --git a/Runtime/Serie/Line/Line.cs b/Runtime/Serie/Line/Line.cs
index 3a928bde..bbc2cc76 100644
--- a/Runtime/Serie/Line/Line.cs
+++ b/Runtime/Serie/Line/Line.cs
@@ -7,22 +7,10 @@ namespace XCharts.Runtime
[SerieConvert(typeof(Bar), typeof(Pie))]
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
[DefaultAnimation(AnimationType.LeftToRight, false)]
- [SerieComponent(
- typeof(LabelStyle),
- typeof(EndLabelStyle),
- typeof(LineArrow),
- typeof(AreaStyle),
- typeof(EmphasisStyle),
- typeof(BlurStyle),
- typeof(SelectStyle))]
- [SerieDataComponent(
- typeof(ItemStyle),
- typeof(LabelStyle),
- typeof(SerieSymbol),
- typeof(EmphasisStyle),
- typeof(BlurStyle),
- typeof(SelectStyle))]
+ [DefaultTooltip(Tooltip.Type.Line, Tooltip.Trigger.Axis)]
[SerieDataExtraField("m_State", "m_Ignore")]
+ [SerieComponent(typeof(LabelStyle), typeof(EndLabelStyle), typeof(LineArrow), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
+ [SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(SerieSymbol), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
public class Line : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }
diff --git a/Runtime/Serie/Line/SimplifiedLine.cs b/Runtime/Serie/Line/SimplifiedLine.cs
index 81c105e3..0e278988 100644
--- a/Runtime/Serie/Line/SimplifiedLine.cs
+++ b/Runtime/Serie/Line/SimplifiedLine.cs
@@ -8,6 +8,7 @@ namespace XCharts.Runtime
[SerieConvert(typeof(SimplifiedBar), typeof(Line))]
[CoordOptions(typeof(GridCoord))]
[DefaultAnimation(AnimationType.LeftToRight, false)]
+ [DefaultTooltip(Tooltip.Type.Line, Tooltip.Trigger.Axis)]
[SerieComponent(typeof(AreaStyle))]
[SerieDataComponent()]
[SerieDataExtraField()]
diff --git a/Runtime/Serie/Radar/Radar.cs b/Runtime/Serie/Radar/Radar.cs
index 626465e9..d7d2e3dc 100644
--- a/Runtime/Serie/Radar/Radar.cs
+++ b/Runtime/Serie/Radar/Radar.cs
@@ -30,7 +30,7 @@ namespace XCharts.Runtime
public static Serie AddDefaultSerie(BaseChart chart, string serieName)
{
- chart.AddChartComponentWhenNoExist();
+ chart.EnsureChartComponent();
var serie = chart.AddSerie(serieName);
serie.symbol.show = true;
serie.symbol.type = SymbolType.Circle;
diff --git a/Runtime/Serie/Scatter/EffectScatter.cs b/Runtime/Serie/Scatter/EffectScatter.cs
index ca10028e..0e3e89ae 100644
--- a/Runtime/Serie/Scatter/EffectScatter.cs
+++ b/Runtime/Serie/Scatter/EffectScatter.cs
@@ -5,6 +5,7 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(EffectScatterHandler), true)]
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
+ [DefaultTooltip(Tooltip.Type.None, Tooltip.Trigger.Item)]
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataExtraField("m_Radius")]
diff --git a/Runtime/Serie/Scatter/Scatter.cs b/Runtime/Serie/Scatter/Scatter.cs
index a6367539..bf64074f 100644
--- a/Runtime/Serie/Scatter/Scatter.cs
+++ b/Runtime/Serie/Scatter/Scatter.cs
@@ -5,6 +5,7 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(ScatterHandler), true)]
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
+ [DefaultTooltip(Tooltip.Type.None, Tooltip.Trigger.Item)]
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataExtraField("m_Radius")]
diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs
index 1f7c2348..020e7605 100644
--- a/Runtime/Serie/SerieContext.cs
+++ b/Runtime/Serie/SerieContext.cs
@@ -115,5 +115,8 @@ namespace XCharts.Runtime
public List drawPoints = new List();
public SerieParams param = new SerieParams();
public ChartLabel titleObject { get; set; }
+
+ public Tooltip.Type tooltipType;
+ public Tooltip.Trigger tooltipTrigger;
}
}
\ No newline at end of file