Compare commits

..

51 Commits

Author SHA1 Message Date
monitor1394
f130c8378a 发布v1.3.0版本 2020-03-11 22:04:40 +08:00
monitor1394
43c323153c 优化LineChartlabel偏移显示 2020-03-11 21:53:45 +08:00
monitor1394
64636b1f0f 优化清空并重新添加数据后的自动刷新问题 2020-03-11 08:41:42 +08:00
monitor1394
c42a46b1a9 增加LineChart的普通折线图可通过ignore参数设置忽略数据的支持 2020-03-10 12:35:19 +08:00
monitor1394
11f639ba8d 增加LineChart的普通折线图可通过设置ingore参数过滤数据的支持 2020-03-10 09:15:55 +08:00
monitor1394
7c0534098a 增加LineChart的普通折线图可通过设置ingore参数过滤数据的支持 2020-03-10 09:12:47 +08:00
monitor1394
9118fdb660 增加BarChart可通过ItemStyle配置边框的支持 2020-03-09 22:10:48 +08:00
monitor1394
1cf107f47b 增加RingChart环形图 2020-03-08 10:47:48 +08:00
monitor1394
16f7781e49 调整SeriearcShaped参数重命名为roundCap 2020-03-06 07:09:15 +08:00
monitor1394
ca5839576a 增加运行时和非运行时参数变更自动刷新图表 2020-03-05 20:25:19 +08:00
monitor1394
3ef5f9653a Merge branch 'master' of https://github.com/monitor1394/unity-ugui-XCharts 2020-03-02 18:00:05 +08:00
monitor1394
d6df474182 适配Unity2019版本 2020-03-02 17:59:57 +08:00
monitor1394
5cf7b5d571 重构Legend图例,改变样式,增加自定义图标等设置 2020-02-26 22:52:57 +08:00
monitor1394
8c1cc28776 修复快速添加的图表不响应事件的问题 2020-02-23 14:15:06 +08:00
monitor1394
d4426776b7 渐出动画 2020-02-23 11:17:46 +08:00
monitor1394
2468393f14 增加BaseChart.AnimationFadeOut()渐入动画,重构动画系统 2020-02-23 11:06:16 +08:00
monitor1394
70a303cb12 增加TextStylelineSpacing参数配置行间距 2020-02-13 09:23:30 +08:00
monitor1394
e5f136c954 增加RadarsplitLine参数配置分割线,去掉lineStyle参数 2020-02-12 19:13:44 +08:00
monitor1394
dd72e773e7 new feature 2020-02-11 21:33:58 +08:00
monitor1394
8459bccb1e 增加TooltipbackgroundImage参数配置背景图 2020-02-11 21:30:20 +08:00
monitor1394
c73e1d6e3f 增加TooltippaddingLeftRightpaddingTopBottom参数配置文字和边框的间距 2020-02-11 21:01:01 +08:00
monitor1394
695c2fe311 增加TooltiplineStyle参数配置指示线样式 2020-02-11 20:37:48 +08:00
monitor1394
29598de9b7 增加AxissplitLine参数控制分割线 2020-02-11 20:37:34 +08:00
monitor1394
d60ae1a5cf 增加Serieclip参数控制是否超出坐标系外裁剪 2020-02-10 18:30:05 +08:00
monitor1394
5443e4931a 修复报错 2020-02-08 15:16:28 +08:00
monitor1394
3cee08c434 newfeature 2020-02-08 14:51:31 +08:00
monitor1394
5246d59173 更新demo 2020-02-08 14:51:23 +08:00
monitor1394
5b923f9990 更新文档 2020-02-08 14:14:39 +08:00
monitor1394
c458d4c27c 优化TextLimit文本长度自适应 2020-02-08 14:14:24 +08:00
monitor1394
49ed5ac153 增加SerieSymbolgap参数控制图形标记的外留白距离 2020-02-08 14:13:45 +08:00
monitor1394
616d63a4de 增加TextLimit组件可以设置AxisLabel的文本自适应 2020-01-26 22:34:57 +08:00
monitor1394
8043b116a2 优化Tooltip设置itemFormatter时显示系列颜色 2020-01-20 19:25:08 +08:00
monitor1394
8b7955f498 增加Radar雷达图在inspector配置areaStyle的支持 2020-01-20 19:13:49 +08:00
monitor1394
ce11222784 发布v1.2.0版本 2020-01-15 22:05:53 +08:00
monitor1394
87059b2e7f newfeature 2020-01-15 22:02:32 +08:00
monitor1394
4e7bcceda3 增加AxisLabel格式化为整数的支持 2020-01-15 19:49:09 +08:00
monitor1394
c4f95d3c4f 增加折线图对数轴Log的支持 2020-01-15 19:41:21 +08:00
monitor1394
892b84829d 优化Demo 2020-01-09 21:49:02 +08:00
monitor1394
519063e5e0 修复当设置DataZoomminShowNum时可能异常的问题 2020-01-09 19:30:15 +08:00
monitor1394
9dea742254 修复当设置AxisLineonZero时刻度显示异常的问题 2020-01-08 19:33:30 +08:00
monitor1394
5b9652e48d 增加Mask遮罩遮挡支持 2020-01-08 19:05:56 +08:00
monitor1394
02915db85b 更新版本日期 2019-12-21 20:17:59 +08:00
monitor1394
db36d68788 增加Tooltip的单个数据项和标题的字符串模版格式器 2019-12-21 20:12:27 +08:00
monitor1394
0dbc2e1c5c 增加DataZoom的最小显示数据个数minShowNum 2019-12-21 20:00:58 +08:00
monitor1394
4c27359cc0 更新最新版本日期 2019-12-20 09:19:20 +08:00
monitor1394
44ebca4a39 更新雷达图API接口 2019-12-20 09:18:05 +08:00
monitor1394
c7272f1817 增加Demo40_Radar.cs雷达图代码操作Demo 2019-12-20 09:17:37 +08:00
monitor1394
4898b0060f 添加RadarChart相关API接口 2019-12-20 09:17:15 +08:00
monitor1394
3147eb156e 优化serie的name为空时的tooltip显示问题 2019-12-19 22:15:12 +08:00
monitor1394
6f8017f0bf 优化warning 2019-12-19 22:10:36 +08:00
monitor1394
7e6d7d72d7 优化Grid引起的warning问题 2019-12-19 22:10:19 +08:00
124 changed files with 367256 additions and 79465 deletions

View File

@@ -1,7 +1,40 @@
# 更新日志
* (2019.11.17) 发布`v1.1.0`版本
* (2020.03.11) 发布`v1.3.0`版本
* (2020.03.11) 优化`LineChart``label`偏移显示
* (2020.03.11) 优化清空并重新添加数据后的自动刷新问题
* (2020.03.10) 增加`LineChart`的普通折线图可通过`ignore`参数设置忽略数据的支持
* (2020.03.09) 增加`BarChart`可通过`ItemStyle`配置边框的支持
* (2020.03.08) 增加`RingChart`环形图
* (2020.03.05) 调整`Serie``arcShaped`参数重命名为`roundCap`
* (2020.03.05) 增加运行时和非运行时参数变更自动刷新图表
* (2020.02.26) 重构`Legend`图例,改变样式,增加自定义图标等设置
* (2020.02.23) 增加`BaseChart.AnimationFadeOut()`渐出动画,重构动画系统
* (2020.02.13) 增加`BaseChart.RefreshTooltip()`接口立即重新初始化`Tooltip`组件
* (2020.02.13) 增加`Tooltip``textStyle`参数配置内容文本样式,去掉`fontSize``fontStyle`参数
* (2020.02.13) 增加`TextStyle``lineSpacing`参数配置行间距
* (2020.02.11) 增加`Radar``splitLine`参数配置分割线,去掉`lineStyle`参数
* (2020.02.11) 增加`Tooltip``backgroundImage`参数配置背景图
* (2020.02.11) 增加`Tooltip``paddingLeftRight``paddingTopBottom`参数配置文字和边框的间距
* (2020.02.11) 增加`Tooltip``lineStyle`参数配置指示线样式
* (2020.02.11) 增加`Axis``splitLine`参数控制分割线,去掉`showSplitLine``splitLineType`参数(更新时需要重新设置分割线相关设置)
* (2020.02.10) 增加`Serie``clip`参数控制是否超出坐标系外裁剪(只适用于折线图、柱状图、散点图)
* (2020.02.08) 增加`SerieSymbol``gap`参数控制图形标记的外留白距离
* (2020.01.26) 增加`TextLimit`组件可以设置`AxisLabel`的文本自适应
* (2020.01.20) 优化`Tooltip`设置`itemFormatter`时显示系列颜色
* (2020.01.20) 增加`Radar`雷达图在`inspector`配置`areaStyle`的支持
* (2020.01.15) 发布`v1.2.0`版本
* (2020.01.15) 增加`AxisLabel`格式化为整数的支持(`{value:f0}`
* (2020.01.15) 增加折线图对数轴`Log`的支持
* (2020.01.09) 修复当设置`DataZoom``minShowNum`时可能异常的问题
* (2020.01.08) 修复当设置`AxisLine``onZero`时刻度显示异常的问题
* (2020.01.08) 增加`Mask`遮罩遮挡支持
* (2019.12.21) 增加`Tooltip`的单个数据项和标题的字符串模版格式器
* (2019.12.21) 增加`DataZoom`的最小显示数据个数`minShowNum`
* (2019.12.20) 增加`Demo40_Radar.cs`雷达图代码操作`Demo`
* (2019.12.20) 添加`RadarChart`相关API接口
* (2019.12.17) 发布`v1.1.0`版本
* (2019.12.16) 修复`Overlay`模式下不显示`Tooltip`的问题
* (2019.12.15) 增加`Title``TextStyle`支持
* (2019.12.11) 修复`Legend`都隐藏时`Value轴`还显示数值的问题
@@ -9,7 +42,7 @@
* (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题
* (2019.12.04) 优化和完善数据更新`UpdateData`接口
* (2019.12.03) 增加圆环饼图的圆角支持,参数:`serie.arcShaped`
* (2019.12.03) 增加数据更新动画,参数:`serie.animation.updateAnimation`
* (2019.12.03) 增加数据更新动画,参数:`serie.animation.dataChangeEnable`
* (2019.11.30) 增加`GaugeChart`仪表盘
* (2019.11.22) 修复`BarChart`清空数据重新赋值后`SerieLabel`显示异常的问题
* (2019.11.16) 修复`SerieLabel`设置`color`等参数不生效的问题

View File

@@ -27,7 +27,7 @@ namespace XCharts
{
updateTime = 0;
var serie = chart.series.GetSerie(0);
//serie.animation.updateAnimation = true;
//serie.animation.dataChangeEnable = true;
var dataCount = serie.dataCount;
if (chart is RadarChart)
{

View File

@@ -38,10 +38,12 @@ namespace XCharts
chart.RemoveData();
chart.AddSerie(SerieType.Line);
chart.AddSerie(SerieType.Line);
for (int i = 0; i < 10; i++)
{
chart.AddXAxisData("x" + i);
chart.AddData(0, Random.Range(10, 20));
chart.AddData(1, Random.Range(10, 20));
}
}
}

View File

@@ -0,0 +1,124 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
[DisallowMultipleComponent]
public class Demo40_Radar : MonoBehaviour
{
private RadarChart chart;
private Serie serie, serie1;
void Awake()
{
LoopDemo();
}
private void OnEnable()
{
LoopDemo();
}
void LoopDemo()
{
StopAllCoroutines();
StartCoroutine(RadarDemo());
}
IEnumerator RadarDemo()
{
StartCoroutine(RadarAdd());
yield return new WaitForSeconds(2);
StartCoroutine(RadarUpdate());
yield return new WaitForSeconds(2);
StartCoroutine(RadarAddMultiple());
yield return new WaitForSeconds(2);
LoopDemo();
}
IEnumerator RadarAdd()
{
chart = gameObject.GetComponent<RadarChart>();
if (chart == null) chart = gameObject.AddComponent<RadarChart>();
chart.RemoveRadar();
chart.RemoveData();
chart.title.text = "RadarChart - 雷达图";
chart.title.subText = "";
chart.legend.show = true;
chart.legend.location.align = Location.Align.TopLeft;
chart.legend.location.top = 60;
chart.legend.location.left = 2;
chart.legend.itemWidth = 70;
chart.legend.itemHeight = 20;
chart.legend.orient = Orient.Vertical;
chart.AddRadar(Radar.Shape.Polygon, new Vector2(0.5f, 0.4f), 0.4f);
chart.AddIndicator(0, "indicator1", 0, 100);
chart.AddIndicator(0, "indicator2", 0, 100);
chart.AddIndicator(0, "indicator3", 0, 100);
chart.AddIndicator(0, "indicator4", 0, 100);
chart.AddIndicator(0, "indicator5", 0, 100);
serie = chart.AddSerie(SerieType.Radar, "test");
serie.radarIndex = 0;
chart.AddData(0, new List<float> { 10, 20, 60, 40, 20 }, "data1");
chart.AddData(0, new List<float> { 40, 60, 90, 80, 70 }, "data2");
yield return new WaitForSeconds(1);
}
IEnumerator RadarUpdate()
{
chart.UpdateIndicator(0, 0, "new1", 0, 100);
chart.UpdateData(0, 0, new List<float> { 15, 30, 50, 60, 50 });
chart.UpdateDataName(0, 0, "new1");
yield return new WaitForSeconds(1);
}
IEnumerator RadarAddMultiple()
{
chart.RemoveRadar();
chart.RemoveData();
chart.title.text = "RadarChart - 多雷达图";
chart.title.subText = "";
chart.legend.show = true;
chart.legend.location.align = Location.Align.TopLeft;
chart.legend.location.top = 60;
chart.legend.location.left = 2;
chart.legend.itemWidth = 70;
chart.legend.itemHeight = 20;
chart.legend.orient = Orient.Vertical;
chart.AddRadar(Radar.Shape.Polygon, new Vector2(0.25f, 0.4f), 0.25f);
for (int i = 1; i <= 5; i++)
{
chart.AddIndicator(0, "radar1" + i, 0, 100);
}
chart.AddRadar(Radar.Shape.Circle, new Vector2(0.75f, 0.4f), 0.25f);
for (int i = 1; i <= 5; i++)
{
chart.AddIndicator(1, "radar2" + i, 0, 100);
}
serie = chart.AddSerie(SerieType.Radar, "test1");
serie.radarIndex = 0;
chart.AddData(0, new List<float> { 10, 20, 60, 40, 20 }, "data1");
serie1 = chart.AddSerie(SerieType.Radar, "test2");
serie1.radarIndex = 1;
chart.AddData(1, new List<float> { 10, 20, 60, 40, 20 }, "data2");
yield return new WaitForSeconds(1);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5420ab107823641e49c2df9e3556ea30
guid: cb56350d2a2b24960a7174a1d3f2ea56
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -37,8 +37,8 @@ namespace XCharts
serie.center[1] = 0.5f;
serie.radius[0] = 80;
serie.splitNumber = 5;
serie.animation.updateAnimation = true;
serie.arcShaped = true;
serie.animation.dataChangeEnable = true;
serie.roundCap = true;
serie.titleStyle.show = true;
serie.titleStyle.textStyle.offset = new Vector2(0, 20);

View File

@@ -19,29 +19,37 @@ namespace XCharts
void Awake()
{
chart = gameObject.GetComponent<BaseChart>();
var btnTrans = transform.parent.Find("Button");
if (btnTrans)
{
btnTrans.gameObject.GetComponent<Button>().onClick.AddListener(OnTestBtn);
}
}
void Update()
{
updateTime += Time.deltaTime;
if (chart && updateTime > 2)
if (Input.GetKeyDown(KeyCode.Space))
{
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));
}
}
AddData();
}
}
void OnTestBtn()
{
chart.ClearData();
}
void AddData()
{
chart.ClearData();
int count = Random.Range(5, 20);
for (int i = 0; i < count; i++)
{
(chart as CoordinateChart).AddXAxisData("x" + i);
if (Random.Range(1, 3) == 2)
chart.AddData(0, Random.Range(10, 200));
else
{
chart.UpdateData(0, Random.Range(0, dataCount), Random.Range(10, 90));
}
chart.AddData(0, Random.Range(10, 100));
}
}
}

View File

@@ -6,8 +6,6 @@
## `BaseChart`
---
* `BaseChart.themeInfo`:主题组件`ThemeInfo`
* `BaseChart.title`:标题组件`Title`
* `BaseChart.legend`:图例组件`Legend`
@@ -42,17 +40,18 @@
* `BaseChart.IsActiveByLegend(string legendName)`:获得指定图例名字的系列是否显示。
* `BaseChart.RefreshChart()`:在下一帧刷新图表。
* `BaseChart.RefreshLabel()`:在下一帧刷新文本标签。
* `BaseChart.RefreshTooltip()`:立即刷新`Tooltip`组件。
* `BaseChart.UpdateTheme(Theme theme)`:切换图表主题。
* `BaseChart.AnimationEnable(bool flag)`:启用或关闭起始动画。
* `BaseChart.AnimationStart()`开始初始动画。
* `BaseChart.AnimationStop()`:停止初始化动画。
* `BaseChart.AnimationReset()`重置初始动画,重新播放
* `BaseChart.AnimationEnable(bool flag)`:启用或关闭动画。
* `BaseChart.AnimationFadeIn()`渐入动画。
* `BaseChart.AnimationFadeOut()`:渐出动画。
* `BaseChart.AnimationPause()`暂停动画
* `BaseChart.AnimationResume()`:继续动画。
* `BaseChart.AnimationReset()`:重置动画。
* `BaseChart.ClickLegendButton(int legendIndex, string legendName, bool show)`:点击图例按钮。
## `CoordinateChart`
---
* `CoordinateChart.grid`:网格组件 `Grid`
* `CoordinateChart.xAxises`:左右两个 `X` 轴组件 `XAxis`
* `CoordinateChart.yAxises`:左右两个 `Y` 轴组件 `YAxis`
@@ -74,45 +73,48 @@
## `LineChart`
---
* 继承 `BaseChart`
* 继承自 `CoordinateChart`
## `BarChart`
---
* 继承自 `BaseChart`
* 继承自 `CoordinateChart`
## `PieChart`
---
* 继承自 `BaseChart`
## `RadarChart`
---
* 继承自 `BaseChart`
* `radars`:雷达组件列表 `Radar`
* `RadarChart.radars`:雷达坐标系组件列表 `Radar`
* `RadarChart.RemoveRadar()`:移除所有雷达坐标系组件。
* `RadarChart.AddRadar(Radar radar)`:添加雷达坐标系组件。
* `RadarChart.AddRadar(Radar.Shape shape, Vector2 center, float radius, int splitNumber = 5,float lineWidth = 0.6f, bool showIndicator = true, bool showSplitArea = true)`:添加雷达坐标系组件。
* `RadarChart.AddIndicator(int radarIndex, string name, float min, float max)`:添加指示器。
* `RadarChart.UpdateIndicator(int radarIndex, int indicatorIndex, string name, float min, float max)`:更新指示器。
* `RadarChart.GetRadar(int radarIndex)`:获得指定索引的雷达坐标系组件。
* `RadarChart.GetIndicator(int radarIndex, int indicatorIndex)`:获得指定雷达坐标系组件指定索引的指示器。
## `ScatterChart`
---
* 继承自 `BaseChart`
* 继承自 `CoordinateChart`
## `HeatmapChart`
---
* 继承自 `BaseChart`
* 继承自 `CoordinateChart`
## `RingChart`
* 继承自 `BaseChart`
* `RingChart.UpdateMax(int serieIndex, int dataIndex, float value)`:更新指定系列执行数据项的最大值。
* `RingChart.UpdateMax(int serieIndex, float value)`:更新指定系列的所有数据项的最大值。
* `RingChart.UpdateMax(float value)`:更新第一个系列第一个数据项的最大值。
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XCharts配置项手册](XCharts配置项手册.md)
[XCharts问答](XCharts问答.md)

View File

@@ -19,6 +19,7 @@
* [Serie-Scatter 散点图](#Serie-Scatter)
* [Serie-Heatmap 热力图](#Serie-Heatmap)
* [Serie-Gauge 仪表盘](#Serie-Gauge)
* [Serie-Ring 环形图](#Serie-Ring)
* [Settings 设置](#Settings)
* [Theme 主题](#Theme)
* [Tooltip 提示框](#Tooltip)
@@ -31,6 +32,7 @@
* [AxisLabel 坐标轴刻度标签](#AxisLabel)
* [AxisLine 坐标轴轴线](#AxisLine)
* [AxisName 坐标轴名称](#AxisName)
* [AxisSplitLine 坐标轴分割线条](#AxisSplitLine)
* [AxisSplitArea 坐标轴分割区域](#AxisSplitArea)
* [AxisTick 坐标轴刻度](#AxisTick)
* [Emphasis 高亮样式](#Emphasis)
@@ -42,6 +44,7 @@
* [SerieData 数据项](#SerieData)
* [SerieLabel 图形上的文本标签](#SerieLabel)
* [SerieSymbol 图形标记](#SerieSymbol)
* [TextLimit 文本自适应](#TextLimit)
* [TextStyle 文本样式](#TextStyle)
## `Theme`
@@ -116,12 +119,14 @@
* `Horizonal`:水平。
* `Vertical`:垂直。
* `location`:图例的显示位置 [Location](#Location)。
* `itemWidth`每个图例项的宽度。
* `itemHeight`每个图例项的高度。
* `itemWidth`图例标记的图形宽度。
* `itemHeight`图例标记的图形高度。
* `itemGap`:图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。
* `itemFontSize`:图例项的字体大小
* `itemAutoColor`:图例标记的图形是否自动匹配颜色
* `formatter`:图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{name}`
* `data`:图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 `name`(如果是饼图,也可以是饼图单个数据的 `name`)。如果 `data` 没有被指定,会自动从当前系列中获取。指定 `data` 时里面的数据项和 `serie` 匹配时才会生效。
* `icons`:自定义的图例标记图形。
* `textStyle`:图例的内容文本样式 [TextStyle](#TextStyle)。
相关接口:
@@ -142,7 +147,7 @@
* `Between`:显示在顶点之间。
* `radius`:雷达图的半径。
* `center`雷达图的中心点。数组的第一项是横坐标第二项是纵坐标。当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
* `splitLine`:分割线条 [AxisSplitLine](#AxisSplitLine)。
* `splitArea`:分割区域 [AxisSplitArea](#AxisSplitArea)。
* `indicator`:是否显示指示器。
* `indicatorGap`:指示器和雷达的间距。
@@ -155,13 +160,23 @@
* `min`:指示器的最小值,默认为 0 无限制。
* `textStyle`:文本样式 [TextStyle](#TextStyle)。
## `TextLimit`
* `enable`:是否启用文本自适应。默认为`true`
* `maxWidth`:设定最大宽度。默认为`0`表示自动获取,否则表示自定义。当文本的宽度大于该值进行裁剪。
* `gap`:两边留白像素距离。默认为`10`
* `suffix` 长度超出被裁剪后附加的后缀。默认为`...`
## `TextStyle`
* `rotate`:旋转。
* `offset`:偏移。
* `color`:颜色。
* `backgroundColor`:背景颜色。
* `font`:字体。
* `fontSize`:字体大小。
* `fontStyle`:字体风格。
* `lineSpacing`:行间距。
## `Tooltip`
@@ -175,18 +190,24 @@
* `Shadow`:阴影指示器。
* `None`:无指示器。
* `Corss`十字准星指示器。坐标轴显示Label和交叉线。
* `formatter`:提示框内容字符串模版格式器。支持用 `\n``<br/>` 换行。其中变量 `{a}`, `{b}`, `{c}`, `{d}` 在不同图表类型下代表数据含义为:
* `formatter`:提示框内容字符串模版格式器。支持用 `\n``<br/>` 换行。`formatter`不为空时,优先使用`formatter`,否则使用`itemFormatter`。示例:`{a}:{c}``{a1}:{c1:f1}`其中变量 `{a}`, `{b}`, `{c}`, `{d}` 在不同图表类型下代表数据含义为:
* 折线区域图、柱状条形图、K线图 : `{a}`(系列名称),`{b}`(类目值),`{c}`(数值), `{d}`(无)。
* 散点图(气泡)图 : `{a}`(系列名称),`{b}`(数据名称),`{c}`(数值数组), `{d}`(无)。
* 地图 : `{a}`(系列名称),`{b}`(区域名称),`{c}`(合并数值), `{d}`(无)。
* 饼图、仪表盘、漏斗图: `{a}`(系列名称),`{b}`(数据项名称),`{c}`(数值), `{d}`(百分比)。
* `titleFormatter`:提示框标题内容的字符串模版格式器。支持用 `\n``<br/>` 换行。仅当`itemFormatter`生效时才有效。
* `itemFormatter`:提示框单个`serie`或数据项内容的字符串模版格式器。支持用 `\n``<br/>` 换行。当`formatter`不为空时,优先使用`formatter`,否则使用`itemFormatter`
* `fixedWidth`:固定宽度。当同时设置 `fixedWidth``minWidth` 时,`fixedWidth``minWidth` 优先级高。
* `fixedHeight`:固定高度。当同时设置 `fixedHeight``minHeight` 时,`fixedHeight``minHeight` 优先级高。
* `minWidth`:最小宽度。当同时设置 `fixedWidth``minWidth` 时,`fixedWidth``minWidth` 优先级高。
* `minHeight`:最小高度。当同时设置 f`ixedHeight``minHeight` 时,`fixedHeight``minHeight` 优先级高。
* `fontSize`:文字的字体大小
* `fontStyle`:文字的字体风格
* `paddingLeftRight`:文字和边框的左右边距
* `paddingTopBottom`:文字和边框的上下边距
* `backgroundImage`:提示框的背景图。
* `forceENotation`是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
* `ignoreDataDefaultContent`:被忽略数据的默认显示字符信息。
* `lineStyle`:指示器线条样式 [LineStyle](#LineStyle)。
* `textStyle`:显示内容文本样式 [TextStyle](#TextStyle)。
## `DataZoom`
@@ -219,6 +240,7 @@
* `scrollSensitivity`:缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。
* `fontSize`:字体大小。
* `fontStyle`:字体样式。
* `minShowNum`最小显示数据个数。当DataZoom放大到最大时最小显示的数据个数。
## `VisualMap`
@@ -287,9 +309,12 @@
相关参数:
* `show`:是否显示 `X` 轴。默认 `xAxises[0]``true``xAxises[1]``false`
* `type`:坐标轴类型。默认为 `Category`有以下两种类型:
* `type`:坐标轴类型。默认为 `Category`支持以下类型:
* `Value`:数值轴,用于连续数据。
* `Category`:类目轴,适用于离散的类目数据,为该类型时必须通过 `data` 设置类目数据。
* `Log`:对数轴,适用于对数数据。
* `logBaseE`:对数轴是否以自然数 `e` 为底数,为 `true``logBase` 失效,只在对数轴(`type:'Log'`)中有效。
* `logBase`:对数轴的底数,只在对数轴(`type:'Log'`)中有效。
* `minMaxType`:坐标轴刻度最大最小值显示类型。默认为 `Default`。有以下三种类型:
* `Default`0-最大值。
* `MinMax`:最小值-最大值。
@@ -298,13 +323,6 @@
* `max`:设定的坐标轴刻度最大值,当 `minMaxType``Custom` 时有效。
* `splitNumber`:坐标轴的分割段数。默认为 `5`。当 `splitNumber` 设为 `0` 时,表示绘制所有的类目数据。
* `interval`:强制设置坐标轴分割间隔。无法在类目轴中使用。设置改值时 `splitNumber` 无效。
* `splitLineType`:分割线类型。默认为 `Dashed`。有以下五种类型:
* `None`:不显示分割线。
* `Solid`:实线。
* `Dashed`:虚线。
* `Dotted`:点线。
* `DashDot`:点划线。
* `DashDotDot`:双点划线。
* `boundaryGap`:坐标轴两边是否留白。默认为 `true`
* `maxCache`类目数据中可缓存的最大数据量。默认为0没有限制大于0时超过指定值会移除旧数据再插入新数据。
* `data`:类目数据,在类目轴(`type: 'Category'`)中有效。
@@ -312,7 +330,8 @@
* `axisName`:坐标轴名称相关配置 [AxisName](#AxisName)。
* `axisTick`:坐标轴刻度相关配置 [AxisTick](#AxisTick)。
* `axisLabel`:坐标轴刻度标签 [AxisLabel](#AxisLabel)。
* `splitArea`:坐标轴轴线坐标轴分割区域 [SplitArea](#SplitArea)。
* `splitLine`:坐标轴轴线坐标轴分割线 [AxisSplitLine](#SplitLine)。
* `splitArea`:坐标轴轴线坐标轴分割区域 [AxisSplitArea](#AxisSplitArea)。
相关接口:
@@ -419,7 +438,7 @@
* `pieSpace`:饼图项间的空隙留白。
* `pieCenter`:饼图的中心点。
* `pieRadius`:饼图的半径。`radius[0]` 表示内径,`radius[1]` 表示外径。
* `arcShaped`:启用弧形圆角效果。目前只在仪表盘和圆环饼图中有效
* `roundCap`:启用圆弧效果
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
@@ -446,6 +465,9 @@
* `Min`:取过滤点的最小值。
* `Sum`:取过滤点之和。
* `sampleAverage`:设定的采样平均值。当 `sampleType``Peak` 时,用于和过滤数据的平均值做对比是取最大值还是最小值。默认为`0`时会实时计算所有数据的平均值。
* `clip`:是否裁剪超出坐标系部分的图形。
* `ignore`:是否开启忽略数据。当为 `true` 时,数据值为 `ignoreValue` 时不进行绘制。
* `ignoreValue`:忽略数据的默认值。当 `ignore``true` 才有效。
* `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `lineType`:折线图样式类型。支持以下十种类型:
@@ -488,6 +510,7 @@
* `barCategoryGap`同一系列的柱间距离默认为类目间距的20%,可设固定值。在同一坐标系上,此属性会被多个 `'bar'` 系列共享。此属性应设置于此坐标系中最后一个 `'bar'` 系列上才会生效,并且是对此坐标系中所有 `'bar'` 系列生效。
* `barZebraWidth`:斑马线的粗细。`barType``Zebra` 时有效。
* `barZebraGap`:斑马线的间距。`barType``Zebra` 时有效。
* `clip`:是否裁剪超出坐标系部分的图形。
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `itemStyle`:柱条样式 [ItemStyle](#ItemStyle)。
* `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。
@@ -510,7 +533,7 @@
* `space`:扇区间隙。
* `center`中心点坐标。当值为0-1的浮点数时表示百分比。
* `radius`:半径。`radius[0]`为内径,`radius[1]`为外径。当内径大于0时即为圆环图。
* `arcShaped`:是否启用圆效果。只在圆环图中有效。
* `roundCap`:是否启用圆效果。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
@@ -525,6 +548,7 @@
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `radarIndex`:雷达图所使用的 `radar` 组件的 `index`
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
@@ -535,6 +559,7 @@
* `show`:系列是否显示在图表上。
* `type``Scatter`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `clip`:是否裁剪超出坐标系部分的图形。
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
@@ -570,7 +595,7 @@
* `startAngle`仪表盘起始角度。和时钟一样12点钟位置是0度顺时针到360度。
* `endAngle`仪表盘结束角度。和时钟一样12点钟位置是0度顺时针到360度。
* `splitNumber`:仪表盘刻度分割段数。
* `arcShaped`:是否启用圆效果。
* `roundCap`:是否启用圆效果。
* `titleStyle`:仪表盘标题 [TitleStyle](#TitleStyle)。
* `gaugeAxis` 仪表盘坐标轴 [GaugeAxis](#GaugeAxis)。
* `gaugePointer`:仪表盘指针 [GaugePointer](#GaugePointer)。
@@ -580,6 +605,26 @@
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。仪表盘的数据一般只有一个,值通过`label`样式显示,`name`通过`titleStyle`样式显示。
## `Serie-Ring`
环形图系列。
* `show`:系列是否显示在图表上。
* `type``Ring`
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `center`中心点坐标。当值为0-1的浮点数时表示百分比。
* `radius`:仪表盘半径。
* `startAngle`仪表盘起始角度。和时钟一样12点钟位置是0度顺时针到360度。
* `ringGap`:环形图的环间隙。
* `roundCap`:是否启用圆弧效果。
* `clockwise`:是否顺时针,默认为`true`
* `titleStyle`:环形图中心标题 [TitleStyle](#TitleStyle)。
* `itemStyle`:环形图的圆环样式,包括设置背景颜色和边框等 [ItemStyle](#ItemStyle)。
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
* `emphasis`:高亮样式 [Emphasis](#Emphasis)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。环形图的数据只有二维,`data[0]`表示当前值,`data[1]`表示最大值。
## `Settings`
全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
@@ -591,14 +636,13 @@
## `SerieAnimation`
* `enable`:是否开起始画效果
* `easing`:动画的缓动效果。支持以下动画效果:
* `Linear`:线性效果
* `duration`:设定的动画时长,单位毫秒。
* `updateAnimation`:是否开启数据变更动画
* `updateDuration`:数据变更动画时长,单位毫秒
* `threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画
* `delay`:动画延时,单位毫秒。
* `enable`:是否开启动画系统
* ~~`threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。~~
* `fadeInDelay`:设定的渐入动画延时,单位毫秒
* `fadeInDuration`:设定的渐入动画时长,单位毫秒。
* `fadeOutDuration`:设定的渐出动画时长,单位毫秒
* `dataChangeEnable`:是否开启数据变更动画
* `dataChangeDuration`:数据变更动画时长,单位毫秒
## `AreaStyle`
@@ -624,8 +668,9 @@
* `color`刻度标签文字的颜色默认取主题Theme的axisTextColor。
* `fontSize`:文字的字体大小。
* `fontStyle`:文字字体的风格。
* `formatter`:图例内容字符串模版格式器。支持用 \n 换行。模板变量为图例名称 {value}{value:f1} 表示取1为小数
* `formatter`:图例内容字符串模版格式器。支持用 \n 换行。模板变量为图例名称 {value}支持{value:f0}{value:f1}{value:f2}。
* `forceENotation`是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
* `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。
## `AxisLine`
@@ -652,6 +697,12 @@
* `fontSize`:坐标轴名称的文字大小。
* `fontStyle`:坐标轴名称的文字风格。
## `AxisSplitLine`
* `show`:是否显示坐标分割线。
* `interval`分割线的显示间隔。0表示显示所有分割线1表示隔一个隔显示一个分割线以此类推。
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
## `AxisSplitArea`
* `show`:是否显示坐标分割区域。
@@ -674,10 +725,14 @@
* `show`:是否启用。
* `color`:颜色。
* `backgroundColor`:背景颜色。
* `backgroundWidth`:背景的宽。
* `centerColor`:中心区域的颜色。如环形图的中心区域。
* `centerGap`:中心区域的间隙。如环形图的中心区域于最内环的间隙。
* `borderType`:边框的类型。
* `borderColor`:边框的颜色。
* `borderWidth`:边框宽。
* `borderWidth`opacity。
* `opacity`:透明度
## `LineArrow`
@@ -692,7 +747,7 @@
## `LineStyle`
* `show`:是否显示线条。在折线图中无效。
* `show`:是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
* `type`:线条类型。支持以下五种类型:
* `None`:不显示分割线。
* `Solid`:实线。
@@ -776,6 +831,7 @@
* `Triangle`:三角形。
* `Diamond`:菱形。
* `None`:不显示标记。
* `gap`:图形标记的外留白距离。
* `sizeType`:标记图形的大小获取方式。支持以下三种类型:
* `Custom`:自定义大小。
* `FromData`:通过 `dataIndex` 从数据中获取,再乘以一个比例系数 `dataScale`

View File

@@ -22,11 +22,12 @@ namespace XCharts
drawRect.height = EditorGUIUtility.singleLineHeight;
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_Easting = prop.FindPropertyRelative("m_Easting");
SerializedProperty m_FadeInDuration = prop.FindPropertyRelative("m_FadeInDuration");
SerializedProperty m_FadeOutDuration = prop.FindPropertyRelative("m_FadeOutDuration");
SerializedProperty m_DataChangeEnable = prop.FindPropertyRelative("m_DataChangeEnable");
SerializedProperty m_DataChangeDuration = prop.FindPropertyRelative("m_DataChangeDuration");
SerializedProperty m_FadeInDelay = prop.FindPropertyRelative("m_FadeInDelay");
SerializedProperty m_Threshold = prop.FindPropertyRelative("m_Threshold");
SerializedProperty m_ActualDuration = prop.FindPropertyRelative("m_ActualDuration");
// SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress");
@@ -37,23 +38,26 @@ namespace XCharts
if (ChartEditorHelper.IsToggle(m_AnimationModuleToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Easting);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
//EditorGUI.PropertyField(drawRect, m_Easting);
//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.PropertyField(drawRect, m_Delay);
if (m_Delay.floatValue < 0) m_Delay.floatValue = 0;
EditorGUI.PropertyField(drawRect, m_FadeInDelay);
if (m_FadeInDelay.floatValue < 0) m_FadeInDelay.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Duration);
if (m_Duration.floatValue < 0) m_Duration.floatValue = 0;
EditorGUI.PropertyField(drawRect, m_FadeInDuration);
if (m_FadeInDuration.floatValue < 0) m_FadeInDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_UpdateAnimation);
EditorGUI.PropertyField(drawRect, m_FadeOutDuration);
if (m_FadeOutDuration.floatValue < 0) m_FadeOutDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_UpdateDuration);
if (m_UpdateDuration.floatValue < 0) m_UpdateDuration.floatValue = 0;
EditorGUI.PropertyField(drawRect, m_DataChangeEnable);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_DataChangeDuration);
if (m_DataChangeDuration.floatValue < 0) m_DataChangeDuration.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);

View File

@@ -33,17 +33,18 @@ namespace XCharts
SerializedProperty m_Show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
SerializedProperty m_LogBaseE = prop.FindPropertyRelative("m_LogBaseE");
SerializedProperty m_LogBase = prop.FindPropertyRelative("m_LogBase");
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval");
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
SerializedProperty m_ShowSplitLine = prop.FindPropertyRelative("m_ShowSplitLine");
SerializedProperty m_SplitLineType = prop.FindPropertyRelative("m_SplitLineType");
SerializedProperty m_BoundaryGap = prop.FindPropertyRelative("m_BoundaryGap");
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine");
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
@@ -59,6 +60,13 @@ namespace XCharts
EditorGUI.indentLevel++;
EditorGUI.PropertyField(drawRect, m_Type);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (type == Axis.AxisType.Log)
{
EditorGUI.PropertyField(drawRect, m_LogBaseE);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LogBase);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
if (type == Axis.AxisType.Value)
{
EditorGUI.PropertyField(drawRect, m_MinMaxType);
@@ -80,27 +88,11 @@ namespace XCharts
break;
}
}
EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Interval);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_ShowSplitLine.boolValue)
{
drawRect.width = EditorGUIUtility.labelWidth + 10;
EditorGUI.PropertyField(drawRect, m_ShowSplitLine);
//drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.x = EditorGUIUtility.labelWidth + 35;
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 55;
EditorGUI.PropertyField(drawRect, m_SplitLineType, GUIContent.none);
drawRect.x = pos.x;
drawRect.width = pos.width;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
else
{
EditorGUI.PropertyField(drawRect, m_ShowSplitLine);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
EditorGUI.PropertyField(drawRect, m_BoundaryGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisLine);
@@ -115,6 +107,8 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, m_AxisLabel);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLabel);
EditorGUI.PropertyField(drawRect, m_SplitLine);
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine);
EditorGUI.PropertyField(drawRect, m_SplitArea);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
@@ -149,8 +143,9 @@ namespace XCharts
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
float height = 0;
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
if (type == Axis.AxisType.Category)
{
@@ -180,11 +175,21 @@ namespace XCharts
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
}
}
else if (type == Axis.AxisType.Log)
{
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
if (m_MinMaxType.enumValueIndex == (int)Axis.AxisMinMaxType.Custom)
{
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
}
}
height += EditorGUI.GetPropertyHeight(m_AxisName);
height += EditorGUI.GetPropertyHeight(m_AxisLine);
height += EditorGUI.GetPropertyHeight(m_AxisTick);
height += EditorGUI.GetPropertyHeight(m_AxisLabel);
height += EditorGUI.GetPropertyHeight(m_SplitArea);
height += EditorGUI.GetPropertyHeight(m_SplitLine);
return height;
}
}
@@ -192,7 +197,7 @@ namespace XCharts
private int InitToggle(SerializedProperty prop)
{
int index = 0;
int.TryParse(prop.displayName.Split(' ')[1],out index);
int.TryParse(prop.displayName.Split(' ')[1], out index);
if (index >= m_DataFoldout.Count)
{
m_DataFoldout.Add(false);

View File

@@ -30,6 +30,7 @@ namespace XCharts
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation");
SerializedProperty m_TextLimit = prop.FindPropertyRelative("m_TextLimit");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLabelToggle, prop, "Axis Label", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -54,6 +55,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ForceENotation);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TextLimit);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextLimit);
--EditorGUI.indentLevel;
}
}
@@ -63,7 +66,8 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_AxisLabelToggle, prop))
{
height += 9 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextLimit"));
}
return height;
}

View File

@@ -0,0 +1,55 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(AxisSplitLine), true)]
public class AxisSplitLineDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_AxisSplitLineToggle = 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_Interval = prop.FindPropertyRelative("m_Interval");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisSplitLineToggle, prop, "Split Line", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_AxisSplitLineToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Interval);
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)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_AxisSplitLineToggle, prop))
{
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
}
else
{
height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}
}

View File

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

View File

@@ -35,6 +35,7 @@ namespace XCharts
SerializedProperty m_RangeMode = prop.FindPropertyRelative("m_RangeMode");
SerializedProperty m_Start = prop.FindPropertyRelative("m_Start");
SerializedProperty m_End = prop.FindPropertyRelative("m_End");
SerializedProperty m_MinShowNum = prop.FindPropertyRelative("m_MinShowNum");
SerializedProperty m_ScrollSensitivity = prop.FindPropertyRelative("m_ScrollSensitivity");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
@@ -79,8 +80,11 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_End);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MinShowNum);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_Start.floatValue < 0) m_Start.floatValue = 0;
if (m_End.floatValue > 100) m_End.floatValue = 100;
if (m_MinShowNum.intValue < 0) m_MinShowNum.intValue = 0;
--EditorGUI.indentLevel;
}
}
@@ -91,7 +95,7 @@ namespace XCharts
int num = 1;
if (m_DataZoomModuleToggle)
{
num += 7;
num += 8;
if (prop.FindPropertyRelative("m_SupportSlider").boolValue) num += 6;
}

View File

@@ -22,6 +22,10 @@ namespace XCharts
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
SerializedProperty m_BackgroundWidth = prop.FindPropertyRelative("m_BackgroundWidth");
SerializedProperty m_CenterColor = prop.FindPropertyRelative("m_CenterColor");
SerializedProperty m_CenterGap = prop.FindPropertyRelative("m_CenterGap");
SerializedProperty m_BorderType = prop.FindPropertyRelative("m_BorderType");
SerializedProperty m_BorderWidth = prop.FindPropertyRelative("m_BorderWidth");
SerializedProperty m_BorderColor = prop.FindPropertyRelative("m_BorderColor");
@@ -33,6 +37,14 @@ namespace XCharts
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_CenterColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_CenterGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BorderType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BorderWidth);
@@ -50,7 +62,7 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_ItemStyleToggle, prop))
{
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -14,7 +14,9 @@ namespace XCharts
public class LegendDrawer : PropertyDrawer
{
private bool m_DataFoldout = false;
private bool m_IconsFoldout = false;
private int m_DataSize = 0;
private int m_IconsSize = 0;
private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText;
private bool m_LegendModuleToggle = false;
@@ -30,9 +32,11 @@ namespace XCharts
SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth");
SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight");
SerializedProperty itemGap = prop.FindPropertyRelative("m_ItemGap");
SerializedProperty itemFontSize = prop.FindPropertyRelative("m_ItemFontSize");
SerializedProperty m_ItemAutoColor = prop.FindPropertyRelative("m_ItemAutoColor");
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons");
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LegendModuleToggle, "Legend", show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -45,7 +49,7 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, itemGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, itemFontSize);
EditorGUI.PropertyField(drawRect, m_ItemAutoColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SelectedMode);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -57,12 +61,20 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop,pos.width);
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
drawRect.width = pos.width;
if (m_DataFoldout)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
}
m_IconsFoldout = EditorGUI.Foldout(drawRect, m_IconsFoldout, "Icons");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_IconsFoldout)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_IconsSize, m_Icons);
}
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel;
}
}
@@ -73,7 +85,7 @@ namespace XCharts
if (m_LegendModuleToggle)
{
SerializedProperty location = prop.FindPropertyRelative("m_Location");
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(location);
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout)
@@ -83,6 +95,14 @@ namespace XCharts
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.standardVerticalSpacing;
}
if (m_IconsFoldout)
{
SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons");
int num = m_Icons.arraySize + 1;
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.standardVerticalSpacing;
}
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
}
if (m_ShowJsonDataArea)
{

View File

@@ -19,7 +19,7 @@ namespace XCharts
SerializedProperty m_Radius;
SerializedProperty m_SplitNumber;
SerializedProperty m_Center;
SerializedProperty m_LineStyle;
SerializedProperty m_SplitLine;
SerializedProperty m_SplitArea;
SerializedProperty m_Indicator;
SerializedProperty m_IndicatorGap;
@@ -39,7 +39,7 @@ namespace XCharts
m_Radius = prop.FindPropertyRelative("m_Radius");
m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
m_Center = prop.FindPropertyRelative("m_Center");
m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
m_Indicator = prop.FindPropertyRelative("m_Indicator");
m_IndicatorGap = prop.FindPropertyRelative("m_IndicatorGap");
@@ -85,8 +85,8 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_SplitLine);
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine);
EditorGUI.PropertyField(drawRect, m_SplitArea);
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -112,7 +112,7 @@ namespace XCharts
propNum += 7;
if (m_IndicatorJsonAreaToggle) propNum += 4;
float height = propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitLine"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitArea"));
if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop))

View File

@@ -62,13 +62,17 @@ namespace XCharts
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
SerializedProperty m_StartAngle = prop.FindPropertyRelative("m_StartAngle");
SerializedProperty m_EndAngle = prop.FindPropertyRelative("m_EndAngle");
SerializedProperty m_RingGap = prop.FindPropertyRelative("m_RingGap");
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
//SerializedProperty m_Clockwise = prop.FindPropertyRelative("m_Clockwise");
SerializedProperty m_ArcShaped = prop.FindPropertyRelative("m_ArcShaped");
SerializedProperty m_Clockwise = prop.FindPropertyRelative("m_Clockwise");
SerializedProperty m_RoundCap = prop.FindPropertyRelative("m_RoundCap");
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_Clip = prop.FindPropertyRelative("m_Clip");
SerializedProperty m_Ignore = prop.FindPropertyRelative("m_Ignore");
SerializedProperty m_IgnoreValue = prop.FindPropertyRelative("m_IgnoreValue");
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
int index = InitToggle(prop);
@@ -118,6 +122,12 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SampleAverage);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Clip);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Ignore);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IgnoreValue);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_LineStyle);
@@ -159,6 +169,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BarZebraGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Clip);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
@@ -177,21 +189,47 @@ namespace XCharts
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);
EditorGUI.PropertyField(drawRect, m_RoundCap);
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.Ring:
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center");
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Radius, "Radius");
EditorGUI.PropertyField(drawRect, m_StartAngle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_RingGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_RoundCap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Clockwise);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TitleStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TitleStyle);
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;
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);
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
EditorGUI.PropertyField(drawRect, m_Clip);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_Label);
@@ -200,6 +238,8 @@ namespace XCharts
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Heatmap:
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);
@@ -226,7 +266,7 @@ namespace XCharts
{
m_SplitNumber.intValue = 36;
}
EditorGUI.PropertyField(drawRect, m_ArcShaped);
EditorGUI.PropertyField(drawRect, m_RoundCap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TitleStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TitleStyle);
@@ -377,23 +417,17 @@ namespace XCharts
}
if (showDetail)
{
EditorGUI.indentLevel++;
EditorGUI.indentLevel += 2;
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.PropertyField(drawRect, m_Label);
ChartEditorHelper.MakeBool(ref drawRect, m_EnableLabel, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.indentLevel--;
EditorGUI.indentLevel -= 2;
}
}
@@ -407,15 +441,12 @@ namespace XCharts
}
else
{
SerializedProperty type = prop.FindPropertyRelative("m_Type");
var serieType = (SerieType)type.enumValueIndex;
switch (serieType)
{
case SerieType.Line:
height += 13 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing;
height += 16 * EditorGUIUtility.singleLineHeight + 15 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow"));
@@ -426,7 +457,7 @@ namespace XCharts
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Bar:
height += 16 * EditorGUIUtility.singleLineHeight + 15 * EditorGUIUtility.standardVerticalSpacing;
height += 17 * EditorGUIUtility.singleLineHeight + 16 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
@@ -439,14 +470,25 @@ namespace XCharts
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Ring:
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TitleStyle"));
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;
case SerieType.Radar:
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
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 += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
@@ -454,6 +496,7 @@ namespace XCharts
break;
case SerieType.Heatmap:
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
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"));
@@ -488,10 +531,9 @@ namespace XCharts
for (int i = 0; i < num; i++)
{
var item = m_Data.GetArrayElementAtIndex(i);
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
//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 += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Label"));
}
}
}

View File

@@ -32,6 +32,7 @@ namespace XCharts
SerializedProperty m_StartIndex = prop.FindPropertyRelative("m_StartIndex");
SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval");
SerializedProperty m_ForceShowLast = prop.FindPropertyRelative("m_ForceShowLast");
SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieSymbolToggle, prop, null, m_Type, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -39,6 +40,8 @@ namespace XCharts
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Gap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SizeType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
SerieSymbolSizeType sizeType = (SerieSymbolSizeType)m_SizeType.enumValueIndex;
@@ -84,13 +87,13 @@ namespace XCharts
switch (sizeType)
{
case SerieSymbolSizeType.Custom:
return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
case SerieSymbolSizeType.FromData:
return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
case SerieSymbolSizeType.FromData:
return 11 * EditorGUIUtility.singleLineHeight + 11 * EditorGUIUtility.standardVerticalSpacing;
case SerieSymbolSizeType.Callback:
return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
}
return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -0,0 +1,53 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(TextLimit), true)]
public class TextLimitDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_TextLimitToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable");
SerializedProperty m_MaxWidth = prop.FindPropertyRelative("m_MaxWidth");
SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap");
SerializedProperty m_LimitSuffix = prop.FindPropertyRelative("m_Suffix");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextLimitToggle, prop, "Text Limit", m_Enable, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_TextLimitToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_MaxWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Gap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LimitSuffix);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_TextLimitToggle, prop))
{
height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}
}

View File

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

View File

@@ -14,49 +14,57 @@ 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)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Font = prop.FindPropertyRelative("m_Font");
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
// ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, "Text Style");
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
// {
// ++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Rotate);
SerializedProperty m_LineSpacing = prop.FindPropertyRelative("m_LineSpacing");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, null,null,false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset);
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// --EditorGUI.indentLevel;
// }
if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Font);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Rotate);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset);
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineSpacing);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
// float height = 0;
// if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
// {
// height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
// }
// else
// {
// height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
// }
float height = 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
float height = 0;
if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
{
height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
}
else
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}

View File

@@ -34,19 +34,16 @@ namespace XCharts
{
EditorGUI.PropertyField(drawRect, text);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
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_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.PropertyField(drawRect, location);
drawRect.y += EditorGUI.GetPropertyHeight(location);
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
EditorGUI.PropertyField(drawRect, m_SubTextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle);
}
--EditorGUI.indentLevel;
}

View File

@@ -21,14 +21,14 @@ namespace XCharts
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_textStyle = prop.FindPropertyRelative("m_textStyle");
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.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel;
}
}
@@ -39,7 +39,7 @@ namespace XCharts
if (ChartEditorHelper.IsToggle(m_TitleStyleToggle, prop))
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_textStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
}
else
{

View File

@@ -22,22 +22,33 @@ namespace XCharts
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty type = prop.FindPropertyRelative("m_Type");
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
SerializedProperty m_TitleFormatter = prop.FindPropertyRelative("m_TitleFormatter");
SerializedProperty m_ItemFormatter = prop.FindPropertyRelative("m_ItemFormatter");
SerializedProperty m_FixedWidth = prop.FindPropertyRelative("m_FixedWidth");
SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight");
SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth");
SerializedProperty m_MinHeight = prop.FindPropertyRelative("m_MinHeight");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation");
SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight");
SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom");
SerializedProperty m_BackgroundImage = prop.FindPropertyRelative("m_BackgroundImage");
SerializedProperty m_IgnoreDataDefaultContent = prop.FindPropertyRelative("m_IgnoreDataDefaultContent");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_TooltipModuleToggle)
{
EditorGUI.indentLevel++;
EditorGUI.PropertyField(drawRect, type);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Formatter);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TitleFormatter);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ItemFormatter);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FixedWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FixedHeight);
@@ -46,19 +57,30 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_MinHeight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
EditorGUI.PropertyField(drawRect, m_PaddingLeftRight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
EditorGUI.PropertyField(drawRect, m_PaddingTopBottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundImage);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ForceENotation);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IgnoreDataDefaultContent);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
EditorGUI.indentLevel--;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (m_TooltipModuleToggle)
return 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
return 14 * EditorGUIUtility.singleLineHeight + 13 * EditorGUIUtility.standardVerticalSpacing +
EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")) +
EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
else
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}

View File

@@ -79,17 +79,32 @@ public class ChartEditorHelper
float defaultX = drawRect.x;
drawRect.width = EditorGUIUtility.labelWidth;
moduleToggle = EditorGUI.Foldout(drawRect, moduleToggle, content, bold ? foldoutStyle : EditorStyles.foldout);
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2;
drawRect.width = 40;
if (prop != null)
{
EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
}
MakeBool(ref drawRect, prop);
drawRect.width = defaultWidth;
drawRect.x = defaultX;
return moduleToggle;
}
public static void MakeBool(ref Rect drawRect, SerializedProperty boolProp, int index = 0, string name = null)
{
float defaultWidth = drawRect.width;
float defaultX = drawRect.x;
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + index * 30;
drawRect.width = 20 + EditorGUI.indentLevel * 20;
if (boolProp != null)
{
EditorGUI.PropertyField(drawRect, boolProp, GUIContent.none);
drawRect.x += 13;
drawRect.width = 200;
if (!string.IsNullOrEmpty(name))
{
EditorGUI.LabelField(drawRect, name);
}
}
drawRect.width = defaultWidth;
drawRect.x = defaultX;
}
public static bool MakeFoldout(ref Rect drawRect, ref Dictionary<string, bool> moduleToggle, SerializedProperty prop,
string moduleName, SerializedProperty showProp = null, bool bold = true)
{
@@ -102,7 +117,7 @@ public class ChartEditorHelper
float defaultWidth = drawRect.width;
float defaultX = drawRect.x;
drawRect.width = EditorGUIUtility.labelWidth;
drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
var displayName = string.IsNullOrEmpty(moduleName) ? prop.displayName : moduleName;
toggle = EditorGUI.Foldout(drawRect, toggle, displayName, bold ? foldoutStyle : EditorStyles.foldout);
if (moduleToggle[key] != toggle)
@@ -114,7 +129,7 @@ public class ChartEditorHelper
{
if (showProp.propertyType == SerializedPropertyType.Boolean)
{
drawRect.width = 80;
drawRect.width = 100;
}
else
{

View File

@@ -8,6 +8,7 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace XCharts
{
@@ -28,6 +29,10 @@ namespace XCharts
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvasObject.AddComponent<CanvasScaler>();
canvasObject.AddComponent<GraphicRaycaster>();
var eventSystem = new GameObject();
eventSystem.name = "EventSystem";
eventSystem.AddComponent<EventSystem>();
eventSystem.AddComponent<StandaloneInputModule>();
return canvas.transform;
}
}
@@ -104,5 +109,11 @@ namespace XCharts
{
AddChart<GaugeChart>("GaugeChart");
}
[MenuItem("GameObject/XCharts/RingChart", priority = 51)]
public static void AddRingChart()
{
AddChart<RingChart>("RingChart");
}
}
}

View File

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

View File

@@ -21,7 +21,7 @@ namespace XCharts
/// <summary>
/// The theme info.
/// </summary>
public ThemeInfo themeInfo { get { return m_ThemeInfo; } }
public ThemeInfo themeInfo { get { return m_ThemeInfo; } set { m_ThemeInfo = value; } }
/// <summary>
/// The title setting of chart.
/// 标题组件
@@ -92,7 +92,9 @@ namespace XCharts
{
m_Series.ClearData();
m_Legend.ClearData();
m_Tooltip.ClearValue();
m_CheckAnimation = false;
m_ReinitLabel = true;
RefreshChart();
}
@@ -105,7 +107,9 @@ namespace XCharts
{
m_Legend.ClearData();
m_Series.RemoveAll();
m_Tooltip.ClearValue();
m_CheckAnimation = false;
m_ReinitLabel = true;
RefreshChart();
}
@@ -220,7 +224,7 @@ namespace XCharts
/// <param name="yValue">y data</param>
/// <param name="dataName">the name of data</param>
/// <returns>Returns True on success</returns>
public virtual SerieData AddData(string serieName, float xValue, float yValue, string dataName)
public virtual SerieData AddData(string serieName, float xValue, float yValue, string dataName = null)
{
var serieData = m_Series.AddXYData(serieName, xValue, yValue, dataName);
if (serieData != null)
@@ -402,9 +406,19 @@ namespace XCharts
var serie = m_Series.GetSerie(serieIndex);
if (serie != null && !string.IsNullOrEmpty(serie.name))
{
var legendIndex = m_LegendRealShowName.IndexOf(serie.name);
var bgColor1 = active ? m_ThemeInfo.GetColor(legendIndex) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(serie.name, bgColor1);
UpdateLegendColor(serie.name, active);
}
}
protected virtual void UpdateLegendColor(string legendName, bool active)
{
var legendIndex = m_LegendRealShowName.IndexOf(legendName);
if (legendIndex >= 0)
{
var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_ThemeInfo, active);
var contentColor = LegendHelper.GetContentColor(legend, m_ThemeInfo, active);
m_Legend.UpdateButtonColor(legendName, iconColor);
m_Legend.UpdateContentColor(legendName, contentColor);
}
}
@@ -482,6 +496,14 @@ namespace XCharts
m_ReinitLabel = true;
}
/// <summary>
/// 刷新Tooltip组件。
/// </summary>
public void RefreshTooltip()
{
InitTooltip();
}
/// <summary>
/// Update chart theme.
/// 切换图表主题。
@@ -515,32 +537,62 @@ namespace XCharts
m_Series.AnimationEnable(flag);
}
/// <summary>
/// Start play animation.
/// 开始初始动画。
/// </summary>
[Obsolete("Use BaseChart.AnimationFadeIn() instead.", true)]
public void AnimationStart()
{
m_Series.AnimationStart();
}
[Obsolete("Use BaseChart.AnimationFadeOut() instead.", true)]
public void MissAnimationStart()
{
}
/// <summary>
/// fadeIn animation.
/// 开始渐入动画。
/// </summary>
public void AnimationFadeIn()
{
m_Series.AnimationFadeIn();
RefreshChart();
}
/// <summary>
/// fadeIn animation.
/// 开始渐出动画。
/// </summary>
public void AnimationFadeOut()
{
m_Series.AnimationFadeOut();
RefreshChart();
}
/// <summary>
/// Pause animation.
/// 暂停动画。
/// </summary>
public void AnimationPause()
{
m_Series.AnimationPause();
RefreshChart();
}
/// <summary>
/// Stop play animation.
/// 停止初始化动画。
/// 继续动画。
/// </summary>
public void AnimationStop()
public void AnimationResume()
{
m_CheckAnimation = false;
m_Series.AnimationStop();
m_Series.AnimationResume();
RefreshChart();
}
/// <summary>
/// Reset animation to play.
/// 重置初始动画,重新播放
/// Reset animation.
/// 重置动画
/// </summary>
public void AnimationReset()
{
m_CheckAnimation = false;
m_Series.AnimationReset();
RefreshChart();
}
@@ -556,5 +608,34 @@ namespace XCharts
OnLegendButtonClick(legendIndex, legendName, show);
RefreshChart();
}
/// <summary>
/// 坐标是否在图表范围内
/// </summary>
/// <param name="local"></param>
/// <returns></returns>
public bool IsInChart(Vector2 local)
{
if (local.x < 0 || local.x > chartWidth ||
local.y < 0 || local.y > chartHeight)
{
return false;
}
return true;
}
public Vector3 ClampInChart(Vector3 pos)
{
if (IsInChart(pos)) return pos;
else
{
var np = new Vector3(pos.x, pos.y);
if (np.x < 0) np.x = 0;
if (np.x > chartWidth) np.x = chartWidth;
if (np.y < 0) np.y = 0;
if (np.y > chartHeight) np.y = chartHeight;
return np;
}
}
}
}

View File

@@ -129,7 +129,6 @@ namespace XCharts
public void AddXAxisData(string category, int xAxisIndex = 0)
{
m_XAxises[xAxisIndex].AddData(category);
m_XAxisChanged = true;
}
/// <summary>
@@ -141,23 +140,22 @@ namespace XCharts
public void AddYAxisData(string category, int yAxisIndex = 0)
{
m_YAxises[yAxisIndex].AddData(category);
m_YAxisChanged = true;
}
/// <summary>
/// reutrn true when all the show axis is `Value` type.
/// 纯数值坐标。
/// 纯数值坐标轴(数值轴或对数轴)
/// </summary>
/// <returns></returns>
public bool IsValue()
{
foreach (var axis in m_XAxises)
{
if (axis.show && !axis.IsValue()) return false;
if (axis.show && !axis.IsValue() && !axis.IsLog()) return false;
}
foreach (var axis in m_YAxises)
{
if (axis.show && !axis.IsValue()) return false;
if (axis.show && !axis.IsValue() && !axis.IsLog()) return false;
}
return true;
}
@@ -200,6 +198,20 @@ namespace XCharts
{
CheckMinMaxValue();
}
public Vector3 ClampInCoordinate(Vector3 pos)
{
if (IsInCooridate(pos)) return pos;
else
{
var np = new Vector3(pos.x, pos.y);
if (np.x < coordinateX) np.x = coordinateX;
if (np.x > coordinateX + coordinateWidth) np.x = coordinateX + coordinateWidth;
if (np.y < coordinateY) np.y = coordinateY;
if (np.y > coordinateY + coordinateHeight) np.y = coordinateY + coordinateHeight;
return np;
}
}
}
}

View File

@@ -0,0 +1,130 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public partial class RadarChart
{
/// <summary>
/// 雷达坐标系组件列表。
/// </summary>
public List<Radar> radars { get { return m_Radars; } }
/// <summary>
/// 移除所有数据,包含雷达坐标系指示器数据。
/// </summary>
public override void RemoveData()
{
base.RemoveData();
foreach (var radar in m_Radars)
{
radar.indicatorList.Clear();
}
}
/// <summary>
/// 移除所有雷达坐标系组件。
/// </summary>
public void RemoveRadar()
{
m_Radars.Clear();
}
/// <summary>
/// 添加雷达坐标系组件。
/// </summary>
public void AddRadar(Radar radar)
{
m_Radars.Add(radar);
}
/// <summary>
/// 添加雷达坐标系组件。
/// </summary>
/// <param name="shape">形状,圆形还是多边形</param>
/// <param name="center">中心点0-1浮点数时表示百分比</param>
/// <param name="radius">半径0-1浮点数时表示百分比</param>
/// <param name="splitNumber">指示器轴的分割段数</param>
/// <param name="lineWidth">线条宽</param>
/// <param name="showIndicator">是否显示指示器名称</param>
/// <param name="showSplitArea">是否显示分割区域</param>
/// <returns></returns>
public Radar AddRadar(Radar.Shape shape, Vector2 center, float radius, int splitNumber = 5,
float lineWidth = 0.6f, bool showIndicator = true, bool showSplitArea = true)
{
var radar = new Radar();
radar.shape = shape;
radar.splitNumber = splitNumber;
radar.radius = radius;
radar.indicator = showIndicator;
radar.center[0] = center.x;
radar.center[1] = center.y;
radar.splitArea.show = showSplitArea;
radar.splitLine.lineStyle.width = lineWidth;
m_Radars.Add(radar);
return radar;
}
/// <summary>
/// 添加指示器。
/// </summary>
/// <param name="radarIndex">雷达坐标系组件索引从0开始</param>
/// <param name="name">指示器名称</param>
/// <param name="min">指示器最小值</param>
/// <param name="max">指示器最大值</param>
/// <returns></returns>
public Radar.Indicator AddIndicator(int radarIndex, string name, float min, float max)
{
var radar = GetRadar(radarIndex);
if (radar == null) return null;
return radar.AddIndicator(name, min, max);
}
/// <summary>
/// 更新指示器。
/// </summary>
/// <param name="radarIndex">雷达坐标系组件的索引从0开始</param>
/// <param name="indicatorIndex">指示器索引从0开始</param>
/// <param name="name">指示器名称</param>
/// <param name="min">指示器最小值</param>
/// <param name="max">指示器最大值</param>
/// <returns></returns>
public bool UpdateIndicator(int radarIndex, int indicatorIndex, string name, float min, float max)
{
var radar = GetRadar(radarIndex);
if (radar == null) return false;
return radar.UpdateIndicator(indicatorIndex, name, min, max);
}
/// <summary>
/// 获得指定索引的雷达坐标系组件。
/// </summary>
/// <param name="radarIndex"></param>
/// <returns></returns>
public Radar GetRadar(int radarIndex)
{
if (radarIndex < 0 || radarIndex > m_Radars.Count - 1) return null;
return m_Radars[radarIndex];
}
/// <summary>
/// 获得指定雷达坐标系组件指定索引的指示器。
/// </summary>
/// <param name="radarIndex"></param>
/// <param name="indicatorIndex"></param>
/// <returns></returns>
public Radar.Indicator GetIndicator(int radarIndex, int indicatorIndex)
{
var radar = GetRadar(radarIndex);
if (radar != null) return radar.GetIndicator(indicatorIndex);
else return null;
}
}
}

View File

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

View File

@@ -0,0 +1,95 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public partial class RingChart
{
/// <summary>
/// 更新指定系列执行数据项的最大值
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="dataIndex"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool UpdateMax(int serieIndex, int dataIndex, float value)
{
var serie = m_Series.GetSerie(serieIndex);
if (serie != null)
{
var serieData = serie.GetSerieData(dataIndex);
if (serieData != null)
{
return serieData.UpdateData(1, value);
}
}
return false;
}
/// <summary>
/// 更新指定系列的所有数据项的最大值
/// </summary>
/// <param name="serieIndex"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool UpdateMax(int serieIndex, float value)
{
var serie = m_Series.GetSerie(serieIndex);
if (serie != null)
{
var flag = true;
foreach (var serieData in serie.data)
{
if (!serieData.UpdateData(1, value)) flag = false;
}
return flag;
}
return false;
}
/// <summary>
/// 更新第一个系列第一个数据项的最大值
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public bool UpdateMax(float value)
{
return UpdateMax(0, 0, value);
}
/// <summary>
/// Adds the data with the specified maximum value to the specified serie.
/// 添加指定最大值的数据到指定系列中。
/// </summary>
/// <param name="serieName">the name of serie</param>
/// <param name="value">the data</param>
/// <param name="max">the max data</param>
/// <param name="dataName">the name of data</param>
/// <returns>Returns True on success</returns>
public override SerieData AddData(string serieName, float value, float max, string dataName = null)
{
return base.AddData(serieName, value, max, dataName);
}
/// <summary>
/// Adds the data with the specified maximum value to the specified serie.
/// 添加指定最大值的数据到指定系列中。
/// </summary>
/// <param name="serieIndex">the index of serie</param>
/// <param name="value">the data</param>
/// <param name="max">the max data</param>
/// <param name="dataName">the name of data</param>
/// <returns>Returns True on success</returns>
public override SerieData AddData(int serieIndex, float value, float max, string dataName = null)
{
return base.AddData(serieIndex, value, max, dataName);
}
}
}

View File

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

View File

@@ -15,12 +15,26 @@ namespace XCharts
[SerializeField] protected string m_JsonData;
[SerializeField] protected bool m_DataFromJson;
[NonSerialized] protected bool m_VertsDirty;
[NonSerialized] protected bool m_ComponentDirty;
/// <summary>
/// json格式的字符串数据
/// </summary>
/// <returns></returns>
public string jsonData { get { return m_JsonData; } set { m_JsonData = value; ParseJsonData(value); } }
/// <summary>
/// 图表重绘标记。
/// </summary>
public virtual bool vertsDirty { get { return m_VertsDirty; } }
/// <summary>
/// 组件重新初始化标记。
/// </summary>
public virtual bool componentDirty { get { return m_ComponentDirty; } }
/// <summary>
/// 需要重绘图表或重新初始化组件。
/// </summary>
public bool anyDirty { get { return vertsDirty || componentDirty; } }
internal void OnAfterDeserialize()
{
if (m_DataFromJson)
@@ -38,5 +52,37 @@ namespace XCharts
{
throw new Exception("no support yet");
}
internal virtual void SetVerticesDirty()
{
m_VertsDirty = true;
}
internal virtual void ClearVerticesDirty()
{
m_VertsDirty = false;
}
internal virtual void SetComponentDirty()
{
m_ComponentDirty = true;
}
internal virtual void ClearComponentDirty()
{
m_ComponentDirty = false;
}
public virtual void ClearDirty()
{
ClearVerticesDirty();
ClearComponentDirty();
}
public virtual void SetAllDirty()
{
SetVerticesDirty();
SetComponentDirty();
}
}
}

View File

@@ -17,7 +17,7 @@ namespace XCharts
/// 直角坐标系的坐标轴组件。
/// </summary>
[System.Serializable]
public class Axis : MainComponent, IEquatable<Axis>
public class Axis : MainComponent
{
/// <summary>
/// the type of axis.
@@ -27,14 +27,19 @@ namespace XCharts
{
/// <summary>
/// Numerical axis, suitable for continuous data.
/// 数值轴适用于连续数据。
/// 数值轴适用于连续数据。
/// </summary>
Value,
/// <summary>
/// Category axis, suitable for discrete category data. Data should only be set via data for this type.
/// 类目轴适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。
/// 类目轴适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。
/// </summary>
Category
Category,
/// <summary>
/// Log axis, suitable for log data.
/// 对数轴。适用于对数数据。
/// </summary>
Log
}
/// <summary>
@@ -60,38 +65,6 @@ namespace XCharts
Custom
}
/// <summary>
/// the type of split line.
/// 分割线类型
/// </summary>
public enum SplitLineType
{
/// <summary>
/// 不显示分割线
/// </summary>
None,
/// <summary>
/// 实线
/// </summary>
Solid,
/// <summary>
/// 虚线
/// </summary>
Dashed,
/// <summary>
/// 点线
/// </summary>
Dotted,
/// <summary>
/// 点划线
/// </summary>
DashDot,
/// <summary>
/// 双点划线
/// </summary>
DashDotDot
}
[SerializeField] protected bool m_Show = true;
[SerializeField] protected AxisType m_Type;
[SerializeField] protected AxisMinMaxType m_MinMaxType;
@@ -99,15 +72,16 @@ namespace XCharts
[SerializeField] protected float m_Max;
[SerializeField] protected int m_SplitNumber = 5;
[SerializeField] protected float m_Interval = 0;
[SerializeField] protected bool m_ShowSplitLine = false;
[SerializeField] protected SplitLineType m_SplitLineType = SplitLineType.Dashed;
[SerializeField] protected bool m_BoundaryGap = true;
[SerializeField] protected int m_MaxCache = 0;
[SerializeField] protected float m_LogBase = 10;
[SerializeField] protected bool m_LogBaseE = false;
[SerializeField] protected List<string> m_Data = new List<string>();
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
[SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel;
[SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[NonSerialized] private float m_ValueRange;
@@ -117,88 +91,187 @@ namespace XCharts
/// Set this to false to prevent the axis from showing.
/// 是否显示坐标轴。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of axis.
/// 坐标轴类型。
/// </summary>
public AxisType type { get { return m_Type; } set { m_Type = value; } }
public AxisType type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetAllDirty(); }
}
/// <summary>
/// the type of axis minmax.
/// 坐标轴刻度最大最小值显示类型。
/// </summary>
public AxisMinMaxType minMaxType { get { return m_MinMaxType; } set { m_MinMaxType = value; } }
public AxisMinMaxType minMaxType
{
get { return m_MinMaxType; }
set { if (PropertyUtility.SetStruct(ref m_MinMaxType, value)) SetAllDirty(); }
}
/// <summary>
/// The minimun value of axis.
/// 设定的坐标轴刻度最小值当minMaxType为Custom时有效。
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
public float min
{
get { return m_Min; }
set { if (PropertyUtility.SetStruct(ref m_Min, value)) SetAllDirty(); }
}
/// <summary>
/// The maximum value of axis.
/// 设定的坐标轴刻度最大值当minMaxType为Custom时有效。
/// </summary>
public float max { get { return m_Max; } set { m_Max = value; } }
public float max
{
get { return m_Max; }
set { if (PropertyUtility.SetStruct(ref m_Max, value)) SetAllDirty(); }
}
/// <summary>
/// Number of segments that the axis is split into.
/// 坐标轴的分割段数。
/// </summary>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
/// <summary>
/// 强制设置坐标轴分割间隔。无法在类目轴中使用。
/// Compulsively set segmentation interval for axis.This is unavailable for category axis.
/// </summary>
public float interval { get { return m_Interval; } set { m_Interval = value; } }
/// <summary>
/// showSplitLineSet this to false to prevent the splitLine from showing. value type axes are shown by default, while category type axes are hidden.
/// 是否显示分隔线。默认数值轴显示,类目轴不显示。
/// </summary>
public bool showSplitLine { get { return m_ShowSplitLine; } set { m_ShowSplitLine = value; } }
/// <summary>
/// the type of split line.
/// 分割线类型。
/// </summary>
public SplitLineType splitLineType { get { return m_SplitLineType; } set { m_SplitLineType = value; } }
public float interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetAllDirty(); }
}
/// <summary>
/// The boundary gap on both sides of a coordinate axis.
/// 坐标轴两边是否留白。
/// </summary>
public bool boundaryGap { get { return m_BoundaryGap; } set { m_BoundaryGap = value; } }
public bool boundaryGap
{
get { return m_BoundaryGap; }
set { if (PropertyUtility.SetStruct(ref m_BoundaryGap, value)) SetAllDirty(); }
}
/// <summary>
/// Base of logarithm, which is valid only for numeric axes with type: 'Log'.
/// 对数轴的底数只在对数轴type:'Log')中有效。
/// </summary>
public float logBase
{
get { return m_LogBase; }
set { if (PropertyUtility.SetStruct(ref m_LogBase, value)) SetAllDirty(); }
}
/// <summary>
/// 对数轴是否以自然数 e 为底数,为 true 时 logBase 失效。
/// </summary>
public bool logBaseE
{
get { return m_LogBaseE; }
set { if (PropertyUtility.SetStruct(ref m_LogBaseE, value)) SetAllDirty(); }
}
/// <summary>
/// The max number of axis data cache.
/// The first data will be remove when the size of axis data is larger then maxCache.
/// 可缓存的最大数据量。默认为0没有限制大于0时超过指定值会移除旧数据再插入新数据。
/// </summary>
public int maxCache { get { return m_MaxCache; } set { m_MaxCache = value < 0 ? 0 : value; } }
public int maxCache
{
get { return m_MaxCache; }
set { if (PropertyUtility.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// Category data, available in type: 'Category' axis.
/// 类目数据在类目轴type: 'category')中有效。
/// </summary>
public List<string> data { get { return m_Data; } set { if (value != null) m_Data = value; } }
public List<string> data
{
get { return m_Data; }
set { if (value != null) { m_Data = value; SetAllDirty(); } }
}
/// <summary>
/// axis Line.
/// 坐标轴轴线。
/// </summary>
public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
/// /// </summary>
public AxisLine axisLine
{
get { return m_AxisLine; }
set { if (value != null) { m_AxisLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis name.
/// 坐标轴名称。
/// </summary>
public AxisName axisName { get { return m_AxisName; } set { m_AxisName = value; } }
public AxisName axisName
{
get { return m_AxisName; }
set { if (value != null) { m_AxisName = value; SetComponentDirty(); } }
}
/// <summary>
/// axis tick.
/// 坐标轴刻度。
/// </summary>
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
public AxisTick axisTick
{
get { return m_AxisTick; }
set { if (value != null) { m_AxisTick = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis label.
/// 坐标轴刻度标签。
/// </summary>
public AxisLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
public AxisLabel axisLabel
{
get { return m_AxisLabel; }
set { if (value != null) { m_AxisLabel = value; SetComponentDirty(); } }
}
/// <summary>
/// axis split line.
/// 坐标轴分割线。
/// </summary>
public AxisSplitLine splitLine
{
get { return m_SplitLine; }
set { if (value != null) { m_SplitLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis split area.
/// 坐标轴分割区域。
/// </summary>
public AxisSplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
public AxisSplitArea splitArea
{
get { return m_SplitArea; }
set { if (value != null) { m_SplitArea = value; SetVerticesDirty(); } }
}
public override bool vertsDirty
{
get { return m_VertsDirty || axisLine.anyDirty || axisTick.anyDirty || splitLine.anyDirty || splitArea.anyDirty; }
}
public override bool componentDirty
{
get { return m_ComponentDirty || axisName.anyDirty || axisLabel.anyDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
axisName.ClearComponentDirty();
axisLabel.ClearComponentDirty();
}
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
axisLine.ClearVerticesDirty();
axisTick.ClearVerticesDirty();
splitLine.ClearVerticesDirty();
splitArea.ClearVerticesDirty();
}
/// <summary>
/// the axis label text list.
/// 坐标轴刻度标签的Text列表。
@@ -213,20 +286,10 @@ namespace XCharts
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;
}
m_RuntimeMinValue = value;
m_RuntimeLastMinValue = value;
m_RuntimeMinValueUpdateTime = Time.time;
m_RuntimeMinValueChanged = true;
}
}
/// <summary>
@@ -238,20 +301,10 @@ namespace XCharts
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;
}
m_RuntimeMaxValue = value;
m_RuntimeLastMaxValue = value;
m_RuntimeMaxValueUpdateTime = Time.time;
m_RuntimeMaxValueChanged = false;
}
}
/// <summary>
@@ -264,9 +317,12 @@ namespace XCharts
/// 坐标轴原点在Y轴的偏移。
/// </summary>
public float runtimeZeroYOffset { get; internal set; }
public int runtimeMinLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMinValue) : (int)Mathf.Log(runtimeMinValue, logBase); } }
public int runtimeMaxLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMaxValue) : (int)Mathf.Log(runtimeMaxValue, logBase); } }
private int filterStart;
private int filterEnd;
private int filterMinShow;
private List<string> filterData;
private List<Text> m_AxisLabelTextList = new List<Text>();
private GameObject m_TooltipLabel;
@@ -283,35 +339,17 @@ namespace XCharts
private bool m_RuntimeMinValueFirstChanged = true;
private bool m_RuntimeMaxValueFirstChanged = true;
public void Copy(Axis other)
{
m_Show = other.show;
m_Type = other.type;
m_Min = other.min;
m_Max = other.max;
m_SplitNumber = other.splitNumber;
m_Interval = other.interval;
m_ShowSplitLine = other.showSplitLine;
m_SplitLineType = other.splitLineType;
m_BoundaryGap = other.boundaryGap;
m_AxisName.Copy(other.axisName);
m_AxisLabel.Copy(other.axisLabel);
m_Data.Clear();
m_Data.Capacity = m_Data.Count;
foreach (var d in other.data) m_Data.Add(d);
}
/// <summary>
/// 清空类目数据
/// </summary>
public void ClearData()
{
m_Data.Clear();
SetAllDirty();
}
/// <summary>
/// 当前坐标轴是否类目轴
/// 是否类目轴
/// </summary>
/// <returns></returns>
public bool IsCategory()
@@ -320,7 +358,7 @@ namespace XCharts
}
/// <summary>
/// 当前坐标轴是否数值轴
/// 是否数值轴
/// </summary>
/// <returns></returns>
public bool IsValue()
@@ -328,6 +366,15 @@ namespace XCharts
return type == AxisType.Value;
}
/// <summary>
/// 是否为对数轴。
/// </summary>
/// <returns></returns>
public bool IsLog()
{
return type == AxisType.Log;
}
/// <summary>
/// 添加一个类目到类目数据列表
/// </summary>
@@ -343,6 +390,7 @@ namespace XCharts
}
}
m_Data.Add(category);
SetAllDirty();
}
/// <summary>
@@ -389,15 +437,27 @@ namespace XCharts
{
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
if (startIndex != filterStart || endIndex != filterEnd || m_NeedUpdateFilterData)
if (endIndex < startIndex) endIndex = startIndex;
if (startIndex != filterStart || endIndex != filterEnd || dataZoom.minShowNum != filterMinShow || m_NeedUpdateFilterData)
{
filterStart = startIndex;
filterEnd = endIndex;
filterMinShow = dataZoom.minShowNum;
m_NeedUpdateFilterData = false;
if (m_Data.Count > 0)
{
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
filterData = m_Data.GetRange(startIndex, count);
if (count < dataZoom.minShowNum)
{
if (dataZoom.minShowNum > m_Data.Count) count = m_Data.Count;
else count = dataZoom.minShowNum;
}
if (startIndex + count > m_Data.Count)
{
int start = endIndex - count;
filterData = m_Data.GetRange(start < 0 ? 0 : start, count);
}
else filterData = m_Data.GetRange(startIndex, count);
}
else
{
@@ -434,6 +494,10 @@ namespace XCharts
}
else return m_SplitNumber;
}
else if (type == AxisType.Log)
{
return m_SplitNumber;
}
int dataCount = GetDataList(dataZoom).Count;
if (m_SplitNumber <= 0) return dataCount;
if (dataCount > 2 * m_SplitNumber || dataCount <= 0)
@@ -493,6 +557,7 @@ namespace XCharts
DataZoom dataZoom, bool forcePercent)
{
int split = GetSplitNumber(coordinateWidth, dataZoom);
if (m_Type == AxisType.Value)
{
if (minValue == 0 && maxValue == 0) return string.Empty;
@@ -510,6 +575,12 @@ namespace XCharts
if (forcePercent) return string.Format("{0}%", (int)value);
else return m_AxisLabel.GetFormatterContent(value, minValue, maxValue);
}
else if (m_Type == AxisType.Log)
{
float value = m_LogBaseE ? Mathf.Exp(runtimeMinLogIndex + index) :
Mathf.Pow(m_LogBase, runtimeMinLogIndex + index);
return m_AxisLabel.GetFormatterContent(value, minValue, maxValue, true);
}
var showData = GetDataList(dataZoom);
int dataCount = showData.Count;
if (dataCount <= 0) return "";
@@ -536,7 +607,7 @@ namespace XCharts
/// <returns></returns>
internal int GetScaleNumber(float coordinateWidth, DataZoom dataZoom)
{
if (type == AxisType.Value)
if (type == AxisType.Value || type == AxisType.Log)
{
int splitNum = GetSplitNumber(coordinateWidth, dataZoom);
return m_BoundaryGap ? splitNum + 1 : splitNum;
@@ -647,6 +718,15 @@ namespace XCharts
/// <param name="maxValue"></param>
internal void AdjustMinMaxValue(ref float minValue, ref float maxValue, bool needFormat)
{
if (m_Type == AxisType.Log)
{
int minSplit = 0;
int maxSplit = 0;
maxValue = ChartHelper.GetMaxLogValue(maxValue, m_LogBase, m_LogBaseE, out maxSplit);
minValue = ChartHelper.GetMinLogValue(minValue, m_LogBase, m_LogBaseE, out minSplit);
splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
return;
}
if (minMaxType == Axis.AxisMinMaxType.Custom)
{
if (min != 0 || max != 0)
@@ -688,11 +768,69 @@ namespace XCharts
m_ValueRange = maxValue - minValue;
}
internal void UpdateMinValue(float value, bool check)
{
if (value != m_RuntimeMaxValue)
{
if (check && Application.isPlaying)
{
if (m_RuntimeMinValueFirstChanged)
{
m_RuntimeMinValueFirstChanged = false;
}
else
{
m_RuntimeLastMinValue = m_RuntimeMinValue;
m_RuntimeMinValueChanged = true;
m_RuntimeMinValueUpdateTime = Time.time;
}
m_RuntimeMinValue = value;
}
else
{
m_RuntimeMinValue = value;
m_RuntimeLastMinValue = value;
m_RuntimeMinValueUpdateTime = Time.time;
m_RuntimeMinValueChanged = true;
}
}
}
internal void UpdateMaxValue(float value, bool check)
{
if (value != m_RuntimeMaxValue)
{
if (check && Application.isPlaying)
{
if (m_RuntimeMaxValueFirstChanged)
{
m_RuntimeMaxValueFirstChanged = false;
}
else
{
m_RuntimeLastMaxValue = m_RuntimeMaxValue;
m_RuntimeMaxValueChanged = true;
m_RuntimeMaxValueUpdateTime = Time.time;
}
m_RuntimeMaxValue = value;
}
else
{
m_RuntimeMaxValue = value;
m_RuntimeLastMaxValue = value;
m_RuntimeMaxValueUpdateTime = Time.time;
m_RuntimeMaxValueChanged = false;
}
}
}
internal float GetCurrMinValue(float duration)
{
if (!Application.isPlaying) return m_RuntimeMinValue;
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMinValueChanged) return m_RuntimeMinValue;
var time = Time.time - m_RuntimeMinValueUpdateTime;
if (time == 0) return m_RuntimeMinValue;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
@@ -708,11 +846,13 @@ namespace XCharts
internal float GetCurrMaxValue(float duration)
{
if (!Application.isPlaying) return m_RuntimeMaxValue;
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMaxValueChanged) return m_RuntimeMaxValue;
var time = Time.time - m_RuntimeMaxValueUpdateTime;
if (time == 0) return m_RuntimeMaxValue;
var total = duration / 1000;
if (duration > 0 && time <= total)
if (duration > 0 && time < total)
{
var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
return curr;
@@ -726,6 +866,7 @@ namespace XCharts
public bool IsValueChanging(float duration)
{
if (!Application.isPlaying) return false;
if (GetCurrMinValue(duration) != m_RuntimeMinValue || GetCurrMaxValue(duration) != m_RuntimeMaxValue)
{
return true;
@@ -736,65 +877,10 @@ namespace XCharts
}
}
public override bool Equals(object obj)
public float GetLogValue(float value)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Axis)
{
return Equals((Axis)obj);
}
else
{
return false;
}
}
public bool Equals(Axis other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return show == other.show &&
type == other.type &&
min == other.min &&
max == other.max &&
splitNumber == other.splitNumber &&
interval == other.interval &&
showSplitLine == other.showSplitLine &&
m_AxisLabel.Equals(other.axisLabel) &&
splitLineType == other.splitLineType &&
boundaryGap == other.boundaryGap &&
runtimeMinValue == other.runtimeMinValue &&
runtimeMaxValue == other.runtimeMaxValue &&
axisName.Equals(other.axisName) &&
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
}
public static bool operator ==(Axis left, Axis right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(Axis left, Axis right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
if (value <= 0) return 0;
return logBaseE ? Mathf.Log(value) : Mathf.Log(value, logBase);
}
public override void ParseJsonData(string jsonData)
@@ -812,27 +898,6 @@ namespace XCharts
[System.Serializable]
public class XAxis : Axis
{
public XAxis Clone()
{
var axis = XAxisPool.Get();
axis.show = show;
axis.type = type;
axis.min = min;
axis.max = max;
axis.splitNumber = splitNumber;
axis.interval = interval;
axis.showSplitLine = showSplitLine;
axis.splitLineType = splitLineType;
axis.boundaryGap = boundaryGap;
axis.axisName.Copy(axisName);
axis.axisLabel.Copy(axisLabel);
axis.data.Clear();
if (axis.data.Capacity < data.Count) axis.data.Capacity = data.Count;
foreach (var d in data) axis.data.Add(d);
return axis;
}
public static XAxis defaultXAxis
{
get
@@ -844,14 +909,15 @@ namespace XCharts
m_Min = 0,
m_Max = 0,
m_SplitNumber = 5,
m_ShowSplitLine = false,
m_SplitLineType = SplitLineType.Dashed,
m_BoundaryGap = true,
m_Data = new List<string>()
{
"x1","x2","x3","x4","x5"
}
};
axis.splitLine.show = false;
axis.splitLine.lineStyle.type = LineStyle.Type.Dashed;
axis.axisLabel.textLimit.enable = true;
return axis;
}
}
@@ -865,27 +931,6 @@ namespace XCharts
[System.Serializable]
public class YAxis : Axis
{
public YAxis Clone()
{
var axis = YAxisPool.Get();
axis.show = show;
axis.type = type;
axis.min = min;
axis.max = max;
axis.splitNumber = splitNumber;
axis.interval = interval;
axis.showSplitLine = showSplitLine;
axis.splitLineType = splitLineType;
axis.boundaryGap = boundaryGap;
axis.axisName.Copy(axisName);
axis.axisLabel.Copy(axisLabel);
axis.data.Clear();
if (axis.data.Capacity < data.Count) axis.data.Capacity = data.Count;
foreach (var d in data) axis.data.Add(d);
return axis;
}
public static YAxis defaultYAxis
{
get
@@ -897,11 +942,12 @@ namespace XCharts
m_Min = 0,
m_Max = 0,
m_SplitNumber = 5,
m_ShowSplitLine = true,
m_SplitLineType = SplitLineType.Dashed,
m_BoundaryGap = false,
m_Data = new List<string>(5),
};
axis.splitLine.show = true;
axis.splitLine.lineStyle.type = LineStyle.Type.Dashed;
axis.axisLabel.textLimit.enable = false;
return axis;
}
}

View File

@@ -80,6 +80,7 @@ namespace XCharts
[SerializeField] private float m_End;
[SerializeField] private float m_StartValue;
[SerializeField] private float m_EndValue;
[SerializeField] private int m_MinShowNum = 1;
[Range(1f, 20f)]
[SerializeField] private float m_ScrollSensitivity = 1.1f;
[SerializeField] private int m_FontSize = 18;
@@ -89,52 +90,92 @@ namespace XCharts
/// Whether to show dataZoom.
/// 是否显示缩放区域。
/// </summary>
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
}
/// <summary>
/// The mode of data filter.
/// 数据过滤类型。
/// </summary>
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
public FilterMode filterMode
{
get { return m_FilterMode; }
set { if (PropertyUtility.SetStruct(ref m_FilterMode, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify which xAxis is controlled by the dataZoom.
/// 控制哪一个 x 轴。
/// </summary>
public int xAxisIndex { get { return m_XAxisIndex; } set { m_XAxisIndex = value; } }
public int xAxisIndex
{
get { return m_XAxisIndex; }
set { if (PropertyUtility.SetStruct(ref m_XAxisIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify which yAxis is controlled by the dataZoom.
/// 控制哪一个 y 轴。
/// </summary>
public int yAxisIndex { get { return m_YAxisIndex; } set { m_YAxisIndex = value; } }
public int yAxisIndex
{
get { return m_YAxisIndex; }
set { if (PropertyUtility.SetStruct(ref m_YAxisIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否支持内置。内置于坐标系中,使用户可以在坐标系上通过鼠标拖拽、鼠标滚轮、手指滑动(触屏上)来缩放或漫游坐标系。
/// </summary>
public bool supportInside { get { return m_SupportInside; } set { m_SupportInside = value; } }
public bool supportInside
{
get { return m_SupportInside; }
set { if (PropertyUtility.SetStruct(ref m_SupportInside, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否支持滑动条。有单独的滑动条,用户在滑动条上进行缩放或漫游。
/// </summary>
public bool supportSlider { get { return m_SupportSlider; } set { m_SupportSlider = value; } }
public bool supportSlider
{
get { return m_SupportSlider; }
set { if (PropertyUtility.SetStruct(ref m_SupportSlider, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否支持框选。提供一个选框进行数据区域缩放。
/// </summary>
private bool supportSelect { get { return m_SupportSelect; } set { m_SupportSelect = value; } }
private bool supportSelect
{
get { return m_SupportSelect; }
set { if (PropertyUtility.SetStruct(ref m_SupportSelect, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show data shadow, to indicate the data tendency in brief.
/// default:true
/// 是否显示数据阴影。数据阴影可以简单地反应数据走势。
/// </summary>
public bool showDataShadow { get { return m_ShowDataShadow; } set { m_ShowDataShadow = value; } }
public bool showDataShadow
{
get { return m_ShowDataShadow; }
set { if (PropertyUtility.SetStruct(ref m_ShowDataShadow, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show detail, that is, show the detailed data information when dragging.
/// 是否显示detail即拖拽时候显示详细数值信息。
/// </summary>
public bool showDetail { get { return m_ShowDetail; } set { m_ShowDetail = value; } }
public bool showDetail
{
get { return m_ShowDetail; }
set { if (PropertyUtility.SetStruct(ref m_ShowDetail, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify whether to lock the size of window (selected area).
/// default:false
/// 是否锁定选择区域(或叫做数据窗口)的大小。
/// 如果设置为 true 则锁定选择区域的大小,也就是说,只能平移,不能缩放。
/// </summary>
public bool zoomLock { get { return m_ZoomLock; } set { m_ZoomLock = value; } }
public bool zoomLock
{
get { return m_ZoomLock; }
set { if (PropertyUtility.SetStruct(ref m_ZoomLock, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief.
/// default:true
@@ -145,27 +186,43 @@ namespace XCharts
/// The background color of the component.
/// 组件的背景颜色。
/// </summary>
private Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
private Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Distance between dataZoom component and the bottom side of the container.
/// bottom value is a instant pixel value like 10.
/// default:10
/// 组件离容器下侧的距离。
/// </summary>
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of dataZoom component.
/// height value is a instant pixel value like 10.
/// default:50
/// 组件高度。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
public float height
{
get { return m_Height; }
set { if (PropertyUtility.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// Use absolute value or percent value in DataZoom.start and DataZoom.end.
/// default:RangeMode.Percent.
/// 取绝对值还是百分比。
/// </summary>
public RangeMode rangeMode { get { return m_RangeMode; } set { m_RangeMode = value; } }
public RangeMode rangeMode
{
get { return m_RangeMode; }
set { if (PropertyUtility.SetStruct(ref m_RangeMode, value)) SetVerticesDirty(); }
}
/// <summary>
/// The start percentage of the window out of the data extent, in the range of 0 ~ 100.
/// default:30
@@ -174,7 +231,7 @@ namespace XCharts
public float start
{
get { return m_Start; }
set { m_Start = value; if (m_Start < 0) m_Start = 0; if (m_Start > 100) m_Start = 100; }
set { m_Start = value; if (m_Start < 0) m_Start = 0; if (m_Start > 100) m_Start = 100; SetVerticesDirty(); }
}
/// <summary>
/// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
@@ -184,7 +241,15 @@ namespace XCharts
public float end
{
get { return m_End; }
set { m_End = value; if (m_End < 0) m_End = 0; if (m_End > 100) m_End = 100; }
set { m_End = value; if (m_End < 0) m_End = 0; if (m_End > 100) m_End = 100; SetVerticesDirty(); }
}
/// <summary>
/// 最小显示数据个数。当DataZoom放大到最大时最小显示的数据个数。
/// </summary>
public int minShowNum
{
get { return m_MinShowNum; }
set { if (PropertyUtility.SetStruct(ref m_MinShowNum, value)) SetVerticesDirty(); }
}
/// <summary>
/// The sensitivity of dataZoom scroll.
@@ -192,17 +257,29 @@ namespace XCharts
/// default:10
/// 缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。
/// </summary>
public float scrollSensitivity { get { return m_ScrollSensitivity; } set { m_ScrollSensitivity = value; } }
public float scrollSensitivity
{
get { return m_ScrollSensitivity; }
set { if (PropertyUtility.SetStruct(ref m_ScrollSensitivity, value)) SetVerticesDirty(); }
}
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
/// 文字字体的风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// The start label.

View File

@@ -5,10 +5,8 @@
/* */
/******************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
@@ -17,7 +15,7 @@ namespace XCharts
/// 图例组件展现了不同系列的标记,颜色和名字。可以通过点击图例控制哪些系列不显示。
/// </summary>
[System.Serializable]
public class Legend : MainComponent, IPropertyChanged, IEquatable<Legend>
public class Legend : MainComponent, IPropertyChanged
{
/// <summary>
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
@@ -43,61 +41,108 @@ namespace XCharts
[SerializeField] private SelectedMode m_SelectedMode;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultRight;
[SerializeField] private float m_ItemWidth = 50.0f;
[SerializeField] private float m_ItemHeight = 20.0f;
[SerializeField] private float m_ItemGap = 5;
[SerializeField] private int m_ItemFontSize = 18;
[SerializeField] private float m_ItemWidth = 24.0f;
[SerializeField] private float m_ItemHeight = 12.0f;
[SerializeField] private float m_ItemGap = 10f;
[SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private string m_Formatter;
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18);
[SerializeField] private List<string> m_Data = new List<string>();
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
private Dictionary<string, Button> m_DataBtnList = new Dictionary<string, Button>();
private Dictionary<string, LegendItem> m_DataBtnList = new Dictionary<string, LegendItem>();
/// <summary>
/// Whether to show legend component.
/// 是否显示图例组件。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
/// 选择模式。控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
/// </summary>
/// <value></value>
public SelectedMode selectedMode { get { return m_SelectedMode; } set { m_SelectedMode = value; } }
public SelectedMode selectedMode
{
get { return m_SelectedMode; }
set { if (PropertyUtility.SetStruct(ref m_SelectedMode, value)) SetComponentDirty(); }
}
/// <summary>
/// Specify whether the layout of legend component is horizontal or vertical.
/// 布局方式是横还是竖。
/// </summary>
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
public Orient orient
{
get { return m_Orient; }
set { if (PropertyUtility.SetStruct(ref m_Orient, value)) SetComponentDirty(); }
}
/// <summary>
/// The location of legend.
/// 图例显示的位置。
/// </summary>
public Location location { get { return m_Location; } set { m_Location = value; } }
public Location location
{
get { return m_Location; }
set { if (PropertyUtility.SetClass(ref m_Location, value)) SetComponentDirty(); }
}
/// <summary>
/// the width of legend item.
/// 每个图例项的宽度。
/// Image width of legend symbol.
/// 图例标记的图形宽度。
/// </summary>
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
public float itemWidth
{
get { return m_ItemWidth; }
set { if (PropertyUtility.SetStruct(ref m_ItemWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the height of legend item.
/// 每个图例项的高度。
/// Image height of legend symbol.
/// 图例标记的图形高度。
/// </summary>
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
public float itemHeight
{
get { return m_ItemHeight; }
set { if (PropertyUtility.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// The distance between each legend, horizontal distance in horizontal layout, and vertical distance in vertical layout.
/// 图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。
/// </summary>
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
public float itemGap
{
get { return m_ItemGap; }
set { if (PropertyUtility.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); }
}
/// <summary>
/// font size of item text.
/// 图例项的字体大小
/// Whether the legend symbol matches the color automatically.
/// 图例标记的图形是否自动匹配颜色
/// </summary>
public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } }
public bool itemAutoColor
{
get { return m_ItemAutoColor; }
set { if (PropertyUtility.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
}
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {name}
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
/// the style of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtility.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// Data array of legend. An array item is usually a name representing string. (If it is a pie chart,
/// it could also be the name of a single data in the pie chart) of a series.
@@ -105,13 +150,76 @@ namespace XCharts
/// 图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 name如果是饼图也可以是饼图单个数据的 name
/// 如果 data 没有被指定会自动从当前系列中获取。指定data时里面的数据项和serie匹配时才会生效。
/// </summary>
public List<string> data { get { return m_Data; } }
public List<string> data
{
get { return m_Data; }
set { if (value != null) { m_Data = value; SetComponentDirty(); } }
}
/// <summary>
/// 自定义的图例标记图形。
/// </summary>
public List<Sprite> icons
{
get { return m_Icons; }
set { if (value != null) { m_Icons = value; SetComponentDirty(); } }
}
/// <summary>
/// 图表是否需要刷新(图例组件不需要刷新图表)
/// </summary>
public override bool vertsDirty { get { return false; } }
/// <summary>
/// 组件是否需要刷新
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
/// <summary>
/// the button list of legend.
/// 图例按钮列表。
/// </summary>
/// <value></value>
public Dictionary<string, Button> buttonList { get { return m_DataBtnList; } }
public Dictionary<string, LegendItem> buttonList { get { return m_DataBtnList; } }
public float runtimeWidth
{
get
{
var width = 0f;
foreach (var kv in buttonList)
{
if (orient == Orient.Horizonal)
width += kv.Value.width + m_ItemGap;
else if (kv.Value.width > width)
width = kv.Value.width;
}
return orient == Orient.Horizonal ? width - m_ItemGap : width;
}
}
public float runtimeHeight
{
get
{
var height = 0f;
foreach (var kv in buttonList)
{
if (orient == Orient.Vertical)
height += kv.Value.height + m_ItemGap;
else if (kv.Value.height > height)
height = kv.Value.height;
}
return orient == Orient.Vertical ? height - m_ItemGap : height;
}
}
/// <summary>
/// 一个在顶部居中显示的默认图例。
@@ -126,84 +234,16 @@ namespace XCharts
m_SelectedMode = SelectedMode.Multiple,
m_Orient = Orient.Horizonal,
m_Location = Location.defaultTop,
m_ItemWidth = 60.0f,
m_ItemHeight = 20.0f,
m_ItemGap = 5,
m_ItemFontSize = 16
m_ItemWidth = 24.0f,
m_ItemHeight = 12.0f,
m_ItemGap = 10f,
};
legend.location.top = 30;
legend.textStyle.offset = new Vector2(2, 0);
legend.textStyle.fontSize = 18;
return legend;
}
}
public void Copy(Legend legend)
{
m_Show = legend.show;
m_SelectedMode = legend.selectedMode;
m_Orient = legend.orient;
m_Location.Copy(legend.location);
m_ItemWidth = legend.itemWidth;
m_ItemHeight = legend.itemHeight;
m_ItemGap = legend.itemGap;
m_ItemFontSize = legend.itemFontSize;
m_Data.Clear();
foreach (var d in legend.data) m_Data.Add(d);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Legend)
{
return Equals((Legend)obj);
}
else
{
return false;
}
}
public bool Equals(Legend other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return show == other.show &&
selectedMode == other.selectedMode &&
orient == other.orient &&
location == other.location &&
itemWidth == other.itemWidth &&
itemHeight == other.itemHeight &&
itemGap == other.itemGap &&
itemFontSize == other.itemFontSize &&
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
}
public static bool operator ==(Legend left, Legend right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(Legend left, Legend right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// 清空
@@ -211,6 +251,7 @@ namespace XCharts
public void ClearData()
{
m_Data.Clear();
SetComponentDirty();
}
/// <summary>
@@ -232,6 +273,7 @@ namespace XCharts
if (m_Data.Contains(name))
{
m_Data.Remove(name);
SetComponentDirty();
}
}
@@ -244,6 +286,7 @@ namespace XCharts
if (!m_Data.Contains(name) && !string.IsNullOrEmpty(name))
{
m_Data.Add(name);
SetComponentDirty();
}
}
@@ -285,13 +328,11 @@ namespace XCharts
/// <param name="name"></param>
/// <param name="btn"></param>
/// <param name="total"></param>
public void SetButton(string name, Button btn, int total)
public void SetButton(string name, LegendItem item, int total)
{
m_DataBtnList[name] = item;
int index = m_DataBtnList.Values.Count;
btn.transform.localPosition = GetButtonLocationPosition(total, index);
m_DataBtnList[name] = btn;
btn.gameObject.SetActive(show);
btn.GetComponentInChildren<Text>().text = name;
item.SetActive(show);
}
/// <summary>
@@ -303,7 +344,27 @@ namespace XCharts
{
if (m_DataBtnList.ContainsKey(name))
{
m_DataBtnList[name].GetComponent<Image>().color = color;
m_DataBtnList[name].SetIconColor(color);
}
}
public void UpdateContentColor(string name, Color color)
{
if (m_DataBtnList.ContainsKey(name))
{
m_DataBtnList[name].SetContentColor(color);
}
}
public Sprite GetIcon(int index)
{
if (index >= 0 && index < m_Icons.Count)
{
return m_Icons[index];
}
else
{
return null;
}
}
@@ -315,62 +376,6 @@ namespace XCharts
m_Location.OnChanged();
}
/// <summary>
/// 根据图例的布局和位置类型获得具体位置
/// </summary>
/// <param name="size"></param>
/// <param name="index"></param>
/// <returns></returns>
private Vector2 GetButtonLocationPosition(int size, int index)
{
switch (m_Orient)
{
case Orient.Vertical:
switch (m_Location.align)
{
case Location.Align.TopCenter:
case Location.Align.TopLeft:
case Location.Align.TopRight:
return new Vector2(0, -index * (itemHeight + itemGap));
case Location.Align.Center:
case Location.Align.CenterLeft:
case Location.Align.CenterRight:
float totalHeight = size * itemHeight + (size - 1) * itemGap;
float startY = totalHeight / 2;
return new Vector2(0, startY - index * (itemHeight + itemGap));
case Location.Align.BottomCenter:
case Location.Align.BottomLeft:
case Location.Align.BottomRight:
return new Vector2(0, (size - index - 1) * (itemHeight + itemGap));
}
return Vector2.zero;
case Orient.Horizonal:
switch (m_Location.align)
{
case Location.Align.TopLeft:
case Location.Align.CenterLeft:
case Location.Align.BottomLeft:
return new Vector2(index * (itemWidth + itemGap), 0);
case Location.Align.TopCenter:
case Location.Align.Center:
case Location.Align.BottomCenter:
float totalWidth = size * itemWidth + (size - 1) * itemGap;
float startX = totalWidth / 2;
return new Vector2(-startX + itemWidth / 2 + index * (itemWidth + itemGap), 0);
case Location.Align.TopRight:
case Location.Align.CenterRight:
case Location.Align.BottomRight:
return new Vector2(-(size - index - 1) * (itemWidth + itemGap), 0);
}
return Vector2.zero;
}
return Vector2.zero;
}
/// <summary>
/// 从json字符串解析数据json格式如['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
/// </summary>
@@ -379,6 +384,7 @@ namespace XCharts
{
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
m_Data = ChartHelper.ParseStringFromString(jsonData);
SetComponentDirty();
}
public string GetFormatterContent(string category)

View File

@@ -18,7 +18,7 @@ namespace XCharts
/// 雷达图坐标系组件,只适用于雷达图。
/// </summary>
[System.Serializable]
public class Radar : MainComponent, IEquatable<Radar>
public class Radar : MainComponent
{
/// <summary>
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
@@ -48,7 +48,7 @@ namespace XCharts
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
/// </summary>
[System.Serializable]
public class Indicator : IEquatable<Indicator>
public class Indicator
{
[SerializeField] private string m_Name;
[SerializeField] private float m_Max;
@@ -79,54 +79,12 @@ namespace XCharts
/// 指示器的文本组件。
/// </summary>
public Text text { get; set; }
public Indicator Clone()
{
return new Indicator()
{
m_Name = name,
m_Max = max,
m_Min = min,
m_TextStyle = textStyle.Clone()
};
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Indicator)
{
return Equals((Indicator)obj);
}
else
{
return false;
}
}
public bool Equals(Indicator other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return m_Name.Equals(other.name) &&
m_TextStyle.Equals(other.textStyle);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
[SerializeField] private Shape m_Shape;
[SerializeField] private float m_Radius = 100;
[SerializeField] private int m_SplitNumber = 5;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
[SerializeField] private AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] private bool m_Indicator = true;
[SerializeField] private PositionType m_PositionType = PositionType.Vertice;
@@ -137,46 +95,82 @@ namespace XCharts
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
/// </summary>
/// <value></value>
public Shape shape { get { return m_Shape; } set { m_Shape = value; } }
public Shape shape
{
get { return m_Shape; }
set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetAllDirty(); }
}
/// <summary>
/// the radius of radar.
/// 雷达图的半径。
/// </summary>
public float radius { get { return m_Radius; } set { m_Radius = value; } }
public float radius
{
get { return m_Radius; }
set { if (PropertyUtility.SetStruct(ref m_Radius, value)) SetAllDirty(); }
}
/// <summary>
/// Segments of indicator axis.
/// 指示器轴的分割段数。
/// </summary>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
/// <summary>
/// the center of radar chart.
/// 雷达图的中心点。数组的第一项是横坐标,第二项是纵坐标。
/// 当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。
/// </summary>
public float[] center { get { return m_Center; } set { m_Center = value; } }
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
/// the line style of radar.
/// 线条样式
/// split line.
/// 分割线。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
public AxisSplitLine splitLine
{
get { return m_SplitLine; }
set { if (PropertyUtility.SetClass(ref m_SplitLine, value, true)) SetAllDirty(); }
}
/// <summary>
/// Split area of axis in grid area.
/// 分割区域。
/// </summary>
public AxisSplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
public AxisSplitArea splitArea
{
get { return m_SplitArea; }
set { if (PropertyUtility.SetClass(ref m_SplitArea, value, true)) SetAllDirty(); }
}
/// <summary>
/// Whether to show indicator.
/// 是否显示指示器。
/// </summary>
public bool indicator { get { return m_Indicator; } set { m_Indicator = value; } }
public bool indicator
{
get { return m_Indicator; }
set { if (PropertyUtility.SetStruct(ref m_Indicator, value)) SetComponentDirty(); }
}
/// <summary>
/// 指示器和雷达的间距。
/// </summary>
public float indicatorGap { get { return m_IndicatorGap; } set { m_IndicatorGap = value; } }
public float indicatorGap
{
get { return m_IndicatorGap; }
set { if (PropertyUtility.SetStruct(ref m_IndicatorGap, value)) SetComponentDirty(); }
}
/// <summary>
/// 显示位置类型。
/// /// 显示位置类型。
/// </summary>
public PositionType positionType { get { return m_PositionType; } set { m_PositionType = value; } }
public PositionType positionType
{
get { return m_PositionType; }
set { if (PropertyUtility.SetStruct(ref m_PositionType, value)) SetAllDirty(); }
}
/// <summary>
/// the indicator list.
/// 指示器列表。
@@ -207,7 +201,7 @@ namespace XCharts
var radar = new Radar
{
m_Shape = Shape.Polygon,
m_Radius = 0.4f,
m_Radius = 0.35f,
m_SplitNumber = 5,
m_Indicator = true,
m_IndicatorList = new List<Indicator>(5){
@@ -219,74 +213,14 @@ namespace XCharts
}
};
radar.center[0] = 0.5f;
radar.center[1] = 0.45f;
radar.center[1] = 0.4f;
radar.splitLine.show = true;
radar.splitArea.show = true;
radar.lineStyle.width = 0.6f;
radar.splitLine.lineStyle.width = 0.6f;
return radar;
}
}
public void Copy(Radar other)
{
m_Shape = other.shape;
m_Radius = other.radius;
m_SplitNumber = other.splitNumber;
m_Center[0] = other.center[0];
m_Center[1] = other.center[1];
m_Indicator = other.indicator;
indicatorList.Clear();
foreach (var d in other.indicatorList) indicatorList.Add(d.Clone());
}
public Radar Clone()
{
var radar = new Radar();
radar.shape = shape;
radar.positionType = positionType;
radar.radius = radius;
radar.splitNumber = splitNumber;
radar.center[0] = center[0];
radar.center[1] = center[1];
radar.indicatorList.Clear();
radar.indicator = indicator;
radar.indicatorGap = indicatorGap;
foreach (var d in indicatorList) radar.indicatorList.Add(d.Clone());
return radar;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Radar)
{
return Equals((Radar)obj);
}
else
{
return false;
}
}
public bool Equals(Radar other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return radius == other.radius &&
shape == other.shape &&
positionType == other.positionType &&
splitNumber == other.splitNumber &&
center[0] == other.center[0] &&
center[1] == other.center[1] &&
indicator == other.indicator &&
indicatorGap == other.indicatorGap &&
IsEqualsIndicatorList(indicatorList, other.indicatorList);
}
private bool IsEqualsIndicatorList(List<Indicator> indicators1, List<Indicator> indicators2)
{
if (indicators1.Count != indicators2.Count) return false;
@@ -299,29 +233,6 @@ namespace XCharts
return true;
}
public static bool operator ==(Radar left, Radar right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(Radar left, Radar right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override void ParseJsonData(string jsonData)
{
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
@@ -417,5 +328,33 @@ namespace XCharts
var y = runtimeCenterPos.y + (runtimeRadius + indicatorGap) * Mathf.Cos(angle);
return new Vector3(x, y);
}
public Radar.Indicator AddIndicator(string name, float min, float max)
{
var indicator = new Radar.Indicator();
indicator.name = name;
indicator.min = min;
indicator.max = max;
indicatorList.Add(indicator);
SetAllDirty();
return indicator;
}
public bool UpdateIndicator(int indicatorIndex, string name, float min, float max)
{
var indicator = GetIndicator(indicatorIndex);
if (indicator == null) return false;
indicator.name = name;
indicator.min = min;
indicator.max = max;
SetAllDirty();
return true;
}
public Radar.Indicator GetIndicator(int indicatorIndex)
{
if (indicatorIndex < 0 || indicatorIndex > indicatorList.Count - 1) return null;
return indicatorList[indicatorIndex];
}
}
}

View File

@@ -7,8 +7,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Serialization;
namespace XCharts
{
@@ -52,6 +52,10 @@ namespace XCharts
/// 仪表盘。
/// </summary>
Gauge,
/// <summary>
/// 环形图。只支持一个数据的环形图。
/// </summary>
Ring,
}
/// <summary>
@@ -194,7 +198,7 @@ namespace XCharts
[System.Serializable]
public class Serie : MainComponent
{
[SerializeField] [DefaultValue("true")] private bool m_Show = true;
[SerializeField] private bool m_Show = true;
[SerializeField] private SerieType m_Type;
[SerializeField] private string m_Name;
[SerializeField] private string m_Stack;
@@ -225,8 +229,11 @@ namespace XCharts
[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 bool m_Clockwise = true;
[FormerlySerializedAs("m_ArcShaped")]
[SerializeField] private bool m_RoundCap;
[SerializeField] private float m_RingGap = 10f;
[SerializeField] private int m_SplitNumber;
[SerializeField] private GaugeType m_GaugeType = GaugeType.Pointer;
[SerializeField] private GaugeAxis m_GaugeAxis = new GaugeAxis();
@@ -246,32 +253,49 @@ namespace XCharts
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
[SerializeField] private bool m_ShowDataName;
[SerializeField] private bool m_ShowDataIcon;
[SerializeField] private bool m_Clip = true;
[SerializeField] private bool m_Ignore = false;
[SerializeField] private float m_IgnoreValue = 0;
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
[NonSerialized] private int m_FilterStart;
[NonSerialized] private int m_FilterEnd;
[NonSerialized] private int m_FilterMinShow;
[NonSerialized] private List<SerieData> m_FilterData;
[NonSerialized] private Dictionary<int, List<Vector3>> m_UpSmoothPoints = new Dictionary<int, List<Vector3>>();
[NonSerialized] private Dictionary<int, List<Vector3>> m_DownSmoothPoints = new Dictionary<int, List<Vector3>>();
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
[NonSerialized] private bool m_NeedUpdateFilterData;
[NonSerialized] private bool m_NameDirty;
/// <summary>
/// Whether to show serie in chart.
/// 系列是否显示在图表上。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) { SetVerticesDirty(); SetNameDirty(); } }
}
/// <summary>
/// the chart type of serie.
/// 系列的图表类型。
/// </summary>
public SerieType type { get { return m_Type; } set { m_Type = value; } }
public SerieType type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// Series name used for displaying in tooltip and filtering with legend.
/// 系列名称,用于 tooltip 的显示legend 的图例筛选。
/// </summary>
public string name { get { return m_Name; } set { m_Name = value; } }
public string name
{
get { return m_Name; }
set { if (PropertyUtility.SetClass(ref m_Name, value)) { SetVerticesDirty(); SetNameDirty(); } }
}
/// <summary>
/// 图例名称。当系列名称不为空时图例名称即为系列名称反之则为索引index。
/// </summary>
@@ -280,17 +304,29 @@ namespace XCharts
/// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other.
/// 数据堆叠同个类目轴上系列配置相同的stack值后后一个系列的值会在前一个系列的值上相加。
/// </summary>
public string stack { get { return m_Stack; } set { m_Stack = value; } }
public string stack
{
get { return m_Stack; }
set { if (PropertyUtility.SetClass(ref m_Stack, value)) SetVerticesDirty(); }
}
/// <summary>
/// Index of axis to combine with, which is useful for multiple x axes in one chart.
/// 使用的坐标轴轴的 index在单个图表实例中存在多个坐标轴轴的时候有用。
/// </summary>
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
public int axisIndex
{
get { return m_AxisIndex; }
set { if (PropertyUtility.SetStruct(ref m_AxisIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// Index of radar component that radar chart uses.
/// 雷达图所使用的 radar 组件的 index。
/// </summary>
public int radarIndex { get { return m_RadarIndex; } set { m_RadarIndex = value; } }
public int radarIndex
{
get { return m_RadarIndex; }
set { if (PropertyUtility.SetStruct(ref m_RadarIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// The min number of data to show in chart.
/// 系列所显示数据的最小索引
@@ -298,7 +334,7 @@ namespace XCharts
public int minShow
{
get { return m_MinShow; }
set { m_MinShow = value; if (m_MinShow < 0) m_MinShow = 0; }
set { if (PropertyUtility.SetStruct(ref m_MinShow, value < 0 ? 0 : value)) { SetVerticesDirty(); } }
}
/// <summary>
/// The max number of data to show in chart.
@@ -307,7 +343,7 @@ namespace XCharts
public int maxShow
{
get { return m_MaxShow; }
set { m_MaxShow = value; if (m_MaxShow < 0) m_MaxShow = 0; }
set { if (PropertyUtility.SetStruct(ref m_MaxShow, value < 0 ? 0 : value)) { SetVerticesDirty(); } }
}
/// <summary>
/// The max number of serie data cache.
@@ -318,55 +354,95 @@ namespace XCharts
public int maxCache
{
get { return m_MaxCache; }
set { m_MaxCache = value; if (m_MaxCache < 0) m_MaxCache = 0; }
set { if (PropertyUtility.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) { SetVerticesDirty(); } }
}
/// <summary>
/// The style of area.
/// 区域填充样式。
/// </summary>
public AreaStyle areaStyle { get { return m_AreaStyle; } set { m_AreaStyle = value; } }
public AreaStyle areaStyle
{
get { return m_AreaStyle; }
set { if (PropertyUtility.SetClass(ref m_AreaStyle, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// the symbol of serie data item.
/// 标记的图形。
/// </summary>
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } }
public SerieSymbol symbol
{
get { return m_Symbol; }
set { if (PropertyUtility.SetClass(ref m_Symbol, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// The type of line chart.
/// 折线图样式类型。
/// </summary>
public LineType lineType { get { return m_LineType; } set { m_LineType = value; } }
public LineType lineType
{
get { return m_LineType; }
set { if (PropertyUtility.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the min pixel dist of sample.
/// 采样的最小像素距离默认为0时不采样。当两个数据点间的水平距离小于改值时开启采样保证两点间的水平距离不小于改值。
/// </summary>
public float sampleDist { get { return m_SampleDist; } set { m_SampleDist = value < 0 ? 0 : value; } }
public float sampleDist
{
get { return m_SampleDist; }
set { if (PropertyUtility.SetStruct(ref m_SampleDist, value < 0 ? 0 : value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of sample.
/// 采样类型。当sampleDist大于0时有效。
/// </summary>
public SampleType sampleType { get { return m_SampleType; } set { m_SampleType = value; } }
public SampleType sampleType
{
get { return m_SampleType; }
set { if (PropertyUtility.SetStruct(ref m_SampleType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 设定的采样平均值。当sampleType 为 Peak 时用于和过滤数据的平均值做对比是取最大值还是最小值。默认为0时会实时计算所有数据的平均值。
/// </summary>
public float sampleAverage { get { return m_SampleAverage; } set { m_SampleAverage = value; } }
public float sampleAverage
{
get { return m_SampleAverage; }
set { if (PropertyUtility.SetStruct(ref m_SampleAverage, value)) SetVerticesDirty(); }
}
/// <summary>
/// The style of line.
/// 线条样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (PropertyUtility.SetClass(ref m_LineStyle, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 柱形图类型。
/// </summary>
public BarType barType { get { return m_BarType; } set { m_BarType = value; } }
public BarType barType
{
get { return m_BarType; }
set { if (PropertyUtility.SetStruct(ref m_BarType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 柱形图是否为百分比堆积。相同stack的serie只要有一个barPercentStack为true则就显示成百分比堆叠柱状图。
/// </summary>
public bool barPercentStack { get { return m_BarPercentStack; } set { m_BarPercentStack = value; } }
public bool barPercentStack
{
get { return m_BarPercentStack; }
set { if (PropertyUtility.SetStruct(ref m_BarPercentStack, value)) SetVerticesDirty(); }
}
/// <summary>
/// The width of the bar. Adaptive when default 0.
/// 柱条的宽度,不设时自适应。支持设置成相对于类目宽度的百分比。
/// </summary>
public float barWidth { get { return m_BarWidth; } set { m_BarWidth = value; } }
public float barWidth
{
get { return m_BarWidth; }
set { if (PropertyUtility.SetStruct(ref m_BarWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The gap between bars between different series, is a percent value like '0.3f' , which means 30% of the bar width, can be set as a fixed value.
/// <para>Set barGap as '-1' can overlap bars that belong to different series, which is useful when making a series of bar be background.
@@ -377,8 +453,11 @@ namespace XCharts
/// 如果想要两个系列的柱子重叠,可以设置 barGap 为 '-1f'。这在用柱子做背景的时候有用。
/// 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。
/// </summary>
/// <value></value>
public float barGap { get { return m_BarGap; } set { m_BarGap = value; } }
public float barGap
{
get { return m_BarGap; }
set { if (PropertyUtility.SetStruct(ref m_BarGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// The bar gap of a single series, defaults to be 20% of the category gap, can be set as a fixed value.
/// In a single coodinate system, this attribute is shared by multiple 'bar' series.
@@ -387,123 +466,312 @@ namespace XCharts
/// 同一系列的柱间距离默认为类目间距的20%,可设固定值。
/// 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。
/// </summary>
public float barCategoryGap { get { return m_BarCategoryGap; } set { m_BarCategoryGap = value; } }
public float barCategoryGap
{
get { return m_BarCategoryGap; }
set { if (PropertyUtility.SetStruct(ref m_BarCategoryGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 斑马线的粗细。
/// </summary>
public float barZebraWidth { get { return m_BarZebraWidth; } set { m_BarZebraWidth = value > 0 ? value : 0; } }
public float barZebraWidth
{
get { return m_BarZebraWidth; }
set { if (PropertyUtility.SetStruct(ref m_BarZebraWidth, value < 0 ? 0 : value)) SetVerticesDirty(); }
}
/// <summary>
/// 斑马线的间距。
/// </summary>
public float barZebraGap { get { return m_BarZebraGap; } set { m_BarZebraGap = value > 0 ? value : 0; } }
public float barZebraGap
{
get { return m_BarZebraGap; }
set { if (PropertyUtility.SetStruct(ref m_BarZebraGap, value < 0 ? 0 : value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether offset when mouse click pie chart item.
/// 鼠标点击时是否开启偏移一般用在PieChart图表中。
/// </summary>
public bool pieClickOffset { get { return m_ClickOffset; } set { m_ClickOffset = value; } }
public bool pieClickOffset
{
get { return m_ClickOffset; }
set { if (PropertyUtility.SetStruct(ref m_ClickOffset, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show as Nightingale chart.
/// 是否展示成南丁格尔图,通过半径区分数据大小。
/// </summary>
public RoseType pieRoseType { get { return m_RoseType; } set { m_RoseType = value; } }
public RoseType pieRoseType
{
get { return m_RoseType; }
set { if (PropertyUtility.SetStruct(ref m_RoseType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the space of pie chart item.
/// 饼图项间的空隙留白。
/// </summary>
public float pieSpace { get { return m_Space; } set { m_Space = value; } }
public float pieSpace
{
get { return m_Space; }
set { if (PropertyUtility.SetStruct(ref m_Space, value)) SetVerticesDirty(); }
}
/// <summary>
/// the center of chart.
/// 中心点。
/// </summary>
public float[] center { get { return m_Center; } set { m_Center = value; } }
public float[] center
{
get { return m_Center; }
set { if (value != null && value.Length == 2) { m_Center = value; SetVerticesDirty(); } }
}
/// <summary>
/// the radius of chart.
/// 半径。radius[0]表示内径radius[1]表示外径。
/// </summary>
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
public float[] radius
{
get { return m_Radius; }
set { if (value != null && value.Length == 2) { m_Radius = value; SetVerticesDirty(); } }
}
[Obsolete("Use Serie.center instead.", true)]
public float[] pieCenter { get { return center; } set { center = value; } }
public float[] pieCenter
{
get { return center; }
set { center = value; }
}
[Obsolete("Use Serie.radius instead.", true)]
public float[] pieRadius { get { return radius; } set { radius = value; } }
public float[] pieRadius
{
get { return radius; }
set { radius = value; }
}
/// <summary>
/// 最小值,映射到 startAngle。
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
public float min
{
get { return m_Min; }
set { if (PropertyUtility.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
}
/// <summary>
/// 最大值,映射到 endAngle。
/// </summary>
public float max { get { return m_Max; } set { m_Max = value; } }
public float max
{
get { return m_Max; }
set { if (PropertyUtility.SetStruct(ref m_Max, value)) SetVerticesDirty(); }
}
/// <summary>
/// 起始角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float startAngle { get { return m_StartAngle; } set { m_StartAngle = value; } }
public float startAngle
{
get { return m_StartAngle; }
set { if (PropertyUtility.SetStruct(ref m_StartAngle, value)) SetVerticesDirty(); }
}
/// <summary>
/// 结束角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float endAngle { get { return m_EndAngle; } set { m_EndAngle = value; } }
public float endAngle
{
get { return m_EndAngle; }
set { if (PropertyUtility.SetStruct(ref m_EndAngle, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否顺时针。
/// </summary>
public bool clockwise { get { return m_Clockwise; } set { m_Clockwise = value; } }
public bool clockwise
{
get { return m_Clockwise; }
set { if (PropertyUtility.SetStruct(ref m_Clockwise, value)) SetVerticesDirty(); }
}
/// <summary>
/// 刻度分割段数
/// 环形图的环间隙
/// </summary>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value > 36 ? 36 : value; } }
public float ringGap
{
get { return m_RingGap; }
set { if (PropertyUtility.SetStruct(ref m_RingGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否开启圆弧形边角
/// 刻度分割段数。最大可设置36
/// </summary>
public bool arcShaped { get { return m_ArcShaped; } set { m_ArcShaped = value; } }
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value > 36 ? 36 : value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否开启圆弧效果。
/// </summary>
public bool roundCap
{
get { return m_RoundCap; }
set { if (PropertyUtility.SetStruct(ref m_RoundCap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否开启忽略数据。当为 true 时,数据值为 ignoreValue 时不进行绘制。
/// </summary>
public bool ignore
{
get { return m_Ignore; }
set { if (PropertyUtility.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); }
}
/// <summary>
/// 忽略数据的默认值。当ignore为true才有效。
/// </summary>
public float ignoreValue
{
get { return m_IgnoreValue; }
set { if (PropertyUtility.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); }
}
/// <summary>
/// 仪表盘轴线。
/// </summary>
public GaugeAxis gaugeAxis { get { return m_GaugeAxis; } set { m_GaugeAxis = value; } }
public GaugeAxis gaugeAxis
{
get { return m_GaugeAxis; }
set { if (PropertyUtility.SetClass(ref m_GaugeAxis, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 仪表盘指针。
/// </summary>
public GaugePointer gaugePointer { get { return m_GaugePointer; } set { m_GaugePointer = value; } }
public GaugePointer gaugePointer
{
get { return m_GaugePointer; }
set { if (PropertyUtility.SetClass(ref m_GaugePointer, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 仪表盘类型。
/// </summary>
public GaugeType gaugeType { get { return m_GaugeType; } set { m_GaugeType = value; } }
public GaugeType gaugeType
{
get { return m_GaugeType; }
set { if (PropertyUtility.SetStruct(ref m_GaugeType, value)) SetVerticesDirty(); }
}
/// <summary>
/// Text label of graphic element,to explain some data information about graphic item like value, name and so on.
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
/// </summary>
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
public SerieLabel label
{
get { return m_Label; }
set { if (PropertyUtility.SetClass(ref m_Label, value, true)) SetAllDirty(); }
}
/// <summary>
/// The start animation.
/// 起始动画。
/// </summary>
public SerieAnimation animation { get { return m_Animation; } set { m_Animation = value; } }
public SerieAnimation animation
{
get { return m_Animation; }
set { if (PropertyUtility.SetClass(ref m_Animation, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// The arrow of line.
/// 折线图的箭头。
/// </summary>
public LineArrow lineArrow { get { return m_LineArrow; } set { m_LineArrow = value; } }
public LineArrow lineArrow
{
get { return m_LineArrow; }
set { if (PropertyUtility.SetClass(ref m_LineArrow, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// The style of data item.
/// 图形样式。
/// </summary>
public ItemStyle itemStyle { get { return m_ItemStyle; } set { m_ItemStyle = value; } }
public ItemStyle itemStyle
{
get { return m_ItemStyle; }
set { if (PropertyUtility.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 高亮的图形样式和文本标签样式。
/// </summary>
public Emphasis emphasis { get { return m_Emphasis; } set { m_Emphasis = value; } }
public Emphasis emphasis
{
get { return m_Emphasis; }
set { if (PropertyUtility.SetClass(ref m_Emphasis, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 标题样式。
/// </summary>
public TitleStyle titleStyle { get { return m_TitleStyle; } set { m_TitleStyle = value; } }
public TitleStyle titleStyle
{
get { return m_TitleStyle; }
set { if (PropertyUtility.SetClass(ref m_TitleStyle, value, true)) SetAllDirty(); }
}
/// <summary>
/// 数据项里的数据维数。
/// </summary>
/// <value></value>
public int showDataDimension { get { return m_ShowDataDimension; } }
/// <summary>
/// 在Editor的inpsector上是否显示name参数
/// </summary>
public bool showDataName { get { return m_ShowDataName; } set { m_ShowDataName = value; } }
/// <summary>
/// If clip the overflow on the coordinate system.
/// 是否裁剪超出坐标系部分的图形。
/// </summary>
public bool clip
{
get { return m_Clip; }
set { if (PropertyUtility.SetStruct(ref m_Clip, value)) SetVerticesDirty(); }
}
/// <summary>
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
/// </summary>
public List<SerieData> data { get { return m_Data; } }
public override bool vertsDirty
{
get
{
return m_VertsDirty ||
symbol.vertsDirty ||
lineStyle.vertsDirty ||
lineArrow.vertsDirty ||
itemStyle.vertsDirty ||
areaStyle.vertsDirty ||
label.vertsDirty ||
emphasis.vertsDirty ||
gaugeAxis.vertsDirty ||
gaugePointer.vertsDirty;
}
}
public override bool componentDirty { get { return m_ComponentDirty || titleStyle.componentDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
symbol.ClearVerticesDirty();
lineStyle.ClearVerticesDirty();
lineArrow.ClearVerticesDirty();
itemStyle.ClearVerticesDirty();
areaStyle.ClearVerticesDirty();
label.ClearVerticesDirty();
emphasis.ClearVerticesDirty();
gaugeAxis.ClearVerticesDirty();
gaugePointer.ClearVerticesDirty();
titleStyle.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
symbol.ClearComponentDirty();
lineStyle.ClearComponentDirty();
lineArrow.ClearComponentDirty();
itemStyle.ClearComponentDirty();
areaStyle.ClearComponentDirty();
label.ClearComponentDirty();
emphasis.ClearComponentDirty();
gaugeAxis.ClearComponentDirty();
gaugePointer.ClearComponentDirty();
titleStyle.ClearComponentDirty();
}
/// <summary>
/// The index of serie,start at 0.
/// 系列的索引从0开始。
@@ -544,7 +812,22 @@ namespace XCharts
/// </summary>
public float runtimePieDataTotal { get; internal set; }
internal int runtimeLastCheckDataCount { get; set; }
public bool nameDirty { get { return m_NameDirty; } }
private void SetNameDirty()
{
m_NameDirty = true;
}
public void ClearNameDirty()
{
m_NameDirty = false;
}
public override void ClearDirty()
{
base.ClearDirty();
}
internal List<Vector3> GetUpSmoothList(int dataIndex, int size = 100)
{
if (m_UpSmoothPoints.ContainsKey(dataIndex))
@@ -701,6 +984,7 @@ namespace XCharts
public void ClearData()
{
m_Data.Clear();
SetVerticesDirty();
}
/// <summary>
@@ -709,7 +993,15 @@ namespace XCharts
/// <param name="index"></param>
public void RemoveData(int index)
{
m_Data.RemoveAt(index);
if (index >= 0 && index < m_Data.Count)
{
if (!string.IsNullOrEmpty(m_Data[index].name))
{
SetNameDirty();
}
SetVerticesDirty();
m_Data.RemoveAt(index);
}
}
/// <summary>
@@ -731,15 +1023,28 @@ namespace XCharts
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;
SetVerticesDirty();
CheckDataName(dataName);
return serieData;
}
private void CheckDataName(string dataName)
{
if (string.IsNullOrEmpty(dataName))
{
SetNameDirty();
}
else
{
m_ShowDataName = true;
}
}
/// <summary>
/// 添加xy数据到维度X和维度Y
/// </summary>
@@ -760,12 +1065,13 @@ namespace XCharts
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;
SetVerticesDirty();
CheckDataName(dataName);
return serieData;
}
@@ -804,9 +1110,10 @@ namespace XCharts
for (int i = 0; i < valueList.Count; i++)
{
serieData.data.Add(valueList[i]);
serieData.lastData.Add(valueList[i]);
}
m_Data.Add(serieData);
SetVerticesDirty();
CheckDataName(dataName);
return serieData;
}
}
@@ -968,15 +1275,28 @@ namespace XCharts
{
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
if (startIndex != m_FilterStart || endIndex != m_FilterEnd || m_NeedUpdateFilterData)
if (endIndex < startIndex) endIndex = startIndex;
if (startIndex != m_FilterStart || endIndex != m_FilterEnd || dataZoom.minShowNum != m_FilterMinShow || m_NeedUpdateFilterData)
{
m_FilterStart = startIndex;
m_FilterEnd = endIndex;
m_FilterMinShow = dataZoom.minShowNum;
m_NeedUpdateFilterData = false;
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
if (count < dataZoom.minShowNum)
{
if (dataZoom.minShowNum > m_Data.Count) count = m_Data.Count;
else count = dataZoom.minShowNum;
}
if (m_Data.Count > 0)
{
m_FilterData = m_Data.GetRange(startIndex, count);
if (startIndex + count > m_Data.Count)
{
int start = endIndex - count;
m_FilterData = m_Data.GetRange(start < 0 ? 0 : start, count);
}
else m_FilterData = m_Data.GetRange(startIndex, count);
}
else
{
@@ -1024,7 +1344,9 @@ namespace XCharts
{
if (index >= 0 && index < m_Data.Count)
{
return m_Data[index].UpdateData(dimension, value);
var flag = m_Data[index].UpdateData(dimension, value);
if (flag) SetVerticesDirty();
return flag;
}
else
{
@@ -1041,9 +1363,10 @@ namespace XCharts
{
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);
var serieData = m_Data[index];
for (int i = 0; i < values.Count; i++)
serieData.UpdateData(i, values[i]);
SetVerticesDirty();
return true;
}
return false;
@@ -1055,6 +1378,7 @@ namespace XCharts
{
var serieData = m_Data[index];
serieData.name = name;
SetNameDirty();
if (serieData.labelText != null)
{
serieData.labelText.text = name == null ? "" : name;
@@ -1232,6 +1556,20 @@ namespace XCharts
return false;
}
public bool IsIngoreValue(float value)
{
return m_Ignore && Mathf.Approximately(value, m_IgnoreValue);
}
public bool IsIngorePoint(int index)
{
if (index >= 0 && index < dataPoints.Count)
{
return ChartHelper.IsIngore(dataPoints[index]);
}
return false;
}
/// <summary>
/// 更新运行时中心点和半径
/// </summary>
@@ -1361,6 +1699,7 @@ namespace XCharts
}
}
}
SetAllDirty();
}
}
}

View File

@@ -18,12 +18,13 @@ namespace XCharts
[System.Serializable]
public class Series : MainComponent
{
[SerializeField] protected List<Serie> m_Series;
[NonSerialized] private bool m_LabelDirty;
[Obsolete("Use Series.list instead.", true)]
public List<Serie> series { get { return m_Series; } }
/// <summary>
/// the list of serie
/// 系列列表。
@@ -51,12 +52,80 @@ namespace XCharts
}
}
public override bool vertsDirty
{
get
{
if (m_VertsDirty) return true;
foreach (var serie in m_Series)
{
if (serie.vertsDirty) return true;
}
return false;
}
}
public bool labelDirty
{
get
{
if (m_LabelDirty) return true;
foreach (var serie in m_Series)
{
if (serie.label.componentDirty) return true;
}
return false;
}
}
public bool labelUpdate
{
get
{
foreach (var serie in m_Series)
{
if (serie.label.vertsDirty) return true;
}
return false;
}
}
public void SetLabelDirty()
{
m_LabelDirty = true;
}
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
foreach (var serie in m_Series)
{
serie.ClearVerticesDirty();
}
}
internal void ClearLabelDirty()
{
m_LabelDirty = false;
foreach (var serie in m_Series)
{
serie.label.ClearVerticesDirty();
}
}
public override void SetAllDirty()
{
base.SetAllDirty();
SetLabelDirty();
}
/// <summary>
/// 清空所有系列的数据
/// </summary>
public void ClearData()
{
AnimationStop();
AnimationFadeIn();
foreach (var serie in m_Series)
{
serie.ClearData();
@@ -179,11 +248,24 @@ namespace XCharts
return false;
}
/// <summary>
/// 是否有需裁剪的serie。
/// </summary>
/// <returns></returns>
internal bool IsAnyClipSerie()
{
foreach (var serie in m_Series)
{
if (serie.clip) return true;
}
return false;
}
internal bool IsAnyUpdateAnimationSerie()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable && serie.animation.updateAnimation)
if (serie.animation.enable && serie.animation.dataChangeEnable)
{
return true;
}
@@ -244,7 +326,7 @@ namespace XCharts
/// </summary>
public void RemoveAll()
{
AnimationStop();
AnimationFadeIn();
m_Series.Clear();
}
@@ -279,8 +361,9 @@ namespace XCharts
{
serie.symbol.type = SerieSymbolType.None;
}
serie.animation.Reset();
serie.animation.Restart();
m_Series.Add(serie);
SetVerticesDirty();
return serie;
}
@@ -452,7 +535,8 @@ namespace XCharts
return false;
}
public bool UpdateData(string serieName,int dataIndex,List<float> values){
public bool UpdateData(string serieName, int dataIndex, List<float> values)
{
var serie = GetSerie(serieName);
if (serie != null)
{
@@ -460,7 +544,8 @@ namespace XCharts
}
return false;
}
public bool UpdateData(int serieIndex,int dataIndex,List<float> values){
public bool UpdateData(int serieIndex, int dataIndex, List<float> values)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
@@ -600,6 +685,8 @@ namespace XCharts
if (serie != null)
{
serie.show = active;
serie.animation.Reset();
if (active) serie.animation.FadeIn();
}
}
@@ -746,16 +833,8 @@ namespace XCharts
}
else
{
if (max > 1)
{
minVaule = Mathf.FloorToInt(min);
maxValue = Mathf.CeilToInt(max);
}
else
{
minVaule = min;
maxValue = max;
}
minVaule = min > 1 ? Mathf.FloorToInt(min) : min;
maxValue = max > 1 ? Mathf.CeilToInt(max) : max;
}
}
@@ -954,6 +1033,7 @@ namespace XCharts
{
case SerieType.Pie:
case SerieType.Radar:
case SerieType.Ring:
for (int i = 0; i < serie.data.Count; i++)
{
if (string.IsNullOrEmpty(serie.data[i].name))
@@ -999,32 +1079,54 @@ namespace XCharts
}
/// <summary>
/// 开始初始动画
/// 渐入动画
/// </summary>
public void AnimationStart()
public void AnimationFadeIn()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable)
{
serie.animation.Start();
serie.animation.FadeIn();
}
}
}
/// <summary>
/// 停止初始动画
/// 渐出动画
/// </summary>
public void AnimationStop()
public void AnimationFadeOut()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Stop();
if (serie.animation.enable) serie.animation.FadeOut();
}
}
/// <summary>
/// 重置初始动画
/// 暂停动画
/// </summary>
public void AnimationPause()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Pause();
}
}
/// <summary>
/// 继续动画
/// </summary>
public void AnimationResume()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Resume();
}
}
/// <summary>
/// 重置动画
/// </summary>
public void AnimationReset()
{

View File

@@ -30,14 +30,22 @@ namespace XCharts
/// and different curves with slightly different appearance can be obtained.
/// 曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
/// </summary>
public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value <= 0 ? 1f : value; } }
public float lineSmoothStyle
{
get { return m_LineSmoothStyle; }
set { if (PropertyUtility.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// Smoothness of curve. The smaller the value, the smoother the curve, but the number of vertices will increase.
/// When the area with gradient is filled, the larger the value, the worse the transition effect.
/// 曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
/// </summary>
/// <value></value>
public float lineSmoothness { get { return m_LineSmoothness; } set { m_LineSmoothness = value <= 0 ? 1f : value; } }
public float lineSmoothness
{
get { return m_LineSmoothness; }
set { if (PropertyUtility.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// The partition distance of a line segment. A line in a normal line chart is made up of many segments,
/// the number of which is determined by the change in value. The smaller the number of segments,
@@ -45,25 +53,44 @@ namespace XCharts
/// 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
/// </summary>
/// <value></value>
public float lineSegmentDistance { get { return m_LineSegmentDistance; } set { m_LineSegmentDistance = value <= 0 ? 1f : value; } }
public float lineSegmentDistance
{
get { return m_LineSegmentDistance; }
set { if (PropertyUtility.SetStruct(ref m_LineSegmentDistance, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// the smoothess of cricle.
/// 圆形的平滑度。数越小圆越平滑,但顶点数也会随之增加。
/// </summary>
public float cicleSmoothness { get { return m_CicleSmoothness; } set { m_CicleSmoothness = value <= 0 ? 1f : value; } }
public float cicleSmoothness
{
get { return m_CicleSmoothness; }
set { if (PropertyUtility.SetStruct(ref m_CicleSmoothness, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// 可视化组件的调节三角形长。
/// 可视化组件的调节三角形长。
/// </summary>
/// <value></value>
public float visualMapTriangeLen { get { return m_VisualMapTriangeLen; } set { m_VisualMapTriangeLen = value <= 0 ? 1f : value; } }
public float visualMapTriangeLen
{
get { return m_VisualMapTriangeLen; }
set { if (PropertyUtility.SetStruct(ref m_VisualMapTriangeLen, value < 0 ? 1f : value)) SetVerticesDirty(); }
}
/// <summary>
/// 饼图鼠标移到高亮时的额外半径
/// </summary>
public float pieTooltipExtraRadius { get { return m_PieTooltipExtraRadius; } set { m_PieTooltipExtraRadius = value <= 0 ? 0 : value; } }
public float pieTooltipExtraRadius
{
get { return m_PieTooltipExtraRadius; }
set { if (PropertyUtility.SetStruct(ref m_PieTooltipExtraRadius, value < 0 ? 0f : value)) SetVerticesDirty(); }
}
/// <summary>
/// 饼图选中时的中心点偏移
/// </summary>
public float pieSelectedOffset { get { return m_PieSelectedOffset; } set { m_PieSelectedOffset = value <= 0 ? 0 : value; } }
public float pieSelectedOffset
{
get { return m_PieSelectedOffset; }
set { if (PropertyUtility.SetStruct(ref m_PieSelectedOffset, value < 0 ? 0f : value)) SetVerticesDirty(); }
}
}
}

View File

@@ -36,7 +36,7 @@ namespace XCharts
/// Theme.
/// 主题相关配置。
/// </summary>
public class ThemeInfo : MainComponent, IEquatable<ThemeInfo>
public class ThemeInfo : MainComponent
{
[SerializeField] private Theme m_Theme = Theme.Default;
[SerializeField] private Font m_Font;
@@ -86,7 +86,11 @@ namespace XCharts
/// the theme of chart.
/// 主题类型。
/// </summary>
public Theme theme { get { return m_Theme; } set { m_Theme = value; } }
public Theme theme
{
get { return m_Theme; }
set { if (PropertyUtility.SetStruct(ref m_Theme, value)) SetComponentDirty(); }
}
/// <summary>
/// the font of chart text。
/// 字体。
@@ -94,7 +98,7 @@ namespace XCharts
public Font font
{
get { return m_CustomFont != null ? m_CustomFont : m_Font; }
set { m_CustomFont = value; }
set { if (PropertyUtility.SetClass(ref m_CustomFont, value)) SetComponentDirty(); }
}
/// <summary>
/// the background color of chart.
@@ -103,7 +107,7 @@ namespace XCharts
public Color32 backgroundColor
{
get { return m_CustomBackgroundColor != Color.clear ? m_CustomBackgroundColor : m_BackgroundColor; }
set { m_CustomBackgroundColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomBackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the main title text color.
@@ -112,7 +116,7 @@ namespace XCharts
public Color32 titleTextColor
{
get { return m_CustomTitleTextColor != Color.clear ? m_CustomTitleTextColor : m_TitleTextColor; }
set { m_CustomTitleTextColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTitleTextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the subtitie text color.
@@ -121,7 +125,7 @@ namespace XCharts
public Color32 titleSubTextColor
{
get { return m_CustomTitleSubTextColor != Color.clear ? m_CustomTitleSubTextColor : m_TitleSubTextColor; }
set { m_CustomTitleSubTextColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTitleSubTextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the legend text color.
@@ -130,7 +134,7 @@ namespace XCharts
public Color32 legendTextColor
{
get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; }
set { m_CustomLegendTextColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomLegendTextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the legend unable text color.
@@ -139,7 +143,7 @@ namespace XCharts
public Color32 legendUnableColor
{
get { return m_CustomLegendUnableColor != Color.clear ? m_CustomLegendUnableColor : m_LegendUnableColor; }
set { m_CustomLegendUnableColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomLegendUnableColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the axis text color.
@@ -148,7 +152,7 @@ namespace XCharts
public Color32 axisTextColor
{
get { return m_CustomAxisTextColor != Color.clear ? m_CustomAxisTextColor : m_AxisTextColor; }
set { m_CustomAxisTextColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomAxisTextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of axis line.
@@ -157,7 +161,7 @@ namespace XCharts
public Color32 axisLineColor
{
get { return m_CustomAxisLineColor != Color.clear ? m_CustomAxisLineColor : m_AxisLineColor; }
set { m_CustomAxisLineColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomAxisLineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of axis split line.
@@ -166,7 +170,7 @@ namespace XCharts
public Color32 axisSplitLineColor
{
get { return m_CustomAxisSplitLineColor != Color.clear ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; }
set { m_CustomAxisSplitLineColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomAxisSplitLineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the tooltip background color.
@@ -175,7 +179,7 @@ namespace XCharts
public Color32 tooltipBackgroundColor
{
get { return m_CustomTooltipBackgroundColor != Color.clear ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; }
set { m_CustomTooltipBackgroundColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTooltipBackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of tooltip shadow crosshair indicator.
@@ -184,7 +188,7 @@ namespace XCharts
public Color32 tooltipFlagAreaColor
{
get { return m_CustomTooltipFlagAreaColor != Color.clear ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; }
set { m_CustomTooltipFlagAreaColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTooltipFlagAreaColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of tooltip text.
@@ -193,7 +197,7 @@ namespace XCharts
public Color32 tooltipTextColor
{
get { return m_CustomTooltipTextColor != Color.clear ? m_CustomTooltipTextColor : m_TooltipTextColor; }
set { m_CustomTooltipTextColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTooltipTextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the background color of tooltip cross indicator's axis label.
@@ -202,7 +206,7 @@ namespace XCharts
public Color32 tooltipLabelColor
{
get { return m_CustomTooltipLabelColor != Color.clear ? m_CustomTooltipLabelColor : m_TooltipLabelColor; }
set { m_CustomTooltipLabelColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTooltipLabelColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color tooltip indicator line.
@@ -211,7 +215,7 @@ namespace XCharts
public Color32 tooltipLineColor
{
get { return m_CustomTooltipLineColor != Color.clear ? m_CustomTooltipLineColor : m_TooltipLineColor; }
set { m_CustomTooltipLineColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomTooltipLineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of datazoom text.
@@ -220,7 +224,7 @@ namespace XCharts
public Color32 dataZoomTextColor
{
get { return m_CustomDataZoomTextColor != Color.clear ? m_CustomDataZoomTextColor : m_DataZoomTextColor; }
set { m_CustomDataZoomTextColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomDataZoomTextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of datazoom line.
@@ -229,7 +233,7 @@ namespace XCharts
public Color32 dataZoomLineColor
{
get { return m_CustomDataZoomLineColor != Color.clear ? m_CustomDataZoomLineColor : m_DataZoomLineColor; }
set { m_CustomDataZoomLineColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomDataZoomLineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of datazoom selected area.
@@ -238,7 +242,7 @@ namespace XCharts
public Color32 dataZoomSelectedColor
{
get { return m_CustomDataZoomSelectedColor != Color.clear ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; }
set { m_CustomDataZoomSelectedColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomDataZoomSelectedColor, value)) SetVerticesDirty(); }
}
/// <summary>
@@ -247,7 +251,7 @@ namespace XCharts
public Color32 visualMapBackgroundColor
{
get { return m_CustomVisualMapBackgroundColor != Color.clear ? m_CustomVisualMapBackgroundColor : m_VisualMapBackgroundColor; }
set { m_CustomVisualMapBackgroundColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomVisualMapBackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
@@ -256,14 +260,14 @@ namespace XCharts
public Color32 visualMapBorderColor
{
get { return m_CustomVisualMapBorderColor != Color.clear ? m_CustomVisualMapBorderColor : m_VisualMapBorderColor; }
set { m_CustomVisualMapBorderColor = value; }
set { if (PropertyUtility.SetColor(ref m_CustomVisualMapBorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
/// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。
/// </summary>
public List<Color32> colorPalette { set { m_CustomColorPalette = value; } }
public List<Color32> colorPalette { set { m_CustomColorPalette = value; SetVerticesDirty(); } }
/// <summary>
/// Gets the color of the specified index from the palette.
@@ -310,6 +314,22 @@ namespace XCharts
}
}
public void Copy(Theme theme)
{
switch (theme)
{
case Theme.Dark:
Copy(ThemeInfo.Dark);
break;
case Theme.Default:
Copy(ThemeInfo.Default);
break;
case Theme.Light:
Copy(ThemeInfo.Light);
break;
}
}
/// <summary>
/// copy all configurations from theme.
/// 复制主题的所有配置。
@@ -391,7 +411,7 @@ namespace XCharts
m_LegendUnableColor = GetColor("#cccccc"),
m_TitleTextColor = GetColor("#514D4D"),
m_TitleSubTextColor = GetColor("#514D4D"),
m_LegendTextColor = GetColor("#eee"),
m_LegendTextColor = GetColor("#514D4D"),
m_AxisTextColor = GetColor("#514D4D"),
m_AxisLineColor = GetColor("#514D4D"),
m_AxisSplitLineColor = GetColor("#51515120"),
@@ -577,64 +597,6 @@ namespace XCharts
return (Color32)color;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is ThemeInfo)
{
return Equals((ThemeInfo)obj);
}
else
{
return false;
}
}
public bool Equals(ThemeInfo other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return m_Font == other.m_Font &&
ChartHelper.IsValueEqualsColor(m_LegendUnableColor, other.m_LegendUnableColor) &&
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.m_BackgroundColor) &&
ChartHelper.IsValueEqualsColor(m_TitleTextColor, other.m_TitleTextColor) &&
ChartHelper.IsValueEqualsColor(m_TitleSubTextColor, other.m_TitleSubTextColor) &&
ChartHelper.IsValueEqualsColor(m_AxisTextColor, other.m_AxisTextColor) &&
ChartHelper.IsValueEqualsColor(m_AxisLineColor, other.m_AxisLineColor) &&
ChartHelper.IsValueEqualsColor(m_AxisSplitLineColor, other.m_AxisSplitLineColor) &&
ChartHelper.IsValueEqualsColor(m_TooltipBackgroundColor, other.m_TooltipBackgroundColor) &&
ChartHelper.IsValueEqualsColor(m_AxisSplitLineColor, other.m_AxisSplitLineColor) &&
ChartHelper.IsValueEqualsColor(m_TooltipTextColor, other.m_TooltipTextColor) &&
ChartHelper.IsValueEqualsColor(m_TooltipFlagAreaColor, other.m_TooltipFlagAreaColor) &&
ChartHelper.IsValueEqualsColor(m_DataZoomLineColor, other.m_DataZoomLineColor) &&
ChartHelper.IsValueEqualsColor(m_DataZoomSelectedColor, other.m_DataZoomSelectedColor) &&
ChartHelper.IsValueEqualsColor(m_DataZoomTextColor, other.m_DataZoomTextColor) &&
m_ColorPalette.Length == other.m_ColorPalette.Length;
}
public static bool operator ==(ThemeInfo left, ThemeInfo right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(ThemeInfo left, ThemeInfo right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();

View File

@@ -15,7 +15,7 @@ namespace XCharts
/// 标题组件,包含主标题和副标题。
/// </summary>
[Serializable]
public class Title : MainComponent, IPropertyChanged, IEquatable<Title>
public class Title : MainComponent, IPropertyChanged
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Text;
@@ -30,50 +30,61 @@ namespace XCharts
/// Set this to false to prevent the title from showing.
/// 是否显示标题组件。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show { get { return m_Show; } set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// The main title text, supporting for \n for newlines.
/// 主标题文本,支持使用 \n 换行。
/// </summary>
public string text { get { return m_Text; } set { m_Text = value; } }
public string text { get { return m_Text; } set { if (PropertyUtility.SetClass(ref m_Text, value)) SetComponentDirty(); } }
/// <summary>
/// [default:16]
/// main title font size.
/// 主标题文字的字体大小。
/// </summary>
[Obsolete("use textStyle instead.", false)]
[Obsolete("use textStyle instead.", true)]
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; } }
public TextStyle textStyle { get { return m_TextStyle; } set { if (PropertyUtility.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } }
/// <summary>
/// Subtitle text, supporting for \n for newlines.
/// 副标题文本,支持使用 \n 换行。
/// </summary>
public string subText { get { return m_SubText; } set { m_SubText = value; } }
public string subText { get { return m_SubText; } set { if (PropertyUtility.SetClass(ref m_SubText, value)) SetComponentDirty(); } }
/// <summary>
/// 副标题文本样式。
/// </summary>
public TextStyle subTextStyle { get { return m_SubTextStyle; } set { m_SubTextStyle = value; } }
public TextStyle subTextStyle { get { return m_SubTextStyle; } set { if (PropertyUtility.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); } }
/// <summary>
/// [default:14]
/// subtitle font size.
/// 副标题文字的字体大小。
/// </summary>
[Obsolete("use subTextStyle instead.", false)]
[Obsolete("use subTextStyle instead.", true)]
public int subTextFontSize { get { return m_SubTextStyle.fontSize; } set { m_SubTextStyle.fontSize = value; } }
/// <summary>
/// [default:8]
/// The gap between the main title and subtitle.
/// 主副标题之间的间距。
/// </summary>
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
public float itemGap { get { return m_ItemGap; } set { if (PropertyUtility.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } }
/// <summary>
/// The location of title component.
/// 标题显示位置。
/// </summary>
public Location location { get { return m_Location; } set { m_Location = value; } }
public Location location { get { return m_Location; } set { if (PropertyUtility.SetClass(ref m_Location, value)) SetComponentDirty(); } }
public override bool vertsDirty { get { return false; } }
public override bool componentDirty { get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty || subTextStyle.componentDirty; } }
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
textStyle.ClearComponentDirty();
subTextStyle.ClearComponentDirty();
}
public static Title defaultTitle
{
@@ -92,70 +103,6 @@ namespace XCharts
return title;
}
}
public void Copy(Title title)
{
m_Show = title.show;
m_Text = title.text;
m_TextStyle.Copy(title.textStyle);
m_SubTextStyle.Copy(title.subTextStyle);
m_SubText = title.subText;
m_ItemGap = title.itemGap;
m_Location.Copy(title.location);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Title)
{
return Equals((Title)obj);
}
else
{
return false;
}
}
public bool Equals(Title other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return m_Show == other.show &&
m_Text.Equals(other.text) &&
m_TextStyle.Equals(other.textStyle) &&
m_SubText.Equals(other.subText) &&
m_SubTextStyle.Equals(other.subTextStyle) &&
m_ItemGap == other.itemGap &&
m_Location.Equals(other.location);
}
public static bool operator ==(Title left, Title right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(Title left, Title right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public void OnChanged()
{

View File

@@ -1,4 +1,5 @@
/******************************************/
using System.Collections.ObjectModel;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
@@ -8,6 +9,8 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;
namespace XCharts
{
@@ -49,33 +52,74 @@ namespace XCharts
[SerializeField] private bool m_Show;
[SerializeField] private Type m_Type;
[SerializeField] private string m_Formatter;
[SerializeField] private string m_ItemFormatter;
[SerializeField] private string m_TitleFormatter;
[SerializeField] private float m_FixedWidth = 0;
[SerializeField] private float m_FixedHeight = 0;
[SerializeField] private float m_MinWidth = 0;
[SerializeField] private float m_MinHeight = 0;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_ForceENotation = false;
[SerializeField] private float m_PaddingLeftRight = 5f;
[SerializeField] private float m_PaddingTopBottom = 5f;
[SerializeField] private string m_IgnoreDataDefaultContent = "-";
[SerializeField] private Sprite m_BackgroundImage;
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18, FontStyle.Normal);
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid, 0.7f);
private GameObject m_GameObject;
private GameObject m_Content;
private Text m_ContentText;
private Image m_ContentImage;
private RectTransform m_ContentRect;
private RectTransform m_ContentTextRect;
private List<int> lastDataIndex { get; set; }
/// <summary>
/// Whether to show the tooltip component.
/// 是否显示提示框组件。
/// </summary>
/// <returns></returns>
public bool show { get { return m_Show; } set { m_Show = value; SetActive(value); } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) { SetAllDirty(); SetActive(value); } }
}
/// <summary>
/// Indicator type.
/// 提示框指示器类型。
/// </summary>
public Type type { get { return m_Type; } set { m_Type = value; } }
public Type type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetAllDirty(); }
}
/// <summary>
/// 提示框内容字符串模版格式器。支持用 \n 或 "<br/>" 换行。
/// 提示框内容字符串模版格式器。支持用 \n 或 "<br/>" 换行。当formatter不为空时优先使用formatter否则使用itemFormatter。
/// 模板变量有 {a}, {b}{c}{d}{e},分别表示系列名,数据名,数据值等。{a0},{b1},c{1}等可指定serie。
/// 其中变量{a}, {b}, {c}, {d}在不同图表类型下代表数据含义为:
/// <list type="bullet">
/// <item><description>折线区域图、柱状条形图、K线图 : {a}(系列名称),{b}(类目值),{c}(数值), {d}(无)。</description></item>
/// <item><description>散点图(气泡)图 : {a}(系列名称),{b}(数据名称),{c}(数值数组), {d}(无)。</description></item>
/// <item><description>地图 : {a}(系列名称),{b}(区域名称),{c}(合并数值), {d}(无)。</description></item>
/// <item><description>饼图、仪表盘、漏斗图: {a}(系列名称),{b}(数据项名称),{c}(数值), {d}(百分比)。</description></item>
/// </list>
/// 示例:"{a}:{c}","{a1}:{c1:f1}"
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <summary>
/// 提示框标题内容的字符串模版格式器。支持用 \n 或 "<br/>" 换行。仅当itemFormatter生效时才有效。
/// 模板变量有 {a}, {b}{c}{d}{e},分别表示系列名,数据名,数据值等。{a0},{b1},c{1}等可指定serie。
/// 其中变量{a}, {b}, {c}, {d}在不同图表类型下代表数据含义为:
/// <list type="bullet">
/// <item><description>折线区域图、柱状条形图、K线图 : {a}(系列名称),{b}(类目值),{c}(数值), {d}(无)。</description></item>
/// <item><description>散点图(气泡)图 : {a}(系列名称),{b}(数据名称),{c}(数值数组), {d}(无)。</description></item>
/// <item><description>地图 : {a}(系列名称),{b}(区域名称),{c}(合并数值), {d}(无)。</description></item>
/// <item><description>饼图、仪表盘、漏斗图: {a}(系列名称),{b}(数据项名称),{c}(数值), {d}(百分比)。</description></item>
/// </list>
/// 示例:"{a}:{c}","{a1}:{c1:f1}"
/// </summary>
public string titleFormatter { get { return m_TitleFormatter; } set { m_TitleFormatter = value; } }
/// <summary>
/// 提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 或 "<br/>" 换行。当formatter不为空时优先使用formatter否则使用itemFormatter。
/// 模板变量有 {a}, {b}{c}{d}{e},分别表示系列名,数据名,数据值等。
/// 其中变量{a}, {b}, {c}, {d}在不同图表类型下代表数据含义为:
/// <list type="bullet">
@@ -84,11 +128,10 @@ namespace XCharts
/// <item><description>地图 : {a}(系列名称),{b}(区域名称),{c}(合并数值), {d}(无)。</description></item>
/// <item><description>饼图、仪表盘、漏斗图: {a}(系列名称),{b}(数据项名称),{c}(数值), {d}(百分比)。</description></item>
/// </list>
/// 示例:"{a}:{c}","{a}:{c:f1}"
/// </summary>
/// <example>
/// 示例:“{a}:{c}”
/// </example>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
/// <summary>
/// 固定宽度。比 minWidth 优先。
/// </summary>
@@ -105,20 +148,64 @@ namespace XCharts
/// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
/// </summary>
public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } }
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
/// <summary>
/// font style.
/// 文字的字体风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
[Obsolete("Use Tooltip.textStyle.fontSize instead.", true)]
public int fontSize { get; set; }
[Obsolete("Use Tooltip.textStyle.fontStyle instead.", true)]
public FontStyle fontStyle { get; set; }
/// <summary>
/// 是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
/// </summary>
public bool forceENotation { get { return m_ForceENotation; } set { m_ForceENotation = value; } }
/// <summary>
/// the text padding of left and right. defaut:5.
/// 左右边距。
/// </summary>
public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
/// <summary>
/// the text padding of top and bottom. defaut:5.
/// 上下边距。
/// </summary>
public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } }
/// <summary>
/// 被忽略数据的默认显示字符信息。
/// </summary>
public string ignoreDataDefaultContent { get { return m_IgnoreDataDefaultContent; } set { m_IgnoreDataDefaultContent = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetBackground(m_BackgroundImage); } }
/// <summary>
/// 提示框内容文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (value != null) { m_TextStyle = value; SetComponentDirty(); } }
}
/// <summary>
/// 指示线样式。
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) m_LineStyle = value; SetComponentDirty(); }
}
/// <summary>
/// 组件是否需要刷新
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty || lineStyle.componentDirty || textStyle.componentDirty; }
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
lineStyle.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
/// <summary>
/// The data index currently indicated by Tooltip.
@@ -195,7 +282,13 @@ namespace XCharts
{
m_Content = content;
m_ContentRect = m_Content.GetComponent<RectTransform>();
m_ContentImage = m_Content.GetComponent<Image>();
m_ContentText = m_Content.GetComponentInChildren<Text>();
if (m_ContentText != null)
{
m_ContentTextRect = m_ContentText.gameObject.GetComponentInChildren<RectTransform>();
}
SetBackground(backgroundImage);
}
/// <summary>
@@ -214,8 +307,21 @@ namespace XCharts
/// <param name="color"></param>
public void SetContentBackgroundColor(Color color)
{
if (m_Content != null && m_Content.GetComponent<Image>() != null)
m_Content.GetComponent<Image>().color = color;
if (m_ContentImage != null)
m_ContentImage.color = color;
}
/// <summary>
/// 设置提示框文本背景图片
/// </summary>
/// <param name="sprite"></param>
public void SetBackground(Sprite sprite)
{
if (m_ContentImage != null)
{
m_ContentImage.type = Image.Type.Sliced;
m_ContentImage.sprite = sprite;
}
}
/// <summary>
@@ -242,11 +348,15 @@ namespace XCharts
float wid, hig;
if (m_FixedWidth > 0) wid = m_FixedWidth;
else if (m_MinWidth > 0 && m_ContentText.preferredWidth < m_MinWidth) wid = m_MinWidth;
else wid = m_ContentText.preferredWidth + 8;
else wid = m_ContentText.preferredWidth + m_PaddingLeftRight * 2;
if (m_FixedHeight > 0) hig = m_FixedHeight;
else if (m_MinHeight > 0 && m_ContentText.preferredHeight < m_MinHeight) hig = m_MinHeight;
else hig = m_ContentText.preferredHeight + 8;
m_ContentRect.sizeDelta = new Vector2(wid, hig);
else hig = m_ContentText.preferredHeight + m_PaddingTopBottom * 2;
if (m_ContentRect != null) m_ContentRect.sizeDelta = new Vector2(wid, hig);
if (m_ContentTextRect != null)
{
m_ContentTextRect.anchoredPosition = new Vector3(m_PaddingLeftRight, -m_PaddingTopBottom);
}
}
}
@@ -341,11 +451,69 @@ namespace XCharts
return runtimeDataIndex[0] == index || runtimeDataIndex[1] == index;
}
internal string GetFormatterContent(int dataIndex, Series series, string category, DataZoom dataZoom = null)
public bool IsNoFormatter()
{
return string.IsNullOrEmpty(m_Formatter) && string.IsNullOrEmpty(m_ItemFormatter);
}
internal string GetFormatterContent(int dataIndex, Series series, string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null)
{
if (string.IsNullOrEmpty(m_Formatter))
{
return "";
if (string.IsNullOrEmpty(m_ItemFormatter)) return "";
else
{
var sb = ChartHelper.sb;
var title = m_TitleFormatter;
var formatTitle = !string.IsNullOrEmpty(title);
var needCategory = false;
var first = true;
sb.Length = 0;
for (int i = 0; i < series.Count; i++)
{
var serie = series.GetSerie(i);
var serieData = serie.GetSerieData(dataIndex, dataZoom);
var percent = serieData.GetData(1) / serie.yTotal * 100;
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
if (serie.show)
{
string content = m_ItemFormatter;
content = content.Replace("{a}", serie.name);
content = content.Replace("{b}", needCategory ? category : serieData.name);
content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
if (!first) sb.Append("\n");
sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
sb.Append(content);
first = false;
}
if (formatTitle)
{
if (i == 0)
{
title = title.Replace("{a}", serie.name);
title = title.Replace("{b}", needCategory ? category : serieData.name);
title = title.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
title = title.Replace("{d}", ChartCached.FloatToStr(percent, 1));
}
title = title.Replace("{a" + i + "}", serie.name);
title = title.Replace("{b" + i + "}", needCategory ? category : serieData.name);
title = title.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
title = title.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
}
}
if (string.IsNullOrEmpty(title))
{
if (needCategory) return category + "\n" + sb.ToString();
else return sb.ToString();
}
else
{
title = title.Replace("\\n", "\n");
title = title.Replace("<br/>", "\n");
return title + "\n" + sb.ToString();
}
}
}
else
{
@@ -357,25 +525,18 @@ namespace XCharts
{
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
var serieData = serie.GetSerieData(dataIndex, dataZoom);
var percent = serieData.GetData(1) / serie.yTotal * 100;
if (i == 0)
{
content = content.Replace("{a}", serie.name);
content = content.Replace("{b}", needCategory ? category : serieData.name);
content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
//if (serie.type == SerieType.Pie)
{
var percent = serieData.GetData(1) / serie.yTotal * 100;
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
}
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
}
content = content.Replace("{a" + i + "}", serie.name);
content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name);
content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
//if (serie.type == SerieType.Pie)
{
var percent = serieData.GetData(1) / serie.yTotal * 100;
content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
}
content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
}
}
content = content.Replace("\\n", "\n");
@@ -398,5 +559,21 @@ namespace XCharts
return content;
}
}
internal Color GetLineColor(ThemeInfo theme)
{
if (lineStyle.color != Color.clear)
{
var color = lineStyle.color;
color.a *= lineStyle.opacity;
return color;
}
else
{
var color = (Color)theme.tooltipLineColor;
color.a *= lineStyle.opacity;
return color;
}
}
}
}

View File

@@ -73,27 +73,51 @@ namespace XCharts
/// <summary>
/// 是否开启组件功能。
/// </summary>
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否显示组件。如果设置为 false不会显示但是数据映射的功能还存在。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
}
/// <summary>
/// 组件类型。
/// </summary>
public Type type { get { return m_Type; } set { m_Type = value; } }
public Type type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// 选择模式。
/// </summary>
public SelectedMode selectedMode { get { return m_SelectedMode; } set { m_SelectedMode = value; } }
public SelectedMode selectedMode
{
get { return m_SelectedMode; }
set { if (PropertyUtility.SetStruct(ref m_SelectedMode, value)) SetVerticesDirty(); }
}
/// <summary>
/// 允许的最小值。'min' 必须用户指定。[visualMap.min, visualMap.max] 形成了视觉映射的『定义域』。
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
public float min
{
get { return m_Min; }
set { if (PropertyUtility.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
}
/// <summary>
/// 允许的最大值。'max' 必须用户指定。[visualMap.min, visualMax.max] 形成了视觉映射的『定义域』。
/// </summary>
public float max { get { return m_Max; } set { m_Max = value < min ? min + 1 : value; } }
public float max
{
get { return m_Max; }
set { m_Max = value < min ? min + 1 : value; SetVerticesDirty(); }
}
/// <summary>
/// 指定手柄对应数值的位置。range 应在 min max 范围内。
/// </summary>
@@ -110,55 +134,116 @@ namespace XCharts
/// 对于连续型数据自动平均切分成几段默认为0时自动匹配inRange颜色列表大小。
/// </summary>
/// <value></value>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否显示拖拽用的手柄(手柄能拖拽调整选中范围)。
/// </summary>
public bool calculable { get { return m_Calculable; } set { m_Calculable = value; } }
public bool calculable
{
get { return m_Calculable; }
set { if (PropertyUtility.SetStruct(ref m_Calculable, value)) SetVerticesDirty(); }
}
/// <summary>
/// 拖拽时,是否实时更新。
/// </summary>
public bool realtime { get { return m_Realtime; } set { m_Realtime = value; } }
public bool realtime
{
get { return m_Realtime; }
set { if (PropertyUtility.SetStruct(ref m_Realtime, value)) SetVerticesDirty(); }
}
/// <summary>
/// 图形的宽度,即颜色条的宽度。
/// </summary>
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
public float itemWidth
{
get { return m_ItemWidth; }
set { if (PropertyUtility.SetStruct(ref m_ItemWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 图形的高度,即颜色条的高度。
/// </summary>
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
public float itemHeight
{
get { return m_ItemHeight; }
set { if (PropertyUtility.SetStruct(ref m_ItemHeight, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框线宽单位px。
/// </summary>
public float borderWidth { get { return m_BorderWidth; } set { m_BorderWidth = value; } }
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 指定用数据的『哪个维度』,映射到视觉元素上。『数据』即 series.data。从1开始默认为0取 data 中最后一个维度。
/// </summary>
public int dimension { get { return m_Dimension; } set { m_Dimension = value; } }
public int dimension
{
get { return m_Dimension; }
set { if (PropertyUtility.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); }
}
/// <summary>
/// 打开 hoverLink 功能时,鼠标悬浮到 visualMap 组件上时,鼠标位置对应的数值 在 图表中对应的图形元素,会高亮。
/// 反之,鼠标悬浮到图表中的图形元素上时,在 visualMap 组件的相应位置会有三角提示其所对应的数值。
/// </summary>
/// <value></value>
public bool hoverLink { get { return m_HoverLink; } set { m_HoverLink = value; } }
public bool hoverLink
{
get { return m_HoverLink; }
set { if (PropertyUtility.SetStruct(ref m_HoverLink, value)) SetVerticesDirty(); }
}
/// <summary>
/// Specify whether the layout of component is horizontal or vertical.
/// 布局方式是横还是竖。
/// </summary>
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
public Orient orient
{
get { return m_Orient; }
set { if (PropertyUtility.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
}
/// <summary>
/// The location of component.
/// 组件显示的位置。
/// </summary>
public Location location { get { return m_Location; } set { m_Location = value; } }
public Location location
{
get { return m_Location; }
set { if (PropertyUtility.SetClass(ref m_Location, value)) SetVerticesDirty(); }
}
/// <summary>
/// 定义 在选中范围中 的视觉颜色。
/// </summary>
public List<Color> inRange { get { return m_InRange; } set { if (value != null) m_InRange = value; } }
public List<Color> inRange
{
get { return m_InRange; }
set { if (value != null) { m_InRange = value; SetVerticesDirty(); } }
}
/// <summary>
/// 定义 在选中范围外 的视觉颜色。
/// </summary>
public List<Color> outOfRange { get { return m_OutOfRange; } set { if (value != null) m_OutOfRange = value; } }
public List<Color> outOfRange
{
get { return m_OutOfRange; }
set { if (value != null) { m_OutOfRange = value; SetVerticesDirty(); } }
}
public override bool vertsDirty { get { return m_VertsDirty || location.anyDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
location.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
}
/// <summary>
/// 鼠标悬停选中的index

View File

@@ -22,7 +22,7 @@ namespace XCharts
/// </para>
/// </summary>
[Serializable]
public class Grid : MainComponent, IEquatable<Grid>
public class Grid : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Left;
@@ -35,32 +35,56 @@ namespace XCharts
/// Whether to show the grid in rectangular coordinate.
/// 是否显示直角坐标系网格。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Distance between grid component and the left side of the container.
/// grid 组件离容器左侧的距离。
/// </summary>
public float left { get { return m_Left; } set { m_Left = value; } }
public float left
{
get { return m_Left; }
set { if (PropertyUtility.SetStruct(ref m_Left, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between grid component and the right side of the container.
/// grid 组件离容器右侧的距离。
/// </summary>
public float right { get { return m_Right; } set { m_Right = value; } }
public float right
{
get { return m_Right; }
set { if (PropertyUtility.SetStruct(ref m_Right, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between grid component and the top side of the container.
/// grid 组件离容器上侧的距离。
/// </summary>
public float top { get { return m_Top; } set { m_Top = value; } }
public float top
{
get { return m_Top; }
set { if (PropertyUtility.SetStruct(ref m_Top, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between grid component and the bottom side of the container.
/// grid 组件离容器下侧的距离。
/// </summary>
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
}
/// <summary>
/// Background color of grid, which is transparent by default.
/// 网格背景色,默认透明。
/// </summary>
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
public static Grid defaultGrid
{
@@ -77,67 +101,5 @@ namespace XCharts
return coordinate;
}
}
public void Copy(Grid other)
{
m_Show = other.show;
m_Left = other.left;
m_Right = other.right;
m_Top = other.top;
m_Bottom = other.bottom;
m_BackgroundColor = other.backgroundColor;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Grid)
{
return Equals((Grid)obj);
}
else
{
return false;
}
}
public bool Equals(Grid other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return m_Show == other.show &&
m_Left == other.left &&
m_Right == other.right &&
m_Top == other.top &&
m_Bottom == other.bottom &&
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.backgroundColor);
}
public static bool operator ==(Grid left, Grid right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(Grid left, Grid right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

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

View File

@@ -52,41 +52,73 @@ namespace XCharts
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the origin of area.
/// 区域填充的起始位置。
/// </summary>
public AreaOrigin origin { get { return m_Origin; } set { m_Origin = value; } }
public AreaOrigin origin
{
get { return m_Origin; }
set { if (PropertyUtility.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 区域填充的颜色如果toColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
public Color toColor { get { return m_ToColor; } set { m_ToColor = value; } }
public Color toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
/// 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 鼠标悬浮时是否高亮之前的区域
/// </summary>
public bool tooltipHighlight { get { return m_TooltipHighlight; } set { m_TooltipHighlight = value; } }
public bool tooltipHighlight
{
get { return m_TooltipHighlight; }
set { if (PropertyUtility.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 高亮时区域填充的颜色如果highlightToColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color highlightColor { get { return m_HighlightColor; } set { m_HighlightColor = value; } }
public Color highlightColor
{
get { return m_HighlightColor; }
set { if (PropertyUtility.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start highlightColor to highlightToColor.
/// 高亮时渐变色的终点颜色。
/// </summary>
public Color highlightToColor { get { return m_HighlightToColor; } set { m_HighlightToColor = value; } }
public Color highlightToColor
{
get { return m_HighlightToColor; }
set { if (PropertyUtility.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); }
}
public static AreaStyle defaultAreaStyle
{

View File

@@ -7,6 +7,7 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
@@ -27,57 +28,112 @@ namespace XCharts
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
[SerializeField] private bool m_ForceENotation = false;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
/// <summary>
/// Set this to false to prevent the axis label from appearing.
/// 是否显示刻度标签。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// The display interval of the axis label.
/// 坐标轴刻度标签的显示间隔在类目轴中有效。0表示显示所有标签1表示隔一个隔显示一个标签以此类推。
/// </summary>
public int interval { get { return m_Interval; } set { m_Interval = value; } }
public int interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetComponentDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
/// 刻度标签是否朝内,默认朝外。
/// </summary>
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtility.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotation degree of axis label, which is especially useful when there is no enough space for category axis.
/// 刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。
/// </summary>
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// The margin between the axis label and the axis line.
/// 刻度标签与轴线之间的距离。
/// </summary>
public float margin { get { return m_Margin; } set { m_Margin = value; } }
public float margin
{
get { return m_Margin; }
set { if (PropertyUtility.SetStruct(ref m_Margin, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of axis label text.
/// 刻度标签文字的颜色默认取Theme的axisTextColor。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
/// 文字字体的风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {value}{value:f1} 表示取1为小数
/// 模板变量为图例名称 {value}支持{value:f0}{value:f1}{value:f2}
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
/// 是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
/// </summary>
public bool forceENotation { get { return m_ForceENotation; } set { m_ForceENotation = value; } }
public bool forceENotation
{
get { return m_ForceENotation; }
set { if (PropertyUtility.SetStruct(ref m_ForceENotation, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本限制。
/// </summary>
public TextLimit textLimit
{
get { return m_TextLimit; }
set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } }
}
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
textLimit.ClearComponentDirty();
}
public static AxisLabel defaultAxisLabel
{
@@ -96,60 +152,39 @@ namespace XCharts
};
}
}
public void Copy(AxisLabel other)
{
m_Show = other.show;
m_Interval = other.interval;
m_Inside = other.inside;
m_Rotate = other.rotate;
m_Margin = other.margin;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
m_Formatter = other.formatter;
}
public override bool Equals(object obj)
public void SetRelatedText(Text txt, float labelWidth)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisLabel)obj;
return m_Show == other.show &&
m_Interval.Equals(other.interval) &&
m_Inside == other.inside &&
m_Rotate == other.rotate &&
m_Margin == other.margin &&
m_Color == other.color &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle &&
m_ForceENotation == other.forceENotation &&
m_Formatter == other.formatter;
}
public override int GetHashCode()
{
return base.GetHashCode();
m_TextLimit.SetRelatedText(txt, labelWidth);
}
public string GetFormatterContent(string category)
{
if (string.IsNullOrEmpty(category)) return category;
if (string.IsNullOrEmpty(m_Formatter))
return category;
{
return m_TextLimit.GetLimitContent(category);
}
else
{
var content = m_Formatter.Replace("{value}", category);
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
return m_TextLimit.GetLimitContent(content);
}
}
public string GetFormatterContent(float value, float minValue, float maxValue)
public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false)
{
if (string.IsNullOrEmpty(m_Formatter))
{
if (isLog)
{
if (value - (int)value == 0)
return ChartCached.IntToStr((int)value);
else
return ChartCached.FloatToStr(value);
}
if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1)
{
int minAcc = ChartHelper.GetFloatAccuracy(minValue);
@@ -166,6 +201,8 @@ namespace XCharts
else if (m_Formatter.Contains("{value"))
{
var content = m_Formatter;
if (content.Contains("{value:f0}"))
content = m_Formatter.Replace("{value:f0}", ChartCached.IntToStr((int)value));
if (content.Contains("{value:f2}"))
content = m_Formatter.Replace("{value:f2}", ChartCached.FloatToStr(value, 2));
else if (content.Contains("{value:f1}"))
@@ -173,7 +210,6 @@ namespace XCharts
else if (content.Contains("{value}"))
{
if (value - (int)value == 0)
content = m_Formatter.Replace("{value}", ChartCached.IntToStr((int)value));
else
content = m_Formatter.Replace("{value}", ChartCached.FloatToStr(value, 1));

View File

@@ -13,7 +13,7 @@ namespace XCharts
/// Settings related to axis line.
/// 坐标轴的分隔线。
/// </summary>
[System.Serializable]
[System.Serializable]
public class AxisLine : SubComponent
{
[SerializeField] private bool m_Show;
@@ -29,42 +29,74 @@ namespace XCharts
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// When mutiple axes exists, this option can be used to specify which axis can be "onZero" to.
/// X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效。
/// </summary>
public bool onZero { get { return m_OnZero; } set { m_OnZero = value; } }
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// line style line width.
/// 坐标轴线线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the arrow symbol of axis.
/// 是否显示箭头。
/// </summary>
public bool symbol { get { return m_Symbol; } set { m_Symbol = value; } }
public bool symbol
{
get { return m_Symbol; }
set { if (PropertyUtility.SetStruct(ref m_Symbol, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of arrow symbol.
/// 箭头宽。
/// </summary>
public float symbolWidth { get { return m_SymbolWidth; } set { m_SymbolWidth = value; } }
public float symbolWidth
{
get { return m_SymbolWidth; }
set { if (PropertyUtility.SetStruct(ref m_SymbolWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the height of arrow symbol.
/// 箭头高。
/// </summary>
public float symbolHeight { get { return m_SymbolHeight; } set { m_SymbolHeight = value; } }
public float symbolHeight
{
get { return m_SymbolHeight; }
set { if (PropertyUtility.SetStruct(ref m_SymbolHeight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the offset of arrow symbol.
/// 箭头偏移。
/// </summary>
public float symbolOffset { get { return m_SymbolOffset; } set { m_SymbolOffset = value; } }
public float symbolOffset
{
get { return m_SymbolOffset; }
set { if (PropertyUtility.SetStruct(ref m_SymbolOffset, value)) SetVerticesDirty(); }
}
/// <summary>
/// the dent of arrow symbol.
/// 箭头的凹陷程度。
/// </summary>
public float symbolDent { get { return m_SymbolDent; } set { m_SymbolDent = value; } }
public float symbolDent
{
get { return m_SymbolDent; }
set { if (PropertyUtility.SetStruct(ref m_SymbolDent, value)) SetVerticesDirty(); }
}
public static AxisLine defaultAxisLine
{
@@ -78,7 +110,7 @@ namespace XCharts
m_Symbol = false,
m_SymbolWidth = 10,
m_SymbolHeight = 15,
m_SymbolOffset = 0,
m_SymbolOffset = -5f,
m_SymbolDent = 3,
};
return axisLine;

View File

@@ -40,42 +40,74 @@ namespace XCharts
/// Whether to show axis name.
/// 是否显示坐标名称。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the name of axis.
/// 坐标轴名称。
/// </summary>
public string name { get { return m_Name; } set { m_Name = value; } }
public string name
{
get { return m_Name; }
set { if (PropertyUtility.SetClass(ref m_Name, value)) SetComponentDirty(); }
}
/// <summary>
/// Location of axis name.
/// 坐标轴名称显示位置。
/// </summary>
public Location location { get { return m_Location; } set { m_Location = value; } }
public Location location
{
get { return m_Location; }
set { if (PropertyUtility.SetStruct(ref m_Location, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of axis name and axis line.
/// 坐标轴名称与轴线之间的偏移。
/// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotation of axis name.
/// 坐标轴名字旋转,角度值。
/// </summary>
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// Color of axis name.
/// 坐标轴名称的文字颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// axis name font size.
/// 坐标轴名称的文字大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// axis name font style.
/// 坐标轴名称的文字风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
public static AxisName defaultAxisName
{
@@ -93,39 +125,5 @@ namespace XCharts
};
}
}
public void Copy(AxisName other)
{
m_Show = other.show;
m_Name = other.name;
m_Location = other.location;
m_Offset = other.offset;
m_Rotate = other.rotate;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisName)obj;
return m_Show == other.show &&
m_Name.Equals(other.name) &&
m_Location == other.location &&
m_Rotate == other.rotate &&
m_Color == other.color &&
m_Offset == other.offset &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@@ -25,14 +25,22 @@ namespace XCharts
/// Set this to true to show the splitArea.
/// 是否显示分隔区域。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Color of split area. SplitArea color could also be set in color array,
/// which the split lines would take as their colors in turns.
/// Dark and light colors in turns are used by default.
/// 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
/// </summary>
public List<Color> color { get { return m_Color; } set { m_Color = value; } }
public List<Color> color
{
get { return m_Color; }
set { if (value != null) { m_Color = value; SetVerticesDirty(); } }
}
public static AxisSplitArea defaultSplitArea
{

View File

@@ -0,0 +1,85 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Split line of axis in grid area.
/// 坐标轴在 grid 区域中的分隔线。
/// </summary>
[Serializable]
public class AxisSplitLine : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private int m_Interval;
[SerializeField] private LineStyle m_LineStyle = new LineStyle(0.7f);
/// <summary>
/// Set this to true to show the split line.
/// 是否显示分隔线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
public int interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } }
}
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();
}
public static AxisSplitLine defaultSplitLine
{
get
{
return new AxisSplitLine()
{
m_Show = false,
};
}
}
internal Color GetColor(ThemeInfo theme)
{
if (lineStyle.color != Color.clear)
{
var color = lineStyle.color;
color.a *= lineStyle.opacity;
return color;
}
else
{
var color = (Color)theme.axisSplitLineColor;
color.a *= lineStyle.opacity;
return color;
}
}
internal bool NeedShow(int index)
{
return show && (interval == 0 || index % (interval + 1) == 0);
}
}
}

View File

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

View File

@@ -26,22 +26,38 @@ namespace XCharts
/// Set this to false to prevent the axis tick from showing.
/// 是否显示坐标轴刻度。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis.
/// 类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。
/// </summary>
public bool alignWithLabel { get { return m_AlignWithLabel; } set { m_AlignWithLabel = value; } }
public bool alignWithLabel
{
get { return m_AlignWithLabel; }
set { if (PropertyUtility.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
/// 坐标轴刻度是否朝内,默认朝外。
/// </summary>
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtility.SetStruct(ref m_Inside, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the axis tick.
/// 坐标轴刻度的长度。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
public float length
{
get { return m_Length; }
set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
public static AxisTick defaultTick
{

View File

@@ -22,14 +22,43 @@ namespace XCharts
/// <summary>
/// 是否启用高亮样式。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { m_Show = value; }
}
/// <summary>
/// 图形文本标签。
/// </summary>
public SerieLabel label { get { return m_Label; } }
public SerieLabel label
{
get { return m_Label; }
set { if (PropertyUtility.SetClass(ref m_Label, value, true)) SetAllDirty(); }
}
/// <summary>
/// 图形样式。
/// </summary>
public ItemStyle itemStyle { get { return m_ItemStyle; } }
public ItemStyle itemStyle
{
get { return m_ItemStyle; }
set { if (PropertyUtility.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || label.vertsDirty || itemStyle.vertsDirty; } }
public override bool componentDirty { get { return m_ComponentDirty || label.componentDirty; } }
internal override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
label.ClearVerticesDirty();
itemStyle.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
label.ClearComponentDirty();
}
}
}

View File

@@ -10,7 +10,6 @@ using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge axis line.
/// 仪表盘轴线相关设置。

View File

@@ -25,16 +25,28 @@ namespace XCharts
/// <summary>
/// 是否显示指针。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 指针长度。可以是绝对值也可以是相对于半径的百分比0-1的浮点数
/// </summary>
/// <value></value>
public float length { get { return m_Length; } set { m_Length = value; } }
public float length
{
get { return m_Length; }
set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <summary>
/// 指针宽度。
/// </summary>
/// <value></value>
public float width { get { return m_Width; } set { m_Width = value; } }
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
}
}

View File

@@ -36,6 +36,10 @@ namespace XCharts
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth;
[SerializeField] private Color m_CenterColor;
[SerializeField] private float m_CenterGap;
[SerializeField] private Type m_BorderType = Type.Solid;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color m_BorderColor;
@@ -44,26 +48,96 @@ namespace XCharts
/// <summary>
/// 是否启用。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景颜色。
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域颜色。
/// </summary>
public Color centerColor
{
get { return m_CenterColor; }
set { if (PropertyUtility.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域间隙。
/// </summary>
public float centerGap
{
get { return m_CenterGap; }
set { if (PropertyUtility.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景颜色。
/// </summary>
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的类型。
/// </summary>
public Type borderType { get { return m_BorderType; } set { m_BorderType = value; } }
public Type borderType
{
get { return m_BorderType; }
set { if (PropertyUtility.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
/// </summary>
public Color borderColor { get { return m_BorderColor; } set { m_BorderColor = value; } }
public Color borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtility.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框宽。
/// </summary>
public float borderWidth { get { return m_BorderWidth; } set { m_BorderWidth = value; } }
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 实际边框宽。边框不显示时为0。
/// </summary>
public float runtimeBorderWidth { get { return NeedShowBorder() ? borderWidth : 0; } }
/// <summary>
/// 是否需要显示边框。
/// </summary>
public bool NeedShowBorder()
{
return borderWidth != 0 && borderColor != Color.clear;
}
}
}

View File

@@ -37,31 +37,55 @@ namespace XCharts
/// Whether to show the arrow.
/// 是否显示箭头。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The position of arrow.
/// 箭头位置。
/// </summary>
public Position position { get { return m_Position; } set { m_Position = value; } }
public Position position
{
get { return m_Position; }
set { if (PropertyUtility.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// The widht of arrow.
/// 箭头宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of arrow.
/// 箭头高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
public float height
{
get { return m_Height; }
set { if (PropertyUtility.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// The offset of arrow.
/// 箭头偏移。
/// </summary>
public float offset { get { return m_Offset; } set { m_Offset = value; } }
public float offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// The dent of arrow.
/// 箭头的凹度。
/// </summary>
public float dent { get { return m_Dent; } set { m_Dent = value; } }
public float dent
{
get { return m_Dent; }
set { if (PropertyUtility.SetStruct(ref m_Dent, value)) SetVerticesDirty(); }
}
}
}

View File

@@ -52,28 +52,92 @@ namespace XCharts
/// <summary>
/// Whether show line.
/// 是否显示线条。在折线图中无效。
/// 是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of line.
/// 线的类型。
/// </summary>
public Type type { get { return m_Type; } set { m_Type = value; } }
public Type type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of line, default use serie color.
/// 线的颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of line.
/// 线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// /// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0.
/// 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
public LineStyle()
{
}
public LineStyle(float width)
{
this.width = width;
}
public LineStyle(LineStyle.Type type, float width)
{
this.type = type;
this.width = width;
}
public void Copy(LineStyle other)
{
m_Show = other.show;
m_Type = other.type;
m_Color = other.color;
m_Width = other.width;
m_Opacity = other.opacity;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (LineStyle)obj;
return m_Show == other.show &&
m_Type == other.type &&
m_Width == other.width &&
m_Opacity == other.opacity &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@@ -15,7 +15,7 @@ namespace XCharts
/// 位置类型。通过Align快速设置大体位置再通过leftrighttopbottom微调具体位置。
/// </summary>
[Serializable]
public class Location : SubComponent, IPropertyChanged, IEquatable<Location>
public class Location : SubComponent, IPropertyChanged
{
/// <summary>
/// 对齐方式
@@ -47,27 +47,47 @@ namespace XCharts
/// <summary>
/// 对齐方式。
/// </summary>
public Align align { get { return m_Align; } set { m_Align = value; UpdateAlign(); } }
public Align align
{
get { return m_Align; }
set { if (PropertyUtility.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器左侧的距离。
/// </summary>
public float left { get { return m_Left; } set { m_Left = value; UpdateAlign(); } }
public float left
{
get { return m_Left; }
set { if (PropertyUtility.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器右侧的距离。
/// </summary>
public float right { get { return m_Right; } set { m_Right = value; UpdateAlign(); } }
public float right
{
get { return m_Right; }
set { if (PropertyUtility.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器上侧的距离。
/// </summary>
public float top { get { return m_Top; } set { m_Top = value; UpdateAlign(); } }
public float top
{
get { return m_Top; }
set { if (PropertyUtility.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器下侧的距离。
/// </summary>
public float bottom { get { return m_Bottom; } set { m_Bottom = value; UpdateAlign(); } }
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// the anchor of text.
@@ -250,67 +270,6 @@ namespace XCharts
}
}
public void Copy(Location location)
{
m_Align = location.align;
m_Left = location.left;
m_Right = location.right;
m_Top = location.top;
m_Bottom = location.bottom;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Location)
{
return Equals((Location)obj);
}
else
{
return false;
}
}
public bool Equals(Location other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return align == other.align &&
left == other.left &&
right == other.right &&
top == other.top &&
bottom == other.bottom;
}
public static bool operator ==(Location left, Location right)
{
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
}
public static bool operator !=(Location left, Location right)
{
return !(left == right);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
/// </summary>

View File

@@ -1,4 +1,5 @@
/******************************************/
using System.Threading;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
@@ -23,11 +24,12 @@ namespace XCharts
}
[SerializeField] private bool m_Enable = true;
[SerializeField] private Easing m_Easting;
[SerializeField] private float m_Duration = 1000;
[SerializeField] private int m_Threshold = 2000;
[SerializeField] private float m_Delay = 0;
[SerializeField] private bool m_UpdateAnimation = true;
[SerializeField] private float m_UpdateDuration = 500;
[SerializeField] private float m_FadeInDuration = 1000;
[SerializeField] private float m_FadeInDelay = 0;
[SerializeField] private float m_FadeOutDuration = 1000f;
[SerializeField] private bool m_DataChangeEnable = true;
[SerializeField] private float m_DataChangeDuration = 500;
[SerializeField] private float m_ActualDuration;
/// <summary>
@@ -39,12 +41,17 @@ namespace XCharts
/// Easing method used for the first animation.
/// 动画的缓动效果。
/// </summary>
public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
//public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// 设定的动画时长(毫秒)。
/// The milliseconds duration of the fadeIn animation.
/// 设定的渐入动画时长(毫秒)。
/// </summary>
public float duration { get { return m_Duration; } set { m_Duration = value < 0 ? 0 : value; } }
public float fadeInDuration { get { return m_FadeInDuration; } set { m_FadeInDuration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds duration of the fadeOut animation.
/// 设定的渐出动画时长(毫秒)。
/// </summary>
public float fadeOutDuration { get { return m_FadeOutDuration; } set { m_FadeOutDuration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。
@@ -59,21 +66,24 @@ namespace XCharts
/// The milliseconds delay before updating the first animation.
/// 动画延时(毫秒)。
/// </summary>
public float delay { get { return m_Delay; } set { m_Delay = value < 0 ? 0 : value; } }
public float delay { get { return m_FadeInDelay; } set { m_FadeInDelay = value < 0 ? 0 : value; } }
/// <summary>
/// 是否开启数据变更动画。
/// </summary>
public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } }
public bool dataChangeEnable { get { return m_DataChangeEnable; } set { m_DataChangeEnable = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// The milliseconds duration of the data change animation.
/// 数据变更的动画时长(毫秒)。
/// </summary>
public float updateDuration { get { return m_UpdateDuration; } set { m_UpdateDuration = value < 0 ? 0 : value; } }
public float dataChangeDuration { get { return m_DataChangeDuration; } set { m_DataChangeDuration = value < 0 ? 0 : value; } }
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
private bool m_IsStart = false;
private bool m_FadeIn = false;
private bool m_IsEnd = true;
private bool m_Inited = false;
private bool m_IsPause = false;
private bool m_FadeOut = false;
private bool m_FadeOuted = false;
private bool m_IsInit = false;
private float startTime { get; set; }
private int m_CurrDataProgress { get; set; }
@@ -82,13 +92,21 @@ namespace XCharts
[SerializeField] private float m_DestDetailProgress;
private float m_CurrSymbolProgress;
public void Start()
public void FadeIn()
{
if (m_IsStart) return;
if (m_FadeOut) return;
if (m_IsPause)
{
m_IsPause = false;
return;
}
if (m_FadeIn) return;
startTime = Time.time;
m_IsStart = true;
m_FadeIn = true;
m_IsEnd = false;
m_Inited = false;
m_IsInit = false;
m_IsPause = false;
m_FadeOuted = false;
m_CurrDataProgress = 1;
m_DestDataProgress = 1;
m_CurrDetailProgress = 0;
@@ -97,34 +115,89 @@ namespace XCharts
m_DataAnimationState.Clear();
}
public void Stop()
public void Restart()
{
m_IsStart = false;
m_IsEnd = true;
m_Inited = false;
Reset();
FadeIn();
}
public void FadeOut()
{
if (m_IsPause)
{
m_IsPause = false;
return;
}
m_FadeOut = true;
startTime = Time.time;
m_FadeIn = true;
m_IsEnd = false;
m_IsInit = false;
m_IsPause = false;
m_CurrDataProgress = 0;
m_DestDataProgress = 0;
m_CurrDetailProgress = 0;
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_DataAnimationState.Clear();
}
public void End()
public void Pause()
{
if (!m_IsPause)
{
m_IsPause = true;
}
}
public void Resume()
{
if (m_IsPause)
{
m_IsPause = false;
}
}
private void End()
{
if (m_IsEnd) return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
m_CurrDataProgress = m_DestDataProgress + 1;
m_CurrDataProgress = m_DestDataProgress + (m_FadeOut ? -1 : 1);
m_FadeIn = false;
m_IsEnd = true;
m_IsInit = false;
if (m_FadeOut)
{
m_FadeOut = false;
m_FadeOuted = true;
}
}
public void Reset()
{
Stop();
Start();
m_FadeIn = false;
m_IsEnd = true;
m_IsInit = false;
m_IsPause = false;
m_FadeOut = false;
m_FadeOuted = false;
m_DataAnimationState.Clear();
}
public void InitProgress(int data, float curr, float dest)
{
if (!m_Inited && !m_IsEnd)
if (m_IsInit || m_IsEnd) return;
if (curr > dest) return;
m_IsInit = true;
m_DestDataProgress = data;
if (m_FadeOut)
{
m_CurrDetailProgress = dest;
m_DestDetailProgress = curr;
}
else
{
m_Inited = true;
m_DestDataProgress = data;
m_CurrDetailProgress = curr;
m_DestDetailProgress = dest;
}
@@ -132,23 +205,21 @@ namespace XCharts
public void SetDataFinish(int dataIndex)
{
if (!m_IsEnd)
{
m_CurrDataProgress = dataIndex + 1;
}
if (m_IsEnd) return;
m_CurrDataProgress = dataIndex + (m_FadeOut ? -1 : 1);
}
public void SetDataState(int index, float state)
private void SetDataState(int index, float state)
{
m_DataAnimationState[index] = state;
}
public float GetDataState(int index)
private float GetDataState(int index, float dest)
{
if (IsInDelay()) return 0;
if (IsInDelay()) return dest;
if (!m_DataAnimationState.ContainsKey(index))
{
m_DataAnimationState.Add(index, 0);
m_DataAnimationState.Add(index, dest);
}
return m_DataAnimationState[index];
}
@@ -166,7 +237,7 @@ namespace XCharts
return (delay > 0 && Time.time - startTime < delay / 1000);
}
public bool CheckDetailBreak(int dataIndex, float detail)
public bool CheckDetailBreak(float detail)
{
return !IsFinish() && detail > m_CurrDetailProgress;
}
@@ -182,29 +253,95 @@ namespace XCharts
{
if (!m_Enable || m_IsEnd) return true;
if (IsInDelay()) return false;
return dataIndex <= m_CurrDataProgress;
if (m_FadeOut) return dataIndex > 0;
else return dataIndex <= m_CurrDataProgress;
}
internal void CheckProgress(float delta)
internal void CheckProgress(float total)
{
if (!enable) return;
if (IsFinish()) return;
if (!m_IsInit || m_IsPause || m_IsEnd) return;
if (IsInDelay()) return;
if (m_IsEnd) return;
if (m_CurrDetailProgress > m_DestDetailProgress)
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
var duration = GetCurrAnimationDuration();
var delta = total / duration * Time.deltaTime;
if (m_FadeOut)
{
End();
m_CurrDetailProgress -= delta;
if (m_CurrDetailProgress <= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
}
else
{
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
m_CurrDetailProgress += delta;
if (m_CurrDetailProgress >= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
}
}
internal void CheckSymbol(float delta, float dest)
internal float GetCurrAnimationDuration()
{
m_CurrSymbolProgress += delta;
if (m_CurrSymbolProgress > dest) m_CurrSymbolProgress = dest;
if (m_FadeOut) return m_FadeOutDuration > 0 ? m_FadeOutDuration / 1000 : 1;
else return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1;
}
internal float CheckBarProgress(int dataIndex, float barHig)
{
//if (!m_IsInit) return barHig;
var destHig = m_FadeOut ? barHig : 0;
if (IsInDelay() || IsFinish() || m_IsEnd)
{
return m_FadeOuted ? 0 : barHig;
}
else if (m_IsPause)
{
return GetDataState(dataIndex, destHig);
}
else
{
var duration = GetCurrAnimationDuration();
var delta = barHig / duration * Time.deltaTime;
var currHig = GetDataState(dataIndex, destHig) + (m_FadeOut ? -delta : delta);
SetDataState(dataIndex, currHig);
if (m_FadeOut)
{
if (currHig <= 0)
{
End();
currHig = 0;
}
}
else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
{
End();
currHig = barHig;
}
return currHig;
}
}
internal void CheckSymbol(float dest)
{
if (!enable || m_IsEnd || m_IsPause || !m_IsInit) return;
if (IsInDelay()) return;
var duration = GetCurrAnimationDuration();
var delta = dest / duration * Time.deltaTime;
if (m_FadeOut)
{
m_CurrSymbolProgress -= delta;
if (m_CurrSymbolProgress < 0) m_CurrSymbolProgress = 0;
}
else
{
m_CurrSymbolProgress += delta;
if (m_CurrSymbolProgress > dest) m_CurrSymbolProgress = dest;
}
}
public float GetSysmbolSize(float dest)
@@ -212,7 +349,8 @@ namespace XCharts
#if UNITY_EDITOR
if (!Application.isPlaying) return dest;
#endif
if (!enable || m_IsEnd) return dest;
if (!enable) return dest;
if (m_IsEnd) return m_FadeOut ? 0 : dest;
return m_CurrSymbolProgress;
}
@@ -246,8 +384,13 @@ namespace XCharts
public float GetUpdateAnimationDuration()
{
if (m_Enable && m_UpdateAnimation && IsFinish()) return m_UpdateDuration;
if (m_Enable && m_DataChangeEnable && IsFinish()) return m_DataChangeDuration;
else return 0;
}
public bool HasFadeOut()
{
return enable && m_FadeOuted && m_IsEnd;
}
}
}

View File

@@ -153,10 +153,9 @@ 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_PreviousData = 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)
{
@@ -167,15 +166,27 @@ namespace XCharts
else return 0;
}
public float GetLastData(int index)
public float GetPreviousData(int index)
{
if (index >= 0 && index < lastData.Count)
if (index >= 0 && index < m_PreviousData.Count)
{
return m_LastData[index];
return m_PreviousData[index];
}
else return 0;
}
public float GetFirstData(float animationDuration = 500f)
{
if (m_Data.Count > 0) return GetCurrData(0, animationDuration);
return 0;
}
public float GetLastData()
{
if (m_Data.Count > 0) return m_Data[m_Data.Count - 1];
return 0;
}
public float GetCurrData(int index, float animationDuration = 500f)
{
if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0)
@@ -185,7 +196,7 @@ namespace XCharts
if (time <= total)
{
CheckLastData();
var curr = Mathf.Lerp(GetLastData(index), GetData(index), time / total);
var curr = Mathf.Lerp(GetPreviousData(index), GetData(index), time / total);
return curr;
}
else
@@ -205,7 +216,7 @@ namespace XCharts
if (dimension >= 0 && dimension < data.Count)
{
CheckLastData();
m_LastData[dimension] = data[dimension];
m_PreviousData[dimension] = data[dimension];
m_DataUpdateTime[dimension] = Time.time;
m_DataUpdateFlag[dimension] = true;
data[dimension] = value;
@@ -216,12 +227,14 @@ namespace XCharts
private void CheckLastData()
{
if (m_LastData.Count != m_Data.Count)
if (m_PreviousData.Count != m_Data.Count)
{
m_LastData.Clear();
m_PreviousData.Clear();
m_DataUpdateTime.Clear();
m_DataUpdateFlag.Clear();
for (int i = 0; i < m_Data.Count; i++)
{
m_LastData.Add(m_Data[i]);
m_PreviousData.Add(m_Data[i]);
m_DataUpdateTime.Add(Time.time);
m_DataUpdateFlag.Add(false);
}

View File

@@ -5,6 +5,7 @@
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
@@ -101,16 +102,26 @@ namespace XCharts
[SerializeField] private float m_BorderWidth = 0.5f;
[SerializeField] private Color m_BorderColor = Color.grey;
[SerializeField] private bool m_ForceENotation = false;
[NonSerialized] private bool m_LabelDirty = false;
/// <summary>
/// Whether the label is showed.
/// 是否显示文本标签。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The position of label.
/// 标签的位置。
/// </summary>
public Position position { get { return m_Position; } set { m_Position = value; } }
public Position position
{
get { return m_Position; }
set { if (PropertyUtility.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// 标签内容字符串模版格式器。支持用 \n 换行。
/// 模板变量有:
@@ -124,112 +135,200 @@ namespace XCharts
/// <example>
/// 示例:“{b}:{c}”
/// </example>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// offset to the host graphic element.
/// 距离图形元素的偏移
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
public Vector3 offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// 距离轴线的距离。
/// </summary>
public float margin { get { return m_Margin; } set { m_Margin = value; } }
public float margin
{
get { return m_Margin; }
set { if (PropertyUtility.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
}
/// <summary>
/// Text color,If set as default ,the color will assigned as series color.
/// 自定义文字颜色,默认和系列的颜色一致。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetStruct(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// the background color. If set as default, it means than don't show background.
/// 标签的背景色,默认无颜色。
/// </summary>
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of background. If set as default value 0, it means than the background width auto set as the text width.
/// 标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
/// </summary>
/// <value></value>
public float backgroundWidth { get { return m_BackgroundWidth; } set { m_BackgroundWidth = value; } }
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the height of background. If set as default value 0, it means than the background height auto set as the text height.
/// 标签的背景高度。一般不用指定,不指定时则自动是文字的高度。
/// </summary>
/// <value></value>
public float backgroundHeight { get { return m_BackgroundHeight; } set { m_BackgroundHeight = value; } }
public float backgroundHeight
{
get { return m_BackgroundHeight; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotate label.
/// 标签旋转。
/// </summary>
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of left and right. defaut:2.
/// 左右边距。
/// </summary>
public float paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
public float paddingLeftRight
{
get { return m_PaddingLeftRight; }
set { if (PropertyUtility.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of top and bottom. defaut:2.
/// 上下边距。
/// </summary>
public float paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } }
public float paddingTopBottom
{
get { return m_PaddingTopBottom; }
set { if (PropertyUtility.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetAllDirty(); }
}
/// <summary>
/// font style.
/// 文字的字体风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetAllDirty(); }
}
/// <summary>
/// Whether to show visual guide line.Will show when label position is set as 'outside'.
/// 是否显示视觉引导线。在 label 位置 设置为'outside'的时候会显示视觉引导线。
/// </summary>
public bool line { get { return m_Line; } set { m_Line = value; } }
public bool line
{
get { return m_Line; }
set { if (PropertyUtility.SetStruct(ref m_Line, value)) SetComponentDirty(); }
}
/// <summary>
/// the type of visual guide line.
/// 视觉引导线类型。
/// </summary>
public LineType lineType { get { return m_LineType; } set { m_LineType = value; } }
public LineType lineType
{
get { return m_LineType; }
set { if (PropertyUtility.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of visual guild line.
/// 视觉引导线颜色。默认和serie一致取自调色板。
/// </summary>
public Color lineColor { get { return m_LineColor; } set { m_LineColor = value; } }
public Color lineColor
{
get { return m_LineColor; }
set { if (PropertyUtility.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of visual guild line.
/// 视觉引导线的宽度。
/// </summary>
public float lineWidth { get { return m_LineWidth; } set { m_LineWidth = value; } }
public float lineWidth
{
get { return m_LineWidth; }
set { if (PropertyUtility.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the first segment of visual guide line.
/// 视觉引导线第一段的长度。
/// </summary>
public float lineLength1 { get { return m_LineLength1; } set { m_LineLength1 = value; } }
public float lineLength1
{
get { return m_LineLength1; }
set { if (PropertyUtility.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the second segment of visual guide line.
/// 视觉引导线第二段的长度。
/// </summary>
public float lineLength2 { get { return m_LineLength2; } set { m_LineLength2 = value; } }
public float lineLength2
{
get { return m_LineLength2; }
set { if (PropertyUtility.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show border.
/// 是否显示边框。
/// </summary>
public bool border { get { return m_Border; } set { m_Border = value; } }
public bool border
{
get { return m_Border; }
set { if (PropertyUtility.SetStruct(ref m_Border, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of border.
/// 边框宽度。
/// </summary>
public float borderWidth { get { return m_BorderWidth; } set { m_BorderWidth = value; } }
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of border.
/// 边框颜色。
/// </summary>
public Color borderColor { get { return m_BorderColor; } set { m_BorderColor = value; } }
public Color borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtility.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
/// </summary>
public bool forceENotation { get { return m_ForceENotation; } set { m_ForceENotation = value; } }
public bool forceENotation
{
get { return m_ForceENotation; }
set { if (PropertyUtility.SetStruct(ref m_ForceENotation, value)) SetVerticesDirty(); }
}
public string GetFormatterContent(string serieName, string dataName, float dataValue, float dataTotal = 0)
{

View File

@@ -92,77 +92,143 @@ namespace XCharts
[SerializeField] private int m_StartIndex;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
[SerializeField] private float m_Gap = 0;
/// <summary>
/// the type of symbol.
/// 标记类型。
/// </summary>
public SerieSymbolType type { get { return m_Type; } set { m_Type = value; } }
public SerieSymbolType type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of symbol size.
/// 标记图形的大小获取方式。
/// </summary>
public SerieSymbolSizeType sizeType { get { return m_SizeType; } set { m_SizeType = value; } }
public SerieSymbolSizeType sizeType
{
get { return m_SizeType; }
set { if (PropertyUtility.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of symbol.
/// 标记的大小。
/// </summary>
public float size { get { return m_Size; } set { m_Size = value; } }
public float size
{
get { return m_Size; }
set { if (PropertyUtility.SetStruct(ref m_Size, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of selected symbol.
/// 被选中的标记的大小。
/// </summary>
public float selectedSize { get { return m_SelectedSize; } set { m_SelectedSize = value; } }
public float selectedSize
{
get { return m_SelectedSize; }
set { if (PropertyUtility.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// whitch data index is when the sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的数据源索引。
/// </summary>
public int dataIndex { get { return m_DataIndex; } set { m_DataIndex = value; } }
public int dataIndex
{
get { return m_DataIndex; }
set { if (PropertyUtility.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of data when sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的倍数系数。
/// </summary>
public float dataScale { get { return m_DataScale; } set { m_DataScale = value; } }
public float dataScale
{
get { return m_DataScale; }
set { if (PropertyUtility.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of selected data when sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的高亮倍数系数。
/// </summary>
public float selectedDataScale { get { return m_SelectedDataScale; } set { m_SelectedDataScale = value; } }
public float selectedDataScale
{
get { return m_SelectedDataScale; }
set { if (PropertyUtility.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时指定的回调函数。
/// </summary>
public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } }
public SymbolSizeCallback sizeCallback
{
get { return m_SizeCallback; }
set { if (PropertyUtility.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时指定的高亮回调函数。
/// </summary>
public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } }
public SymbolSizeCallback selectedSizeCallback
{
get { return m_SelectedSizeCallback; }
set { if (PropertyUtility.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of symbol,default from serie.
/// 标记图形的颜色,默认和系列一致。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// the opacity of color.
/// 图形标记的透明度。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
/// 开始显示图形标记的索引。
/// </summary>
public int startIndex { get { return m_StartIndex; } set { m_StartIndex = value; } }
public int startIndex
{
get { return m_StartIndex; }
set { if (PropertyUtility.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the interval of show symbol.
/// 显示图形标记的间隔。0表示显示所有标签1表示隔一个隔显示一个标签以此类推。
/// </summary>
public int interval { get { return m_Interval; } set { m_Interval = value; } }
public int interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// whether to show the last symbol.
/// 是否强制显示最后一个图形标记。
/// </summary>
public bool forceShowLast { get { return m_ForceShowLast; } set { m_ForceShowLast = value; } }
public bool forceShowLast
{
get { return m_ForceShowLast; }
set { if (PropertyUtility.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); }
}
/// <summary>
/// the gap of symbol and line segment.
/// 图形标记和线条的间隙距离。
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
/// <summary>
/// the setting for effect scatter.

View File

@@ -0,0 +1,126 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// 文本字符限制和自适应。当文本长度超过设定的长度时进行裁剪,并将后缀附加在最后。
/// 只在类目轴中有效。
/// </summary>
[Serializable]
public class TextLimit : SubComponent
{
[SerializeField] private bool m_Enable = true;
[SerializeField] private float m_MaxWidth = 0;
[SerializeField] private float m_Gap = 1;
[SerializeField] private string m_Suffix = "...";
/// <summary>
/// 是否启用文本自适应。默认为true。
/// </summary>
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetComponentDirty(); }
}
/// <summary>
/// 设定最大宽度。默认为0表示自动获取否则表示自定义。当文本的宽度大于该值进行裁剪。
/// </summary>
public float maxWidth
{
get { return m_MaxWidth; }
set { if (PropertyUtility.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// 两边留白像素距离。默认为10
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetComponentDirty(); }
}
/// <summary>
/// 长度超出时的后缀。
/// </summary>
public string suffix
{
get { return m_Suffix; }
set { if (PropertyUtility.SetClass(ref m_Suffix, value)) SetComponentDirty(); }
}
private Text m_RelatedText;
private TextGenerationSettings m_RelatedTextSettings;
private float m_RelatedTextWidth = 0;
public void SetRelatedText(Text txt, float labelWidth)
{
m_RelatedText = txt;
m_RelatedTextSettings = txt.GetGenerationSettings(Vector2.zero);
m_RelatedTextWidth = labelWidth;
}
public string GetLimitContent(string content)
{
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
if (m_RelatedText == null || checkWidth <= 0) return content;
else
{
if (m_Enable)
{
float len = m_RelatedText.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings);
float suffixLen = m_RelatedText.cachedTextGenerator.GetPreferredWidth(suffix, m_RelatedTextSettings);
if (len >= checkWidth - m_Gap * 2)
{
return content.Substring(0, GetAdaptLength(content, suffixLen)) + suffix;
}
else
{
return content;
}
}
else
{
return content;
}
}
}
private int GetAdaptLength(string content, float suffixLen)
{
int start = 0;
int middle = content.Length / 2;
int end = content.Length;
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
float limit = checkWidth - m_Gap * 2 - suffixLen;
if (limit < 0) return 0;
float len = 0;
while (len != limit && middle != start)
{
len = m_RelatedText.cachedTextGenerator.GetPreferredWidth(content.Substring(0, middle), m_RelatedTextSettings);
if (len < limit)
{
start = middle;
}
else if (len > limit)
{
end = middle;
}
else
{
break;
}
middle = (start + end) / 2;
}
return middle;
}
}
}

View File

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

View File

@@ -1,4 +1,3 @@
using System.Threading;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
@@ -16,24 +15,39 @@ namespace XCharts
/// 文本的相关设置。
/// </summary>
[Serializable]
public class TextStyle : SubComponent, IEquatable<TextStyle>
public class TextStyle : SubComponent
{
[SerializeField] private Font m_Font;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private float m_LineSpacing = 1f;
[SerializeField] private float m_PaddingLeft = 0f;
[SerializeField] private float m_PaddingRight = 0f;
[SerializeField] private float m_PaddingTop = 0f;
[SerializeField] private float m_PaddingBottom = 0f;
/// <summary>
/// Rotation of text.
/// 文本的旋转。
/// </summary>
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of position.
/// 坐标偏移。
/// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
@@ -41,17 +55,56 @@ namespace XCharts
/// the color of text.
/// 文本的颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本的背景颜色。
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font of text.
/// 文本字体
/// </summary>
public Font font
{
get { return m_Font; }
set { if (PropertyUtility.SetClass(ref m_Font, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文本字体大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
/// 文本字体的风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// text line spacing.
/// 行间距。
/// </summary>
public float lineSpacing
{
get { return m_LineSpacing; }
set { if (PropertyUtility.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
}
public TextStyle()
{
@@ -82,59 +135,5 @@ namespace XCharts
this.color = color;
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();
textStyle.rotate = rotate;
textStyle.color = color;
textStyle.fontSize = fontSize;
textStyle.fontStyle = fontStyle;
textStyle.offset = offset;
return textStyle;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is TextStyle)
{
return Equals((TextStyle)obj);
}
else
{
return false;
}
}
public bool Equals(TextStyle other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return rotate == other.rotate &&
fontSize == other.fontSize &&
fontStyle == other.fontStyle &&
offset == other.offset &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@@ -9,6 +9,7 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
namespace XCharts
{
@@ -17,65 +18,42 @@ namespace XCharts
/// 标题相关设置。
/// </summary>
[Serializable]
public class TitleStyle : SubComponent, IEquatable<TitleStyle>
public class TitleStyle : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private TextStyle m_textStyle = new TextStyle(18);
[FormerlySerializedAs("m_textStyle")]
[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; } }
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本的颜色。
/// </summary>
public TextStyle textStyle { get { return m_textStyle; } set { m_textStyle = value; } }
/// <summary>
///
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtility.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
}
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
internal override void ClearComponentDirty()
{
base.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
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;
@@ -93,13 +71,13 @@ namespace XCharts
{
if (runtimeText)
{
runtimeText.transform.localPosition = pos + new Vector3(m_textStyle.offset.x, m_textStyle.offset.y);
runtimeText.transform.localPosition = pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y);
}
}
public void SetText(string text)
{
if (runtimeText)
if (runtimeText && !runtimeText.text.Equals(text))
{
if (textStyle.color != Color.clear) runtimeText.color = textStyle.color;
runtimeText.text = text;

View File

@@ -32,20 +32,25 @@ namespace XCharts
base.Start();
foreach (var serie in m_Series.list)
{
UpdateTitle(serie);
UpdateLabel(serie);
TitleStyleHelper.CheckTitle(serie, ref m_ReinitTitle, ref m_UpdateTitleText);
SerieLabelHelper.CheckLabel(serie, ref m_ReinitLabel, ref m_UpdateLabelText);
}
UpdateTitleAndLabelText();
UpdateAxisLabel();
}
protected override void Update()
{
base.Update();
if (m_UpdateLabelText || m_UpdateTitleText)
if (m_UpdateTitleText)
{
m_UpdateTitleText = false;
TitleStyleHelper.UpdateTitleText(m_Series);
}
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
UpdateTitleAndLabelText();
SerieLabelHelper.UpdateLabelText(m_Series,m_ThemeInfo);
UpdateAxisLabel();
}
}
@@ -64,7 +69,7 @@ namespace XCharts
serie.center[1] = 0.5f;
serie.radius[0] = 80;
serie.splitNumber = 5;
serie.animation.updateAnimation = true;
serie.animation.dataChangeEnable = true;
serie.titleStyle.show = true;
serie.titleStyle.textStyle.offset = new Vector2(0, 20);
serie.label.show = true;
@@ -85,7 +90,7 @@ namespace XCharts
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);
@@ -103,7 +108,7 @@ namespace XCharts
item.SetIconActive(false);
serie.gaugeAxis.AddLabelObject(item);
}
UpdateAxisLabel(serie);
UpdateAxisLabel(serie);
}
}
@@ -130,26 +135,23 @@ namespace XCharts
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);
DrawLineStyle(vh, serie);
DrawAxisTick(vh, serie);
DrawPointer(vh, serie, currAngle);
UpdateTitle(serie);
// UpdateAxisLabel(serie);
UpdateLabel(serie);
TitleStyleHelper.CheckTitle(serie, ref m_ReinitTitle, ref m_UpdateTitleText);
SerieLabelHelper.CheckLabel(serie, ref m_ReinitLabel, ref m_UpdateLabelText);
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);
serie.animation.CheckProgress(destAngle - serie.startAngle);
RefreshChart();
}
else if (NeedRefresh(serie))
@@ -167,17 +169,17 @@ namespace XCharts
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)
if (serie.roundCap)
{
DrawArcShape(vh, serie, serie.startAngle, backgroundColor, true);
DrawArcShape(vh, serie, serie.endAngle, backgroundColor);
DrawRoundCap(vh, serie, serie.startAngle, backgroundColor, true);
DrawRoundCap(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)
if (serie.roundCap && currAngle != serie.startAngle)
{
DrawArcShape(vh, serie, currAngle, color);
DrawArcShape(vh, serie, serie.startAngle, color, true);
DrawRoundCap(vh, serie, currAngle, color);
DrawRoundCap(vh, serie, serie.startAngle, color, true);
}
}
@@ -215,7 +217,7 @@ namespace XCharts
ChartDrawer.DrawPolygon(vh, p1, p3, p2, p4, pointerColor);
}
private void DrawSplitLine(VertexHelper vh, Serie serie)
private void DrawLineStyle(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return;
@@ -276,7 +278,7 @@ namespace XCharts
return false;
}
private void DrawArcShape(VertexHelper vh, Serie serie, float angle, Color color, bool invert = false)
private void DrawRoundCap(VertexHelper vh, Serie serie, float angle, Color color, bool invert = false)
{
var radius = serie.gaugeAxis.axisLine.width / 2;
var len = serie.runtimeInsideRadius + radius;
@@ -297,27 +299,6 @@ namespace XCharts
}
}
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;
@@ -348,56 +329,12 @@ namespace XCharts
}
}
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()
private void UpdateAxisLabel()
{
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);
}
}
@@ -405,6 +342,10 @@ namespace XCharts
private float GetCurrAngle(Serie serie, bool dest)
{
if (serie.animation.HasFadeOut())
{
return serie.animation.GetCurrDetail();
}
float rangeValue = serie.max - serie.min;
float rangeAngle = serie.endAngle - serie.startAngle;
float value = 0;
@@ -412,6 +353,7 @@ namespace XCharts
if (serie.dataCount > 0)
{
var serieData = serie.data[0];
serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset;
value = dest ? serieData.GetData(1) : serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
value = Mathf.Clamp(value, serie.min, serie.max);
}

View File

@@ -85,7 +85,7 @@ namespace XCharts
}
#endif
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
var xData = m_Tooltip.runtimeXValues[0];
var yData = m_Tooltip.runtimeYValues[0];

View File

@@ -0,0 +1,218 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class LegendHelper
{
public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active)
{
var textStyle = legend.textStyle;
if (active) return textStyle.color != Color.clear ? textStyle.color : (Color)themeInfo.legendTextColor;
else return (Color)themeInfo.legendUnableColor;
}
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, bool active)
{
if (active)
{
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
return (Color)themeInfo.GetColor(readIndex);
else
return Color.white;
}
else return (Color)themeInfo.legendUnableColor;
}
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
string content, Color itemColor, bool active)
{
var objName = i + "_" + legendName;
var anchorMin = new Vector2(0, 0.5f);
var anchorMax = new Vector2(0, 0.5f);
var pivot = new Vector2(0, 0.5f);
var sizeDelta = new Vector2(100, 30);
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
var textStyle = legend.textStyle;
var font = textStyle.font ? textStyle.font : themeInfo.font;
var contentColor = GetContentColor(legend, themeInfo, active);
var objAnchorMin = legend.location.runtimeAnchorMin;
var objAnchorMax = legend.location.runtimeAnchorMax;
var objPivot = legend.location.runtimePivot;
var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta);
var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
var img = ChartHelper.GetOrAddComponent<Image>(btnObj);
img.color = Color.clear;
ChartHelper.GetOrAddComponent<Button>(btnObj);
ChartHelper.GetOrAddComponent<Image>(iconObj);
ChartHelper.GetOrAddComponent<Image>(contentObj);
Text txt = ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor,
TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize,
textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
var item = new LegendItem();
item.index = i;
item.name = objName;
item.legendName = legendName;
item.SetObject(btnObj);
item.SetIconSize(legend.itemWidth, legend.itemHeight);
item.SetIconColor(itemColor);
item.SetIconImage(legend.GetIcon(i));
item.SetContentPosition(textStyle.offsetv3);
item.SetContent(content);
item.SetContentBackgroundColor(textStyle.backgroundColor);
return item;
}
public static void ResetItemPosition(Legend legend)
{
var startX = 0f;
var currWidth = 0f;
var currHeight = 0f;
switch (legend.orient)
{
case Orient.Vertical:
switch (legend.location.align)
{
case Location.Align.TopCenter:
startX = legend.runtimeWidth / 2;
currHeight = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2, -currHeight));
currHeight += item.height + legend.itemGap;
}
break;
case Location.Align.TopLeft:
currHeight = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(0, -currHeight));
currHeight += item.height + legend.itemGap;
}
break;
case Location.Align.TopRight:
currHeight = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, -currHeight));
currHeight += item.height + legend.itemGap;
}
break;
case Location.Align.Center:
startX = legend.runtimeWidth / 2;
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.CenterLeft:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(0, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.CenterRight:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.BottomCenter:
startX = legend.runtimeWidth / 2;
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.BottomLeft:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(0, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.BottomRight:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
}
break;
case Orient.Horizonal:
switch (legend.location.align)
{
case Location.Align.TopLeft:
case Location.Align.CenterLeft:
case Location.Align.BottomLeft:
currWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(currWidth, 0));
currWidth += item.width + legend.itemGap;
}
break;
case Location.Align.TopCenter:
case Location.Align.Center:
case Location.Align.BottomCenter:
startX = legend.runtimeWidth / 2;
currWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2 + currWidth, 0));
currWidth += item.width + legend.itemGap;
}
break;
case Location.Align.TopRight:
case Location.Align.CenterRight:
case Location.Align.BottomRight:
startX = -legend.runtimeWidth;
currWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(startX + currWidth + item.width, 0));
currWidth += item.width + legend.itemGap;
}
break;
}
break;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 928a0ea2a67c74bdcad4f252830a7592
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 UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class SerieHelper
{
internal static Color GetItemBackgroundColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
if (serie.itemStyle.backgroundColor != Color.clear)
{
var color = serie.itemStyle.backgroundColor;
if (highlight) color *= color;
color.a *= serie.itemStyle.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a = 0.2f;
return color;
}
}
internal static Color GetItemColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
if (serie.itemStyle.color != Color.clear)
{
var color = serie.itemStyle.color;
if (highlight) color *= color;
color.a *= serie.itemStyle.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= serie.itemStyle.opacity;
return color;
}
}
public static bool IsDownPoint(Serie serie, int index)
{
var dataPoints = serie.dataPoints;
if (dataPoints.Count < 2) return false;
else if (index > 0 && index < dataPoints.Count - 1)
{
var lp = dataPoints[index - 1];
var np = dataPoints[index + 1];
var cp = dataPoints[index];
var dot = Vector3.Cross(np - lp, cp - np);
return dot.z < 0;
}
else if (index == 0)
{
return dataPoints[0].y < dataPoints[1].y;
}
else if (index == dataPoints.Count - 1)
{
return dataPoints[index].y < dataPoints[index - 1].y;
}
else
{
return false;
}
}
}
}

View File

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

View File

@@ -0,0 +1,128 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class SerieLabelHelper
{
public static void CheckLabel(Serie serie, ref bool m_ReinitLabel, ref bool m_UpdateLabelText)
{
switch (serie.type)
{
case SerieType.Gauge:
case SerieType.Ring:
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
if (serie.label.show && serie.show)
{
if (serieData.IsInitLabel())
{
serieData.SetLabelActive(true);
m_UpdateLabelText = true;
}
else
{
m_ReinitLabel = true;
}
}
else
{
serieData.SetLabelActive(false);
}
}
break;
}
}
public static void UpdateLabelText(Series series, ThemeInfo themeInfo)
{
foreach (var serie in series.list)
{
if (!serie.label.show) continue;
switch (serie.type)
{
case SerieType.Gauge:
SetGaugeLabelText(serie);
break;
case SerieType.Ring:
SetRingLabelText(serie, themeInfo);
break;
}
}
}
public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
{
if (serie.label.color != Color.clear)
{
return serie.label.color;
}
else
{
return themeInfo.GetColor(index);
}
}
private static void SetGaugeLabelText(Serie serie)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
if (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);
serieData.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
if (serie.label.color != Color.clear)
{
serieData.SetLabelColor(serie.label.color);
}
}
}
}
private static void SetRingLabelText(Serie serie, ThemeInfo themeInfo)
{
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
if (serieData.IsInitLabel())
{
if (!serie.show || !serieData.show)
{
serieData.SetLabelActive(false);
continue;
}
var value = serieData.GetData(0);
var total = serieData.GetData(1);
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
serieData.SetLabelActive(true);
serieData.SetLabelText(content);
serieData.SetLabelColor(GetLabelColor(serie, themeInfo, i));
if (serie.label.position == SerieLabel.Position.Bottom)
{
var labelWidth = serieData.GetLabelWidth();
if (serie.clockwise)
serieData.SetLabelPosition(serieData.labelPosition - new Vector3(labelWidth / 2, 0));
else
serieData.SetLabelPosition(serieData.labelPosition + new Vector3(labelWidth / 2, 0));
}
else
{
serieData.SetLabelPosition(serieData.labelPosition);
}
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,43 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class TitleStyleHelper
{
public static void CheckTitle(Serie serie, ref bool m_ReinitTitle, ref bool m_UpdateTitleText)
{
if (serie.titleStyle.show)
{
if (serie.titleStyle.IsInited())
{
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
m_UpdateTitleText = true;
}
else
{
m_ReinitTitle = true;
}
}
}
public static void UpdateTitleText(Series series)
{
foreach (var serie in series.list) UpdateTitleText(serie);
}
public static void UpdateTitleText(Serie serie)
{
if (serie.titleStyle.show)
{
serie.titleStyle.SetText(serie.name);
}
}
}
}

View File

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

View File

@@ -0,0 +1,20 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
namespace XCharts
{
public class APIException : System.Exception
{
public APIException() { }
public APIException(string message) : base(message) { }
public APIException(string message, System.Exception inner) : base(message, inner) { }
protected APIException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}

View File

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

View File

@@ -30,7 +30,7 @@ namespace XCharts
Vertical
}
public partial class BaseChart : Graphic, IPointerDownHandler, IPointerUpHandler,
public partial class BaseChart : MaskableGraphic, IPointerDownHandler, IPointerUpHandler,
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
IDragHandler, IEndDragHandler, IScrollHandler
{
@@ -51,7 +51,6 @@ namespace XCharts
[SerializeField] protected Action<VertexHelper> m_CustomDrawCallback;
[NonSerialized] private Theme m_CheckTheme = 0;
[NonSerialized] private Title m_CheckTitle = Title.defaultTitle;
[NonSerialized] private Legend m_CheckLegend = Legend.defaultLegend;
[NonSerialized] private float m_CheckWidth = 0;
[NonSerialized] private float m_CheckHeight = 0;
@@ -59,19 +58,27 @@ namespace XCharts
[NonSerialized] private Vector2 m_CheckMaxAnchor;
[NonSerialized] private float m_CheckSerieCount = 0;
[NonSerialized] private List<string> m_CheckSerieName = new List<string>();
[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 bool m_IsPlayingAnimation = false;
[NonSerialized] protected List<string> m_LegendRealShowName = new List<string>();
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
protected virtual void InitComponent()
{
InitTitle();
InitLegend();
InitSerieLabel();
InitSerieTitle();
InitTooltip();
}
protected override void Awake()
{
if (m_ThemeInfo == null)
@@ -87,13 +94,9 @@ namespace XCharts
m_CheckWidth = m_ChartWidth;
m_CheckHeight = m_ChartHeight;
m_CheckTheme = m_ThemeInfo.theme;
InitTitle();
InitLegend();
InitSerieLabel();
InitSerieTitle();
InitTooltip();
m_Series.AnimationStop();
m_Series.AnimationStart();
InitComponent();
m_Series.AnimationReset();
m_Series.AnimationFadeIn();
}
protected override void Start()
@@ -104,9 +107,8 @@ namespace XCharts
protected virtual void Update()
{
CheckSize();
CheckTheme();
CheckTile();
CheckLegend();
CheckComponent();
CheckPointerPos();
CheckTooltip();
CheckRefreshChart();
@@ -114,6 +116,61 @@ namespace XCharts
CheckAnimation();
}
protected virtual void CheckComponent()
{
if (m_ThemeInfo.anyDirty)
{
if (m_CheckTheme != m_ThemeInfo.theme)
{
m_CheckTheme = m_ThemeInfo.theme;
m_ThemeInfo.Copy(m_CheckTheme);
OnThemeChanged();
}
if (m_ThemeInfo.componentDirty)
{
m_Title.SetAllDirty();
m_Legend.SetAllDirty();
m_Tooltip.SetAllDirty();
}
if (m_ThemeInfo.vertsDirty) RefreshChart();
m_ThemeInfo.ClearDirty();
}
if (m_Title.anyDirty)
{
if (m_Title.componentDirty) InitTitle();
if (m_Title.vertsDirty) RefreshChart();
m_Title.ClearDirty();
}
if (m_Legend.anyDirty)
{
if (m_Legend.componentDirty) InitLegend();
if (m_Legend.vertsDirty) RefreshChart();
m_Legend.ClearDirty();
}
if (m_Tooltip.anyDirty)
{
if (m_Tooltip.componentDirty) InitTooltip();
if (m_Tooltip.vertsDirty) RefreshChart();
m_Tooltip.ClearDirty();
}
if (m_Settings.vertsDirty)
{
RefreshChart();
m_Settings.ClearDirty();
}
if (m_Series.anyDirty)
{
if (m_Series.vertsDirty) RefreshChart();
if (m_Series.labelDirty) m_ReinitLabel = true;
if (m_Series.labelUpdate && !m_RefreshChart) m_RefreshLabel = true;
foreach (var serie in m_Series.list)
{
if (serie.titleStyle.componentDirty) m_ReinitTitle = true;
}
m_Series.ClearDirty();
}
}
protected override void OnEnable()
{
base.OnEnable();
@@ -142,6 +199,16 @@ namespace XCharts
m_Series = Series.defaultSeries;
Awake();
}
protected override void OnValidate()
{
m_ThemeInfo.SetAllDirty();
m_Title.SetAllDirty();
m_Legend.SetAllDirty();
m_Tooltip.SetAllDirty();
m_ReinitLabel = true;
m_ReinitTitle = true;
}
#endif
protected override void OnDestroy()
@@ -170,8 +237,8 @@ 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.textStyle.fontSize), m_Title.textStyle.fontSize, m_Title.textStyle.rotate,
m_Title.textStyle.fontStyle);
new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize,
m_Title.textStyle.rotate, m_Title.textStyle.fontStyle, m_Title.textStyle.lineSpacing);
titleText.alignment = anchor;
titleText.gameObject.SetActive(m_Title.show);
@@ -179,9 +246,9 @@ namespace XCharts
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,
m_ThemeInfo.font, m_ThemeInfo.titleSubTextColor, anchor, anchorMin, anchorMax, pivot,
new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize,
m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle);
m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle, m_Title.subTextStyle.lineSpacing);
subText.alignment = anchor;
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
@@ -230,21 +297,18 @@ namespace XCharts
string legendName = m_Legend.GetFormatterContent(datas[i]);
var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
var objName = s_LegendObjectName + "_" + i + "_" + datas[i];
Button btn = ChartHelper.AddButtonObject(objName, legendObject.transform,
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
var bgColor = IsActiveByLegend(datas[i]) ?
m_ThemeInfo.GetColor(readIndex) : m_ThemeInfo.legendUnableColor;
m_Legend.SetButton(legendName, btn, totalLegend);
m_Legend.UpdateButtonColor(legendName, bgColor);
btn.GetComponentInChildren<Text>().text = legendName;
ChartHelper.ClearEventListener(btn.gameObject);
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
var active = IsActiveByLegend(datas[i]);
var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, active);
var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo,
legendName, bgColor, active);
m_Legend.SetButton(legendName, item, totalLegend);
ChartHelper.ClearEventListener(item.button.gameObject);
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
{
if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return;
var temp = data.selectedObject.name.Split('_');
string selectedName = temp[2];
int clickedIndex = int.Parse(temp[1]);
string selectedName = temp[1];
int clickedIndex = int.Parse(temp[0]);
if (m_Legend.selectedMode == Legend.SelectedMode.Multiple)
{
OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
@@ -261,27 +325,27 @@ namespace XCharts
for (int n = 0; n < btnList.Length; n++)
{
temp = btnList[n].name.Split('_');
selectedName = temp[2];
var index = int.Parse(temp[1]);
selectedName = btnList[n].legendName;
var index = btnList[n].index;
OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false);
}
}
}
});
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) =>
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) =>
{
if (btn == null) return;
var temp = btn.name.Split('_');
string selectedName = temp[2];
int index = int.Parse(temp[1]);
if (item.button == null) return;
var temp = item.button.name.Split('_');
string selectedName = temp[1];
int index = int.Parse(temp[0]);
OnLegendButtonEnter(index, selectedName);
});
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) =>
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) =>
{
if (btn == null) return;
var temp = btn.name.Split('_');
string selectedName = temp[2];
int index = int.Parse(temp[1]);
if (item.button == null) return;
var temp = item.button.name.Split('_');
string selectedName = temp[1];
int index = int.Parse(temp[0]);
OnLegendButtonExit(index, selectedName);
});
}
@@ -292,6 +356,7 @@ namespace XCharts
OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false);
}
}
LegendHelper.ResetItemPosition(m_Legend);
}
private void InitSerieLabel()
@@ -328,10 +393,10 @@ namespace XCharts
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
serieData.InitLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
serieData.SetLabelActive(false);
//serieData.SetLabelText(serieData.name);
count++;
}
}
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
}
private void InitSerieTitle()
@@ -349,13 +414,15 @@ namespace XCharts
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);
var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color,
TextAnchor.MiddleCenter, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate,
textStyle.fontStyle, textStyle.lineSpacing);
txt.text = "";
txt.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector2.zero;
ChartHelper.SetActive(txt, false);
ChartHelper.SetActive(txt, serie.titleStyle.show);
serie.titleStyle.runtimeText = txt;
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
@@ -364,7 +431,6 @@ namespace XCharts
}
}
private void InitTooltip()
{
var tooltipObject = ChartHelper.AddObject("tooltip", transform, chartAnchorMin,
@@ -372,9 +438,10 @@ namespace XCharts
tooltipObject.transform.localPosition = Vector3.zero;
DestroyImmediate(tooltipObject.GetComponent<Image>());
var parent = tooltipObject.transform;
var textStyle = m_Tooltip.textStyle;
ChartHelper.HideAllObject(tooltipObject.transform);
GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font,
m_Tooltip.fontSize, m_Tooltip.fontStyle);
textStyle.fontSize, textStyle.fontStyle, textStyle.lineSpacing);
m_Tooltip.SetObj(tooltipObject);
m_Tooltip.SetContentObj(content);
m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
@@ -407,46 +474,17 @@ namespace XCharts
}
}
private void CheckTheme()
{
if (m_CheckTheme != m_ThemeInfo.theme)
{
m_CheckTheme = m_ThemeInfo.theme;
OnThemeChanged();
}
}
private void CheckTile()
{
if (!m_CheckTitle.Equals(m_Title))
{
m_CheckTitle.Copy(m_Title);
OnTitleChanged();
}
}
private void CheckLegend()
{
if (m_CheckLegend != m_Legend)
if (m_Legend.show)
{
m_CheckLegend.Copy(m_Legend);
OnLegendChanged();
}
else if (m_Legend.show)
{
if (m_CheckSerieCount != m_Series.Count)
foreach (var serie in series.list)
{
m_CheckSerieCount = m_Series.Count;
m_CheckSerieName.Clear();
var serieNames = m_Series.GetSerieNameList();
foreach (var name in serieNames) m_CheckSerieName.Add(name);
OnLegendChanged();
}
else if (!ChartHelper.IsValueEqualsList(m_CheckSerieName, m_Series.GetSerieNameList()))
{
var serieNames = m_Series.GetSerieNameList();
foreach (var name in serieNames) m_CheckSerieName.Add(name);
OnLegendChanged();
if (serie.nameDirty)
{
m_Legend.SetAllDirty();
serie.ClearNameDirty();
}
}
}
}
@@ -520,25 +558,17 @@ namespace XCharts
protected void CheckRefreshChart()
{
if (m_RefreshChart)
if (m_RefreshChart || m_Series.vertsDirty)
{
int tempWid = (int)chartWidth;
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid);
//SetAllDirty();
SetVerticesDirty();
m_RefreshChart = false;
m_Series.ClearVerticesDirty();
}
}
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;
@@ -562,50 +592,24 @@ namespace XCharts
if (!m_CheckAnimation)
{
m_CheckAnimation = true;
m_Series.AnimationStart();
m_Series.AnimationFadeIn();
}
}
protected virtual void OnRefreshLabel()
{
}
protected virtual void OnSizeChanged()
{
InitTitle();
InitLegend();
InitTooltip();
InitSerieLabel();
m_Title.SetAllDirty();
m_Legend.SetAllDirty();
m_Tooltip.SetAllDirty();
m_Series.SetLabelDirty();
}
protected virtual void OnThemeChanged()
{
switch (m_ThemeInfo.theme)
{
case Theme.Dark:
m_ThemeInfo.Copy(ThemeInfo.Dark);
break;
case Theme.Default:
m_ThemeInfo.Copy(ThemeInfo.Default);
break;
case Theme.Light:
m_ThemeInfo.Copy(ThemeInfo.Light);
break;
}
InitTitle();
InitLegend();
InitTooltip();
}
protected virtual void OnTitleChanged()
{
InitTitle();
}
protected virtual void OnLegendChanged()
{
InitLegend();
}
protected virtual void OnYMaxValueChanged()
@@ -687,7 +691,7 @@ namespace XCharts
return show;
}
protected virtual void RefreshTooltip()
protected virtual void UpdateTooltip()
{
}
@@ -712,9 +716,8 @@ namespace XCharts
{
}
private void DrawBackground(VertexHelper vh)
protected virtual void DrawBackground(VertexHelper vh)
{
// draw bg
Vector3 p1 = new Vector3(0, chartHeight);
Vector3 p2 = new Vector3(chartWidth, chartHeight);
Vector3 p3 = new Vector3(chartWidth, 0);
@@ -723,35 +726,92 @@ namespace XCharts
}
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color)
float tickness, Vector3 pos, Color color, float gap)
{
var backgroundColor = m_ThemeInfo.backgroundColor;
var smoothness = m_Settings.cicleSmoothness;
switch (type)
{
case SerieSymbolType.None:
break;
case SerieSymbolType.Circle:
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, m_Settings.cicleSmoothness);
if (gap > 0)
{
ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, smoothness);
}
else
{
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, smoothness);
}
break;
case SerieSymbolType.EmptyCircle:
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness);
if (gap > 0)
{
ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, backgroundColor, smoothness);
}
else
{
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, backgroundColor, smoothness);
}
break;
case SerieSymbolType.Rect:
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
if (gap > 0)
{
ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor);
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
}
else
{
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
}
break;
case SerieSymbolType.Triangle:
var x = symbolSize * Mathf.Cos(30 * Mathf.PI / 180);
var y = symbolSize * Mathf.Sin(30 * Mathf.PI / 180);
var p1 = new Vector2(pos.x - x, pos.y - y);
var p2 = new Vector2(pos.x, pos.y + symbolSize);
var p3 = new Vector2(pos.x + x, pos.y - y);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
if (gap > 0)
{
ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color);
}
else
{
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color);
}
break;
case SerieSymbolType.Diamond:
p1 = new Vector2(pos.x - symbolSize, pos.y);
p2 = new Vector2(pos.x, pos.y + symbolSize);
p3 = new Vector2(pos.x + symbolSize, pos.y);
var p4 = new Vector2(pos.x, pos.y - symbolSize);
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color);
if (gap > 0)
{
ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color);
}
else
{
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color);
}
break;
}
}
protected void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
Vector3 startPos, Vector3 endPos, Color color)
{
var type = lineStyle.type;
var width = lineStyle.width;
switch (type)
{
case LineStyle.Type.Dashed:
ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.Dotted:
ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.Solid:
ChartDrawer.DrawLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.DashDot:
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.DashDotDot:
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color);
break;
}
}
@@ -779,30 +839,8 @@ namespace XCharts
if (serieLabel.border)
{
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);
p4 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y - labelHalfHig - 2 * borderWid);
var p5 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig - borderWid);
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 (serieLabel.rotate > 0)
{
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, 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);
ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
}
}

View File

@@ -31,13 +31,10 @@ namespace XCharts
private bool m_DataZoomEndDrag;
private float m_DataZoomLastStartIndex;
private float m_DataZoomLastEndIndex;
private bool m_XAxisChanged;
private bool m_YAxisChanged;
private bool m_CheckMinMaxValue;
private bool m_CheckDataZoomLabel;
private List<XAxis> m_CheckXAxises = new List<XAxis>();
private List<YAxis> m_CheckYAxises = new List<YAxis>();
private Grid m_CheckCoordinate = Grid.defaultGrid;
private bool m_XAxisesDirty;
private bool m_YAxisesDirty;
private Dictionary<int, List<Serie>> m_StackSeries = new Dictionary<int, List<Serie>>();
private List<float> m_SeriesCurrHig = new List<float>();
@@ -55,14 +52,61 @@ namespace XCharts
protected override void Update()
{
base.Update();
CheckYAxis();
CheckXAxis();
CheckMinMaxValue();
CheckCoordinate();
CheckRaycastTarget();
CheckDataZoom();
CheckVisualMap();
base.Update();
}
protected override void CheckComponent()
{
if (m_DataZoom.anyDirty)
{
if (m_DataZoom.componentDirty) InitDataZoom();
if (m_DataZoom.vertsDirty) RefreshChart();
m_DataZoom.ClearDirty();
}
if (m_VisualMap.anyDirty)
{
if (m_VisualMap.vertsDirty) RefreshChart();
m_VisualMap.ClearDirty();
}
if (m_Grid.anyDirty)
{
if (m_Grid.componentDirty)
{
m_XAxisesDirty = true;
m_YAxisesDirty = true;
OnCoordinateChanged();
}
if (m_Grid.vertsDirty) RefreshChart();
m_Grid.ClearDirty();
}
for (int i = 0; i < m_XAxises.Count; i++)
{
var axis = m_XAxises[i];
if (m_XAxisesDirty || axis.anyDirty)
{
if (axis.componentDirty || m_XAxisesDirty) InitXAxis(i, axis);
if (axis.vertsDirty || m_XAxisesDirty) RefreshChart();
axis.ClearDirty();
m_XAxisesDirty = false;
}
}
for (int i = 0; i < m_YAxises.Count; i++)
{
var axis = m_YAxises[i];
if (m_YAxisesDirty || axis.anyDirty)
{
if (axis.componentDirty || m_YAxisesDirty) InitYAxis(i, axis);
if (axis.vertsDirty || m_YAxisesDirty) RefreshChart();
axis.ClearDirty();
m_YAxisesDirty = false;
}
}
base.CheckComponent();
}
#if UNITY_EDITOR
@@ -74,6 +118,16 @@ namespace XCharts
m_YAxises.Clear();
Awake();
}
protected override void OnValidate()
{
base.OnValidate();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
m_Grid.SetAllDirty();
m_DataZoom.SetAllDirty();
m_VisualMap.SetAllDirty();
}
#endif
protected override void DrawChart(VertexHelper vh)
@@ -81,16 +135,67 @@ namespace XCharts
base.DrawChart(vh);
DrawCoordinate(vh);
DrawSerie(vh);
DrawAxisTick(vh);
DrawDataZoomSlider(vh);
DrawVisualMap(vh);
}
protected override void DrawBackground(VertexHelper vh)
{
if (m_Series.IsAnyClipSerie())
{
var xLineDiff = xAxis0.axisLine.width;
var yLineDiff = yAxis0.axisLine.width;
var xSplitDiff = xAxis0.splitLine.lineStyle.width;
var ySplitDiff = yAxis0.splitLine.lineStyle.width;
var cpty = coordinateY + coordinateHeight + ySplitDiff;
var cp1 = new Vector3(coordinateX - yLineDiff, coordinateY - xLineDiff);
var cp2 = new Vector3(coordinateX - yLineDiff, cpty);
var cp3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, cpty);
var cp4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY - xLineDiff);
ChartDrawer.DrawPolygon(vh, cp1, cp2, cp3, cp4, m_ThemeInfo.backgroundColor);
}
else
{
base.DrawBackground(vh);
}
}
protected void DrawClip(VertexHelper vh)
{
if (!m_Series.IsAnyClipSerie()) return;
var xLineDiff = xAxis0.axisLine.width;
var yLineDiff = yAxis0.axisLine.width;
var xSplitDiff = xAxis0.splitLine.lineStyle.width;
var ySplitDiff = yAxis0.splitLine.lineStyle.width;
var lp1 = new Vector3(0, 0);
var lp2 = new Vector3(0, chartHeight);
var lp3 = new Vector3(coordinateX - yLineDiff, chartHeight);
var lp4 = new Vector3(coordinateX - yLineDiff, 0);
ChartDrawer.DrawPolygon(vh, lp1, lp2, lp3, lp4, m_ThemeInfo.backgroundColor);
var rp1 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, 0);
var rp2 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, chartHeight);
var rp3 = new Vector3(chartWidth, chartHeight);
var rp4 = new Vector3(chartWidth, 0);
ChartDrawer.DrawPolygon(vh, rp1, rp2, rp3, rp4, m_ThemeInfo.backgroundColor);
var up1 = new Vector3(coordinateX - yLineDiff, coordinateY + coordinateHeight + ySplitDiff);
var up2 = new Vector3(coordinateX - yLineDiff, chartHeight);
var up3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, chartHeight);
var up4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY + coordinateHeight + ySplitDiff);
ChartDrawer.DrawPolygon(vh, up1, up2, up3, up4, m_ThemeInfo.backgroundColor);
var dp1 = new Vector3(coordinateX - yLineDiff, 0);
var dp2 = new Vector3(coordinateX - yLineDiff, coordinateY - xLineDiff);
var dp3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY - xLineDiff);
var dp4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, 0);
ChartDrawer.DrawPolygon(vh, dp1, dp2, dp3, dp4, m_ThemeInfo.backgroundColor);
}
protected virtual void DrawSerie(VertexHelper vh)
{
base.DrawChart(vh);
if (!m_CheckMinMaxValue) return;
m_IsPlayingStartAnimation = false;
m_IsPlayingAnimation = false;
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
m_Series.GetStackSeries(ref m_StackSeries);
int seriesCount = m_StackSeries.Count;
@@ -130,6 +235,7 @@ namespace XCharts
}
}
}
DrawClip(vh);
DrawLabelBackground(vh);
DrawLinePoint(vh);
DrawLineArrow(vh);
@@ -142,7 +248,7 @@ namespace XCharts
if (!IsInCooridate(local))
{
m_Tooltip.ClearValue();
RefreshTooltip();
UpdateTooltip();
}
else
{
@@ -254,7 +360,7 @@ namespace XCharts
if (m_Tooltip.IsSelected())
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
UpdateTooltip();
if (m_Tooltip.IsDataIndexChanged() || m_Tooltip.type == Tooltip.Type.Corss)
{
m_Tooltip.UpdateLastDataIndex();
@@ -269,9 +375,9 @@ namespace XCharts
}
protected StringBuilder sb = new StringBuilder(100);
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
base.RefreshTooltip();
base.UpdateTooltip();
int index;
Axis tempAxis;
bool isCartesian = IsValue();
@@ -300,12 +406,18 @@ namespace XCharts
return;
}
if (string.IsNullOrEmpty(tooltip.formatter))
if (tooltip.IsNoFormatter())
{
sb.Length = 0;
if (!isCartesian)
{
sb.Append(tempAxis.GetData(index, m_DataZoom));
var category = tempAxis.GetData(index, m_DataZoom);
if (!string.IsNullOrEmpty(category)) sb.Append(category);
else
{
m_Tooltip.SetActive(false);
return;
}
}
for (int i = 0; i < m_Series.Count; i++)
{
@@ -315,6 +427,7 @@ namespace XCharts
string key = serie.name;
float xValue, yValue;
serie.GetXYData(index, m_DataZoom, out xValue, out yValue);
var isIngore = serie.IsIngorePoint(index);
if (isCartesian)
{
var serieData = serie.GetSerieData(index, m_DataZoom);
@@ -327,10 +440,12 @@ namespace XCharts
}
else
{
var valueTxt = isIngore ? m_Tooltip.ignoreDataDefaultContent :
ChartCached.FloatToStr(yValue, 0, m_Tooltip.forceENotation);
sb.Append("\n")
.Append("<color=#").Append(m_ThemeInfo.GetColorStr(i)).Append(">● </color>")
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
.Append(ChartCached.FloatToStr(yValue, 0, m_Tooltip.forceENotation));
.Append(valueTxt);
}
}
}
@@ -339,7 +454,7 @@ namespace XCharts
else
{
var category = tempAxis.GetData(index, m_DataZoom);
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, category, m_DataZoom));
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, category, m_ThemeInfo, m_DataZoom));
}
var pos = m_Tooltip.GetContentPos();
if (pos.x + m_Tooltip.runtimeWidth > chartWidth)
@@ -413,9 +528,9 @@ namespace XCharts
protected override void OnThemeChanged()
{
base.OnThemeChanged();
InitDataZoom();
InitAxisX();
InitAxisY();
m_DataZoom.SetAllDirty();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
}
private void InitDefaultAxises()
@@ -487,8 +602,9 @@ namespace XCharts
Vector2.zero, new Vector2(1, 0.5f), new Vector2(m_Grid.left, 20),
yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle);
}
float labelWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
float labelWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth);
txt.transform.localPosition = GetLabelYPosition(totalWidth + (yAxis.boundaryGap ? labelWidth / 2 : 0), i, yAxisIndex, yAxis);
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
@@ -582,12 +698,13 @@ namespace XCharts
m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0, 1),
new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(labelWidth, 20),
xAxis.axisLabel.fontSize, xAxis.axisLabel.rotate, xAxis.axisLabel.fontStyle);
if (i == 0) xAxis.axisLabel.SetRelatedText(txt, labelWidth);
txt.transform.localPosition = GetLabelXPosition(totalWidth + (xAxis.boundaryGap ? labelWidth : labelWidth / 2),
i, xAxisIndex, xAxis);
totalWidth += labelWidth;
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
txt.text = xAxis.GetLabelName(coordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom, isPercentStack);
txt.text = xAxis.GetLabelName(coordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom,
isPercentStack);
txt.gameObject.SetActive(xAxis.show &&
(xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0));
xAxis.axisLabelTextList.Add(txt);
@@ -699,56 +816,9 @@ namespace XCharts
{
posY = startY - xAxis.axisLabel.margin - xAxis.axisLabel.fontSize / 2;
}
// if (xAxis.boundaryGap)
// {
// return new Vector3(coordinateX + (i + 1) * scaleWid, posY);
// }
// else
// {
// return new Vector3(coordinateX + (i + 1 - 0.5f) * scaleWid, posY);
// }
return new Vector3(coordinateX + scaleWid, posY);
}
private void CheckCoordinate()
{
if (m_CheckCoordinate != m_Grid)
{
m_CheckCoordinate.Copy(m_Grid);
OnCoordinateChanged();
}
}
private void CheckYAxis()
{
if (m_YAxisChanged || !ChartHelper.IsValueEqualsList<YAxis>(m_CheckYAxises, m_YAxises))
{
foreach (var axis in m_CheckYAxises)
{
YAxisPool.Release(axis);
}
m_CheckYAxises.Clear();
foreach (var axis in m_YAxises) m_CheckYAxises.Add(axis.Clone());
m_YAxisChanged = false;
OnYAxisChanged();
}
}
private void CheckXAxis()
{
if (m_XAxisChanged || !ChartHelper.IsValueEqualsList<XAxis>(m_CheckXAxises, m_XAxises))
{
foreach (var axis in m_CheckXAxises)
{
XAxisPool.Release(axis);
}
m_CheckXAxises.Clear();
foreach (var axis in m_XAxises) m_CheckXAxises.Add(axis.Clone());
m_XAxisChanged = false;
OnXAxisChanged();
}
}
private void CheckMinMaxValue()
{
if (m_XAxises == null || m_YAxises == null) return;
@@ -792,8 +862,8 @@ namespace XCharts
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
{
m_CheckMinMaxValue = true;
axis.runtimeMinValue = tempMinValue;
axis.runtimeMaxValue = tempMaxValue;
axis.UpdateMinValue(tempMinValue, !m_IsPlayingAnimation);
axis.UpdateMaxValue(tempMaxValue, !m_IsPlayingAnimation);
axis.runtimeZeroXOffset = 0;
axis.runtimeZeroYOffset = 0;
if (tempMinValue != 0 || tempMaxValue != 0)
@@ -819,7 +889,7 @@ namespace XCharts
RefreshChart();
}
}
if (axis.IsValueChanging(500) && !m_IsPlayingStartAnimation)
if (axis.IsValueChanging(500) && !m_IsPlayingAnimation)
{
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
@@ -830,25 +900,15 @@ namespace XCharts
protected virtual void OnCoordinateChanged()
{
InitAxisX();
InitAxisY();
}
protected virtual void OnYAxisChanged()
{
InitAxisY();
}
protected virtual void OnXAxisChanged()
{
InitAxisX();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
}
protected override void OnSizeChanged()
{
base.OnSizeChanged();
InitAxisX();
InitAxisY();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
}
private void DrawCoordinate(VertexHelper vh)
@@ -856,11 +916,11 @@ namespace XCharts
DrawGrid(vh);
for (int i = 0; i < m_XAxises.Count; i++)
{
DrawXAxisTickAndSplit(vh, i, m_XAxises[i]);
DrawXAxisSplit(vh, i, m_XAxises[i]);
}
for (int i = 0; i < m_YAxises.Count; i++)
{
DrawYAxisTickAndSplit(vh, i, m_YAxises[i]);
DrawYAxisSplit(vh, i, m_YAxises[i]);
}
for (int i = 0; i < m_XAxises.Count; i++)
{
@@ -872,6 +932,18 @@ namespace XCharts
}
}
private void DrawAxisTick(VertexHelper vh)
{
for (int i = 0; i < m_XAxises.Count; i++)
{
DrawXAxisTick(vh, i, m_XAxises[i]);
}
for (int i = 0; i < m_YAxises.Count; i++)
{
DrawYAxisTick(vh, i, m_YAxises[i]);
}
}
private void DrawGrid(VertexHelper vh)
{
if (m_Grid.show && m_Grid.backgroundColor != Color.clear)
@@ -884,7 +956,7 @@ namespace XCharts
}
}
private void DrawYAxisTickAndSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis)
private void DrawYAxisSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis)
{
if (yAxis.NeedShowSplit())
{
@@ -895,7 +967,6 @@ namespace XCharts
for (int i = 0; i < size; i++)
{
var scaleWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
float pX = 0;
float pY = totalWidth;
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
{
@@ -909,9 +980,42 @@ namespace XCharts
new Vector2(coordinateX, pY + scaleWidth),
yAxis.splitArea.getColor(i));
}
if (yAxis.splitLine.show)
{
if (!xAxis.axisLine.show || !xAxis.axisLine.onZero || zeroPos.y != pY)
{
if (yAxis.splitLine.NeedShow(i))
{
DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(coordinateX, pY),
new Vector3(coordinateX + coordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo));
}
}
}
totalWidth += scaleWidth;
}
}
}
private void DrawYAxisTick(VertexHelper vh, int yAxisIndex, YAxis yAxis)
{
if (yAxis.NeedShowSplit())
{
var size = yAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
var totalWidth = coordinateY;
var xAxis = m_XAxises[yAxisIndex];
for (int i = 0; i < size; i++)
{
var scaleWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
float pX = 0;
float pY = totalWidth;
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
{
pY -= scaleWidth / 2;
}
if (yAxis.axisTick.show)
{
var startX = coordinateX + m_XAxises[yAxisIndex].runtimeZeroXOffset;
var startX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
startX -= yAxis.axisLine.width;
if (yAxis.IsValue() && yAxisIndex > 0) startX += coordinateWidth;
bool inside = yAxis.axisTick.inside;
if ((inside && yAxisIndex == 0) || (!inside && yAxisIndex == 1))
@@ -925,20 +1029,24 @@ namespace XCharts
ChartDrawer.DrawLine(vh, new Vector3(startX, pY), new Vector3(pX, pY),
yAxis.axisLine.width, m_ThemeInfo.axisLineColor);
}
if (yAxis.showSplitLine)
{
if (!xAxis.axisLine.show || zeroPos.y != pY)
{
DrawSplitLine(vh, yAxis, yAxis.splitLineType, new Vector3(coordinateX, pY),
new Vector3(coordinateX + coordinateWidth, pY), m_ThemeInfo.axisSplitLineColor);
}
}
totalWidth += scaleWidth;
}
}
if (yAxis.show && yAxis.axisLine.show)
{
var lineX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
if (yAxis.IsValue() && yAxisIndex > 0) lineX += coordinateWidth;
var top = new Vector3(lineX, coordinateY + coordinateHeight + yAxis.axisLine.width);
if (yAxis.axisLine.symbol)
{
var axisLine = yAxis.axisLine;
ChartDrawer.DrawArrow(vh, new Vector3(lineX, coordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
}
}
}
private void DrawXAxisTickAndSplit(VertexHelper vh, int xAxisIndex, XAxis xAxis)
private void DrawXAxisSplit(VertexHelper vh, int xAxisIndex, XAxis xAxis)
{
if (xAxis.NeedShowSplit())
{
@@ -950,7 +1058,6 @@ namespace XCharts
{
var scaleWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
float pX = totalWidth;
float pY = 0;
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
{
pX -= scaleWidth / 2;
@@ -963,9 +1070,42 @@ namespace XCharts
new Vector2(pX + scaleWidth, coordinateY),
xAxis.splitArea.getColor(i));
}
if (xAxis.splitLine.show)
{
if (!yAxis.axisLine.show || !yAxis.axisLine.onZero || zeroPos.x != pX)
{
if (xAxis.splitLine.NeedShow(i))
{
DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, coordinateY),
new Vector3(pX, coordinateY + coordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo));
}
}
}
totalWidth += scaleWidth;
}
}
}
private void DrawXAxisTick(VertexHelper vh, int xAxisIndex, XAxis xAxis)
{
if (xAxis.NeedShowSplit())
{
var size = xAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
var totalWidth = coordinateX;
var yAxis = m_YAxises[xAxisIndex];
for (int i = 0; i < size; i++)
{
var scaleWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
float pX = totalWidth;
float pY = 0;
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
{
pX -= scaleWidth / 2;
}
if (xAxis.axisTick.show)
{
var startY = coordinateY + m_YAxises[xAxisIndex].runtimeZeroYOffset;
var startY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
startY -= xAxis.axisLine.width;
if (xAxis.IsValue() && xAxisIndex > 0) startY += coordinateHeight;
bool inside = xAxis.axisTick.inside;
if ((inside && xAxisIndex == 0) || (!inside && xAxisIndex == 1))
@@ -979,17 +1119,21 @@ namespace XCharts
ChartDrawer.DrawLine(vh, new Vector3(pX, startY), new Vector3(pX, pY),
xAxis.axisLine.width, m_ThemeInfo.axisLineColor);
}
if (xAxis.showSplitLine)
{
if (!yAxis.axisLine.show || zeroPos.x != pX)
{
DrawSplitLine(vh, xAxis, xAxis.splitLineType, new Vector3(pX, coordinateY),
new Vector3(pX, coordinateY + coordinateHeight), m_ThemeInfo.axisSplitLineColor);
}
}
totalWidth += scaleWidth;
}
}
if (xAxis.show && xAxis.axisLine.show)
{
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHeight;
var top = new Vector3(coordinateX + coordinateWidth + xAxis.axisLine.width, lineY);
if (xAxis.axisLine.symbol)
{
var axisLine = xAxis.axisLine;
ChartDrawer.DrawArrow(vh, new Vector3(coordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
}
}
}
private void DrawXAxisLine(VertexHelper vh, int xAxisIndex, XAxis xAxis)
@@ -1001,12 +1145,6 @@ namespace XCharts
var left = new Vector3(coordinateX - xAxis.axisLine.width, lineY);
var top = new Vector3(coordinateX + coordinateWidth + xAxis.axisLine.width, lineY);
ChartDrawer.DrawLine(vh, left, top, xAxis.axisLine.width, m_ThemeInfo.axisLineColor);
if (xAxis.axisLine.symbol)
{
var axisLine = xAxis.axisLine;
ChartDrawer.DrawArrow(vh, new Vector3(coordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
}
}
}
@@ -1019,12 +1157,6 @@ namespace XCharts
var top = new Vector3(lineX, coordinateY + coordinateHeight + yAxis.axisLine.width);
ChartDrawer.DrawLine(vh, new Vector3(lineX, coordinateY - yAxis.axisLine.width),
top, yAxis.axisLine.width, m_ThemeInfo.axisLineColor);
if (yAxis.axisLine.symbol)
{
var axisLine = yAxis.axisLine;
ChartDrawer.DrawArrow(vh, new Vector3(lineX, coordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
}
}
}
@@ -1104,29 +1236,6 @@ namespace XCharts
}
}
protected void DrawSplitLine(VertexHelper vh, Axis axis, Axis.SplitLineType type,
Vector3 startPos, Vector3 endPos, Color color)
{
switch (type)
{
case Axis.SplitLineType.Dashed:
ChartDrawer.DrawDashLine(vh, startPos, endPos, axis.axisLine.width, color);
break;
case Axis.SplitLineType.Dotted:
ChartDrawer.DrawDotLine(vh, startPos, endPos, axis.axisLine.width, color);
break;
case Axis.SplitLineType.Solid:
ChartDrawer.DrawLine(vh, startPos, endPos, axis.axisLine.width, color);
break;
case Axis.SplitLineType.DashDot:
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, axis.axisLine.width, color);
break;
case Axis.SplitLineType.DashDotDot:
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, axis.axisLine.width, color);
break;
}
}
protected void DrawXTooltipIndicator(VertexHelper vh)
{
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
@@ -1147,12 +1256,12 @@ namespace XCharts
if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x;
Vector2 sp = new Vector2(pX, coordinateY);
Vector2 ep = new Vector2(pX, coordinateY + coordinateHeight);
DrawSplitLine(vh, xAxis, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
if (m_Tooltip.type == Tooltip.Type.Corss)
{
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
DrawSplitLine(vh, yAxis, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
}
break;
case Tooltip.Type.Shadow:
@@ -1190,12 +1299,12 @@ namespace XCharts
float pY = coordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(coordinateX, pY);
Vector2 ep = new Vector2(coordinateX + coordinateWidth, pY);
DrawSplitLine(vh, xAxis, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
if (m_Tooltip.type == Tooltip.Type.Corss)
{
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
DrawSplitLine(vh, yAxis, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
}
break;
case Tooltip.Type.Shadow:
@@ -1338,32 +1447,41 @@ namespace XCharts
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (serie.label.show || serieData.iconStyle.show)
if ((serie.label.show || serieData.iconStyle.show))
{
var pos = serie.dataPoints[j];
var value = serieData.data[1];
switch (serie.type)
var isIngore = ChartHelper.IsIngore(pos);
if (isIngore)
{
case SerieType.Line:
break;
case SerieType.Bar:
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[j];
switch (serie.label.position)
{
case SerieLabel.Position.Center:
pos = isYAxis ? new Vector3(bottomPos.x + (pos.x - bottomPos.x) / 2, pos.y) :
new Vector3(pos.x, bottomPos.y + (pos.y - bottomPos.y) / 2);
break;
case SerieLabel.Position.Bottom:
pos = isYAxis ? new Vector3(bottomPos.x, pos.y) : new Vector3(pos.x, bottomPos.y);
break;
}
break;
serieData.SetLabelActive(false);
}
else
{
var value = serieData.data[1];
switch (serie.type)
{
case SerieType.Line:
break;
case SerieType.Bar:
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[j];
switch (serie.label.position)
{
case SerieLabel.Position.Center:
pos = isYAxis ? new Vector3(bottomPos.x + (pos.x - bottomPos.x) / 2, pos.y) :
new Vector3(pos.x, bottomPos.y + (pos.y - bottomPos.y) / 2);
break;
case SerieLabel.Position.Bottom:
pos = isYAxis ? new Vector3(bottomPos.x, pos.y) : new Vector3(pos.x, bottomPos.y);
break;
}
break;
}
m_RefreshLabel = true;
serieData.labelPosition = pos;
if (serie.label.show) DrawLabelBackground(vh, serie, serieData);
}
m_RefreshLabel = true;
serieData.labelPosition = pos;
if (serie.label.show) DrawLabelBackground(vh, serie, serieData);
}
else
{
@@ -1386,7 +1504,6 @@ 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)
@@ -1409,8 +1526,9 @@ namespace XCharts
{
content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
}
serieData.SetLabelActive(value != 0);
serieData.SetLabelPosition(serie.label.offset);
serieData.SetLabelActive(value != 0 && serieData.labelPosition != Vector3.zero);
var down = serie.type == SerieType.Line && SerieHelper.IsDownPoint(serie, j);
serieData.SetLabelPosition(down ? -serie.label.offset : serie.label.offset);
if (serieData.SetLabelText(content)) RefreshChart();
}
else
@@ -1641,6 +1759,82 @@ namespace XCharts
RefreshDataZoomLabel();
RefreshChart();
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color32 color, bool clip)
{
if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3) || !IsInChart(p4)) return;
if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2) || IsInCooridate(p3) || IsInCooridate(p4))))
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color, color);
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
bool clip, bool vertical = true)
{
if (!IsInChart(p)) return;
if (!clip || (clip && (IsInCooridate(p))))
ChartDrawer.DrawPolygon(vh, p, radius, color, vertical);
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color32 startColor, Color32 toColor, bool clip)
{
p1 = ClampInCoordinate(p1);
p2 = ClampInCoordinate(p2);
p3 = ClampInCoordinate(p3);
p4 = ClampInCoordinate(p4);
if (!clip || (clip && (IsInCooridate(p1) && IsInCooridate(p2) && IsInCooridate(p3) && IsInCooridate(p4))))
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor);
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, ref Vector3 p4,
Color32 startColor, Color32 toColor, bool clip)
{
p1 = ClampInCoordinate(p1);
p2 = ClampInCoordinate(p2);
p3 = ClampInCoordinate(p3);
p4 = ClampInCoordinate(p4);
if (!clip || (clip && (IsInCooridate(p1) && IsInCooridate(p2) && IsInCooridate(p3) && IsInCooridate(p4))))
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor);
}
protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3,
Color32 color, bool clip)
{
CheckClipAndDrawTriangle(vh, p1, p2, p3, color, color, color, clip);
}
protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1,
Vector3 p2, Vector3 p3, Color32 color, Color32 color2, Color32 color3, bool clip)
{
if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3)) return;
if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2) || IsInCooridate(p3))))
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color, color2, color3);
}
protected void CheckClipAndDrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size,
Color32 color, bool clip)
{
if (!IsInChart(p1) || !IsInChart(p2)) return;
if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2))))
ChartDrawer.DrawLine(vh, p1, p2, size, color);
}
protected void CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color, float gap, bool clip)
{
if (!IsInChart(pos)) return;
if (!clip || (clip && (IsInCooridate(pos))))
DrawSymbol(vh, type, symbolSize, tickness, pos, color, gap);
}
protected void CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size,
float zebraWidth, float zebraGap, Color32 color, bool clip)
{
p1 = ClampInChart(p1);
p2 = ClampInChart(p2);
ChartDrawer.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color);
}
}
}

View File

@@ -18,6 +18,7 @@ namespace XCharts
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{
if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
@@ -44,9 +45,10 @@ 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);
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
float borderWidth = serie.itemStyle.runtimeBorderWidth;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
@@ -55,7 +57,7 @@ namespace XCharts
}
var serieData = showData[i];
serieData.canShowLabel = true;
float value = showData[i].GetCurrData(1, updateDuration);
float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + yAxis.axisLine.width;
float pY = coordinateY + +i * categoryWidth;
@@ -80,11 +82,17 @@ namespace XCharts
float currHig = CheckAnimation(serie, i, barHig);
Vector3 p1 = new Vector3(pX, pY + space + barWidth);
Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth);
Vector3 p3 = new Vector3(pX + currHig, pY + space);
Vector3 p4 = new Vector3(pX, pY + space);
serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2));
Vector3 p1 = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth);
Vector3 p2 = new Vector3(pX + currHig - 2 * borderWidth, pY + space + barWidth - borderWidth);
Vector3 p3 = new Vector3(pX + currHig - 2 * borderWidth, pY + space + borderWidth);
Vector3 p4 = new Vector3(pX + borderWidth, pY + space + borderWidth);
Vector3 top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2);
p1 = ClampInCoordinate(p1);
p2 = ClampInCoordinate(p2);
p3 = ClampInCoordinate(p3);
p4 = ClampInCoordinate(p4);
top = ClampInCoordinate(top);
serie.dataPoints.Add(top);
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
@@ -96,11 +104,20 @@ namespace XCharts
{
p1 = (p4 + p1) / 2;
p2 = (p2 + p3) / 2;
ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
CheckClipAndDrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
areaColor, serie.clip);
}
else
{
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
CheckClipAndDrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor, serie.clip);
if (borderWidth > 0)
{
var borderColor = serie.itemStyle.borderColor;
var itemWidth = Mathf.Abs(p3.x - p1.x);
var itemHeight = Mathf.Abs(p2.y - p4.y);
var center = new Vector3((p1.x + p3.x) / 2, (p2.y + p4.y) / 2);
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
}
}
}
}
@@ -116,23 +133,11 @@ namespace XCharts
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
{
float currHig = barHig;
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig);
if (!serie.animation.IsFinish())
{
if (serie.animation.IsInDelay()) currHig = 0;
else
{
var speed = serie.animation.duration > 0 ? barHig / serie.animation.duration * 1000 : barHig;
currHig = serie.animation.GetDataState(dataIndex) + speed * Time.deltaTime;
serie.animation.SetDataState(dataIndex, currHig);
if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
{
serie.animation.End();
currHig = barHig;
}
}
RefreshChart();
m_IsPlayingStartAnimation = true;
m_IsPlayingAnimation = true;
}
return currHig;
}
@@ -140,6 +145,7 @@ namespace XCharts
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{
if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
@@ -166,16 +172,17 @@ 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);
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
float borderWidth = serie.itemStyle.runtimeBorderWidth;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
float value = showData[i].GetCurrData(1, updateDuration);
float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
float pX = coordinateX + i * categoryWidth;
float zeroY = coordinateY + yAxis.runtimeZeroYOffset;
@@ -200,16 +207,20 @@ namespace XCharts
}
float currHig = CheckAnimation(serie, i, barHig);
Vector3 p1 = new Vector3(pX + space, pY);
Vector3 p2 = new Vector3(pX + space, pY + currHig);
Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig);
Vector3 p4 = new Vector3(pX + space + barWidth, pY);
serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig));
Vector3 p1 = new Vector3(pX + space + borderWidth, pY + borderWidth);
Vector3 p2 = new Vector3(pX + space + borderWidth, pY + currHig - 2 * borderWidth);
Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig - 2 * borderWidth);
Vector3 p4 = new Vector3(pX + space + barWidth, pY + borderWidth);
Vector3 top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
p1 = ClampInCoordinate(p1);
p2 = ClampInCoordinate(p2);
p3 = ClampInCoordinate(p3);
p4 = ClampInCoordinate(p4);
top = ClampInCoordinate(top);
serie.dataPoints.Add(top);
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
if (serie.show)
{
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
@@ -218,11 +229,20 @@ namespace XCharts
{
p1 = (p4 + p1) / 2;
p2 = (p2 + p3) / 2;
ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
CheckClipAndDrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
areaColor, serie.clip);
}
else
{
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, areaColor, areaToColor, serie.clip);
if (borderWidth > 0)
{
var borderColor = serie.itemStyle.borderColor;
var itemWidth = Mathf.Abs(p3.x - p1.x);
var itemHeight = Mathf.Abs(p2.y - p4.y);
var center = new Vector3((p1.x + p3.x) / 2, (p2.y + p4.y) / 2);
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
}
}
}
}

View File

@@ -116,6 +116,7 @@ namespace XCharts
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
{
if (serie.animation.HasFadeOut()) return;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
var xCount = xAxis.data.Count;
@@ -135,7 +136,7 @@ namespace XCharts
serie.dataPoints.Clear();
serie.animation.InitProgress(1, 0, xCount);
var animationIndex = serie.animation.GetCurrIndex();
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var dataChanging = false;
for (int i = 0; i < xCount; i++)
{
@@ -146,7 +147,7 @@ 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.GetCurrData(dimension, updateDuration);
var value = serieData.GetCurrData(dimension, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
serie.dataPoints.Add(pos);
@@ -183,10 +184,8 @@ namespace XCharts
}
if (!serie.animation.IsFinish())
{
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;
serie.animation.CheckProgress(xCount);
m_IsPlayingAnimation = true;
RefreshChart();
}
if (dataChanging)

View File

@@ -17,6 +17,7 @@ namespace XCharts
{
protected void DrawLinePoint(VertexHelper vh)
{
var clip = m_Series.IsAnyClipSerie();
for (int n = 0; n < m_Series.Count; n++)
{
var serie = m_Series.GetSerie(n);
@@ -32,12 +33,14 @@ namespace XCharts
if (serie.lineArrow.position == LineArrow.Position.End && i == count - 1) continue;
}
Vector3 p = serie.dataPoints[i];
if (ChartHelper.IsIngore(p)) continue;
bool highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted || serie.highlighted;
float symbolSize = highlight ? serie.symbol.selectedSize : serie.symbol.size;
var symbolColor = serie.GetSymbolColor(m_ThemeInfo, n, highlight);
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, p, symbolColor);
CheckClipAndDrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, p, symbolColor,
serie.symbol.gap, clip);
}
}
}
@@ -77,6 +80,7 @@ namespace XCharts
protected void DrawXLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{
if (!IsActive(serie.index)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
if (showData.Count <= 0) return;
Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false);
@@ -112,7 +116,7 @@ namespace XCharts
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (i = serie.minShow; i < maxCount; i += rate)
{
if (i == maxCount - 1) includeLastData = true;
@@ -120,11 +124,18 @@ 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, updateDuration, ref dataChanging);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
updateDuration);
serie.dataPoints.Add(np);
if (serie.IsIngoreValue(showData[i].GetData(1)))
{
serie.dataPoints.Add(Vector3.zero);
}
else
{
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage,
i, dataChangeDuration, ref dataChanging);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
dataChangeDuration);
serie.dataPoints.Add(np);
}
}
if (dataChanging)
{
@@ -134,10 +145,17 @@ namespace XCharts
{
i = maxCount - 1;
seriesHig.Add(0);
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.IsIngoreValue(showData[i].GetData(1)))
{
serie.dataPoints.Add(Vector3.zero);
}
else
{
float yValue = showData[i].GetCurrData(1, dataChangeDuration);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
dataChangeDuration);
serie.dataPoints.Add(np);
}
}
if (serie.dataPoints.Count <= 0)
{
@@ -153,8 +171,15 @@ namespace XCharts
if (serie.minShow > 0 && serie.minShow < showData.Count)
{
i = serie.minShow - 1;
float yValue = showData[i].GetCurrData(1, updateDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, updateDuration);
if (serie.IsIngoreValue(showData[i].GetData(1)))
{
serie.dataPoints.Add(Vector3.zero);
}
else
{
float yValue = showData[i].GetCurrData(1, dataChangeDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, dataChangeDuration);
}
}
else
{
@@ -163,8 +188,15 @@ namespace XCharts
if (serie.maxShow > 0 && serie.maxShow < showData.Count)
{
i = serie.maxShow;
float yValue = showData[i].GetCurrData(1, updateDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, updateDuration);
if (serie.IsIngoreValue(showData[i].GetData(1)))
{
serie.dataPoints.Add(Vector3.zero);
}
else
{
float yValue = showData[i].GetCurrData(1, dataChangeDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, dataChangeDuration);
}
}
else
{
@@ -174,7 +206,8 @@ namespace XCharts
{
np = serie.dataPoints[i];
serie.ClearSmoothList(i);
if (!serie.animation.NeedAnimation(i)) break;
//if(np == Vector3.zero) continue;
//if (!serie.animation.NeedAnimation(i)) break;
bool isFinish = true;
if (serie.areaStyle.tooltipHighlight && m_Tooltip.show && i <= m_Tooltip.runtimeDataIndex[0])
{
@@ -189,21 +222,24 @@ namespace XCharts
switch (serie.lineType)
{
case LineType.Normal:
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
nnp = GetNNPos(serie.dataPoints, i, np);
isFinish = DrawNormalLine(vh, serie, xAxis, lp, np, nnp, i, lineColor,
areaColor, areaToColor, zeroPos);
break;
case LineType.Smooth:
case LineType.SmoothDash:
llp = i > 1 ? serie.dataPoints[i - 2] : firstLastPos;
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : lastNextPos;
//llp = i > 1 ? serie.dataPoints[i - 2] : firstLastPos;
//nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : lastNextPos;
llp = GetLLPos(serie.dataPoints, i, firstLastPos);
nnp = GetNNPos(serie.dataPoints, i, lastNextPos);
isFinish = DrawSmoothLine(vh, serie, xAxis, lp, np, llp, nnp, i,
lineColor, areaColor, areaToColor, isStack, zeroPos);
break;
case LineType.StepStart:
case LineType.StepMiddle:
case LineType.StepEnd:
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
//nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
nnp = GetNNPos(serie.dataPoints, i, np);
isFinish = DrawStepLine(vh, serie, xAxis, lp, np, nnp, i, lineColor,
areaColor, areaToColor, zeroPos);
break;
@@ -215,20 +251,48 @@ namespace XCharts
break;
}
if (isFinish) serie.animation.SetDataFinish(i);
lp = np;
if (np != Vector3.zero) lp = np;
}
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = totalDetailProgress / duration;
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
m_IsPlayingStartAnimation = true;
serie.animation.CheckProgress(totalDetailProgress);
serie.animation.CheckSymbol(serie.symbol.size);
m_IsPlayingAnimation = true;
RefreshChart();
}
}
private Vector3 GetNNPos(List<Vector3> dataPoints, int index, Vector3 np)
{
int size = dataPoints.Count;
if (index >= size) return np;
for (int i = index + 1; i < size; i++)
{
if (dataPoints[i] != Vector3.zero) return dataPoints[i];
}
return np;
}
private Vector3 GetLastPos(List<Vector3> dataPoints, int index, Vector3 pos)
{
if (index <= 0) return pos;
for (int i = index - 1; i > 0; i--)
{
if (dataPoints[i] != Vector3.zero) return dataPoints[i];
}
return pos;
}
private Vector3 GetLLPos(List<Vector3> dataPoints, int index, Vector3 lp)
{
if (index <= 1) return lp;
for (int i = index - 2; i > 0; i--)
{
if (dataPoints[i] != Vector3.zero) return dataPoints[i];
}
return lp;
}
private float DataAverage(ref List<SerieData> showData, SampleType sampleType, int minCount, int maxCount, int rate)
{
var totalAverage = 0f;
@@ -245,12 +309,12 @@ namespace XCharts
}
private float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
int minCount, int maxCount, float totalAverage, int index, float updateDuration, ref bool dataChanging)
int minCount, int maxCount, float totalAverage, int index, float dataChangeDuration, ref bool dataChanging)
{
if (rate <= 1 || index == minCount)
{
if (showData[index].IsDataChanged()) dataChanging = true;
return showData[index].GetCurrData(1, updateDuration);
return showData[index].GetCurrData(1, dataChangeDuration);
}
switch (sampleType)
{
@@ -259,7 +323,7 @@ namespace XCharts
float total = 0;
for (int i = index; i > index - rate; i--)
{
total += showData[i].GetCurrData(1, updateDuration);
total += showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
}
if (sampleType == SampleType.Average) return total / rate;
@@ -268,7 +332,7 @@ namespace XCharts
float max = float.MinValue;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].GetCurrData(1, updateDuration);
var value = showData[i].GetCurrData(1, dataChangeDuration);
if (value > max) max = value;
if (showData[i].IsDataChanged()) dataChanging = true;
}
@@ -277,7 +341,7 @@ namespace XCharts
float min = float.MaxValue;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].GetCurrData(1, updateDuration);
var value = showData[i].GetCurrData(1, dataChangeDuration);
if (value < min) min = value;
if (showData[i].IsDataChanged()) dataChanging = true;
}
@@ -288,7 +352,7 @@ namespace XCharts
total = 0;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].GetCurrData(1, updateDuration);
var value = showData[i].GetCurrData(1, dataChangeDuration);
total += value;
if (value < min) min = value;
if (value > max) max = value;
@@ -299,34 +363,66 @@ namespace XCharts
else return min;
}
if (showData[index].IsDataChanged()) dataChanging = true;
return showData[index].GetCurrData(1, updateDuration);
return showData[index].GetCurrData(1, dataChangeDuration);
}
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i,
float scaleWid, float serieHig, ref Vector3 np, float duration)
float scaleWid, float serieHig, ref Vector3 np, float duration, bool isIngoreValue = false)
{
if (isIngoreValue)
{
np = Vector3.zero;
return 0;
}
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())
if (xAxis.IsValue() || xAxis.IsLog())
{
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 ((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;
if (xAxis.IsLog())
{
int minIndex = xAxis.runtimeMinLogIndex;
float nowIndex = xAxis.GetLogValue(xValue);
xDataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * coordinateWidth;
}
else
{
if ((xMaxValue - xMinValue) <= 0) xDataHig = 0;
else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
}
if (yAxis.IsLog())
{
int minIndex = yAxis.runtimeMinLogIndex;
float nowIndex = yAxis.GetLogValue(yValue);
yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * coordinateHeight;
}
else
{
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 ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
if (yAxis.IsLog())
{
int minIndex = yAxis.runtimeMinLogIndex;
float nowIndex = yAxis.GetLogValue(yValue);
yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * coordinateHeight;
}
else
{
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
}
np = new Vector3(pX, pY + yDataHig);
}
return yDataHig;
@@ -335,6 +431,7 @@ namespace XCharts
protected void DrawYLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{
if (!IsActive(serie.index)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
Vector3 lp = Vector3.zero;
Vector3 np = Vector3.zero;
@@ -369,19 +466,29 @@ namespace XCharts
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);
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
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].GetCurrData(1, updateDuration);
float value = showData[i].GetCurrData(1, dataChangeDuration);
float pY = startY + i * scaleWid;
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
float dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
float dataHig = 0;
if (xAxis.IsLog())
{
int minIndex = xAxis.runtimeMinLogIndex;
float nowIndex = xAxis.GetLogValue(value);
dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * coordinateWidth;
}
else
{
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
}
np = new Vector3(pX + dataHig, pY);
serie.dataPoints.Add(np);
seriesHig[i] += dataHig;
@@ -395,10 +502,20 @@ namespace XCharts
{
i = maxCount - 1;
seriesHig.Add(0);
float value = showData[i].GetCurrData(1, updateDuration);
float value = showData[i].GetCurrData(1, dataChangeDuration);
float pY = startY + i * scaleWid;
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
float dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
float dataHig = 0;
if (xAxis.IsLog())
{
int minIndex = xAxis.runtimeMinLogIndex;
float nowIndex = xAxis.GetLogValue(value);
dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * coordinateWidth;
}
else
{
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
}
np = new Vector3(pX + dataHig, pY);
serie.dataPoints.Add(np);
seriesHig[i] += dataHig;
@@ -467,12 +584,10 @@ namespace XCharts
}
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = (totalDetailProgress - dataCount * serie.lineStyle.width * 0.5f) / duration;
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
m_IsPlayingStartAnimation = true;
float total = totalDetailProgress - dataCount * serie.lineStyle.width * 0.5f;
serie.animation.CheckProgress(total);
serie.animation.CheckSymbol(serie.symbol.size);
m_IsPlayingAnimation = true;
RefreshChart();
}
}
@@ -489,7 +604,7 @@ namespace XCharts
if ((isYAxis && ySmall) || (!isYAxis && xSmall))
{
if (serie.animation.CheckDetailBreak(np, isYAxis)) return false;
ChartDrawer.DrawLine(vh, lp, np, serie.lineStyle.width, lineColor);
CheckClipAndDrawLine(vh, lp, np, serie.lineStyle.width, lineColor, serie.clip);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, lp, np, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
@@ -559,7 +674,7 @@ namespace XCharts
if ((isYAxis && tp1.y > lastDnPos.y) || (!isYAxis && tp1.x > lastDnPos.x) || dataIndex == 1 || IsValue())
{
isStart = true;
ChartDrawer.DrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor);
CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip);
}
}
else
@@ -568,21 +683,21 @@ namespace XCharts
{
if (np != nnp)
{
ChartDrawer.DrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor);
ChartDrawer.DrawTriangle(vh, upPos1, upPos2, dnPos, lineColor);
CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip);
CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip);
}
else ChartDrawer.DrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor);
else CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip);
}
else
{
if ((isYAxis && tp2.y < dnPos.y) || (!isYAxis && tp2.x < dnPos.x) || IsValue())
{
ChartDrawer.DrawLine(vh, start, cp, serie.lineStyle.width, lineColor);
CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.width, lineColor, serie.clip);
}
else
{
ChartDrawer.DrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor);
ChartDrawer.DrawTriangle(vh, upPos1, upPos2, dnPos, lineColor);
CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip);
CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip);
i = segment;
}
}
@@ -609,7 +724,7 @@ namespace XCharts
if ((isYAxis && tp2.y > lastDnPos.y) || (!isYAxis && tp2.x > lastDnPos.x) || dataIndex == 1 || IsValue())
{
isStart = true;
ChartDrawer.DrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor);
CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip);
}
}
else
@@ -618,19 +733,19 @@ namespace XCharts
{
if (np != nnp)
{
ChartDrawer.DrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor);
ChartDrawer.DrawTriangle(vh, dnPos, upPos2, upPos1, lineColor);
CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip);
CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip);
}
else ChartDrawer.DrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor);
else CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip);
}
else
{
if ((isYAxis && tp1.y < dnPos.y) || (!isYAxis && tp1.x < dnPos.x) || IsValue())
ChartDrawer.DrawLine(vh, start, cp, serie.lineStyle.width, lineColor);
CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.width, lineColor, serie.clip);
else
{
ChartDrawer.DrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor);
ChartDrawer.DrawTriangle(vh, dnPos, upPos2, upPos1, lineColor);
CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip);
CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip);
i = segment;
}
}
@@ -744,7 +859,7 @@ namespace XCharts
if ((isYAxis && ep.y > luPos.y) || (!isYAxis && ep.x > luPos.x))
{
var tp = isYAxis ? new Vector3(luPos.x, sp.y) : new Vector3(sp.x, luPos.y);
ChartDrawer.DrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor);
CheckClipAndDrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip);
break;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
@@ -766,7 +881,7 @@ namespace XCharts
{
first = true;
var tp = isYAxis ? new Vector3(rdPos.x, ep.y) : new Vector3(ep.x, rdPos.y);
ChartDrawer.DrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor);
CheckClipAndDrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor, serie.clip);
sp = ep;
continue;
}
@@ -790,7 +905,7 @@ namespace XCharts
if ((isYAxis && ep.y > rdPos.y) || (!isYAxis && ep.x > rdPos.x))
{
var tp = isYAxis ? new Vector3(rdPos.x, sp.y) : new Vector3(sp.x, rdPos.y);
ChartDrawer.DrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor);
CheckClipAndDrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor, serie.clip);
break;
}
if (rdPos != Vector3.zero) DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
@@ -812,7 +927,7 @@ namespace XCharts
{
first = true;
var tp = isYAxis ? new Vector3(luPos.x, ep.y) : new Vector3(ep.x, luPos.y);
ChartDrawer.DrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor);
CheckClipAndDrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip);
sp = ep;
continue;
}
@@ -916,7 +1031,7 @@ namespace XCharts
{
start = bezierPoints[i];
to = bezierPoints[i + 1];
ChartDrawer.DrawLine(vh, start, to, lineWidth, lineColor);
CheckClipAndDrawLine(vh, start, to, lineWidth, lineColor, serie.clip);
}
return true;
}
@@ -932,8 +1047,8 @@ namespace XCharts
bool isFinish = true;
if (dataIndex > 1)
{
ChartDrawer.DrawTriangle(vh, smoothStartPosUp, startUp, lp, lineColor);
ChartDrawer.DrawTriangle(vh, smoothStartPosDn, startDn, lp, lineColor);
CheckClipAndDrawTriangle(vh, smoothStartPosUp, startUp, lp, lineColor, serie.clip);
CheckClipAndDrawTriangle(vh, smoothStartPosDn, startDn, lp, lineColor, serie.clip);
smoothPoints.Add(smoothStartPosUp);
smoothDownPoints.Add(smoothStartPosDn);
}
@@ -955,8 +1070,8 @@ namespace XCharts
diff = dir1v * lineWidth;
toUp = to - diff;
toDn = to + diff;
if (isYAxis) ChartDrawer.DrawPolygon(vh, startDn, toDn, toUp, startUp, lineColor);
else ChartDrawer.DrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor);
if (isYAxis) CheckClipAndDrawPolygon(vh, startDn, toDn, toUp, startUp, lineColor, serie.clip);
else CheckClipAndDrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor, serie.clip);
smoothPoints.Add(toUp);
smoothDownPoints.Add(toDn);
if (k == bezierPoints.Count - 1)
@@ -976,13 +1091,13 @@ namespace XCharts
{
tnp = new Vector3(zeroPos.x + xAxis.axisLine.width, toDn.y);
tlp = new Vector3(zeroPos.x + xAxis.axisLine.width, startDn.y);
ChartDrawer.DrawPolygon(vh, startDn, toDn, tnp, tlp, areaColor, areaToColor);
CheckClipAndDrawPolygon(vh, startDn, toDn, tnp, tlp, areaColor, areaToColor, serie.clip);
}
else if (start.x < zeroPos.x && to.x < zeroPos.x)
{
tnp = new Vector3(zeroPos.x - xAxis.axisLine.width, toUp.y);
tlp = new Vector3(zeroPos.x - xAxis.axisLine.width, startUp.y);
ChartDrawer.DrawPolygon(vh, tnp, tlp, startUp, toUp, areaToColor, areaColor);
CheckClipAndDrawPolygon(vh, tnp, tlp, startUp, toUp, areaToColor, areaColor, serie.clip);
}
}
else
@@ -991,13 +1106,13 @@ namespace XCharts
{
tnp = new Vector3(toDn.x, zeroPos.y + xAxis.axisLine.width);
tlp = new Vector3(startDn.x, zeroPos.y + xAxis.axisLine.width);
ChartDrawer.DrawPolygon(vh, startDn, toDn, tnp, tlp, areaColor, areaToColor);
CheckClipAndDrawPolygon(vh, startDn, toDn, tnp, tlp, areaColor, areaToColor, serie.clip);
}
else if (start.y < zeroPos.y && to.y < zeroPos.y)
{
tnp = new Vector3(toUp.x, zeroPos.y - xAxis.axisLine.width);
tlp = new Vector3(startUp.x, zeroPos.y - xAxis.axisLine.width);
ChartDrawer.DrawPolygon(vh, tlp, tnp, toUp, startUp, areaToColor, areaColor);
CheckClipAndDrawPolygon(vh, tlp, tnp, toUp, startUp, areaToColor, areaColor, serie.clip);
}
}
}
@@ -1037,12 +1152,12 @@ namespace XCharts
if (k < lastSmoothPoints.Count - 1)
{
tnp = lastSmoothPoints[lastCount - 1];
ChartDrawer.DrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip);
while (lastCount < lastSmoothPoints.Count)
{
tlp = lastSmoothPoints[lastCount];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
ChartDrawer.DrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip);
lastCount++;
tnp = tlp;
}
@@ -1054,7 +1169,7 @@ namespace XCharts
{
tlp = lastSmoothPoints[lastSmoothPoints.Count - 1];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
ChartDrawer.DrawTriangle(vh, to, start, tlp, areaColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, to, start, tlp, areaColor, areaColor, areaToColor, serie.clip);
start = to;
continue;
}
@@ -1064,7 +1179,7 @@ namespace XCharts
{
tlp = lastSmoothPoints[lastCount - 1];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
ChartDrawer.DrawPolygon(vh, start, to, tnp, tlp, areaColor, areaToColor);
CheckClipAndDrawPolygon(vh, start, to, tnp, tlp, areaColor, areaToColor, serie.clip);
lastCount++;
}
else
@@ -1072,12 +1187,12 @@ namespace XCharts
if (diff < 0)
{
tnp = lastSmoothPoints[lastCount - 1];
ChartDrawer.DrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip);
while (diff < 0 && lastCount < lastSmoothPoints.Count)
{
tlp = lastSmoothPoints[lastCount];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
ChartDrawer.DrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip);
lastCount++;
diff = isYAxis ? tlp.y - to.y : tlp.x - to.x;
tnp = tlp;
@@ -1087,7 +1202,7 @@ namespace XCharts
{
tlp = lastSmoothPoints[lastCount - 1];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
ChartDrawer.DrawTriangle(vh, start, to, tlp, areaColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, start, to, tlp, areaColor, areaColor, areaToColor, serie.clip);
}
}
start = to;
@@ -1098,7 +1213,7 @@ namespace XCharts
var p2 = lastSmoothPoints[lastSmoothPoints.Count - 1];
if (!serie.animation.CheckDetailBreak(p1, isYAxis))
{
ChartDrawer.DrawTriangle(vh, p1, start, p2, areaToColor, areaColor, areaToColor);
CheckClipAndDrawTriangle(vh, p1, start, p2, areaToColor, areaColor, areaToColor, serie.clip);
}
}
}
@@ -1129,15 +1244,15 @@ namespace XCharts
for (int i = 1; i < linePointList.Count; i++)
{
ep = linePointList[i];
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
sp = ep;
}
ChartDrawer.DrawPolygon(vh, middle, lineWidth, lineColor);
CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip);
}
else
{
if (dataIndex == 1) ChartDrawer.DrawPolygon(vh, lp, lineWidth, lineColor);
ChartDrawer.DrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor);
if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip);
CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip);
}
if (serie.areaStyle.show)
{
@@ -1157,7 +1272,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1168,7 +1283,7 @@ namespace XCharts
if (nnp != np)
{
if (serie.animation.CheckDetailBreak(np, isYAxis)) return false;
ChartDrawer.DrawPolygon(vh, np, lineWidth, lineColor);
CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip);
bool flag = ((isYAxis && nnp.x > np.x && np.x > zeroPos.x) || (!isYAxis && nnp.y > np.y && np.y > zeroPos.y));
if (serie.areaStyle.show && flag)
{
@@ -1194,7 +1309,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1202,7 +1317,7 @@ namespace XCharts
sp = ep;
}
if (serie.animation.CheckDetailBreak(middle1, isYAxis)) return false;
ChartDrawer.DrawPolygon(vh, middle1, lineWidth, lineColor);
CheckClipAndDrawPolygon(vh, middle1, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show && Vector3.Dot(middleZero - middle1, middle2 - middle1) <= 0)
{
DrawPolygonToZero(vh, middle1 - diff1, middle1 + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1210,8 +1325,8 @@ namespace XCharts
}
else
{
if (dataIndex == 1) ChartDrawer.DrawPolygon(vh, lp, lineWidth, lineColor);
ChartDrawer.DrawLine(vh, lp + diff1, middle1 + diff1, lineWidth, lineColor);
if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip);
CheckClipAndDrawLine(vh, lp + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip);
}
//draw middle1 to middle2
@@ -1222,10 +1337,10 @@ namespace XCharts
for (int i = 1; i < linePointList.Count; i++)
{
ep = linePointList[i];
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
sp = ep;
}
ChartDrawer.DrawPolygon(vh, middle2, lineWidth, lineColor);
CheckClipAndDrawPolygon(vh, middle2, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show && Vector3.Dot(middleZero - middle2, middle2 - middle1) >= 0)
{
DrawPolygonToZero(vh, middle2 - diff1, middle2 + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1233,7 +1348,7 @@ namespace XCharts
}
else
{
ChartDrawer.DrawLine(vh, middle1 + diff2, middle2 + diff2, lineWidth, lineColor);
CheckClipAndDrawLine(vh, middle1 + diff2, middle2 + diff2, lineWidth, lineColor, serie.clip);
}
//draw middle2 to np
if (Vector3.Distance(middle2, np) > 2 * lineWidth)
@@ -1244,7 +1359,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1252,7 +1367,7 @@ namespace XCharts
sp = ep;
}
if (serie.animation.CheckDetailBreak(np, isYAxis)) return false;
ChartDrawer.DrawPolygon(vh, np, lineWidth, lineColor);
CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, np - diff1, np + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1260,7 +1375,7 @@ namespace XCharts
}
else
{
ChartDrawer.DrawLine(vh, middle1 + diff1, middle1 + diff1, lineWidth, lineColor);
CheckClipAndDrawLine(vh, middle1 + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip);
}
break;
case LineType.StepEnd:
@@ -1279,7 +1394,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1287,7 +1402,7 @@ namespace XCharts
sp = ep;
}
if (serie.animation.CheckDetailBreak(middle, isYAxis)) return false;
ChartDrawer.DrawPolygon(vh, middle, lineWidth, lineColor);
CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip);
if (serie.areaStyle.show && Vector3.Dot(np - middle, middleZero - middle) <= 0)
{
DrawPolygonToZero(vh, middle - diff1, middle + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1295,8 +1410,8 @@ namespace XCharts
}
else
{
if (dataIndex == 1) ChartDrawer.DrawPolygon(vh, lp, lineWidth, lineColor);
ChartDrawer.DrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor);
if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip);
CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip);
}
if (Vector3.Distance(middle, np) > 2 * lineWidth)
@@ -1306,14 +1421,14 @@ namespace XCharts
for (int i = 1; i < linePointList.Count; i++)
{
ep = linePointList[i];
ChartDrawer.DrawLine(vh, sp, ep, lineWidth, lineColor);
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip);
sp = ep;
}
if (nnp != np) ChartDrawer.DrawPolygon(vh, np, lineWidth, lineColor);
if (nnp != np) CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip);
}
else
{
ChartDrawer.DrawLine(vh, middle + diff2, np + diff2, lineWidth, lineColor);
CheckClipAndDrawLine(vh, middle + diff2, np + diff2, lineWidth, lineColor, serie.clip);
}
bool flag2 = ((isYAxis && middle.x > np.x && np.x > zeroPos.x) || (!isYAxis && middle.y > np.y && np.y > zeroPos.y));
if (serie.areaStyle.show && flag2)

View File

@@ -14,6 +14,7 @@ namespace XCharts
{
protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
{
if (serie.animation.HasFadeOut()) return;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);
@@ -23,13 +24,13 @@ namespace XCharts
: serie.dataCount;
serie.animation.InitProgress(1, 0, 1);
var rate = serie.animation.GetCurrRate();
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var dataChanging = false;
for (int n = serie.minShow; n < maxCount; n++)
{
var serieData = serie.GetDataList(m_DataZoom)[n];
float xValue = serieData.GetCurrData(0, updateDuration);
float yValue = serieData.GetCurrData(1, updateDuration);
float xValue = serieData.GetCurrData(0, dataChangeDuration);
float yValue = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
float pX = coordinateX + xAxis.axisLine.width;
float pY = coordinateY + yAxis.axisLine.width;
@@ -55,21 +56,19 @@ namespace XCharts
{
var nowSize = serie.symbol.animationSize[count];
color.a = (symbolSize - nowSize) / symbolSize;
DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color);
DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color, serie.symbol.gap);
}
RefreshChart();
}
else
{
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color, serie.symbol.gap);
}
}
if (!serie.animation.IsFinish())
{
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;
serie.animation.CheckProgress(1);
m_IsPlayingAnimation = true;
RefreshChart();
}
if (dataChanging)

View File

@@ -19,7 +19,7 @@ namespace XCharts
private Text m_LabelText;
private RectTransform m_LabelRect;
private Image m_IconImage;
private RectTransform m_IconRect;
// private RectTransform m_IconRect;
public Image icon { get { return m_IconImage; } }
public Text label { get { return m_LabelText; } }
@@ -43,7 +43,7 @@ namespace XCharts
m_IconImage = image;
if (image != null)
{
m_IconRect = m_IconImage.GetComponent<RectTransform>();
// m_IconRect = m_IconImage.GetComponent<RectTransform>();
}
}

View File

@@ -0,0 +1,190 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
public class LegendItem
{
private int m_Index;
private string m_Name;
private string m_LegendName;
private GameObject m_GameObject;
private Button m_Button;
private Image m_Icon;
private Text m_Text;
private Image m_TextBackground;
private RectTransform m_Rect;
private RectTransform m_IconRect;
private RectTransform m_TextRect;
private RectTransform m_TextBackgroundRect;
private float m_Gap = 0f;
private float m_LabelPaddingLeftRight = 0f;
private float m_LabelPaddingTopBottom = 0f;
private bool m_LabelAutoSize = true;
public int index { get { return m_Index; } set { m_Index = value; } }
public string name { get { return m_Name; } set { m_Name = value; } }
public string legendName { get { return m_LegendName; } set { m_LegendName = value; } }
public GameObject gameObject { get { return m_GameObject; } }
public Button button { get { return m_Button; } }
public float width
{
get
{
if (m_IconRect && m_TextBackgroundRect)
{
return m_IconRect.sizeDelta.x + m_Gap + m_TextBackgroundRect.sizeDelta.x;
}
else
{
return 0;
}
}
}
public float height
{
get
{
if (m_IconRect && m_TextBackgroundRect)
{
return Mathf.Max(m_IconRect.sizeDelta.y, m_TextBackgroundRect.sizeDelta.y);
}
else
{
return 0;
}
}
}
public void SetObject(GameObject obj)
{
m_GameObject = obj;
m_Button = obj.GetComponent<Button>();
m_Rect = obj.GetComponent<RectTransform>();
m_Icon = obj.transform.Find("icon").gameObject.GetComponent<Image>();
m_TextBackground = obj.transform.Find("content").gameObject.GetComponent<Image>();
m_Text = obj.transform.Find("content/Text").gameObject.GetComponent<Text>();
m_IconRect = m_Icon.gameObject.GetComponent<RectTransform>();
m_TextRect = m_Text.gameObject.GetComponent<RectTransform>();
m_TextBackgroundRect = m_TextBackground.gameObject.GetComponent<RectTransform>();
}
public void SetButton(Button button)
{
m_Button = button;
}
public void SetIcon(Image icon)
{
m_Icon = icon;
}
public void SetText(Text text)
{
m_Text = text;
}
public void SetTextBackground(Image image)
{
m_TextBackground = image;
}
public void SetIconSize(float width, float height)
{
if (m_IconRect)
{
m_IconRect.sizeDelta = new Vector2(width, height);
}
}
public void SetIconColor(Color color)
{
if (m_Icon)
{
m_Icon.color = color;
}
}
public void SetIconImage(Sprite image)
{
if (m_Icon)
{
m_Icon.sprite = image;
}
}
public void SetContentColor(Color color)
{
if (m_Text)
{
m_Text.color = color;
}
}
public void SetContentBackgroundColor(Color color)
{
if (m_TextBackground)
{
m_TextBackground.color = color;
}
}
public void SetContentPosition(Vector3 offset)
{
m_Gap = offset.x;
if (m_TextBackgroundRect)
{
var posX = m_IconRect.sizeDelta.x + offset.x;
m_TextBackgroundRect.anchoredPosition3D = new Vector3(posX, offset.y, 0);
}
}
public bool SetContent(string content)
{
if (m_Text && !m_Text.text.Equals(content))
{
m_Text.text = content;
if (m_LabelAutoSize)
{
var newSize = string.IsNullOrEmpty(content) ? Vector2.zero :
new Vector2(m_Text.preferredWidth, m_Text.preferredHeight);
var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
if (sizeChange)
{
m_TextRect.sizeDelta = newSize;
m_TextRect.anchoredPosition3D = new Vector3(m_LabelPaddingLeftRight, 0);
m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.preferredWidth + m_LabelPaddingLeftRight * 2,
m_Text.preferredHeight + m_LabelPaddingTopBottom * 2 - 4);
m_Rect.sizeDelta = new Vector3(width, height);
}
return sizeChange;
}
}
return false;
}
public void SetPosition(Vector3 position)
{
if (m_GameObject)
{
m_GameObject.transform.localPosition = position;
}
}
public void SetActive(bool active)
{
if (m_GameObject)
{
m_GameObject.SetActive(active);
}
}
}
}

View File

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

View File

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
internal static class PropertyUtility
{
public static bool SetColor(ref Color currentValue, Color newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetColor(ref Color32 currentValue, Color32 newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
{
if (EqualityComparer<T>.Default.Equals(currentValue, newValue))
return false;
currentValue = newValue;
return true;
}
public static bool SetClass<T>(ref T currentValue, T newValue, bool notNull = false) where T : class
{
if (notNull)
{
if (newValue == null)
{
Debug.LogError("can not be null.");
return false;
}
}
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
return false;
currentValue = newValue;
return true;
}
}
}

View File

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

View File

@@ -14,20 +14,23 @@ namespace XCharts
internal static class SerieLabelPool
{
private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200);
private static Dictionary<int, bool> m_ReleaseDic = new Dictionary<int, bool>(1000);
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, float iconWidth, float iconHeight)
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)
{
element = ChartHelper.AddSerieLabel(name, parent, font,
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
label.backgroundWidth, label.backgroundHeight);
label.backgroundWidth, label.backgroundHeight, 1);
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
}
else
{
element = m_Stack.Pop();
m_ReleaseDic.Remove(element.GetInstanceID());
element.name = name;
element.transform.SetParent(parent);
element.transform.localEulerAngles = new Vector3(0, 0, label.rotate);
@@ -44,10 +47,12 @@ namespace XCharts
public static void Release(GameObject element)
{
ChartHelper.SetActive(element, false);
//if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
// Debug.LogError("Internal error. Trying to destroy object that is already released to pool." + element.name);
if (Application.isPlaying)
if (!Application.isPlaying) return;
if (!m_ReleaseDic.ContainsKey(element.GetInstanceID()))
{
m_Stack.Push(element);
m_ReleaseDic.Add(element.GetInstanceID(), true);
}
}
public static void ReleaseAll(Transform parent)
@@ -62,6 +67,7 @@ namespace XCharts
public static void ClearAll()
{
m_Stack.Clear();
m_ReleaseDic.Clear();
}
}
}

View File

@@ -32,6 +32,7 @@ namespace XCharts
{
base.Reset();
m_Title.text = "PieChart";
m_Legend.show = true;
RemoveData();
AddSerie(SerieType.Pie, "serie1");
AddData(0, 70, "pie1");
@@ -58,7 +59,7 @@ namespace XCharts
serie.index = i;
var data = serie.data;
serie.animation.InitProgress(data.Count, 0, 360);
if (!serie.show)
if (!serie.show || serie.animation.HasFadeOut())
{
continue;
}
@@ -77,13 +78,12 @@ namespace XCharts
sd.canShowLabel = false;
}
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float dataChangeDuration = 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.GetCurrData(1, updateDuration);
float value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
Color color = m_ThemeInfo.GetColor(serieNameCount);
@@ -123,7 +123,7 @@ namespace XCharts
serieData.runtimePieCurrAngle = serieData.runtimePieToAngle;
serieData.runtiemPieOffsetCenter = center;
serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
if (serie.animation.CheckDetailBreak(n, serieData.runtimePieToAngle))
if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
{
isFinish = false;
serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail();
@@ -144,7 +144,7 @@ namespace XCharts
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);
DrawRoundCap(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, drawStartDegree, drawEndDegree);
}
@@ -152,7 +152,7 @@ namespace XCharts
{
var drawStartDegree = startDegree + serie.pieSpace;
var drawEndDegree = serieData.runtimePieCurrAngle - serie.pieSpace;
DrawArcShape(vh, serie, serieData, center, color, ref drawStartDegree, ref drawEndDegree);
DrawRoundCap(vh, serie, serieData, center, color, ref drawStartDegree, ref drawEndDegree);
ChartDrawer.DrawDoughnut(vh, center, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
}
@@ -164,11 +164,8 @@ namespace XCharts
}
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = 360 / duration;
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
serie.animation.CheckProgress(360);
serie.animation.CheckSymbol(serie.symbol.size);
RefreshChart();
}
if (dataChanging)
@@ -181,10 +178,10 @@ namespace XCharts
raycastTarget = isClickOffset && isDataHighlight;
}
private void DrawArcShape(VertexHelper vh, Serie serie, SerieData serieData, Vector3 centerPos,
private void DrawRoundCap(VertexHelper vh, Serie serie, SerieData serieData, Vector3 centerPos,
Color color, ref float drawStartDegree, ref float drawEndDegree)
{
if (serie.arcShaped && serieData.runtimePieInsideRadius > 0)
if (serie.roundCap && serieData.runtimePieInsideRadius > 0)
{
var width = (serieData.runtimePieOutsideRadius - serieData.runtimePieInsideRadius) / 2;
var radius = serieData.runtimePieInsideRadius + width;
@@ -192,14 +189,8 @@ namespace XCharts
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);
ChartDrawer.DrawRoundCap(vh, centerPos, width, radius, drawStartDegree, serie.clockwise, color, false);
ChartDrawer.DrawRoundCap(vh, centerPos, width, radius, drawEndDegree, serie.clockwise, color, true);
}
}
@@ -488,9 +479,8 @@ namespace XCharts
protected override void OnLegendButtonClick(int index, string legendName, bool show)
{
bool active = CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(legendName, bgColor1);
CheckDataShow(legendName, show);
UpdateLegendColor(legendName, show);
RefreshChart();
}
@@ -531,7 +521,7 @@ namespace XCharts
if (selected)
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
UpdateTooltip();
}
else if (m_Tooltip.IsActive())
{
@@ -570,16 +560,16 @@ namespace XCharts
}
StringBuilder sb = new StringBuilder();
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
base.RefreshTooltip();
base.UpdateTooltip();
bool showTooltip = false;
foreach (var serie in m_Series.list)
{
int index = m_Tooltip.runtimeDataIndex[serie.index];
if (index < 0) continue;
showTooltip = true;
if (string.IsNullOrEmpty(tooltip.formatter))
if (tooltip.IsNoFormatter())
{
string key = serie.data[index].name;
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(index);
@@ -596,7 +586,7 @@ namespace XCharts
}
else
{
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, null));
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, null, m_ThemeInfo));
}
var pos = m_Tooltip.GetContentPos();

View File

@@ -16,34 +16,17 @@ namespace XCharts
[ExecuteInEditMode]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public class RadarChart : BaseChart
public partial class RadarChart : BaseChart
{
private const string INDICATOR_TEXT = "indicator";
[SerializeField] private List<Radar> m_Radars = new List<Radar>();
private List<Radar> m_CheckRadars = new List<Radar>();
private bool m_IsEnterLegendButtom;
public List<Radar> radars { get { return m_Radars; } }
/// <summary>
/// 移除所有数据,包含指示器数据。
/// </summary>
public override void RemoveData()
{
base.RemoveData();
foreach (var radar in m_Radars)
{
radar.indicatorList.Clear();
}
m_CheckRadars.Clear();
}
private bool m_RadarsDirty;
protected override void OnLegendButtonClick(int index, string legendName, bool show)
{
bool active = CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(legendName, bgColor1);
CheckDataShow(legendName, show);
UpdateLegendColor(legendName, show);
RefreshChart();
}
@@ -70,7 +53,26 @@ namespace XCharts
protected override void Update()
{
base.Update();
CheckRadarInfoChanged();
}
protected override void CheckComponent()
{
var anyDirty = IsAnyRadarDirty();
if (m_RadarsDirty || anyDirty)
{
InitIndicator();
OnRadarChanged();
RefreshChart();
m_Tooltip.UpdateToTop();
if (anyDirty)
{
foreach (var radar in m_Radars)
{
radar.ClearDirty();
}
}
}
base.CheckComponent();
}
#if UNITY_EDITOR
@@ -84,12 +86,19 @@ namespace XCharts
serie.symbol.type = SerieSymbolType.EmptyCircle;
serie.symbol.size = 4;
serie.symbol.selectedSize = 6;
serie.showDataName = true;
List<float> data = new List<float>();
for (int i = 0; i < 5; i++)
{
data.Add(Random.Range(20, 90));
}
AddData(0, data);
AddData(0, data, "legendName");
}
protected override void OnValidate()
{
base.OnValidate();
m_RadarsDirty = true;
}
#endif
@@ -112,7 +121,7 @@ namespace XCharts
var textColor = textStyle.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : textStyle.color;
var txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font,
textColor, anchor, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(txtWid, txtHig), textStyle.fontSize, textStyle.rotate, textStyle.fontStyle);
new Vector2(txtWid, txtHig), textStyle.fontSize, textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
txt.text = radar.indicatorList[i].name;
txt.gameObject.SetActive(radar.indicator);
var txtWidth = txt.preferredWidth;
@@ -137,20 +146,17 @@ namespace XCharts
}
}
private void CheckRadarInfoChanged()
private bool IsAnyRadarDirty()
{
if (!ChartHelper.IsValueEqualsList(m_CheckRadars, m_Radars))
foreach (var radar in m_Radars)
{
m_CheckRadars.Clear();
foreach (var radar in m_Radars) m_CheckRadars.Add(radar.Clone());
OnRadarChanged();
if (radar.anyDirty) return true;
}
return false;
}
private void OnRadarChanged()
protected virtual void OnRadarChanged()
{
InitIndicator();
m_Tooltip.UpdateToTop();
}
protected override void DrawChart(VertexHelper vh)
@@ -193,7 +199,7 @@ namespace XCharts
break;
}
}
InitIndicator();
m_RadarsDirty = true;
}
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
@@ -213,13 +219,13 @@ namespace XCharts
var angle = 2 * Mathf.PI / indicatorNum;
Vector3 p = radar.runtimeCenterPos;
serie.animation.InitProgress(1, 0, 1);
if (!IsActive(i))
if (!IsActive(i) || serie.animation.HasFadeOut())
{
continue;
}
var rate = serie.animation.GetCurrRate();
var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
@@ -264,7 +270,7 @@ namespace XCharts
if (n >= serieData.data.Count) break;
float min = radar.GetIndicatorMin(n);
float max = radar.GetIndicatorMax(n);
float value = serieData.GetCurrData(n, updateDuration);
float value = serieData.GetCurrData(n, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0)
{
@@ -291,7 +297,7 @@ namespace XCharts
}
if (serie.lineStyle.show)
{
ChartDrawer.DrawLine(vh, startPoint, toPoint, serie.lineStyle.width, lineColor);
DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor);
}
startPoint = toPoint;
}
@@ -303,7 +309,7 @@ namespace XCharts
}
if (serie.lineStyle.show)
{
ChartDrawer.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor);
DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor);
}
if (serie.symbol.type != SerieSymbolType.None)
{
@@ -312,15 +318,14 @@ namespace XCharts
symbolColor.a *= serie.symbol.opacity;
foreach (var point in pointList)
{
DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, point, symbolColor);
DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, point, symbolColor,
serie.symbol.gap);
}
}
}
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = 1 / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckProgress(1);
RefreshChart();
}
if (dataChanging)
@@ -332,7 +337,7 @@ namespace XCharts
private void DrawRadar(VertexHelper vh, Radar radar)
{
if (!radar.lineStyle.show && !radar.splitArea.show)
if (!radar.splitLine.show && !radar.splitArea.show)
{
return;
}
@@ -360,9 +365,9 @@ namespace XCharts
{
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color);
}
if (radar.lineStyle.show)
if (radar.splitLine.NeedShow(i))
{
ChartDrawer.DrawLine(vh, p2, p3, radar.lineStyle.width, lineColor);
DrawLineStyle(vh, radar.splitLine.lineStyle, p2, p3, lineColor);
}
p1 = p4;
p2 = p3;
@@ -374,16 +379,16 @@ namespace XCharts
float currAngle = j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
if (radar.lineStyle.show)
if (radar.splitLine.show)
{
ChartDrawer.DrawLine(vh, p, p3, radar.lineStyle.width / 2, lineColor);
DrawLineStyle(vh, radar.splitLine.lineStyle, p, p3, lineColor);
}
}
}
private void DrawCricleRadar(VertexHelper vh, Radar radar)
{
if (!radar.lineStyle.show && !radar.splitArea.show)
if (!radar.splitLine.show && !radar.splitArea.show)
{
return;
}
@@ -403,9 +408,9 @@ namespace XCharts
ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear,
m_Settings.cicleSmoothness, 0, 360);
}
if (radar.lineStyle.show)
if (radar.splitLine.show)
{
ChartDrawer.DrawEmptyCricle(vh, p, outsideRadius, radar.lineStyle.width, lineColor,
ChartDrawer.DrawEmptyCricle(vh, p, outsideRadius, radar.splitLine.lineStyle.width, lineColor,
Color.clear, m_Settings.cicleSmoothness);
}
insideRadius = outsideRadius;
@@ -415,30 +420,18 @@ namespace XCharts
float currAngle = j * angle;
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
if (radar.lineStyle.show)
if (radar.splitLine.show)
{
ChartDrawer.DrawLine(vh, p, p1, radar.lineStyle.width / 2, lineColor);
ChartDrawer.DrawLine(vh, p, p1, radar.splitLine.lineStyle.width / 2, lineColor);
}
}
}
private Color GetLineColor(Radar radar)
{
if (radar.lineStyle.color != Color.clear)
{
var color = radar.lineStyle.color;
color.a *= radar.lineStyle.opacity;
return color;
}
else
{
var color = (Color)m_ThemeInfo.axisLineColor;
color.a *= radar.lineStyle.opacity;
return color;
}
return radar.splitLine.GetColor(m_ThemeInfo);
}
protected override void CheckTootipArea(Vector2 local)
{
if (m_IsEnterLegendButtom) return;
@@ -485,14 +478,14 @@ namespace XCharts
else
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
UpdateTooltip();
RefreshChart();
}
}
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
base.RefreshTooltip();
base.UpdateTooltip();
int serieIndex = m_Tooltip.runtimeDataIndex[0];
if (serieIndex < 0)
{
@@ -512,7 +505,7 @@ namespace XCharts
{
string key = radar.indicatorList[i].name;
float value = serieData.GetData(i);
sb.Append("\n");
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append("\n");
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, 0, m_Tooltip.forceENotation));
}
m_Tooltip.UpdateContentText(sb.ToString());

View File

@@ -0,0 +1,364 @@

/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
[AddComponentMenu("XCharts/RingChart", 20)]
[ExecuteInEditMode]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public partial class RingChart : BaseChart
{
private bool m_UpdateTitleText = false;
private bool m_UpdateLabelText = false;
private bool m_IsEnterLegendButtom;
protected override void Update()
{
base.Update();
if (m_UpdateTitleText)
{
m_UpdateTitleText = false;
TitleStyleHelper.UpdateTitleText(m_Series);
}
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
}
}
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
m_Title.text = "RingChart";
m_Tooltip.type = Tooltip.Type.Line;
RemoveData();
var serie = AddSerie(SerieType.Ring, "serie1");
serie.roundCap = true;
serie.radius = new float[] { 0.3f, 0.35f };
serie.titleStyle.show = false;
serie.titleStyle.textStyle.offset = new Vector2(0, 30);
serie.label.show = true;
serie.label.position = SerieLabel.Position.Center;
serie.label.formatter = "{d:f0}%";
serie.label.fontSize = 28;
var value = Random.Range(30, 90);
var max = 100;
AddData(0, value, max, "data1");
}
#endif
protected override void DrawChart(VertexHelper vh)
{
base.DrawChart(vh);
for (int i = 0; i < m_Series.list.Count; i++)
{
var serie = m_Series.list[i];
var data = serie.data;
serie.index = i;
if (!serie.show || serie.type != SerieType.Ring || serie.animation.HasFadeOut())
{
continue;
}
serie.animation.InitProgress(data.Count, serie.startAngle, serie.startAngle + 360);
serie.UpdateCenter(chartWidth, chartHeight);
TitleStyleHelper.CheckTitle(serie, ref m_ReinitTitle, ref m_UpdateTitleText);
SerieLabelHelper.CheckLabel(serie, ref m_ReinitLabel, ref m_UpdateLabelText);
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var ringWidth = serie.runtimeOutsideRadius - serie.runtimeInsideRadius;
var dataChanging = false;
for (int j = 0; j < data.Count; j++)
{
var serieData = data[j];
if (!serieData.show) continue;
if (serieData.IsDataChanged()) dataChanging = true;
var value = serieData.GetFirstData(dataChangeDuration);
var max = serieData.GetLastData();
var degree = 360 * value / max;
var startDegree = GetStartAngle(serie);
var toDegree = GetToAngle(serie, degree);
var itemColor = SerieHelper.GetItemColor(serie, m_ThemeInfo, j, serieData.highlighted);
var outsideRadius = serie.runtimeOutsideRadius - j * (ringWidth + serie.ringGap);
var insideRadius = outsideRadius - ringWidth;
var centerRadius = (outsideRadius + insideRadius) / 2;
serieData.runtimePieStartAngle = serie.clockwise ? startDegree : toDegree;
serieData.runtimePieToAngle = serie.clockwise ? toDegree : startDegree;
serieData.runtimePieInsideRadius = insideRadius;
serieData.runtimePieOutsideRadius = outsideRadius;
DrawBackground(vh, serie, j, insideRadius, outsideRadius);
DrawRoundCap(vh, serie, serie.runtimeCenterPos, itemColor, insideRadius, outsideRadius,
ref startDegree, ref toDegree);
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
outsideRadius, itemColor, Color.clear, m_Settings.cicleSmoothness,
startDegree, toDegree);
DrawBorder(vh, serie, insideRadius, outsideRadius);
DrawCenter(vh, serie, insideRadius, j == data.Count - 1);
UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius);
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(360);
serie.animation.CheckSymbol(serie.symbol.size);
RefreshChart();
}
if (dataChanging)
{
RefreshChart();
}
}
}
private float GetStartAngle(Serie serie)
{
return serie.clockwise ? serie.startAngle : 360 - serie.startAngle;
}
private float GetToAngle(Serie serie, float angle)
{
var toAngle = angle + serie.startAngle;
if (!serie.clockwise)
{
toAngle = 360 - toAngle - serie.startAngle;
}
if (!serie.animation.IsFinish())
{
var currAngle = serie.animation.GetCurrDetail();
if (serie.clockwise)
{
toAngle = toAngle > currAngle ? currAngle : toAngle;
}
else
{
toAngle = toAngle < 360 - currAngle ? 360 - currAngle : toAngle;
}
}
return toAngle;
}
private void DrawCenter(VertexHelper vh, Serie serie, float insideRadius, bool last)
{
if (serie.itemStyle.centerColor != Color.clear && last)
{
var radius = insideRadius - serie.itemStyle.centerGap;
ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, serie.itemStyle.centerColor);
}
}
private void UpateLabelPosition(Serie serie, SerieData serieData, int index, float startAngle,
float toAngle, float centerRadius)
{
if (!serie.label.show) return;
switch (serie.label.position)
{
case SerieLabel.Position.Center:
serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset;
break;
case SerieLabel.Position.Bottom:
var px1 = Mathf.Sin(startAngle * Mathf.Deg2Rad) * centerRadius;
var py1 = Mathf.Cos(startAngle * Mathf.Deg2Rad) * centerRadius;
var xDiff = serie.clockwise ? -serie.label.margin : serie.label.margin;
serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px1 + xDiff, py1);
break;
case SerieLabel.Position.Top:
startAngle += serie.clockwise ? -serie.label.margin : serie.label.margin;
toAngle += serie.clockwise ? serie.label.margin : -serie.label.margin;
var px2 = Mathf.Sin(toAngle * Mathf.Deg2Rad) * centerRadius;
var py2 = Mathf.Cos(toAngle * Mathf.Deg2Rad) * centerRadius;
serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px2, py2);
break;
}
}
private void DrawBackground(VertexHelper vh, Serie serie, int index, float insideRadius, float outsideRadius)
{
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, m_ThemeInfo, index, false);
if (serie.itemStyle.backgroundWidth != 0)
{
var centerRadius = (outsideRadius + insideRadius) / 2;
var inradius = centerRadius - serie.itemStyle.backgroundWidth / 2;
var outradius = centerRadius + serie.itemStyle.backgroundWidth / 2;
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, inradius,
outradius, backgroundColor, Color.clear, m_Settings.cicleSmoothness);
}
else
{
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
outsideRadius, backgroundColor, Color.clear, m_Settings.cicleSmoothness);
}
}
private void DrawBorder(VertexHelper vh, Serie serie, float insideRadius, float outsideRadius)
{
if (serie.itemStyle.show && serie.itemStyle.borderWidth > 0 && serie.itemStyle.borderColor != Color.clear)
{
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, outsideRadius,
outsideRadius + serie.itemStyle.borderWidth, serie.itemStyle.borderColor,
Color.clear, m_Settings.cicleSmoothness);
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
insideRadius + serie.itemStyle.borderWidth, serie.itemStyle.borderColor,
Color.clear, m_Settings.cicleSmoothness);
}
}
private void DrawRoundCap(VertexHelper vh, Serie serie, Vector3 centerPos, Color color,
float insideRadius, float outsideRadius, ref float drawStartDegree, ref float drawEndDegree)
{
if (serie.roundCap && insideRadius > 0 && drawStartDegree != drawEndDegree)
{
var width = (outsideRadius - insideRadius) / 2;
var radius = insideRadius + width;
var diffDegree = Mathf.Asin(width / radius) * Mathf.Rad2Deg;
drawStartDegree += serie.clockwise ? diffDegree : -diffDegree;
drawEndDegree -= serie.clockwise ? diffDegree : -diffDegree;
ChartDrawer.DrawRoundCap(vh, centerPos, width, radius, drawStartDegree, serie.clockwise, color, false);
ChartDrawer.DrawRoundCap(vh, centerPos, width, radius, drawEndDegree, serie.clockwise, color, true);
}
}
protected override void OnLegendButtonClick(int index, string legendName, bool show)
{
CheckDataShow(legendName, show);
UpdateLegendColor(legendName, show);
RefreshChart();
}
protected override void OnLegendButtonEnter(int index, string legendName)
{
m_IsEnterLegendButtom = true;
CheckDataHighlighted(legendName, true);
RefreshChart();
}
protected override void OnLegendButtonExit(int index, string legendName)
{
m_IsEnterLegendButtom = false;
CheckDataHighlighted(legendName, false);
RefreshChart();
}
protected override void CheckTootipArea(Vector2 local)
{
if (m_IsEnterLegendButtom) return;
m_Tooltip.runtimeDataIndex.Clear();
bool selected = false;
foreach (var serie in m_Series.list)
{
int index = GetRingIndex(serie, local);
m_Tooltip.runtimeDataIndex.Add(index);
if (serie.type != SerieType.Ring) continue;
bool refresh = false;
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (serieData.highlighted != (j == index)) refresh = true;
serieData.highlighted = j == index;
}
if (index >= 0) selected = true;
if (refresh) RefreshChart();
}
if (selected)
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
UpdateTooltip();
}
else if (m_Tooltip.IsActive())
{
m_Tooltip.SetActive(false);
RefreshChart();
}
}
private int GetRingIndex(Serie serie, Vector2 local)
{
if (serie.type != SerieType.Ring) return -1;
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
if (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++)
{
var serieData = serie.data[i];
if (dist >= serieData.runtimePieInsideRadius &&
dist <= serieData.runtimePieOutsideRadius &&
angle >= serieData.runtimePieStartAngle &&
angle <= serieData.runtimePieToAngle)
{
return i;
}
}
return -1;
}
float VectorAngle(Vector2 from, Vector2 to)
{
float angle;
Vector3 cross = Vector3.Cross(from, to);
angle = Vector2.Angle(from, to);
angle = cross.z > 0 ? -angle : angle;
angle = (angle + 360) % 360;
return angle;
}
StringBuilder sb = new StringBuilder();
protected override void UpdateTooltip()
{
base.UpdateTooltip();
bool showTooltip = false;
foreach (var serie in m_Series.list)
{
int index = m_Tooltip.runtimeDataIndex[serie.index];
if (index < 0) continue;
showTooltip = true;
if (tooltip.IsNoFormatter())
{
var serieData = serie.GetSerieData(index);
float value = serieData.GetFirstData();
sb.Length = 0;
if (!string.IsNullOrEmpty(serieData.name))
{
sb.Append("<color=#").Append(m_ThemeInfo.GetColorStr(index)).Append(">● </color>")
.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, 0, m_Tooltip.forceENotation));
}
else
{
sb.Append(ChartCached.FloatToStr(value, 0, m_Tooltip.forceENotation));
}
m_Tooltip.UpdateContentText(sb.ToString());
}
else
{
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, null, m_ThemeInfo));
}
var pos = m_Tooltip.GetContentPos();
if (pos.x + m_Tooltip.runtimeWidth > chartWidth)
{
pos.x = chartWidth - m_Tooltip.runtimeWidth;
}
if (pos.y - m_Tooltip.runtimeHeight < 0)
{
pos.y = m_Tooltip.runtimeHeight;
}
m_Tooltip.UpdateContentPos(pos);
}
m_Tooltip.SetActive(showTooltip);
}
}
}

View File

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

Some files were not shown because too many files have changed in this diff Show More