Compare commits

...

39 Commits

Author SHA1 Message Date
monitor1394
3df991e5c0 发布v1.1.0版本 2019-12-17 09:01:00 +08:00
monitor1394
5d885e190b new feature 2019-12-16 09:45:30 +08:00
monitor1394
be0bdd0248 修复Overlay模式下不显示Tooltip的问题 2019-12-16 09:44:52 +08:00
monitor1394
78cf3dafa7 增加Title的TextStyle支持 2019-12-15 21:36:59 +08:00
monitor1394
03aaa61e91 Merge branch 'master' of https://github.com/monitor1394/unity-ugui-XCharts 2019-12-11 02:15:04 +08:00
monitor1394
44ed434e13 更新文档 2019-12-11 02:14:58 +08:00
monitor1394
067a70e385 修复Legend都隐藏时Value轴还显示数值的问题 2019-12-11 02:14:37 +08:00
monitor1394
ac61213db3 修复Series->Data->Size重置为0后设置无效的问题 2019-12-11 01:39:27 +08:00
monitor1394
59d8b7fb52 修复Series->Data->Size重置为0后设置无效的问题 2019-12-11 01:38:29 +08:00
monitor1394
1a52a8e098 修复数据过小时AxisLabel直接科学计数法显示的问题 2019-12-06 10:08:48 +08:00
monitor1394
9e51e16e9c 优化和完善数据更新UpdateData接口 2019-12-04 09:44:59 +08:00
monitor1394
b29fc0ed02 增加圆环饼图的圆角支持 2019-12-03 09:34:18 +08:00
monitor1394
74b304a72d 增加数据更新动画 2019-12-03 07:49:37 +08:00
monitor1394
ab057cb623 增加GaugeChart仪表盘 2019-11-30 21:28:54 +08:00
monitor1394
3a478c2abc 增加GaugeChart仪表盘 2019-11-30 21:24:04 +08:00
monitor1394
d8a8b5e50e 更新文档链接 2019-11-22 09:55:50 +08:00
monitor1394
8b5ddc725d 更新版本日期 2019-11-22 09:49:09 +08:00
monitor1394
55807ac941 更新版本日期 2019-11-22 09:48:37 +08:00
monitor1394
110f4ee5f8 修复BarChart清空数据重新赋值后SerieLabel显示异常的问题 2019-11-22 09:46:30 +08:00
monitor1394
5aaa53c503 修复Label字体样式参数设置无效的问题 2019-11-16 21:16:43 +08:00
monitor1394
dc3168747c 修复SerieLabel设置color不生效的问题 2019-11-16 20:15:35 +08:00
monitor1394
38d9232136 发布v1.0.5版本 2019-11-12 19:54:39 +08:00
monitor1394
b661c8e3d1 使用Unity2017.4.27f1作为开发版本,更好的支持低版本 2019-11-12 12:49:07 +08:00
monitor1394
1a949ecb50 整理代码 2019-11-12 12:47:25 +08:00
monitor1394
27dca7c67b Merge pull request #23 from jrapoport/master
support standard c# string formatters in axis labels
2019-11-12 12:39:37 +08:00
Jacob Rapoport
a19a917941 support standard c# string formatters on axis labels 2019-11-11 18:21:30 -08:00
Jacob Rapoport
fb08b62839 Merge branch 'master' of ssh://github.com/monitor1394/unity-ugui-XCharts 2019-11-11 18:12:06 -08:00
monitor1394
bd75f43b2a 修复Label坐标显示异常的问题 2019-11-12 09:49:25 +08:00
monitor1394
668aa4ef0f 修复2018.3以下版本打开项目报错的问题 2019-11-12 08:00:47 +08:00
monitor1394
837658ddcc 增加忽略文件 2019-11-12 08:00:36 +08:00
monitor1394
6503ac2e24 修复2018.3以下版本打开报错的问题 2019-11-12 07:59:46 +08:00
monitor1394
eae0afe659 修复Demo脚本丢失问题 2019-11-12 07:57:10 +08:00
monitor1394
ddb526fb42 增加IconStyle子组件,优化SerieData的图标配置 2019-11-12 07:38:02 +08:00
monitor1394
db50c8ffbe 修复图标显示在上覆盖Label的问题 2019-11-11 09:41:21 +08:00
monitor1394
7198734083 修复饼图当数据过小时视觉引导线会穿透的的问题 2019-11-11 09:24:24 +08:00
monitor1394
6cfcf84b5d 修复饼图添加数据时Label异常的问题 2019-11-09 16:34:16 +08:00
monitor1394
70bcebe9ea 更新文档 2019-11-09 07:51:37 +08:00
monitor1394
d45e2695a5 优化结构,分离为XCharts和XChartsDemo两部分 2019-11-09 07:00:58 +08:00
Jacob Rapoport
d4e7fdbb9c add UpdateThemeInfo API 2019-10-26 17:19:09 -07:00
93 changed files with 299161 additions and 137694 deletions

8
.gitignore vendored
View File

@@ -11,10 +11,10 @@
/Assets/Package
/Assets/Package.meta
/Assets/XCharts/Demo/demo_test.unity
/Assets/XCharts/Demo/demo_test.unity.meta
/Assets/XCharts/Demo/empty.unity
/Assets/XCharts/Demo/empty.unity.meta
/Assets/XChartsDemo/demo_test.unity
/Assets/XChartsDemo/demo_test.unity.meta
/Assets/XChartsDemo/empty.unity
/Assets/XChartsDemo/empty.unity.meta
*.sln
*.csproj

View File

@@ -1,6 +1,26 @@
# 更新日志
* (2019.11.17) 发布`v1.1.0`版本
* (2019.12.16) 修复`Overlay`模式下不显示`Tooltip`的问题
* (2019.12.15) 增加`Title``TextStyle`支持
* (2019.12.11) 修复`Legend`都隐藏时`Value轴`还显示数值的问题
* (2019.12.11) 修复`Series->Data->Size`重置为0后设置无效的问题
* (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题
* (2019.12.04) 优化和完善数据更新`UpdateData`接口
* (2019.12.03) 增加圆环饼图的圆角支持,参数:`serie.arcShaped`
* (2019.12.03) 增加数据更新动画,参数:`serie.animation.updateAnimation`
* (2019.11.30) 增加`GaugeChart`仪表盘
* (2019.11.22) 修复`BarChart`清空数据重新赋值后`SerieLabel`显示异常的问题
* (2019.11.16) 修复`SerieLabel`设置`color`等参数不生效的问题
* (2019.11.12) 发布`v1.0.5`版本
* (2019.11.12) 修复`2018.3`以下版本打开项目报错的问题
* (2019.11.12) 增加`IconStyle`子组件,优化`SerieData`的图标配置
* (2019.11.11) 修复`Serie`的图标显示在上层遮挡`Label`的问题
* (2019.11.11) 修复饼图当数据过小时视觉引导线会穿透的的问题
* (2019.11.09) 修复饼图添加数据时`Label`异常的问题
* (2019.11.09) 优化结构,分离为`XCharts``XChartsDemo`两部分
* (2019.11.05) 发布`v1.0.4`版本
* (2019.11.05) 增加`Radar`雷达组件文本样式参数配置支持
* (2019.11.04) 修复`Unity2018.3`以下版本代码不兼容的问题
* (2019.11.04) 优化`SerieLabel`过多时引起的性能问题

View File

@@ -1,8 +1,6 @@
fileFormatVersion: 2
guid: 5e6b0fb015bc6524d8bab146b6f2ba3a
folderAsset: yes
timeCreated: 1553641866
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:

View File

@@ -1,17 +0,0 @@
{
"name": "XCharts.Editor.Demo",
"references": [
"XCharts.Demo.Runtime",
"XCharts.Runtime"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

View File

@@ -0,0 +1,52 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo01_UpdateData : MonoBehaviour
{
private float updateTime = 0;
BaseChart chart;
void Awake()
{
chart = gameObject.GetComponent<BaseChart>();
}
void Update()
{
updateTime += Time.deltaTime;
if (chart && updateTime > 2)
{
updateTime = 0;
var serie = chart.series.GetSerie(0);
//serie.animation.updateAnimation = true;
var dataCount = serie.dataCount;
if (chart is RadarChart)
{
var dimension = serie.GetSerieData(0).data.Count - 1;
chart.UpdateData(0, 0, Random.Range(0, dimension + 1), Random.Range(0, 100));
}
else if (chart is HeatmapChart)
{
var dimension = serie.GetSerieData(0).data.Count - 1;
for (int i = 0; i < dataCount; i++)
{
chart.UpdateData(0, i, dimension, Random.Range(0, 10));
}
}
else
{
chart.UpdateData(0, Random.Range(0, dataCount), Random.Range(10, 90));
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6faaaf3d4a8444b4b2736825e237fcf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -66,10 +66,10 @@ namespace XCharts
chart.RemoveData();
serie = chart.AddSerie(SerieType.Pie, "访问来源");
serie.pieRadius[0] = 0;
serie.pieRadius[1] = 110;
serie.pieCenter[0] = 0.5f;
serie.pieCenter[1] = 0.4f;
serie.radius[0] = 0;
serie.radius[1] = 110;
serie.center[0] = 0.5f;
serie.center[1] = 0.4f;
chart.AddData(0, 335, "直接访问");
chart.AddData(0, 310, "邮件营销");
chart.AddData(0, 243, "联盟广告");
@@ -105,10 +105,10 @@ namespace XCharts
IEnumerator Doughnut()
{
chart.title.subText = "圆环图";
serie.pieRadius[0] = 2f;
while (serie.pieRadius[0] < serie.pieRadius[1] * 0.7f)
serie.radius[0] = 2f;
while (serie.radius[0] < serie.radius[1] * 0.7f)
{
serie.pieRadius[0] += m_RadiusSpeed * Time.deltaTime;
serie.radius[0] += m_RadiusSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
@@ -134,14 +134,14 @@ namespace XCharts
chart.AddData(1, 335, "直达");
chart.AddData(1, 679, "营销广告");
chart.AddData(1, 1548, "搜索引擎");
serie1.pieRadius[0] = 0;
serie1.pieRadius[1] = 2f;
serie1.pieCenter[0] = 0.5f;
serie1.pieCenter[1] = 0.4f;
serie1.radius[0] = 0;
serie1.radius[1] = 2f;
serie1.center[0] = 0.5f;
serie1.center[1] = 0.4f;
chart.RefreshChart();
while (serie1.pieRadius[1] < serie.pieRadius[0] * 0.75f)
while (serie1.radius[1] < serie.radius[0] * 0.75f)
{
serie1.pieRadius[1] += m_RadiusSpeed * Time.deltaTime;
serie1.radius[1] += m_RadiusSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
@@ -163,7 +163,7 @@ namespace XCharts
chart.legend.show = false;
serie1.ClearData();
serie.ClearData();
serie1.pieRadius = serie.pieRadius = new float[2] { 0, 80 };
serie1.radius = serie.radius = new float[2] { 0, 80 };
serie1.label.position = SerieLabel.Position.Outside;
serie1.label.lineType = SerieLabel.LineType.Curves;
serie1.label.color = Color.clear;
@@ -179,24 +179,24 @@ namespace XCharts
chart.AddData(i, 40, "rose8");
}
while (serie.pieCenter[0] > 0.25f || serie1.pieCenter[0] < 0.7f)
while (serie.center[0] > 0.25f || serie1.center[0] < 0.7f)
{
if (serie.pieCenter[0] > 0.25f) serie.pieCenter[0] -= m_CenterSpeed * Time.deltaTime;
if (serie1.pieCenter[0] < 0.7f) serie1.pieCenter[0] += m_CenterSpeed * Time.deltaTime;
if (serie.center[0] > 0.25f) serie.center[0] -= m_CenterSpeed * Time.deltaTime;
if (serie1.center[0] < 0.7f) serie1.center[0] += m_CenterSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
yield return new WaitForSeconds(1);
while (serie.pieRadius[0] > 3f)
while (serie.radius[0] > 3f)
{
serie.pieRadius[0] -= m_RadiusSpeed * Time.deltaTime;
serie1.pieRadius[0] -= m_RadiusSpeed * Time.deltaTime;
serie.radius[0] -= m_RadiusSpeed * Time.deltaTime;
serie1.radius[0] -= m_RadiusSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
serie.pieRadius[0] = 0;
serie1.pieRadius[0] = 0;
serie.radius[0] = 0;
serie1.radius[0] = 0;
serie.pieRoseType = RoseType.Area;
serie1.pieRoseType = RoseType.Radius;
chart.RefreshChart();

View File

@@ -0,0 +1,70 @@
using System.Runtime.InteropServices;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo70_Gauge : MonoBehaviour
{
private GaugeChart chart;
private float updateTime;
void Awake()
{
chart = gameObject.GetComponent<GaugeChart>();
if (chart == null)
{
chart = gameObject.AddComponent<GaugeChart>();
}
chart.title.text = "GaugeChart";
chart.RemoveData();
var serie = chart.AddSerie(SerieType.Gauge, "速度");
serie.min = 0;
serie.max = 220;
serie.startAngle = -125;
serie.endAngle = 125;
serie.center[0] = 0.5f;
serie.center[1] = 0.5f;
serie.radius[0] = 80;
serie.splitNumber = 5;
serie.animation.updateAnimation = true;
serie.arcShaped = true;
serie.titleStyle.show = true;
serie.titleStyle.textStyle.offset = new Vector2(0, 20);
serie.label.show = true;
serie.label.offset = new Vector3(0, -20);
serie.gaugeAxis.show = true;
serie.gaugeAxis.axisLine.width = 15;
serie.gaugePointer.show = true;
serie.gaugePointer.width = 15;
var value = UnityEngine.Random.Range(serie.min, serie.max);
chart.AddData(0, value, "km/h");
}
void Update()
{
updateTime += Time.deltaTime;
if (updateTime > 2)
{
updateTime = 0;
var value = UnityEngine.Random.Range(0, 220);
chart.UpdateData(0, 0, value);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 250f744fcb07d4401994d964c4369d9d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -14,27 +14,34 @@ namespace XCharts
[ExecuteInEditMode]
public class Demo_Test : MonoBehaviour
{
LineChart chart;
private float updateTime = 0;
BaseChart chart;
void Awake()
{
chart = gameObject.GetComponent<LineChart>();
if (chart == null)
{
chart = gameObject.AddComponent<LineChart>();
}
var buttom = transform.parent.gameObject.GetComponentInChildren<Button>();
buttom.onClick.AddListener(AddData);
chart = gameObject.GetComponent<BaseChart>();
}
void AddData()
void Update()
{
chart.series.list[0].ClearData();
chart.series.list[1].ClearData();
for (int i = 0; i < 5; i++)
updateTime += Time.deltaTime;
if (chart && updateTime > 2)
{
chart.AddData(0, Random.Range(20, 100));
chart.AddData(1, Random.Range(1, 10));
updateTime = 0;
var serie = chart.series.GetSerie(0);
serie.animation.updateAnimation = true;
var dataCount = serie.dataCount;
if (chart is HeatmapChart)
{
var dimension = serie.GetSerieData(0).data.Count - 1;
for (int i = 0; i < dataCount; i++)
{
chart.UpdateData(0, i, dimension, Random.Range(0, 10));
}
}
else
{
chart.UpdateData(0, Random.Range(0, dataCount), Random.Range(10, 90));
}
}
}
}

View File

@@ -29,6 +29,10 @@
* `BaseChart.AddData(int serieIndex, float xValue, float yValue, string dataName = null)`:添加`x,y`数据到指定系列中。
* `BaseChart.UpdateData(string serieName,int dataIndex, float value)`:更新指定系列中的指定索引数据。
* `BaseChart.UpdateData(int serieIndex,int dataIndex, float value)`:更新指定系列中的指定索引数据。
* `BaseChart.UpdateData(string serieName, int dataIndex, List<float> multidimensionalData)`:更新指定系列指定索引的数据项的多维数据。
* `BaseChart.UpdateData(int serieIndex, int dataIndex, List<float> multidimensionalData)`:更新指定系列指定索引的数据项的多维数据。
* `BaseChart.UpdateData(string serieName, int dataIndex, int dimension, float value)`更新指定系列指定索引指定维数的数据。维数从0开始。
* `BaseChart.UpdateData(int serieIndex, int dataIndex, int dimension, float value)`更新指定系列指定索引指定维数的数据。维数从0开始。
* `BaseChart.UpdateDataName(string serieName,int dataIndex, string dataName)`:更新指定系列中的指定索引数据名称。
* `BaseChart.UpdateDataName(int serieIndex, int dataIndex, string dataName)`:更新指定系列中的指定索引数据名称。
* `BaseChart.SetActive(string serieName, bool active)`:设置指定系列是否显示。

View File

@@ -12,6 +12,13 @@
* [Legend 图例](#Legend)
* [Radar 雷达](#Radar)
* [Series 系列](#Series)
* [Serie-Line 折线图](#Serie-Line)
* [Serie-Bar 柱形图](#Serie-Bar)
* [Serie-Pie 饼图](#Serie-Pie)
* [Serie-Radar 雷达图](#Serie-Radar)
* [Serie-Scatter 散点图](#Serie-Scatter)
* [Serie-Heatmap 热力图](#Serie-Heatmap)
* [Serie-Gauge 仪表盘](#Serie-Gauge)
* [Settings 设置](#Settings)
* [Theme 主题](#Theme)
* [Tooltip 提示框](#Tooltip)
@@ -39,7 +46,6 @@
## `Theme`
---
主题组件。主题用来配置图表的全局配色等其他参数。
相关参数:
@@ -72,22 +78,31 @@
## `Title`
---
标题组件,包含主标题和副标题。
相关参数:
* `show`:是否显示标题组件。
* `text`:主标题文本,支持使用 `\n` 换行。
* `textFontSize`:主标题文字的字体大小
* `textStyle`:主标题文本样式 [TextStyle](#TextStyle)
* `subText`:副标题文本,支持使用 `\n` 换行。
* `subTextFontSize`:副标题文字的字体大小
* `subTextStyle`:副标题文本样式 [TextStyle](#TextStyle)
* `itemGap`:主副标题之间的间距。
* `location`:标题显示位置 [Location](#Location)。
## `TitleStyle`
标题样式。
* `show`:是否显示标题组件。
* `rotate`:旋转。
* `offset`:偏移。
* `color`:颜色。
* `fontSize`:字体大小。
* `fontStyle`:字体风格。
## `Legend`
---
图例组件。图例组件展现了不同系列的标记,颜色和名字。可以通过点击图例控制哪些系列不显示。
相关参数:
@@ -119,8 +134,6 @@
## `Radar`
---
* `shape`:雷达图绘制类型。
* `Polygon`:多边形。
* `Circle`:圆形。
@@ -137,8 +150,6 @@
## `Radar.Indicator`
---
* `name`:指示器名称。
* `max`:指示器的最大值,默认为 0 无限制。
* `min`:指示器的最小值,默认为 0 无限制。
@@ -146,8 +157,6 @@
## `TextStyle`
---
* `rotate`:旋转。
* `offset`:偏移。
* `color`:颜色。
@@ -156,8 +165,6 @@
## `Tooltip`
---
提示框组件。
相关参数:
@@ -183,8 +190,6 @@
## `DataZoom`
---
区域缩放组件。用于区域缩放,从而能自由关注细节的数据信息,或者概览数据整体,或者去除离群点的影响。
目前只支持控制 `X` 轴。
@@ -217,8 +222,6 @@
## `VisualMap`
---
视觉映射组件。用于进行『视觉编码』,也就是将数据映射到视觉元素(视觉通道)。
* `enable`:开启或关闭视觉映射功能。
@@ -249,8 +252,6 @@
## `Grid`
---
网格组件。直角坐标系内绘图网格,单个 `grid` 内最多可以放置上下两个 `X` 轴,左右两个 `Y` 轴。可以在网格上绘制折线图,柱状图,散点图(气泡图)。目前最多只能存在一个 `grid` 组件。
相关参数:
@@ -262,9 +263,24 @@
* `bottom`:组件离容器底部的距离。
* `backgroundColor`:背景颜色。
## `XAxis`
## `GaugeAxis`
---
仪表盘坐标轴。
* `axisLine`:坐标轴轴线样式。
* `splitLine`:坐标轴分割线样式。
* `axisTick`:坐标轴刻度样式。
* `axisLabel`:坐标轴刻度标签样式。
* `axisLabelText`坐标轴刻度标签自定义内容。当内容为空时axisLabel根据刻度自动显示内容否则取自该列表定义的内容。
## `GaugePointer`
仪表盘指针。
* `width`:指针宽度。
* `length`指针长度。当为0-1的浮点数时表示相对仪表盘半径的百分比。
## `XAxis`
直角坐标系 `grid` 中的 `X` 轴。单个 `grid` 组件最多只能放上下两个 `X` 轴。两个 `X` 轴存储在 `xAxises` 中。
@@ -307,8 +323,6 @@
## `YAxis`
---
直角坐标系 `grid` 中的 `Y` 轴。单个 `grid` 组件最多只能放左右两个 `Y` 轴。两个 `Y` 轴存储在 `yAxises` 中。
相关参数:
@@ -349,8 +363,6 @@
## `Series`
---
系列列表。每个系列通过 type 决定自己的图表类型。
相关参数:
@@ -407,18 +419,169 @@
* `pieSpace`:饼图项间的空隙留白。
* `pieCenter`:饼图的中心点。
* `pieRadius`:饼图的半径。`radius[0]` 表示内径,`radius[1]` 表示外径。
* `arcShaped`:启用弧形圆角效果。目前只在仪表盘和圆环饼图中有效。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `lineArrow`:折线图的箭头 [LineArrow](#LineArrow)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
相关接口:
## `Serie-Line`
折线图系列。
* `show`:系列是否显示在图表上。
* `type``Line`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `stack`:数据堆叠。同个类目轴上系列配置相同的 `stack` 值后,后一个系列的值会在前一个系列的值上相加。
* `axisIndex`:使用的坐标轴轴的 `index`,在单个图表实例中存在多个坐标轴轴的时候有用。
* `minShow`:系列显示数据的最小索引。
* `maxShow`:系列显示数据的最大索引。
* `maxCache`:系列中可缓存的最大数据量。默认为`0`没有限制大于0时超过指定值会移除旧数据再插入新数据。
* `sampleDist`采样的最小水平像素距离,默认为`0`时不采样。当两个数据点间的水平像素距离小于该值时,开启采样,保证两点间的水平像素距离不小于该值。
* `sampleType`:采样类型。当`sampleDist`大于`0`时有效。支持以下五种采样类型:
* `Peak`:取峰值。当过滤点的平均值大于等于`sampleAverage`时,取最大值;反之取最小值。
* `Average`:取过滤点的平均值。
* `Max`:取过滤点的最大值。
* `Min`:取过滤点的最小值。
* `Sum`:取过滤点之和。
* `sampleAverage`:设定的采样平均值。当 `sampleType``Peak` 时,用于和过滤数据的平均值做对比是取最大值还是最小值。默认为`0`时会实时计算所有数据的平均值。
* `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `lineType`:折线图样式类型。支持以下十种类型:
* `Normal`:普通折线图。
* `Smooth`:平滑曲线。
* `SmoothDash`:平滑虚线。
* `StepStart`:阶梯线图:当前点。
* `StepMiddle`:阶梯线图:当前点和下一个点的中间。
* `StepEnd`:阶梯线图:下一个拐点。
* `Dash`:虚线。
* `Dot`:点线。
* `DashDot`:点划线。
* `DashDotDot`:双点划线。
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `lineArrow`:折线图的箭头 [LineArrow](#LineArrow)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
## `Serie-Bar`
折线图系列。
* `show`:系列是否显示在图表上。
* `type``Bar`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `stack`:数据堆叠。同个类目轴上系列配置相同的 `stack` 值后,后一个系列的值会在前一个系列的值上相加。
* `axisIndex`:使用的坐标轴轴的 `index`,在单个图表实例中存在多个坐标轴轴的时候有用。
* `minShow`:系列显示数据的最小索引。
* `maxShow`:系列显示数据的最大索引。
* `maxCache`:系列中可缓存的最大数据量。默认为`0`没有限制大于0时超过指定值会移除旧数据再插入新数据。
* `barType`:柱状图类型。以下几种类型:
* `Normal`:普通柱状图。
* `Zebra`:斑马柱状图。
* `Capsule`:胶囊柱状图。
* `barPercentStack`:是否百分比堆叠柱状图,相同 `stack``serie` 只要有一个 `barPercentStack``true`,则就显示成百分比堆叠柱状图。
* `barWidth`:柱条的宽度,不设时自适应。支持设置成相对于类目宽度的百分比。
* `barGap`:不同系列的柱间距离。为百分比(如 `'0.3f'`,表示柱子宽度的 `30%`)。如果想要两个系列的柱子重叠,可以设置 `barGap``'-1f'`。这在用柱子做背景的时候有用。在同一坐标系上,此属性会被多个 `'bar'` 系列共享。此属性应设置于此坐标系中最后一个 `'bar'` 系列上才会生效,并且是对此坐标系中所有 `'bar'` 系列生效。
* `barCategoryGap`同一系列的柱间距离默认为类目间距的20%,可设固定值。在同一坐标系上,此属性会被多个 `'bar'` 系列共享。此属性应设置于此坐标系中最后一个 `'bar'` 系列上才会生效,并且是对此坐标系中所有 `'bar'` 系列生效。
* `barZebraWidth`:斑马线的粗细。`barType``Zebra` 时有效。
* `barZebraGap`:斑马线的间距。`barType``Zebra` 时有效。
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `itemStyle`:柱条样式 [ItemStyle](#ItemStyle)。
* `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
## `Serie-Pie`
饼图系列。
* `show`:系列是否显示在图表上。
* `type``Pie`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `pieRoseType`:南丁格尔玫瑰图类型,支持以下类型:
* `None`:不展示成南丁格尔玫瑰图。
* `Radius`:扇区圆心角展现数据的百分比,半径展现数据的大小。
* `Area`:所有扇区圆心角相同,仅通过半径展现数据大小。
* `space`:扇区间隙。
* `center`中心点坐标。当值为0-1的浮点数时表示百分比。
* `radius`:半径。`radius[0]`为内径,`radius[1]`为外径。当内径大于0时即为圆环图。
* `arcShaped`:是否启用圆角效果。只在圆环图中有效。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
## `Serie-Radar`
雷达图系列。
* `show`:系列是否显示在图表上。
* `type``Radar`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `radarIndex`:雷达图所使用的 `radar` 组件的 `index`
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
## `Serie-Scatter`
散点图系列。
* `show`:系列是否显示在图表上。
* `type``Scatter`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
## `Serie-Heatmap`
热力图系列。
* `show`:系列是否显示在图表上。
* `type``Scatter`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
## `Serie-Gauge`
仪表盘系列。
* `show`:系列是否显示在图表上。
* `type``Gauge`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `gaugeType`:仪表盘类型,支持以下类型:
* `Pointer`:指针类型。
* `ProgressBar`:进度条类型。
* `center`中心点坐标。当值为0-1的浮点数时表示百分比。
* `radius`:仪表盘半径。
* `min`最小的数据值。映射到startAngle。
* `max`最大的数据值。映射到endAngle。
* `startAngle`仪表盘起始角度。和时钟一样12点钟位置是0度顺时针到360度。
* `endAngle`仪表盘结束角度。和时钟一样12点钟位置是0度顺时针到360度。
* `splitNumber`:仪表盘刻度分割段数。
* `arcShaped`:是否启用圆角效果。
* `titleStyle`:仪表盘标题 [TitleStyle](#TitleStyle)。
* `gaugeAxis` 仪表盘坐标轴 [GaugeAxis](#GaugeAxis)。
* `gaugePointer`:仪表盘指针 [GaugePointer](#GaugePointer)。
* `itemStyle`:仪表盘指针样式 [ItemStyle](#ItemStyle)。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。仪表盘的数据一般只有一个,值通过`label`样式显示,`name`通过`titleStyle`样式显示。
## `Settings`
---
全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
* `lineSmoothStyle`:曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
@@ -426,21 +589,19 @@
* `lineSegmentDistance` 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
* `cicleSmoothness`:圆形(包括扇形、环形等)的平滑度。数越小圆越平滑,但顶点数也会随之增加。
## `Animation`
---
## `SerieAnimation`
* `enable`:是否开起始画效果。
* `easing`:动画的缓动效果。支持以下动画效果:
* `Linear`:线性效果。
* `duration`:设定的动画时长,单位毫秒。
* `updateAnimation`:是否开启数据变更动画。
* `updateDuration`:数据变更动画时长,单位毫秒。
* `threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
* `delay`:动画延时,单位毫秒。
## `AreaStyle`
---
* `show`:是否显示区域填充。
* `origin`:区域填充的起始位置 `AreaOrigin`。有以下三种填充方式:
* `Auto`:填充坐标轴轴线到数据间的区域。
@@ -455,8 +616,6 @@
## `AxisLabel`
---
* `show`:是否显示刻度标签。
* `interval`坐标轴刻度标签的显示间隔在类目轴中有效。0表示显示所有标签1表示隔一个隔显示一个标签以此类推。
* `inside`:刻度标签是否朝内,默认朝外。
@@ -470,8 +629,6 @@
## `AxisLine`
---
* `show`:是否显示坐标轴轴线。
* `onZero`X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效。
* `width`:坐标轴线线宽。
@@ -483,8 +640,6 @@
## `AxisName`
---
* `show`:是否显示坐标名称。
* `name`:坐标轴名称。
* `location`:坐标轴名称的位置。支持以下类型:
@@ -499,15 +654,11 @@
## `AxisSplitArea`
---
* `show`:是否显示坐标分割区域。
* `color`:分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
## `AxisTick`
---
* `show`:是否显示坐标轴刻度。
* `alignWithLabel`:类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。
* `inside`:坐标轴刻度是否朝内,默认朝外。
@@ -515,16 +666,12 @@
## `Emphasis`
---
* `show`:是否启用高亮样式。
* `label`:图形文本标签样式 [SerieLabel](#SerieLabel)。
* `itemStyle`:图形样式 [ItemStyle](#ItemStyle)。
## `ItemStyle`
---
* `show`:是否启用。
* `color`:颜色。
* `borderType`:边框的类型。
@@ -534,8 +681,6 @@
## `LineArrow`
---
* `show`:是否显示箭头。
* `position`:箭头显示位置。支持以下两种位置:
* `End`:末端显示。最后一个数据上显示箭头。
@@ -547,8 +692,6 @@
## `LineStyle`
---
* `show`:是否显示线条。在折线图中无效。
* `type`:线条类型。支持以下五种类型:
* `None`:不显示分割线。
@@ -563,8 +706,6 @@
## `Location`
---
* `align`:对齐方式。有以下对齐方式。
* `TopLeft`:左上角对齐。
* `TopRight`:右上角对齐。
@@ -582,8 +723,6 @@
## `SerieData`
---
* `name`:数据项名称。
* `selected`:该数据项是否被选中。
* `radius`:自定义半径。可用在饼图中自定义某个数据项的半径。
@@ -596,8 +735,6 @@
## `SerieLabel`
---
* `show`:是否显示文本标签。
* `position`:标签的位置。折线图时强制默认为 `Center`,支持以下 `5` 种位置:
* `Outside`:饼图扇区外侧,通过视觉引导线连到相应的扇区。只在饼图种可用。
@@ -632,8 +769,6 @@
## `SerieSymbol`
---
* `type`:标记类型。支持以下六种类型:
* `EmptyCircle`:空心圆。
* `Circle`:实心圆。

View File

@@ -27,6 +27,7 @@
[QA 21如何显示图例](#如何显示图例)
[QA 22如何做成预设](#如何做成预设)
[QA 23如何在图表上画点画线等自定义内容](#如何在图表上画点画线等自定义内容)
[QA 24如何实现心电图类似的数据移动效果](#如何实现心电图类似的数据移动效果)
## 如何调整坐标轴与背景的边距
@@ -120,6 +121,10 @@
xcharts有自定义绘制回调`customDrawCallback`,具体可参考`Demo12_CustomDrawing.cs`
## 如何实现心电图类似的数据移动效果
axis和serie都设置相同的maxCache。maxCache可固定数据个数当数据超过设定时会先删除第一个在添加新数据实现数据移动效果。
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XChartsAPI接口](XChartsAPI.md)
[XCharts配置项手册](XCharts配置项手册.md)

View File

@@ -0,0 +1,33 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEditor;
namespace XCharts
{
/// <summary>
/// Editor class used to edit UI GaugeChart.
/// </summary>
[CustomEditor(typeof(GaugeChart), false)]
public class GaugeChartEditor : BaseChartEditor
{
protected SerializedProperty m_Radar;
protected SerializedProperty m_Radars;
protected override void OnEnable()
{
base.OnEnable();
m_Target = (GaugeChart)target;
}
protected override void OnEndInspectorGUI()
{
base.OnEndInspectorGUI();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd96c5068df484d1c95748a85d8380a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -24,11 +24,13 @@ namespace XCharts
SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable");
SerializedProperty m_Easting = prop.FindPropertyRelative("m_Easting");
SerializedProperty m_Duration = prop.FindPropertyRelative("m_Duration");
SerializedProperty m_UpdateAnimation = prop.FindPropertyRelative("m_UpdateAnimation");
SerializedProperty m_UpdateDuration = prop.FindPropertyRelative("m_UpdateDuration");
SerializedProperty m_Delay = prop.FindPropertyRelative("m_Delay");
SerializedProperty m_Threshold = prop.FindPropertyRelative("m_Threshold");
SerializedProperty m_ActualDuration = prop.FindPropertyRelative("m_ActualDuration");
SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress");
SerializedProperty m_DestDetailProgress = prop.FindPropertyRelative("m_DestDetailProgress");
// SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress");
// SerializedProperty m_DestDetailProgress = prop.FindPropertyRelative("m_DestDetailProgress");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AnimationModuleToggle, prop, null, m_Enable, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -37,20 +39,26 @@ namespace XCharts
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Easting);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Duration);
if (m_Duration.intValue < 0) m_Duration.intValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Delay);
if (m_Delay.intValue < 0) m_Delay.intValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Threshold);
if (m_Threshold.intValue < 0) m_Threshold.intValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "CurrDetailProgress:" + m_CurrDetailProgress.floatValue);
EditorGUI.PropertyField(drawRect, m_Delay);
if (m_Delay.floatValue < 0) m_Delay.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "DestDetailProgress:" + m_DestDetailProgress.floatValue);
EditorGUI.PropertyField(drawRect, m_Duration);
if (m_Duration.floatValue < 0) m_Duration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "Actual duration:" + m_ActualDuration.intValue + " ms");
EditorGUI.PropertyField(drawRect, m_UpdateAnimation);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_UpdateDuration);
if (m_UpdateDuration.floatValue < 0) m_UpdateDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.LabelField(drawRect, "CurrDetailProgress:" + m_CurrDetailProgress.floatValue);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.LabelField(drawRect, "DestDetailProgress:" + m_DestDetailProgress.floatValue);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "Actual duration:" + m_ActualDuration.floatValue + " ms");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}

View File

@@ -0,0 +1,82 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(GaugeAxis), true)]
public class GaugeAxisDrawer : PropertyDrawer
{
private bool m_DataFoldout = false;
private int m_DataSize = 0;
private Dictionary<string, bool> m_AxisLineToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine");
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
SerializedProperty m_AxisLabelText = prop.FindPropertyRelative("m_AxisLabelText");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLineToggle, prop, "Gauge Axis", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_AxisLineToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_AxisLine);
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLine);
EditorGUI.PropertyField(drawRect, m_SplitLine);
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine);
EditorGUI.PropertyField(drawRect, m_AxisTick);
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick);
EditorGUI.PropertyField(drawRect, m_AxisLabel);
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLabel);
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Axis Label Text");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = pos.width;
if (m_DataFoldout)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_AxisLabelText);
}
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_AxisLineToggle, prop))
{
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AxisLine"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitLine"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AxisTick"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AxisLabel"));
if (m_DataFoldout)
{
SerializedProperty m_Data = prop.FindPropertyRelative("m_AxisLabelText");
int num = m_Data.arraySize + 1;
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
else
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dec6cfc5ef85147738a81d8de84b079a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(GaugeAxis.AxisLine), true)]
public class GaugeAxisLineDrawer : PropertyDrawer
{
private bool m_DataFoldout = false;
private int m_DataSize = 0;
private Dictionary<string, bool> m_Toggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity");
SerializedProperty m_BarBackgroundColor = prop.FindPropertyRelative("m_BarBackgroundColor");
SerializedProperty m_BarColor = prop.FindPropertyRelative("m_BarColor");
SerializedProperty m_StageColor = prop.FindPropertyRelative("m_StageColor");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Axis Line", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Width);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Opacity);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarBackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Stage Color");
drawRect.width = pos.width;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_StageColor);
}
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
float height = 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout)
{
var arraySize = prop.FindPropertyRelative("m_StageColor").arraySize + 1;
height += arraySize * EditorGUIUtility.singleLineHeight + (arraySize) * EditorGUIUtility.standardVerticalSpacing;
height += 2 * EditorGUIUtility.standardVerticalSpacing;
return height;
}
return height;
}
else
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb7a86643ea2349c8ac2475ab81cb2f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(GaugeAxis.AxisLine.StageColor), true)]
public class GaugeAxisLineStageColorDrawer : PropertyDrawer
{
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Percent = prop.FindPropertyRelative("m_Percent");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
ChartEditorHelper.MakeTwoField(ref drawRect, drawRect.width, m_Percent, m_Color, "Stage");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc7cae70713a74fb496ef686296bc46b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(GaugeAxis.SplitLine), true)]
public class GaugeAxisSplitDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_Toggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Length = prop.FindPropertyRelative("m_Length");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Split Line", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Length);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
float height = 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
return height;
}
else
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d11eb7847e5c74746a570a7c9f6b339a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(GaugeAxis.AxisTick), true)]
public class GaugeAxisTickDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_Toggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Length = prop.FindPropertyRelative("m_Length");
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Axis Tick", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Length);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
float height = 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
return height;
}
else
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f561506277b949c1b22116a3f3d3f4f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(GaugePointer), true)]
public class GaugePointerDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_Toggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
SerializedProperty m_Length = prop.FindPropertyRelative("m_Length");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Gauge Pointer", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Width);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Length);
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (ChartEditorHelper.IsToggle(m_Toggle, prop))
{
return 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
else
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3d180de37dd24cfc9bcbb46f650c902
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(IconStyle), true)]
public class IconStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_IconStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Layer = prop.FindPropertyRelative("m_Layer");
SerializedProperty m_Sprite = prop.FindPropertyRelative("m_Sprite");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
SerializedProperty m_Height = prop.FindPropertyRelative("m_Height");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_IconStyleToggle, prop, null, m_Show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_IconStyleToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Layer);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Sprite);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Width);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Height);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset);
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (ChartEditorHelper.IsToggle(m_IconStyleToggle, prop))
{
var hight = 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
hight += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
hight += EditorGUIUtility.standardVerticalSpacing;
return hight;
}
else
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cae26ad61d224d8a97d41bdc52ec0b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -58,6 +58,17 @@ namespace XCharts
SerializedProperty m_DataDimension = prop.FindPropertyRelative("m_ShowDataDimension");
SerializedProperty m_ShowDataName = prop.FindPropertyRelative("m_ShowDataName");
SerializedProperty m_ShowDataIcon = prop.FindPropertyRelative("m_ShowDataIcon");
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
SerializedProperty m_StartAngle = prop.FindPropertyRelative("m_StartAngle");
SerializedProperty m_EndAngle = prop.FindPropertyRelative("m_EndAngle");
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
//SerializedProperty m_Clockwise = prop.FindPropertyRelative("m_Clockwise");
SerializedProperty m_ArcShaped = prop.FindPropertyRelative("m_ArcShaped");
SerializedProperty m_GaugeType = prop.FindPropertyRelative("m_GaugeType");
SerializedProperty m_GaugeAxis = prop.FindPropertyRelative("m_GaugeAxis");
SerializedProperty m_GaugePointer = prop.FindPropertyRelative("m_GaugePointer");
SerializedProperty m_TitleStyle = prop.FindPropertyRelative("m_TitleStyle");
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
int index = InitToggle(prop);
@@ -82,87 +93,155 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, name);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, stack);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (serieType == SerieType.Radar)
{
EditorGUI.PropertyField(drawRect, m_RadarIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
else
{
EditorGUI.PropertyField(drawRect, m_AxisIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
EditorGUI.PropertyField(drawRect, m_MinShow);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MaxShow);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MaxCache);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_MinShow.intValue < 0) m_MinShow.intValue = 0;
if (m_MinShow.intValue < 0) m_MinShow.intValue = 0;
if (m_MaxCache.intValue < 0) m_MaxCache.intValue = 0;
if (serieType == SerieType.Line)
{
EditorGUI.PropertyField(drawRect, m_LineType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleDist);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleAverage);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
if (serieType == SerieType.Line
|| serieType == SerieType.Scatter
|| serieType == SerieType.EffectScatter
|| serieType == SerieType.Radar)
{
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
}
if (serieType == SerieType.Bar)
{
EditorGUI.PropertyField(drawRect, m_BarType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarPercentStack);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarZebraWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarZebraGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
if (serieType == SerieType.Pie)
{
EditorGUI.PropertyField(drawRect, m_RoseType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Space);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center");
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Radius, "Radius");
}
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
if (serieType == SerieType.Line)
switch (serieType)
{
EditorGUI.PropertyField(drawRect, m_LineArrow);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineArrow);
case SerieType.Line:
EditorGUI.PropertyField(drawRect, stack);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MinShow);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MaxShow);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MaxCache);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_MinShow.intValue < 0) m_MinShow.intValue = 0;
if (m_MinShow.intValue < 0) m_MinShow.intValue = 0;
if (m_MaxCache.intValue < 0) m_MaxCache.intValue = 0;
EditorGUI.PropertyField(drawRect, m_LineType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleDist);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleAverage);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_LineArrow);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineArrow);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Bar:
EditorGUI.PropertyField(drawRect, stack);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MinShow);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MaxShow);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MaxCache);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_MinShow.intValue < 0) m_MinShow.intValue = 0;
if (m_MinShow.intValue < 0) m_MinShow.intValue = 0;
if (m_MaxCache.intValue < 0) m_MaxCache.intValue = 0;
EditorGUI.PropertyField(drawRect, m_BarType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarPercentStack);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarZebraWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarZebraGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Pie:
EditorGUI.PropertyField(drawRect, m_RoseType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Space);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center");
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Radius, "Radius");
EditorGUI.PropertyField(drawRect, m_ArcShaped);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Radar:
EditorGUI.PropertyField(drawRect, m_RadarIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Heatmap:
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Gauge:
EditorGUI.PropertyField(drawRect, m_GaugeType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center");
//ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Radius, "Radius");
EditorGUI.PropertyField(drawRect, m_Radius.GetArrayElementAtIndex(0), new GUIContent("Radius"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Min);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Max);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_StartAngle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_EndAngle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_SplitNumber.intValue > 36)
{
m_SplitNumber.intValue = 36;
}
EditorGUI.PropertyField(drawRect, m_ArcShaped);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TitleStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TitleStyle);
EditorGUI.PropertyField(drawRect, m_GaugeAxis);
drawRect.y += EditorGUI.GetPropertyHeight(m_GaugeAxis);
EditorGUI.PropertyField(drawRect, m_GaugePointer);
drawRect.y += EditorGUI.GetPropertyHeight(m_GaugePointer);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
}
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
EditorGUI.PropertyField(drawRect, m_Animation);
drawRect.y += EditorGUI.GetPropertyHeight(m_Animation);
drawRect.width = EditorGUIUtility.labelWidth + 10;
@@ -173,7 +252,7 @@ namespace XCharts
{
EditorGUI.indentLevel++;
float nameWid = 40;
float nameWid = 42;
EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension);
var nameRect = new Rect(pos.width - 2 * nameWid + 14, drawRect.y, nameWid, pos.height);
if (GUI.Button(nameRect, new GUIContent("Name")))
@@ -181,7 +260,7 @@ namespace XCharts
m_ShowDataName.boolValue = !m_ShowDataName.boolValue;
}
var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid, pos.height);
if (GUI.Button(iconRect, new GUIContent("Icon")))
if (GUI.Button(iconRect, new GUIContent("Other")))
{
m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue;
}
@@ -232,7 +311,7 @@ namespace XCharts
}
private void DrawDataElement(ref Rect drawRect, int dimension, SerializedProperty m_Datas, bool showName,
bool showIconDetail, bool showSelected, int index, float currentWidth)
bool showDetail, bool showSelected, int index, float currentWidth)
{
var lastX = drawRect.x;
var lastWid = drawRect.width;
@@ -253,7 +332,7 @@ namespace XCharts
if (showSelected)
{
drawRect.width = drawRect.width - 18;
EditorGUI.PropertyField(drawRect, element);
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + index));
drawRect.x = currentWidth - 45;
EditorGUI.PropertyField(drawRect, selected, GUIContent.none);
drawRect.x = lastX;
@@ -261,7 +340,7 @@ namespace XCharts
}
else
{
EditorGUI.PropertyField(drawRect, element);
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + index));
}
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
}
@@ -274,7 +353,7 @@ namespace XCharts
var xWid = dataWid - 4;
for (int i = 0; i < dimension; i++)
{
if (i >= data.arraySize - 1)
while (i >= data.arraySize - 1)
{
data.InsertArrayElementAtIndex(data.arraySize);
}
@@ -296,35 +375,23 @@ namespace XCharts
EditorGUIUtility.fieldWidth = lastFieldWid;
EditorGUIUtility.labelWidth = lastLabelWid;
}
if (showIconDetail)
if (showDetail)
{
EditorGUI.indentLevel++;
var m_ShowIcon = serieData.FindPropertyRelative("m_ShowIcon");
var m_IconImage = serieData.FindPropertyRelative("m_IconImage");
var m_IconColor = serieData.FindPropertyRelative("m_IconColor");
var m_IconWidth = serieData.FindPropertyRelative("m_IconWidth");
var m_IconHeight = serieData.FindPropertyRelative("m_IconHeight");
var m_IconOffset = serieData.FindPropertyRelative("m_IconOffset");
EditorGUI.PropertyField(drawRect, m_ShowIcon);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IconImage);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IconColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IconWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IconHeight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "Icon Offset");
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
var tempWidth = (drawRect.width - startX + 72) / 2;
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
var centerYRect = new Rect(centerXRect.x + tempWidth - 58, drawRect.y, tempWidth, drawRect.height);
var x = EditorGUI.FloatField(centerXRect, m_IconOffset.vector3Value.x);
var y = EditorGUI.FloatField(centerYRect, m_IconOffset.vector3Value.y);
m_IconOffset.vector3Value = new Vector3(x, y);
var m_Icon = serieData.FindPropertyRelative("m_IconStyle");
var m_EnableLabel = serieData.FindPropertyRelative("m_EnableLabel");
var m_Label = serieData.FindPropertyRelative("m_Label");
EditorGUI.PropertyField(drawRect, m_Icon);
drawRect.y += EditorGUI.GetPropertyHeight(m_Icon);
EditorGUI.PropertyField(drawRect, m_EnableLabel);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_EnableLabel.boolValue)
{
EditorGUI.indentLevel++;
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}
@@ -340,48 +407,93 @@ namespace XCharts
}
else
{
height += 9 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
SerializedProperty type = prop.FindPropertyRelative("m_Type");
var serieType = (SerieType)type.enumValueIndex;
if (serieType == SerieType.Line
|| serieType == SerieType.Scatter
|| serieType == SerieType.EffectScatter
|| serieType == SerieType.Radar)
{
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
}
if (serieType == SerieType.Pie)
switch (serieType)
{
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
}
if (serieType == SerieType.Line)
{
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow"));
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
}
if (serieType == SerieType.Bar)
{
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
case SerieType.Line:
height += 13 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Bar:
height += 16 * EditorGUIUtility.singleLineHeight + 15 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Pie:
height += 9 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Radar:
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Heatmap:
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Gauge:
height += 13 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TitleStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_GaugeAxis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_GaugePointer"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
}
if (m_DataFoldout[index])
{
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
int num = m_Data.arraySize + 2;
if (num > 30) num = 15;
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
int num = m_Data.arraySize;
if (num > 30)
{
num = 11;
height += (num + 1) * EditorGUIUtility.singleLineHeight + (num) * EditorGUIUtility.standardVerticalSpacing;
}
else
{
height += (num) * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
}
if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue)
{
num *= 5;
num += 2;
for (int i = 0; i < num; i++)
{
var item = m_Data.GetArrayElementAtIndex(i);
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_IconStyle"));
if (item.FindPropertyRelative("m_EnableLabel").boolValue)
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Label"));
}
}
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
}
if (m_ShowJsonDataArea)
{

View File

@@ -24,6 +24,7 @@ namespace XCharts
SerializedProperty m_Position = prop.FindPropertyRelative("m_Position");
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
SerializedProperty m_Margin = prop.FindPropertyRelative("m_Margin");
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight");
SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom");
@@ -62,6 +63,8 @@ namespace XCharts
m_Offset.vector3Value = new Vector3(x, y);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Margin);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Formatter);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -112,7 +115,7 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop))
{
height += 23 * EditorGUIUtility.singleLineHeight + 22 * EditorGUIUtility.standardVerticalSpacing;
height += 24 * EditorGUIUtility.singleLineHeight + 23 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -14,7 +14,7 @@ namespace XCharts
[CustomPropertyDrawer(typeof(TextStyle), true)]
public class TextStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>();
//private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{

View File

@@ -21,9 +21,9 @@ namespace XCharts
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty text = prop.FindPropertyRelative("m_Text");
SerializedProperty m_TextFontSize = prop.FindPropertyRelative("m_TextFontSize");
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
SerializedProperty subText = prop.FindPropertyRelative("m_SubText");
SerializedProperty m_SubTextFontSize = prop.FindPropertyRelative("m_SubTextFontSize");
SerializedProperty m_SubTextStyle = prop.FindPropertyRelative("m_SubTextStyle");
SerializedProperty m_ItemGap = prop.FindPropertyRelative("m_ItemGap");
SerializedProperty location = prop.FindPropertyRelative("m_Location");
@@ -35,17 +35,17 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, text);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_TextFontSize, new GUIContent("Font Size"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, subText);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_SubTextFontSize, new GUIContent("Font Size"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SubTextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle);
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, location);
}
--EditorGUI.indentLevel;
@@ -56,9 +56,10 @@ namespace XCharts
float height = 0;
if (m_TitleModuleToggle)
{
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
SerializedProperty location = prop.FindPropertyRelative("m_Location");
height += EditorGUI.GetPropertyHeight(location);
height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SubTextStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Location"));
}
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
return height;

View File

@@ -0,0 +1,51 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(TitleStyle), true)]
public class TitleStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_TitleStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_textStyle = prop.FindPropertyRelative("m_textStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TitleStyleToggle, prop, "Title Style", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_TitleStyleToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_textStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_textStyle);
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_TitleStyleToggle, prop))
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_textStyle"));
}
else
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e451ee4c9f65a414784fd5fd9cad6ec1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -114,7 +114,7 @@ public class ChartEditorHelper
{
if (showProp.propertyType == SerializedPropertyType.Boolean)
{
drawRect.width = 60;
drawRect.width = 80;
}
else
{

View File

@@ -98,5 +98,11 @@ namespace XCharts
{
AddChart<HeatmapChart>("HeatmapChart");
}
[MenuItem("GameObject/XCharts/GaugeChart", priority = 50)]
public static void AddGaugeChart()
{
AddChart<GaugeChart>("GaugeChart");
}
}
}

View File

@@ -2,12 +2,12 @@
A powerful, easy-to-use, configurable charting and data visualization library for Unity.
一款基于`UGUI`的功能强大、易用、参数可配置的数据可视化图表插件。支持折线图、柱状图、饼图、雷达图、散点图、热力图等常见图表。
一款基于`UGUI`的功能强大、易用、参数可配置的数据可视化图表插件。支持折线图、柱状图、饼图、雷达图、散点图、热力图、仪表盘等常见图表。
## 特性
* 内置丰富示例和模板,参数可视化配置,效果实时预览,纯代码绘制。
* 支持折线图、柱状图、饼图、雷达图、散点图、热力图等常见图表。
* 支持折线图、柱状图、饼图、雷达图、散点图、热力图、仪表盘等常见图表。
* 支持直线图、曲线图、面积图、阶梯线图等折线图。
* 支持并列柱图、堆叠柱图、堆积百分比柱图、斑马柱图等柱状图。
* 支持环形图、玫瑰图等饼图。

View File

@@ -258,10 +258,14 @@ namespace XCharts
/// <param name="serieName">the name of serie</param>
/// <param name="dataIndex">the index of data</param>
/// <param name="value">the data will be update</param>
public virtual void UpdateData(string serieName, int dataIndex, float value)
public virtual bool UpdateData(string serieName, int dataIndex, float value)
{
m_Series.UpdateData(serieName, dataIndex, value);
RefreshChart();
if (m_Series.UpdateData(serieName, dataIndex, value))
{
RefreshChart();
return true;
}
return false;
}
/// <summary>
@@ -271,10 +275,80 @@ namespace XCharts
/// <param name="serieIndex">the index of serie</param>
/// <param name="dataIndex">the index of data</param>
/// <param name="value">the data will be update</param>
public virtual void UpdateData(int serieIndex, int dataIndex, float value)
public virtual bool UpdateData(int serieIndex, int dataIndex, float value)
{
m_Series.UpdateData(serieIndex, dataIndex, value);
RefreshChart();
if (m_Series.UpdateData(serieIndex, dataIndex, value))
{
RefreshChart();
return true;
}
return false;
}
/// <summary>
/// 更新指定系列指定索引的数据项的多维数据。
/// </summary>
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="multidimensionalData">一个数据项的多维数据列表,而不是多个数据项的数据</param>
public virtual bool UpdateData(string serieName, int dataIndex, List<float> multidimensionalData)
{
if (m_Series.UpdateData(serieName, dataIndex, multidimensionalData))
{
RefreshChart();
return true;
}
return false;
}
/// <summary>
/// 更新指定系列指定索引的数据项的多维数据。
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="multidimensionalData">一个数据项的多维数据列表,而不是多个数据项的数据</param>
public virtual bool UpdateData(int serieIndex, int dataIndex, List<float> multidimensionalData)
{
if (m_Series.UpdateData(serieIndex, dataIndex, multidimensionalData))
{
RefreshChart();
return true;
}
return false;
}
/// <summary>
/// 更新指定系列指定索引指定维数的数据。维数从0开始。
/// </summary>
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="dimension">指定维数从0开始</param>
/// <param name="value"></param>
public virtual bool UpdateData(string serieName, int dataIndex, int dimension, float value)
{
if (m_Series.UpdateData(serieName, dataIndex, dimension, value))
{
RefreshChart();
return true;
}
return false;
}
/// <summary>
/// 更新指定系列指定索引指定维数的数据。维数从0开始。
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="dimension">指定维数从0开始</param>
/// <param name="value"></param>
public virtual bool UpdateData(int serieIndex, int dataIndex, int dimension, float value)
{
if (m_Series.UpdateData(serieIndex, dataIndex, dimension, value))
{
RefreshChart();
return true;
}
return false;
}
/// <summary>
@@ -284,9 +358,9 @@ namespace XCharts
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="dataName"></param>
public virtual void UpdateDataName(string serieName, int dataIndex, string dataName)
public virtual bool UpdateDataName(string serieName, int dataIndex, string dataName)
{
m_Series.UpdateDataName(serieName, dataIndex, dataName);
return m_Series.UpdateDataName(serieName, dataIndex, dataName);
}
/// <summary>
@@ -296,9 +370,9 @@ namespace XCharts
/// <param name="serieIndex"></param>
/// <param name="dataName"></param>
/// <param name="dataIndex"></param>
public virtual void UpdateDataName(int serieIndex, int dataIndex, string dataName)
public virtual bool UpdateDataName(int serieIndex, int dataIndex, string dataName)
{
m_Series.UpdateDataName(serieIndex, dataIndex, dataName);
return m_Series.UpdateDataName(serieIndex, dataIndex, dataName);
}
/// <summary>
@@ -422,15 +496,15 @@ namespace XCharts
/// <summary>
/// Update chart theme info.
/// 切换图表主题。
/// </summary>
/// <param name="info">info</param>
public void UpdateThemeInfo(ThemeInfo info)
/// <param name="themeInfo">themeInfo</param>
public void UpdateThemeInfo(ThemeInfo themeInfo)
{
m_ThemeInfo = info;
m_ThemeInfo = themeInfo;
UpdateTheme(m_ThemeInfo.theme);
}
/// <summary>
/// Whether series animation enabel.
/// 启用或关闭起始动画。

View File

@@ -208,12 +208,52 @@ namespace XCharts
/// the current minimun value.
/// 当前最小值。
/// </summary>
public float runtimeMinValue { get; internal set; }
public float runtimeMinValue
{
get { return m_RuntimeMinValue; }
internal set
{
if (value != m_RuntimeMinValue)
{
if (m_RuntimeMinValueFirstChanged)
{
m_RuntimeMinValueFirstChanged = false;
}
else
{
m_RuntimeLastMinValue = m_RuntimeMinValue;
m_RuntimeMinValueChanged = true;
m_RuntimeMinValueUpdateTime = Time.time;
}
m_RuntimeMinValue = value;
}
}
}
/// <summary>
/// the current maximum value.
/// 当前最大值。
/// </summary>
public float runtimeMaxValue { get; internal set; }
public float runtimeMaxValue
{
get { return m_RuntimeMaxValue; }
internal set
{
if (value != m_RuntimeMaxValue)
{
if (m_RuntimeMaxValueFirstChanged)
{
m_RuntimeMaxValueFirstChanged = false;
}
else
{
m_RuntimeLastMaxValue = m_RuntimeMaxValue;
m_RuntimeMaxValueChanged = true;
m_RuntimeMaxValueUpdateTime = Time.time;
}
m_RuntimeMaxValue = value;
}
}
}
/// <summary>
/// the x offset of zero position.
/// 坐标轴原点在X轴的偏移。
@@ -232,6 +272,16 @@ namespace XCharts
private GameObject m_TooltipLabel;
private Text m_TooltipLabelText;
private RectTransform m_TooltipLabelRect;
private float m_RuntimeMinValue;
private float m_RuntimeLastMinValue;
private bool m_RuntimeMinValueChanged;
private float m_RuntimeMinValueUpdateTime;
private float m_RuntimeMaxValue;
private float m_RuntimeLastMaxValue;
private bool m_RuntimeMaxValueChanged;
private float m_RuntimeMaxValueUpdateTime;
private bool m_RuntimeMinValueFirstChanged = true;
private bool m_RuntimeMaxValueFirstChanged = true;
public void Copy(Axis other)
{
@@ -445,6 +495,7 @@ namespace XCharts
int split = GetSplitNumber(coordinateWidth, dataZoom);
if (m_Type == AxisType.Value)
{
if (minValue == 0 && maxValue == 0) return string.Empty;
float value = 0;
if (forcePercent) maxValue = 100;
if (m_Interval > 0)
@@ -528,13 +579,15 @@ namespace XCharts
/// 更新刻度标签文字
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateLabelText(float coordinateWidth, DataZoom dataZoom, bool forcePercent)
internal void UpdateLabelText(float coordinateWidth, DataZoom dataZoom, bool forcePercent, float duration)
{
var minValue = GetCurrMinValue(duration);
var maxValue = GetCurrMaxValue(duration);
for (int i = 0; i < axisLabelTextList.Count; i++)
{
if (axisLabelTextList[i] != null)
{
axisLabelTextList[i].text = GetLabelName(coordinateWidth, i, runtimeMinValue, runtimeMaxValue, dataZoom, forcePercent);
axisLabelTextList[i].text = GetLabelName(coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent);
}
}
}
@@ -583,6 +636,7 @@ namespace XCharts
{
if (!show) return false;
if (IsCategory() && data.Count <= 0) return false;
else if (IsValue() && m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return false;
else return true;
}
@@ -591,7 +645,7 @@ namespace XCharts
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
internal void AdjustMinMaxValue(ref float minValue, ref float maxValue)
internal void AdjustMinMaxValue(ref float minValue, ref float maxValue, bool needFormat)
{
if (minMaxType == Axis.AxisMinMaxType.Custom)
{
@@ -606,31 +660,82 @@ namespace XCharts
switch (minMaxType)
{
case Axis.AxisMinMaxType.Default:
if (minValue > 0 && maxValue > 0)
if (minValue == 0 && maxValue == 0)
{
}
else if (minValue > 0 && maxValue > 0)
{
minValue = 0;
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
}
else if (minValue < 0 && maxValue < 0)
{
minValue = ChartHelper.GetMinDivisibleValue(minValue);
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = 0;
}
else
{
minValue = ChartHelper.GetMinDivisibleValue(minValue);
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
}
break;
case Axis.AxisMinMaxType.MinMax:
minValue = ChartHelper.GetMinDivisibleValue(minValue);
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
break;
}
}
m_ValueRange = maxValue - minValue;
}
internal float GetCurrMinValue(float duration)
{
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMinValueChanged) return m_RuntimeMinValue;
var time = Time.time - m_RuntimeMinValueUpdateTime;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
var curr = Mathf.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total);
return curr;
}
else
{
m_RuntimeMinValueChanged = false;
return m_RuntimeMinValue;
}
}
internal float GetCurrMaxValue(float duration)
{
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMaxValueChanged) return m_RuntimeMaxValue;
var time = Time.time - m_RuntimeMaxValueUpdateTime;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
return curr;
}
else
{
m_RuntimeMaxValueChanged = false;
return m_RuntimeMaxValue;
}
}
public bool IsValueChanging(float duration)
{
if (GetCurrMinValue(duration) != m_RuntimeMinValue || GetCurrMaxValue(duration) != m_RuntimeMaxValue)
{
return true;
}
else
{
return false;
}
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))

View File

@@ -48,6 +48,10 @@ namespace XCharts
/// 热力图。主要通过颜色去表现数值的大小,必须要配合 visualMap 组件使用。
/// </summary>
Heatmap,
/// <summary>
/// 仪表盘。
/// </summary>
Gauge,
}
/// <summary>
@@ -142,6 +146,21 @@ namespace XCharts
Capsule
}
/// <summary>
/// 仪表盘类型
/// </summary>
public enum GaugeType
{
/// <summary>
/// 指针型
/// </summary>
Pointer,
/// <summary>
/// 进度条型
/// </summary>
ProgressBar
}
/// <summary>
/// 采样类型
/// </summary>
@@ -202,6 +221,16 @@ namespace XCharts
[SerializeField] private float m_BarZebraWidth = 4f;
[SerializeField] private float m_BarZebraGap = 2f;
[SerializeField] private float m_Min;
[SerializeField] private float m_Max;
[SerializeField] private float m_StartAngle;
[SerializeField] private float m_EndAngle;
[SerializeField] private bool m_Clockwise;
[SerializeField] private bool m_ArcShaped;
[SerializeField] private int m_SplitNumber;
[SerializeField] private GaugeType m_GaugeType = GaugeType.Pointer;
[SerializeField] private GaugeAxis m_GaugeAxis = new GaugeAxis();
[SerializeField] private GaugePointer m_GaugePointer = new GaugePointer();
[SerializeField] private bool m_ClickOffset = true;
[SerializeField] private RoseType m_RoseType = RoseType.None;
@@ -213,6 +242,7 @@ namespace XCharts
[SerializeField] private LineArrow m_LineArrow = new LineArrow();
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
[SerializeField] private TitleStyle m_TitleStyle = new TitleStyle();
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
[SerializeField] private bool m_ShowDataName;
[SerializeField] private bool m_ShowDataIcon;
@@ -383,15 +413,59 @@ namespace XCharts
/// </summary>
public float pieSpace { get { return m_Space; } set { m_Space = value; } }
/// <summary>
/// the center of pie chart.
/// 饼图的中心点。
/// the center of chart.
/// 中心点。
/// </summary>
public float[] pieCenter { get { return m_Center; } set { m_Center = value; } }
public float[] center { get { return m_Center; } set { m_Center = value; } }
/// <summary>
/// the radius of pie chart.
/// 饼图的半径。radius[0]表示内径radius[1]表示外径。
/// the radius of chart.
/// 半径。radius[0]表示内径radius[1]表示外径。
/// </summary>
public float[] pieRadius { get { return m_Radius; } set { m_Radius = value; } }
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
[Obsolete("Use Serie.center instead.", true)]
public float[] pieCenter { get { return center; } set { center = value; } }
[Obsolete("Use Serie.radius instead.", true)]
public float[] pieRadius { get { return radius; } set { radius = value; } }
/// <summary>
/// 最小值,映射到 startAngle。
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
/// <summary>
/// 最大值,映射到 endAngle。
/// </summary>
public float max { get { return m_Max; } set { m_Max = value; } }
/// <summary>
/// 起始角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float startAngle { get { return m_StartAngle; } set { m_StartAngle = value; } }
/// <summary>
/// 结束角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float endAngle { get { return m_EndAngle; } set { m_EndAngle = value; } }
/// <summary>
/// 是否顺时针。
/// </summary>
public bool clockwise { get { return m_Clockwise; } set { m_Clockwise = value; } }
/// <summary>
/// 刻度分割段数。
/// </summary>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value > 36 ? 36 : value; } }
/// <summary>
/// 是否开启圆弧形边角。
/// </summary>
public bool arcShaped { get { return m_ArcShaped; } set { m_ArcShaped = value; } }
/// <summary>
/// 仪表盘轴线。
/// </summary>
public GaugeAxis gaugeAxis { get { return m_GaugeAxis; } set { m_GaugeAxis = value; } }
/// <summary>
/// 仪表盘指针。
/// </summary>
public GaugePointer gaugePointer { get { return m_GaugePointer; } set { m_GaugePointer = value; } }
/// <summary>
/// 仪表盘类型。
/// </summary>
public GaugeType gaugeType { get { return m_GaugeType; } set { m_GaugeType = value; } }
/// <summary>
/// Text label of graphic element,to explain some data information about graphic item like value, name and so on.
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
@@ -416,7 +490,15 @@ namespace XCharts
/// 高亮的图形样式和文本标签样式。
/// </summary>
public Emphasis emphasis { get { return m_Emphasis; } set { m_Emphasis = value; } }
/// <summary>
/// 标题样式。
/// </summary>
public TitleStyle titleStyle { get { return m_TitleStyle; } set { m_TitleStyle = value; } }
/// <summary>
/// 数据项里的数据维数。
/// </summary>
/// <value></value>
public int showDataDimension { get { return m_ShowDataDimension; } }
/// <summary>
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
/// </summary>
@@ -444,15 +526,15 @@ namespace XCharts
/// <summary>
/// 饼图的中心点位置。
/// </summary>
public Vector3 runtimePieCenterPos { get; internal set; }
public Vector3 runtimeCenterPos { get; internal set; }
/// <summary>
/// 饼图的内径
/// </summary>
public float runtimePieInsideRadius { get; internal set; }
public float runtimeInsideRadius { get; internal set; }
/// <summary>
/// 饼图的外径
/// </summary>
public float runtimePieOutsideRadius { get; internal set; }
public float runtimeOutsideRadius { get; internal set; }
/// <summary>
/// 饼图的数据项最大值
/// </summary>
@@ -461,6 +543,7 @@ namespace XCharts
/// 饼图的数据项之和
/// </summary>
public float runtimePieDataTotal { get; internal set; }
internal int runtimeLastCheckDataCount { get; set; }
internal List<Vector3> GetUpSmoothList(int dataIndex, int size = 100)
{
@@ -589,7 +672,7 @@ namespace XCharts
foreach (var sdata in data)
{
if (sdata.show)
total += sdata.data[1];
total += sdata.GetCurrData(1, animation.GetUpdateAnimationDuration());
}
return total;
}
@@ -645,9 +728,15 @@ namespace XCharts
}
}
int xValue = m_Data.Count;
var serieData = new SerieData() { data = new List<float>() { xValue, value }, name = dataName };
var serieData = new SerieData()
{
data = new List<float>() { xValue, value },
lastData = new List<float>() { xValue, value },
name = dataName
};
serieData.index = xValue;
m_Data.Add(serieData);
m_ShowDataDimension = 1;
return serieData;
}
@@ -668,9 +757,15 @@ namespace XCharts
m_Data.RemoveAt(0);
}
}
var serieData = new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName };
var serieData = new SerieData()
{
data = new List<float>() { xValue, yValue },
lastData = new List<float>() { xValue, yValue },
name = dataName
};
serieData.index = m_Data.Count;
m_Data.Add(serieData);
m_ShowDataDimension = 2;
return serieData;
}
@@ -702,12 +797,14 @@ namespace XCharts
m_Data.RemoveAt(0);
}
}
m_ShowDataDimension = valueList.Count;
var serieData = new SerieData();
serieData.name = dataName;
serieData.index = m_Data.Count;
for (int i = 0; i < valueList.Count; i++)
{
serieData.data.Add(valueList[i]);
serieData.lastData.Add(valueList[i]);
}
m_Data.Add(serieData);
return serieData;
@@ -731,6 +828,17 @@ namespace XCharts
return 0;
}
public float GetYCurrData(int index, DataZoom dataZoom = null)
{
if (index < 0) return 0;
var serieData = GetDataList(dataZoom);
if (index < serieData.Count)
{
return serieData[index].GetCurrData(1, animation.GetUpdateAnimationDuration());
}
return 0;
}
/// <summary>
/// 获得维度Y索引对应的数据和数据名
/// </summary>
@@ -767,6 +875,24 @@ namespace XCharts
return null;
}
/// <summary>
/// 获得指定索引的数据项的Label
/// </summary>
/// <param name="index"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public SerieLabel GetSerieLabel(int index, DataZoom dataZoom = null)
{
var data = GetDataList(dataZoom);
if (index >= 0 && index <= data.Count - 1)
{
var serieData = data[index];
if (serieData.enableLabel) return serieData.label;
else return label;
}
return null;
}
/// <summary>
/// 获得指定索引的维度X和维度Y的数据
/// </summary>
@@ -869,9 +995,10 @@ namespace XCharts
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
public void UpdateYData(int index, float value)
public bool UpdateYData(int index, float value)
{
UpdateData(index, 1, value);
return true;
}
/// <summary>
@@ -880,10 +1007,11 @@ namespace XCharts
/// <param name="index"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
public void UpdateXYData(int index, float xValue, float yValue)
public bool UpdateXYData(int index, float xValue, float yValue)
{
UpdateData(index, 0, xValue);
UpdateData(index, 1, yValue);
var flag1 = UpdateData(index, 0, xValue);
var flag2 = UpdateData(index, 1, yValue);
return flag1 || flag2;
}
/// <summary>
@@ -892,16 +1020,36 @@ namespace XCharts
/// <param name="index">要更新数据的索引</param>
/// <param name="dimension">要更新数据的维数</param>
/// <param name="value">新的数据值</param>
public void UpdateData(int index, int dimension, float value)
public bool UpdateData(int index, int dimension, float value)
{
if (index < 0) return;
if (index < m_Data.Count && dimension < m_Data[index].data.Count)
if (index >= 0 && index < m_Data.Count)
{
m_Data[index].data[dimension] = value;
return m_Data[index].UpdateData(dimension, value);
}
else
{
return false;
}
}
public void UpdateDataName(int index, string name)
/// <summary>
/// 更新指定索引的数据项数据列表
/// </summary>
/// <param name="index"></param>
/// <param name="values"></param>
public bool UpdateData(int index, List<float> values)
{
if (index >= 0 && index < m_Data.Count && values != null)
{
var list = m_Data[index].data;
list.Clear();
foreach (var v in values) list.Add(v);
return true;
}
return false;
}
public bool UpdateDataName(int index, string name)
{
if (index >= 0 && index < m_Data.Count)
{
@@ -911,7 +1059,9 @@ namespace XCharts
{
serieData.labelText.text = name == null ? "" : name;
}
return true;
}
return false;
}
/// <summary>
@@ -1027,7 +1177,7 @@ namespace XCharts
{
foreach (var data in m_Data)
{
data.showIcon = flag;
data.iconStyle.show = flag;
}
}
@@ -1041,7 +1191,7 @@ namespace XCharts
if (dataIndex >= 0 && dataIndex < m_Data.Count)
{
var data = m_Data[dataIndex];
data.showIcon = flag;
data.iconStyle.show = flag;
}
}
@@ -1054,8 +1204,8 @@ namespace XCharts
{
foreach (var data in m_Data)
{
data.iconWidth = width;
data.iconHeight = height;
data.iconStyle.width = width;
data.iconStyle.height = height;
}
}
@@ -1069,7 +1219,7 @@ namespace XCharts
if (dataIndex >= 0 && dataIndex < m_Data.Count)
{
var data = m_Data[dataIndex];
data.iconImage = image;
data.iconStyle.sprite = image;
}
}
@@ -1077,11 +1227,27 @@ namespace XCharts
{
foreach (var data in m_Data)
{
if (data.showIcon) return true;
if (data.iconStyle.show) return true;
}
return false;
}
/// <summary>
/// 更新运行时中心点和半径
/// </summary>
/// <param name="chartWidth"></param>
/// <param name="chartHeight"></param>
internal void UpdateCenter(float chartWidth, float chartHeight)
{
if (center.Length < 2) return;
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
runtimeCenterPos = new Vector2(centerX, centerY);
var minWidth = Mathf.Min(chartWidth, chartHeight);
runtimeInsideRadius = radius[0] <= 1 ? minWidth * radius[0] : radius[0];
runtimeOutsideRadius = radius[1] <= 1 ? minWidth * radius[1] : radius[1];
}
/// <summary>
/// 设置指定index的数据图标的尺寸
/// </summary>
@@ -1093,8 +1259,8 @@ namespace XCharts
if (dataIndex >= 0 && dataIndex < m_Data.Count)
{
var data = m_Data[dataIndex];
data.iconWidth = width;
data.iconHeight = height;
data.iconStyle.width = width;
data.iconStyle.height = height;
}
}
@@ -1108,7 +1274,7 @@ namespace XCharts
if (dataIndex >= 0 && dataIndex < m_Data.Count)
{
var data = m_Data[dataIndex];
data.iconColor = color;
data.iconStyle.color = color;
}
}

View File

@@ -81,6 +81,18 @@ namespace XCharts
}
}
public float GetCurrData(int serieIndex, int dataIndex)
{
if (serieIndex >= 0 && serieIndex < Count)
{
return m_Series[serieIndex].GetYCurrData(dataIndex);
}
else
{
return 0;
}
}
/// <summary>
/// 获得指定系列名的第一个系列
/// </summary>
@@ -167,6 +179,18 @@ namespace XCharts
return false;
}
internal bool IsAnyUpdateAnimationSerie()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable && serie.animation.updateAnimation)
{
return true;
}
}
return false;
}
/// <summary>
/// 获得上一个同堆叠且显示的serie。
/// </summary>
@@ -370,13 +394,14 @@ namespace XCharts
/// <param name="name"></param>
/// <param name="value"></param>
/// <param name="dataIndex"></param>
public void UpdateData(string serieName, int dataIndex, float value)
public bool UpdateData(string serieName, int dataIndex, float value)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.UpdateYData(dataIndex, value);
return serie.UpdateYData(dataIndex, value);
}
return false;
}
/// <summary>
@@ -385,13 +410,14 @@ namespace XCharts
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="dataName"></param>
public void UpdateDataName(string serieName, int dataIndex, string dataName)
public bool UpdateDataName(string serieName, int dataIndex, string dataName)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.UpdateDataName(dataIndex, dataName);
return serie.UpdateDataName(dataIndex, dataName);
}
return false;
}
/// <summary>
@@ -400,13 +426,14 @@ namespace XCharts
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="dataName"></param>
public void UpdateDataName(int serieIndex, int dataIndex, string dataName)
public bool UpdateDataName(int serieIndex, int dataIndex, string dataName)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
serie.UpdateDataName(dataIndex, dataName);
return serie.UpdateDataName(dataIndex, dataName);
}
return false;
}
/// <summary>
@@ -415,13 +442,65 @@ namespace XCharts
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="value"></param>
public void UpdateData(int serieIndex, int dataIndex, float value)
public bool UpdateData(int serieIndex, int dataIndex, float value)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
serie.UpdateYData(dataIndex, value);
return serie.UpdateYData(dataIndex, value);
}
return false;
}
public bool UpdateData(string serieName,int dataIndex,List<float> values){
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateData(dataIndex, values);
}
return false;
}
public bool UpdateData(int serieIndex,int dataIndex,List<float> values){
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateData(dataIndex, values);
}
return false;
}
/// <summary>
/// 更新指定系列指定数据项指定维度的数据值
/// </summary>
/// <param name="serieIndex">系列</param>
/// <param name="dataIndex">数据项</param>
/// <param name="dimension">数据维数从0开始</param>
/// <param name="value">值</param>
public bool UpdateData(int serieIndex, int dataIndex, int dimension, float value)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
return serie.UpdateData(dataIndex, dimension, value);
}
return false;
}
/// <summary>
/// 更新指定系列指定数据项指定维度的数据值
/// </summary>
/// <param name="serieName"></param>
/// <param name="dataIndex"></param>
/// <param name="dimension">数据维数从0开始</param>
/// <param name="value"></param>
public bool UpdateData(string serieName, int dataIndex, int dimension, float value)
{
var serie = GetSerie(serieName);
if (serie != null)
{
return serie.UpdateData(dataIndex, dimension, value);
}
return false;
}
@@ -432,13 +511,14 @@ namespace XCharts
/// <param name="dataIndex"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
public void UpdateXYData(string serieName, int dataIndex, float xValue, float yValue)
public bool UpdateXYData(string serieName, int dataIndex, float xValue, float yValue)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.UpdateXYData(dataIndex, xValue, yValue);
return serie.UpdateXYData(dataIndex, xValue, yValue);
}
return false;
}
/// <summary>
@@ -448,13 +528,14 @@ namespace XCharts
/// <param name="dataIndex"></param>
/// <param name="xValue"></param>
/// <param name="yValue"></param>
public void UpdateXYData(int serieIndex, int dataIndex, float xValue, float yValue)
public bool UpdateXYData(int serieIndex, int dataIndex, float xValue, float yValue)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
serie.UpdateXYData(dataIndex, xValue, yValue);
return serie.UpdateXYData(dataIndex, xValue, yValue);
}
return false;
}
/// <summary>
@@ -603,8 +684,9 @@ namespace XCharts
{
if (yValue)
{
if (data.data[1] > max) max = data.data[1];
if (data.data[1] < min) min = data.data[1];
var currData = data.GetData(1);
if (currData > max) max = currData;
if (currData < min) min = currData;
}
else
{
@@ -641,7 +723,7 @@ namespace XCharts
if (!_serieTotalValueForMinMax.ContainsKey(j))
_serieTotalValueForMinMax[j] = 0;
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] +
(yValue ? showData[j].data[1] : showData[i].data[0]);
(yValue ? showData[j].GetData(1) : showData[i].data[0]);
}
}
@@ -668,7 +750,9 @@ namespace XCharts
{
minVaule = Mathf.FloorToInt(min);
maxValue = Mathf.CeilToInt(max);
}else{
}
else
{
minVaule = min;
maxValue = max;
}

View File

@@ -19,11 +19,11 @@ namespace XCharts
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Text;
[SerializeField] private int m_TextFontSize;
[SerializeField] private TextStyle m_TextStyle = new TextStyle(16);
[SerializeField] private string m_SubText;
[SerializeField] private int m_SubTextFontSize;
[SerializeField] private float m_ItemGap;
[SerializeField] private Location m_Location;
[SerializeField] private TextStyle m_SubTextStyle = new TextStyle(14);
[SerializeField] private float m_ItemGap = 8;
[SerializeField] private Location m_Location = Location.defaultTop;
/// <summary>
/// [default:true]
@@ -41,20 +41,30 @@ namespace XCharts
/// main title font size.
/// 主标题文字的字体大小。
/// </summary>
public int textFontSize { get { return m_TextFontSize; } set { m_TextFontSize = value; } }
[Obsolete("use textStyle instead.", false)]
public int textFontSize { get { return m_TextStyle.fontSize; } set { m_TextStyle.fontSize = value; } }
/// <summary>
/// 主标题文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
/// <summary>
/// Subtitle text, supporting for \n for newlines.
/// 副标题文本,支持使用 \n 换行。
/// </summary>
public string subText { get { return m_SubText; } set { m_SubText = value; } }
/// <summary>
/// 副标题文本样式。
/// </summary>
public TextStyle subTextStyle { get { return m_SubTextStyle; } set { m_SubTextStyle = value; } }
/// <summary>
/// [default:14]
/// subtitle font size.
/// 副标题文字的字体大小。
/// </summary>
public int subTextFontSize { get { return m_SubTextFontSize; } set { m_SubTextFontSize = value; } }
[Obsolete("use subTextStyle instead.", false)]
public int subTextFontSize { get { return m_SubTextStyle.fontSize; } set { m_SubTextStyle.fontSize = value; } }
/// <summary>
/// [default:14]
/// [default:8]
/// The gap between the main title and subtitle.
/// 主副标题之间的间距。
/// </summary>
@@ -73,9 +83,9 @@ namespace XCharts
{
m_Show = true,
m_Text = "Chart Title",
m_TextFontSize = 16,
m_TextStyle = new TextStyle(16),
m_SubText = "",
m_SubTextFontSize = 14,
m_SubTextStyle = new TextStyle(14),
m_ItemGap = 8,
m_Location = Location.defaultTop
};
@@ -86,9 +96,9 @@ namespace XCharts
{
m_Show = title.show;
m_Text = title.text;
m_TextFontSize = title.textFontSize;
m_TextStyle.Copy(title.textStyle);
m_SubTextStyle.Copy(title.subTextStyle);
m_SubText = title.subText;
m_SubTextFontSize = title.subTextFontSize;
m_ItemGap = title.itemGap;
m_Location.Copy(title.location);
}
@@ -117,9 +127,9 @@ namespace XCharts
}
return m_Show == other.show &&
m_Text.Equals(other.text) &&
m_TextFontSize == other.textFontSize &&
m_TextStyle.Equals(other.textStyle) &&
m_SubText.Equals(other.subText) &&
m_SubTextFontSize == other.subTextFontSize &&
m_SubTextStyle.Equals(other.subTextStyle) &&
m_ItemGap == other.itemGap &&
m_Location.Equals(other.location);
}

View File

@@ -154,7 +154,8 @@ namespace XCharts
{
int minAcc = ChartHelper.GetFloatAccuracy(minValue);
int maxAcc = ChartHelper.GetFloatAccuracy(maxValue);
int acc = Mathf.Max(minAcc, maxAcc);
int curAcc = ChartHelper.GetFloatAccuracy(value);
int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc);
return ChartCached.FloatToStr(value, acc, m_ForceENotation);
}
else if (value - (int)value == 0)
@@ -162,7 +163,7 @@ namespace XCharts
else
return ChartCached.FloatToStr(value, 1);
}
else
else if (m_Formatter.Contains("{value"))
{
var content = m_Formatter;
if (content.Contains("{value:f2}"))
@@ -182,6 +183,10 @@ namespace XCharts
content = content.Replace("<br/>", "\n");
return content;
}
else
{
return value.ToString(m_Formatter);
}
}
}
}

View File

@@ -0,0 +1,305 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge axis line.
/// 仪表盘轴线相关设置。
/// </summary>
[System.Serializable]
public class GaugeAxis : SubComponent
{
[System.Serializable]
public class AxisLine
{
[System.Serializable]
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
public float percent { get { return m_Percent; } set { m_Percent = value; } }
/// <summary>
/// 颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color color)
{
m_Percent = percent;
m_Color = color;
}
}
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Width = 15f;
[SerializeField] private float m_Opacity = 1f;
[SerializeField] private Color m_BarColor;
[SerializeField] private Color m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// line style line width.
/// 坐标轴线线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// The opacity of axis line.
/// 透明度。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
/// <summary>
/// 进度条颜色。
/// </summary>
public Color barColor { get { return m_BarColor; } set { m_BarColor = value; } }
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
}
/// <summary>
/// 分割线
/// </summary>
[System.Serializable]
public class SplitLine
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 15;
[SerializeField]
private LineStyle m_LineStyle = new LineStyle()
{
width = 1.5f,
type = LineStyle.Type.Solid,
color = new Color32(238, 238, 238, 255)
};
/// <summary>
/// 是否显示分割线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 分割线长度。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 分割线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
}
/// <summary>
/// 刻度
/// </summary>
[System.Serializable]
public class AxisTick
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 5;
[SerializeField] private float m_SplitNumber = 5;
[SerializeField]
private LineStyle m_LineStyle = new LineStyle()
{
width = 1f,
type = LineStyle.Type.Solid,
color = new Color32(238, 238, 238, 255)
};
/// <summary>
/// 是否显示刻度。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 刻度长度。当为0-1的浮点数时表示半径的百分比。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 分割线之间的分割段数。
/// </summary>
public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
/// <summary>
/// 刻度线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
}
[SerializeField] private bool m_Show = true;
[SerializeField] private AxisLine m_AxisLine = new AxisLine();
[SerializeField] private SplitLine m_SplitLine = new SplitLine();
[SerializeField] private AxisTick m_AxisTick = new AxisTick();
[SerializeField] private SerieLabel m_AxisLabel = new SerieLabel();
[SerializeField] private List<string> m_AxisLabelText = new List<string>();
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 仪表盘轴线。
/// </summary>
public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
/// <summary>
/// 分割线。
/// </summary>
public SplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
/// <summary>
/// 刻度。
/// </summary>
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
/// <summary>
/// 文本标签。
/// </summary>
public SerieLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
/// <summary>
/// 自定义Label的内容。
/// </summary>
public List<string> axisLabelText { get { return m_AxisLabelText; } set { m_AxisLabelText = value; } }
public List<float> runtimeStageAngle = new List<float>();
public List<Vector3> runtimeLabelPosition = new List<Vector3>();
private List<LabelObject> m_RuntimeLabelList = new List<LabelObject>();
internal Color GetAxisLineColor(ThemeInfo theme, int index)
{
var color = axisLine.barColor != Color.clear ? axisLine.barColor : (Color)theme.GetColor(index);
color.a *= axisLine.opacity;
return color;
}
internal Color GetAxisLineBackgroundColor(ThemeInfo theme, int index)
{
var color = axisLine.barBackgroundColor != Color.clear ? axisLine.barBackgroundColor : Color.grey;
color.a *= axisLine.opacity;
return color;
}
internal Color GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
{
Color color;
if (splitLine.lineStyle.color != Color.clear)
{
color = splitLine.lineStyle.color;
color.a *= splitLine.lineStyle.opacity;
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= splitLine.lineStyle.opacity;
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= splitLine.lineStyle.opacity;
return color;
}
internal Color GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
{
Color color;
if (axisTick.lineStyle.color != Color.clear)
{
color = axisTick.lineStyle.color;
color.a *= axisTick.lineStyle.opacity;
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= axisTick.lineStyle.opacity;
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= axisTick.lineStyle.opacity;
return color;
}
internal Color GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
{
Color color;
if (itemStyle.color != Color.clear)
{
color = itemStyle.color;
color.a *= itemStyle.opacity;
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= itemStyle.opacity;
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= itemStyle.opacity;
return color;
}
public void ClearLabelObject()
{
m_RuntimeLabelList.Clear();
}
public void AddLabelObject(LabelObject label)
{
m_RuntimeLabelList.Add(label);
}
public LabelObject GetLabelObject(int index)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
return m_RuntimeLabelList[index];
}
return null;
}
public void SetLabelObjectPosition(int index, Vector3 pos)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
m_RuntimeLabelList[index].SetPosition(pos);
}
}
public void SetLabelObjectText(int index, string text)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
m_RuntimeLabelList[index].SetText(text);
}
}
public void SetLabelObjectActive(bool flag)
{
foreach (var label in m_RuntimeLabelList)
{
label.SetActive(flag);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67cba46d89b9b478fa6dcf067e7b49b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge pointer.
/// 仪表盘指针相关设置。
/// </summary>
[System.Serializable]
public class GaugePointer : SubComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 0.8f;
[SerializeField] private float m_Width = 15;
/// <summary>
/// 是否显示指针。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 指针长度。可以是绝对值也可以是相对于半径的百分比0-1的浮点数
/// </summary>
/// <value></value>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 指针宽度。
/// </summary>
/// <value></value>
public float width { get { return m_Width; } set { m_Width = value; } }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55e453b57f6514da09e98571439d4dcc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// 系列数据项的图标
/// </summary>
[System.Serializable]
public class IconStyle : SubComponent
{
public enum Layer
{
UnderLabel,
AboveLabel
}
[SerializeField] private bool m_Show;
[SerializeField] private Layer m_Layer;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 40;
[SerializeField] private float m_Height = 40;
[SerializeField] private Vector3 m_Offset;
/// <summary>
/// Whether the data icon is show.
/// 是否显示图标。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; UpdateIcon(); } }
/// <summary>
/// 显示在上层还是在下层。
/// </summary>
public Layer layer { get { return m_Layer; } set { m_Layer = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
/// <summary>
/// 图标偏移。
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
public Image image { get; private set; }
public RectTransform rect { get; private set; }
public void SetImage(Image image)
{
this.image = image;
if (image)
{
rect = image.GetComponent<RectTransform>();
if (m_Layer == Layer.UnderLabel)
rect.SetSiblingIndex(0);
else
rect.SetSiblingIndex(image.transform.childCount - 1);
UpdateIcon();
}
}
public void SetActive(bool flag)
{
if (image)
{
ChartHelper.SetActive(image.gameObject, flag);
}
}
public void UpdateIcon()
{
if (image == null) return;
if (show)
{
ChartHelper.SetActive(image.gameObject, true);
image.sprite = m_Sprite;
image.color = m_Color;
rect.sizeDelta = new Vector2(m_Width, m_Height);
image.transform.localPosition = m_Offset;
}
else
{
ChartHelper.SetActive(image.gameObject, false);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82c4d360f7b5b4ee7845e9bbe611c8a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -23,10 +23,12 @@ namespace XCharts
}
[SerializeField] private bool m_Enable = true;
[SerializeField] private Easing m_Easting;
[SerializeField] private int m_Duration = 1000;
[SerializeField] private float m_Duration = 1000;
[SerializeField] private int m_Threshold = 2000;
[SerializeField] private int m_Delay = 0;
[SerializeField] private int m_ActualDuration;
[SerializeField] private float m_Delay = 0;
[SerializeField] private bool m_UpdateAnimation = true;
[SerializeField] private float m_UpdateDuration = 500;
[SerializeField] private float m_ActualDuration;
/// <summary>
/// Whether to enable animation.
@@ -42,12 +44,12 @@ namespace XCharts
/// The milliseconds duration of the first animation.
/// 设定的动画时长(毫秒)。
/// </summary>
public int duration { get { return m_Duration; } set { m_Duration = value; } }
public float duration { get { return m_Duration; } set { m_Duration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。
/// </summary>
public int actualDuration { get { return m_ActualDuration; } }
public float actualDuration { get { return m_ActualDuration; } }
/// <summary>
/// Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.
/// 是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
@@ -57,7 +59,16 @@ namespace XCharts
/// The milliseconds delay before updating the first animation.
/// 动画延时(毫秒)。
/// </summary>
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
public float delay { get { return m_Delay; } set { m_Delay = value < 0 ? 0 : value; } }
/// <summary>
/// 是否开启数据变更动画。
/// </summary>
public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// 数据变更的动画时长(毫秒)。
/// </summary>
public float updateDuration { get { return m_UpdateDuration; } set { m_UpdateDuration = value < 0 ? 0 : value; } }
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
private bool m_IsStart = false;
@@ -147,7 +158,7 @@ namespace XCharts
#if UNITY_EDITOR
if (!Application.isPlaying) return true;
#endif
return !enable || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress);
return !enable || m_IsEnd || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress);
}
public bool IsInDelay()
@@ -232,5 +243,11 @@ namespace XCharts
{
return m_CurrDataProgress;
}
public float GetUpdateAnimationDuration()
{
if (m_Enable && m_UpdateAnimation && IsFinish()) return m_UpdateDuration;
else return 0;
}
}
}

View File

@@ -9,6 +9,7 @@ using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
namespace XCharts
{
@@ -22,13 +23,9 @@ namespace XCharts
[SerializeField] private string m_Name;
[SerializeField] private bool m_Selected;
[SerializeField] private float m_Radius;
[SerializeField] private bool m_ShowIcon;
[SerializeField] private Sprite m_IconImage;
[SerializeField] private Color m_IconColor = Color.white;
[SerializeField] private float m_IconWidth = 40;
[SerializeField] private float m_IconHeight = 40;
[SerializeField] private Vector3 m_IconOffset;
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
[SerializeField] private bool m_EnableLabel = false;
[SerializeField] private SerieLabel m_Label = new SerieLabel();
[SerializeField] private List<float> m_Data = new List<float>();
private bool m_Show = true;
@@ -58,32 +55,18 @@ namespace XCharts
/// </summary>
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
/// <summary>
/// Whether the data icon is show.
/// 是否显示图标
/// the icon of data.
/// 数据项图标样式
/// </summary>
public bool showIcon { get { return m_ShowIcon; } set { m_ShowIcon = value; } }
public IconStyle iconStyle { get { return m_IconStyle; } set { m_IconStyle = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// 是否启用单个数据项的标签设置。
/// </summary>
public Sprite iconImage { get { return m_IconImage; } set { m_IconImage = value; } }
public bool enableLabel { get { return m_EnableLabel; } set { m_EnableLabel = value; } }
/// <summary>
/// 图标颜色
/// 单个数据项的标签设置
/// </summary>
public Color iconColor { get { return m_IconColor; } set { m_IconColor = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float iconWidth { get { return m_IconWidth; } set { m_IconWidth = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float iconHeight { get { return m_IconHeight; } set { m_IconHeight = value; } }
/// <summary>
/// 图标偏移。
/// </summary>
public Vector3 iconOffset { get { return m_IconOffset; } set { m_IconOffset = value; } }
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
/// <summary>
/// An arbitrary dimension data list of data item.
/// 可指定任意维数的数值列表。
@@ -109,7 +92,7 @@ namespace XCharts
/// 标志位置。
/// </summary>
public Vector3 labelPosition { get; set; }
public bool m_CanShowLabel = true;
private bool m_CanShowLabel = true;
/// <summary>
/// 是否可以显示Label
/// </summary>
@@ -124,8 +107,7 @@ namespace XCharts
/// 最小值。
/// </summary>
public float min { get { return m_Data.Min(); } }
public Image icon { get; private set; }
public RectTransform iconRect { get; private set; }
/// <summary>
/// 关联的gameObject
/// </summary>
@@ -171,12 +153,88 @@ namespace XCharts
public float runtimePieOffsetRadius { get; internal set; }
public Vector3 runtiemPieOffsetCenter { get; internal set; }
private List<float> m_LastData = new List<float>();
private List<float> m_DataUpdateTime = new List<float>();
private List<bool> m_DataUpdateFlag = new List<bool>();
public List<float> lastData { get { return m_LastData; } internal set { m_LastData = value; } }
public float GetData(int index)
{
if (index >= 0 && index < m_Data.Count) return m_Data[index];
if (index >= 0 && index < m_Data.Count)
{
return m_Data[index];
}
else return 0;
}
public float GetLastData(int index)
{
if (index >= 0 && index < lastData.Count)
{
return m_LastData[index];
}
else return 0;
}
public float GetCurrData(int index, float animationDuration = 500f)
{
if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0)
{
var time = Time.time - m_DataUpdateTime[index];
var total = animationDuration / 1000;
if (time <= total)
{
CheckLastData();
var curr = Mathf.Lerp(GetLastData(index), GetData(index), time / total);
return curr;
}
else
{
m_DataUpdateFlag[index] = false;
return GetData(index);
}
}
else
{
return GetData(index);
}
}
public bool UpdateData(int dimension, float value)
{
if (dimension >= 0 && dimension < data.Count)
{
CheckLastData();
m_LastData[dimension] = data[dimension];
m_DataUpdateTime[dimension] = Time.time;
m_DataUpdateFlag[dimension] = true;
data[dimension] = value;
return true;
}
return false;
}
private void CheckLastData()
{
if (m_LastData.Count != m_Data.Count)
{
m_LastData.Clear();
for (int i = 0; i < m_Data.Count; i++)
{
m_LastData.Add(m_Data[i]);
m_DataUpdateTime.Add(Time.time);
m_DataUpdateFlag.Add(false);
}
}
}
public bool IsDataChanged()
{
foreach (var b in m_DataUpdateFlag)
if (b) return true;
return false;
}
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
{
gameObject = labelObj;
@@ -197,7 +255,7 @@ namespace XCharts
public bool SetLabelText(string text)
{
if (labelText)
if (labelText && !labelText.text.Equals(text))
{
labelText.text = text;
if (m_LabelAutoSize)
@@ -213,6 +271,14 @@ namespace XCharts
return false;
}
public void SetLabelColor(Color color)
{
if (labelText)
{
labelText.color = color;
}
}
public float GetLabelWidth()
{
if (labelRect) return labelRect.sizeDelta.x;
@@ -238,28 +304,30 @@ namespace XCharts
if (labelRect) labelRect.localPosition = position;
}
public void SetIconObj(GameObject iconObj)
[Obsolete("Use SerieData.SetIconImage() instead.", true)]
public void SetIconObj(GameObject iconObj) { }
public void SetIconImage(Image image)
{
icon = iconObj.GetComponent<Image>();
iconRect = iconObj.GetComponent<RectTransform>();
UpdateIcon();
if (iconStyle == null) return;
iconStyle.SetImage(image);
}
public void UpdateIcon()
{
if (icon == null) return;
if (m_ShowIcon)
{
ChartHelper.SetActive(icon.gameObject, true);
icon.sprite = m_IconImage;
icon.color = m_IconColor;
iconRect.sizeDelta = new Vector2(m_IconWidth, m_IconHeight);
icon.transform.localPosition = m_IconOffset;
}
else
{
ChartHelper.SetActive(icon.gameObject, false);
}
if (iconStyle == null) return;
iconStyle.UpdateIcon();
}
public bool IsInitLabel()
{
return labelText != null;
}
public SerieLabel GetSerieLabel(SerieLabel parentLabel)
{
if (enableLabel) return label;
else return parentLabel;
}
}
}

View File

@@ -80,6 +80,7 @@ namespace XCharts
[SerializeField] private bool m_Show = false;
[SerializeField] Position m_Position;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private float m_Margin;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_PaddingLeftRight = 2f;
@@ -130,6 +131,10 @@ namespace XCharts
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// 距离轴线的距离。
/// </summary>
public float margin { get { return m_Margin; } set { m_Margin = value; } }
/// <summary>
/// Text color,If set as default ,the color will assigned as series color.
/// 自定义文字颜色,默认和系列的颜色一致。
/// </summary>

View File

@@ -35,6 +35,8 @@ namespace XCharts
/// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
/// <summary>
/// the color of text.
/// 文本的颜色。
@@ -81,6 +83,15 @@ namespace XCharts
this.rotate = rotate;
}
public void Copy(TextStyle style)
{
this.fontSize = style.fontSize;
this.fontStyle = style.fontStyle;
this.color = style.color;
this.rotate = style.rotate;
this.offset = style.offset;
}
public TextStyle Clone()
{
var textStyle = new TextStyle();

View File

@@ -0,0 +1,109 @@
/*
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// the title of serie.
/// 标题相关设置。
/// </summary>
[Serializable]
public class TitleStyle : SubComponent, IEquatable<TitleStyle>
{
[SerializeField] private bool m_Show;
[SerializeField] private TextStyle m_textStyle = new TextStyle(18);
/// <summary>
/// Whether to show title.
/// 是否显示标题。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// the color of text.
/// 文本的颜色。
/// </summary>
public TextStyle textStyle { get { return m_textStyle; } set { m_textStyle = value; } }
/// <summary>
///
/// </summary>
public Text runtimeText { get; set; }
public TitleStyle Clone()
{
var title = new TitleStyle();
title.show = show;
title.textStyle = textStyle.Clone();
return title;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is TitleStyle)
{
return Equals((TitleStyle)obj);
}
else
{
return false;
}
}
public bool Equals(TitleStyle other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return textStyle.Equals(other.textStyle);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public bool IsInited()
{
return runtimeText != null;
}
public void SetActive(bool active)
{
if (runtimeText)
{
ChartHelper.SetActive(runtimeText, active);
}
}
public void UpdatePosition(Vector3 pos)
{
if (runtimeText)
{
runtimeText.transform.localPosition = pos + new Vector3(m_textStyle.offset.x, m_textStyle.offset.y);
}
}
public void SetText(string text)
{
if (runtimeText)
{
if (textStyle.color != Color.clear) runtimeText.color = textStyle.color;
runtimeText.text = text;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f3865dea73ae403581fe83cfeca13f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,430 @@
using System;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
[AddComponentMenu("XCharts/GaugeChart", 19)]
[ExecuteInEditMode]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public class GaugeChart : BaseChart
{
private static readonly string s_AxisLabelObjectName = "axis_label";
private bool m_UpdateTitleText = false;
private bool m_UpdateLabelText = false;
protected override void Awake()
{
base.Awake();
InitAxisLabel();
}
protected override void Start()
{
base.Start();
foreach (var serie in m_Series.list)
{
UpdateTitle(serie);
UpdateLabel(serie);
}
UpdateTitleAndLabelText();
}
protected override void Update()
{
base.Update();
if (m_UpdateLabelText || m_UpdateTitleText)
{
m_UpdateTitleText = false;
m_UpdateLabelText = false;
UpdateTitleAndLabelText();
}
}
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
RemoveData();
m_Title.text = "GuageChart";
var serie = AddSerie(SerieType.Gauge, "serie1");
serie.min = 0;
serie.max = 100;
serie.startAngle = -125;
serie.endAngle = 125;
serie.center[0] = 0.5f;
serie.center[1] = 0.5f;
serie.radius[0] = 80;
serie.splitNumber = 5;
serie.animation.updateAnimation = true;
serie.titleStyle.show = true;
serie.titleStyle.textStyle.offset = new Vector2(0, 20);
serie.label.show = true;
serie.label.offset = new Vector3(0, -30);
serie.itemStyle.show = true;
serie.gaugeAxis.axisLabel.show = true;
serie.gaugeAxis.axisLabel.margin = 18;
AddData(0, UnityEngine.Random.Range(10, 90), "title");
InitAxisLabel();
}
#endif
private void InitAxisLabel()
{
var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, transform, Vector2.zero,
Vector2.zero, Vector2.zero, new Vector2(chartWidth, chartHeight));
SerieLabelPool.ReleaseAll(labelObject.transform);
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.list[i];
var serieLabel = serie.gaugeAxis.axisLabel;
serie.gaugeAxis.ClearLabelObject();
var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1);
var startAngle = serie.startAngle;
for (int j = 0; j < count; j++)
{
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
var color = Color.grey;
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, m_ThemeInfo.font, color, 100, 100);
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
var item = new LabelObject();
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
item.SetIcon(iconImage);
item.SetIconActive(false);
serie.gaugeAxis.AddLabelObject(item);
}
UpdateAxisLabel(serie);
}
}
protected override void DrawChart(VertexHelper vh)
{
base.DrawChart(vh);
DrawData(vh);
}
protected override void OnThemeChanged()
{
base.OnThemeChanged();
}
private void DrawData(VertexHelper vh)
{
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.list[i];
if (serie.type != SerieType.Gauge) continue;
DrawGauge(vh, serie);
}
}
private void DrawGauge(VertexHelper vh, Serie serie)
{
serie.UpdateCenter(chartWidth, chartHeight);
var destAngle = GetCurrAngle(serie, true);
serie.animation.InitProgress(0, serie.startAngle, destAngle);
var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail();
DrawProgressBar(vh, serie, currAngle);
DrawStageColor(vh, serie);
DrawSplitLine(vh, serie);
DrawAxisTick(vh, serie);
DrawPointer(vh, serie, currAngle);
UpdateTitle(serie);
// UpdateAxisLabel(serie);
UpdateLabel(serie);
CheckAnimation(serie);
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = (destAngle - serie.startAngle) / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
RefreshChart();
}
else if (NeedRefresh(serie))
{
RefreshChart();
}
}
private void DrawProgressBar(VertexHelper vh, Serie serie, float currAngle)
{
if (serie.gaugeType != GaugeType.ProgressBar) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return;
var color = serie.gaugeAxis.GetAxisLineColor(m_ThemeInfo, serie.index);
var backgroundColor = serie.gaugeAxis.GetAxisLineBackgroundColor(m_ThemeInfo, serie.index);
var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width;
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius,
backgroundColor, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, serie.startAngle, serie.endAngle);
if (serie.arcShaped)
{
DrawArcShape(vh, serie, serie.startAngle, backgroundColor, true);
DrawArcShape(vh, serie, serie.endAngle, backgroundColor);
}
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius,
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, serie.startAngle, currAngle);
if (serie.arcShaped && currAngle != serie.startAngle)
{
DrawArcShape(vh, serie, currAngle, color);
DrawArcShape(vh, serie, serie.startAngle, color, true);
}
}
private void DrawStageColor(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return;
var totalAngle = serie.endAngle - serie.startAngle;
var tempStartAngle = serie.startAngle;
var tempEndAngle = serie.startAngle;
var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width;
serie.gaugeAxis.runtimeStageAngle.Clear();
for (int i = 0; i < serie.gaugeAxis.axisLine.stageColor.Count; i++)
{
var stageColor = serie.gaugeAxis.axisLine.stageColor[i];
tempEndAngle = serie.startAngle + totalAngle * stageColor.percent;
serie.gaugeAxis.runtimeStageAngle.Add(tempEndAngle);
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius,
stageColor.color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, tempStartAngle, tempEndAngle);
tempStartAngle = tempEndAngle;
}
}
private void DrawPointer(VertexHelper vh, Serie serie, float currAngle)
{
if (!serie.gaugePointer.show) return;
var pointerColor = serie.gaugeAxis.GetPointerColor(m_ThemeInfo, serie.index, currAngle, serie.itemStyle);
var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1 ?
serie.runtimeInsideRadius * serie.gaugePointer.length :
serie.gaugePointer.length;
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width);
var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2);
var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2);
ChartDrawer.DrawPolygon(vh, p1, p3, p2, p4, pointerColor);
}
private void DrawSplitLine(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return;
if (serie.splitNumber <= 0) return;
var splitLine = serie.gaugeAxis.splitLine;
var totalAngle = serie.endAngle - serie.startAngle;
var diffAngle = totalAngle / serie.splitNumber;
var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width;
var insideRadius = outsideRadius - splitLine.length;
var lineWidth = splitLine.lineStyle.width;
for (int i = 0; i < serie.splitNumber + 1; i++)
{
var angle = serie.startAngle + i * diffAngle;
var lineColor = serie.gaugeAxis.GetSplitLineColor(m_ThemeInfo, serie.index, angle);
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius);
ChartDrawer.DrawLine(vh, p1, p2, lineWidth, lineColor);
}
}
private void DrawAxisTick(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisTick.show) return;
if (serie.splitNumber <= 0) return;
var axisTick = serie.gaugeAxis.axisTick;
var totalAngle = serie.endAngle - serie.startAngle;
var diffAngle = totalAngle / serie.splitNumber;
var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width;
var insideRadius = outsideRadius - (axisTick.length < 1 ? serie.gaugeAxis.axisLine.width * axisTick.length : axisTick.length);
var lineWidth = axisTick.lineStyle.width;
for (int i = 0; i < serie.splitNumber; i++)
{
for (int j = 1; j < axisTick.splitNumber; j++)
{
var angle = serie.startAngle + i * diffAngle + j * (diffAngle / axisTick.splitNumber);
var lineColor = serie.gaugeAxis.GetSplitLineColor(m_ThemeInfo, serie.index, angle);
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius);
ChartDrawer.DrawLine(vh, p1, p2, lineWidth, lineColor);
}
}
}
private bool NeedRefresh(Serie serie)
{
if (serie.type == SerieType.Gauge)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
var destValue = serieData.GetData(1);
var currValue = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
return destValue != currValue;
}
}
return false;
}
private void DrawArcShape(VertexHelper vh, Serie serie, float angle, Color color, bool invert = false)
{
var radius = serie.gaugeAxis.axisLine.width / 2;
var len = serie.runtimeInsideRadius + radius;
var pos = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, len);
var startAngle = invert ? angle + 180 : angle;
var endAngle = invert ? angle + 360 : angle + 180;
ChartDrawer.DrawSector(vh, pos, radius, color, startAngle, endAngle);
}
private void CheckAnimation(Serie serie)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
var value = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
var data = serieData.GetData(1);
if (value != data) m_RefreshChart = true;
}
}
private void UpdateTitle(Serie serie)
{
if (serie.titleStyle.show)
{
if (serie.titleStyle.IsInited())
{
serie.titleStyle.SetActive(true);
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
m_UpdateTitleText = true;
}
else
{
m_ReinitTitle = true;
}
}
else
{
serie.titleStyle.SetActive(false);
}
}
private void UpdateAxisLabel(Serie serie)
{
var show = serie.gaugeAxis.show && serie.gaugeAxis.axisLabel.show;
serie.gaugeAxis.SetLabelObjectActive(show);
if (!show)
{
return;
}
var count = serie.splitNumber > 36 ? 36 : serie.splitNumber;
var startAngle = serie.startAngle;
var totalAngle = serie.endAngle - serie.startAngle;
var totalValue = serie.max - serie.min;
var diffAngle = totalAngle / count;
var diffValue = totalValue / count;
var radius = serie.runtimeInsideRadius - serie.gaugeAxis.axisLabel.margin;
var serieData = serie.GetSerieData(0);
var dataName = serieData != null ? serieData.name : null;
var customLabelText = serie.gaugeAxis.axisLabelText;
for (int j = 0; j <= count; j++)
{
var angle = serie.startAngle + j * diffAngle;
var value = serie.min + j * diffValue;
var pos = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, radius);
var text = customLabelText != null && j < customLabelText.Count ? customLabelText[j] :
serie.gaugeAxis.axisLabel.GetFormatterContent(serie.name, dataName, value, totalValue);
serie.gaugeAxis.SetLabelObjectText(j, text);
serie.gaugeAxis.SetLabelObjectPosition(j, pos);
}
}
private void UpdateLabel(Serie serie)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
if (serie.label.show)
{
if (serieData.IsInitLabel())
{
serieData.SetLabelActive(true);
serieData.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
m_UpdateLabelText = true;
}
else
{
m_ReinitLabel = true;
}
}
else
{
serieData.SetLabelActive(false);
}
}
}
private void UpdateTitleAndLabelText()
{
foreach (var serie in m_Series.list)
{
if (serie.type == SerieType.Gauge)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
if (serie.label.show && serieData.IsInitLabel())
{
var value = serieData.GetData(1);
var total = serie.max;
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
serieData.SetLabelText(content);
if (serie.label.color != Color.clear)
{
serieData.SetLabelColor(serie.label.color);
}
}
if (serie.titleStyle.show && serie.titleStyle.IsInited())
{
serie.titleStyle.SetText(serieData.name);
}
}
UpdateAxisLabel(serie);
}
}
}
private float GetCurrAngle(Serie serie, bool dest)
{
float rangeValue = serie.max - serie.min;
float rangeAngle = serie.endAngle - serie.startAngle;
float value = 0;
float angle = serie.startAngle;
if (serie.dataCount > 0)
{
var serieData = serie.data[0];
value = dest ? serieData.GetData(1) : serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
value = Mathf.Clamp(value, serie.min, serie.max);
}
if (rangeValue > 0)
{
angle += rangeAngle * value / rangeValue;
}
return angle;
}
protected override void OnRefreshLabel()
{
//TODO:
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c7cdc3b6d7f9473289a599c00a2569c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -34,9 +34,10 @@ namespace XCharts
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
IDragHandler, IEndDragHandler, IScrollHandler
{
private static readonly string s_TitleObjectName = "title";
private static readonly string s_LegendObjectName = "legend";
private static readonly string s_SerieLabelObjectName = "label";
protected static readonly string s_TitleObjectName = "title";
protected static readonly string s_LegendObjectName = "legend";
protected static readonly string s_SerieLabelObjectName = "label";
protected static readonly string s_SerieTitleObjectName = "serie";
[SerializeField] protected float m_ChartWidth;
[SerializeField] protected float m_ChartHeight;
@@ -54,12 +55,17 @@ namespace XCharts
[NonSerialized] private Legend m_CheckLegend = Legend.defaultLegend;
[NonSerialized] private float m_CheckWidth = 0;
[NonSerialized] private float m_CheckHeight = 0;
[NonSerialized] private Vector2 m_CheckMinAnchor;
[NonSerialized] private Vector2 m_CheckMaxAnchor;
[NonSerialized] private float m_CheckSerieCount = 0;
[NonSerialized] private List<string> m_CheckSerieName = new List<string>();
[NonSerialized] private bool m_RefreshChart = false;
[NonSerialized] private bool m_RefreshLabel = false;
[NonSerialized] private bool m_ReinitLabel = false;
[NonSerialized] private bool m_CheckAnimation = false;
[NonSerialized] protected bool m_RefreshChart = false;
[NonSerialized] protected bool m_RefreshLabel = false;
[NonSerialized] protected bool m_ReinitLabel = false;
[NonSerialized] protected bool m_ReinitTitle = false;
[NonSerialized] protected bool m_CheckAnimation = false;
[NonSerialized] protected bool m_IsPlayingStartAnimation = false;
[NonSerialized] protected List<string> m_LegendRealShowName = new List<string>();
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
@@ -84,6 +90,7 @@ namespace XCharts
InitTitle();
InitLegend();
InitSerieLabel();
InitSerieTitle();
InitTooltip();
m_Series.AnimationStop();
m_Series.AnimationStart();
@@ -153,7 +160,7 @@ namespace XCharts
Vector2 anchorMax = m_Title.location.runtimeAnchorMax;
Vector2 pivot = m_Title.location.runtimePivot;
Vector3 titlePosition = m_Title.location.GetPosition(chartWidth, chartHeight);
Vector3 subTitlePosition = -new Vector3(0, m_Title.textFontSize + m_Title.itemGap, 0);
Vector3 subTitlePosition = -new Vector3(0, m_Title.textStyle.fontSize + m_Title.itemGap, 0);
float titleWid = chartWidth;
var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax,
@@ -163,20 +170,22 @@ namespace XCharts
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
new Vector2(titleWid, m_Title.textFontSize), m_Title.textFontSize);
new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize, m_Title.textStyle.rotate,
m_Title.textStyle.fontStyle);
titleText.alignment = anchor;
titleText.gameObject.SetActive(m_Title.show);
titleText.transform.localPosition = Vector2.zero;
titleText.transform.localPosition = Vector3.zero + m_Title.textStyle.offsetv3;
titleText.text = m_Title.text.Replace("\\n", "\n");
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
new Vector2(titleWid, m_Title.subTextFontSize), m_Title.subTextFontSize);
new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize,
m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle);
subText.alignment = anchor;
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
subText.transform.localPosition = subTitlePosition;
subText.transform.localPosition = subTitlePosition + m_Title.subTextStyle.offsetv3;
subText.text = m_Title.subText.Replace("\\n", "\n");
}
@@ -287,9 +296,8 @@ namespace XCharts
private void InitSerieLabel()
{
var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, chartAnchorMin,
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
//ChartHelper.DestroyAllChildren(labelObject.transform);
var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, Vector2.zero,
Vector2.zero, Vector2.zero, new Vector2(chartWidth, chartHeight));
SerieLabelPool.ReleaseAll(labelObject.transform);
int count = 0;
for (int i = 0; i < m_Series.Count; i++)
@@ -298,33 +306,64 @@ namespace XCharts
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (!serie.label.show && j > 100) continue;
var serieLabel = serieData.GetSerieLabel(serie.label);
if (!serieLabel.show && j > 100) continue;
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
var color = Color.grey;
if (serie.type == SerieType.Pie)
{
color = (serie.label.position == SerieLabel.Position.Inside) ? Color.white :
color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white :
(Color)m_ThemeInfo.GetColor(count);
}
else
{
color = serie.label.color != Color.clear ? serie.label.color :
color = serieLabel.color != Color.clear ? serieLabel.color :
(Color)m_ThemeInfo.GetColor(i);
}
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serie.label, m_ThemeInfo.font, color, serieData);
var iconObj = labelObj.transform.Find("Icon").gameObject;
serieData.SetIconObj(iconObj);
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, m_ThemeInfo.font, color,
serieData.iconStyle.width, serieData.iconStyle.height);
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
serieData.SetIconImage(iconImage);
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
serieData.InitLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
serieData.SetLabelActive(false);
serieData.SetLabelText(serieData.name);
//serieData.SetLabelText(serieData.name);
count++;
}
}
}
private void InitSerieTitle()
{
var titleObject = ChartHelper.AddObject(s_SerieTitleObjectName, transform, Vector2.zero,
Vector2.zero, Vector2.zero, new Vector2(chartWidth, chartHeight));
ChartHelper.HideAllObject(titleObject);
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.list[i];
var textStyle = serie.titleStyle.textStyle;
var color = textStyle.color == Color.clear ? m_ThemeInfo.GetColor(i) : (Color32)textStyle.color;
var anchorMin = new Vector2(0.5f, 0.5f);
var anchorMax = new Vector2(0.5f, 0.5f);
var pivot = new Vector2(0.5f, 0.5f);
var fontSize = 10;
var sizeDelta = new Vector2(50, fontSize + 2);
var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color, TextAnchor.MiddleCenter,
anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate, textStyle.fontStyle);
txt.text = "";
txt.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector2.zero;
ChartHelper.SetActive(txt, false);
serie.titleStyle.runtimeText = txt;
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
txt.text = serieData.name;
}
}
}
private void InitTooltip()
{
@@ -359,6 +398,13 @@ namespace XCharts
{
SetSize(sizeDelta.x, sizeDelta.y);
}
if (m_CheckMinAnchor != rectTransform.anchorMin || m_CheckMaxAnchor != rectTransform.anchorMax)
{
m_CheckMaxAnchor = rectTransform.anchorMax;
m_CheckMinAnchor = rectTransform.anchorMin;
m_ReinitLabel = true;
}
}
private void CheckTheme()
@@ -413,8 +459,9 @@ namespace XCharts
{
if (canvas == null) return;
Vector2 local;
var cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
Input.mousePosition, canvas.worldCamera, out local))
Input.mousePosition, cam, out local))
{
pointerPos = Vector2.zero;
}
@@ -484,12 +531,25 @@ namespace XCharts
protected void CheckRefreshLabel()
{
foreach (var serie in m_Series.list)
{
if (serie.label.show && serie.runtimeLastCheckDataCount != serie.dataCount)
{
m_ReinitLabel = true;
serie.runtimeLastCheckDataCount = serie.dataCount;
}
}
if (m_ReinitLabel)
{
m_ReinitLabel = false;
m_LegendRealShowName = m_Series.GetSerieNameList();
InitSerieLabel();
}
if (m_ReinitTitle)
{
m_ReinitTitle = false;
InitSerieTitle();
}
if (m_RefreshLabel)
{
m_RefreshLabel = false;
@@ -516,6 +576,7 @@ namespace XCharts
InitTitle();
InitLegend();
InitTooltip();
InitSerieLabel();
}
protected virtual void OnThemeChanged()
@@ -699,25 +760,26 @@ namespace XCharts
{
var labelHalfWid = serieData.GetLabelWidth() / 2;
var labelHalfHig = serieData.GetLabelHeight() / 2;
var centerPos = serieData.labelPosition + serie.label.offset;
var serieLabel = serieData.GetSerieLabel(serie.label);
var centerPos = serieData.labelPosition + serieLabel.offset;
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
var p2 = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
var p3 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
var p4 = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);
if (serie.label.rotate > 0)
if (serieLabel.rotate > 0)
{
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serie.label.rotate);
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serie.label.rotate);
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serie.label.rotate);
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serie.label.rotate);
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
}
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serie.label.backgroundColor);
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);
if (serie.label.border)
if (serieLabel.border)
{
var borderWid = serie.label.borderWidth;
var borderWid = serieLabel.borderWidth;
p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig + borderWid);
p2 = new Vector3(centerPos.x + labelHalfWid + 2 * borderWid, centerPos.y + labelHalfHig + borderWid);
p3 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y + labelHalfHig);
@@ -726,21 +788,21 @@ namespace XCharts
var p6 = new Vector3(centerPos.x - labelHalfWid - 2 * borderWid, centerPos.y - labelHalfHig - borderWid);
var p7 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y - labelHalfHig);
var p8 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y + labelHalfHig + 2 * borderWid);
if (serie.label.rotate > 0)
if (serieLabel.rotate > 0)
{
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serie.label.rotate);
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serie.label.rotate);
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serie.label.rotate);
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serie.label.rotate);
p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serie.label.rotate);
p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serie.label.rotate);
p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serie.label.rotate);
p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serie.label.rotate);
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serieLabel.rotate);
p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serieLabel.rotate);
p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serieLabel.rotate);
p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serieLabel.rotate);
}
ChartDrawer.DrawLine(vh, p1, p2, borderWid, serie.label.borderColor);
ChartDrawer.DrawLine(vh, p3, p4, borderWid, serie.label.borderColor);
ChartDrawer.DrawLine(vh, p5, p6, borderWid, serie.label.borderColor);
ChartDrawer.DrawLine(vh, p7, p8, borderWid, serie.label.borderColor);
ChartDrawer.DrawLine(vh, p1, p2, borderWid, serieLabel.borderColor);
ChartDrawer.DrawLine(vh, p3, p4, borderWid, serieLabel.borderColor);
ChartDrawer.DrawLine(vh, p5, p6, borderWid, serieLabel.borderColor);
ChartDrawer.DrawLine(vh, p7, p8, borderWid, serieLabel.borderColor);
}
}

View File

@@ -90,6 +90,7 @@ namespace XCharts
{
base.DrawChart(vh);
if (!m_CheckMinMaxValue) return;
m_IsPlayingStartAnimation = false;
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
m_Series.GetStackSeries(ref m_StackSeries);
int seriesCount = m_StackSeries.Count;
@@ -787,7 +788,7 @@ namespace XCharts
{
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, false, out tempMinValue, out tempMaxValue);
}
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue);
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue, true);
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
{
m_CheckMinMaxValue = true;
@@ -814,10 +815,17 @@ namespace XCharts
{
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack);
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack, 500);
RefreshChart();
}
}
if (axis.IsValueChanging(500) && !m_IsPlayingStartAnimation)
{
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack, 500);
RefreshChart();
}
}
protected virtual void OnCoordinateChanged()
@@ -878,7 +886,7 @@ namespace XCharts
private void DrawYAxisTickAndSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis)
{
if (yAxis.show)
if (yAxis.NeedShowSplit())
{
var size = yAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
var totalWidth = coordinateY;
@@ -1044,7 +1052,7 @@ namespace XCharts
float minValue = 0;
float maxValue = 0;
m_Series.GetYMinMaxValue(null, 0, IsValue(), out minValue, out maxValue);
axis.AdjustMinMaxValue(ref minValue, ref maxValue);
axis.AdjustMinMaxValue(ref minValue, ref maxValue, true);
int rate = 1;
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
@@ -1053,10 +1061,11 @@ namespace XCharts
if (rate < 1) rate = 1;
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
for (int i = 0; i < maxCount; i += rate)
{
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i);
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
serie.animation.GetUpdateAnimationDuration(), ref dataChanging);
float pX = coordinateX + i * scaleWid;
float dataHig = (axis.runtimeMaxValue - axis.runtimeMinValue) == 0 ? 0 :
(value - axis.runtimeMinValue) / (axis.runtimeMaxValue - axis.runtimeMinValue) * hig;
@@ -1074,6 +1083,10 @@ namespace XCharts
}
lp = np;
}
if (dataChanging)
{
RefreshChart();
}
}
switch (m_DataZoom.rangeMode)
{
@@ -1325,7 +1338,7 @@ namespace XCharts
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (serie.label.show || serieData.showIcon)
if (serie.label.show || serieData.iconStyle.show)
{
var pos = serie.dataPoints[j];
var value = serieData.data[1];
@@ -1348,6 +1361,7 @@ namespace XCharts
}
break;
}
m_RefreshLabel = true;
serieData.labelPosition = pos;
if (serie.label.show) DrawLabelBackground(vh, serie, serieData);
}
@@ -1372,6 +1386,7 @@ namespace XCharts
if (j >= serie.dataPoints.Count) break;
var serieData = serie.data[j];
var pos = serie.dataPoints[j];
serieData.SetGameObjectPosition(serieData.labelPosition);
serieData.UpdateIcon();
if (serie.show && serie.label.show && serieData.canShowLabel)

View File

@@ -23,7 +23,7 @@ namespace XCharts
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
var showData = serie.GetDataList(m_DataZoom);
float categoryWidth = yAxis.GetDataWidth(coordinateHeight,showData.Count, m_DataZoom);
float categoryWidth = yAxis.GetDataWidth(coordinateHeight, showData.Count, m_DataZoom);
float barGap = GetBarGap();
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
float barWidth = serie.GetBarWidth(categoryWidth);
@@ -43,13 +43,20 @@ namespace XCharts
}
}
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(updateDuration);
float xMaxValue = xAxis.GetCurrMaxValue(updateDuration);
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
float value = showData[i].data[1];
var serieData = showData[i];
serieData.canShowLabel = true;
float value = showData[i].GetCurrData(1, updateDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + yAxis.axisLine.width;
float pY = coordinateY + +i * categoryWidth;
if (!yAxis.boundaryGap) pY -= categoryWidth / 2;
@@ -59,14 +66,15 @@ namespace XCharts
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
barHig = value / valueTotal * coordinateWidth;
barHig = valueTotal != 0 ? (value / valueTotal * coordinateWidth) : 0;
seriesHig[i] += barHig;
}
else
{
valueTotal = xAxis.runtimeMaxValue - xAxis.runtimeMinValue;
barHig = (xAxis.runtimeMinValue > 0 ? value - xAxis.runtimeMinValue : value)
/ valueTotal * coordinateWidth;
valueTotal = xMaxValue - xMinValue;
if (valueTotal != 0)
barHig = (xMinValue > 0 ? value - xMinValue : value)
/ valueTotal * coordinateWidth;
seriesHig[i] += barHig;
}
@@ -100,6 +108,10 @@ namespace XCharts
{
m_BarLastOffset += barGapWidth;
}
if (dataChanging)
{
RefreshChart();
}
}
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
@@ -120,6 +132,7 @@ namespace XCharts
}
}
RefreshChart();
m_IsPlayingStartAnimation = true;
}
return currHig;
}
@@ -132,7 +145,7 @@ namespace XCharts
var xAxis = m_XAxises[serie.axisIndex];
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
float categoryWidth = xAxis.GetDataWidth(coordinateWidth,showData.Count, m_DataZoom);
float categoryWidth = xAxis.GetDataWidth(coordinateWidth, showData.Count, m_DataZoom);
float barGap = GetBarGap();
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
float barWidth = serie.GetBarWidth(categoryWidth);
@@ -152,13 +165,18 @@ namespace XCharts
}
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(updateDuration);
float yMaxValue = yAxis.GetCurrMaxValue(updateDuration);
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
float value = showData[i].data[1];
float value = showData[i].GetCurrData(1, updateDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
float pX = coordinateX + i * categoryWidth;
float zeroY = coordinateY + yAxis.runtimeZeroYOffset;
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
@@ -169,14 +187,15 @@ namespace XCharts
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
barHig = value / valueTotal * coordinateHeight;
barHig = valueTotal != 0 ? (value / valueTotal * coordinateHeight) : 0;
seriesHig[i] += barHig;
}
else
{
valueTotal = yAxis.runtimeMaxValue - yAxis.runtimeMinValue;
barHig = (yAxis.runtimeMinValue > 0 ? value - yAxis.runtimeMinValue : value)
/ valueTotal * coordinateHeight;
valueTotal = yMaxValue - yMinValue;
if (valueTotal != 0)
barHig = (yMinValue > 0 ? value - yMinValue : value)
/ valueTotal * coordinateHeight;
seriesHig[i] += barHig;
}
@@ -207,6 +226,10 @@ namespace XCharts
}
}
}
if (dataChanging)
{
RefreshChart();
}
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
{
m_BarLastOffset += barGapWidth;

View File

@@ -135,6 +135,8 @@ namespace XCharts
serie.dataPoints.Clear();
serie.animation.InitProgress(1, 0, xCount);
var animationIndex = serie.animation.GetCurrIndex();
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChanging = false;
for (int i = 0; i < xCount; i++)
{
for (int j = 0; j < yCount; j++)
@@ -144,7 +146,8 @@ namespace XCharts
var serieData = dataList[dataIndex];
var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
serieData.data.Count - 1;
var value = serieData.data[dimension];
var value = serieData.GetCurrData(dimension, updateDuration);
if (serieData.IsDataChanged()) dataChanging = true;
var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
serie.dataPoints.Add(pos);
serieData.canShowLabel = false;
@@ -159,7 +162,7 @@ namespace XCharts
if (!m_VisualMap.IsInSelectedValue(value)) continue;
color = m_VisualMap.GetColor(value);
}
if(animationIndex>= 0 && i> animationIndex) continue;
if (animationIndex >= 0 && i > animationIndex) continue;
serieData.canShowLabel = true;
var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.runtimeXValues[0] && j == (int)m_Tooltip.runtimeYValues[0])
|| m_VisualMap.runtimeSelectedIndex > 0;
@@ -183,6 +186,11 @@ namespace XCharts
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = xCount / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
m_IsPlayingStartAnimation = true;
RefreshChart();
}
if (dataChanging)
{
RefreshChart();
}
}

View File

@@ -111,6 +111,8 @@ namespace XCharts
var includeLastData = false;
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration();
for (i = serie.minShow; i < maxCount; i += rate)
{
if (i == maxCount - 1) includeLastData = true;
@@ -118,16 +120,23 @@ namespace XCharts
{
for (int j = 0; j < rate; j++) seriesHig.Add(0);
}
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage,
i, updateDuration, ref dataChanging);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
updateDuration);
serie.dataPoints.Add(np);
}
if (dataChanging)
{
RefreshChart();
}
if (!includeLastData)
{
i = maxCount - 1;
seriesHig.Add(0);
float yValue = showData[i].data[1];
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
float yValue = showData[i].GetCurrData(1, updateDuration);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
updateDuration);
serie.dataPoints.Add(np);
}
if (serie.dataPoints.Count <= 0)
@@ -144,8 +153,8 @@ namespace XCharts
if (serie.minShow > 0 && serie.minShow < showData.Count)
{
i = serie.minShow - 1;
float yValue = showData[i].data[1];
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos);
float yValue = showData[i].GetCurrData(1, updateDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, updateDuration);
}
else
{
@@ -154,14 +163,13 @@ namespace XCharts
if (serie.maxShow > 0 && serie.maxShow < showData.Count)
{
i = serie.maxShow;
float yValue = showData[i].data[1];
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos);
float yValue = showData[i].GetCurrData(1, updateDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, updateDuration);
}
else
{
lastNextPos = serie.dataPoints[serie.dataPoints.Count - 1];
}
for (i = 1; i < serie.dataPoints.Count; i++)
{
np = serie.dataPoints[i];
@@ -216,6 +224,7 @@ namespace XCharts
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
m_IsPlayingStartAnimation = true;
RefreshChart();
}
}
@@ -236,9 +245,13 @@ namespace XCharts
}
private float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
int minCount, int maxCount, float totalAverage, int index)
int minCount, int maxCount, float totalAverage, int index, float updateDuration, ref bool dataChanging)
{
if (rate <= 1 || index == minCount) return showData[index].data[1];
if (rate <= 1 || index == minCount)
{
if (showData[index].IsDataChanged()) dataChanging = true;
return showData[index].GetCurrData(1, updateDuration);
}
switch (sampleType)
{
case SampleType.Sum:
@@ -246,7 +259,8 @@ namespace XCharts
float total = 0;
for (int i = index; i > index - rate; i--)
{
total += showData[i].data[1];
total += showData[i].GetCurrData(1, updateDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
}
if (sampleType == SampleType.Average) return total / rate;
else return total;
@@ -254,16 +268,18 @@ namespace XCharts
float max = float.MinValue;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].data[1];
var value = showData[i].GetCurrData(1, updateDuration);
if (value > max) max = value;
if (showData[i].IsDataChanged()) dataChanging = true;
}
return max;
case SampleType.Min:
float min = float.MaxValue;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].data[1];
var value = showData[i].GetCurrData(1, updateDuration);
if (value < min) min = value;
if (showData[i].IsDataChanged()) dataChanging = true;
}
return min;
case SampleType.Peak:
@@ -272,40 +288,45 @@ namespace XCharts
total = 0;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].data[1];
var value = showData[i].GetCurrData(1, updateDuration);
total += value;
if (value < min) min = value;
if (value > max) max = value;
if (showData[i].IsDataChanged()) dataChanging = true;
}
var average = total / rate;
if (average >= totalAverage) return max;
else return min;
}
return showData[index].data[1];
if (showData[index].IsDataChanged()) dataChanging = true;
return showData[index].GetCurrData(1, updateDuration);
}
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i,
float scaleWid, float serieHig, ref Vector3 np)
float scaleWid, float serieHig, ref Vector3 np, float duration)
{
float xDataHig, yDataHig;
float xMinValue = xAxis.GetCurrMinValue(duration);
float xMaxValue = xAxis.GetCurrMaxValue(duration);
float yMinValue = yAxis.GetCurrMinValue(duration);
float yMaxValue = yAxis.GetCurrMaxValue(duration);
if (xAxis.IsValue())
{
float xValue = i > showData.Count - 1 ? 0 : showData[i].data[0];
float pX = coordinateX + xAxis.axisLine.width;
float pY = serieHig + coordinateY + xAxis.axisLine.width;
if ((xAxis.runtimeMaxValue - xAxis.runtimeMinValue) <= 0) xDataHig = 0;
else xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
if ((yAxis.runtimeMaxValue - yAxis.runtimeMinValue) <= 0) yDataHig = 0;
else yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
if ((xMaxValue - xMinValue) <= 0) xDataHig = 0;
else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
np = new Vector3(pX + xDataHig, pY + yDataHig);
}
else
{
float pX = startX + i * scaleWid;
float pY = serieHig + coordinateY + yAxis.axisLine.width;
if ((yAxis.runtimeMaxValue - yAxis.runtimeMinValue) <= 0) yDataHig = 0;
else yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
np = new Vector3(pX, pY + yDataHig);
}
return yDataHig;
@@ -347,28 +368,37 @@ namespace XCharts
var sampleDist = serie.sampleDist;
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWidth / sampleDist));
if (rate < 1) rate = 1;
var dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(updateDuration);
float xMaxValue = xAxis.GetCurrMaxValue(updateDuration);
for (i = serie.minShow; i < maxCount; i += rate)
{
if (i >= seriesHig.Count)
{
for (int j = 0; j < rate; j++) seriesHig.Add(0);
}
float value = showData[i].data[1];
float value = showData[i].GetCurrData(1, updateDuration);
float pY = startY + i * scaleWid;
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
float dataHig = (value - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
float dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
np = new Vector3(pX + dataHig, pY);
serie.dataPoints.Add(np);
seriesHig[i] += dataHig;
if (showData[i].IsDataChanged()) dataChanging = true;
}
if (dataChanging)
{
RefreshChart();
}
if (maxCount % rate != 0)
{
i = maxCount - 1;
seriesHig.Add(0);
float value = showData[i].data[1];
float value = showData[i].GetCurrData(1, updateDuration);
float pY = startY + i * scaleWid;
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
float dataHig = (value - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
float dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
np = new Vector3(pX + dataHig, pY);
serie.dataPoints.Add(np);
seriesHig[i] += dataHig;
@@ -442,6 +472,7 @@ namespace XCharts
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
m_IsPlayingStartAnimation = true;
RefreshChart();
}
}

View File

@@ -23,11 +23,14 @@ namespace XCharts
: serie.dataCount;
serie.animation.InitProgress(1, 0, 1);
var rate = serie.animation.GetCurrRate();
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChanging = false;
for (int n = serie.minShow; n < maxCount; n++)
{
var serieData = serie.GetDataList(m_DataZoom)[n];
float xValue = serieData.data[0];
float yValue = serieData.data[1];
float xValue = serieData.GetCurrData(0, updateDuration);
float yValue = serieData.GetCurrData(1, updateDuration);
if (serieData.IsDataChanged()) dataChanging = true;
float pX = coordinateX + xAxis.axisLine.width;
float pY = coordinateY + yAxis.axisLine.width;
float xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
@@ -66,6 +69,11 @@ namespace XCharts
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = 1 / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
m_IsPlayingStartAnimation = true;
RefreshChart();
}
if (dataChanging)
{
RefreshChart();
}
}

View File

@@ -0,0 +1,96 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
public class LabelObject
{
private GameObject m_GameObject;
private bool m_LabelAutoSize = true;
private float m_LabelPaddingLeftRight = 3f;
private float m_LabelPaddingTopBottom = 3f;
private Text m_LabelText;
private RectTransform m_LabelRect;
private Image m_IconImage;
private RectTransform m_IconRect;
public Image icon { get { return m_IconImage; } }
public Text label { get { return m_LabelText; } }
public LabelObject()
{
}
public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
{
m_GameObject = labelObj;
m_LabelAutoSize = autoSize;
m_LabelPaddingLeftRight = paddingLeftRight;
m_LabelPaddingTopBottom = paddingTopBottom;
m_LabelText = labelObj.GetComponentInChildren<Text>();
m_LabelRect = m_LabelText.GetComponent<RectTransform>();
}
public void SetIcon(Image image)
{
m_IconImage = image;
if (image != null)
{
m_IconRect = m_IconImage.GetComponent<RectTransform>();
}
}
public void SetIconSprite(Sprite sprite)
{
if (m_IconImage != null) m_IconImage.sprite = sprite;
}
public void SetIconSize(float width, float height)
{
if (m_LabelRect != null) m_LabelRect.sizeDelta = new Vector3(width, height);
}
public void SetIconActive(bool flag)
{
ChartHelper.SetActive(m_IconImage, flag);
}
public void SetPosition(Vector3 position)
{
if (m_GameObject != null)
{
m_GameObject.transform.localPosition = position;
}
}
public void SetActive(bool flag)
{
ChartHelper.SetActive(m_GameObject, flag);
}
public bool SetText(string text)
{
if (m_LabelText && !m_LabelText.text.Equals(text))
{
m_LabelText.text = text;
if (m_LabelAutoSize)
{
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
new Vector2(m_LabelText.preferredWidth + m_LabelPaddingLeftRight * 2,
m_LabelText.preferredHeight + m_LabelPaddingTopBottom * 2);
var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
if (sizeChange) m_LabelRect.sizeDelta = newSize;
return sizeChange;
}
}
return false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4e7ef04b9a0e4526b49bf63967cfef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,6 +7,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
@@ -14,7 +15,7 @@ namespace XCharts
{
private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200);
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, SerieData serieData)
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, float iconWidth, float iconHeight)
{
GameObject element;
if (m_Stack.Count == 0 || !Application.isPlaying)
@@ -22,13 +23,19 @@ namespace XCharts
element = ChartHelper.AddSerieLabel(name, parent, font,
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
label.backgroundWidth, label.backgroundHeight);
ChartHelper.AddIcon("Icon", element.transform, serieData.iconWidth, serieData.iconHeight);
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
}
else
{
element = m_Stack.Pop();
element.name = name;
element.transform.SetParent(parent);
element.transform.localEulerAngles = new Vector3(0, 0, label.rotate);
var text = element.GetComponentInChildren<Text>();
text.color = color;
text.font = font;
text.fontSize = label.fontSize;
text.fontStyle = label.fontStyle;
ChartHelper.SetActive(element, true);
}
return element;

View File

@@ -20,7 +20,6 @@ namespace XCharts
{
private bool isDrawPie;
private bool m_IsEnterLegendButtom;
private bool m_RefreshLabel;
protected override void Awake()
{
@@ -67,7 +66,7 @@ namespace XCharts
if (serie.pieClickOffset) isClickOffset = true;
serie.runtimePieDataMax = serie.yMax;
serie.runtimePieDataTotal = serie.yTotal;
UpdatePieCenter(serie);
serie.UpdateCenter(chartWidth, chartHeight);
float totalDegree = 360;
float startDegree = 0;
@@ -77,12 +76,15 @@ namespace XCharts
if (sd.show && serie.pieRoseType == RoseType.Area) showdataCount++;
sd.canShowLabel = false;
}
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
for (int n = 0; n < data.Count; n++)
{
if (!serie.animation.NeedAnimation(n)) break;
var serieData = data[n];
serieData.index = n;
float value = serieData.data[1];
float value = serieData.GetCurrData(1, updateDuration);
if (serieData.IsDataChanged()) dataChanging = true;
serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
Color color = m_ThemeInfo.GetColor(serieNameCount);
serieData.runtimePieStartAngle = startDegree;
@@ -98,8 +100,8 @@ namespace XCharts
serieData.runtimePieToAngle = startDegree + degree;
serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
serie.runtimePieInsideRadius + (serie.runtimePieOutsideRadius - serie.runtimePieInsideRadius) * value / serie.runtimePieDataMax :
serie.runtimePieOutsideRadius;
serie.runtimeInsideRadius + (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimePieDataMax :
serie.runtimeOutsideRadius;
if (serieData.highlighted)
{
isDataHighlight = true;
@@ -116,11 +118,11 @@ namespace XCharts
float currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad;
float currSin = Mathf.Sin(currRad);
float currCos = Mathf.Cos(currRad);
var center = serie.runtimePieCenterPos;
var center = serie.runtimeCenterPos;
serieData.runtimePieCurrAngle = serieData.runtimePieToAngle;
serieData.runtiemPieOffsetCenter = center;
serieData.runtimePieInsideRadius = serie.runtimePieInsideRadius;
serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
if (serie.animation.CheckDetailBreak(n, serieData.runtimePieToAngle))
{
isFinish = false;
@@ -140,14 +142,19 @@ namespace XCharts
serieData.runtiemPieOffsetCenter = new Vector3(center.x + serieData.runtimePieOffsetRadius * currSin,
center.y + serieData.runtimePieOffsetRadius * currCos);
var drawStartDegree = startDegree + serie.pieSpace;
var drawEndDegree = serieData.runtimePieCurrAngle - serie.pieSpace;
DrawArcShape(vh, serie, serieData, serieData.runtiemPieOffsetCenter, color, ref drawStartDegree, ref drawEndDegree);
ChartDrawer.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, startDegree, serieData.runtimePieCurrAngle);
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
}
else
{
var drawStartDegree = startDegree + serie.pieSpace;
var drawEndDegree = serieData.runtimePieCurrAngle - serie.pieSpace;
DrawArcShape(vh, serie, serieData, center, color, ref drawStartDegree, ref drawEndDegree);
ChartDrawer.DrawDoughnut(vh, center, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, startDegree, serieData.runtimePieCurrAngle);
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
}
serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
isDrawPie = true;
@@ -164,21 +171,48 @@ namespace XCharts
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
RefreshChart();
}
if (dataChanging)
{
RefreshChart();
}
}
DrawLabelLine(vh);
DrawLabelBackground(vh);
raycastTarget = isClickOffset && isDataHighlight;
}
private void DrawArcShape(VertexHelper vh, Serie serie, SerieData serieData, Vector3 centerPos,
Color color, ref float drawStartDegree, ref float drawEndDegree)
{
if (serie.arcShaped && serieData.runtimePieInsideRadius > 0)
{
var width = (serieData.runtimePieOutsideRadius - serieData.runtimePieInsideRadius) / 2;
var radius = serieData.runtimePieInsideRadius + width;
var diffDegree = Mathf.Asin(width / radius) * Mathf.Rad2Deg;
drawStartDegree += diffDegree;
drawEndDegree -= diffDegree;
var px = Mathf.Sin(drawStartDegree * Mathf.Deg2Rad) * radius;
var py = Mathf.Cos(drawStartDegree * Mathf.Deg2Rad) * radius;
var pos = new Vector3(px, py) + centerPos;
ChartDrawer.DrawSector(vh, pos, width, color, drawStartDegree + 180, drawStartDegree + 360);
px = Mathf.Sin(drawEndDegree * Mathf.Deg2Rad) * radius;
py = Mathf.Cos(drawEndDegree * Mathf.Deg2Rad) * radius;
pos = new Vector3(px, py) + centerPos;
ChartDrawer.DrawSector(vh, pos, width, color, drawEndDegree, drawEndDegree + 180);
}
}
private void DrawLabelLine(VertexHelper vh)
{
foreach (var serie in m_Series.list)
{
if (serie.type == SerieType.Pie && serie.label.show)
if (serie.type == SerieType.Pie)
{
foreach (var serieData in serie.data)
{
if (serieData.canShowLabel)
var serieLabel = serieData.GetSerieLabel(serie.label);
if (serieLabel.show && serieData.canShowLabel)
{
int colorIndex = m_LegendRealShowName.IndexOf(serieData.name);
Color color = m_ThemeInfo.GetColor(colorIndex);
@@ -193,11 +227,12 @@ namespace XCharts
{
foreach (var serie in m_Series.list)
{
if (serie.type == SerieType.Pie && serie.label.show)
if (serie.type == SerieType.Pie)
{
foreach (var serieData in serie.data)
{
if (serieData.canShowLabel)
var serieLabel = serieData.GetSerieLabel(serie.label);
if (serieLabel.show && serieData.canShowLabel)
{
UpdateLabelPostion(serie, serieData);
DrawLabelBackground(vh, serie, serieData);
@@ -209,86 +244,89 @@ namespace XCharts
private void DrawLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
{
if (serie.label.show
&& serie.label.position == SerieLabel.Position.Outside
&& serie.label.line)
var serieLabel = serieData.GetSerieLabel(serie.label);
if (serieLabel.show
&& serieLabel.position == SerieLabel.Position.Outside
&& serieLabel.line)
{
var insideRadius = serieData.runtimePieInsideRadius;
var outSideRadius = serieData.runtimePieOutsideRadius;
var center = serie.runtimePieCenterPos;
var center = serie.runtimeCenterPos;
var currAngle = serieData.runtimePieHalfAngle;
if (serie.label.lineColor != Color.clear) color = serie.label.lineColor;
else if (serie.label.lineType == SerieLabel.LineType.HorizontalLine) color *= color;
if (serieLabel.lineColor != Color.clear) color = serieLabel.lineColor;
else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine) color *= color;
float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad);
float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
var radius1 = serie.label.lineType == SerieLabel.LineType.HorizontalLine ?
serie.runtimePieOutsideRadius : outSideRadius;
var radius2 = serie.runtimePieOutsideRadius + serie.label.lineLength1;
var radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ?
serie.runtimeOutsideRadius : outSideRadius;
var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1;
var radius3 = insideRadius + (outSideRadius - insideRadius) / 2;
if (radius1 < serie.runtimeInsideRadius) radius1 = serie.runtimeInsideRadius;
radius1 -= 0.1f;
var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos);
var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos);
var pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
float tx, ty;
Vector3 pos3, pos4, pos6;
var horizontalLineCircleRadius = serie.label.lineWidth * 4f;
var horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
var lineCircleDiff = horizontalLineCircleRadius - 0.3f;
if (currAngle < 90)
{
ty = serie.label.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
tx = serie.label.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x - tx, pos2.y + ty - serie.label.lineWidth);
ty = serieLabel.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
tx = serieLabel.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x - tx, pos2.y + ty - serieLabel.lineWidth);
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serie.label.lineLength1 - lineCircleDiff;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.right * lineCircleDiff;
pos4 = pos6 + Vector3.right * r4;
}
else if (currAngle < 180)
{
ty = serie.label.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
tx = serie.label.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x - tx, pos2.y - ty + serie.label.lineWidth);
ty = serieLabel.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
tx = serieLabel.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x - tx, pos2.y - ty + serieLabel.lineWidth);
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serie.label.lineLength1 - lineCircleDiff;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.right * lineCircleDiff;
pos4 = pos6 + Vector3.right * r4;
}
else if (currAngle < 270)
{
ty = serie.label.lineWidth * Mathf.Sin((180 + currAngle) * Mathf.Deg2Rad);
tx = serie.label.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
ty = serieLabel.lineWidth * Mathf.Sin((180 + currAngle) * Mathf.Deg2Rad);
tx = serieLabel.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x + tx, pos2.y - ty + serie.label.lineWidth);
pos3 = new Vector3(pos2.x + tx, pos2.y - ty + serieLabel.lineWidth);
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
r4 += serie.label.lineLength1 - lineCircleDiff;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.left * lineCircleDiff;
pos4 = pos6 + Vector3.left * r4;
}
else
{
ty = serie.label.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
tx = serie.label.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x + tx, pos2.y + ty - serie.label.lineWidth);
ty = serieLabel.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
tx = serieLabel.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
pos3 = new Vector3(pos2.x + tx, pos2.y + ty - serieLabel.lineWidth);
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
r4 += serie.label.lineLength1 - lineCircleDiff;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.left * lineCircleDiff;
pos4 = pos6 + Vector3.left * r4;
}
var pos5 = new Vector3(currAngle > 180 ? pos3.x - serie.label.lineLength2 : pos3.x + serie.label.lineLength2, pos3.y);
switch (serie.label.lineType)
var pos5 = new Vector3(currAngle > 180 ? pos3.x - serieLabel.lineLength2 : pos3.x + serieLabel.lineLength2, pos3.y);
switch (serieLabel.lineType)
{
case SerieLabel.LineType.BrokenLine:
ChartDrawer.DrawLine(vh, pos1, pos2, serie.label.lineWidth, color);
ChartDrawer.DrawLine(vh, pos3, pos5, serie.label.lineWidth, color);
ChartDrawer.DrawLine(vh, pos1, pos2, serieLabel.lineWidth, color);
ChartDrawer.DrawLine(vh, pos3, pos5, serieLabel.lineWidth, color);
break;
case SerieLabel.LineType.Curves:
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serie.label.lineWidth, color, m_Settings.lineSmoothness);
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, m_Settings.lineSmoothness);
break;
case SerieLabel.LineType.HorizontalLine:
ChartDrawer.DrawCricle(vh, pos0, horizontalLineCircleRadius, color);
ChartDrawer.DrawLine(vh, pos6, pos4, serie.label.lineWidth, color);
ChartDrawer.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color);
break;
}
}
@@ -334,13 +372,14 @@ namespace XCharts
if (serieData.labelText == null) return;
var currAngle = serieData.runtimePieHalfAngle;
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
var showLabel = ((serie.label.show || isHighlight) && serieData.canShowLabel);
if (showLabel || serieData.showIcon)
var serieLabel = serieData.GetSerieLabel(serie.label);
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
if (showLabel || serieData.iconStyle.show)
{
serieData.SetLabelActive(showLabel);
float rotate = 0;
bool isInsidePosition = serie.label.position == SerieLabel.Position.Inside;
if (serie.label.rotate > 0 && isInsidePosition)
bool isInsidePosition = serieLabel.position == SerieLabel.Position.Inside;
if (serieLabel.rotate > 0 && isInsidePosition)
{
if (currAngle > 180) rotate += 270 - currAngle;
else rotate += -(currAngle - 90);
@@ -350,16 +389,16 @@ namespace XCharts
{
if (serie.emphasis.label.color != Color.clear) color = serie.emphasis.label.color;
}
else if (serie.label.color != Color.clear)
else if (serieLabel.color != Color.clear)
{
color = serie.label.color;
color = serieLabel.color;
}
else
{
color = isInsidePosition ? Color.white : serieColor;
}
var fontSize = isHighlight ? serie.emphasis.label.fontSize : serie.label.fontSize;
var fontStyle = isHighlight ? serie.emphasis.label.fontStyle : serie.label.fontStyle;
var fontSize = isHighlight ? serie.emphasis.label.fontSize : serieLabel.fontSize;
var fontStyle = isHighlight ? serie.emphasis.label.fontStyle : serieLabel.fontStyle;
serieData.labelText.color = color;
serieData.labelText.fontSize = fontSize;
@@ -368,15 +407,20 @@ namespace XCharts
serieData.labelRect.transform.localEulerAngles = new Vector3(0, 0, rotate);
UpdateLabelPostion(serie, serieData);
if (!string.IsNullOrEmpty(serie.label.formatter))
if (!string.IsNullOrEmpty(serieLabel.formatter))
{
var value = serieData.data[1];
var total = serie.yTotal;
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
var content = serieLabel.GetFormatterContent(serie.name, serieData.name, value, total);
if (serieData.SetLabelText(content)) RefreshChart();
}
else
{
if (serieData.SetLabelText(serieData.name)) RefreshChart();
}
serieData.SetGameObjectPosition(serieData.labelPosition);
if (showLabel) serieData.SetLabelPosition(serie.label.offset);
if (showLabel) serieData.SetLabelPosition(serieLabel.offset);
else serieData.SetLabelActive(false);
}
else
{
@@ -387,53 +431,55 @@ namespace XCharts
protected void UpdateLabelPostion(Serie serie, SerieData serieData)
{
if (serieData.labelText == null) return;
var currAngle = serieData.runtimePieHalfAngle;
var currRad = currAngle * Mathf.Deg2Rad;
var offsetRadius = serieData.runtimePieOffsetRadius;
var insideRadius = serieData.runtimePieInsideRadius;
var outsideRadius = serieData.runtimePieOutsideRadius;
switch (serie.label.position)
var serieLabel = serieData.GetSerieLabel(serie.label);
switch (serieLabel.position)
{
case SerieLabel.Position.Center:
serieData.labelPosition = serie.runtimePieCenterPos;
serieData.labelPosition = serie.runtimeCenterPos;
break;
case SerieLabel.Position.Inside:
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
var labelCenter = new Vector2(serie.runtimePieCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimePieCenterPos.y + labelRadius * Mathf.Cos(currRad));
var labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
serieData.labelPosition = labelCenter;
break;
case SerieLabel.Position.Outside:
if (serie.label.lineType == SerieLabel.LineType.HorizontalLine)
if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine)
{
var radius1 = serie.runtimePieOutsideRadius;
var radius1 = serie.runtimeOutsideRadius;
var radius3 = insideRadius + (outsideRadius - insideRadius) / 2;
var currSin = Mathf.Sin(currRad);
var currCos = Mathf.Cos(currRad);
var pos0 = new Vector3(serie.runtimePieCenterPos.x + radius3 * currSin, serie.runtimePieCenterPos.y + radius3 * currCos);
var pos0 = new Vector3(serie.runtimeCenterPos.x + radius3 * currSin, serie.runtimeCenterPos.y + radius3 * currCos);
if (currAngle > 180)
{
currSin = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
currCos = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
}
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serie.label.lineLength1 + serie.label.lineWidth * 4;
r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
r4 += serieData.labelText.preferredWidth / 2;
serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
}
else
{
labelRadius = serie.runtimePieOutsideRadius + serie.label.lineLength1;
labelCenter = new Vector2(serie.runtimePieCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimePieCenterPos.y + labelRadius * Mathf.Cos(currRad));
labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
float labelWidth = serieData.labelText.preferredWidth;
if (currAngle > 180)
{
serieData.labelPosition = new Vector2(labelCenter.x - serie.label.lineLength2 - 5 - labelWidth / 2, labelCenter.y);
serieData.labelPosition = new Vector2(labelCenter.x - serieLabel.lineLength2 - 5 - labelWidth / 2, labelCenter.y);
}
else
{
serieData.labelPosition = new Vector2(labelCenter.x + serie.label.lineLength2 + 5 + labelWidth / 2, labelCenter.y);
serieData.labelPosition = new Vector2(labelCenter.x + serieLabel.lineLength2 + 5 + labelWidth / 2, labelCenter.y);
}
}
break;
@@ -462,17 +508,6 @@ namespace XCharts
RefreshChart();
}
private void UpdatePieCenter(Serie serie)
{
if (serie.pieCenter.Length < 2) return;
var centerX = serie.pieCenter[0] <= 1 ? chartWidth * serie.pieCenter[0] : serie.pieCenter[0];
var centerY = serie.pieCenter[1] <= 1 ? chartHeight * serie.pieCenter[1] : serie.pieCenter[1];
serie.runtimePieCenterPos = new Vector2(centerX, centerY);
var minWidth = Mathf.Min(chartWidth, chartHeight);
serie.runtimePieInsideRadius = serie.pieRadius[0] <= 1 ? minWidth * serie.pieRadius[0] : serie.pieRadius[0];
serie.runtimePieOutsideRadius = serie.pieRadius[1] <= 1 ? minWidth * serie.pieRadius[1] : serie.pieRadius[1];
}
protected override void CheckTootipArea(Vector2 local)
{
if (m_IsEnterLegendButtom) return;
@@ -508,9 +543,9 @@ namespace XCharts
private int GetPosPieIndex(Serie serie, Vector2 local)
{
if (serie.type != SerieType.Pie) return -1;
var dist = Vector2.Distance(local, serie.runtimePieCenterPos);
if (dist < serie.runtimePieInsideRadius || dist > serie.runtimePieOutsideRadius) return -1;
Vector2 dir = local - new Vector2(serie.runtimePieCenterPos.x, serie.runtimePieCenterPos.y);
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
if (dist < serie.runtimeInsideRadius || dist > serie.runtimeOutsideRadius) return -1;
Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y);
float angle = VectorAngle(Vector2.up, dir);
for (int i = 0; i < serie.data.Count; i++)
{

View File

@@ -218,6 +218,8 @@ namespace XCharts
continue;
}
var rate = serie.animation.GetCurrRate();
var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration();
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
@@ -262,7 +264,8 @@ namespace XCharts
if (n >= serieData.data.Count) break;
float min = radar.GetIndicatorMin(n);
float max = radar.GetIndicatorMax(n);
float value = serieData.data[n];
float value = serieData.GetCurrData(n, updateDuration);
if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0)
{
serie.GetMinMaxData(n, out min, out max);
@@ -320,6 +323,10 @@ namespace XCharts
serie.animation.CheckProgress(Time.deltaTime * speed);
RefreshChart();
}
if (dataChanging)
{
RefreshChart();
}
}
}

View File

@@ -41,9 +41,9 @@ namespace XCharts
}
else
{
if (f == 0) valueDic[value] = forceE ? value.ToString("E") : value.ToString();
else if (f == 1) valueDic[value] = value.ToString("f1");
else if (f == 2) valueDic[value] = value.ToString("f2");
if (f == 0) valueDic[value] = forceE ? value.ToString("E0") : value.ToString();
else if (f == 1) valueDic[value] = forceE ? value.ToString("E1") : value.ToString("f1");
else if (f == 2) valueDic[value] = forceE ? value.ToString("E2") : value.ToString("f2");
else valueDic[value] = (f > 3 || forceE) ? value.ToString("E0") : value.ToString(GetFn(f));
return valueDic[value];
}
@@ -103,9 +103,9 @@ namespace XCharts
}
}
internal static string GetAxisLabelName(string prefix, bool isYAxis,int axisIndex, int i)
internal static string GetAxisLabelName(string prefix, bool isYAxis, int axisIndex, int i)
{
int key = (isYAxis?2:1) * 1000000 + (axisIndex+1) * 100000 + i;
int key = (isYAxis ? 2 : 1) * 1000000 + (axisIndex + 1) * 100000 + i;
if (s_AxisLabelName.ContainsKey(key))
{
return s_AxisLabelName[key];

View File

@@ -41,6 +41,18 @@ namespace XCharts
SetActive(gameObject.transform, active);
}
public static void SetActive(Image image, bool active)
{
if (image == null) return;
SetActive(image.gameObject, active);
}
public static void SetActive(Text text, bool active)
{
if (text == null) return;
SetActive(text.gameObject, active);
}
/// <summary>
/// 通过设置scale实现是否显示优化性能减少GC
/// </summary>
@@ -357,6 +369,16 @@ namespace XCharts
color1.r == color2.r;
}
public static bool IsValueEqualsVector2(Vector2 v1, Vector2 v2)
{
return v1.x == v2.x && v1.y == v2.y;
}
public static bool IsValueEqualsVector3(Vector3 v1, Vector3 v2)
{
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
}
public static bool IsValueEqualsList<T>(List<T> list1, List<T> list2)
{
if (list1 == null || list2 == null) return false;
@@ -491,7 +513,8 @@ namespace XCharts
count++;
intvalue = (int)(value * Mathf.Pow(10, count));
}
return count;
if (count == 12 && (value == 0 || value == 1)) return 1;
else return count;
}
public static void AddEventListener(GameObject obj, EventTriggerType type,
@@ -586,5 +609,13 @@ namespace XCharts
Vector3 resultVec3 = center + point;
return resultVec3;
}
public static Vector3 GetPosition(Vector3 center, float angle, float radius)
{
var rad = angle * Mathf.Deg2Rad;
var px = Mathf.Sin(rad) * radius;
var py = Mathf.Cos(rad) * radius;
return center + new Vector3(px, py);
}
}
}

View File

@@ -24,8 +24,8 @@ namespace XCharts
public class XChartsMgr : MonoBehaviour
{
public const string version = "1.0.4";
public const int date = 20191105;
public const string version = "1.1.0";
public const int date = 20191217;
[SerializeField] private string m_NowVersion;
[SerializeField] private string m_NewVersion;

View File

@@ -1,7 +1,7 @@
{
"name": "com.monitor1394.xcharts",
"displayName": "XCharts",
"version": "1.0.4",
"version": "1.1.0",
"unity": "2018.3",
"description": "A charting and data visualization library for Unity.",
"keywords": [

View File

@@ -1,7 +1,7 @@
{
"version": "1.0.4",
"date": "20191105",
"checkdate": "20191105",
"desc": "欢迎 Github 上点 Star 支持,非常感谢!",
"version": "1.1.0",
"date": "20191217",
"checkdate": "20191217",
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
"homepage": "https://github.com/monitor1394/unity-ugui-XCharts"
}

View File

@@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 2d3606aaaf73f468984f4615b496f408
AssemblyDefinitionImporter:
guid: 926cd5f4d8406451cb0c54e3ae6f71cd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 05b7d15b7a92f4c1eb56dbf47522bf6c
guid: e7c05fe198b1e46eabc5896450bf9cec
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -8,7 +8,7 @@
using UnityEditor;
using UnityEngine;
namespace XCharts
namespace XChartsDemo
{
[CustomPropertyDrawer(typeof(ChartModule), true)]
public class ChartModuleDrawer : PropertyDrawer

View File

@@ -8,7 +8,7 @@
using UnityEditor;
namespace XCharts
namespace XChartsDemo
{
/// <summary>
/// Editor class used to edit UI BaseChart.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7a51c10c0ca30408fba6f8e59145ce69
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -9,8 +9,9 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using XCharts;
namespace XCharts
namespace XChartsDemo
{
[System.Serializable]
public class ChartModule
@@ -34,7 +35,7 @@ namespace XCharts
[SerializeField] private Color m_ButtonNormalColor;
[SerializeField] private Color m_ButtonSelectedColor;
[SerializeField] private Color m_ButtonHighlightColor;
[SerializeField] private List<ChartModule> m_ChartModule;
[SerializeField] private List<ChartModule> m_ChartModule = new List<ChartModule>();
private GameObject m_BtnClone;
private Theme m_SelectedTheme;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 85bc0178fe453471fb2706bf81a09235
guid: f81ca580204024b8db33b4646c549c4f
MonoImporter:
externalObjects: {}
serializedVersion: 2

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -1,8 +1,9 @@
# 教程5分钟上手XCharts
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XChartsAPI接口](XChartsAPI.md)
[XCharts配置项手册](XCharts配置项手册.md)
[XCharts问答](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts问答.md)
[XChartsAPI接口](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XChartsAPI.md)
[XCharts配置项手册](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts配置项手册.md)
## 获取和引入 XCharts
@@ -105,5 +106,6 @@ for (int i = 0; i < 10; i++)
你还可以用代码控制更多的参数,[XCharts配置项手册](XCharts配置项手册.md)里面的所有参数都是可以通过代码控制的。
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XChartsAPI接口](XChartsAPI.md)
[XCharts配置项手册](XCharts配置项手册.md)
[XCharts问答](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts问答.md)
[XChartsAPI接口](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XChartsAPI.md)
[XCharts配置项手册](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts配置项手册.md)

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 monitor1394
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,40 +0,0 @@
{
"dependencies": {
"com.unity.ads": "2.0.8",
"com.unity.analytics": "3.2.2",
"com.unity.collab-proxy": "1.2.15",
"com.unity.package-manager-ui": "2.0.7",
"com.unity.purchasing": "2.0.3",
"com.unity.textmeshpro": "1.3.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

View File

@@ -6,5 +6,6 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/XCharts/Demo/demo_xchart.unity
path: Assets/XChartsDemo/demo_xchart.unity
guid: 5adbd6df9174d6943b7eb8d23651ffd1
m_configObjects: {}

View File

@@ -1 +1 @@
m_EditorVersion: 2018.3.14f1
m_EditorVersion: 2017.4.27f1

137
README.md
View File

@@ -1,9 +1,9 @@
# XCharts
![license](https://img.shields.io/github/license/monitor1394/unity-ugui-XCharts)
![issues](https://img.shields.io/github/issues/monitor1394/unity-ugui-XCharts)
![issues](https://img.shields.io/github/stars/monitor1394/unity-ugui-XCharts)
![issues](https://img.shields.io/github/forks/monitor1394/unity-ugui-XCharts)
[![npm Package](https://img.shields.io/npm/v/unity-ugui-xcharts.svg)](https://www.npmjs.org/package/unity-ugui-xcharts)
[![downloads per month](http://img.shields.io/npm/dm/unity-ugui-xcharts.svg)](https://www.npmjs.org/package/unity-ugui-xcharts)
![qq](https://img.shields.io/badge/QQ群-202030963-green)
A powerful, easy-to-use, configurable charting and data visualization library for Unity.
@@ -127,137 +127,6 @@ XCharts的图表由组件和数据组成。不同的组件和数据可以组合
* 更新日志看这里☞ [XCharts更新日志](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/CHANGELOG.md)
* 新手教程看这里☞ [教程5分钟上手XCharts](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/教程5分钟上手XCharts.md)
## 结构
``` js
<root>
├── Demo // Demo
│ ├── Editor
│ │ ├── ChartModuleDrawer.cs
│ │ └── DemoEditor.cs
│ ├── Runtime
│ │ ├── Demo_Dynamic.cs
│ │ ├── Demo_LargeData.cs
│ │ ├── Demo_PieChart.cs
│ │ ├── Demo_Test.cs
│ │ ├── Demo.cs
│ │ ├── Demo00_CheatSheet.cs
│ │ ├── Demo10_LineChart.cs
│ │ ├── Demo11_AddSinCurve.cs
│ │ ├── Demo12_CustomDrawing.cs
│ │ ├── Demo13_LineSimple.cs
│ │ ├── Demo20_BarChart.cs
│ │ ├── Demo30_PieChart.cs
│ │ ├── Demo50_Scatter.cs
│ │ ├── Demo60_Heatmap.cs
│ └── demo-xchart.unity
├── Editor // Editor相关代码
│ ├── PropertyDrawers // 组件Drawer
│ │ ├── AnimationDrawer.cs
│ │ ├── AreaStyleDrawer.cs
│ │ ├── AxisDrawer.cs
│ │ ├── AxisLabelDrawer.cs
│ │ ├── AxisLineDrawer.cs
│ │ ├── AxisNameDrawer.cs
│ │ ├── AxisSplitAreaDrawer.cs
│ │ ├── AxisTickDrawer.cs
│ │ ├── DataZoomDrawer.cs
│ │ ├── EmphasisDrawer.cs
│ │ ├── GridDrawer.cs
│ │ ├── ItemStyleDrawer.cs
│ │ ├── LegendDrawer.cs
│ │ ├── LineArrowDrawer.cs
│ │ ├── LineStyleDrawer.cs
│ │ ├── LocationDrawer.cs
│ │ ├── RadarDrawer.cs
│ │ ├── RadarIndicatorDrawer.cs
│ │ ├── SerieDrawer.cs
│ │ ├── SerieLabelDrawer.cs
│ │ ├── SeriesDrawer.cs
│ │ ├── SerieSymbolDrawer.cs
│ │ ├── SettingsDrawer.cs
│ │ ├── ThemeInfoDrawer.cs
│ │ ├── TitleDrawer.cs
│ │ ├── TooltipDrawer.cs
│ │ ├── VisualMapDrawer.cs
│ │ ├── XAxisDrawer.cs
│ │ └── YAxisDrawer.cs
│ ├── Ultility // Editor相关工具类
│ │ └── ChartEditorHelper.cs
│ ├── BarChartEditor.cs
│ ├── BaseChartEditor.cs
│ ├── CoordinateChartEditor.cs
│ ├── HeatmapChartEditor.cs
│ ├── LineChartEditor.cs
│ ├── PieChartEditor.cs
│ ├── RadarChartEditor.cs
│ └── ScatterChartEditor.cs
└── Runtime // 核心代码
├── API // Chart API
│ ├── BaseChart_API.cs
│ └── CoordinateChart_API.cs
├── Component // Chart的主组件和子组件
│ ├── Main
│ │ ├── Axis.cs
│ │ ├── DataZoom.cs
│ │ ├── Grid.cs
│ │ ├── Legend.cs
│ │ ├── Radar.cs
│ │ ├── Serie.cs
│ │ ├── Series.cs
│ │ ├── Settings.cs
│ │ ├── Theme.cs
│ │ ├── Title.cs
│ │ ├── Tooltip.cs
│ │ └── VisualMap.cs
│ ├── Sub
│ │ ├── Animation.cs
│ │ ├── AreaStyle.cs
│ │ ├── AxisLabel.cs
│ │ ├── AxisLine.cs
│ │ ├── AxisName.cs
│ │ ├── AxisSplitName.cs
│ │ ├── AxisTick.cs
│ │ ├── Emphasis.cs
│ │ ├── ItemStyle.cs
│ │ ├── LineArrow.cs
│ │ ├── LineStyle.cs
│ │ ├── Location.cs
│ │ ├── SerieData.cs
│ │ ├── SerieLabel.cs
│ │ └── SerieSymbol.cs
│ ├── ChartComponent.cs
│ ├── MainComponent.cs
│ └── SubComponent.cs
├── Helper
├── Interface
│ ├── IJsonData.cs
│ └── IPropertyChanged.cs
├── Internal
│ ├── AxisPool.cs
│ ├── BaseChart.cs
│ ├── CoordinateChart_DrawBar.cs
│ ├── CoordinateChart_DrawHeatmap.cs
│ ├── CoordinateChart_DrawLine.cs
│ ├── CoordinateChart_DrawScatter.cs
│ ├── CoordinateChart.cs
│ ├── JsonDataSupport.cs
│ ├── ListPool.cs
│ └── ObjectPool.cs
├── Template
├── Utility
│ ├── ChartCached.cs
│ ├── ChartDrawer.cs
│ └── ChartHelper.cs
├── BarChart.cs
├── HeatmapChart.cs
├── LineChart.cs
├── PieChart.cs
├── RadarChart.cs
└── ScatterChart.cs
```
## 更新日志
[更新日志](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/CHANGELOG.md)