2019-10-22 04:09:04 +08:00
|
|
|
|
/******************************************/
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/* Copyright (c) 2018 monitor1394 */
|
|
|
|
|
|
/* https://github.com/monitor1394 */
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/******************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System.Text;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
using UnityEngine;
|
2019-07-02 18:33:12 +08:00
|
|
|
|
using UnityEngine.EventSystems;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace XCharts
|
|
|
|
|
|
{
|
2019-07-15 00:24:04 +08:00
|
|
|
|
[AddComponentMenu("XCharts/PieChart", 15)]
|
|
|
|
|
|
[ExecuteInEditMode]
|
|
|
|
|
|
[RequireComponent(typeof(RectTransform))]
|
|
|
|
|
|
[DisallowMultipleComponent]
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public class PieChart : BaseChart
|
|
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
private bool isDrawPie;
|
|
|
|
|
|
private bool m_IsEnterLegendButtom;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
|
2019-07-15 00:24:04 +08:00
|
|
|
|
protected override void Awake()
|
|
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
base.Awake();
|
|
|
|
|
|
raycastTarget = false;
|
2019-07-15 00:24:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
protected override void Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Reset();
|
2019-07-15 19:21:22 +08:00
|
|
|
|
m_Title.text = "PieChart";
|
2020-02-26 22:52:57 +08:00
|
|
|
|
m_Legend.show = true;
|
2019-07-15 00:24:04 +08:00
|
|
|
|
RemoveData();
|
2019-10-05 18:23:06 +08:00
|
|
|
|
AddSerie(SerieType.Pie, "serie1");
|
2019-07-28 00:44:53 +08:00
|
|
|
|
AddData(0, 70, "pie1");
|
|
|
|
|
|
AddData(0, 20, "pie2");
|
|
|
|
|
|
AddData(0, 10, "pie3");
|
2019-07-15 00:24:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2019-07-28 00:44:53 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Update();
|
|
|
|
|
|
if (!isDrawPie) RefreshChart();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
protected override void DrawChart(VertexHelper vh)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.DrawChart(vh);
|
2019-07-19 21:55:22 +08:00
|
|
|
|
int serieNameCount = -1;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
bool isClickOffset = false;
|
|
|
|
|
|
bool isDataHighlight = false;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
for (int i = 0; i < m_Series.Count; i++)
|
|
|
|
|
|
{
|
2019-10-01 13:52:02 +08:00
|
|
|
|
var serie = m_Series.list[i];
|
2019-07-19 21:55:22 +08:00
|
|
|
|
serie.index = i;
|
2019-09-05 09:21:37 +08:00
|
|
|
|
var data = serie.data;
|
|
|
|
|
|
serie.animation.InitProgress(data.Count, 0, 360);
|
2020-02-23 11:06:16 +08:00
|
|
|
|
if (!serie.show || serie.animation.HasFadeOut())
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
continue;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-09-05 09:21:37 +08:00
|
|
|
|
bool isFinish = true;
|
2019-08-15 21:44:30 +08:00
|
|
|
|
if (serie.pieClickOffset) isClickOffset = true;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serie.runtimePieDataMax = serie.yMax;
|
|
|
|
|
|
serie.runtimePieDataTotal = serie.yTotal;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
serie.UpdateCenter(chartWidth, chartHeight);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
|
|
|
|
|
|
float totalDegree = 360;
|
|
|
|
|
|
float startDegree = 0;
|
2019-07-29 08:01:39 +08:00
|
|
|
|
int showdataCount = 0;
|
2019-09-05 09:21:37 +08:00
|
|
|
|
foreach (var sd in serie.data)
|
2019-07-29 08:01:39 +08:00
|
|
|
|
{
|
2019-09-05 09:21:37 +08:00
|
|
|
|
if (sd.show && serie.pieRoseType == RoseType.Area) showdataCount++;
|
|
|
|
|
|
sd.canShowLabel = false;
|
2019-07-29 08:01:39 +08:00
|
|
|
|
}
|
2019-12-03 07:49:37 +08:00
|
|
|
|
bool dataChanging = false;
|
2020-02-23 11:06:16 +08:00
|
|
|
|
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
2019-07-28 00:44:53 +08:00
|
|
|
|
for (int n = 0; n < data.Count; n++)
|
2019-07-02 18:33:12 +08:00
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
var serieData = data[n];
|
2020-04-08 09:02:46 +08:00
|
|
|
|
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
|
2019-10-16 19:05:24 +08:00
|
|
|
|
serieData.index = n;
|
2020-02-23 11:06:16 +08:00
|
|
|
|
float value = serieData.GetCurrData(1, dataChangeDuration);
|
2019-12-03 07:49:37 +08:00
|
|
|
|
if (serieData.IsDataChanged()) dataChanging = true;
|
2019-10-16 19:05:24 +08:00
|
|
|
|
serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
|
|
|
|
|
|
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
|
2020-04-08 09:02:46 +08:00
|
|
|
|
var borderWidth = itemStyle.borderWidth;
|
|
|
|
|
|
var borderColor = itemStyle.borderColor;
|
|
|
|
|
|
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieStartAngle = startDegree;
|
|
|
|
|
|
serieData.runtimePieToAngle = startDegree;
|
|
|
|
|
|
serieData.runtimePieHalfAngle = startDegree;
|
|
|
|
|
|
serieData.runtimePieCurrAngle = startDegree;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
if (!serieData.show)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2019-10-05 18:23:06 +08:00
|
|
|
|
float degree = serie.pieRoseType == RoseType.Area ?
|
2019-11-02 08:24:37 +08:00
|
|
|
|
(totalDegree / showdataCount) : (totalDegree * value / serie.runtimePieDataTotal);
|
|
|
|
|
|
serieData.runtimePieToAngle = startDegree + degree;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
|
2019-11-30 21:24:04 +08:00
|
|
|
|
serie.runtimeInsideRadius + (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimePieDataMax :
|
|
|
|
|
|
serie.runtimeOutsideRadius;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
if (serieData.highlighted)
|
|
|
|
|
|
{
|
|
|
|
|
|
isDataHighlight = true;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieOutsideRadius += m_Settings.pieTooltipExtraRadius;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2020-04-08 09:02:46 +08:00
|
|
|
|
var offset = 0f;
|
2019-08-15 21:44:30 +08:00
|
|
|
|
if (serie.pieClickOffset && serieData.selected)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2019-10-16 19:15:55 +08:00
|
|
|
|
offset += m_Settings.pieSelectedOffset;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2019-11-02 08:24:37 +08:00
|
|
|
|
var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2;
|
|
|
|
|
|
serieData.runtimePieHalfAngle = startDegree + halfDegree;
|
|
|
|
|
|
float currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
float currSin = Mathf.Sin(currRad);
|
|
|
|
|
|
float currCos = Mathf.Cos(currRad);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var center = serie.runtimeCenterPos;
|
2019-09-05 09:21:37 +08:00
|
|
|
|
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieCurrAngle = serieData.runtimePieToAngle;
|
|
|
|
|
|
serieData.runtiemPieOffsetCenter = center;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
|
2020-03-08 10:47:48 +08:00
|
|
|
|
if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
|
2019-09-05 09:21:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
isFinish = false;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail();
|
2019-09-05 09:21:37 +08:00
|
|
|
|
}
|
2019-07-28 00:44:53 +08:00
|
|
|
|
if (offset > 0)
|
|
|
|
|
|
{
|
2020-04-08 09:02:46 +08:00
|
|
|
|
serieData.runtimePieOffsetRadius = 0;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieInsideRadius -= serieData.runtimePieOffsetRadius;
|
|
|
|
|
|
serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius;
|
2019-08-15 21:44:30 +08:00
|
|
|
|
if (serie.pieClickOffset && serieData.selected)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtimePieOffsetRadius += m_Settings.pieSelectedOffset;
|
|
|
|
|
|
if (serieData.runtimePieInsideRadius > 0) serieData.runtimePieInsideRadius += m_Settings.pieSelectedOffset;
|
|
|
|
|
|
serieData.runtimePieOutsideRadius += m_Settings.pieSelectedOffset;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.runtiemPieOffsetCenter = new Vector3(center.x + serieData.runtimePieOffsetRadius * currSin,
|
|
|
|
|
|
center.y + serieData.runtimePieOffsetRadius * currCos);
|
2020-04-08 09:02:46 +08:00
|
|
|
|
var drawEndDegree = serieData.runtimePieCurrAngle;
|
|
|
|
|
|
var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0;
|
|
|
|
|
|
ChartDrawer.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius,
|
|
|
|
|
|
serieData.runtimePieOutsideRadius, color, toColor, Color.clear, startDegree, drawEndDegree,
|
|
|
|
|
|
borderWidth, borderColor, serie.pieSpace / 2, m_Settings.cicleSmoothness, needRoundCap, serie.clockwise);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2020-04-08 09:02:46 +08:00
|
|
|
|
else //if(n==0)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2020-04-08 09:02:46 +08:00
|
|
|
|
var drawEndDegree = serieData.runtimePieCurrAngle;
|
|
|
|
|
|
var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
ChartDrawer.DrawDoughnut(vh, center, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
|
2020-04-08 09:02:46 +08:00
|
|
|
|
color, toColor, Color.clear, startDegree, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2,
|
|
|
|
|
|
m_Settings.cicleSmoothness, needRoundCap, serie.clockwise);
|
2020-03-17 08:37:48 +08:00
|
|
|
|
DrawCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2019-11-02 08:24:37 +08:00
|
|
|
|
serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
isDrawPie = true;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
startDegree = serieData.runtimePieToAngle;
|
2019-09-05 09:21:37 +08:00
|
|
|
|
if (isFinish) serie.animation.SetDataFinish(n);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
else break;
|
2019-09-05 09:21:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!serie.animation.IsFinish())
|
|
|
|
|
|
{
|
2020-02-23 11:06:16 +08:00
|
|
|
|
serie.animation.CheckProgress(360);
|
|
|
|
|
|
serie.animation.CheckSymbol(serie.symbol.size);
|
2019-09-05 09:21:37 +08:00
|
|
|
|
RefreshChart();
|
2019-07-02 18:33:12 +08:00
|
|
|
|
}
|
2019-12-03 07:49:37 +08:00
|
|
|
|
if (dataChanging)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshChart();
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-10-05 18:23:06 +08:00
|
|
|
|
DrawLabelLine(vh);
|
2019-09-06 09:11:46 +08:00
|
|
|
|
DrawLabelBackground(vh);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
raycastTarget = isClickOffset && isDataHighlight;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-17 08:37:48 +08:00
|
|
|
|
private void DrawCenter(VertexHelper vh, Serie serie, ItemStyle itemStyle, float insideRadius)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (itemStyle.centerColor != Color.clear)
|
|
|
|
|
|
{
|
|
|
|
|
|
var radius = insideRadius - itemStyle.centerGap;
|
|
|
|
|
|
ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, m_Settings.cicleSmoothness);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
private void DrawLabelLine(VertexHelper vh)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var serie in m_Series.list)
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serie.type == SerieType.Pie)
|
2019-10-05 18:23:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
foreach (var serieData in serie.data)
|
|
|
|
|
|
{
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serieLabel.show && serieData.canShowLabel)
|
2019-10-05 18:23:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
int colorIndex = m_LegendRealShowName.IndexOf(serieData.name);
|
|
|
|
|
|
Color color = m_ThemeInfo.GetColor(colorIndex);
|
|
|
|
|
|
DrawLabelLine(vh, serie, serieData, color);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-06 09:11:46 +08:00
|
|
|
|
private void DrawLabelBackground(VertexHelper vh)
|
|
|
|
|
|
{
|
2019-10-01 13:52:02 +08:00
|
|
|
|
foreach (var serie in m_Series.list)
|
2019-09-06 09:11:46 +08:00
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serie.type == SerieType.Pie)
|
2019-09-06 09:11:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
foreach (var serieData in serie.data)
|
|
|
|
|
|
{
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serieLabel.show && serieData.canShowLabel)
|
2019-09-06 09:11:46 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
UpdateLabelPostion(serie, serieData);
|
2019-09-06 09:11:46 +08:00
|
|
|
|
DrawLabelBackground(vh, serie, serieData);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
private void DrawLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serieLabel.show
|
|
|
|
|
|
&& serieLabel.position == SerieLabel.Position.Outside
|
|
|
|
|
|
&& serieLabel.line)
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
var insideRadius = serieData.runtimePieInsideRadius;
|
|
|
|
|
|
var outSideRadius = serieData.runtimePieOutsideRadius;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var center = serie.runtimeCenterPos;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
var currAngle = serieData.runtimePieHalfAngle;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serieLabel.lineColor != Color.clear) color = serieLabel.lineColor;
|
|
|
|
|
|
else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine) color *= color;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad);
|
|
|
|
|
|
float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ?
|
|
|
|
|
|
serie.runtimeOutsideRadius : outSideRadius;
|
|
|
|
|
|
var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var radius3 = insideRadius + (outSideRadius - insideRadius) / 2;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (radius1 < serie.runtimeInsideRadius) radius1 = serie.runtimeInsideRadius;
|
2019-11-11 09:24:24 +08:00
|
|
|
|
radius1 -= 0.1f;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos);
|
|
|
|
|
|
var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos);
|
|
|
|
|
|
var pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
float tx, ty;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
Vector3 pos3, pos4, pos6;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var lineCircleDiff = horizontalLineCircleRadius - 0.3f;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
if (currAngle < 90)
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ty = serieLabel.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
tx = serieLabel.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
pos3 = new Vector3(pos2.x - tx, pos2.y + ty - serieLabel.lineWidth);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
pos6 = pos0 + Vector3.right * lineCircleDiff;
|
|
|
|
|
|
pos4 = pos6 + Vector3.right * r4;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (currAngle < 180)
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ty = serieLabel.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
tx = serieLabel.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
pos3 = new Vector3(pos2.x - tx, pos2.y - ty + serieLabel.lineWidth);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
pos6 = pos0 + Vector3.right * lineCircleDiff;
|
|
|
|
|
|
pos4 = pos6 + Vector3.right * r4;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (currAngle < 270)
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ty = serieLabel.lineWidth * Mathf.Sin((180 + currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
tx = serieLabel.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
pos3 = new Vector3(pos2.x + tx, pos2.y - ty + serieLabel.lineWidth);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
pos6 = pos0 + Vector3.left * lineCircleDiff;
|
|
|
|
|
|
pos4 = pos6 + Vector3.left * r4;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ty = serieLabel.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
tx = serieLabel.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
pos3 = new Vector3(pos2.x + tx, pos2.y + ty - serieLabel.lineWidth);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
r4 += serieLabel.lineLength1 - lineCircleDiff;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
pos6 = pos0 + Vector3.left * lineCircleDiff;
|
|
|
|
|
|
pos4 = pos6 + Vector3.left * r4;
|
|
|
|
|
|
}
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var pos5 = new Vector3(currAngle > 180 ? pos3.x - serieLabel.lineLength2 : pos3.x + serieLabel.lineLength2, pos3.y);
|
|
|
|
|
|
switch (serieLabel.lineType)
|
2019-10-05 18:23:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
case SerieLabel.LineType.BrokenLine:
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ChartDrawer.DrawLine(vh, pos1, pos2, serieLabel.lineWidth, color);
|
|
|
|
|
|
ChartDrawer.DrawLine(vh, pos3, pos5, serieLabel.lineWidth, color);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case SerieLabel.LineType.Curves:
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, m_Settings.lineSmoothness);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case SerieLabel.LineType.HorizontalLine:
|
2019-10-11 12:32:42 +08:00
|
|
|
|
ChartDrawer.DrawCricle(vh, pos0, horizontalLineCircleRadius, color);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
ChartDrawer.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
break;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnRefreshLabel()
|
|
|
|
|
|
{
|
|
|
|
|
|
int serieNameCount = -1;
|
|
|
|
|
|
for (int i = 0; i < m_Series.Count; i++)
|
|
|
|
|
|
{
|
2019-10-01 13:52:02 +08:00
|
|
|
|
var serie = m_Series.list[i];
|
2019-07-29 00:25:10 +08:00
|
|
|
|
serie.index = i;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
if (!serie.show) continue;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
var data = serie.data;
|
|
|
|
|
|
|
2019-07-29 08:01:39 +08:00
|
|
|
|
int showdataCount = 0;
|
2019-08-15 21:44:30 +08:00
|
|
|
|
if (serie.pieRoseType == RoseType.Area)
|
2019-07-29 08:01:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
foreach (var sd in serie.data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sd.show) showdataCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-07-29 00:25:10 +08:00
|
|
|
|
for (int n = 0; n < data.Count; n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var serieData = data[n];
|
2019-09-05 09:21:37 +08:00
|
|
|
|
if (!serieData.canShowLabel)
|
|
|
|
|
|
{
|
|
|
|
|
|
serieData.SetLabelActive(false);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2019-10-05 18:23:06 +08:00
|
|
|
|
if (!serieData.show) continue;
|
|
|
|
|
|
serieNameCount = m_LegendRealShowName.IndexOf(serieData.name);
|
|
|
|
|
|
Color color = m_ThemeInfo.GetColor(serieNameCount);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
DrawLabel(serie, n, serieData, color);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
private void DrawLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor)
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
2019-08-20 09:40:19 +08:00
|
|
|
|
if (serieData.labelText == null) return;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
var currAngle = serieData.runtimePieHalfAngle;
|
2019-10-14 07:45:56 +08:00
|
|
|
|
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
|
2019-11-12 07:38:02 +08:00
|
|
|
|
if (showLabel || serieData.iconStyle.show)
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
2019-09-25 09:44:53 +08:00
|
|
|
|
serieData.SetLabelActive(showLabel);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
float rotate = 0;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
bool isInsidePosition = serieLabel.position == SerieLabel.Position.Inside;
|
|
|
|
|
|
if (serieLabel.rotate > 0 && isInsidePosition)
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (currAngle > 180) rotate += 270 - currAngle;
|
|
|
|
|
|
else rotate += -(currAngle - 90);
|
|
|
|
|
|
}
|
|
|
|
|
|
Color color = serieColor;
|
|
|
|
|
|
if (isHighlight)
|
|
|
|
|
|
{
|
2019-10-14 07:45:56 +08:00
|
|
|
|
if (serie.emphasis.label.color != Color.clear) color = serie.emphasis.label.color;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
2019-11-30 21:24:04 +08:00
|
|
|
|
else if (serieLabel.color != Color.clear)
|
2019-07-29 00:25:10 +08:00
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
color = serieLabel.color;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
color = isInsidePosition ? Color.white : serieColor;
|
|
|
|
|
|
}
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var fontSize = isHighlight ? serie.emphasis.label.fontSize : serieLabel.fontSize;
|
|
|
|
|
|
var fontStyle = isHighlight ? serie.emphasis.label.fontStyle : serieLabel.fontStyle;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
|
2019-08-20 09:40:19 +08:00
|
|
|
|
serieData.labelText.color = color;
|
|
|
|
|
|
serieData.labelText.fontSize = fontSize;
|
|
|
|
|
|
serieData.labelText.fontStyle = fontStyle;
|
2019-07-29 00:25:10 +08:00
|
|
|
|
|
2019-09-06 09:11:46 +08:00
|
|
|
|
serieData.labelRect.transform.localEulerAngles = new Vector3(0, 0, rotate);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
UpdateLabelPostion(serie, serieData);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(serieLabel.formatter))
|
2019-09-23 09:23:51 +08:00
|
|
|
|
{
|
|
|
|
|
|
var value = serieData.data[1];
|
|
|
|
|
|
var total = serie.yTotal;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var content = serieLabel.GetFormatterContent(serie.name, serieData.name, value, total);
|
2019-09-23 18:47:45 +08:00
|
|
|
|
if (serieData.SetLabelText(content)) RefreshChart();
|
2019-09-23 09:23:51 +08:00
|
|
|
|
}
|
2019-11-30 21:24:04 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (serieData.SetLabelText(serieData.name)) RefreshChart();
|
|
|
|
|
|
}
|
2019-09-25 09:44:53 +08:00
|
|
|
|
serieData.SetGameObjectPosition(serieData.labelPosition);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (showLabel) serieData.SetLabelPosition(serieLabel.offset);
|
|
|
|
|
|
else serieData.SetLabelActive(false);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-08-16 00:13:01 +08:00
|
|
|
|
serieData.SetLabelActive(false);
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
2019-09-25 09:44:53 +08:00
|
|
|
|
serieData.UpdateIcon();
|
2019-07-29 00:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
protected void UpdateLabelPostion(Serie serie, SerieData serieData)
|
|
|
|
|
|
{
|
2019-11-09 16:34:16 +08:00
|
|
|
|
if (serieData.labelText == null) return;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
var currAngle = serieData.runtimePieHalfAngle;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var currRad = currAngle * Mathf.Deg2Rad;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
var offsetRadius = serieData.runtimePieOffsetRadius;
|
|
|
|
|
|
var insideRadius = serieData.runtimePieInsideRadius;
|
|
|
|
|
|
var outsideRadius = serieData.runtimePieOutsideRadius;
|
2020-03-17 08:37:48 +08:00
|
|
|
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
switch (serieLabel.position)
|
2019-10-05 18:23:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
case SerieLabel.Position.Center:
|
2019-11-30 21:24:04 +08:00
|
|
|
|
serieData.labelPosition = serie.runtimeCenterPos;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case SerieLabel.Position.Inside:
|
|
|
|
|
|
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
|
|
|
|
|
|
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
|
2019-10-05 18:23:06 +08:00
|
|
|
|
serieData.labelPosition = labelCenter;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SerieLabel.Position.Outside:
|
2019-11-30 21:24:04 +08:00
|
|
|
|
if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine)
|
2019-10-05 18:23:06 +08:00
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var radius1 = serie.runtimeOutsideRadius;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var radius3 = insideRadius + (outsideRadius - insideRadius) / 2;
|
|
|
|
|
|
var currSin = Mathf.Sin(currRad);
|
|
|
|
|
|
var currCos = Mathf.Cos(currRad);
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var pos0 = new Vector3(serie.runtimeCenterPos.x + radius3 * currSin, serie.runtimeCenterPos.y + radius3 * currCos);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
if (currAngle > 180)
|
|
|
|
|
|
{
|
|
|
|
|
|
currSin = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
currCos = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
|
|
|
|
|
}
|
|
|
|
|
|
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
r4 += serieData.labelText.preferredWidth / 2;
|
|
|
|
|
|
serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
|
|
|
|
|
labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
|
|
|
|
|
|
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
|
2019-10-05 18:23:06 +08:00
|
|
|
|
float labelWidth = serieData.labelText.preferredWidth;
|
|
|
|
|
|
if (currAngle > 180)
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
serieData.labelPosition = new Vector2(labelCenter.x - serieLabel.lineLength2 - 5 - labelWidth / 2, labelCenter.y);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-30 21:24:04 +08:00
|
|
|
|
serieData.labelPosition = new Vector2(labelCenter.x + serieLabel.lineLength2 + 5 + labelWidth / 2, labelCenter.y);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-04 15:24:31 +08:00
|
|
|
|
protected override void OnLegendButtonClick(int index, string legendName, bool show)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2020-02-26 22:52:57 +08:00
|
|
|
|
CheckDataShow(legendName, show);
|
|
|
|
|
|
UpdateLegendColor(legendName, show);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
RefreshChart();
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
|
2019-07-28 00:44:53 +08:00
|
|
|
|
protected override void OnLegendButtonEnter(int index, string legendName)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_IsEnterLegendButtom = true;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
CheckDataHighlighted(legendName, true);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
RefreshChart();
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-28 00:44:53 +08:00
|
|
|
|
protected override void OnLegendButtonExit(int index, string legendName)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
m_IsEnterLegendButtom = false;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
CheckDataHighlighted(legendName, false);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
RefreshChart();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
protected override void CheckTootipArea(Vector2 local)
|
|
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
if (m_IsEnterLegendButtom) return;
|
2019-11-02 08:24:37 +08:00
|
|
|
|
m_Tooltip.runtimeDataIndex.Clear();
|
2019-07-28 00:44:53 +08:00
|
|
|
|
bool selected = false;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
foreach (var serie in m_Series.list)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
int index = GetPosPieIndex(serie, local);
|
2019-11-02 08:24:37 +08:00
|
|
|
|
m_Tooltip.runtimeDataIndex.Add(index);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
if (serie.type != SerieType.Pie) continue;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
bool refresh = false;
|
|
|
|
|
|
for (int j = 0; j < serie.data.Count; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var serieData = serie.data[j];
|
|
|
|
|
|
if (serieData.highlighted != (j == index)) refresh = true;
|
|
|
|
|
|
serieData.highlighted = j == index;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (index >= 0) selected = true;
|
|
|
|
|
|
if (refresh) RefreshChart();
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-07-28 00:44:53 +08:00
|
|
|
|
if (selected)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-05-29 09:53:30 +08:00
|
|
|
|
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
2020-02-13 09:23:30 +08:00
|
|
|
|
UpdateTooltip();
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2019-09-23 09:23:51 +08:00
|
|
|
|
else if (m_Tooltip.IsActive())
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_Tooltip.SetActive(false);
|
2019-09-20 08:55:52 +08:00
|
|
|
|
RefreshChart();
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-05 18:23:06 +08:00
|
|
|
|
private int GetPosPieIndex(Serie serie, Vector2 local)
|
2019-07-02 18:33:12 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
if (serie.type != SerieType.Pie) return -1;
|
2019-11-30 21:24:04 +08:00
|
|
|
|
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
|
|
|
|
|
|
if (dist < serie.runtimeInsideRadius || dist > serie.runtimeOutsideRadius) return -1;
|
|
|
|
|
|
Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y);
|
2019-07-02 18:33:12 +08:00
|
|
|
|
float angle = VectorAngle(Vector2.up, dir);
|
2019-10-05 18:23:06 +08:00
|
|
|
|
for (int i = 0; i < serie.data.Count; i++)
|
2019-07-02 18:33:12 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var serieData = serie.data[i];
|
2019-11-02 08:24:37 +08:00
|
|
|
|
if (angle >= serieData.runtimePieStartAngle && angle <= serieData.runtimePieToAngle)
|
2019-07-02 18:33:12 +08:00
|
|
|
|
{
|
2019-07-28 00:44:53 +08:00
|
|
|
|
return i;
|
2019-07-02 18:33:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-07-18 09:42:36 +08:00
|
|
|
|
return -1;
|
2019-07-02 18:33:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
float VectorAngle(Vector2 from, Vector2 to)
|
|
|
|
|
|
{
|
|
|
|
|
|
float angle;
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 cross = Vector3.Cross(from, to);
|
|
|
|
|
|
angle = Vector2.Angle(from, to);
|
|
|
|
|
|
angle = cross.z > 0 ? -angle : angle;
|
|
|
|
|
|
angle = (angle + 360) % 360;
|
|
|
|
|
|
return angle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-13 09:23:30 +08:00
|
|
|
|
protected override void UpdateTooltip()
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2020-02-13 09:23:30 +08:00
|
|
|
|
base.UpdateTooltip();
|
2019-07-28 00:44:53 +08:00
|
|
|
|
bool showTooltip = false;
|
2019-10-05 18:23:06 +08:00
|
|
|
|
foreach (var serie in m_Series.list)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
int index = m_Tooltip.runtimeDataIndex[serie.index];
|
2019-07-28 00:44:53 +08:00
|
|
|
|
if (index < 0) continue;
|
|
|
|
|
|
showTooltip = true;
|
2020-03-21 11:26:50 +08:00
|
|
|
|
var content = TooltipHelper.GetFormatterContent(m_Tooltip, index, m_Series, m_ThemeInfo);
|
|
|
|
|
|
m_Tooltip.UpdateContentText(content);
|
2019-07-28 00:44:53 +08:00
|
|
|
|
var pos = m_Tooltip.GetContentPos();
|
2019-11-02 08:24:37 +08:00
|
|
|
|
if (pos.x + m_Tooltip.runtimeWidth > chartWidth)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
pos.x = chartWidth - m_Tooltip.runtimeWidth;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
2019-11-02 08:24:37 +08:00
|
|
|
|
if (pos.y - m_Tooltip.runtimeHeight < 0)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
pos.y = m_Tooltip.runtimeHeight;
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
m_Tooltip.UpdateContentPos(pos);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-07-28 00:44:53 +08:00
|
|
|
|
m_Tooltip.SetActive(showTooltip);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-07-02 18:33:12 +08:00
|
|
|
|
|
|
|
|
|
|
public override void OnPointerDown(PointerEventData eventData)
|
|
|
|
|
|
{
|
2019-07-19 21:55:22 +08:00
|
|
|
|
Vector2 local;
|
|
|
|
|
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
|
|
|
|
|
eventData.position, canvas.worldCamera, out local))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-10-05 18:23:06 +08:00
|
|
|
|
for (int i = 0; i < m_Series.Count; i++)
|
2019-07-02 18:33:12 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var serie = m_Series.GetSerie(i);
|
|
|
|
|
|
if (serie.type == SerieType.Pie)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
var index = GetPosPieIndex(serie, local);
|
|
|
|
|
|
if (index >= 0)
|
2019-07-28 00:44:53 +08:00
|
|
|
|
{
|
2019-10-05 18:23:06 +08:00
|
|
|
|
for (int j = 0; j < serie.data.Count; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (j == index) serie.data[j].selected = !serie.data[j].selected;
|
|
|
|
|
|
else serie.data[j].selected = false;
|
|
|
|
|
|
}
|
2019-07-28 00:44:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-07-02 18:33:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
RefreshChart();
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|