diff --git a/Editor/MainComponents/TooltipEditor.cs b/Editor/MainComponents/TooltipEditor.cs index 1982e426..aa5af106 100644 --- a/Editor/MainComponents/TooltipEditor.cs +++ b/Editor/MainComponents/TooltipEditor.cs @@ -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"); diff --git a/Resources/XCSettings.asset b/Resources/XCSettings.asset index 00e4a7d1..0695abb2 100644 --- a/Resources/XCSettings.asset +++ b/Resources/XCSettings.asset @@ -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} diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 808214d8..15a353f2 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -31,19 +31,18 @@ namespace XCharts var grid = chart.GetChartComponent(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); + } } } } diff --git a/Runtime/Component/Debug/DebugInfo.cs b/Runtime/Component/Debug/DebugInfo.cs index dbdf0dd7..4e74e9ba 100644 --- a/Runtime/Component/Debug/DebugInfo.cs +++ b/Runtime/Component/Debug/DebugInfo.cs @@ -3,6 +3,7 @@ using UnityEngine; using System; using System.Collections.Generic; using System.Text; +using UnityEngine.UI; namespace XCharts { diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs index c8fd54e1..25ad3d57 100644 --- a/Runtime/Component/Tooltip/Tooltip.cs +++ b/Runtime/Component/Tooltip/Tooltip.cs @@ -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(); } } /// /// Whether to trigger after always display. - /// 是否触发后一直显示。 + /// 是否触发后一直显示提示框浮层。 /// - public bool alwayShow { get { return m_AlwayShow; } set { m_AlwayShow = value; } } + public bool alwayShowContent { get { return m_AlwayShowContent; } set { m_AlwayShowContent = value; } } + /// + /// 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。 + /// + public bool showContent { get { return m_ShowContent; } set { m_ShowContent = value; } } /// /// 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); } /// diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index 5874b9b1..429a350e 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -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; diff --git a/Runtime/Component/Tooltip/TooltipView.cs b/Runtime/Component/Tooltip/TooltipView.cs index b62468fa..60e5c05d 100644 --- a/Runtime/Component/Tooltip/TooltipView.cs +++ b/Runtime/Component/Tooltip/TooltipView.cs @@ -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() diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index adb4a0c0..9cc4b796 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -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); diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 1ca1b59f..b10fb787 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -96,6 +96,10 @@ namespace XCharts /// public Action onPointerClickBar { set { m_OnPointerClickBar = value; m_ForceOpenRaycastTarget = true; } } /// + /// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue + /// + public Action onUpdateAxisPointer { set { m_OnUpdateAxisPointer = value; } get { return m_OnUpdateAxisPointer; } } + /// /// Redraw chart in next frame. /// 在下一帧刷新图表。 /// diff --git a/Runtime/Internal/BaseChart.Component.cs b/Runtime/Internal/BaseChart.Component.cs index 49e76e66..770c6fe4 100644 --- a/Runtime/Internal/BaseChart.Component.cs +++ b/Runtime/Internal/BaseChart.Component.cs @@ -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); diff --git a/Runtime/Internal/BaseChart.Serie.cs b/Runtime/Internal/BaseChart.Serie.cs index 0fb1d938..9d7cb25c 100644 --- a/Runtime/Internal/BaseChart.Serie.cs +++ b/Runtime/Internal/BaseChart.Serie.cs @@ -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; diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index d8f53352..1376a2d4 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -87,6 +87,7 @@ namespace XCharts protected Action m_OnCustomDrawSerieAfterCallback; protected Action m_OnPointerClickPie; protected Action m_OnPointerClickBar; + protected Action m_OnUpdateAxisPointer; internal bool m_CheckAnimation = false; internal protected List m_LegendRealShowName = new List(); @@ -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() diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index d6e8093a..23123e64 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -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 chartList = new List(); diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs index 50299245..07921cb0 100644 --- a/Runtime/Serie/SerieContext.cs +++ b/Runtime/Serie/SerieContext.cs @@ -92,11 +92,11 @@ namespace XCharts /// /// theme的颜色索引 /// - internal int colorIndex; + public int colorIndex; /// /// 绘制点 /// - internal List drawPoints = new List(); + public List drawPoints = new List(); public SerieParams param = new SerieParams(); } } \ No newline at end of file diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 9b793d0c..6e3322e6 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -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); diff --git a/Runtime/Theme/ThemeStyle.cs b/Runtime/Theme/ThemeStyle.cs index e6032cbd..a498a099 100644 --- a/Runtime/Theme/ThemeStyle.cs +++ b/Runtime/Theme/ThemeStyle.cs @@ -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]