mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 14:30:10 +00:00
增加Tooltip指示器类型,优化显示控制
This commit is contained in:
@@ -21,9 +21,12 @@ namespace XCharts
|
||||
public float barWidth { get { return m_BarWidth; } set { m_BarWidth = value; } }
|
||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||
|
||||
public static Bar defaultBar{
|
||||
get{
|
||||
return new Bar(){
|
||||
public static Bar defaultBar
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Bar()
|
||||
{
|
||||
m_InSameBar = false,
|
||||
m_BarWidth = 0.6f,
|
||||
m_Space = 10
|
||||
@@ -42,6 +45,7 @@ namespace XCharts
|
||||
base.Reset();
|
||||
m_Bar = Bar.defaultBar;
|
||||
m_Title.text = "BarChart";
|
||||
m_Tooltip.type = Tooltip.Type.Shadow;
|
||||
RemoveData();
|
||||
AddSerie("serie1", SerieType.Line);
|
||||
for (int i = 0; i < 5; i++)
|
||||
@@ -159,44 +163,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
if (m_Tooltip.crossLabel)
|
||||
{
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
Vector3 sp = new Vector2(m_Tooltip.pointerPos.x, coordinateY);
|
||||
Vector3 ep = new Vector2(m_Tooltip.pointerPos.x, coordinateY + coordinateHig);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
float splitWidth = yAxis.GetSplitWidth(coordinateHig, m_DataZoom);
|
||||
float pY = coordinateY + (m_Tooltip.yValues[i] - 1) * splitWidth +
|
||||
(yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
sp = new Vector2(coordinateX, pY);
|
||||
ep = new Vector2(coordinateX + coordinateWid, pY);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
float splitWidth = yAxis.GetSplitWidth(coordinateHig, m_DataZoom);
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
float pX = coordinateX + coordinateWid;
|
||||
float pY = coordinateY + splitWidth * (m_Tooltip.yValues[i] - 1) -
|
||||
(yAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
Vector3 p1 = new Vector3(coordinateX, pY);
|
||||
Vector3 p2 = new Vector3(coordinateX, pY + tooltipSplitWid);
|
||||
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
|
||||
Vector3 p4 = new Vector3(pX, pY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawYTooltipIndicator(vh);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -218,45 +185,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
if (m_Tooltip.crossLabel)
|
||||
{
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
if (!xAxis.show) continue;
|
||||
Vector3 sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
|
||||
Vector3 ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
|
||||
float splitWidth = xAxis.GetSplitWidth(coordinateWid, m_DataZoom);
|
||||
float px = coordinateX + (m_Tooltip.xValues[i] - 1) * splitWidth
|
||||
+ (xAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
sp = new Vector2(px, coordinateY);
|
||||
ep = new Vector2(px, coordinateY + coordinateHig);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
if (!xAxis.show) continue;
|
||||
float splitWidth = xAxis.GetSplitWidth(coordinateWid, m_DataZoom);
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
float pX = coordinateX + splitWidth * (m_Tooltip.xValues[i] - 1) -
|
||||
(xAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
float pY = coordinateY + coordinateHig;
|
||||
Vector3 p1 = new Vector3(pX, coordinateY);
|
||||
Vector3 p2 = new Vector3(pX, pY);
|
||||
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
|
||||
Vector3 p4 = new Vector3(pX + tooltipSplitWid, coordinateY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawXTooltipIndicator(vh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace XCharts
|
||||
Vertical
|
||||
}
|
||||
|
||||
public class BaseChart : MaskableGraphic, IPointerDownHandler, IPointerUpHandler,
|
||||
public class BaseChart : Graphic, IPointerDownHandler, IPointerUpHandler,
|
||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
@@ -232,7 +232,7 @@ namespace XCharts
|
||||
/// <returns>True when activated</returns>
|
||||
public virtual bool IsActive(int serieIndex)
|
||||
{
|
||||
return m_Legend.IsActive(serieIndex) || m_Series.IsActive(serieIndex);
|
||||
return m_Legend.IsActive(serieIndex) && m_Series.IsActive(serieIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -284,6 +284,18 @@ namespace XCharts
|
||||
CheckRefreshChart();
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
Awake();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
ChartHelper.DestoryAllChilds(transform);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
@@ -453,17 +465,18 @@ namespace XCharts
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.isInited)
|
||||
{
|
||||
if (m_Tooltip.dataIndex != 0)
|
||||
|
||||
if (m_Tooltip.dataIndex[0] != 0 || m_Tooltip.dataIndex[1] != 0)
|
||||
{
|
||||
m_Tooltip.dataIndex = 0;
|
||||
m_Tooltip.dataIndex[0] = m_Tooltip.dataIndex[1] = -1;
|
||||
m_Tooltip.SetActive(false);
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_Tooltip.dataIndex = 0;
|
||||
|
||||
m_Tooltip.dataIndex[0] = m_Tooltip.dataIndex[1] = -1;
|
||||
Vector2 local;
|
||||
if (canvas == null) return;
|
||||
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, canvas.worldCamera, out local))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -66,22 +67,44 @@ namespace XCharts
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Add a category data to xAxis.
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="xAxisIndex"></param>
|
||||
/// <param name="category">the category data</param>
|
||||
/// <param name="xAxisIndex">which xAxis should category add to</param>
|
||||
public void AddXAxisData(string category, int xAxisIndex = 0)
|
||||
{
|
||||
m_XAxises[xAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a category data to yAxis.
|
||||
/// </summary>
|
||||
/// <param name="category">the category data</param>
|
||||
/// <param name="yAxisIndex">which yAxis should category add to</param>
|
||||
public void AddYAxisData(string category, int yAxisIndex = 0)
|
||||
{
|
||||
m_YAxises[yAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether is Cartesian coordinates
|
||||
/// </summary>
|
||||
/// <returns>reutrn true when all show axis is value type</returns>
|
||||
public bool IsCartesian()
|
||||
{
|
||||
foreach (var axis in m_XAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsValue()) return false;
|
||||
}
|
||||
foreach (var axis in m_YAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsValue()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -131,17 +154,44 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var isCartesian = IsCartesian();
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
if (xAxis.IsValue())
|
||||
var yAxis = m_YAxises[i];
|
||||
if(!xAxis.show && !yAxis.show) continue;
|
||||
if (isCartesian && xAxis.show && yAxis.show)
|
||||
{
|
||||
var value = (xAxis.maxValue - xAxis.minValue) * (local.x - coordinateX - xAxis.zeroXOffset) / coordinateWid;
|
||||
if (xAxis.minValue > 0) value += xAxis.minValue;
|
||||
m_Tooltip.xValues[i] = value;
|
||||
var yRate = (yAxis.maxValue - yAxis.minValue) / coordinateHig;
|
||||
var xRate = (xAxis.maxValue - xAxis.minValue) / coordinateWid;
|
||||
var yValue = yRate * (local.y - coordinateY - yAxis.zeroYOffset);
|
||||
if (yAxis.minValue > 0) yValue += yAxis.minValue;
|
||||
m_Tooltip.yValues[i] = yValue;
|
||||
var xValue = xRate * (local.x - coordinateX - xAxis.zeroXOffset);
|
||||
if (xAxis.minValue > 0) xValue += xAxis.minValue;
|
||||
m_Tooltip.xValues[i] = xValue;
|
||||
|
||||
for (int j = 0; j < m_Series.Count; j++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(j);
|
||||
serie.selected = false;
|
||||
for (int n = 0; n < serie.xData.Count; n++)
|
||||
{
|
||||
var xdata = serie.xData[n];
|
||||
var ydata = serie.yData[n];
|
||||
if (Mathf.Abs(xValue - xdata) / xRate < 5 && Mathf.Abs(yValue - ydata) / yRate < 5)
|
||||
{
|
||||
m_Tooltip.dataIndex[i] = n;
|
||||
serie.selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (xAxis.IsCategory())
|
||||
{
|
||||
var value = (yAxis.maxValue - yAxis.minValue) * (local.y - coordinateY - yAxis.zeroYOffset) / coordinateHig;
|
||||
if (yAxis.minValue > 0) value += yAxis.minValue;
|
||||
m_Tooltip.yValues[i] = value;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
@@ -149,24 +199,17 @@ namespace XCharts
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.xValues[i] = j + 1;
|
||||
if (i == 0) m_Tooltip.dataIndex = j + 1;
|
||||
m_Tooltip.xValues[i] = j;
|
||||
m_Tooltip.dataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var yAxis = m_YAxises[i];
|
||||
if (yAxis.IsValue())
|
||||
{
|
||||
var value = (yAxis.maxValue - yAxis.minValue) * (local.y - coordinateY - yAxis.zeroYOffset) / coordinateHig;
|
||||
if (yAxis.minValue > 0) value += yAxis.minValue;
|
||||
m_Tooltip.yValues[i] = value;
|
||||
}
|
||||
else
|
||||
else if (yAxis.IsCategory())
|
||||
{
|
||||
var value = (xAxis.maxValue - xAxis.minValue) * (local.x - coordinateX - xAxis.zeroXOffset) / coordinateWid;
|
||||
if (xAxis.minValue > 0) value += xAxis.minValue;
|
||||
m_Tooltip.xValues[i] = value;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
@@ -174,23 +217,25 @@ namespace XCharts
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.yValues[i] = j + 1;
|
||||
if (i == 0) m_Tooltip.dataIndex = j + 1;
|
||||
m_Tooltip.yValues[i] = j;
|
||||
m_Tooltip.dataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
if (m_Tooltip.IsSelected())
|
||||
{
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex || m_Tooltip.crossLabel)
|
||||
if (m_Tooltip.IsDataIndexChanged() || m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
m_Tooltip.UpdateLastDataIndex();
|
||||
RefreshChart();
|
||||
}
|
||||
m_Tooltip.lastDataIndex = m_Tooltip.dataIndex;
|
||||
}else{
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,14 +244,20 @@ namespace XCharts
|
||||
base.RefreshTooltip();
|
||||
int index;
|
||||
Axis tempAxis;
|
||||
if (m_XAxises[0].type == Axis.AxisType.Value)
|
||||
bool isCartesian = IsCartesian();
|
||||
if (isCartesian)
|
||||
{
|
||||
index = (int)m_Tooltip.yValues[0] - 1;
|
||||
index = m_Tooltip.dataIndex[0];
|
||||
tempAxis = m_XAxises[0];
|
||||
}
|
||||
else if (m_XAxises[0].type == Axis.AxisType.Value)
|
||||
{
|
||||
index = (int)m_Tooltip.yValues[0];
|
||||
tempAxis = m_YAxises[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
index = (int)m_Tooltip.xValues[0] - 1;
|
||||
index = (int)m_Tooltip.xValues[0];
|
||||
tempAxis = m_XAxises[0];
|
||||
}
|
||||
if (index < 0)
|
||||
@@ -214,30 +265,39 @@ namespace XCharts
|
||||
m_Tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
if (m_Series.Count == 1)
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!isCartesian)
|
||||
{
|
||||
float value = m_Series.GetData(0, index);
|
||||
string txt = tempAxis.GetData(index, m_DataZoom) + ": " + value;
|
||||
m_Tooltip.UpdateContentText(txt);
|
||||
sb.Append(tempAxis.GetData(index, m_DataZoom));
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(tempAxis.GetData(index, m_DataZoom));
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
var serie = m_Series.GetSerie(i);
|
||||
if (serie.show)
|
||||
{
|
||||
if (m_Series.series[i].show)
|
||||
string key = serie.name;
|
||||
//if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(i);
|
||||
if(!string.IsNullOrEmpty(key)) key += ":";
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(index, m_DataZoom, out xValue, out yValue);
|
||||
if (isCartesian)
|
||||
{
|
||||
if (serie.selected)
|
||||
{
|
||||
sb.AppendFormat("{0}[{1}, {2}]\n", key, xValue, yValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(i));
|
||||
string key = m_Series.series[i].name;
|
||||
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(i);
|
||||
float value = m_Series.series[i].GetYData(index, m_DataZoom);
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("<color=#{0}>● </color>", strColor);
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
sb.AppendFormat("{0}{1}", key, yValue);
|
||||
}
|
||||
}
|
||||
m_Tooltip.UpdateContentText(sb.ToString());
|
||||
}
|
||||
m_Tooltip.UpdateContentText(sb.ToString().Trim());
|
||||
|
||||
var pos = m_Tooltip.GetContentPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
@@ -263,7 +323,8 @@ namespace XCharts
|
||||
|
||||
private void UpdateAxisTooltipLabel(int axisIndex, Axis axis)
|
||||
{
|
||||
axis.SetTooltipLabelActive(axis.show && m_Tooltip.crossLabel);
|
||||
var showTooltipLabel = axis.show && m_Tooltip.type == Tooltip.Type.Corss;
|
||||
axis.SetTooltipLabelActive(showTooltipLabel);
|
||||
string labelText = "";
|
||||
Vector2 labelPos = Vector2.zero;
|
||||
if (axis is XAxis)
|
||||
@@ -277,9 +338,9 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
labelText = axis.GetData((int)m_Tooltip.xValues[axisIndex] - 1, m_DataZoom);
|
||||
labelText = axis.GetData((int)m_Tooltip.xValues[axisIndex], m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(coordinateWid, m_DataZoom);
|
||||
int index = (int)m_Tooltip.xValues[axisIndex] - 1;
|
||||
int index = (int)m_Tooltip.xValues[axisIndex];
|
||||
float px = coordinateX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f;
|
||||
labelPos = new Vector2(px, posY - diff);
|
||||
}
|
||||
@@ -295,9 +356,9 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
labelText = axis.GetData((int)m_Tooltip.yValues[axisIndex] - 1, m_DataZoom);
|
||||
labelText = axis.GetData((int)m_Tooltip.yValues[axisIndex], m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(coordinateHig, m_DataZoom);
|
||||
int index = (int)m_Tooltip.yValues[axisIndex] - 1;
|
||||
int index = (int)m_Tooltip.yValues[axisIndex];
|
||||
float py = coordinateY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0);
|
||||
labelPos = new Vector2(posX - diff, py);
|
||||
}
|
||||
@@ -433,7 +494,7 @@ namespace XCharts
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
yAxis.SetTooltipLabel(labelObj);
|
||||
yAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
yAxis.SetTooltipLabelActive(yAxis.show && m_Tooltip.show && m_Tooltip.crossLabel);
|
||||
yAxis.SetTooltipLabelActive(yAxis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,7 +581,7 @@ namespace XCharts
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
xAxis.SetTooltipLabel(labelObj);
|
||||
xAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
xAxis.SetTooltipLabelActive(xAxis.show && m_Tooltip.show && m_Tooltip.crossLabel);
|
||||
xAxis.SetTooltipLabelActive(xAxis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,7 +701,7 @@ namespace XCharts
|
||||
private void UpdateAxisMinMaxValue(int axisIndex, Axis axis)
|
||||
{
|
||||
axis.minValue = 0;
|
||||
axis.maxValue = 0;
|
||||
axis.maxValue = 100;
|
||||
if (axis.IsCategory()) return;
|
||||
|
||||
int tempMinValue = 0;
|
||||
@@ -661,6 +722,7 @@ namespace XCharts
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue);
|
||||
|
||||
if (tempMinValue != axis.minValue || tempMaxValue != axis.maxValue)
|
||||
{
|
||||
axis.minValue = tempMinValue;
|
||||
@@ -827,15 +889,15 @@ namespace XCharts
|
||||
{
|
||||
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].zeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHig;
|
||||
var left = new Vector3(coordinateX - m_Coordinate.tickness, lineY);
|
||||
var top = new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, lineY);
|
||||
ChartHelper.DrawLine(vh, new Vector3(coordinateX - m_Coordinate.tickness, lineY),
|
||||
top, m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawLine(vh, left,top, m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
if (xAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = xAxis.axisLine;
|
||||
top.x += xAxis.axisLine.symbolOffset;
|
||||
var middle = new Vector3(top.x - axisLine.symbolHeight + axisLine.symbolDent, lineY);
|
||||
var left = new Vector3(top.x - axisLine.symbolHeight, lineY - axisLine.symbolWidth / 2);
|
||||
left = new Vector3(top.x - axisLine.symbolHeight, lineY - axisLine.symbolWidth / 2);
|
||||
var right = new Vector3(top.x - axisLine.symbolHeight, lineY + axisLine.symbolWidth / 2);
|
||||
ChartHelper.DrawTriangle(vh, middle, top, left, m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawTriangle(vh, middle, top, right, m_ThemeInfo.axisLineColor);
|
||||
@@ -961,6 +1023,91 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawXTooltipIndicator(VertexHelper vh)
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
|
||||
if (m_Tooltip.type == Tooltip.Type.None) return;
|
||||
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!xAxis.show) continue;
|
||||
float splitWidth = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
case Tooltip.Type.Line:
|
||||
float pX = coordinateX + m_Tooltip.xValues[i] * splitWidth
|
||||
+ (xAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
if (xAxis.IsValue()) pX = m_Tooltip.pointerPos.x;
|
||||
Vector2 sp = new Vector2(pX, coordinateY);
|
||||
Vector2 ep = new Vector2(pX, coordinateY + coordinateHig);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
pX = coordinateX + splitWidth * m_Tooltip.xValues[i] -
|
||||
(xAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
if (xAxis.IsValue()) pX = m_Tooltip.xValues[i];
|
||||
float pY = coordinateY + coordinateHig;
|
||||
Vector3 p1 = new Vector3(pX, coordinateY);
|
||||
Vector3 p2 = new Vector3(pX, pY);
|
||||
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
|
||||
Vector3 p4 = new Vector3(pX + tooltipSplitWid, coordinateY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawYTooltipIndicator(VertexHelper vh)
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
|
||||
if (m_Tooltip.type == Tooltip.Type.None) return;
|
||||
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
float splitWidth = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
case Tooltip.Type.Line:
|
||||
|
||||
float pY = coordinateY + m_Tooltip.yValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(coordinateX, pY);
|
||||
Vector2 ep = new Vector2(coordinateX + coordinateWid, pY);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
float pX = coordinateX + coordinateWid;
|
||||
pY = coordinateY + splitWidth * m_Tooltip.yValues[i] -
|
||||
(yAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
Vector3 p1 = new Vector3(coordinateX, pY);
|
||||
Vector3 p2 = new Vector3(coordinateX, pY + tooltipSplitWid);
|
||||
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
|
||||
Vector3 p4 = new Vector3(pX, pY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckDataZoom()
|
||||
{
|
||||
if (raycastTarget != m_DataZoom.show)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace XCharts
|
||||
m_ItemFontSize = 16,
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"Legend"
|
||||
"serie1"
|
||||
}
|
||||
};
|
||||
legend.location.top = 30;
|
||||
@@ -138,9 +138,7 @@ namespace XCharts
|
||||
|
||||
public bool IsActive(int seriesIndex)
|
||||
{
|
||||
if (seriesIndex < 0 || seriesIndex > data.Count - 1) seriesIndex = 0;
|
||||
if (seriesIndex >= data.Count) return true;
|
||||
if (seriesIndex < 0 || seriesIndex > m_DataActiveList.Count - 1)
|
||||
if (seriesIndex < 0 || seriesIndex >= m_DataActiveList.Count)
|
||||
return true;
|
||||
else
|
||||
return m_DataActiveList[seriesIndex];
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private bool m_Point;
|
||||
[SerializeField] private float m_PointWidth;
|
||||
[SerializeField] private float m_PointSelectedWidth;
|
||||
[SerializeField] private bool m_Smooth;
|
||||
[SerializeField] [Range(1f, 10f)] private float m_SmoothStyle;
|
||||
[SerializeField] private bool m_Area;
|
||||
@@ -23,8 +24,9 @@ namespace XCharts
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
public bool point { get { return m_Point; } set { m_Point = value; } }
|
||||
public float pointWidth { get { return m_PointWidth; } set { m_PointWidth = value; } }
|
||||
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
|
||||
public float pointSelectedWidth { get { return m_PointSelectedWidth; } set { m_PointSelectedWidth = value; } }
|
||||
public float smoothStyle { get { return m_SmoothStyle; } set { m_SmoothStyle = value; } }
|
||||
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
public bool step { get { return m_Step; } set { m_Step = value; } }
|
||||
public StepType stepTpe { get { return m_StepType; } set { m_StepType = value; } }
|
||||
@@ -38,6 +40,7 @@ namespace XCharts
|
||||
m_Tickness = 0.8f,
|
||||
m_Point = true,
|
||||
m_PointWidth = 2.5f,
|
||||
m_PointSelectedWidth = 5.5f,
|
||||
m_Smooth = false,
|
||||
m_SmoothStyle = 2f,
|
||||
m_Area = false,
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace XCharts
|
||||
{
|
||||
[SerializeField] [DefaultValue("true")] private bool m_Show;
|
||||
[SerializeField] private SerieType m_Type;
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Stack;
|
||||
[SerializeField] private int m_AxisIndex;
|
||||
@@ -26,6 +27,8 @@ namespace XCharts
|
||||
[SerializeField] private List<float> m_YData = new List<float>();
|
||||
[SerializeField] private List<float> m_XData = new List<float>();
|
||||
|
||||
public int index { get; set; }
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public SerieType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace XCharts
|
||||
{
|
||||
m_Series = new List<Serie>(){new Serie(){
|
||||
show = true,
|
||||
index = 0
|
||||
}}
|
||||
};
|
||||
return series;
|
||||
@@ -106,6 +107,7 @@ namespace XCharts
|
||||
if (serie == null)
|
||||
{
|
||||
serie = new Serie();
|
||||
serie.index = m_Series.Count;
|
||||
serie.type = type;
|
||||
serie.show = show;
|
||||
serie.name = serieName;
|
||||
@@ -130,6 +132,7 @@ namespace XCharts
|
||||
if (serie == null)
|
||||
{
|
||||
serie = new Serie();
|
||||
serie.index = m_Series.Count;
|
||||
serie.name = name;
|
||||
serie.yData = new List<float>();
|
||||
m_Series.Add(serie);
|
||||
@@ -244,6 +247,13 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsTooltipSelected(int serieIndex)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null) return serie.selected;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, false, out minVaule, out maxValue);
|
||||
@@ -377,8 +387,10 @@ namespace XCharts
|
||||
int count = 0;
|
||||
Dictionary<string, int> sets = new Dictionary<string, int>();
|
||||
Dictionary<int, List<Serie>> stackSeries = new Dictionary<int, List<Serie>>();
|
||||
foreach (var serie in m_Series)
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series[i];
|
||||
serie.index = i;
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
stackSeries[count] = new List<Serie>();
|
||||
|
||||
@@ -8,8 +8,49 @@ namespace XCharts
|
||||
[System.Serializable]
|
||||
public class Tooltip
|
||||
{
|
||||
/// <summary>
|
||||
/// Type of triggering.
|
||||
/// </summary>
|
||||
public enum Trigger
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggered by axes, which is mainly used for charts that have category axes,
|
||||
/// like bar charts or line charts.
|
||||
/// </summary>
|
||||
Axis,
|
||||
/// <summary>
|
||||
/// Triggered by data item, which is mainly used for charts that don't have a
|
||||
/// category axis like scatter charts or pie charts.
|
||||
/// </summary>
|
||||
Item
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicator type.
|
||||
/// </summary>
|
||||
public enum Type
|
||||
{
|
||||
/// <summary>
|
||||
/// line indicator.
|
||||
/// </summary>
|
||||
Line,
|
||||
/// <summary>
|
||||
/// shadow crosshair indicator.
|
||||
/// </summary>
|
||||
Shadow,
|
||||
/// <summary>
|
||||
/// no indicator displayed.
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
|
||||
/// </summary>
|
||||
Corss
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private bool m_CrossLabel;
|
||||
[SerializeField] private Type m_Type;
|
||||
[SerializeField] private Trigger m_Trigger;
|
||||
|
||||
[NonSerialized] private GameObject m_GameObject;
|
||||
[NonSerialized] private GameObject m_Content;
|
||||
@@ -17,13 +58,17 @@ namespace XCharts
|
||||
[NonSerialized] private RectTransform m_ContentRect;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; SetActive(value); } }
|
||||
public bool crossLabel { get { return m_CrossLabel; } set { m_CrossLabel = value; } }
|
||||
|
||||
public int dataIndex { get; set; }
|
||||
public Type type { get { return m_Type; } set { m_Type = value; } }
|
||||
public Trigger trigger { get { return m_Trigger; } set { m_Trigger = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The data index currently indicated by Tooltip.
|
||||
/// </summary>
|
||||
public int[] dataIndex { get; set; }
|
||||
public int[] lastDataIndex { get; set; }
|
||||
public float[] xValues { get; set; }
|
||||
public float[] yValues { get; set; }
|
||||
public int lastDataIndex { get; set; }
|
||||
|
||||
public Vector2 pointerPos { get; set; }
|
||||
public float width { get { return m_ContentRect.sizeDelta.x; } }
|
||||
public float height { get { return m_ContentRect.sizeDelta.y; } }
|
||||
@@ -37,9 +82,10 @@ namespace XCharts
|
||||
var tooltip = new Tooltip
|
||||
{
|
||||
m_Show = true,
|
||||
m_CrossLabel = false,
|
||||
xValues = new float[2],
|
||||
yValues = new float[2],
|
||||
dataIndex = new int[2],
|
||||
lastDataIndex = new int[2]
|
||||
};
|
||||
return tooltip;
|
||||
}
|
||||
@@ -58,7 +104,8 @@ namespace XCharts
|
||||
m_ContentText = m_Content.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void UpdateToTop(){
|
||||
public void UpdateToTop()
|
||||
{
|
||||
int count = m_GameObject.transform.parent.childCount;
|
||||
m_GameObject.GetComponent<RectTransform>().SetSiblingIndex(count - 1);
|
||||
}
|
||||
@@ -88,14 +135,14 @@ namespace XCharts
|
||||
|
||||
public void ClearValue()
|
||||
{
|
||||
dataIndex = 0;
|
||||
xValues[0] = xValues[1] = 0;
|
||||
yValues[0] = yValues[1] = 0;
|
||||
dataIndex[0] = dataIndex[1] = -1;
|
||||
xValues[0] = xValues[1] = -1;
|
||||
yValues[0] = yValues[1] = -1;
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
lastDataIndex = 0;
|
||||
lastDataIndex[0] = lastDataIndex[1] = -1;
|
||||
if (m_GameObject && m_GameObject.activeInHierarchy != flag)
|
||||
m_GameObject.SetActive(flag);
|
||||
}
|
||||
@@ -113,5 +160,25 @@ namespace XCharts
|
||||
else
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
public bool IsDataIndexChanged()
|
||||
{
|
||||
return dataIndex[0] != lastDataIndex[0] ||
|
||||
dataIndex[1] != lastDataIndex[1];
|
||||
}
|
||||
|
||||
public void UpdateLastDataIndex()
|
||||
{
|
||||
lastDataIndex[0] = dataIndex[0];
|
||||
lastDataIndex[1] = dataIndex[1];
|
||||
}
|
||||
|
||||
public bool IsSelected(){
|
||||
return dataIndex[0] >= 0 || dataIndex[1] >= 0;
|
||||
}
|
||||
|
||||
public bool IsSelectedDataIndex(int index){
|
||||
return dataIndex[0] == index || dataIndex[1] == index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ namespace XCharts
|
||||
base.Reset();
|
||||
m_Line = Line.defaultLine;
|
||||
m_Title.text = "LineChart";
|
||||
m_Tooltip.type = Tooltip.Type.Line;
|
||||
RemoveData();
|
||||
AddSerie("serie1", SerieType.Line);
|
||||
for (int i = 0; i < 5; i++)
|
||||
@@ -44,7 +45,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DrawXCategory(VertexHelper vh)
|
||||
{
|
||||
var stackSeries = m_Series.GetStackSeries();
|
||||
@@ -52,70 +52,24 @@ namespace XCharts
|
||||
|
||||
int serieCount = 0;
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
List<Color> colorList = new List<Color>();
|
||||
List<Color> colors = new List<Color>();
|
||||
int dataCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
DrawXLineSerie(vh, serieCount, serie, ref dataCount, ref points, ref colorList, ref seriesCurrHig);
|
||||
DrawXLineSerie(vh, serieCount, serie, ref dataCount, ref points, ref colors, ref seriesCurrHig);
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
}
|
||||
}
|
||||
// draw point
|
||||
if (m_Line.point)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
Vector3 p = points[i];
|
||||
float pointWid = m_Line.pointWidth;
|
||||
if (m_Tooltip.show && i % dataCount == m_Tooltip.dataIndex - 1)
|
||||
{
|
||||
pointWid = pointWid * 1.8f;
|
||||
}
|
||||
if (m_Theme == Theme.Dark)
|
||||
{
|
||||
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, colorList[i],
|
||||
(int)m_Line.pointWidth * 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness,
|
||||
pointWid, 0, 360, colorList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//draw tooltip line
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var axis = m_XAxises[i];
|
||||
if (!axis.show) continue;
|
||||
float splitWidth = axis.GetSplitWidth(coordinateWid, m_DataZoom);
|
||||
float px = coordinateX + (m_Tooltip.xValues[i] - 1) * splitWidth
|
||||
+ (axis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(px, coordinateY);
|
||||
Vector2 ep = new Vector2(px, coordinateY + coordinateHig);
|
||||
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipLineColor);
|
||||
if (m_Tooltip.crossLabel)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
|
||||
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
}
|
||||
}
|
||||
DrawPoint(vh, dataCount, points, colors);
|
||||
}
|
||||
DrawXTooltipIndicator(vh);
|
||||
}
|
||||
|
||||
private void DrawYCategory(VertexHelper vh)
|
||||
@@ -130,7 +84,6 @@ namespace XCharts
|
||||
{
|
||||
var seriesHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
@@ -140,46 +93,41 @@ namespace XCharts
|
||||
serieCount++;
|
||||
}
|
||||
}
|
||||
// draw point
|
||||
if (m_Line.point)
|
||||
DrawPoint(vh, dataCount, points, colors);
|
||||
}
|
||||
DrawYTooltipIndicator(vh);
|
||||
}
|
||||
|
||||
private void DrawPoint(VertexHelper vh, int dataCount, List<Vector3> points, List<Color> colors)
|
||||
{
|
||||
if (m_Line.point)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
Vector3 p = points[i];
|
||||
float pointWid = m_Line.pointWidth;
|
||||
if (m_Tooltip.show && m_Tooltip.IsSelectedDataIndex(i % dataCount))
|
||||
{
|
||||
Vector3 p = points[i];
|
||||
float pointWid = m_Line.pointWidth;
|
||||
if (m_Tooltip.show && i % dataCount == m_Tooltip.dataIndex - 1)
|
||||
if (IsCartesian())
|
||||
{
|
||||
pointWid = pointWid * 1.8f;
|
||||
}
|
||||
if (m_Theme == Theme.Dark)
|
||||
{
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, colors[i], (int)m_Line.pointWidth * 5);
|
||||
if (m_Series.IsTooltipSelected(i / dataCount))
|
||||
{
|
||||
pointWid = m_Line.pointSelectedWidth;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, colors[i]);
|
||||
pointWid = m_Line.pointSelectedWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//draw tooltip line
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var axis = m_YAxises[i];
|
||||
if (!axis.show) continue;
|
||||
float splitWidth = axis.GetSplitWidth(coordinateHig, m_DataZoom);
|
||||
float pY = coordinateY + (m_Tooltip.yValues[i] - 1) * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(coordinateX, pY);
|
||||
Vector2 ep = new Vector2(coordinateX + coordinateWid, pY);
|
||||
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
if (m_Tooltip.crossLabel)
|
||||
if (m_Theme == Theme.Dark)
|
||||
{
|
||||
sp = new Vector2(m_Tooltip.pointerPos.x, coordinateY);
|
||||
ep = new Vector2(m_Tooltip.pointerPos.x, coordinateY + coordinateHig);
|
||||
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, colors[i], (int)m_Line.pointWidth * 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, colors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +136,7 @@ namespace XCharts
|
||||
private void DrawXLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref int dataCount,
|
||||
ref List<Vector3> points, ref List<Color> colors, ref Dictionary<int, float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
if (!IsActive(serie.index)) return;
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
@@ -385,7 +333,7 @@ namespace XCharts
|
||||
private void DrawYLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref int dataCount,
|
||||
ref List<Vector3> points, ref List<Color> colors, ref Dictionary<int, float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
if (!IsActive(serie.index)) return;
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
@@ -432,7 +380,7 @@ namespace XCharts
|
||||
float pX = seriesHig[i] + coordinateX + m_Coordinate.tickness;
|
||||
float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
|
||||
//Debug.LogError(gameObject.name +","+(pX + dataHig)+","+startY+","+scaleWid+","+xAxis.maxValue+","+xAxis.minValue);
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.step)
|
||||
|
||||
@@ -110,12 +110,12 @@ namespace XCharts
|
||||
float outSideRadius = m_Pie.rose ?
|
||||
m_Pie.insideRadius + (m_PieRadius - m_Pie.insideRadius) * value / dataMax :
|
||||
m_PieRadius;
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex == i + 1)
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex[0] == i)
|
||||
{
|
||||
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||
}
|
||||
var offset = m_Pie.space;
|
||||
if (m_Pie.selected && m_Pie.selectedIndex == i + 1)
|
||||
if (m_Pie.selected && m_Pie.selectedIndex == i)
|
||||
{
|
||||
offset += m_Pie.selectedOffset;
|
||||
}
|
||||
@@ -198,22 +198,22 @@ namespace XCharts
|
||||
float dist = Vector2.Distance(local, m_PieCenter);
|
||||
if (dist > m_PieRadius)
|
||||
{
|
||||
m_Tooltip.dataIndex = 0;
|
||||
m_Tooltip.dataIndex[0] = -1;
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Tooltip.dataIndex = GetPosPieIndex(local);
|
||||
m_Tooltip.dataIndex[0] = GetPosPieIndex(local);
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
if (m_Tooltip.dataIndex[0] >= 0)
|
||||
{
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
if (m_Tooltip.IsSelected())
|
||||
{
|
||||
m_Tooltip.UpdateLastDataIndex();
|
||||
RefreshChart();
|
||||
}
|
||||
m_Tooltip.lastDataIndex = m_Tooltip.dataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,14 +225,14 @@ namespace XCharts
|
||||
{
|
||||
if (i == 0 && angle < m_AngleList[i])
|
||||
{
|
||||
return m_Tooltip.dataIndex = 1;
|
||||
return m_Tooltip.dataIndex[0] = 0;
|
||||
}
|
||||
else if (angle < m_AngleList[i] && angle > m_AngleList[i - 1])
|
||||
{
|
||||
return m_Tooltip.dataIndex = i + 1;
|
||||
return m_Tooltip.dataIndex[0] = i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
float VectorAngle(Vector2 from, Vector2 to)
|
||||
@@ -249,7 +249,7 @@ namespace XCharts
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = m_Tooltip.dataIndex - 1;
|
||||
int index = m_Tooltip.dataIndex[0];
|
||||
if (index < 0)
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
@@ -290,7 +290,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Pie.selectedIndex = 0;
|
||||
m_Pie.selectedIndex = -1;
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ namespace XCharts
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
if (dataPosList.Count <= 0) return;
|
||||
m_Tooltip.dataIndex = 0;
|
||||
m_Tooltip.dataIndex[0] = -1;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!IsActive(i)) continue;
|
||||
@@ -321,12 +321,12 @@ namespace XCharts
|
||||
{
|
||||
if (Vector3.Distance(local, dataPosList[i][j]) <= m_Radar.linePointSize * 1.2f)
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
m_Tooltip.dataIndex[0] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
if (m_Tooltip.dataIndex[0] >= 0)
|
||||
{
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
@@ -345,7 +345,7 @@ namespace XCharts
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = m_Tooltip.dataIndex - 1;
|
||||
int index = m_Tooltip.dataIndex[0];
|
||||
if (index < 0)
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
|
||||
Reference in New Issue
Block a user