From 7e4e0466721f02fd4cbe3c815869be9987482273 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 17 Jan 2021 10:16:30 +0800 Subject: [PATCH] XCharts 2.0 --- README.md | 14 +++++------ Runtime/Internal/BaseChart.cs | 20 ++++----------- Runtime/Internal/BaseGraph.cs | 8 ++---- Runtime/Internal/Helper/VisualMapHelper.cs | 3 --- Runtime/Internal/Painter.cs | 4 +-- Runtime/Internal/Utility/ChartHelper.cs | 9 +++++++ Runtime/XChartsMgr.cs | 29 +++++++--------------- Runtime/XChartsPackageResourceImporter.cs | 2 -- 8 files changed, 34 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 826b2980..3852f57e 100644 --- a/README.md +++ b/README.md @@ -41,16 +41,16 @@ A powerful, easy-to-use, configurable charting and data visualization library fo ## Screenshot - - - - - - +![linechart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-line.png) +![barchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-bar.png) +![piechart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-pie.png) +![radarchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-radar.png) +![scatterchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-scatter.png) +![heatmapchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-heatmap.png) ## Cheat Sheet - +![cheatsheet](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-cheatsheet.gif) `XCharts` consist of components and data. Different components and data can be combined into different types of charts. The component is divided into main component and sub component. The main component contains the sub components. diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 5b6f0c53..541d16e8 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -308,24 +308,19 @@ namespace XCharts base.InitPainter(); m_PainterList.Clear(); if (settings == null) return; + var sizeDelta = new Vector2(m_GraphWidth, m_GraphHeight); for (int i = 0; i < settings.maxPainter; i++) { - var painterObj = ChartHelper.AddObject("painter_" + i, transform, m_GraphMinAnchor, m_GraphMaxAnchor, - m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight)); - painterObj.hideFlags = chartHideFlags; - painterObj.transform.SetSiblingIndex(2 + i); - var painter = ChartHelper.GetOrAddComponent(painterObj); + var painter = ChartHelper.AddPainterObject("painter_" + i, transform, m_GraphMinAnchor, + m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + i); painter.index = m_PainterList.Count; painter.type = Painter.Type.Serie; painter.onPopulateMesh = OnDrawPainterSerie; painter.SetActive(false, m_DebugMode); m_PainterList.Add(painter); } - var painterTopObj = ChartHelper.AddObject("painter_t", transform, m_GraphMinAnchor, m_GraphMaxAnchor, - m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight)); - painterTopObj.hideFlags = chartHideFlags; - painterTopObj.transform.SetSiblingIndex(2 + settings.maxPainter); - m_PainterTop = ChartHelper.GetOrAddComponent(painterTopObj); + m_PainterTop = ChartHelper.AddPainterObject("painter_t", transform, m_GraphMinAnchor, + m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter); m_PainterTop.type = Painter.Type.Top; m_PainterTop.onPopulateMesh = OnDrawPainterTop; m_PainterTop.SetActive(true, m_DebugMode); @@ -684,8 +679,6 @@ namespace XCharts m_Painter.Refresh(); foreach (var painter in m_PainterList) painter.Refresh(); m_PainterTop.Refresh(); - //SetAllDirty(); - //SetVerticesDirty(); m_RefreshChart = false; } } @@ -826,7 +819,6 @@ namespace XCharts protected override void OnDrawPainterBase(VertexHelper vh, Painter painter) { - //Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name); vh.Clear(); DrawBackground(vh); DrawPainterBase(vh); @@ -835,7 +827,6 @@ namespace XCharts protected virtual void OnDrawPainterSerie(VertexHelper vh, Painter painter) { - //Debug.LogError("OnDrawPainterSerie:" + Time.frameCount + "," + painter.name); vh.Clear(); var maxPainter = settings.maxPainter; var maxSeries = m_Series.Count; @@ -851,7 +842,6 @@ namespace XCharts protected virtual void OnDrawPainterTop(VertexHelper vh, Painter painter) { - //Debug.LogError("OnDrawPainterTop:" + Time.frameCount + "," + painter.name); vh.Clear(); if (m_OnCustomDrawCallback != null) { diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index 9e0dca66..bb36e45d 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -219,11 +219,8 @@ namespace XCharts protected virtual void InitPainter() { - var painterObj = ChartHelper.AddObject("painter_b", transform, m_GraphMinAnchor, m_GraphMaxAnchor, - m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight)); - painterObj.transform.SetSiblingIndex(1); - painterObj.hideFlags = chartHideFlags; - m_Painter = ChartHelper.GetOrAddComponent(painterObj); + m_Painter = ChartHelper.AddPainterObject("painter_b", transform, m_GraphMinAnchor, + m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1); m_Painter.type = Painter.Type.Base; m_Painter.onPopulateMesh = OnDrawPainterBase; } @@ -339,7 +336,6 @@ namespace XCharts protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter) { - Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name); DrawBackground(vh); DrawPainterBase(vh); } diff --git a/Runtime/Internal/Helper/VisualMapHelper.cs b/Runtime/Internal/Helper/VisualMapHelper.cs index c94b8803..dde186ce 100644 --- a/Runtime/Internal/Helper/VisualMapHelper.cs +++ b/Runtime/Internal/Helper/VisualMapHelper.cs @@ -6,7 +6,6 @@ /************************************************/ using System; -using System.Collections.Generic; using UnityEngine; namespace XCharts @@ -38,12 +37,10 @@ namespace XCharts { if (visualMap.enable && (visualMap.min != min || visualMap.max != max)) { - //Debug.LogError("minmax:"+min+","+max); if (max >= min) { visualMap.min = min; visualMap.max = max; - //Debug.LogError("minmax2222:"+visualMap.min+","+visualMap.max); } else { diff --git a/Runtime/Internal/Painter.cs b/Runtime/Internal/Painter.cs index 432e424d..c97c6852 100644 --- a/Runtime/Internal/Painter.cs +++ b/Runtime/Internal/Painter.cs @@ -11,7 +11,8 @@ using System; namespace XCharts { - public partial class Painter : MaskableGraphic + [RequireComponent(typeof(CanvasRenderer))] + public class Painter : MaskableGraphic { public enum Type { @@ -32,7 +33,6 @@ namespace XCharts if (gameObject == null) return; if (!gameObject.activeSelf) return; m_Refresh = true; - //Debug.LogError("refresh painter:"+name); } public void Init() diff --git a/Runtime/Internal/Utility/ChartHelper.cs b/Runtime/Internal/Utility/ChartHelper.cs index 7eea3605..d7514332 100644 --- a/Runtime/Internal/Utility/ChartHelper.cs +++ b/Runtime/Internal/Utility/ChartHelper.cs @@ -365,6 +365,15 @@ namespace XCharts return tooltipObj; } + internal static Painter AddPainterObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, + Vector2 pivot, Vector2 sizeDelta, HideFlags hideFlags, int siblingIndex) + { + var painterObj = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + painterObj.hideFlags = hideFlags; + painterObj.transform.SetSiblingIndex(siblingIndex); + return ChartHelper.GetOrAddComponent(painterObj); + } + public static GameObject AddIcon(string name, Transform parent, float width, float height) { var anchorMax = new Vector2(0.5f, 0.5f); diff --git a/Runtime/XChartsMgr.cs b/Runtime/XChartsMgr.cs index e5fa18e7..34305b3e 100644 --- a/Runtime/XChartsMgr.cs +++ b/Runtime/XChartsMgr.cs @@ -163,7 +163,7 @@ namespace XCharts private void CheckVersionWebRequest(UnityWebRequest web) { - if (IsNetworkError(web)) + if (IsWebRequestError(web)) { isNetworkError = true; networkError = web.error; @@ -240,29 +240,18 @@ namespace XCharts changeLog = sb.ToString(); } -#if UNITY_5 || UNITY_2017_1 - public bool IsNetworkError(UnityWebRequest request) + public bool IsWebRequestError(UnityWebRequest request) { - return request.isError && !IsHttpError(request); - } -#else - public bool IsNetworkError(UnityWebRequest request) - { - return request.isNetworkError; - } -#endif - #if UNITY_5 - public bool IsHttpError(UnityWebRequest request) - { - return request.responseCode >= 400; - } + return request.isError && ! request.responseCode >= 400; +#elif UNITY_2017_1 + return request.isError && ! request.isHttpError; +#elif UNITY_2020_2 + return (int)request.result > 1; #else - public bool IsHttpError(UnityWebRequest request) - { - return request.isHttpError; - } + return request.isNetworkError; #endif + } void OnEnable() { diff --git a/Runtime/XChartsPackageResourceImporter.cs b/Runtime/XChartsPackageResourceImporter.cs index be94a6ae..92bd6740 100644 --- a/Runtime/XChartsPackageResourceImporter.cs +++ b/Runtime/XChartsPackageResourceImporter.cs @@ -39,7 +39,6 @@ namespace XCharts AssetDatabase.importPackageCompleted += ImportCallback; string packageFullPath = GetPackageFullPath(); - Debug.LogError("packageFullPath:" + packageFullPath); AssetDatabase.ImportPackage(packageFullPath + "/Package Resources/XCharts Essential Resources.unitypackage", false); } GUILayout.Space(5f); @@ -110,7 +109,6 @@ namespace XCharts } packagePath = Path.GetFullPath("Assets/.."); - Debug.LogError("packagePath:" + packagePath + ":" + Directory.Exists(packagePath)); if (Directory.Exists(packagePath)) { // Search default location for development package