diff --git a/Assets/XCharts/README.md b/Assets/XCharts/README.md index 826b2980..3852f57e 100644 --- a/Assets/XCharts/README.md +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/Internal/BaseChart.cs b/Assets/XCharts/Runtime/Internal/BaseChart.cs index 5b6f0c53..541d16e8 100644 --- a/Assets/XCharts/Runtime/Internal/BaseChart.cs +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/Internal/BaseGraph.cs b/Assets/XCharts/Runtime/Internal/BaseGraph.cs index 9e0dca66..bb36e45d 100644 --- a/Assets/XCharts/Runtime/Internal/BaseGraph.cs +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/Internal/Helper/VisualMapHelper.cs b/Assets/XCharts/Runtime/Internal/Helper/VisualMapHelper.cs index c94b8803..dde186ce 100644 --- a/Assets/XCharts/Runtime/Internal/Helper/VisualMapHelper.cs +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/Internal/Painter.cs b/Assets/XCharts/Runtime/Internal/Painter.cs index 432e424d..c97c6852 100644 --- a/Assets/XCharts/Runtime/Internal/Painter.cs +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/Internal/Utility/ChartHelper.cs b/Assets/XCharts/Runtime/Internal/Utility/ChartHelper.cs index 7eea3605..d7514332 100644 --- a/Assets/XCharts/Runtime/Internal/Utility/ChartHelper.cs +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/XChartsMgr.cs b/Assets/XCharts/Runtime/XChartsMgr.cs index e5fa18e7..34305b3e 100644 --- a/Assets/XCharts/Runtime/XChartsMgr.cs +++ b/Assets/XCharts/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/Assets/XCharts/Runtime/XChartsPackageResourceImporter.cs b/Assets/XCharts/Runtime/XChartsPackageResourceImporter.cs index be94a6ae..92bd6740 100644 --- a/Assets/XCharts/Runtime/XChartsPackageResourceImporter.cs +++ b/Assets/XCharts/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 diff --git a/Assets/XChartsDemo/Runtime/UIUtil.cs b/Assets/XChartsDemo/Runtime/UIUtil.cs index fd48b768..75d62b16 100644 --- a/Assets/XChartsDemo/Runtime/UIUtil.cs +++ b/Assets/XChartsDemo/Runtime/UIUtil.cs @@ -5,9 +5,7 @@ /* */ /************************************************/ -using System.Collections.Generic; using UnityEngine; -using UnityEngine.EventSystems; using UnityEngine.UI; namespace XChartsDemo diff --git a/README.md b/README.md index 4e5fd9a0..b85db0b0 100644 --- a/README.md +++ b/README.md @@ -45,16 +45,16 @@ A powerful, easy-to-use, configurable charting and data visualization library fo ## 截图 -![xcharts-line](Doc/screenshot/xcharts-line.png) -![xcharts-bar](Doc/screenshot/xcharts-bar.png) -![xcharts-pie](Doc/screenshot/xcharts-pie.png) -![xcharts-radar](Doc/screenshot/xcharts-radar.png) -![xcharts-scatter](Doc/screenshot/xcharts-scatter.png) -![xcharts-heatmap](Doc/screenshot/xcharts-heatmap.png) +![linechart](Doc/screenshot/xcharts-line.png) +![barchart](Doc/screenshot/xcharts-bar.png) +![piechart](Doc/screenshot/xcharts-pie.png) +![radarchart](Doc/screenshot/xcharts-radar.png) +![scatterchart](Doc/screenshot/xcharts-scatter.png) +![heatmapchart](Doc/screenshot/xcharts-heatmap.png) ## 术语 -![xcharts-cheatsheet](Doc/screenshot/xcharts-cheatsheet.gif) +![cheatsheet](Doc/screenshot/xcharts-cheatsheet.gif) XCharts的图表由组件和数据组成。不同的组件和数据可以组合成不同类型的图表。组件分为主组件和子组件,主组件包含子组件。 @@ -168,6 +168,6 @@ VIP群:XCharts技术支持VIP群(`867291970`) 企业赞助请备注公司名称。 -![xcharts-alipay](Doc/alipay.png) +![alipay](Doc/alipay.png) 如需商业技术支持,捐助280¥可加VIP群(`867291970`,验证信息请输入捐助的支付宝账号)。