mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 20:28:46 +00:00
RadarChart增加Tooltip
This commit is contained in:
@@ -86,6 +86,7 @@ namespace xcharts
|
|||||||
if (index < 0 || index > dataBtnList.Count - 1)
|
if (index < 0 || index > dataBtnList.Count - 1)
|
||||||
{
|
{
|
||||||
dataBtnList.Add(btn);
|
dataBtnList.Add(btn);
|
||||||
|
dataShowList.Add(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -386,7 +387,7 @@ namespace xcharts
|
|||||||
for (int i = 0; i < legend.dataList.Count; i++)
|
for (int i = 0; i < legend.dataList.Count; i++)
|
||||||
{
|
{
|
||||||
//LegendData data = legend.dataList[i];
|
//LegendData data = legend.dataList[i];
|
||||||
Button btn = ChartUtils.AddButtonObject(LEGEND_TEXT + i, transform, themeInfo.font,
|
Button btn = ChartUtils.AddButtonObject(LEGEND_TEXT +"_"+ i, transform, themeInfo.font,
|
||||||
themeInfo.textColor, Vector2.zero, Vector2.zero, Vector2.zero,
|
themeInfo.textColor, Vector2.zero, Vector2.zero, Vector2.zero,
|
||||||
new Vector2(legend.itemWidth, legend.itemHeight));
|
new Vector2(legend.itemWidth, legend.itemHeight));
|
||||||
legend.SetDataButton(i, btn);
|
legend.SetDataButton(i, btn);
|
||||||
@@ -397,9 +398,10 @@ namespace xcharts
|
|||||||
btn.GetComponentInChildren<Text>().text = legend.dataList[i];
|
btn.GetComponentInChildren<Text>().text = legend.dataList[i];
|
||||||
btn.onClick.AddListener(delegate ()
|
btn.onClick.AddListener(delegate ()
|
||||||
{
|
{
|
||||||
legend.SetShowData(i, !legend.IsShowSeries(i));
|
int index = int.Parse(btn.name.Split('_')[1]);
|
||||||
btn.GetComponent<Image>().color = legend.IsShowSeries(i) ?
|
legend.SetShowData(index, !legend.IsShowSeries(index));
|
||||||
themeInfo.GetColor(i) : themeInfo.unableColor;
|
btn.GetComponent<Image>().color = legend.IsShowSeries(index) ?
|
||||||
|
themeInfo.GetColor(index) : themeInfo.unableColor;
|
||||||
OnYMaxValueChanged();
|
OnYMaxValueChanged();
|
||||||
OnLegendButtonClicked();
|
OnLegendButtonClicked();
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace xcharts
|
|||||||
if (dist > pieRadius)
|
if (dist > pieRadius)
|
||||||
{
|
{
|
||||||
tooltip.DataIndex = 0;
|
tooltip.DataIndex = 0;
|
||||||
RefreshTooltip();
|
tooltip.SetActive(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ namespace xcharts
|
|||||||
private float radarCenterY = 0f;
|
private float radarCenterY = 0f;
|
||||||
private float radarRadius = 0;
|
private float radarRadius = 0;
|
||||||
private List<Text> indicatorTextList = new List<Text>();
|
private List<Text> indicatorTextList = new List<Text>();
|
||||||
|
private List<List<Vector3>> dataPosList = new List<List<Vector3>>();
|
||||||
|
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
@@ -181,10 +184,14 @@ namespace xcharts
|
|||||||
Vector3 startPoint = Vector3.zero;
|
Vector3 startPoint = Vector3.zero;
|
||||||
Vector3 toPoint = Vector3.zero;
|
Vector3 toPoint = Vector3.zero;
|
||||||
Vector3 firstPoint = Vector3.zero;
|
Vector3 firstPoint = Vector3.zero;
|
||||||
|
dataPosList.Clear();
|
||||||
for (int i = 0; i < seriesList.Count; i++)
|
for (int i = 0; i < seriesList.Count; i++)
|
||||||
{
|
{
|
||||||
if (!legend.IsShowSeries(i)) continue;
|
if (!legend.IsShowSeries(i))
|
||||||
|
{
|
||||||
|
dataPosList.Add(new List<Vector3>());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var dataList = seriesList[i].dataList;
|
var dataList = seriesList[i].dataList;
|
||||||
var color = themeInfo.GetColor(i);
|
var color = themeInfo.GetColor(i);
|
||||||
var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f);
|
var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f);
|
||||||
@@ -192,6 +199,7 @@ namespace xcharts
|
|||||||
radarInfo.indicatorList[i].max :
|
radarInfo.indicatorList[i].max :
|
||||||
GetMaxValue();
|
GetMaxValue();
|
||||||
List<Vector3> pointList = new List<Vector3>();
|
List<Vector3> pointList = new List<Vector3>();
|
||||||
|
dataPosList.Add(pointList);
|
||||||
for (int j = 0; j < dataList.Count; j++)
|
for (int j = 0; j < dataList.Count; j++)
|
||||||
{
|
{
|
||||||
var radius = radarInfo.radius * dataList[j] / max;
|
var radius = radarInfo.radius * dataList[j] / max;
|
||||||
@@ -313,5 +321,69 @@ namespace xcharts
|
|||||||
if (radarInfo.bottom > 0) radarCenterY = radarInfo.bottom + radarRadius;
|
if (radarInfo.bottom > 0) radarCenterY = radarInfo.bottom + radarRadius;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void CheckTootipArea(Vector2 local)
|
||||||
|
{
|
||||||
|
if (dataPosList.Count <= 0) return;
|
||||||
|
tooltip.DataIndex = 0;
|
||||||
|
for (int i = 0; i < seriesList.Count; i++)
|
||||||
|
{
|
||||||
|
if (!legend.IsShowSeries(i)) continue;
|
||||||
|
for (int j = 0; j < dataPosList[i].Count; j++)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(local, dataPosList[i][j]) <= radarInfo.linePointSize * 1.2f)
|
||||||
|
{
|
||||||
|
tooltip.DataIndex = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tooltip.DataIndex > 0)
|
||||||
|
{
|
||||||
|
tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||||
|
RefreshTooltip();
|
||||||
|
if (tooltip.LastDataIndex != tooltip.DataIndex)
|
||||||
|
{
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
tooltip.LastDataIndex = tooltip.DataIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tooltip.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void RefreshTooltip()
|
||||||
|
{
|
||||||
|
base.RefreshTooltip();
|
||||||
|
int index = tooltip.DataIndex - 1;
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
tooltip.SetActive(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tooltip.SetActive(true);
|
||||||
|
StringBuilder sb = new StringBuilder(legend.dataList[index]);
|
||||||
|
for (int i = 0; i < radarInfo.indicatorList.Count; i++)
|
||||||
|
{
|
||||||
|
string key = radarInfo.indicatorList[i].name;
|
||||||
|
float value = seriesList[index].dataList[i];
|
||||||
|
sb.Append("\n");
|
||||||
|
sb.AppendFormat("{0}: {1}", key, value);
|
||||||
|
}
|
||||||
|
tooltip.UpdateTooltipText(sb.ToString());
|
||||||
|
|
||||||
|
var pos = tooltip.GetPos();
|
||||||
|
if (pos.x + tooltip.Width > chartWid)
|
||||||
|
{
|
||||||
|
pos.x = chartWid - tooltip.Width;
|
||||||
|
}
|
||||||
|
if (pos.y - tooltip.Height < 0)
|
||||||
|
{
|
||||||
|
pos.y = tooltip.Height;
|
||||||
|
}
|
||||||
|
tooltip.UpdatePos(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user