From 4c89bda4b974bfc59b09c570f7d964ea4e4adf7e Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 23 Sep 2022 08:38:56 +0800 Subject: [PATCH] [improve][Parallel] improve ParallelChart --- CHANGELOG.md | 1 + Editor/Series/ParallelEditor.cs | 1 + .../Axis/ParallelAxis/ParallelAxis.cs | 1 + .../Axis/ParallelAxis/ParallelAxisHander.cs | 2 +- Runtime/Serie/Parallel/Parallel.cs | 3 +- Runtime/Serie/Parallel/ParallelHandler.cs | 28 +++++++++---------- Runtime/Serie/SerieHandler.cs | 2 +- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2922f202..ecf624b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ ## master +* (2022.09.23) 优化`ParallelChart` * (2022.09.22) 增加`SaveAsImage()`接口保存图表到图片 * (2022.09.21) 修复`InsertSerie()`接口不刷新图表的问题 * (2022.09.21) 优化`PolarChart`对`Line`热力图的支持 diff --git a/Editor/Series/ParallelEditor.cs b/Editor/Series/ParallelEditor.cs index c0d7b2c5..c29aff68 100644 --- a/Editor/Series/ParallelEditor.cs +++ b/Editor/Series/ParallelEditor.cs @@ -7,6 +7,7 @@ namespace XCharts.Editor { public override void OnCustomInspectorGUI() { + PropertyField("m_ColorBy"); PropertyField("m_ParallelIndex"); PropertyField("m_LineType"); PropertyField("m_LineStyle"); diff --git a/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs b/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs index 18f86050..7fac3ab5 100644 --- a/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs +++ b/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs @@ -23,6 +23,7 @@ namespace XCharts.Runtime splitLine.show = false; splitLine.lineStyle.type = LineStyle.Type.None; axisLabel.textLimit.enable = true; + axisName.labelStyle.offset = new Vector3(0, 25, 0); } } diff --git a/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs b/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs index 0ae6185c..f1e8d57a 100644 --- a/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs +++ b/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs @@ -160,7 +160,7 @@ namespace XCharts.Runtime internal override float GetAxisLineXOrY() { - return component.context.y; + return component.context.x; } } } \ No newline at end of file diff --git a/Runtime/Serie/Parallel/Parallel.cs b/Runtime/Serie/Parallel/Parallel.cs index 721f9f91..09b65279 100644 --- a/Runtime/Serie/Parallel/Parallel.cs +++ b/Runtime/Serie/Parallel/Parallel.cs @@ -6,7 +6,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(ParallelHandler), true)] [RequireChartComponent(typeof(ParallelCoord))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieExtraComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Parallel : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Parallel/ParallelHandler.cs b/Runtime/Serie/Parallel/ParallelHandler.cs index c126f576..26a5be3b 100644 --- a/Runtime/Serie/Parallel/ParallelHandler.cs +++ b/Runtime/Serie/Parallel/ParallelHandler.cs @@ -8,8 +8,6 @@ namespace XCharts.Runtime [UnityEngine.Scripting.Preserve] internal sealed class ParallelHandler : SerieHandler { - private List m_Points = new List(); - public override void Update() { base.Update(); @@ -38,7 +36,7 @@ namespace XCharts.Runtime var animationIndex = serie.animation.GetCurrIndex(); var isHorizonal = parallel.orient == Orient.Horizonal; - var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex); + var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); float currDetailProgress = !isHorizonal ? @@ -58,9 +56,11 @@ namespace XCharts.Runtime 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; + var colorIndex = serie.colorByData?serieData.index : serie.context.colorIndex; + var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex); + serieData.context.dataPoints.Clear(); for (int i = 0; i < count; i++) { if (animationIndex >= 0 && i > animationIndex) continue; @@ -69,11 +69,11 @@ namespace XCharts.Runtime { if (isSmooth) { - m_Points.Add(pos); + serieData.context.dataPoints.Add(pos); } else if (pos.x <= currProgress) { - m_Points.Add(pos); + serieData.context.dataPoints.Add(pos); } else { @@ -82,9 +82,9 @@ namespace XCharts.Runtime var intersectionPos = Vector3.zero; if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos)) - m_Points.Add(intersectionPos); + serieData.context.dataPoints.Add(intersectionPos); else - m_Points.Add(pos); + serieData.context.dataPoints.Add(pos); break; } } @@ -92,11 +92,11 @@ namespace XCharts.Runtime { if (isSmooth) { - m_Points.Add(pos); + serieData.context.dataPoints.Add(pos); } else if (pos.y <= currProgress) { - m_Points.Add(pos); + serieData.context.dataPoints.Add(pos); } else { @@ -105,21 +105,21 @@ namespace XCharts.Runtime var intersectionPos = Vector3.zero; if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos)) - m_Points.Add(intersectionPos); + serieData.context.dataPoints.Add(intersectionPos); else - m_Points.Add(pos); + serieData.context.dataPoints.Add(pos); break; } } lp = pos; } if (isSmooth) - UGL.DrawCurves(vh, m_Points, lineWidth, lineColor, + UGL.DrawCurves(vh, serieData.context.dataPoints, lineWidth, lineColor, chart.settings.lineSmoothStyle, chart.settings.lineSmoothness, UGL.Direction.XAxis, currProgress, isHorizonal); else - UGL.DrawLine(vh, m_Points, lineWidth, lineColor, isSmooth); + UGL.DrawLine(vh, serieData.context.dataPoints, lineWidth, lineColor, isSmooth); } if (!serie.animation.IsFinish()) { diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 62d0e05e..0b8a53fb 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -448,7 +448,7 @@ namespace XCharts.Runtime var endLabelStyle = serie.endLabel; if (endLabelStyle == null) return; - var dataCount = serie.context.drawPoints.Count; + var dataCount = serie.context.dataPoints.Count; var active = endLabelStyle.show && dataCount > 0; m_EndLabel.SetActive(active); if (active)