diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index 9f14c959..62f1fce1 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -1,6 +1,8 @@ # 更新日志 +* (2020.04.23) 优化`ScatterChart`的`Tooltip`显示效果 +* (2020.04.23) 增加`Tooltip`的`formatter`对`{.}`、`{c:0}`、`{c1:1}`的支持 * (2020.04.19) 优化`LineChart`折线图的区域填充渐变效果 * (2020.04.19) 增加`AxisLabel`的`onZero`参数可将`Label`显示在`0`刻度上 * (2020.04.19) 增加`Serie`和`AxisLabel`的`showAsPositiveNumber`参数将负数数值显示为正数 diff --git a/Assets/XCharts/Documentation/XCharts配置项手册.md b/Assets/XCharts/Documentation/XCharts配置项手册.md index 52731fa3..417064f7 100644 --- a/Assets/XCharts/Documentation/XCharts配置项手册.md +++ b/Assets/XCharts/Documentation/XCharts配置项手册.md @@ -190,7 +190,7 @@ * `Shadow`:阴影指示器。 * `None`:无指示器。 * `Corss`:十字准星指示器。坐标轴显示Label和交叉线。 -* `formatter`:提示框内容字符串模版格式器。支持用 `\n` 或 `
` 换行。当`formatter`不为空时,优先使用`formatter`,否则使用`itemFormatter`。示例:`{a}:{c}`,`{a1}:{c1:f1}`。其中变量 `{a}`, `{b}`, `{c}`, `{d}` 在不同图表类型下代表数据含义为: +* `formatter`:提示框内容字符串模版格式器。支持用 `\n` 或 `
` 换行。当`formatter`不为空时,优先使用`formatter`,否则使用`itemFormatter`。示例:`{a}:{c}`,`{a1}:{c1:f1}`。其中`{.}`表示带动态颜色的圆点;`{c:0}`、`{c1:1}`表示索引为0、1的serie的数据项的第0、第1个数据;其它变量 `{a}`, `{b}`, `{c}`, `{d}` 在不同图表类型下代表数据含义为: * 折线(区域)图、柱状(条形)图、K线图 : `{a}`(系列名称),`{b}`(类目值),`{c}`(数值), `{d}`(无)。 * 散点图(气泡)图 : `{a}`(系列名称),`{b}`(数据名称),`{c}`(数值数组), `{d}`(无)。 * 地图 : `{a}`(系列名称),`{b}`(区域名称),`{c}`(合并数值), `{d}`(无)。 diff --git a/Assets/XCharts/Runtime/Component/Main/Serie.cs b/Assets/XCharts/Runtime/Component/Main/Serie.cs index c19deb5d..55cf3dd3 100644 --- a/Assets/XCharts/Runtime/Component/Main/Serie.cs +++ b/Assets/XCharts/Runtime/Component/Main/Serie.cs @@ -1163,7 +1163,12 @@ namespace XCharts var serieData = GetDataList(dataZoom); if (index < serieData.Count) { - return serieData[index].data[1]; + var value = serieData[index].data[1]; + if (showAsPositiveNumber) + { + value = Mathf.Abs(value); + } + return value; } return 0; } @@ -1174,7 +1179,12 @@ namespace XCharts var serieData = GetDataList(dataZoom); if (index < serieData.Count) { - return serieData[index].GetCurrData(1, animation.GetUpdateAnimationDuration()); + var value = serieData[index].GetCurrData(1, animation.GetUpdateAnimationDuration()); + if (showAsPositiveNumber) + { + value = Mathf.Abs(value); + } + return value; } return 0; } @@ -1195,6 +1205,10 @@ namespace XCharts if (index < serieData.Count) { yData = serieData[index].data[1]; + if (showAsPositiveNumber) + { + yData = Mathf.Abs(yData); + } dataName = serieData[index].name; } } diff --git a/Assets/XCharts/Runtime/Component/Main/Tooltip.cs b/Assets/XCharts/Runtime/Component/Main/Tooltip.cs index f2447cda..dd77133e 100644 --- a/Assets/XCharts/Runtime/Component/Main/Tooltip.cs +++ b/Assets/XCharts/Runtime/Component/Main/Tooltip.cs @@ -95,8 +95,10 @@ namespace XCharts } /// /// 提示框总内容的字符串模版格式器。支持用 \n 或 "
" 换行。当formatter不为空时,优先使用formatter,否则使用itemFormatter。 - /// 模板变量有 {a}, {b},{c},{d},{e},分别表示系列名,数据名,数据值等。{a0},{b1},c{1}等可指定serie。 - /// 其中变量{a}, {b}, {c}, {d}在不同图表类型下代表数据含义为: + /// 模板变量有 {a}, {b},{c},{d},{i},分别表示系列名,数据名,数据值等。{a0},{b1},{c1}等可指定serie。 + /// {.}表示带动态颜色的圆点。 + /// {c1:0}、{c1:1}表示索引为1的serie的数据项的第0、第1个数据。 + /// 其它变量{a}, {b}, {c}, {d}在不同图表类型下代表数据含义为: /// /// 折线(区域)图、柱状(条形)图、K线图 : {a}(系列名称),{b}(类目值),{c}(数值), {d}(无)。 /// 散点图(气泡)图 : {a}(系列名称),{b}(数据名称),{c}(数值数组), {d}(无)。 @@ -207,7 +209,10 @@ namespace XCharts lineStyle.ClearComponentDirty(); textStyle.ClearComponentDirty(); } - + /// + /// 当前提示框所指示的Serie索引(目前只对散点图有效)。 + /// + public Dictionary> runtimeSerieDataIndex { get; internal set; } /// /// The data index currently indicated by Tooltip. /// 当前提示框所指示的数据项索引。 @@ -259,7 +264,8 @@ namespace XCharts runtimeXValues = new float[2] { -1, -1 }, runtimeYValues = new float[2] { -1, -1 }, runtimeDataIndex = new List() { -1, -1 }, - lastDataIndex = new List() { -1, -1 } + lastDataIndex = new List() { -1, -1 }, + runtimeSerieDataIndex = new Dictionary>() }; return tooltip; } @@ -451,5 +457,33 @@ namespace XCharts { return runtimeDataIndex[0] == index || runtimeDataIndex[1] == index; } + + public void ClearSerieDataIndex() + { + foreach (var kv in runtimeSerieDataIndex) + { + kv.Value.Clear(); + } + } + + public void AddSerieDataIndex(int serieIndex, int dataIndex) + { + if (!runtimeSerieDataIndex.ContainsKey(serieIndex)) + { + runtimeSerieDataIndex[serieIndex] = new List(); + } + runtimeSerieDataIndex[serieIndex].Add(dataIndex); + } + + public bool isAnySerieDataIndex() + { + foreach (var kv in runtimeSerieDataIndex) + { + if (kv.Value.Count > 0) return true; + } + return false; + } + + } } \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Component/Sub/SerieData.cs b/Assets/XCharts/Runtime/Component/Sub/SerieData.cs index 91368b79..3bd9ed77 100644 --- a/Assets/XCharts/Runtime/Component/Sub/SerieData.cs +++ b/Assets/XCharts/Runtime/Component/Sub/SerieData.cs @@ -171,6 +171,7 @@ namespace XCharts /// 饼图数据项的偏移半径 /// public float runtimePieOffsetRadius { get; internal set; } + public Vector3 runtimePosition { get; internal set; } public Vector3 runtiemPieOffsetCenter { get; internal set; } private List m_PreviousData = new List(); private List m_DataUpdateTime = new List(); diff --git a/Assets/XCharts/Runtime/Helper/TooltipHelper.cs b/Assets/XCharts/Runtime/Helper/TooltipHelper.cs index 1c90fb4c..d3aa510f 100644 --- a/Assets/XCharts/Runtime/Helper/TooltipHelper.cs +++ b/Assets/XCharts/Runtime/Helper/TooltipHelper.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; /******************************************/ /* */ /* Copyright (c) 2018 monitor1394 */ @@ -12,6 +14,48 @@ namespace XCharts { internal static class TooltipHelper { + private const string PH_A = "{a}"; + private const string PH_B = "{b}"; + private const string PH_C = "{c}"; + private const string PH_D = "{d}"; + private const string PH_I = "{.}"; + private const string PH_Y = "{j}"; + private const string PH_ON = "\\n"; + private const string PH_NN = "\n"; + private const string PH_NN_BBB = "\n"; + private const string PH_BR = "
"; + private static Dictionary> s_PHDic = new Dictionary>(); + private static Dictionary s_PHCCDic = new Dictionary(); + private static Dictionary> s_PHSerieCCDic = new Dictionary>(); + + private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, + ThemeInfo themeInfo) + { + if (!tooltip.runtimeSerieDataIndex.ContainsKey(serie.index)) return; + var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index]; + if (!string.IsNullOrEmpty(serie.name)) + { + sb.Append(serie.name).Append(PH_NN); + } + for (int i = 0; i < dataIndexList.Count; i++) + { + var dataIndex = dataIndexList[i]; + var serieData = serie.GetSerieData(dataIndex); + float xValue, yValue; + serie.GetXYData(dataIndex, null, out xValue, out yValue); + + sb.Append("● "); + if (!string.IsNullOrEmpty(serieData.name)) + sb.Append(serieData.name).Append(": "); + sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, 0, tooltip.forceENotation), + ChartCached.FloatToStr(yValue, 0, tooltip.forceENotation)); + if (i != dataIndexList.Count - 1) + { + sb.Append("\n"); + } + } + } + private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, ThemeInfo themeInfo) @@ -22,7 +66,7 @@ namespace XCharts sb.Length = 0; if (!string.IsNullOrEmpty(serie.name)) { - sb.Append(serie.name).Append("\n"); + sb.Append(serie.name).Append(PH_NN); } sb.Append("● "); if (!string.IsNullOrEmpty(key)) @@ -60,7 +104,7 @@ namespace XCharts { string key = radar.indicatorList[i].name; float value = serieData.GetData(i); - if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append("\n"); + if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append(PH_NN); sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, 0, tooltip.forceENotation)); } break; @@ -110,9 +154,11 @@ namespace XCharts { case SerieType.Line: case SerieType.Bar: + InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom); + break; case SerieType.Scatter: case SerieType.EffectScatter: - InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom); + InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo); break; case SerieType.Radar: break; @@ -139,60 +185,112 @@ namespace XCharts var formatTitle = !string.IsNullOrEmpty(title); var needCategory = false; var first = true; + var isScatter = false; sb.Length = 0; for (int i = 0; i < series.Count; i++) { var serie = series.GetSerie(i); - if (!serie.show) continue; - var serieData = serie.GetSerieData(dataIndex, dataZoom); - if (serieData == null) continue; - var itemFormatter = GetItemFormatter(tooltip, serie, serieData); - var percent = serieData.GetData(1) / serie.yTotal * 100; - needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar); - if (serie.show) + if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter) { - if (string.IsNullOrEmpty(itemFormatter)) + if (serie.show && IsSelectedSerie(tooltip, serie.index)) { - if (!first) sb.Append("\n"); - InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian); - first = false; - continue; + isScatter = true; + var itemFormatter = GetItemFormatter(tooltip, serie, null); + if (string.IsNullOrEmpty(itemFormatter)) + { + if (!first) sb.Append(PH_NN); + InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian); + first = false; + continue; + } + var itemTitle = title; + if (!string.IsNullOrEmpty(itemTitle)) + { + Replace(ref itemTitle, PH_A, i, serie.name, true); + sb.Append(itemTitle).Append(PH_NN); + } + var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index]; + foreach (var tempIndex in dataIndexList) + { + var foundDot = false; + var serieData = serie.GetSerieData(tempIndex); + string content = itemFormatter; + Replace(ref content, PH_A, i, serie.name, true); + Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true); + if (itemFormatter.IndexOf(PH_I) >= 0) + { + foundDot = true; + Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)), true); + } + for (int n = 0; n < serieData.data.Count; n++) + { + var valueStr = ChartCached.FloatToStr(serieData.GetData(n), 0, tooltip.forceENotation); + Replace(ref content, GetPHCC(n), i, valueStr, true); + } + if (!foundDot) + { + sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index))); + } + sb.Append(content).Append(PH_NN); + } } - string content = itemFormatter; - content = content.Replace("{a}", serie.name); - content = content.Replace("{b}", needCategory ? category : serieData.name); - content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation)); - content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1)); - if (!first) sb.Append("\n"); - sb.Append("● "); - sb.Append(content); - first = false; } - if (formatTitle) + else { - if (i == 0) + var serieData = serie.GetSerieData(dataIndex, dataZoom); + if (serieData == null) continue; + var itemFormatter = GetItemFormatter(tooltip, serie, serieData); + var percent = serieData.GetData(1) / serie.yTotal * 100; + needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar); + if (formatTitle) { - title = title.Replace("{a}", serie.name); - title = title.Replace("{b}", needCategory ? category : serieData.name); - title = title.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation)); - title = title.Replace("{d}", ChartCached.FloatToStr(percent, 1)); + var valueStr = ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation); + Replace(ref title, PH_A, i, serie.name, true); + Replace(ref title, PH_B, i, needCategory ? category : serieData.name, true); + Replace(ref title, PH_C, i, valueStr, true); + Replace(ref title, PH_D, i, ChartCached.FloatToStr(percent, 1), true); + } + if (serie.show) + { + if (string.IsNullOrEmpty(itemFormatter)) + { + if (!first) sb.Append(PH_NN); + InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian); + first = false; + continue; + } + string content = itemFormatter; + var valueStr = ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation); + Replace(ref content, PH_A, i, serie.name, true); + Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true); + Replace(ref content, PH_C, i, valueStr, true); + Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, 1), true); + for (int n = 0; n < serieData.data.Count; n++) + { + valueStr = ChartCached.FloatToStr(serieData.GetData(n), 0, tooltip.forceENotation); + Replace(ref content, GetPHCC(n), i, valueStr, true); + } + if (!first) sb.Append(PH_NN); + sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i))); + sb.Append(content); + first = false; } - title = title.Replace("{a" + i + "}", serie.name); - title = title.Replace("{b" + i + "}", needCategory ? category : serieData.name); - title = title.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation)); - title = title.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1)); } } - if (string.IsNullOrEmpty(title)) + if (isScatter) { - if (needCategory) return category + "\n" + sb.ToString(); - else return sb.ToString(); + return TrimAndReplaceLine(sb); + } + else if (string.IsNullOrEmpty(title)) + { + if (needCategory) return category + PH_NN + TrimAndReplaceLine(sb); + else return TrimAndReplaceLine(sb); } else { - title = title.Replace("\\n", "\n"); - title = title.Replace("
", "\n"); - return title + "\n" + sb.ToString(); + title = title.Replace(PH_ON, PH_NN); + title = title.Replace(PH_BR, PH_NN); + return title + PH_NN + TrimAndReplaceLine(sb); } } else @@ -206,25 +304,82 @@ namespace XCharts var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar; var serieData = serie.GetSerieData(dataIndex, dataZoom); var percent = serieData.GetData(1) / serie.yTotal * 100; - if (i == 0) + Replace(ref content, PH_A, i, serie.name); + Replace(ref content, PH_B, i, needCategory ? category : serieData.name); + Replace(ref content, PH_C, i, ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation)); + Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, 1)); + Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(i))); + for (int n = 0; n < serieData.data.Count; n++) { - content = content.Replace("{a}", serie.name); - content = content.Replace("{b}", needCategory ? category : serieData.name); - content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation)); - content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1)); + var valueStr = ChartCached.FloatToStr(serieData.GetData(n), 0, tooltip.forceENotation); + if (i == 0) Replace(ref content, GetPHCC(n), i, valueStr, true); + Replace(ref content, GetPHCC(i, n), i, valueStr, true); } - content = content.Replace("{a" + i + "}", serie.name); - content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name); - content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation)); - content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1)); } } - content = content.Replace("\\n", "\n"); - content = content.Replace("
", "\n"); + content = content.Replace(PH_ON, PH_NN); + content = content.Replace(PH_BR, PH_NN); return content; } } + private static string TrimAndReplaceLine(StringBuilder sb) + { + return sb.ToString().Trim().Replace(PH_ON, PH_NN_BBB).Replace(PH_BR, PH_NN_BBB); + } + + private static bool IsSelectedSerie(Tooltip tooltip, int serieIndex) + { + if (tooltip.runtimeSerieDataIndex.ContainsKey(serieIndex)) + { + return tooltip.runtimeSerieDataIndex[serieIndex].Count > 0; + } + return false; + } + + private static void Replace(ref string content, string placeHolder, int index, string newStr, bool all = false) + { + if ((all || index == 0) && content.IndexOf(placeHolder) >= 0) + { + content = content.Replace(placeHolder, newStr); + } + if (!s_PHDic.ContainsKey(placeHolder)) + { + s_PHDic[placeHolder] = new Dictionary(); + } + if (!s_PHDic[placeHolder].ContainsKey(index)) + { + s_PHDic[placeHolder][index] = placeHolder.Insert(2, index.ToString()); + } + var holder = s_PHDic[placeHolder][index]; + if (content.IndexOf(holder) >= 0) + { + content = content.Replace(holder, newStr); + } + } + + private static string GetPHCC(int index) + { + if (!s_PHCCDic.ContainsKey(index)) + { + s_PHCCDic[index] = "{c:" + index + "}"; + } + return s_PHCCDic[index]; + } + + private static string GetPHCC(int serieIndex, int dataIndex) + { + if (!s_PHSerieCCDic.ContainsKey(serieIndex)) + { + s_PHSerieCCDic[serieIndex] = new Dictionary(); + } + if (!s_PHSerieCCDic[serieIndex].ContainsKey(dataIndex)) + { + s_PHSerieCCDic[serieIndex][dataIndex] = "{c" + serieIndex + ":" + dataIndex + "}"; + } + return s_PHSerieCCDic[serieIndex][dataIndex]; + } + private static string GetItemFormatter(Tooltip tooltip, Serie serie, SerieData serieData) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawScatter.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawScatter.cs index 2f12d552..4a5200c7 100644 --- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawScatter.cs +++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawScatter.cs @@ -15,6 +15,7 @@ namespace XCharts protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie) { if (serie.animation.HasFadeOut()) return; + if (!serie.show) return; var yAxis = m_YAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex]; int maxCount = serie.maxShow > 0 ? @@ -41,6 +42,7 @@ namespace XCharts float yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight; var pos = new Vector3(pX + xDataHig, pY + yDataHig); serie.dataPoints.Add(pos); + serieData.runtimePosition = pos; var datas = serie.data[n].data; float symbolSize = 0; if (serie.highlighted || serieData.highlighted) diff --git a/Assets/XCharts/Runtime/ScatterChart.cs b/Assets/XCharts/Runtime/ScatterChart.cs index edf66ea1..182669b9 100644 --- a/Assets/XCharts/Runtime/ScatterChart.cs +++ b/Assets/XCharts/Runtime/ScatterChart.cs @@ -64,5 +64,71 @@ namespace XCharts RefreshChart(); } } + + protected override void CheckTootipArea(Vector2 local) + { + base.CheckTootipArea(local); + m_Tooltip.ClearSerieDataIndex(); + bool selected = false; + var localv3 = new Vector3(local.x, local.y); + foreach (var serie in m_Series.list) + { + if (!serie.show) continue; + if (serie.type != SerieType.Scatter && serie.type != SerieType.EffectScatter) continue; + bool refresh = false; + for (int j = 0; j < serie.data.Count; j++) + { + var serieData = serie.data[j]; + var dist = Vector3.Distance(local, serieData.runtimePosition); + if (dist <= serie.symbol.size) + { + serieData.selected = true; + m_Tooltip.AddSerieDataIndex(serie.index, j); + selected = true; + } + else + { + serieData.selected = false; + } + } + if (refresh) RefreshChart(); + } + if (selected) + { + m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25)); + UpdateTooltip(); + } + else if (m_Tooltip.IsActive()) + { + m_Tooltip.SetActive(false); + RefreshChart(); + } + } + + protected override void UpdateTooltip() + { + base.UpdateTooltip(); + if (m_Tooltip.isAnySerieDataIndex()) + { + var content = TooltipHelper.GetFormatterContent(m_Tooltip, 0, m_Series, m_ThemeInfo); + m_Tooltip.UpdateContentText(content); + + var pos = m_Tooltip.GetContentPos(); + if (pos.x + m_Tooltip.runtimeWidth > chartWidth) + { + pos.x = chartWidth - m_Tooltip.runtimeWidth; + } + if (pos.y - m_Tooltip.runtimeHeight < 0) + { + pos.y = m_Tooltip.runtimeHeight; + } + m_Tooltip.UpdateContentPos(pos); + m_Tooltip.SetActive(true); + } + else + { + m_Tooltip.SetActive(false); + } + } } } diff --git a/Assets/XCharts/Runtime/Utility/ChartCached.cs b/Assets/XCharts/Runtime/Utility/ChartCached.cs index abb63300..6d83e4c9 100644 --- a/Assets/XCharts/Runtime/Utility/ChartCached.cs +++ b/Assets/XCharts/Runtime/Utility/ChartCached.cs @@ -22,11 +22,10 @@ namespace XCharts private static Dictionary s_ValueToEStr = new Dictionary(1000); private static Dictionary s_IntToStr = new Dictionary(1000); private static Dictionary s_IntToFn = new Dictionary(20); - private static Dictionary s_ColorToStr = new Dictionary(1000); + private static Dictionary s_ColorToStr = new Dictionary(100); private static Dictionary s_SerieLabelName = new Dictionary(1000); private static Dictionary s_AxisLabelName = new Dictionary(1000); - - + private static Dictionary s_ColorDotStr = new Dictionary(100); public static string FloatToStr(float value, int f = 0, bool forceE = false) { @@ -88,6 +87,15 @@ namespace XCharts } } + public static string ColorToDotStr(Color color) + { + if (!s_ColorDotStr.ContainsKey(color)) + { + s_ColorDotStr[color] = "● "; + } + return s_ColorDotStr[color]; + } + internal static string GetSerieLabelName(string prefix, int i, int j) { int key = i * 10000000 + j;