mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 02:40:13 +00:00
3.0 - tooltip
This commit is contained in:
@@ -31,19 +31,18 @@ namespace XCharts
|
||||
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
if (!grid.context.isPointerEnter)
|
||||
{
|
||||
axis.context.pointerValue = double.PositiveInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
var lastPointerValue = axis.context.pointerValue;
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
var dataZoom = chart.GetDataZoomOfAxis(axis);
|
||||
var dataCount = chart.series.Count > 0 ? chart.series[0].GetDataList(dataZoom).Count : 0;
|
||||
var local = chart.pointerPos;
|
||||
|
||||
for (int j = 0; j < axis.GetDataCount(dataZoom); j++)
|
||||
{
|
||||
if (axis is YAxis)
|
||||
@@ -55,6 +54,11 @@ namespace XCharts
|
||||
{
|
||||
axis.context.pointerValue = j;
|
||||
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
|
||||
if (j != lastPointerValue)
|
||||
{
|
||||
if (chart.onUpdateAxisPointer != null)
|
||||
chart.onUpdateAxisPointer(axis, j);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -67,6 +71,11 @@ namespace XCharts
|
||||
{
|
||||
axis.context.pointerValue = j;
|
||||
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
|
||||
if (j != lastPointerValue)
|
||||
{
|
||||
if (chart.onUpdateAxisPointer != null)
|
||||
chart.onUpdateAxisPointer(axis, j);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -85,6 +94,11 @@ namespace XCharts
|
||||
var labelX = axis.GetLabelObjectPosition(0).x;
|
||||
axis.context.pointerValue = yValue;
|
||||
axis.context.pointerLabelPosition = new Vector3(labelX, chart.pointerPos.y);
|
||||
if (yValue != lastPointerValue)
|
||||
{
|
||||
if (chart.onUpdateAxisPointer != null)
|
||||
chart.onUpdateAxisPointer(axis, yValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -97,6 +111,11 @@ namespace XCharts
|
||||
var labelY = axis.GetLabelObjectPosition(0).y;
|
||||
axis.context.pointerValue = xValue;
|
||||
axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY);
|
||||
if (xValue != lastPointerValue)
|
||||
{
|
||||
if (chart.onUpdateAxisPointer != null)
|
||||
chart.onUpdateAxisPointer(axis, xValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace XCharts
|
||||
[SerializeField] private int m_PaddingTopBottom = 10;
|
||||
[SerializeField] private bool m_IgnoreDataShow = false;
|
||||
[SerializeField] private string m_IgnoreDataDefaultContent = "-";
|
||||
[SerializeField] private bool m_AlwayShow = false;
|
||||
[SerializeField] private bool m_ShowContent = true;
|
||||
[SerializeField] private bool m_AlwayShowContent = false;
|
||||
[SerializeField] private Vector2 m_Offset = new Vector2(18f, -25f);
|
||||
[SerializeField] private Sprite m_BackgroundImage;
|
||||
[SerializeField] private Color m_BackgroundColor;
|
||||
@@ -241,9 +242,15 @@ namespace XCharts
|
||||
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; SetComponentDirty(); } }
|
||||
/// <summary>
|
||||
/// Whether to trigger after always display.
|
||||
/// 是否触发后一直显示。
|
||||
/// 是否触发后一直显示提示框浮层。
|
||||
/// </summary>
|
||||
public bool alwayShow { get { return m_AlwayShow; } set { m_AlwayShow = value; } }
|
||||
public bool alwayShowContent { get { return m_AlwayShowContent; } set { m_AlwayShowContent = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show the tooltip floating layer, whose default value is true.
|
||||
/// It should be configurated to be false, if you only need tooltip to trigger the event or show the axisPointer without content.
|
||||
/// 是否显示提示框浮层,默认显示。只需tooltip触发事件或显示axisPointer而不需要显示内容时可配置该项为false。
|
||||
/// </summary>
|
||||
public bool showContent { get { return m_ShowContent; } set { m_ShowContent = value; } }
|
||||
/// <summary>
|
||||
/// The position offset of tooltip relative to the mouse position.
|
||||
/// 提示框相对于鼠标位置的偏移。
|
||||
@@ -395,7 +402,7 @@ namespace XCharts
|
||||
{
|
||||
if (gameObject && gameObject.activeInHierarchy != flag)
|
||||
{
|
||||
gameObject.SetActive(alwayShow ? true : flag);
|
||||
gameObject.SetActive(alwayShowContent ? true : flag);
|
||||
}
|
||||
SetContentActive(flag);
|
||||
}
|
||||
@@ -422,7 +429,8 @@ namespace XCharts
|
||||
{
|
||||
if (view == null)
|
||||
return;
|
||||
view.SetActive(alwayShow ? true : flag);
|
||||
|
||||
view.SetActive(alwayShowContent ? true : flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -478,7 +478,7 @@ namespace XCharts
|
||||
Vector2 sp = new Vector2(pX, grid.context.y);
|
||||
Vector2 ep = new Vector2(pX, grid.context.y + grid.context.height);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme);
|
||||
if (xAxis.IsCategory())
|
||||
if (xAxis.IsCategory() && tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
pX = (float)(grid.context.x + splitWidth * xAxis.context.pointerValue -
|
||||
@@ -542,7 +542,7 @@ namespace XCharts
|
||||
Vector2 sp = new Vector2(grid.context.x, pY);
|
||||
Vector2 ep = new Vector2(grid.context.x + grid.context.width, pY);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme);
|
||||
if (yAxis.IsCategory())
|
||||
if (yAxis.IsCategory() && tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
float pX = grid.context.x + grid.context.width;
|
||||
|
||||
@@ -57,8 +57,8 @@ namespace XCharts
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
m_Active = flag;
|
||||
ChartHelper.SetActive(gameObject, flag);
|
||||
m_Active = flag && tooltip.showContent;
|
||||
ChartHelper.SetActive(gameObject, m_Active);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
|
||||
Reference in New Issue
Block a user