3.0 - tooltip

This commit is contained in:
monitor1394
2022-02-12 20:10:29 +08:00
parent cc4ee3735c
commit a19b796a02
16 changed files with 88 additions and 36 deletions

View File

@@ -11,7 +11,8 @@ namespace XCharts.Editor
++EditorGUI.indentLevel;
PropertyField("m_Type");
PropertyField("m_Trigger");
PropertyField("m_AlwayShow");
PropertyField("m_ShowContent");
PropertyField("m_AlwayShowContent");
PropertyField("m_TitleFormatter");
PropertyField("m_ItemFormatter");
PropertyField("m_NumericFormatter");

View File

@@ -3,8 +3,9 @@
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
@@ -34,9 +35,8 @@ MonoBehaviour:
m_VisualMapBorderWidth: 0
m_SerieLineWidth: 1.8
m_SerieLineSymbolSize: 5
m_SerieLineSymbolSelectedSize: 7
m_SerieScatterSymbolSize: 20
m_SerieScatterSymbolSelectedSize: 30
m_SerieSelectedRate: 1.3
m_SerieCandlestickBorderWidth: 1
m_EditorShowAllListData: 0
m_MaxPainter: 10
@@ -53,3 +53,5 @@ MonoBehaviour:
- {fileID: 11400000, guid: e1dc23a10de1e4c5dbfbaf74c4dfd218, type: 2}
- {fileID: 0}
- {fileID: 0}
- {fileID: 11400000, guid: 0a4f01779f9b24f48846f968fe013a57, type: 2}
- {fileID: 11400000, guid: 4d093c897dc514d12aca94b6b17cb4fa, type: 2}

View File

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

View File

@@ -3,6 +3,7 @@ using UnityEngine;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine.UI;
namespace XCharts
{

View File

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

View File

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

View File

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

View File

@@ -238,18 +238,14 @@ namespace XCharts
{
content = content.Replace(old, dataName);
}
else if (p == 'c' || p == 'C' || p == 'd' || p == 'D')
else if (p == 'd' || p == 'D')
{
var isPercent = p == 'd' || p == 'D';
if (isPercent)
{
if (total != 0)
content = content.Replace(old, ChartCached.FloatToStr(value / total * 100, numericFormatter));
}
else
{
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
}
var rate = total == 0 ? 0 : value / total * 100;
content = content.Replace(old, ChartCached.FloatToStr(rate, numericFormatter));
}
else if (p == 'c' || p == 'C')
{
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
}
}
content = TrimAndReplaceLine(content);

View File

@@ -96,6 +96,10 @@ namespace XCharts
/// </summary>
public Action<PointerEventData, int> onPointerClickBar { set { m_OnPointerClickBar = value; m_ForceOpenRaycastTarget = true; } }
/// <summary>
/// 坐标轴变更数据索引时回调。参数axis, dataIndex/dataValue
/// </summary>
public Action<Axis, double> onUpdateAxisPointer { set { m_OnUpdateAxisPointer = value; } get { return m_OnUpdateAxisPointer; } }
/// <summary>
/// Redraw chart in next frame.
/// 在下一帧刷新图表。
/// </summary>

View File

@@ -55,12 +55,12 @@ namespace XCharts
{
if (!CanAddChartComponent(type))
{
throw new InvalidOperationException("DisallowMultipleComponent:" + type.Name);
throw new InvalidOperationException("CanAddChartComponent:" + type.Name);
}
CheckAddRequireChartComponent(type);
var component = Activator.CreateInstance(type) as MainComponent;
if (component == null)
throw new InvalidOperationException("DisallowMultipleComponent:" + type.Name);
throw new InvalidOperationException("CanAddChartComponent:" + type.Name);
component.SetDefaultValue();
if (component is IUpdateRuntimeData)
(component as IUpdateRuntimeData).UpdateRuntimeData(chartX, chartY, chartWidth, chartHeight);

View File

@@ -484,6 +484,26 @@ namespace XCharts
return false;
}
public double GetData(string serieName, int dataIndex, int dimension = 1)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.GetData(dataIndex, dimension);
}
return 0;
}
public double GetData(int serieIndex, int dataIndex, int dimension = 1)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.GetData(dataIndex, dimension);
}
return 0;
}
public int GetAllSerieDataCount()
{
var total = 0;

View File

@@ -87,6 +87,7 @@ namespace XCharts
protected Action<VertexHelper, Serie> m_OnCustomDrawSerieAfterCallback;
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
protected Action<PointerEventData, int> m_OnPointerClickBar;
protected Action<Axis, double> m_OnUpdateAxisPointer;
internal bool m_CheckAnimation = false;
internal protected List<string> m_LegendRealShowName = new List<string>();
@@ -309,7 +310,7 @@ namespace XCharts
painter.onPopulateMesh = OnDrawPainterSerie;
painter.SetActive(false, m_DebugMode);
painter.material = settings.seriePainterMaterial;
painter.transform.SetSiblingIndex(i + 1);
painter.transform.SetSiblingIndex(index + 1);
m_PainterList.Add(painter);
}
m_PainterTop = ChartHelper.AddPainterObject("painter_t", transform, m_GraphMinAnchor,
@@ -318,7 +319,7 @@ namespace XCharts
m_PainterTop.onPopulateMesh = OnDrawPainterTop;
m_PainterTop.SetActive(true, m_DebugMode);
m_PainterTop.material = settings.topPainterMaterial;
m_PainterTop.transform.SetSiblingIndex(settings.maxPainter);
m_PainterTop.transform.SetSiblingIndex(settings.maxPainter + 1);
}
internal void InitComponentHandlers()

View File

@@ -21,7 +21,7 @@ namespace XCharts
public static class XChartsMgr
{
public static readonly string version = "3.0.0";
public static readonly int versionDate = 20210724;
public static readonly int versionDate = 20220101;
public static string fullVersion { get { return version + "-" + versionDate; } }
internal static List<BaseChart> chartList = new List<BaseChart>();

View File

@@ -92,11 +92,11 @@ namespace XCharts
/// <summary>
/// theme的颜色索引
/// </summary>
internal int colorIndex;
public int colorIndex;
/// <summary>
/// 绘制点
/// </summary>
internal List<PointInfo> drawPoints = new List<PointInfo>();
public List<PointInfo> drawPoints = new List<PointInfo>();
public SerieParams param = new SerieParams();
}
}

View File

@@ -294,7 +294,6 @@ namespace XCharts
serieData.labelObject.SetPosition(serieData.context.position);
serieData.labelObject.UpdateIcon(iconStyle);
if (serie.show
&& currLabel != null
&& (currLabel.show || isHighlight)
@@ -414,7 +413,7 @@ namespace XCharts
param.serieData = serieData;
param.value = serieData.GetData(param.dimension);
param.total = SerieHelper.GetMaxData(serie, dimension);
param.color = chart.theme.GetColor(dataIndex);
param.color = chart.GetLegendRealShowNameColor(serieData.name);
param.marker = SerieHelper.GetItemMarker(serie, serieData, marker);
param.itemFormatter = itemFormatter;
param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter);

View File

@@ -41,6 +41,7 @@ namespace XCharts
{
[SerializeField] private Theme m_SharedTheme;
[SerializeField] private bool m_EnableCustomTheme;
[SerializeField] private Font m_CustomFont;
[SerializeField] private Color32 m_CustomBackgroundColor;
#if UNITY_2020_2
[NonReorderable]