mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
3.0 - unitypackage
This commit is contained in:
33
Runtime/Serie/Parallel/Parallel.cs
Normal file
33
Runtime/Serie/Parallel/Parallel.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
[SerieHandler(typeof(ParallelHandler), true)]
|
||||
[RequireChartComponent(typeof(ParallelCoord))]
|
||||
public class Parallel : Serie, INeedSerieContainer
|
||||
{
|
||||
public int containerIndex { get; internal set; }
|
||||
public int containterInstanceId { get; internal set; }
|
||||
public static void AddDefaultSerie(BaseChart chart, string serieName)
|
||||
{
|
||||
var serie = chart.AddSerie<Parallel>(serieName);
|
||||
serie.lineStyle.width = 0.8f;
|
||||
serie.lineStyle.opacity = 0.6f;
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var data = new List<double>(){
|
||||
Random.Range(0f,50f),
|
||||
Random.Range(0f,100f),
|
||||
Random.Range(0f,1000f),
|
||||
Random.Range(0,5),
|
||||
};
|
||||
serie.AddData(data, "data" + i);
|
||||
}
|
||||
chart.RefreshChart();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Serie/Parallel/Parallel.cs.meta
Normal file
11
Runtime/Serie/Parallel/Parallel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 283df79138f274a6ba975ff8f30c6d30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
153
Runtime/Serie/Parallel/ParallelHandler.cs
Normal file
153
Runtime/Serie/Parallel/ParallelHandler.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class ParallelHandler : SerieHandler<Parallel>
|
||||
{
|
||||
private List<Vector3> m_Points = new List<Vector3>();
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
UpdateSerieContext();
|
||||
}
|
||||
|
||||
public override void DrawSerie(VertexHelper vh)
|
||||
{
|
||||
var colorIndex = chart.GetLegendRealShowNameIndex(serie.legendName);
|
||||
DrawParallelSerie(vh, colorIndex, serie);
|
||||
}
|
||||
|
||||
private void UpdateSerieContext()
|
||||
{
|
||||
}
|
||||
|
||||
private void DrawParallelSerie(VertexHelper vh, int colorIndex, Parallel serie)
|
||||
{
|
||||
if (!serie.show) return;
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
|
||||
var parallel = chart.GetChartComponent<ParallelCoord>(serie.parallelIndex);
|
||||
if (parallel == null)
|
||||
return;
|
||||
|
||||
var axisCount = parallel.context.parallelAxes.Count;
|
||||
if (axisCount <= 0)
|
||||
return;
|
||||
|
||||
var animationIndex = serie.animation.GetCurrIndex();
|
||||
var isHorizonal = parallel.orient == Orient.Horizonal;
|
||||
var lineColor = SerieHelper.GetLineColor(serie, chart.theme, colorIndex, false);
|
||||
var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
|
||||
|
||||
float currDetailProgress = !isHorizonal
|
||||
? parallel.context.x
|
||||
: parallel.context.y;
|
||||
|
||||
float totalDetailProgress = !isHorizonal
|
||||
? parallel.context.x + parallel.context.width
|
||||
: parallel.context.y + parallel.context.height;
|
||||
|
||||
serie.animation.InitProgress(currDetailProgress, totalDetailProgress);
|
||||
|
||||
serie.context.dataPoints.Clear();
|
||||
serie.containerIndex = parallel.index;
|
||||
serie.containterInstanceId = parallel.instanceId;
|
||||
|
||||
var currProgress = serie.animation.GetCurrDetail();
|
||||
var isSmooth = serie.lineType == LineType.Smooth;
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
m_Points.Clear();
|
||||
var count = Mathf.Min(axisCount, serieData.data.Count);
|
||||
var lp = Vector3.zero;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (animationIndex >= 0 && i > animationIndex) continue;
|
||||
var pos = GetPos(parallel, i, serieData.data[i], isHorizonal);
|
||||
if (!isHorizonal)
|
||||
{
|
||||
if (isSmooth)
|
||||
{
|
||||
m_Points.Add(pos);
|
||||
}
|
||||
else if (pos.x <= currProgress)
|
||||
{
|
||||
m_Points.Add(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
var currProgressStart = new Vector3(currProgress, parallel.context.y - 50);
|
||||
var currProgressEnd = new Vector3(currProgress, parallel.context.y + parallel.context.height + 50);
|
||||
var intersectionPos = Vector3.zero;
|
||||
|
||||
if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos))
|
||||
m_Points.Add(intersectionPos);
|
||||
else
|
||||
m_Points.Add(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isSmooth)
|
||||
{
|
||||
m_Points.Add(pos);
|
||||
}
|
||||
else if (pos.y <= currProgress)
|
||||
{
|
||||
m_Points.Add(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
var currProgressStart = new Vector3(parallel.context.x - 50, currProgress);
|
||||
var currProgressEnd = new Vector3(parallel.context.x + parallel.context.width + 50, currProgress);
|
||||
var intersectionPos = Vector3.zero;
|
||||
|
||||
if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos))
|
||||
m_Points.Add(intersectionPos);
|
||||
else
|
||||
m_Points.Add(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
lp = pos;
|
||||
}
|
||||
if (isSmooth)
|
||||
UGL.DrawCurves(vh, m_Points, lineWidth, lineColor, chart.settings.lineSmoothness, currProgress, isHorizonal);
|
||||
else
|
||||
UGL.DrawLine(vh, m_Points, lineWidth, lineColor, isSmooth);
|
||||
}
|
||||
if (!serie.animation.IsFinish())
|
||||
{
|
||||
serie.animation.CheckProgress(totalDetailProgress - currDetailProgress);
|
||||
chart.RefreshPainter(serie);
|
||||
}
|
||||
}
|
||||
|
||||
private static ParallelAxis GetAxis(ParallelCoord parallel, int index)
|
||||
{
|
||||
if (index >= 0 && index < parallel.context.parallelAxes.Count)
|
||||
return parallel.context.parallelAxes[index];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Vector3 GetPos(ParallelCoord parallel, int axisIndex, double dataValue, bool isHorizonal)
|
||||
{
|
||||
var axis = GetAxis(parallel, axisIndex);
|
||||
if (axis == null)
|
||||
return Vector3.zero;
|
||||
|
||||
var sValueDist = axis.GetDistance(dataValue, axis.context.width);
|
||||
return new Vector3(
|
||||
isHorizonal ? axis.context.x + sValueDist : axis.context.x,
|
||||
isHorizonal ? axis.context.y : axis.context.y + sValueDist);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Serie/Parallel/ParallelHandler.cs.meta
Normal file
11
Runtime/Serie/Parallel/ParallelHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 482b461d91f8c4013bf291153d5810e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user