Skip to content

Commit

Permalink
XCharts 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Jan 17, 2021
1 parent ee4aae2 commit f5c76ce
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 64 deletions.
14 changes: 7 additions & 7 deletions Assets/XCharts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ A powerful, easy-to-use, configurable charting and data visualization library fo

## Screenshot

<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-line.png" width="550" height="auto"/>
<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-bar.png" width="550" height="auto"/>
<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-pie.png" width="550" height="auto"/>
<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-radar.png" width="550" height="auto"/>
<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-scatter.png" width="550" height="auto"/>
<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-heatmap.png" width="550" height="auto"/>
![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

<img src="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-cheatsheet.gif" />
![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.

Expand Down
20 changes: 5 additions & 15 deletions Assets/XCharts/Runtime/Internal/BaseChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,19 @@ protected override void InitPainter()
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<Painter>(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<Painter>(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);
Expand Down Expand Up @@ -684,8 +679,6 @@ protected override void CheckRefreshChart()
m_Painter.Refresh();
foreach (var painter in m_PainterList) painter.Refresh();
m_PainterTop.Refresh();
//SetAllDirty();
//SetVerticesDirty();
m_RefreshChart = false;
}
}
Expand Down Expand Up @@ -826,7 +819,6 @@ protected virtual void UpdateTooltip()

protected override void OnDrawPainterBase(VertexHelper vh, Painter painter)
{
//Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name);
vh.Clear();
DrawBackground(vh);
DrawPainterBase(vh);
Expand All @@ -835,7 +827,6 @@ protected override void OnDrawPainterBase(VertexHelper vh, Painter painter)

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;
Expand All @@ -851,7 +842,6 @@ protected virtual void OnDrawPainterSerie(VertexHelper vh, Painter painter)

protected virtual void OnDrawPainterTop(VertexHelper vh, Painter painter)
{
//Debug.LogError("OnDrawPainterTop:" + Time.frameCount + "," + painter.name);
vh.Clear();
if (m_OnCustomDrawCallback != null)
{
Expand Down
8 changes: 2 additions & 6 deletions Assets/XCharts/Runtime/Internal/BaseGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,8 @@ private void InitBackground()

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<Painter>(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;
}
Expand Down Expand Up @@ -339,7 +336,6 @@ protected virtual void OnLocalPositionChanged()

protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter)
{
Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name);
DrawBackground(vh);
DrawPainterBase(vh);
}
Expand Down
3 changes: 0 additions & 3 deletions Assets/XCharts/Runtime/Internal/Helper/VisualMapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;

namespace XCharts
Expand Down Expand Up @@ -38,12 +37,10 @@ public static void SetMinMax(VisualMap visualMap, float min, float max)
{
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
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/XCharts/Runtime/Internal/Painter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace XCharts
{
public partial class Painter : MaskableGraphic
[RequireComponent(typeof(CanvasRenderer))]
public class Painter : MaskableGraphic
{
public enum Type
{
Expand All @@ -32,7 +33,6 @@ public void Refresh()
if (gameObject == null) return;
if (!gameObject.activeSelf) return;
m_Refresh = true;
//Debug.LogError("refresh painter:"+name);
}

public void Init()
Expand Down
9 changes: 9 additions & 0 deletions Assets/XCharts/Runtime/Internal/Utility/ChartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ internal static GameObject AddTooltipContent(string name, Transform parent, Text
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<Painter>(painterObj);
}

public static GameObject AddIcon(string name, Transform parent, float width, float height)
{
var anchorMax = new Vector2(0.5f, 0.5f);
Expand Down
27 changes: 8 additions & 19 deletions Assets/XCharts/Runtime/XChartsMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ IEnumerator GetVersion()

private void CheckVersionWebRequest(UnityWebRequest web)
{
if (IsNetworkError(web))
if (IsWebRequestError(web))
{
isNetworkError = true;
networkError = web.error;
Expand Down Expand Up @@ -240,29 +240,18 @@ private void CheckLog(string text)
changeLog = sb.ToString();
}

#if UNITY_5 || UNITY_2017_1
public bool IsNetworkError(UnityWebRequest request)
public bool IsWebRequestError(UnityWebRequest request)
{
return request.isError && !IsHttpError(request);
}
#if UNITY_5
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 IsNetworkError(UnityWebRequest request)
{
return request.isNetworkError;
}
#endif

#if UNITY_5
public bool IsHttpError(UnityWebRequest request)
{
return request.responseCode >= 400;
}
#else
public bool IsHttpError(UnityWebRequest request)
{
return request.isHttpError;
}
#endif

void OnEnable()
{
Expand Down
2 changes: 0 additions & 2 deletions Assets/XCharts/Runtime/XChartsPackageResourceImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void OnGUI()
AssetDatabase.importPackageCompleted += ImportCallback;

string packageFullPath = GetPackageFullPath();
Debug.LogError("packageFullPath:" + packageFullPath);
AssetDatabase.ImportPackage(packageFullPath + "/Package Resources/XCharts Essential Resources.unitypackage", false);
}
GUILayout.Space(5f);
Expand Down Expand Up @@ -110,7 +109,6 @@ static string GetPackageFullPath()
}

packagePath = Path.GetFullPath("Assets/..");
Debug.LogError("packagePath:" + packagePath + ":" + Directory.Exists(packagePath));
if (Directory.Exists(packagePath))
{
// Search default location for development package
Expand Down
2 changes: 0 additions & 2 deletions Assets/XChartsDemo/Runtime/UIUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
/* */
/************************************************/

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace XChartsDemo
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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的图表由组件和数据组成。不同的组件和数据可以组合成不同类型的图表。组件分为主组件和子组件,主组件包含子组件。

Expand Down Expand Up @@ -168,6 +168,6 @@ VIP群:XCharts技术支持VIP群(`867291970`)

企业赞助请备注公司名称。

![xcharts-alipay](Doc/alipay.png)
![alipay](Doc/alipay.png)

如需商业技术支持,捐助280¥可加VIP群(`867291970`,验证信息请输入捐助的支付宝账号)。

0 comments on commit f5c76ce

Please sign in to comment.