mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-06-10 12:33:43 +00:00
Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2e790561e | ||
|
|
f0e94d35b6 | ||
|
|
76f640f64d | ||
|
|
9d8dc80494 | ||
|
|
bc1d2ac095 | ||
|
|
913c8e1fb2 | ||
|
|
634bb45dc4 | ||
|
|
e4827ac262 | ||
|
|
9ad8a86ffc | ||
|
|
23a8ce52d1 | ||
|
|
38584f618b | ||
|
|
84c47e0d84 | ||
|
|
7ff1405de5 | ||
|
|
acae09bf28 | ||
|
|
b304bd2033 | ||
|
|
72c29235d8 | ||
|
|
5f18f060e3 | ||
|
|
a281028a22 | ||
|
|
fe702f3447 | ||
|
|
6888ba96e3 | ||
|
|
b261ef0573 | ||
|
|
64d0b047b3 | ||
|
|
5c395ade25 | ||
|
|
5149376806 | ||
|
|
d8f739cbdf | ||
|
|
71fb45af9f | ||
|
|
ca63d041b9 | ||
|
|
8fccfdb5fc | ||
|
|
f08ae794ae | ||
|
|
8efa8145b1 | ||
|
|
e247ad9e71 | ||
|
|
645506a6fd | ||
|
|
c5ef7e765b | ||
|
|
3949018555 | ||
|
|
34b0a97198 | ||
|
|
de3e482687 | ||
|
|
8dbbbd7405 | ||
|
|
3316fce8a5 | ||
|
|
f85f96a560 | ||
|
|
8f6f5790b6 | ||
|
|
f69aa1d232 | ||
|
|
bdd53bbe24 | ||
|
|
b20e768cd1 | ||
|
|
4de732a369 | ||
|
|
f87c8445f9 | ||
|
|
8d6d4ce0c5 | ||
|
|
5238689baa | ||
|
|
6f39e692ef | ||
|
|
e873709443 | ||
|
|
8d4a65a002 | ||
|
|
32a8fed625 | ||
|
|
1fccc25873 | ||
|
|
0621845e5a | ||
|
|
18391881d7 | ||
|
|
0e1d5cc81d | ||
|
|
78a83238f7 | ||
|
|
05f21f2d02 | ||
|
|
bcb30f3c82 | ||
|
|
470da8f975 | ||
|
|
8c83e828bf | ||
|
|
a91d190d85 | ||
|
|
e9e7371213 | ||
|
|
9349900ea5 | ||
|
|
0ae9be9c63 | ||
|
|
953bea6962 | ||
|
|
1f676c431a | ||
|
|
f953a069cb | ||
|
|
442206dad8 | ||
|
|
8dd3ef2a63 | ||
|
|
44110feaaf | ||
|
|
a42c1845d6 | ||
|
|
d233f64a68 | ||
|
|
055d3806d8 |
@@ -1,7 +1,14 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
[master](#master)
|
||||
[branch-2.0](#branch-2.0)
|
||||
[v2.6.0](#v2.6.0)
|
||||
[v2.5.0](#v2.5.0)
|
||||
[v2.4.0](#v2.4.0)
|
||||
[v2.3.0](#v2.3.0)
|
||||
[v2.2.3](#v2.2.3)
|
||||
[v2.2.2](#v2.2.2)
|
||||
[v2.2.1](#v2.2.1)
|
||||
[v2.2.0](#v2.2.0)
|
||||
[v2.1.1](#v2.1.1)
|
||||
[v2.1.0](#v2.1.0)
|
||||
@@ -33,7 +40,112 @@
|
||||
[v0.5.0](#v0.5.0)
|
||||
[v0.1.0](#v0.1.0)
|
||||
|
||||
## master
|
||||
## branch-2.0
|
||||
|
||||
## v2.6.0
|
||||
|
||||
* (2021.12.30) Release `v2.6.0` version
|
||||
* (2021.12.21) Fixed `Emphasis` dont work
|
||||
* (2021.12.17) Fixed `MarkLine` does not auto refresh label active when serie hide #178
|
||||
* (2021.12.10) Improved `Radar`'s `AxisLine` and `SplitLine` to be controlled separately
|
||||
* (2021.12.08) Fixed y axis does not refresh when serie hidden
|
||||
* (2021.12.04) Added `Symbol` new types: `EmptyRect`, `EmptyTriangle`, `EmptyDiamond`
|
||||
* (2021.12.04) Added setting symbol empty area color by itemStyle's backgroundColor
|
||||
* (2021.12.03) Fixed formatter `{c}` not work #175
|
||||
* (2021.12.03) Fixed axis `boundaryGap` display error in some cases #174
|
||||
* (2021.11.30) Fixed serie `ignore` display error in some cases #173
|
||||
|
||||
## v2.5.0
|
||||
|
||||
* (2021.11.27) Release `v2.5.0` version
|
||||
* (2021.11.27) Added `Tooltip` delegate function `positionFunction`
|
||||
* (2021.10.29) Removed settings for `TextMeshPro` when package first imported
|
||||
* (2021.10.29) Added support for `{e}` in `Tooltip` #170
|
||||
* (2021.09.08) Improved `RadarChart`
|
||||
* (2021.09.07) Fixed bug where `label` does not disappear at the end of `PieChart` fade animation #168
|
||||
* (2021.09.06) Fixed bug where `GaugeChart` changing `splitNumber` with code does not refresh `label` #167
|
||||
|
||||
## v2.4.0
|
||||
|
||||
### Main points
|
||||
|
||||
* LineChart support the line of ignore data is disconnected or connected
|
||||
* LineChart support animation at a constant speed
|
||||
* Other optimizations and bug fixes
|
||||
|
||||
### Details
|
||||
|
||||
* (2021.08.31) Release `v2.4.0` version
|
||||
* (2021.08.31) Optimized the gradient effect of `RingChart`
|
||||
* (2021.08.31) Fixed bug where `SerieLabel` does not refresh when `DataZoom` is dragged (#165)
|
||||
* (2021.08.25) Fixed an issue where the theme switch could not be save to the scene (#166)
|
||||
* (2021.08.24) Added `Animation`'s `alongWithLinePath`
|
||||
* (2021.08.22) Added `Serie`'s `ignoreLineBreak` (#164)
|
||||
* (2021.08.22) Fixed `Axis` label may not be updated when `DataZoom` is turn on (#164)
|
||||
* (2021.08.15) Improved `Axis`'s `AxisLabel` text rotate setting to avoid inconsistency offset in `DataZoom` (#163)
|
||||
* (2021.08.14) Added `Legend`'s `textAutoColor` to set the text color match with `Serie` color (#163)
|
||||
* (2021.08.12) Optimize `BarChart` setting `Corner` when the positive and negative columns are fillet symmetric
|
||||
* (2021.08.03) Fixed y axis not displaying when all data is 0
|
||||
* (2021.07.29) Fixed ignored data will also participate in calculations when `ignore` is enabled (#161)
|
||||
* (2021.07.29) Improved `BarChart`'s `Zebra` gradient support
|
||||
* (2021.07.26) Fixed issue where `XCharts` path could not be found when `TextMeshPro Enable` (#160)
|
||||
|
||||
## v2.3.0
|
||||
|
||||
### Main points
|
||||
|
||||
* Data store upgraded from `float` to `double`
|
||||
* Added `MarkLine`
|
||||
* `Serie` can use `IconStyle` to configure ICONS uniformly
|
||||
* `Label` supports custom display styles with code
|
||||
* `DataZoom` is perfect
|
||||
* `PieChart` optimization
|
||||
* Problem fixes
|
||||
|
||||
### Upgrade Note
|
||||
|
||||
Since the data type is upgraded to `double`, the implicit conversion of `float` to `double` may have precision problems, so it is recommended that all previous data types of `float` be manually changed to `double`.
|
||||
|
||||
### Details
|
||||
|
||||
* (2021.07.24) Release `v2.3.0` version
|
||||
* (2021.07.22) Improved `SerieSymbol` to support `PictorialBarchart` extension
|
||||
* (2021.07.19) Fixed issue where `Tooltip` was not displayed on `WdbGL` platform
|
||||
* (2021.07.18) Added `iconStyle` for serie
|
||||
* (2021.07.15) Added `MarkLine` (#142)
|
||||
* (2021.07.09) Optimize `BarChart` to set whether to show bars via `seriedata.show`
|
||||
* (2021.07.08) Optimize data storage type from `float` to `double`
|
||||
* (2021.07.05) Fixed `Piechart` `avoidLabelOverlap` parameter not working
|
||||
* (2021.07.04) Fixed incorrect mouse area indication after `PieChart` selected sector
|
||||
* (2021.07.04) Optimize when the `Label` of `PieChart` is `Inside`, the offset can be adjusted by the parameter `Margin`
|
||||
* (2021.07.01) Added `DataZoom` arguments to `supportInsideScroll` and `supportInsideDrag` to set whether scrolling and dragging are supported in the coordinate system
|
||||
* (2021.06.27) Add `showStartLabel` and `showEndLabel` arguments to `AxisLabel` to set whether the `Label` should be displayed at the beginning and end of the `AxisLabel`
|
||||
* (2021.06.27) Added `formatter` delegate method to `AxisLabel` and `SerieLabel` (#145)
|
||||
* (2021.06.27) Added `DataZoom`'s `orient` parameter to set horizontal or vertical styles
|
||||
* (2021.06.21) Added `iconStyle`'s `AutoHideWhenLabelEmpty` to set whether the icon is automatically hidden when `label` is empty
|
||||
|
||||
# # v2.2.3
|
||||
|
||||
* (2021.06.20) Release `v2.2.3` version
|
||||
* (2021.06.20) Fixed the default display of `Icon` in `Axis`
|
||||
|
||||
## v2.2.2
|
||||
|
||||
* (2021.06.18) Release `v2.2.2` version
|
||||
* (2021.06.18) Optimize `Axis` to automatically hide `Icon` when `Label` is empty
|
||||
* (2021.06.17) Fixed an issue where `maxCache` was set to one more number of actual data
|
||||
* (2021.06.17) Fixed an issue where `TextMeshPro` could not be opened and closed in time to refresh
|
||||
* (2021.06.17) Fixed an issue where `XCharts` always pops up when importing `XCharts`
|
||||
|
||||
## v2.2.1
|
||||
|
||||
* (2021.06.13) Release `v2.2.1` version
|
||||
* (2021.06.13) Improved support for multiple screens
|
||||
* (2021.06.12) Added `iconStyle` `align` parameter to set the horizontal alignment of the icon
|
||||
* (2021.06.12) Improve `Theme` import (#148)
|
||||
* (2021.06.10) Fixed compatibility issues with `Unity` version (#154)
|
||||
* (2021.06.05) Improved Candlestickchart support for inverse (#152)
|
||||
* (2021.06.04) Fixed `Gauge` having an abnormal pointer position when the minimum value is negative (#153)
|
||||
|
||||
## v2.2.0
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
[master](#master)
|
||||
[branch-2.0](#branch-2.0)
|
||||
[v2.6.0](#v2.6.0)
|
||||
[v2.5.0](#v2.5.0)
|
||||
[v2.4.0](#v2.4.0)
|
||||
[v2.3.0](#v2.3.0)
|
||||
[v2.2.3](#v2.2.3)
|
||||
[v2.2.2](#v2.2.2)
|
||||
[v2.2.1](#v2.2.1)
|
||||
[v2.2.0](#v2.2.0)
|
||||
[v2.1.1](#v2.1.1)
|
||||
[v2.1.0](#v2.1.0)
|
||||
@@ -33,11 +40,116 @@
|
||||
[v0.5.0](#v0.5.0)
|
||||
[v0.1.0](#v0.1.0)
|
||||
|
||||
## master
|
||||
## branch-2.0
|
||||
|
||||
## v2.6.0
|
||||
|
||||
* (2021.12.30) 发布`v2.6.0`版本
|
||||
* (2021.12.21) 修复`Emphasis`不生效的问题
|
||||
* (2021.12.17) 修复`MarkLine`在运行时`Label`不自动刷新显示隐藏的问题 #178
|
||||
* (2021.12.10) 完善`Radar`的`AxisLine`和`SplitLine`可单独控制
|
||||
* (2021.12.08) 修复`Serie`隐藏后`Y`轴最大值不刷新的问题
|
||||
* (2021.12.04) 增加`Symbol`新类型:`EmptyRect`,`EmptyTriangle`,`EmptyDiamond`
|
||||
* (2021.12.04) 增加`Symbol`的`Empty`区域颜色可通过`ItemStyle`的`backgroundColor`设置的支持
|
||||
* (2021.12.03) 修复`Formatter`的`{c}`通配符不生效的问题 #175
|
||||
* (2021.12.03) 修复`Axis`的`boundaryGap`某些情况下显示的问题 #174
|
||||
* (2021.11.30) 修复`Serie`的`ignore`某些情况下绘制异常的问题 #173
|
||||
|
||||
## v2.5.0
|
||||
|
||||
* (2021.11.27) 发布`v2.5.0`版本
|
||||
* (2021.11.27) 增加`Tooltip`的`positionFunction`的坐标设置委托函数
|
||||
* (2021.10.29) 移除`XCharts`首次导入时`TextMeshPro`的相关设置
|
||||
* (2021.10.29) 增加`Tooltip`对通配符`{e}`的支持 #170
|
||||
* (2021.09.08) 完善`RadarChart`
|
||||
* (2021.09.07) 修复`PieChart`渐出动画结束时`label`没有消失的问题 #168
|
||||
* (2021.09.06) 修复`GaugeChart`用代码改变`splitNumber`不会刷新`label`的问题 #167
|
||||
|
||||
## v2.4.0
|
||||
|
||||
### 版本要点
|
||||
|
||||
* 折线图支持忽略数据的连线是断开还是连接
|
||||
* 折线图支持轨迹匀速动画
|
||||
* 其他优化和问题修复
|
||||
|
||||
### 日志详情
|
||||
|
||||
* (2021.08.31) 发布`v2.4.0`版本
|
||||
* (2021.08.31) 优化`RingChart`的渐变效果
|
||||
* (2021.08.31) 修复`DataZoom`拖动时`SerieLabel`不刷新的问题 (#165)
|
||||
* (2021.08.25) 修复`Theme`主题切换无法保持到场景上的问题 (#166)
|
||||
* (2021.08.24) 增加`Animation`的`alongWithLinePath`参数设置折线轨迹匀速动画
|
||||
* (2021.08.22) 增加`Serie`的`ignoreLineBreak`参数设置忽略数据连线是否断开 (#164)
|
||||
* (2021.08.22) 修复`Axis`在`DataZoom`开启时`Label`可能不更新的问题 (#164)
|
||||
* (2021.08.15) 优化`Axis`的`AxisLabel`文本旋转设置,避免在DataZoom开启时偏移不一致 (#163)
|
||||
* (2021.08.14) 增加`Legend`的`textAutoColor`设置文本颜色和`Serie`一致 (#163)
|
||||
* (2021.08.12) 优化`BarChart`设置`Corner`时正负柱条圆角对称
|
||||
* (2021.08.03) 优化`Serie`的数据全为0时Y轴不显示的问题
|
||||
* (2021.07.29) 修复`Serie`开启`ignore`时被忽略的数据还会参与计算的问题 (#161)
|
||||
* (2021.07.29) 完善`BarChart`的`Zebra`斑马柱图渐变支持
|
||||
* (2021.07.26) 修复`TextMeshPro Enable`时找不到`XCharts`路径的问题 (#160)
|
||||
|
||||
## v2.3.0
|
||||
|
||||
### 版本要点
|
||||
|
||||
* 数据存储由`float`升级为`double`
|
||||
* 新增`MarkLine`标线
|
||||
* `Serie`下可用`IconStyle`统一配置图标
|
||||
* `Label`支持用代码自定义显示样式
|
||||
* `DataZoom`完善
|
||||
* `PieChart`优化
|
||||
* 问题修复
|
||||
|
||||
### 升级注意
|
||||
|
||||
由于数据类型升级为了`double`,`float`隐式转`double`可能有精度问题,所以建议之前为`float`的数据类型都手动改为`double`类型。
|
||||
|
||||
### 日志详情
|
||||
|
||||
* (2021.07.24) 发布`v2.3.0`版本
|
||||
* (2021.07.22) 完善`SerieSymbol`以支持象形柱图`PictorialBarChart`扩展
|
||||
* (2021.07.19) 修复`WdbGL`平台上`Tooltip`不显示的问题
|
||||
* (2021.07.18) 增加`Serie`的`iconStyle`统一配置图标
|
||||
* (2021.07.15) 增加`MarkLine`标线 (#142)
|
||||
* (2021.07.09) 优化`BarChart`可通过`serieData.show`设置是否显示柱条
|
||||
* (2021.07.08) 优化`data`数据存储类型由`float`全部转为`double`
|
||||
* (2021.07.05) 修复`PieChart`的`avoidLabelOverlap`参数不生效的问题
|
||||
* (2021.07.04) 修复`PieChart`选中扇区后鼠标区域指示不准确的问题
|
||||
* (2021.07.04) 优化`PieChart`的`Label`为`Inside`时可通过参数`Margin`调节偏移
|
||||
* (2021.07.01) 增加`DataZoom`的`supportInsideScroll`和`supportInsideDrag`参数设置坐标系内是否支持滚动和拖拽
|
||||
* (2021.06.27) 增加`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置首尾的`Label`是否显示
|
||||
* (2021.06.27) 增加`AxisLabel`和`SerieLabel`的`formatter`委托方法 (#145)
|
||||
* (2021.06.27) 增加`DataZoom`的`orient`参数设置水平或垂直样式
|
||||
* (2021.06.21) 增加`IconStyle`的`autoHideWhenLabelEmpty`参数设置当`label`为空时是否自动隐藏图标
|
||||
|
||||
## v2.2.3
|
||||
|
||||
* (2021.06.20) 发布`v2.2.3`版本
|
||||
* (2021.06.20) 修复`Axis`的`Icon`默认显示出来的问题
|
||||
|
||||
## v2.2.2
|
||||
|
||||
* (2021.06.18) 发布`v2.2.2`版本
|
||||
* (2021.06.18) 优化`Axis`的`Label`为空时自动隐藏`Icon`
|
||||
* (2021.06.17) 修复`maxCache`设置时实际数据个数多一个的问题
|
||||
* (2021.06.17) 修复`TextMeshPro`的开启和关闭不及时刷新的问题
|
||||
* (2021.06.17) 修复`XCharts`导入时总是弹出`XCharts Importer`的问题
|
||||
|
||||
## v2.2.1
|
||||
|
||||
* (2021.06.13) 发布`v2.2.1`版本
|
||||
* (2021.06.13) 完善对多屏幕的支持
|
||||
* (2021.06.12) 增加`IconStyle`的`align`参数设置图标的水平对齐
|
||||
* (2021.06.12) 完善`Theme`主题导入 (#148)
|
||||
* (2021.06.10) 修复`Unity`版本兼容问题 (#154)
|
||||
* (2021.06.05) 完善`CandlestickChart`对`inverse`的支持 (#152)
|
||||
* (2021.06.04) 修复`Gauge`在最小值为负数时指针指示位置异常的问题 (#153)
|
||||
|
||||
## v2.2.0
|
||||
|
||||
* (2021.05.30) 发布`v2.0.0`版本
|
||||
* (2021.05.30) 发布`v2.2.0`版本
|
||||
* (2021.05.25) 完善`TextStyle`的`alignment`的支持 (#150)
|
||||
* (2021.05.24) 修复`PieChart`数据全为`0`时`Label`无法正常显示的问题
|
||||
* (2021.05.24) 修复`Add Serie`面板上`Serie Name`不生效的问题 (#149)
|
||||
|
||||
@@ -84,8 +84,12 @@
|
||||
* `CoordinateChart.ClearAxisData()`:清除所有x轴和y轴的类目数据。
|
||||
* `CoordinateChart.AddXAxisData(string category, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。
|
||||
* `CoordinateChart.AddYAxisData(string category, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。
|
||||
* `CoordinateChart.AddXAxisIcon(Sprite icon, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。
|
||||
* `CoordinateChart.AddYAxisIcon(Sprite icon, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。。
|
||||
* `CoordinateChart.AddXAxisIcon(Sprite icon, int xAxisIndex = 0)`:添加一个图标到指定的 `X` 轴。
|
||||
* `CoordinateChart.AddYAxisIcon(Sprite icon, int yAxisIndex = 0)`:添加一个图标到指定的 `Y` 轴。
|
||||
* `CoordinateChart.UpdateXAxisData(int index, string category, int xAxisIndex = 0)`:更新 `X` 轴的类目数据。
|
||||
* `CoordinateChart.UpdateYAxisData(int index, string category, int yAxisIndex = 0)`:更新 `Y` 轴的类目数据。
|
||||
* `CoordinateChart.UpdateXAxisIcon(int index, Sprite icon, int xAxisIndex = 0)`:更新 `X` 轴的图标。
|
||||
* `CoordinateChart.UpdateYAxisIcon(int index, Sprite icon, int yAxisIndex = 0)`:更新 `Y` 轴的图标。
|
||||
|
||||
* `CoordinateChart.IsValue()`:是否是纯数值坐标。
|
||||
* `CoordinateChart.RefreshDataZoom()`:在下一帧刷新DataZoom组件。
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
* [LineArrow 折线图箭头](#LineArrow)
|
||||
* [LineStyle 折线图样式](#LineStyle)
|
||||
* [Location 位置](#Location)
|
||||
* [MarkLine 标线](#MarkLine)
|
||||
* [SerieAnimation 动画](#SerieAnimation)
|
||||
* [SerieData 数据项](#SerieData)
|
||||
* [SerieLabel 图形上的文本标签](#SerieLabel)
|
||||
@@ -175,6 +176,9 @@
|
||||
* `ceilRate`:最大最小值向上取整的倍率。默认为0时自动计算。
|
||||
* `splitNumber`:分割段数。默认为 `5`。
|
||||
* `isAxisTooltip`:是否Tooltip显示轴线上的所有数据。只对Mutiple类型的Radar有效。
|
||||
* `outRangeColor`:数值超出范围时显示的颜色。
|
||||
* `connectCenter`:数值是否连线到中心点。
|
||||
* `lineGradient`:数值线段是否渐变。
|
||||
* `splitLine`:分割线条 [AxisSplitLine](#AxisSplitLine)。
|
||||
* `splitArea`:分割区域 [AxisSplitArea](#AxisSplitArea)。
|
||||
* `indicator`:是否显示指示器。
|
||||
@@ -186,6 +190,7 @@
|
||||
* `name`:指示器名称。
|
||||
* `max`:指示器的最大值,默认为 0 无限制。
|
||||
* `min`:指示器的最小值,默认为 0 无限制。
|
||||
* `range`:指示器的正常值范围,当数值超出这个范围时显示`Radar`的`outRangeColor`颜色。
|
||||
* `textStyle`:文本样式 [TextStyle](#TextStyle)。
|
||||
|
||||
## `TextLimit`
|
||||
@@ -228,6 +233,7 @@
|
||||
* `{b}`为当前所指示或`index`为`0`的`serie`的数据项`serieData`的`name`,或者类目值(如折线图的`X`轴)。
|
||||
* `{c}`为当前所指示或`index`为`0`的`serie`的`y`维(`dimesion`为`1`)的数值。
|
||||
* `{d}`为当前所指示或`index`为`0`的`serie`的`y`维(`dimesion`为`1`)百分比值,注意不带`%`号。
|
||||
* `{e}`为当前所指示或`index`为`0`的`serie`的数据项`serieData`的`name`。
|
||||
* `{.1}`表示指定`index`为`1`的`serie`对应颜色的圆点。
|
||||
* `{a1}`、`{b1}`、`{c1}`中的`1`表示指定`index`为`1`的`serie`。
|
||||
* `{c1:2}`表示索引为`1`的`serie`的当前指示数据项的第`3`个数据(一个数据项有多个数据,index为`2`表示第`3`个数据)。
|
||||
@@ -809,6 +815,7 @@ K线图系列。
|
||||
* `fadeOutDuration`:设定的渐出动画时长,单位毫秒。如果要设置单个数据项的渐出时长,可以用代码定制:`customFadeOutDuration`。
|
||||
* `dataChangeEnable`:是否开启数据变更动画。
|
||||
* `dataChangeDuration`:数据变更动画时长,单位毫秒。
|
||||
* `alongWithLinePath`:是否沿着线的轨迹进行匀速动画。
|
||||
|
||||
## `AreaStyle`
|
||||
|
||||
@@ -951,11 +958,33 @@ K线图系列。
|
||||
* `top`:离容器上侧的距离。
|
||||
* `bottom`:离容器下侧的距离。
|
||||
|
||||
## `MarkLine`
|
||||
|
||||
* `show`:是否显示标线。
|
||||
* `animation`:标线的动画样式。
|
||||
* `data`:标线的数据项[MarkLineData](#MarkLineData)列表。当数据项的group为0时,每个数据项表示一条标线;当group不为0时,相同group的两个数据项分别表示标线的起始点和终止点来组成一条标线,此时标线的相关样式参数取起始点的参数。
|
||||
|
||||
## `MarkLineData`
|
||||
|
||||
* `name`:标注名称,将会作为文字显示。label的formatter可通过{b}显示名称,通过{c}显示数值。
|
||||
* `type`:特殊的标注类型,用于标注最大值最小值等。。有以下标注类型:
|
||||
* `None`:无类型。此时通过
|
||||
* `Min`:最小值。`dimension`维度上数据的最小值。
|
||||
* `Max`:最大值。`dimension`维度上数据的最大值。
|
||||
* `Average`:平均值。`dimension`维度上数据的平均值。
|
||||
* `Median`:中位数。`dimension`维度上数据的中位数。
|
||||
* `dimension`:当type为特殊类型时,指示从哪个维度的数据上计算特殊值。
|
||||
* `xPosition`:相对原点的 x 坐标,单位像素。当type为None时有效。
|
||||
* `yPosition`:相对原点的 y 坐标,单位像素。当type为None时有效。
|
||||
* `xValue`:X轴上的指定值。当X轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
|
||||
* `yValue`:Y轴上的指定值。当Y轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
|
||||
|
||||
## `SerieData`
|
||||
|
||||
* `name`:数据项名称。
|
||||
* `selected`:该数据项是否被选中。
|
||||
* `radius`:自定义半径。可用在饼图中自定义某个数据项的半径。
|
||||
* `enableIconStyle`: 是否启用单个数据项的图标设置。
|
||||
* `iconStyle`:数据项图标样式。
|
||||
* `enableLabel`:是否启用单个数据项的标签设置。
|
||||
* `label`:单个数据项的标签设置。
|
||||
|
||||
@@ -96,11 +96,11 @@
|
||||
|
||||
## 锯齿太严重_如何让图表更顺滑
|
||||
|
||||
答:开启抗锯齿设置(在`Unity`里设置)。调整UI渲染模式为`Camera`模式,开启`MSAA`,设置`4`倍或更高抗锯齿。锯齿只能减少难以避免,像素越高锯齿越不明显。
|
||||
答:开启抗锯齿设置(在`Unity`里设置)。调整UI渲染模式为`Camera`模式,开启`MSAA`,设置`4`倍或更高抗锯齿。
|
||||
|
||||
## 为什么鼠标移上图表Tooltip不显示
|
||||
|
||||
答:确认`Tooltip`是否开启。确认父节点是否关闭了鼠标事件。
|
||||
答:确认`Tooltip`是否开启;确认父节点是否关闭了鼠标事件。
|
||||
|
||||
## 如何取消Tooltip的竖线
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ __Sub component:__
|
||||
* [LineArrow](#LineArrow)
|
||||
* [LineStyle](#LineStyle)
|
||||
* [Location](#Location)
|
||||
* [MarkLine](#MarkLine)
|
||||
* [SerieAnimation](#SerieAnimation)
|
||||
* [SerieData](#SerieData)
|
||||
* [SerieLabel](#SerieLabel)
|
||||
@@ -175,7 +176,10 @@ Radar coordinate conponnet for radar charts.
|
||||
* `center`: the center of radar chart. The `center[0]` is the x-coordinate, and the `center[1]` is the y-coordinate. When value between 0 and 1 represents a percentage relative to the chart.[default:[0.5f,0.4f]].
|
||||
* `ceilRate`: The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated.[default:0].
|
||||
* `splitNumber`: Segments of indicator axis.[default:5].
|
||||
* `splitNumber`: Tooltip displays all the data on the axis.[default:false].
|
||||
* `isAxisTooltip`: Tooltip displays all the data on the axis.[default:false].
|
||||
* `outRangeColor`: The color displayed when data out of range.[default:red]
|
||||
* `connectCenter`: Whether serie data connect to radar center with line.[default:false]
|
||||
* `lineGradient`: Whether need gradient for data line..[default:true]
|
||||
* `splitLine`: The split line style of radar [AxisSplitLine](#AxisSplitLine).
|
||||
* `splitArea`: The split area style of radar [AxisSplitArea](#AxisSplitArea).
|
||||
* `indicator`: Whether to show indicator.
|
||||
@@ -189,6 +193,7 @@ Indicator of radar chart, which is used to assign multiple variables(dimensions)
|
||||
* `name`: The name of indicator.
|
||||
* `max`: The maximum value of indicator, with default value of 0, but we recommend to set it manually.
|
||||
* `min`: The minimum value of indicator, with default value of 0.
|
||||
* `min`: Normal range. When the value is outside this range, the display color is automatically changed.
|
||||
* `textStyle`: The text style of indicator [TextStyle](#TextStyle).
|
||||
|
||||
## `TextLimit`
|
||||
@@ -232,6 +237,7 @@ Tooltip component.
|
||||
* `{b}` is the `name` of the `serieData` that is currently indicated or whose `index` is `0`, or a `category` value (such as the X-axis of a line chart).
|
||||
* `{c}` is the value of a Y-dimension (`dimesion` is 1) from the `serie` that is currently indicated or whose `index` is `0`.
|
||||
* `{d}` is the percentage value of Y-dimensions (`dimesion` is 1) from the `serie` that is currently indicated or whose `index` is `0`, with no `%` sign.
|
||||
* `{e}` is the `name` of the `serieData` that is currently indicated or whose `index` is `0`.
|
||||
* `{.1}` represents a dot from serie corresponding color that specifies `index` as `1`.
|
||||
* `1` in `{a1}`, `{b1}`, `{c1}` represents a `serie` that specifies an `index` of `1`.
|
||||
* `{c1:2}` represents the third data from `serie`'s current indication data item indexed to `1` (a data item has multiple data, `index` 2 represents the third data).
|
||||
@@ -845,11 +851,33 @@ K线图系列。
|
||||
* `top`: 离容器上侧的距离。
|
||||
* `bottom`: 离容器下侧的距离。
|
||||
|
||||
## `MarkLine`
|
||||
|
||||
* `show`:是否显示标线。
|
||||
* `animation`:标线的动画样式。
|
||||
* `data`:标线的数据项[MarkLineData](#MarkLineData)列表。当数据项的group为0时,每个数据项表示一条标线;当group不为0时,相同group的两个数据项分别表示标线的起始点和终止点来组成一条标线,此时标线的相关样式参数取起始点的参数。
|
||||
|
||||
## `MarkLineData`
|
||||
|
||||
* `name`:标注名称,将会作为文字显示。label的formatter可通过{b}显示名称,通过{c}显示数值。
|
||||
* `type`:特殊的标注类型,用于标注最大值最小值等。。有以下标注类型:
|
||||
* `None`:无类型。此时通过
|
||||
* `Min`:最小值。`dimension`维度上数据的最小值。
|
||||
* `Max`:最大值。`dimension`维度上数据的最大值。
|
||||
* `Average`:平均值。`dimension`维度上数据的平均值。
|
||||
* `Median`:中位数。`dimension`维度上数据的中位数。
|
||||
* `dimension`:当type为特殊类型时,指示从哪个维度的数据上计算特殊值。
|
||||
* `xPosition`:相对原点的 x 坐标,单位像素。当type为None时有效。
|
||||
* `yPosition`:相对原点的 y 坐标,单位像素。当type为None时有效。
|
||||
* `xValue`:X轴上的指定值。当X轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
|
||||
* `yValue`:Y轴上的指定值。当Y轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
|
||||
|
||||
## `SerieData`
|
||||
|
||||
* `name`: 数据项名称。
|
||||
* `selected`: 该数据项是否被选中。
|
||||
* `radius`: 自定义半径。可用在饼图中自定义某个数据项的半径。
|
||||
* `enableIconStyle`: 是否启用单个数据项的图标设置。
|
||||
* `iconStyle`: 数据项图标样式。
|
||||
* `enableLabel`: 是否启用单个数据项的标签设置。
|
||||
* `label`: 单个数据项的标签设置。
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_DataChangeEnable");
|
||||
PropertyField(prop, "m_DataChangeDuration");
|
||||
PropertyField(prop, "m_ActualDuration");
|
||||
PropertyField(prop, "m_AlongWithLinePath");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,12 @@ namespace XCharts
|
||||
EditorGUI.indentLevel++;
|
||||
PropertyField(prop, isPolar ? "m_PolarIndex" : "m_GridIndex");
|
||||
PropertyField(prop, "m_Type");
|
||||
if (type == Axis.AxisType.Time)
|
||||
{
|
||||
var chartTypeName = prop.serializedObject.targetObject.GetType().Name;
|
||||
if (!chartTypeName.Equals("GanttChart"))
|
||||
EditorGUILayout.HelpBox("The Time axis is currently only supported in GanttChart.", MessageType.Warning);
|
||||
}
|
||||
PropertyField(prop, "m_Position");
|
||||
PropertyField(prop, "m_Offset");
|
||||
if (type == Axis.AxisType.Log)
|
||||
@@ -143,6 +149,8 @@ namespace XCharts
|
||||
PropertyField(prop, "m_NumericFormatter");
|
||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||
PropertyField(prop, "m_OnZero");
|
||||
PropertyField(prop, "m_ShowStartLabel");
|
||||
PropertyField(prop, "m_ShowEndLabel");
|
||||
PropertyField(prop, "m_TextLimit");
|
||||
PropertyField(prop, "m_TextStyle");
|
||||
--EditorGUI.indentLevel;
|
||||
|
||||
@@ -19,12 +19,19 @@ namespace XCharts
|
||||
base.OnGUI(pos, prop, label);
|
||||
if (MakeFoldout(prop, "m_Enable"))
|
||||
{
|
||||
var m_SupportInside = prop.FindPropertyRelative("m_SupportInside");
|
||||
var m_SupportSlider = prop.FindPropertyRelative("m_SupportSlider");
|
||||
var m_Start = prop.FindPropertyRelative("m_Start");
|
||||
var m_End = prop.FindPropertyRelative("m_End");
|
||||
var m_MinShowNum = prop.FindPropertyRelative("m_MinShowNum");
|
||||
++EditorGUI.indentLevel;
|
||||
PropertyField(prop, "m_Orient");
|
||||
PropertyField(prop, "m_SupportInside");
|
||||
if (m_SupportInside.boolValue)
|
||||
{
|
||||
PropertyField(prop, "m_SupportInsideScroll");
|
||||
PropertyField(prop, "m_SupportInsideDrag");
|
||||
}
|
||||
PropertyField(prop, m_SupportSlider);
|
||||
PropertyField(prop, "m_ZoomLock");
|
||||
PropertyField(prop, "m_ScrollSensitivity");
|
||||
|
||||
@@ -22,11 +22,13 @@ namespace XCharts
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
PropertyField(prop, "m_Layer");
|
||||
PropertyField(prop, "m_Align");
|
||||
PropertyField(prop, "m_Sprite");
|
||||
PropertyField(prop, "m_Color");
|
||||
PropertyField(prop, "m_Width");
|
||||
PropertyField(prop, "m_Height");
|
||||
PropertyField(prop, "m_Offset");
|
||||
PropertyField(prop, "m_AutoHideWhenLabelEmpty");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_ItemHeight");
|
||||
PropertyField(prop, "m_ItemGap");
|
||||
PropertyField(prop, "m_ItemAutoColor");
|
||||
PropertyField(prop, "m_TextAutoColor");
|
||||
PropertyField(prop, "m_SelectedMode");
|
||||
PropertyField(prop, "m_Orient");
|
||||
PropertyField(prop, "m_Location");
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -26,6 +25,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_ToColor");
|
||||
PropertyField(prop, "m_ToColor2");
|
||||
PropertyField(prop, "m_Width");
|
||||
PropertyField(prop, "m_Length");
|
||||
PropertyField(prop, "m_Opacity");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
69
Assets/XCharts/Editor/PropertyDrawers/MarkLineDrawer.cs
Normal file
69
Assets/XCharts/Editor/PropertyDrawers/MarkLineDrawer.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(MarkLine), true)]
|
||||
public class MarkLineDrawer : BasePropertyDrawer
|
||||
{
|
||||
public override string ClassName { get { return "MarkLine"; } }
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
base.OnGUI(pos, prop, label);
|
||||
if (MakeFoldout(prop, "m_Show"))
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
PropertyField(prop, "m_Animation");
|
||||
PropertyListField(prop, "m_Data", true);
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(MarkLineData), true)]
|
||||
public class MarkLineDataDrawer : BasePropertyDrawer
|
||||
{
|
||||
public override string ClassName { get { return "MarkLineData"; } }
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
base.OnGUI(pos, prop, label);
|
||||
if (MakeFoldout(prop, ""))
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
var type = (MarkLineType)(prop.FindPropertyRelative("m_Type")).enumValueIndex;
|
||||
var group = prop.FindPropertyRelative("m_Group").intValue;
|
||||
PropertyField(prop, "m_Type");
|
||||
PropertyField(prop, "m_Name");
|
||||
switch (type)
|
||||
{
|
||||
case MarkLineType.None:
|
||||
PropertyField(prop, "m_XPosition");
|
||||
PropertyField(prop, "m_YPosition");
|
||||
PropertyField(prop, "m_XValue");
|
||||
PropertyField(prop, "m_YValue");
|
||||
break;
|
||||
case MarkLineType.Min:
|
||||
case MarkLineType.Max:
|
||||
case MarkLineType.Average:
|
||||
case MarkLineType.Median:
|
||||
PropertyField(prop, "m_Dimension");
|
||||
break;
|
||||
}
|
||||
PropertyField(prop, "m_Group");
|
||||
if (group > 0 && type == MarkLineType.None) PropertyField(prop, "m_ZeroPosition");
|
||||
PropertyField(prop, "m_LineStyle");
|
||||
PropertyField(prop, "m_StartSymbol");
|
||||
PropertyField(prop, "m_EndSymbol");
|
||||
PropertyField(prop, "m_Label");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Editor/PropertyDrawers/MarkLineDrawer.cs.meta
Normal file
11
Assets/XCharts/Editor/PropertyDrawers/MarkLineDrawer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9c530aeba79d40a8918424df421d081
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -28,6 +28,9 @@ namespace XCharts
|
||||
PropertyField(prop, "m_SplitNumber");
|
||||
PropertyField(prop, "m_CeilRate");
|
||||
PropertyField(prop, "m_IsAxisTooltip");
|
||||
PropertyField(prop, "m_OutRangeColor");
|
||||
PropertyField(prop, "m_ConnectCenter");
|
||||
PropertyField(prop, "m_LineGradient");
|
||||
PropertyField(prop, "m_AxisLine");
|
||||
PropertyField(prop, "m_SplitLine");
|
||||
PropertyField(prop, "m_SplitArea");
|
||||
@@ -50,6 +53,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_Name");
|
||||
PropertyField(prop, "m_Min");
|
||||
PropertyField(prop, "m_Max");
|
||||
PropertyTwoFiled(prop, "m_Range");
|
||||
PropertyField(prop, "m_TextStyle");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ namespace XCharts
|
||||
m_DrawRect.y += hig;
|
||||
m_Heights[m_KeyName] += hig;
|
||||
|
||||
PropertyField(prop, "m_Name");
|
||||
PropertyField(prop, "m_InsertDataToHead");
|
||||
PropertyField(prop, "m_Name");
|
||||
switch (serieType)
|
||||
{
|
||||
case SerieType.Line:
|
||||
@@ -68,6 +68,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_Clip");
|
||||
PropertyField(prop, "m_Ignore");
|
||||
PropertyField(prop, "m_IgnoreValue");
|
||||
PropertyField(prop, "m_IgnoreLineBreak");
|
||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||
PropertyField(prop, "m_Large");
|
||||
PropertyField(prop, "m_LargeThreshold");
|
||||
@@ -75,6 +76,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_LineStyle");
|
||||
PropertyField(prop, "m_LineArrow");
|
||||
PropertyField(prop, "m_AreaStyle");
|
||||
PropertyField(prop, "m_MarkLine");
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
PropertyField(prop, "m_Stack");
|
||||
@@ -102,6 +104,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||
PropertyField(prop, "m_Large");
|
||||
PropertyField(prop, "m_LargeThreshold");
|
||||
PropertyField(prop, "m_MarkLine");
|
||||
break;
|
||||
case SerieType.Pie:
|
||||
PropertyField(prop, "m_RoseType");
|
||||
@@ -198,6 +201,7 @@ namespace XCharts
|
||||
break;
|
||||
}
|
||||
PropertyField(prop, "m_ItemStyle");
|
||||
PropertyField(prop, "m_IconStyle");
|
||||
PropertyField(prop, "m_Label");
|
||||
PropertyField(prop, "m_Emphasis");
|
||||
PropertyField(prop, "m_Animation");
|
||||
@@ -398,6 +402,9 @@ namespace XCharts
|
||||
{
|
||||
EditorGUI.indentLevel += 2;
|
||||
var m_Ignore = serieData.FindPropertyRelative("m_Ignore");
|
||||
var m_Selected = serieData.FindPropertyRelative("m_Selected");
|
||||
var m_Id = serieData.FindPropertyRelative("m_Id");
|
||||
var m_EnableIcon = serieData.FindPropertyRelative("m_EnableIconStyle");
|
||||
var m_Icon = serieData.FindPropertyRelative("m_IconStyle");
|
||||
var m_EnableLabel = serieData.FindPropertyRelative("m_EnableLabel");
|
||||
var m_Label = serieData.FindPropertyRelative("m_Label");
|
||||
@@ -409,7 +416,12 @@ namespace XCharts
|
||||
var m_Symbol = serieData.FindPropertyRelative("m_Symbol");
|
||||
EditorGUI.PropertyField(drawRect, m_Ignore);
|
||||
AddHeight(EditorGUI.GetPropertyHeight(m_Ignore));
|
||||
EditorGUI.PropertyField(drawRect, m_Selected);
|
||||
AddHeight(EditorGUI.GetPropertyHeight(m_Selected));
|
||||
EditorGUI.PropertyField(drawRect, m_Id);
|
||||
AddHeight(EditorGUI.GetPropertyHeight(m_Id));
|
||||
EditorGUI.PropertyField(drawRect, m_Icon);
|
||||
ChartEditorHelper.MakeBool(drawRect, m_EnableIcon, 1, "(enable)");
|
||||
AddHeight(EditorGUI.GetPropertyHeight(m_Icon));
|
||||
EditorGUI.PropertyField(drawRect, m_Symbol);
|
||||
ChartEditorHelper.MakeBool(drawRect, m_EnableSymbol, 1, "(enable)");
|
||||
|
||||
@@ -21,19 +21,28 @@ namespace XCharts
|
||||
if (MakeFoldout(prop, "m_Show"))
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
var type = (SerieSymbolType)prop.FindPropertyRelative("m_Type").enumValueIndex;
|
||||
PropertyField(prop, "m_Type");
|
||||
if (type == SerieSymbolType.Custom)
|
||||
{
|
||||
PropertyField(prop, "m_Image");
|
||||
PropertyField(prop, "m_ImageType");
|
||||
PropertyField(prop, "m_Width");
|
||||
// PropertyField(prop, "m_Height");
|
||||
// PropertyField(prop, "m_Offset");
|
||||
}
|
||||
PropertyField(prop, "m_Gap");
|
||||
PropertyField(prop, "m_SizeType");
|
||||
switch ((SerieSymbolSizeType)prop.FindPropertyRelative("m_SizeType").enumValueIndex)
|
||||
{
|
||||
case SerieSymbolSizeType.Custom:
|
||||
PropertyField(prop, "m_Size");
|
||||
PropertyField(prop, "m_SelectedSize");
|
||||
PropertyField(prop, "m_Size");
|
||||
PropertyField(prop, "m_SelectedSize");
|
||||
break;
|
||||
case SerieSymbolSizeType.FromData:
|
||||
PropertyField(prop, "m_DataIndex");
|
||||
PropertyField(prop, "m_DataScale");
|
||||
PropertyField(prop, "m_SelectedDataScale");
|
||||
PropertyField(prop, "m_DataIndex");
|
||||
PropertyField(prop, "m_DataScale");
|
||||
PropertyField(prop, "m_SelectedDataScale");
|
||||
break;
|
||||
case SerieSymbolSizeType.Callback:
|
||||
break;
|
||||
@@ -41,6 +50,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_StartIndex");
|
||||
PropertyField(prop, "m_Interval");
|
||||
PropertyField(prop, "m_ForceShowLast");
|
||||
PropertyField(prop, "m_Repeat");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,6 @@ namespace XCharts
|
||||
btnRect.y = m_DrawRect.y - EditorGUIUtility.singleLineHeight - 3;
|
||||
btnRect.width = btnWidth;
|
||||
var chart = prop.serializedObject.targetObject as BaseChart;
|
||||
var lastFont = chart.theme.font;
|
||||
#if dUI_TextMeshPro
|
||||
var lastTMPFont = chart.theme.tmpFont;
|
||||
#endif
|
||||
if (GUI.Button(btnRect, new GUIContent("Reset", "Reset to theme default color")))
|
||||
{
|
||||
chart.theme.ResetTheme();
|
||||
@@ -60,8 +56,18 @@ namespace XCharts
|
||||
}
|
||||
#if dUI_TextMeshPro
|
||||
PropertyField(prop, "m_TMPFont");
|
||||
if(chart.theme.tmpFont == null && !string.IsNullOrEmpty(chart.theme.tmpFontName))
|
||||
{
|
||||
var msg = string.Format("Can't find theme font asset:{0} in project.", chart.theme.tmpFontName);
|
||||
EditorGUILayout.HelpBox(msg, MessageType.Error);
|
||||
}
|
||||
#else
|
||||
PropertyField(prop, "m_Font");
|
||||
if (chart.theme.font == null && !string.IsNullOrEmpty(chart.theme.fontName))
|
||||
{
|
||||
var msg = string.Format("Can't find theme font asset:{0} in project.", chart.theme.fontName);
|
||||
EditorGUILayout.HelpBox(msg, MessageType.Error);
|
||||
}
|
||||
#endif
|
||||
PropertyField(prop, "m_ContrastColor");
|
||||
PropertyField(prop, "m_BackgroundColor");
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
using UnityEngine;
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -23,6 +31,12 @@ namespace XCharts
|
||||
|
||||
public static void CheckAddedAsset(string assetPath)
|
||||
{
|
||||
var fileName = Path.GetFileName(assetPath);
|
||||
if (fileName.Equals("XChartsSettings.asset"))
|
||||
{
|
||||
XThemeMgr.ReloadThemeList();
|
||||
return;
|
||||
}
|
||||
if (!IsThemeAsset(assetPath)) return;
|
||||
var obj = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
|
||||
if (obj == null || obj.text == null) return;
|
||||
@@ -56,7 +70,8 @@ namespace XCharts
|
||||
private static bool IsThemeAsset(string assetPath)
|
||||
{
|
||||
if (!assetPath.EndsWith(".json")) return false;
|
||||
if (!assetPath.StartsWith("XTheme")) return false;
|
||||
var assetName = Path.GetFileNameWithoutExtension(assetPath);
|
||||
if (!assetName.StartsWith(XChartsSettings.THEME_ASSET_NAME_PREFIX)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
27
Assets/XCharts/Editor/Utility/XChartsBuild.cs
Normal file
27
Assets/XCharts/Editor/Utility/XChartsBuild.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Obsolete]
|
||||
public class XChartsBuild : IPreprocessBuild, IPostprocessBuild
|
||||
{
|
||||
public int callbackOrder { get { return 1; } }
|
||||
|
||||
public void OnPostprocessBuild(BuildTarget target, string path)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPreprocessBuild(BuildTarget target, string path)
|
||||
{
|
||||
XThemeMgr.ExportAllCustomTheme();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Editor/Utility/XChartsBuild.cs.meta
Normal file
11
Assets/XCharts/Editor/Utility/XChartsBuild.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df212e63c528e40fa9e8fffcd868ab7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -70,7 +70,6 @@ namespace XCharts
|
||||
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||
GameObjectUtility.EnsureUniqueNameForSibling(chart);
|
||||
Selection.activeGameObject = chart;
|
||||
EditorUtility.SetDirty(chart);
|
||||
}
|
||||
@@ -166,13 +165,14 @@ namespace XCharts
|
||||
Debug.LogError("TextMeshPro is not in the project, please import TextMeshPro package first.");
|
||||
return;
|
||||
}
|
||||
XChartsMgr.ModifyTMPRefence();
|
||||
XChartsMgr.EnableTextMeshPro();
|
||||
XChartsMgr.ModifyTMPRefence();
|
||||
}
|
||||
|
||||
[MenuItem("XCharts/TextMeshPro Disable")]
|
||||
public static void DisableTextMeshPro()
|
||||
{
|
||||
XChartsMgr.ModifyTMPRefence(true);
|
||||
XChartsMgr.DisableTextMeshPro();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace XCharts.Examples
|
||||
chart.grid.left = 50;
|
||||
chart.grid.top = 80;
|
||||
|
||||
chart.dataZoom.enable = false;
|
||||
chart.dataZooms[0].enable = false;
|
||||
chart.visualMap.enable = false;
|
||||
|
||||
chart.RemoveData();
|
||||
@@ -204,56 +204,56 @@ namespace XCharts.Examples
|
||||
chart.title.subText = "DataZoom 区域缩放:可通过拖、拽、缩小、放大来观察细节数据";
|
||||
chart.grid.bottom = 70;
|
||||
|
||||
chart.dataZoom.enable = true;
|
||||
chart.dataZoom.supportInside = true;
|
||||
chart.dataZoom.supportSlider = true;
|
||||
chart.dataZoom.start = 0;
|
||||
chart.dataZoom.end = 100;
|
||||
chart.dataZooms[0].enable = true;
|
||||
chart.dataZooms[0].supportInside = true;
|
||||
chart.dataZooms[0].supportSlider = true;
|
||||
chart.dataZooms[0].start = 0;
|
||||
chart.dataZooms[0].end = 100;
|
||||
|
||||
chart.RefreshChart();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
chart.dataZoom.supportSlider = !chart.dataZoom.supportSlider;
|
||||
chart.dataZooms[0].supportSlider = !chart.dataZooms[0].supportSlider;
|
||||
chart.RefreshChart();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
chart.dataZoom.supportSlider = true;
|
||||
chart.dataZooms[0].supportSlider = true;
|
||||
chart.RefreshChart();
|
||||
yield return new WaitForSeconds(1f);
|
||||
while (chart.dataZoom.start < 40)
|
||||
while (chart.dataZooms[0].start < 40)
|
||||
{
|
||||
chart.dataZoom.start += speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].start += speed * Time.deltaTime * 0.8f;
|
||||
chart.RefreshDataZoom();
|
||||
chart.RefreshChart();
|
||||
yield return null;
|
||||
}
|
||||
while (chart.dataZoom.end > 60)
|
||||
while (chart.dataZooms[0].end > 60)
|
||||
{
|
||||
chart.dataZoom.end -= speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].end -= speed * Time.deltaTime * 0.8f;
|
||||
chart.RefreshDataZoom();
|
||||
chart.RefreshChart();
|
||||
yield return null;
|
||||
}
|
||||
while (chart.dataZoom.start > 0)
|
||||
while (chart.dataZooms[0].start > 0)
|
||||
{
|
||||
chart.dataZoom.start -= speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZoom.end -= speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].start -= speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].end -= speed * Time.deltaTime * 0.8f;
|
||||
chart.RefreshDataZoom();
|
||||
chart.RefreshChart();
|
||||
yield return null;
|
||||
}
|
||||
while (chart.dataZoom.end < 100)
|
||||
while (chart.dataZooms[0].end < 100)
|
||||
{
|
||||
chart.dataZoom.start += speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZoom.end += speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].start += speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].end += speed * Time.deltaTime * 0.8f;
|
||||
chart.RefreshDataZoom();
|
||||
chart.RefreshChart();
|
||||
yield return null;
|
||||
}
|
||||
while (chart.dataZoom.start > 0 || chart.dataZoom.end < 100)
|
||||
while (chart.dataZooms[0].start > 0 || chart.dataZooms[0].end < 100)
|
||||
{
|
||||
chart.dataZoom.start -= speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZoom.end += speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].start -= speed * Time.deltaTime * 0.8f;
|
||||
chart.dataZooms[0].end += speed * Time.deltaTime * 0.8f;
|
||||
chart.RefreshDataZoom();
|
||||
chart.RefreshChart();
|
||||
yield return null;
|
||||
|
||||
@@ -70,15 +70,15 @@ namespace XCharts.Examples
|
||||
|
||||
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");
|
||||
chart.AddData(0, new List<double> { 10, 20, 60, 40, 20 }, "data1");
|
||||
chart.AddData(0, new List<double> { 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.UpdateData(0, 0, new List<double> { 15, 30, 50, 60, 50 });
|
||||
chart.UpdateDataName(0, 0, "new1");
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
@@ -113,11 +113,11 @@ namespace XCharts.Examples
|
||||
|
||||
serie = chart.AddSerie(SerieType.Radar, "test1");
|
||||
serie.radarIndex = 0;
|
||||
chart.AddData(0, new List<float> { 10, 20, 60, 40, 20 }, "data1");
|
||||
chart.AddData(0, new List<double> { 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");
|
||||
chart.AddData(1, new List<double> { 10, 20, 60, 40, 20 }, "data2");
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace XCharts.Examples
|
||||
{
|
||||
RadarChart chart;
|
||||
int count = 0;
|
||||
float max = 0;
|
||||
double max = 0;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -23,16 +24,14 @@ namespace XCharts.Examples
|
||||
chart.series.SetSerieSymbolSizeCallback(SymbolSize, SymbolSelectedSize);
|
||||
}
|
||||
|
||||
float SymbolSize(List<float> data)
|
||||
float SymbolSize(List<double> data)
|
||||
{
|
||||
//return Mathf.Clamp(data[1] * 10,1,100);
|
||||
return (float)(Mathf.Sqrt(data[2]) / 6e2);
|
||||
return (float)(Math.Sqrt(data[2]) / 6e2);
|
||||
}
|
||||
|
||||
float SymbolSelectedSize(List<float> data)
|
||||
float SymbolSelectedSize(List<double> data)
|
||||
{
|
||||
//return Mathf.Clamp(data[1] * 10,1,100);
|
||||
return (float)(Mathf.Sqrt(data[2]) / 5e2);
|
||||
return (float)(Math.Sqrt(data[2]) / 5e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ namespace XCharts.Examples
|
||||
var rate = Random.Range(0, 101);
|
||||
if (rate > 70) value = Random.Range(8f, 10f);
|
||||
else value = Random.Range(1f, 8f);
|
||||
var list = new List<float> { i, j, value };
|
||||
var list = new List<double> { i, j, value };
|
||||
//至少是一个三位数据:(x,y,value)
|
||||
chart.AddData(0, list);
|
||||
}
|
||||
|
||||
@@ -14,31 +14,33 @@
|
||||
<a href="https://github.com/monitor1394/unity-ugui-XCharts/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/monitor1394/unity-ugui-XCharts">
|
||||
</a>
|
||||
<a href="https://github.com/monitor1394/unity-ugui-XCharts/releases">
|
||||
<img src="https://img.shields.io/github/v/release/monitor1394/unity-ugui-XCharts?include_prereleases">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/languages/code-size/monitor1394/unity-ugui-xcharts">
|
||||
</a>
|
||||
<a href="https://www.npmjs.org/package/unity-ugui-xcharts">
|
||||
<img src="https://img.shields.io/npm/v/unity-ugui-xcharts.svg?label=npm">
|
||||
</a>
|
||||
<a href="https://www.npmjs.org/package/unity-ugui-xcharts">
|
||||
<img src="https://img.shields.io/npm/dt/unity-ugui-xcharts?label=npm%20downloads%20">
|
||||
</a>
|
||||
<a href="https://www.npmjs.org/package/unity-ugui-xcharts">
|
||||
<img src="https://img.shields.io/npm/dm/unity-ugui-xcharts?label=%20">
|
||||
</a>
|
||||
<a href="https://github.com/monitor1394/unity-ugui-XCharts/releases">
|
||||
<img src="https://img.shields.io/github/v/release/monitor1394/unity-ugui-XCharts?include_prereleases&label=github">
|
||||
</a>
|
||||
<a href="https://github.com/monitor1394/unity-ugui-XCharts/releases">
|
||||
<img src="https://img.shields.io/github/downloads/monitor1394/unity-ugui-XCharts/total?label=github%20downloads">
|
||||
<img src="https://img.shields.io/npm/dm/unity-ugui-xcharts?label=npm%20downloads%20">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/badge/Unity-5.6%20%7C%202017%20%7C%202018%20%7C%202019%20%7C%202020%20%7C%202021-green">
|
||||
<img src="https://img.shields.io/badge/Unity-5.6+-green">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/badge/TextMeshPro-YES-green">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/stars/monitor1394/unity-ugui-XCharts?style=social">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/forks/monitor1394/unity-ugui-XCharts?style=social">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/issues-closed/monitor1394/unity-ugui-XCharts?color=green&label=%20%20%20%20issues&logoColor=green&style=social">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
A powerful, easy-to-use, configurable charting and data visualization library for Unity. Supporting line, bar, pie, radar, scatter, heatmap, gauge, ring, polar, liquid and other common chart.
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace XCharts
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
public virtual void RemoveData(string serieName)
|
||||
{
|
||||
m_Series.Remove(serieName);
|
||||
m_Series.RemoveSerie(serieName);
|
||||
foreach (var legend in m_Legends) legend.RemoveData(serieName);
|
||||
m_SerieLabelRoot = null;
|
||||
RefreshChart();
|
||||
@@ -220,6 +220,11 @@ namespace XCharts
|
||||
return AddSerie(type, serieName, show, addToHead);
|
||||
}
|
||||
|
||||
public virtual Serie InsertSerie(int index, SerieType serieType, string serieName = null, bool show = true)
|
||||
{
|
||||
return m_Series.InsertSerie(index, serieType, serieName, show);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// If serieName doesn't exist in legend,will be add to legend.
|
||||
@@ -229,7 +234,7 @@ namespace XCharts
|
||||
/// <param name="data">the data to add</param>
|
||||
/// <param name="dataName">the name of data</param>
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual SerieData AddData(string serieName, float data, string dataName = null)
|
||||
public virtual SerieData AddData(string serieName, double data, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddData(serieName, data, dataName);
|
||||
if (serieData != null)
|
||||
@@ -252,7 +257,7 @@ namespace XCharts
|
||||
/// <param name="data">the data to add</param>
|
||||
/// <param name="dataName">the name of data</param>
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual SerieData AddData(int serieIndex, float data, string dataName = null)
|
||||
public virtual SerieData AddData(int serieIndex, double data, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddData(serieIndex, data, dataName);
|
||||
if (serieData != null)
|
||||
@@ -275,7 +280,7 @@ namespace XCharts
|
||||
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
||||
/// <param name="dataName">the name of data</param>
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual SerieData AddData(string serieName, List<float> multidimensionalData, string dataName = null)
|
||||
public virtual SerieData AddData(string serieName, List<double> multidimensionalData, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddData(serieName, multidimensionalData, dataName);
|
||||
if (serieData != null)
|
||||
@@ -298,7 +303,7 @@ namespace XCharts
|
||||
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
||||
/// <param name="dataName">the name of data</param>
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual SerieData AddData(int serieIndex, List<float> multidimensionalData, string dataName = null)
|
||||
public virtual SerieData AddData(int serieIndex, List<double> multidimensionalData, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddData(serieIndex, multidimensionalData, dataName);
|
||||
if (serieData != null)
|
||||
@@ -322,7 +327,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 = null)
|
||||
public virtual SerieData AddData(string serieName, double xValue, double yValue, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddXYData(serieName, xValue, yValue, dataName);
|
||||
if (serieData != null)
|
||||
@@ -346,7 +351,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(int serieIndex, float xValue, float yValue, string dataName = null)
|
||||
public virtual SerieData AddData(int serieIndex, double xValue, double yValue, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddXYData(serieIndex, xValue, yValue, dataName);
|
||||
if (serieData != null)
|
||||
@@ -360,7 +365,7 @@ namespace XCharts
|
||||
}
|
||||
return serieData;
|
||||
}
|
||||
public virtual SerieData AddData(int serieIndex, float open, float close, float lowest, float heighest, string dataName = null)
|
||||
public virtual SerieData AddData(int serieIndex, double open, double close, double lowest, double heighest, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddData(serieIndex, open, close, lowest, heighest, dataName);
|
||||
if (serieData != null)
|
||||
@@ -382,7 +387,7 @@ namespace XCharts
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="dataIndex">the index of data</param>
|
||||
/// <param name="value">the data will be update</param>
|
||||
public virtual bool UpdateData(string serieName, int dataIndex, float value)
|
||||
public virtual bool UpdateData(string serieName, int dataIndex, double value)
|
||||
{
|
||||
if (m_Series.UpdateData(serieName, dataIndex, value))
|
||||
{
|
||||
@@ -399,7 +404,7 @@ namespace XCharts
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="dataIndex">the index of data</param>
|
||||
/// <param name="value">the data will be update</param>
|
||||
public virtual bool UpdateData(int serieIndex, int dataIndex, float value)
|
||||
public virtual bool UpdateData(int serieIndex, int dataIndex, double value)
|
||||
{
|
||||
if (m_Series.UpdateData(serieIndex, dataIndex, value))
|
||||
{
|
||||
@@ -415,7 +420,7 @@ namespace XCharts
|
||||
/// <param name="serieName"></param>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="multidimensionalData">一个数据项的多维数据列表,而不是多个数据项的数据</param>
|
||||
public virtual bool UpdateData(string serieName, int dataIndex, List<float> multidimensionalData)
|
||||
public virtual bool UpdateData(string serieName, int dataIndex, List<double> multidimensionalData)
|
||||
{
|
||||
if (m_Series.UpdateData(serieName, dataIndex, multidimensionalData))
|
||||
{
|
||||
@@ -431,7 +436,7 @@ namespace XCharts
|
||||
/// <param name="serieIndex"></param>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="multidimensionalData">一个数据项的多维数据列表,而不是多个数据项的数据</param>
|
||||
public virtual bool UpdateData(int serieIndex, int dataIndex, List<float> multidimensionalData)
|
||||
public virtual bool UpdateData(int serieIndex, int dataIndex, List<double> multidimensionalData)
|
||||
{
|
||||
if (m_Series.UpdateData(serieIndex, dataIndex, multidimensionalData))
|
||||
{
|
||||
@@ -448,7 +453,7 @@ namespace XCharts
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="dimension">指定维数,从0开始</param>
|
||||
/// <param name="value"></param>
|
||||
public virtual bool UpdateData(string serieName, int dataIndex, int dimension, float value)
|
||||
public virtual bool UpdateData(string serieName, int dataIndex, int dimension, double value)
|
||||
{
|
||||
if (m_Series.UpdateData(serieName, dataIndex, dimension, value))
|
||||
{
|
||||
@@ -465,7 +470,7 @@ namespace XCharts
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="dimension">指定维数,从0开始</param>
|
||||
/// <param name="value"></param>
|
||||
public virtual bool UpdateData(int serieIndex, int dataIndex, int dimension, float value)
|
||||
public virtual bool UpdateData(int serieIndex, int dataIndex, int dimension, double value)
|
||||
{
|
||||
if (m_Series.UpdateData(serieIndex, dataIndex, dimension, value))
|
||||
{
|
||||
@@ -538,7 +543,7 @@ namespace XCharts
|
||||
foreach (var legend in m_Legends)
|
||||
{
|
||||
var iconColor = LegendHelper.GetIconColor(this, legendIndex, legendName, active);
|
||||
var contentColor = LegendHelper.GetContentColor(legend, m_Theme, active);
|
||||
var contentColor = LegendHelper.GetContentColor(legendIndex, legend, m_Theme, active);
|
||||
legend.UpdateButtonColor(legendName, iconColor);
|
||||
legend.UpdateContentColor(legendName, contentColor);
|
||||
}
|
||||
@@ -637,6 +642,10 @@ namespace XCharts
|
||||
public void UpdateTheme(ChartTheme theme)
|
||||
{
|
||||
m_Theme.CopyTheme(theme);
|
||||
SetAllComponentDirty();
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -646,7 +655,7 @@ namespace XCharts
|
||||
/// <param name="flag"></param>
|
||||
public void AnimationEnable(bool flag)
|
||||
{
|
||||
m_Series.AnimationEnable(flag);
|
||||
foreach (var serie in m_Series.list) serie.AnimationEnable(flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -655,8 +664,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void AnimationFadeIn()
|
||||
{
|
||||
m_Series.AnimationFadeIn();
|
||||
RefreshChart();
|
||||
foreach (var serie in m_Series.list) serie.AnimationFadeIn();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -665,8 +673,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void AnimationFadeOut()
|
||||
{
|
||||
m_Series.AnimationFadeOut();
|
||||
RefreshChart();
|
||||
foreach (var serie in m_Series.list) serie.AnimationFadeOut();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -675,8 +682,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void AnimationPause()
|
||||
{
|
||||
m_Series.AnimationPause();
|
||||
RefreshChart();
|
||||
foreach (var serie in m_Series.list) serie.AnimationPause();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -685,8 +691,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void AnimationResume()
|
||||
{
|
||||
m_Series.AnimationResume();
|
||||
RefreshChart();
|
||||
foreach (var serie in m_Series.list) serie.AnimationResume();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -695,8 +700,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void AnimationReset()
|
||||
{
|
||||
m_Series.AnimationReset();
|
||||
RefreshChart();
|
||||
foreach (var serie in m_Series.list) serie.AnimationReset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -166,6 +166,11 @@ namespace XCharts
|
||||
|
||||
public bool ScreenPointToChartPoint(Vector2 screenPoint, out Vector2 chartPoint)
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
|
||||
var relative = Display.RelativeMouseAt(screenPoint);
|
||||
if(relative != Vector3.zero)
|
||||
screenPoint = relative;
|
||||
#endif
|
||||
var cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
screenPoint, cam, out chartPoint))
|
||||
|
||||
@@ -107,6 +107,22 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update category data.
|
||||
/// 更新X轴类目数据。
|
||||
/// </summary>
|
||||
/// <param name="index">the index of category data</param>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="xAxisIndex">which xAxis index to update to</param>
|
||||
public void UpdateXAxisData(int index, string category, int xAxisIndex = 0)
|
||||
{
|
||||
var xAxis = GetXAxis(xAxisIndex);
|
||||
if (xAxis != null)
|
||||
{
|
||||
xAxis.UpdateData(index, category);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an icon to xAxis.
|
||||
/// 添加一个图标到指定的x轴。
|
||||
@@ -122,6 +138,22 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update xAxis icon.
|
||||
/// 更新X轴图标。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="xAxisIndex"></param>
|
||||
public void UdpateXAxisIcon(int index, Sprite icon, int xAxisIndex = 0)
|
||||
{
|
||||
var xAxis = GetXAxis(xAxisIndex);
|
||||
if (xAxis != null)
|
||||
{
|
||||
xAxis.UpdateIcon(index, icon);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a category data to yAxis.
|
||||
/// 添加一个类目数据到指定的y轴。
|
||||
@@ -137,6 +169,22 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update category data.
|
||||
/// 更新Y轴类目数据。
|
||||
/// </summary>
|
||||
/// <param name="index">the index of category data</param>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="yAxisIndex">which yAxis index to update to</param>
|
||||
public void UpdateYAxisData(int index, string category, int yAxisIndex = 0)
|
||||
{
|
||||
var yAxis = GetYAxis(yAxisIndex);
|
||||
if (yAxis != null)
|
||||
{
|
||||
yAxis.UpdateData(index, category);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an icon to yAxis.
|
||||
/// 添加一个图标到指定的y轴。
|
||||
@@ -152,6 +200,21 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新Y轴图标。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="yAxisIndex"></param>
|
||||
public void UpdateYAxisIcon(int index, Sprite icon, int yAxisIndex = 0)
|
||||
{
|
||||
var yAxis = GetYAxis(yAxisIndex);
|
||||
if (yAxis != null)
|
||||
{
|
||||
yAxis.UpdateIcon(index, icon);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reutrn true when all the show axis is `Value` type.
|
||||
/// 纯数值坐标轴(数值轴或对数轴)。
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace XCharts
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public bool UpdateMax(int serieIndex, int dataIndex, float value)
|
||||
public bool UpdateMax(int serieIndex, int dataIndex, double value)
|
||||
{
|
||||
var serie = m_Series.GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
@@ -32,7 +32,7 @@ namespace XCharts
|
||||
/// <param name="serieIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public bool UpdateMax(int serieIndex, float value)
|
||||
public bool UpdateMax(int serieIndex, double value)
|
||||
{
|
||||
var serie = m_Series.GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
@@ -52,7 +52,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public bool UpdateMax(float value)
|
||||
public bool UpdateMax(double value)
|
||||
{
|
||||
return UpdateMax(0, 0, value);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace XCharts
|
||||
/// <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)
|
||||
public override SerieData AddData(string serieName, double value, double max, string dataName = null)
|
||||
{
|
||||
return base.AddData(serieName, value, max, dataName);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace XCharts
|
||||
/// <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)
|
||||
public override SerieData AddData(int serieIndex, double value, double max, string dataName = null)
|
||||
{
|
||||
return base.AddData(serieIndex, value, max, dataName);
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ namespace XCharts
|
||||
/// the current minimun value.
|
||||
/// 当前最小值。
|
||||
/// </summary>
|
||||
public float runtimeMinValue
|
||||
public double runtimeMinValue
|
||||
{
|
||||
get { return m_RuntimeMinValue; }
|
||||
internal set
|
||||
@@ -412,7 +412,7 @@ namespace XCharts
|
||||
/// the current maximum value.
|
||||
/// 当前最大值。
|
||||
/// </summary>
|
||||
public float runtimeMaxValue
|
||||
public double runtimeMaxValue
|
||||
{
|
||||
get { return m_RuntimeMaxValue; }
|
||||
internal set
|
||||
@@ -433,8 +433,8 @@ 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); } }
|
||||
public int runtimeMinLogIndex { get { return logBaseE ? (int)Math.Log(runtimeMinValue) : (int)Math.Log(runtimeMinValue, logBase); } }
|
||||
public int runtimeMaxLogIndex { get { return logBaseE ? (int)Math.Log(runtimeMaxValue) : (int)Math.Log(runtimeMaxValue, logBase); } }
|
||||
public bool runtimeLastCheckInverse { get; set; }
|
||||
public double runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } }
|
||||
public List<string> runtimeData { get { return m_RuntimeData; } }
|
||||
@@ -447,12 +447,12 @@ namespace XCharts
|
||||
private GameObject m_TooltipLabel;
|
||||
private ChartText m_TooltipLabelText;
|
||||
private RectTransform m_TooltipLabelRect;
|
||||
private float m_RuntimeMinValue;
|
||||
private float m_RuntimeLastMinValue;
|
||||
private double m_RuntimeMinValue;
|
||||
private double m_RuntimeLastMinValue;
|
||||
private bool m_RuntimeMinValueChanged;
|
||||
private float m_RuntimeMinValueUpdateTime;
|
||||
private float m_RuntimeMaxValue;
|
||||
private float m_RuntimeLastMaxValue;
|
||||
private double m_RuntimeMaxValue;
|
||||
private double m_RuntimeLastMaxValue;
|
||||
private bool m_RuntimeMaxValueChanged;
|
||||
private float m_RuntimeMaxValueUpdateTime;
|
||||
private bool m_RuntimeMinValueFirstChanged = true;
|
||||
@@ -489,6 +489,12 @@ namespace XCharts
|
||||
return axis;
|
||||
}
|
||||
|
||||
public override void SetComponentDirty()
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
base.SetComponentDirty();
|
||||
}
|
||||
|
||||
public void Copy(Axis axis)
|
||||
{
|
||||
show = axis.show;
|
||||
@@ -562,6 +568,11 @@ namespace XCharts
|
||||
return type == AxisType.Time;
|
||||
}
|
||||
|
||||
public void SetNeedUpdateFilterData()
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个类目到类目数据列表
|
||||
/// </summary>
|
||||
@@ -570,7 +581,7 @@ namespace XCharts
|
||||
{
|
||||
if (maxCache > 0)
|
||||
{
|
||||
while (m_Data.Count > maxCache)
|
||||
while (m_Data.Count >= maxCache)
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
m_Data.RemoveAt(m_InsertDataToHead ? m_Data.Count - 1 : 0);
|
||||
@@ -581,6 +592,24 @@ namespace XCharts
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新类目数据
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="category"></param>
|
||||
public void UpdateData(int index, string category)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
m_Data[index] = category;
|
||||
SetComponentDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加图标
|
||||
/// </summary>
|
||||
/// <param name="icon"></param>
|
||||
public void AddIcon(Sprite icon)
|
||||
{
|
||||
if (maxCache > 0)
|
||||
@@ -595,6 +624,20 @@ namespace XCharts
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新图标
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="icon"></param>
|
||||
public void UpdateIcon(int index, Sprite icon)
|
||||
{
|
||||
if (index >= 0 && index < m_Icons.Count)
|
||||
{
|
||||
m_Icons[index] = icon;
|
||||
SetComponentDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定索引的类目数据
|
||||
/// </summary>
|
||||
@@ -663,37 +706,43 @@ namespace XCharts
|
||||
{
|
||||
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxis(this))
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (endIndex < startIndex) endIndex = startIndex;
|
||||
if (startIndex != filterStart || endIndex != filterEnd || dataZoom.minShowNum != filterMinShow || m_NeedUpdateFilterData)
|
||||
var data = GetDataList();
|
||||
var range = Mathf.RoundToInt(data.Count * (dataZoom.end - dataZoom.start) / 100);
|
||||
if (range <= 0) range = 1;
|
||||
int start = 0, end = 0;
|
||||
if (dataZoom.runtimeInvert)
|
||||
{
|
||||
filterStart = startIndex;
|
||||
filterEnd = endIndex;
|
||||
end = Mathf.CeilToInt(data.Count * dataZoom.end / 100);
|
||||
start = end - range;
|
||||
if (start < 0) start = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = Mathf.FloorToInt(data.Count * dataZoom.start / 100);
|
||||
end = start + range;
|
||||
if (end > data.Count) end = data.Count;
|
||||
}
|
||||
if (start != filterStart || end != filterEnd || dataZoom.minShowNum != filterMinShow || m_NeedUpdateFilterData)
|
||||
{
|
||||
filterStart = start;
|
||||
filterEnd = end;
|
||||
filterMinShow = dataZoom.minShowNum;
|
||||
m_NeedUpdateFilterData = false;
|
||||
var data = GetDataList();
|
||||
if (data.Count > 0)
|
||||
{
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (count < dataZoom.minShowNum)
|
||||
if (range < dataZoom.minShowNum)
|
||||
{
|
||||
if (dataZoom.minShowNum > data.Count) count = data.Count;
|
||||
else count = dataZoom.minShowNum;
|
||||
if (dataZoom.minShowNum > data.Count) range = data.Count;
|
||||
else range = dataZoom.minShowNum;
|
||||
}
|
||||
if (startIndex + count > data.Count)
|
||||
{
|
||||
int start = endIndex - count;
|
||||
filterData = data.GetRange(start < 0 ? 0 : start, count);
|
||||
}
|
||||
else filterData = data.GetRange(startIndex, count);
|
||||
filterData = data.GetRange(start, range);
|
||||
}
|
||||
else
|
||||
{
|
||||
filterData = data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
else if (end == 0)
|
||||
{
|
||||
filterData = emptyFliter;
|
||||
}
|
||||
@@ -766,7 +815,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpdateMinValue(float value, bool check)
|
||||
internal void UpdateMinValue(double value, bool check)
|
||||
{
|
||||
if (value != m_RuntimeMaxValue)
|
||||
{
|
||||
@@ -794,7 +843,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpdateMaxValue(float value, bool check)
|
||||
internal void UpdateMaxValue(double value, bool check)
|
||||
{
|
||||
if (value != m_RuntimeMaxValue)
|
||||
{
|
||||
@@ -822,7 +871,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float GetCurrMinValue(float duration)
|
||||
public double GetCurrMinValue(float duration)
|
||||
{
|
||||
if (!Application.isPlaying) return m_RuntimeMinValue;
|
||||
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
|
||||
@@ -832,7 +881,7 @@ namespace XCharts
|
||||
var total = duration / 1000;
|
||||
if (duration > 0 && time <= total)
|
||||
{
|
||||
var curr = Mathf.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total);
|
||||
var curr = MathUtil.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total);
|
||||
return curr;
|
||||
}
|
||||
else
|
||||
@@ -842,7 +891,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float GetCurrMaxValue(float duration)
|
||||
public double GetCurrMaxValue(float duration)
|
||||
{
|
||||
if (!Application.isPlaying) return m_RuntimeMaxValue;
|
||||
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
|
||||
@@ -852,7 +901,7 @@ namespace XCharts
|
||||
var total = duration / 1000;
|
||||
if (duration > 0 && time < total)
|
||||
{
|
||||
var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
|
||||
var curr = MathUtil.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
|
||||
return curr;
|
||||
}
|
||||
else
|
||||
@@ -875,10 +924,10 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLogValue(float value)
|
||||
public float GetLogValue(double value)
|
||||
{
|
||||
if (value <= 0 || value == 1) return 0;
|
||||
return logBaseE ? Mathf.Log(value) : Mathf.Log(value, logBase);
|
||||
return logBaseE ? (float)Math.Log(value) : (float)Math.Log(value, logBase);
|
||||
}
|
||||
|
||||
public bool IsLeft()
|
||||
|
||||
@@ -74,6 +74,8 @@ namespace XCharts
|
||||
[SerializeField] private List<int> m_XAxisIndexs = new List<int>() { 0 };
|
||||
[SerializeField] private List<int> m_YAxisIndexs = new List<int>() { };
|
||||
[SerializeField] private bool m_SupportInside;
|
||||
[SerializeField] private bool m_SupportInsideScroll = true;
|
||||
[SerializeField] private bool m_SupportInsideDrag = true;
|
||||
[SerializeField] private bool m_SupportSlider;
|
||||
[SerializeField] private bool m_SupportSelect;
|
||||
[SerializeField] private bool m_ShowDataShadow;
|
||||
@@ -96,6 +98,7 @@ namespace XCharts
|
||||
[SerializeField] private int m_MinShowNum = 1;
|
||||
[Range(1f, 20f)]
|
||||
[SerializeField] private float m_ScrollSensitivity = 1.1f;
|
||||
[SerializeField] private Orient m_Orient = Orient.Horizonal;
|
||||
[SerializeField] private TextStyle m_TextStyle;
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid);
|
||||
[SerializeField] private AreaStyle m_AreaStyle = new AreaStyle();
|
||||
@@ -149,6 +152,22 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_SupportInside, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否支持坐标系内滚动
|
||||
/// </summary>
|
||||
public bool supportInsideScroll
|
||||
{
|
||||
get { return m_SupportInsideScroll; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_SupportInsideScroll, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否支持坐标系内拖拽
|
||||
/// </summary>
|
||||
public bool supportInsideDrag
|
||||
{
|
||||
get { return m_SupportInsideDrag; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_SupportInsideDrag, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether a slider is supported. There are separate sliders on which the user zooms or roams.
|
||||
/// 是否支持滑动条。有单独的滑动条,用户在滑动条上进行缩放或漫游。
|
||||
/// </summary>
|
||||
@@ -332,6 +351,18 @@ namespace XCharts
|
||||
get { return m_ScrollSensitivity; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ScrollSensitivity, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify whether the layout of dataZoom component is horizontal or vertical. What's more,
|
||||
/// it indicates whether the horizontal axis or vertical axis is controlled by default in catesian coordinate system.
|
||||
/// 布局方式是横还是竖。不仅是布局方式,对于直角坐标系而言,也决定了,缺省情况控制横向数轴还是纵向数轴。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Orient orient
|
||||
{
|
||||
get { return m_Orient; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// font style.
|
||||
/// 文字格式。
|
||||
@@ -369,16 +400,17 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 运行时实际范围的开始值
|
||||
/// </summary>
|
||||
public float runtimeStartValue { get; internal set; }
|
||||
public double runtimeStartValue { get; internal set; }
|
||||
/// <summary>
|
||||
/// 运行时实际范围的结束值
|
||||
/// </summary>
|
||||
public float runtimeEndValue { get; internal set; }
|
||||
public double runtimeEndValue { get; internal set; }
|
||||
public bool runtimeInvert { get; set; }
|
||||
|
||||
class AxisIndexValueInfo
|
||||
{
|
||||
public float min;
|
||||
public float max;
|
||||
public double min;
|
||||
public double max;
|
||||
}
|
||||
private Dictionary<int, AxisIndexValueInfo> m_XAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
|
||||
private Dictionary<int, AxisIndexValueInfo> m_YAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
|
||||
@@ -415,6 +447,7 @@ namespace XCharts
|
||||
rangeMode = RangeMode.Percent,
|
||||
start = 30,
|
||||
end = 70,
|
||||
m_Orient = Orient.Horizonal,
|
||||
m_ScrollSensitivity = 10,
|
||||
m_TextStyle = new TextStyle(),
|
||||
m_LineStyle = new LineStyle(LineStyle.Type.Solid)
|
||||
@@ -444,22 +477,44 @@ namespace XCharts
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给定的坐标是否在选中区域内
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <param name="startX"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsInSelectedZoom(Vector2 pos)
|
||||
{
|
||||
var start = runtimeX + runtimeWidth * m_Start / 100;
|
||||
var end = runtimeX + runtimeWidth * m_End / 100;
|
||||
Rect rect = Rect.MinMaxRect(start, runtimeY, end, runtimeY + runtimeHeight);
|
||||
return rect.Contains(pos);
|
||||
switch (m_Orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
var start = runtimeX + runtimeWidth * m_Start / 100;
|
||||
var end = runtimeX + runtimeWidth * m_End / 100;
|
||||
return ChartHelper.IsInRect(pos, start, end, runtimeY, runtimeY + runtimeHeight);
|
||||
case Orient.Vertical:
|
||||
start = runtimeY + runtimeHeight * m_Start / 100;
|
||||
end = runtimeY + runtimeHeight * m_End / 100;
|
||||
return ChartHelper.IsInRect(pos, runtimeX, runtimeX + runtimeWidth, start, end);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsInSelectedZoom(int totalIndex, int index, bool invert)
|
||||
{
|
||||
if (totalIndex <= 0) return false;
|
||||
var tstart = invert ? 100 - end : start;
|
||||
var tend = invert ? 100 - start : end;
|
||||
var range = Mathf.RoundToInt(totalIndex * (tend - tstart) / 100);
|
||||
var min = Mathf.FloorToInt(totalIndex * tstart / 100);
|
||||
var max = Mathf.CeilToInt(totalIndex * tend / 100);
|
||||
if (min == 0) max = min + range;
|
||||
if (max == totalIndex) min = max - range;
|
||||
var flag = index >= min && index < min + range;
|
||||
//Debug.LogError("check:" + index + "," + totalIndex + "," + range + "," + min + "," + max + "," + flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -471,9 +526,16 @@ namespace XCharts
|
||||
/// <returns></returns>
|
||||
public bool IsInStartZoom(Vector2 pos)
|
||||
{
|
||||
var start = runtimeX + runtimeWidth * m_Start / 100;
|
||||
Rect rect = Rect.MinMaxRect(start - 10, runtimeY, start + 10, runtimeY + runtimeHeight);
|
||||
return rect.Contains(pos);
|
||||
switch (m_Orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
var start = runtimeX + runtimeWidth * m_Start / 100;
|
||||
return ChartHelper.IsInRect(pos, start - 10, start + 10, runtimeY, runtimeY + runtimeHeight);
|
||||
case Orient.Vertical:
|
||||
start = runtimeY + runtimeHeight * m_Start / 100;
|
||||
return ChartHelper.IsInRect(pos, runtimeX, runtimeX + runtimeWidth, start - 10, start + 10);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -485,14 +547,23 @@ namespace XCharts
|
||||
/// <returns></returns>
|
||||
public bool IsInEndZoom(Vector2 pos)
|
||||
{
|
||||
var end = runtimeX + runtimeWidth * m_End / 100;
|
||||
Rect rect = Rect.MinMaxRect(end - 10, runtimeY, end + 10, runtimeY + runtimeHeight);
|
||||
return rect.Contains(pos);
|
||||
switch (m_Orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
var end = runtimeX + runtimeWidth * m_End / 100;
|
||||
return ChartHelper.IsInRect(pos, end - 10, end + 10, runtimeY, runtimeY + runtimeHeight);
|
||||
case Orient.Vertical:
|
||||
end = runtimeY + runtimeHeight * m_End / 100;
|
||||
return ChartHelper.IsInRect(pos, runtimeX, runtimeX + runtimeWidth, end - 10, end + 10);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsContainsAxis(Axis axis)
|
||||
{
|
||||
if (axis is XAxis) return xAxisIndexs.Contains(axis.index);
|
||||
if (axis == null) return false;
|
||||
else if (axis is XAxis) return xAxisIndexs.Contains(axis.index);
|
||||
else if (axis is YAxis) return yAxisIndexs.Contains(axis.index);
|
||||
else return false;
|
||||
}
|
||||
@@ -589,7 +660,7 @@ namespace XCharts
|
||||
runtimeHeight = chartHeight - runtimeTop - runtimeBottom;
|
||||
}
|
||||
|
||||
internal void SetXAxisIndexValueInfo(int xAxisIndex, float min, float max)
|
||||
internal void SetXAxisIndexValueInfo(int xAxisIndex, double min, double max)
|
||||
{
|
||||
if (!m_XAxisIndexInfos.ContainsKey(xAxisIndex))
|
||||
{
|
||||
@@ -606,7 +677,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetYAxisIndexValueInfo(int yAxisIndex, float min, float max)
|
||||
internal void SetYAxisIndexValueInfo(int yAxisIndex, double min, double max)
|
||||
{
|
||||
if (!m_YAxisIndexInfos.ContainsKey(yAxisIndex))
|
||||
{
|
||||
@@ -633,7 +704,7 @@ namespace XCharts
|
||||
return m_YAxisIndexInfos.ContainsKey(axisIndex);
|
||||
}
|
||||
|
||||
internal void GetXAxisIndexValue(int axisIndex, out float min, out float max)
|
||||
internal void GetXAxisIndexValue(int axisIndex, out double min, out double max)
|
||||
{
|
||||
min = 0;
|
||||
max = 0;
|
||||
@@ -644,7 +715,7 @@ namespace XCharts
|
||||
max = info.max;
|
||||
}
|
||||
}
|
||||
internal void GetYAxisIndexValue(int axisIndex, out float min, out float max)
|
||||
internal void GetYAxisIndexValue(int axisIndex, out double min, out double max)
|
||||
{
|
||||
min = 0;
|
||||
max = 0;
|
||||
@@ -693,7 +764,15 @@ namespace XCharts
|
||||
if (chart == null) return;
|
||||
foreach (var dataZoom in chart.dataZooms)
|
||||
{
|
||||
DrawDataZoomSlider(vh, dataZoom);
|
||||
switch (dataZoom.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
DrawHorizonalDataZoomSlider(vh, dataZoom);
|
||||
break;
|
||||
case Orient.Vertical:
|
||||
DrawVerticalDataZoomSlider(vh, dataZoom);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,7 +789,7 @@ namespace XCharts
|
||||
{
|
||||
if (!dataZoom.enable) continue;
|
||||
var grid = chart.GetDataZoomGridOrDefault(dataZoom);
|
||||
if (dataZoom.supportInside)
|
||||
if (dataZoom.supportInside && dataZoom.supportInsideDrag)
|
||||
{
|
||||
if (chart.IsInGrid(grid, pos))
|
||||
{
|
||||
@@ -719,13 +798,20 @@ namespace XCharts
|
||||
}
|
||||
if (dataZoom.supportSlider)
|
||||
{
|
||||
if (dataZoom.IsInStartZoom(pos))
|
||||
if (!dataZoom.zoomLock)
|
||||
{
|
||||
dataZoom.runtimeStartDrag = true;
|
||||
}
|
||||
else if (dataZoom.IsInEndZoom(pos))
|
||||
{
|
||||
dataZoom.runtimeEndDrag = true;
|
||||
if (dataZoom.IsInStartZoom(pos))
|
||||
{
|
||||
dataZoom.runtimeStartDrag = true;
|
||||
}
|
||||
else if (dataZoom.IsInEndZoom(pos))
|
||||
{
|
||||
dataZoom.runtimeEndDrag = true;
|
||||
}
|
||||
else if (dataZoom.IsInSelectedZoom(pos))
|
||||
{
|
||||
dataZoom.runtimeDrag = true;
|
||||
}
|
||||
}
|
||||
else if (dataZoom.IsInSelectedZoom(pos))
|
||||
{
|
||||
@@ -742,10 +828,19 @@ namespace XCharts
|
||||
foreach (var dataZoom in chart.dataZooms)
|
||||
{
|
||||
var grid = chart.GetDataZoomGridOrDefault(dataZoom);
|
||||
float deltaX = eventData.delta.x;
|
||||
float deltaPercent = deltaX / grid.runtimeWidth * 100;
|
||||
OnDragInside(dataZoom, deltaPercent);
|
||||
OnDragSlider(dataZoom, deltaPercent);
|
||||
switch (dataZoom.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
var deltaPercent = eventData.delta.x / grid.runtimeWidth * 100;
|
||||
OnDragInside(dataZoom, deltaPercent);
|
||||
OnDragSlider(dataZoom, deltaPercent);
|
||||
break;
|
||||
case Orient.Vertical:
|
||||
deltaPercent = eventData.delta.y / grid.runtimeHeight * 100;
|
||||
OnDragInside(dataZoom, deltaPercent);
|
||||
OnDragSlider(dataZoom, deltaPercent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,10 +894,9 @@ namespace XCharts
|
||||
endX = grid.runtimeX + grid.runtimeWidth;
|
||||
startX = grid.runtimeX + grid.runtimeWidth - selectWidth;
|
||||
}
|
||||
dataZoom.start = (startX - grid.runtimeX) / grid.runtimeWidth * 100;
|
||||
dataZoom.end = (endX - grid.runtimeX) / grid.runtimeWidth * 100;
|
||||
RefreshDataZoomLabel();
|
||||
chart.RefreshChart();
|
||||
var start = (startX - grid.runtimeX) / grid.runtimeWidth * 100;
|
||||
var end = (endX - grid.runtimeX) / grid.runtimeWidth * 100;
|
||||
UpdateDataZoomRange(dataZoom, start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -810,41 +904,47 @@ namespace XCharts
|
||||
{
|
||||
if (chart == null) return;
|
||||
if (Input.touchCount > 1) return;
|
||||
Vector2 pos;
|
||||
if (!chart.ScreenPointToChartPoint(eventData.position, out pos)) return;
|
||||
foreach (var dataZoom in chart.dataZooms)
|
||||
{
|
||||
if (!dataZoom.enable || dataZoom.zoomLock) return;
|
||||
Vector2 pos;
|
||||
if (!chart.ScreenPointToChartPoint(eventData.position, out pos))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!dataZoom.enable || dataZoom.zoomLock) continue;
|
||||
var grid = chart.GetDataZoomGridOrDefault(dataZoom);
|
||||
if (!chart.IsInGrid(grid, pos) && !dataZoom.IsInSelectedZoom(pos))
|
||||
if ((dataZoom.supportInside && dataZoom.supportInsideScroll && chart.IsInGrid(grid, pos)) ||
|
||||
dataZoom.IsInZoom(pos))
|
||||
{
|
||||
return;
|
||||
ScaleDataZoom(dataZoom, eventData.scrollDelta.y * dataZoom.scrollSensitivity);
|
||||
}
|
||||
ScaleDataZoom(dataZoom, eventData.scrollDelta.y * dataZoom.scrollSensitivity);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDragInside(DataZoom dataZoom, float deltaPercent)
|
||||
{
|
||||
if (deltaPercent == 0) return;
|
||||
if (Input.touchCount > 1) return;
|
||||
if (!dataZoom.supportInside) return;
|
||||
if (!dataZoom.supportInside || !dataZoom.supportInsideDrag) return;
|
||||
if (!dataZoom.runtimeCoordinateDrag) return;
|
||||
var diff = dataZoom.end - dataZoom.start;
|
||||
if (deltaPercent > 0)
|
||||
{
|
||||
dataZoom.start -= deltaPercent;
|
||||
dataZoom.end = dataZoom.start + diff;
|
||||
if (dataZoom.start > 0)
|
||||
{
|
||||
var start = dataZoom.start - deltaPercent;
|
||||
if (start < 0) start = 0;
|
||||
var end = start + diff;
|
||||
UpdateDataZoomRange(dataZoom, start, end);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataZoom.end += -deltaPercent;
|
||||
dataZoom.start = dataZoom.end - diff;
|
||||
if (dataZoom.end < 100)
|
||||
{
|
||||
var end = dataZoom.end - deltaPercent;
|
||||
if (end > 100) end = 100;
|
||||
var start = end - diff;
|
||||
UpdateDataZoomRange(dataZoom, start, end);
|
||||
}
|
||||
}
|
||||
RefreshDataZoomLabel();
|
||||
chart.RefreshChart();
|
||||
}
|
||||
|
||||
private void OnDragSlider(DataZoom dataZoom, float deltaPercent)
|
||||
@@ -853,83 +953,69 @@ namespace XCharts
|
||||
if (!dataZoom.supportSlider) return;
|
||||
if (dataZoom.runtimeStartDrag)
|
||||
{
|
||||
dataZoom.start += deltaPercent;
|
||||
if (dataZoom.start > dataZoom.end)
|
||||
var start = dataZoom.start + deltaPercent;
|
||||
if (start > dataZoom.end)
|
||||
{
|
||||
dataZoom.start = dataZoom.end;
|
||||
start = dataZoom.end;
|
||||
dataZoom.runtimeEndDrag = true;
|
||||
dataZoom.runtimeStartDrag = false;
|
||||
}
|
||||
if (dataZoom.realtime)
|
||||
{
|
||||
RefreshDataZoomLabel();
|
||||
chart.RefreshChart();
|
||||
}
|
||||
UpdateDataZoomRange(dataZoom, start, dataZoom.end);
|
||||
}
|
||||
else if (dataZoom.runtimeEndDrag)
|
||||
{
|
||||
dataZoom.end += deltaPercent;
|
||||
if (dataZoom.end < dataZoom.start)
|
||||
var end = dataZoom.end + deltaPercent;
|
||||
if (end < dataZoom.start)
|
||||
{
|
||||
dataZoom.end = dataZoom.start;
|
||||
end = dataZoom.start;
|
||||
dataZoom.runtimeStartDrag = true;
|
||||
dataZoom.runtimeEndDrag = false;
|
||||
}
|
||||
if (dataZoom.realtime)
|
||||
{
|
||||
RefreshDataZoomLabel();
|
||||
chart.RefreshChart();
|
||||
}
|
||||
UpdateDataZoomRange(dataZoom, dataZoom.start, end);
|
||||
}
|
||||
else if (dataZoom.runtimeDrag)
|
||||
{
|
||||
if (deltaPercent > 0)
|
||||
{
|
||||
if (dataZoom.end + deltaPercent > 100)
|
||||
{
|
||||
deltaPercent = 100 - dataZoom.end;
|
||||
}
|
||||
if (dataZoom.end + deltaPercent > 100) deltaPercent = 100 - dataZoom.end;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dataZoom.start + deltaPercent < 0)
|
||||
{
|
||||
deltaPercent = -dataZoom.start;
|
||||
}
|
||||
}
|
||||
dataZoom.start += deltaPercent;
|
||||
dataZoom.end += deltaPercent;
|
||||
if (dataZoom.realtime)
|
||||
{
|
||||
RefreshDataZoomLabel();
|
||||
chart.RefreshChart();
|
||||
if (dataZoom.start + deltaPercent < 0) deltaPercent = -dataZoom.start;
|
||||
}
|
||||
UpdateDataZoomRange(dataZoom, dataZoom.start + deltaPercent, dataZoom.end + deltaPercent);
|
||||
}
|
||||
}
|
||||
|
||||
private void ScaleDataZoom(DataZoom dataZoom, float delta)
|
||||
{
|
||||
var grid = chart.GetDataZoomGridOrDefault(dataZoom);
|
||||
float deltaPercent = Mathf.Abs(delta / grid.runtimeWidth * 100);
|
||||
var deltaPercent = dataZoom.orient == Orient.Horizonal ?
|
||||
Mathf.Abs(delta / grid.runtimeWidth * 100) :
|
||||
Mathf.Abs(delta / grid.runtimeHeight * 100);
|
||||
if (delta > 0)
|
||||
{
|
||||
if (dataZoom.end <= dataZoom.start) return;
|
||||
dataZoom.end -= deltaPercent;
|
||||
dataZoom.start += deltaPercent;
|
||||
if (dataZoom.end <= dataZoom.start)
|
||||
{
|
||||
dataZoom.end = dataZoom.start;
|
||||
}
|
||||
UpdateDataZoomRange(dataZoom, dataZoom.start + deltaPercent, dataZoom.end - deltaPercent);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataZoom.end += deltaPercent;
|
||||
dataZoom.start -= deltaPercent;
|
||||
if (dataZoom.end > 100) dataZoom.end = 100;
|
||||
if (dataZoom.start < 0) dataZoom.start = 0;
|
||||
UpdateDataZoomRange(dataZoom, dataZoom.start - deltaPercent, dataZoom.end + deltaPercent);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDataZoomRange(DataZoom dataZoom, float start, float end)
|
||||
{
|
||||
if (end > 100) end = 100;
|
||||
if (start < 0) start = 0;
|
||||
if (end < start) end = start;
|
||||
dataZoom.start = start;
|
||||
dataZoom.end = end;
|
||||
if (dataZoom.realtime)
|
||||
{
|
||||
chart.OnDataZoomRangeChanged(dataZoom);
|
||||
chart.RefreshChart();
|
||||
}
|
||||
RefreshDataZoomLabel();
|
||||
chart.RefreshChart();
|
||||
}
|
||||
|
||||
public void RefreshDataZoomLabel()
|
||||
@@ -939,7 +1025,7 @@ namespace XCharts
|
||||
|
||||
private void CheckDataZoomScale(DataZoom dataZoom)
|
||||
{
|
||||
if (!dataZoom.enable || dataZoom.zoomLock || !dataZoom.supportInside) return;
|
||||
if (!dataZoom.enable || dataZoom.zoomLock || !dataZoom.supportInside || !dataZoom.supportInsideDrag) return;
|
||||
|
||||
if (Input.touchCount == 2)
|
||||
{
|
||||
@@ -1017,14 +1103,13 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
|
||||
private void DrawHorizonalDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
|
||||
{
|
||||
if (!dataZoom.enable || !dataZoom.supportSlider) return;
|
||||
var p1 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY);
|
||||
var p2 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
var p3 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
var p4 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY);
|
||||
var xAxis = chart.GetXAxis(0);
|
||||
var lineColor = dataZoom.lineStyle.GetColor(chart.theme.dataZoom.dataLineColor);
|
||||
var lineWidth = dataZoom.lineStyle.GetWidth(chart.theme.dataZoom.dataLineWidth);
|
||||
var borderWidth = dataZoom.borderWidth == 0 ? chart.theme.dataZoom.borderWidth : dataZoom.borderWidth;
|
||||
@@ -1043,8 +1128,8 @@ namespace XCharts
|
||||
float scaleWid = dataZoom.runtimeWidth / (showData.Count - 1);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float minValue = 0;
|
||||
float maxValue = 0;
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsValue(), axis.inverse, out minValue, out maxValue);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);
|
||||
|
||||
@@ -1058,11 +1143,11 @@ namespace XCharts
|
||||
var dataChanging = false;
|
||||
for (int i = 0; i < maxCount; i += rate)
|
||||
{
|
||||
float value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
double value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
|
||||
float pX = dataZoom.runtimeX + i * scaleWid;
|
||||
float dataHig = (maxValue - minValue) == 0 ? 0 :
|
||||
(value - minValue) / (maxValue - minValue) * dataZoom.runtimeHeight;
|
||||
float dataHig = (float)((maxValue - minValue) == 0 ? 0 :
|
||||
(value - minValue) / (maxValue - minValue) * dataZoom.runtimeHeight);
|
||||
np = new Vector3(pX, chart.chartY + dataZoom.bottom + dataHig);
|
||||
if (i > 0)
|
||||
{
|
||||
@@ -1098,5 +1183,86 @@ namespace XCharts
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawVerticalDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
|
||||
{
|
||||
if (!dataZoom.enable || !dataZoom.supportSlider) return;
|
||||
var p1 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY);
|
||||
var p2 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
var p3 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
var p4 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY);
|
||||
var lineColor = dataZoom.lineStyle.GetColor(chart.theme.dataZoom.dataLineColor);
|
||||
var lineWidth = dataZoom.lineStyle.GetWidth(chart.theme.dataZoom.dataLineWidth);
|
||||
var borderWidth = dataZoom.borderWidth == 0 ? chart.theme.dataZoom.borderWidth : dataZoom.borderWidth;
|
||||
var borderColor = dataZoom.GetBorderColor(chart.theme.dataZoom.borderColor);
|
||||
var backgroundColor = dataZoom.GetBackgroundColor(chart.theme.dataZoom.backgroundColor);
|
||||
var areaColor = dataZoom.areaStyle.GetColor(chart.theme.dataZoom.dataAreaColor);
|
||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor);
|
||||
var centerPos = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth / 2,
|
||||
dataZoom.runtimeY + dataZoom.runtimeHeight / 2);
|
||||
UGL.DrawBorder(vh, centerPos, dataZoom.runtimeWidth, dataZoom.runtimeHeight, borderWidth, borderColor);
|
||||
if (dataZoom.showDataShadow && chart.series.Count > 0)
|
||||
{
|
||||
Serie serie = chart.series.list[0];
|
||||
Axis axis = chart.GetYAxis(0);
|
||||
var showData = serie.GetDataList(null);
|
||||
float scaleWid = dataZoom.runtimeHeight / (showData.Count - 1);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsValue(), axis.inverse, out minValue, out maxValue);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);
|
||||
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
|
||||
var maxCount = showData.Count;
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (dataZoom.runtimeHeight / sampleDist));
|
||||
if (rate < 1) rate = 1;
|
||||
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||
chart.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
var dataChanging = false;
|
||||
for (int i = 0; i < maxCount; i += rate)
|
||||
{
|
||||
double value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
|
||||
float pY = dataZoom.runtimeY + i * scaleWid;
|
||||
float dataHig = (maxValue - minValue) == 0 ? 0 :
|
||||
(float)((value - minValue) / (maxValue - minValue) * dataZoom.runtimeWidth);
|
||||
np = new Vector3(chart.chartX + chart.chartWidth - dataZoom.right - dataHig, pY);
|
||||
if (i > 0)
|
||||
{
|
||||
UGL.DrawLine(vh, lp, np, lineWidth, lineColor);
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - lineWidth);
|
||||
Vector3 anp = new Vector3(np.x, np.y - lineWidth);
|
||||
|
||||
Vector3 tnp = new Vector3(np.x, chart.chartY + dataZoom.bottom + lineWidth);
|
||||
Vector3 tlp = new Vector3(lp.x, chart.chartY + dataZoom.bottom + lineWidth);
|
||||
UGL.DrawQuadrilateral(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
if (dataChanging)
|
||||
{
|
||||
chart.RefreshTopPainter();
|
||||
}
|
||||
}
|
||||
switch (dataZoom.rangeMode)
|
||||
{
|
||||
case DataZoom.RangeMode.Percent:
|
||||
var start = dataZoom.runtimeY + dataZoom.runtimeHeight * dataZoom.start / 100;
|
||||
var end = dataZoom.runtimeY + dataZoom.runtimeHeight * dataZoom.end / 100;
|
||||
var fillerColor = dataZoom.GetFillerColor(chart.theme.dataZoom.fillerColor);
|
||||
|
||||
p1 = new Vector2(dataZoom.runtimeX, start);
|
||||
p2 = new Vector2(dataZoom.runtimeX + dataZoom.runtimeWidth, start);
|
||||
p3 = new Vector2(dataZoom.runtimeX + dataZoom.runtimeWidth, end);
|
||||
p4 = new Vector2(dataZoom.runtimeX, end);
|
||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, fillerColor);
|
||||
UGL.DrawLine(vh, p1, p2, lineWidth, fillerColor);
|
||||
UGL.DrawLine(vh, p3, p4, lineWidth, fillerColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_ItemHeight = 12.0f;
|
||||
[SerializeField] private float m_ItemGap = 10f;
|
||||
[SerializeField] private bool m_ItemAutoColor = true;
|
||||
[SerializeField] private bool m_TextAutoColor = false;
|
||||
[SerializeField] private string m_Formatter;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
[SerializeField] private List<string> m_Data = new List<string>();
|
||||
@@ -176,6 +177,16 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether the legend text matches the color automatically.
|
||||
/// 图例标记的文本是否自动匹配颜色。
|
||||
/// [default:false]
|
||||
/// </summary>
|
||||
public bool textAutoColor
|
||||
{
|
||||
get { return m_TextAutoColor; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_TextAutoColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}.
|
||||
/// 图例内容字符串模版格式器。支持用 \n 换行。
|
||||
/// 模板变量为图例名称 {name}。
|
||||
|
||||
@@ -54,8 +54,9 @@ namespace XCharts
|
||||
public class Indicator
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_Max;
|
||||
[SerializeField] private float m_Min;
|
||||
[SerializeField] private double m_Max;
|
||||
[SerializeField] private double m_Min;
|
||||
[SerializeField] private double[] m_Range = new double[2] { 0, 0 };
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
/// <summary>
|
||||
@@ -67,12 +68,12 @@ namespace XCharts
|
||||
/// The maximum value of indicator, with default value of 0, but we recommend to set it manually.
|
||||
/// 指示器的最大值,默认为 0 无限制。
|
||||
/// </summary>
|
||||
public float max { get { return m_Max; } set { m_Max = value; } }
|
||||
public double max { get { return m_Max; } set { m_Max = value; } }
|
||||
/// <summary>
|
||||
/// The minimum value of indicator, with default value of 0.
|
||||
/// 指示器的最小值,默认为 0 无限制。
|
||||
/// </summary>
|
||||
public float min { get { return m_Min; } set { m_Min = value; } }
|
||||
public double min { get { return m_Min; } set { m_Min = value; } }
|
||||
/// <summary>
|
||||
/// the style of text.
|
||||
/// 文本样式。
|
||||
@@ -83,6 +84,24 @@ namespace XCharts
|
||||
/// 指示器的文本组件。
|
||||
/// </summary>
|
||||
public Text text { get; set; }
|
||||
/// <summary>
|
||||
/// Normal range. When the value is outside this range, the display color is automatically changed.
|
||||
/// 正常值范围。当数值不在这个范围时,会自动变更显示颜色。
|
||||
/// </summary>
|
||||
public double[] range
|
||||
{
|
||||
get { return m_Range; }
|
||||
set { if (value != null && value.Length == 2) { m_Range = value; } }
|
||||
}
|
||||
|
||||
public bool IsInRange(double value)
|
||||
{
|
||||
if (m_Range == null || m_Range.Length < 2) return true;
|
||||
if (m_Range[0] != 0 || m_Range[1] != 0)
|
||||
return value >= m_Range[0] && value <= m_Range[1];
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private Shape m_Shape;
|
||||
@@ -97,6 +116,9 @@ namespace XCharts
|
||||
[SerializeField] private float m_IndicatorGap = 10;
|
||||
[SerializeField] private int m_CeilRate = 0;
|
||||
[SerializeField] private bool m_IsAxisTooltip;
|
||||
[SerializeField] private Color32 m_OutRangeColor = Color.red;
|
||||
[SerializeField] private bool m_ConnectCenter = false;
|
||||
[SerializeField] private bool m_LineGradient = true;
|
||||
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
|
||||
/// <summary>
|
||||
/// [default:true]
|
||||
@@ -214,6 +236,33 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_PositionType, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The color displayed when data out of range.
|
||||
/// 数值超出范围时显示的颜色。
|
||||
/// </summary>
|
||||
public Color32 outRangeColor
|
||||
{
|
||||
get { return m_OutRangeColor; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_OutRangeColor, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether serie data connect to radar center with line.
|
||||
/// 数值是否连线到中心点。
|
||||
/// </summary>
|
||||
public bool connectCenter
|
||||
{
|
||||
get { return m_ConnectCenter; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ConnectCenter, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether need gradient for data line.
|
||||
/// 数值线段是否需要渐变。
|
||||
/// </summary>
|
||||
public bool lineGradient
|
||||
{
|
||||
get { return m_LineGradient; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_LineGradient, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the indicator list.
|
||||
/// 指示器列表。
|
||||
/// </summary>
|
||||
@@ -276,7 +325,13 @@ namespace XCharts
|
||||
return true;
|
||||
}
|
||||
|
||||
public float GetIndicatorMin(int index)
|
||||
public bool IsInIndicatorRange(int index, double value)
|
||||
{
|
||||
var indicator = GetIndicator(index);
|
||||
return indicator == null ? true : indicator.IsInRange(value);
|
||||
}
|
||||
|
||||
public double GetIndicatorMin(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_IndicatorList.Count)
|
||||
{
|
||||
@@ -284,7 +339,7 @@ namespace XCharts
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public float GetIndicatorMax(int index)
|
||||
public double GetIndicatorMax(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_IndicatorList.Count)
|
||||
{
|
||||
|
||||
@@ -247,7 +247,7 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 对齐方式
|
||||
/// </summary>
|
||||
public enum SerieAlign
|
||||
public enum Align
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
@@ -319,12 +319,15 @@ namespace XCharts
|
||||
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
|
||||
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
|
||||
[SerializeField] private TitleStyle m_TitleStyle = new TitleStyle();
|
||||
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||
[SerializeField] private MarkLine m_MarkLine = MarkLine.defaultMarkLine;
|
||||
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
|
||||
[SerializeField] private bool m_ShowDataName;
|
||||
[SerializeField] private bool m_ShowDataIcon;
|
||||
[SerializeField] private bool m_Clip = false;
|
||||
[SerializeField] private bool m_Ignore = false;
|
||||
[SerializeField] private float m_IgnoreValue = 0;
|
||||
[SerializeField] private double m_IgnoreValue = 0;
|
||||
[SerializeField] private bool m_IgnoreLineBreak = false;
|
||||
[SerializeField] private bool m_ShowAsPositiveNumber = false;
|
||||
[SerializeField] private bool m_Large = true;
|
||||
[SerializeField] private int m_LargeThreshold = 200;
|
||||
@@ -337,7 +340,7 @@ namespace XCharts
|
||||
|
||||
[SerializeField] private SerieDataSortType m_DataSortType = SerieDataSortType.Descending;
|
||||
[SerializeField] private Orient m_Orient = Orient.Vertical;
|
||||
[SerializeField] private SerieAlign m_Align = SerieAlign.Center;
|
||||
[SerializeField] private Align m_Align = Align.Center;
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
@@ -354,11 +357,13 @@ namespace XCharts
|
||||
|
||||
[NonSerialized] internal int m_FilterStart;
|
||||
[NonSerialized] internal int m_FilterEnd;
|
||||
[NonSerialized] internal float m_FilterStartValue;
|
||||
[NonSerialized] internal float m_FilterEndValue;
|
||||
[NonSerialized] internal double m_FilterStartValue;
|
||||
[NonSerialized] internal double m_FilterEndValue;
|
||||
[NonSerialized] internal int m_FilterMinShow;
|
||||
[NonSerialized] internal bool m_NeedUpdateFilterData;
|
||||
[NonSerialized] internal List<SerieData> m_FilterData = new List<SerieData>();
|
||||
[NonSerialized] internal List<SerieData> m_SortedData = new List<SerieData>();
|
||||
[NonSerialized] internal List<SerieData> m_RootData = new List<SerieData>();
|
||||
[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>();
|
||||
@@ -762,12 +767,21 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 忽略数据的默认值。当ignore为true才有效。
|
||||
/// </summary>
|
||||
public float ignoreValue
|
||||
public double ignoreValue
|
||||
{
|
||||
get { return m_IgnoreValue; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 忽略数据时折线是断开还是连接。默认false为连接。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public bool ignoreLineBreak
|
||||
{
|
||||
get { return m_IgnoreLineBreak; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_IgnoreLineBreak, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 雷达图类型。
|
||||
/// </summary>
|
||||
public RadarType radarType
|
||||
@@ -852,6 +866,23 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetClass(ref m_TitleStyle, value, true)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 标线。
|
||||
/// </summary>
|
||||
public MarkLine markLine
|
||||
{
|
||||
get { return m_MarkLine; }
|
||||
set { if (PropertyUtil.SetClass(ref m_MarkLine, value, true)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// 数据项图标样式。
|
||||
/// </summary>
|
||||
public IconStyle iconStyle
|
||||
{
|
||||
get { return m_IconStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_IconStyle, value, true)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据项里的数据维数。
|
||||
/// </summary>
|
||||
public int showDataDimension { get { return m_ShowDataDimension; } set { m_ShowDataDimension = value; } }
|
||||
@@ -1044,7 +1075,7 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 组件水平方向对齐方式。
|
||||
/// </summary>
|
||||
public SerieAlign align
|
||||
public Align align
|
||||
{
|
||||
get { return m_Align; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Align, value)) SetVerticesDirty(); }
|
||||
@@ -1067,7 +1098,8 @@ namespace XCharts
|
||||
label.vertsDirty ||
|
||||
emphasis.vertsDirty ||
|
||||
gaugeAxis.vertsDirty ||
|
||||
gaugePointer.vertsDirty;
|
||||
gaugePointer.vertsDirty ||
|
||||
markLine.vertsDirty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1085,6 +1117,8 @@ namespace XCharts
|
||||
gaugeAxis.ClearVerticesDirty();
|
||||
gaugePointer.ClearVerticesDirty();
|
||||
titleStyle.ClearVerticesDirty();
|
||||
markLine.ClearVerticesDirty();
|
||||
iconStyle.ClearVerticesDirty();
|
||||
}
|
||||
|
||||
public override void ClearComponentDirty()
|
||||
@@ -1100,6 +1134,8 @@ namespace XCharts
|
||||
gaugeAxis.ClearComponentDirty();
|
||||
gaugePointer.ClearComponentDirty();
|
||||
titleStyle.ClearComponentDirty();
|
||||
markLine.ClearComponentDirty();
|
||||
iconStyle.ClearComponentDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1136,24 +1172,26 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 运行时的最大数据值
|
||||
/// </summary>
|
||||
public float runtimeDataMax { get; internal set; }
|
||||
public double runtimeDataMax { get; internal set; }
|
||||
/// <summary>
|
||||
/// 运行时的最小数据值
|
||||
/// </summary>
|
||||
public float runtimeDataMin { get; internal set; }
|
||||
public double runtimeDataMin { get; internal set; }
|
||||
/// <summary>
|
||||
/// 饼图的数据项之和
|
||||
/// </summary>
|
||||
public float runtimePieDataTotal { get; internal set; }
|
||||
public double runtimePieDataTotal { get; internal set; }
|
||||
public float runtimeWaveSpeed { get; internal set; }
|
||||
public Painter runtimeCanvas { get; internal set; }
|
||||
public float runtimeCheckValue { get; set; }
|
||||
public double runtimeCheckValue { get; set; }
|
||||
public int runtimeGridIndex { get; internal set; }
|
||||
public float runtimeX { get; internal set; }
|
||||
public float runtimeY { get; internal set; }
|
||||
public float runtimeWidth { get; internal set; }
|
||||
public float runtimeHeight { get; internal set; }
|
||||
public List<SerieData> runtimeFilterData { get { return m_FilterData; } }
|
||||
public Rect runtimeRect { get; internal set; }
|
||||
public List<SerieData> runtimeSortedData { get { return m_SortedData; } }
|
||||
public List<SerieData> rootData { get { return m_RootData; } }
|
||||
public bool nameDirty { get { return m_NameDirty; } }
|
||||
|
||||
private void SetNameDirty()
|
||||
@@ -1213,14 +1251,14 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 维度Y对应数据中最大值。
|
||||
/// </summary>
|
||||
public float yMax
|
||||
public double yMax
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = float.MinValue;
|
||||
var max = double.MinValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[1] > max)
|
||||
if (sdata.show && !IsIgnoreValue(sdata.data[1]) && sdata.data[1] > max)
|
||||
{
|
||||
max = sdata.data[1];
|
||||
}
|
||||
@@ -1232,14 +1270,14 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 维度X对应数据中的最大值。
|
||||
/// </summary>
|
||||
public float xMax
|
||||
public double xMax
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = float.MinValue;
|
||||
var max = double.MinValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[0] > max)
|
||||
if (sdata.show && !IsIgnoreValue(sdata.data[0]) && sdata.data[0] > max)
|
||||
{
|
||||
max = sdata.data[0];
|
||||
}
|
||||
@@ -1251,14 +1289,14 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 维度Y对应数据的最小值。
|
||||
/// </summary>
|
||||
public float yMin
|
||||
public double yMin
|
||||
{
|
||||
get
|
||||
{
|
||||
float min = float.MaxValue;
|
||||
var min = double.MaxValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[1] < min)
|
||||
if (sdata.show && !IsIgnoreValue(sdata.data[1]) && sdata.data[1] < min)
|
||||
{
|
||||
min = sdata.data[1];
|
||||
}
|
||||
@@ -1270,14 +1308,14 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 维度X对应数据的最小值。
|
||||
/// </summary>
|
||||
public float xMin
|
||||
public double xMin
|
||||
{
|
||||
get
|
||||
{
|
||||
float min = float.MaxValue;
|
||||
var min = double.MaxValue;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show && sdata.data[0] < min)
|
||||
if (sdata.show && !IsIgnoreValue(sdata.data[0]) && sdata.data[0] < min)
|
||||
{
|
||||
min = sdata.data[0];
|
||||
}
|
||||
@@ -1289,16 +1327,15 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 维度Y数据的总和。
|
||||
/// </summary>
|
||||
public float yTotal
|
||||
public double yTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
double total = 0;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show)
|
||||
if (sdata.show && !IsIgnoreValue(sdata.data[1]))
|
||||
total += sdata.GetCurrData(1, animation.GetUpdateAnimationDuration());
|
||||
//total += sdata.GetData(1);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
@@ -1307,14 +1344,14 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 维度X数据的总和。
|
||||
/// </summary>
|
||||
public float xTotal
|
||||
public double xTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
double total = 0;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show)
|
||||
if (sdata.show && !IsIgnoreValue(sdata.data[1]))
|
||||
total += sdata.data[0];
|
||||
}
|
||||
return total;
|
||||
@@ -1331,6 +1368,7 @@ namespace XCharts
|
||||
RemoveData(0);
|
||||
}
|
||||
m_Data.Clear();
|
||||
m_NeedUpdateFilterData = true;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
@@ -1364,6 +1402,7 @@ namespace XCharts
|
||||
m_DownSmoothPoints.Remove(serieData.index);
|
||||
}
|
||||
m_Data.RemoveAt(index);
|
||||
m_NeedUpdateFilterData = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1372,7 +1411,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="dataName"></param>
|
||||
public SerieData AddYData(float value, string dataName = null)
|
||||
public SerieData AddYData(double value, string dataName = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
int xValue = m_Data.Count;
|
||||
@@ -1392,6 +1431,7 @@ namespace XCharts
|
||||
{
|
||||
if (m_InsertDataToHead) m_Data.Insert(0, serieData);
|
||||
else m_Data.Add(serieData);
|
||||
m_NeedUpdateFilterData = true;
|
||||
}
|
||||
|
||||
private void CheckDataName(string dataName)
|
||||
@@ -1413,7 +1453,7 @@ namespace XCharts
|
||||
/// <param name="yValue"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <param name="maxDataNumber"></param>
|
||||
public SerieData AddXYData(float xValue, float yValue, string dataName = null)
|
||||
public SerieData AddXYData(double xValue, double yValue, string dataName = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
var serieData = SerieDataPool.Get();
|
||||
@@ -1438,7 +1478,7 @@ namespace XCharts
|
||||
/// <param name="heighest"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns></returns>
|
||||
public SerieData AddData(float open, float close, float lowest, float heighest, string dataName = null)
|
||||
public SerieData AddData(double open, double close, double lowest, double heighest, string dataName = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
var serieData = SerieDataPool.Get();
|
||||
@@ -1463,7 +1503,7 @@ namespace XCharts
|
||||
/// <param name="valueList"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <param name="maxDataNumber"></param>
|
||||
public SerieData AddData(List<float> valueList, string dataName = null)
|
||||
public SerieData AddData(List<double> valueList, string dataName = null)
|
||||
{
|
||||
if (valueList == null || valueList.Count == 0) return null;
|
||||
if (valueList.Count == 1)
|
||||
@@ -1492,11 +1532,37 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public SerieData AddChildData(SerieData parent, double value, string name = null)
|
||||
{
|
||||
var serieData = new SerieData();
|
||||
serieData.name = name;
|
||||
serieData.index = m_Data.Count;
|
||||
serieData.data = new List<double>() { parent.children.Count, value };
|
||||
serieData.parentIndex = parent.index;
|
||||
serieData.runtimeParent = parent;
|
||||
AddSerieDataHeadOrTail(serieData);
|
||||
parent.children.Add(serieData.index);
|
||||
parent.runtimeChildren.Add(serieData);
|
||||
return serieData;
|
||||
}
|
||||
public SerieData AddChildData(SerieData parent, List<double> value, string name = null)
|
||||
{
|
||||
var serieData = new SerieData();
|
||||
serieData.name = name;
|
||||
serieData.index = m_Data.Count;
|
||||
serieData.data = new List<double>(value);
|
||||
serieData.parentIndex = parent.index;
|
||||
serieData.runtimeParent = parent;
|
||||
AddSerieDataHeadOrTail(serieData);
|
||||
parent.children.Add(serieData.index);
|
||||
parent.runtimeChildren.Add(serieData);
|
||||
return serieData;
|
||||
}
|
||||
|
||||
private void CheckMaxCache()
|
||||
{
|
||||
if (m_MaxCache <= 0) return;
|
||||
while (m_Data.Count > m_MaxCache)
|
||||
while (m_Data.Count >= m_MaxCache)
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
if (m_InsertDataToHead) RemoveData(m_Data.Count - 1);
|
||||
@@ -1511,7 +1577,7 @@ namespace XCharts
|
||||
/// <param name="dimension"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public float GetData(int index, int dimension, DataZoom dataZoom = null)
|
||||
public double GetData(int index, int dimension, DataZoom dataZoom = null)
|
||||
{
|
||||
if (index < 0 || dimension < 0) return 0;
|
||||
var serieData = GetSerieData(index, dataZoom);
|
||||
@@ -1520,7 +1586,7 @@ namespace XCharts
|
||||
var value = serieData.GetData(dimension);
|
||||
if (showAsPositiveNumber)
|
||||
{
|
||||
value = Mathf.Abs(value);
|
||||
value = Math.Abs(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -1536,7 +1602,7 @@ namespace XCharts
|
||||
/// <param name="index"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public float GetYData(int index, DataZoom dataZoom = null)
|
||||
public double GetYData(int index, DataZoom dataZoom = null)
|
||||
{
|
||||
if (index < 0) return 0;
|
||||
var serieData = GetDataList(dataZoom);
|
||||
@@ -1545,14 +1611,14 @@ namespace XCharts
|
||||
var value = serieData[index].data[1];
|
||||
if (showAsPositiveNumber)
|
||||
{
|
||||
value = Mathf.Abs(value);
|
||||
value = Math.Abs(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetYCurrData(int index, DataZoom dataZoom = null)
|
||||
public double GetYCurrData(int index, DataZoom dataZoom = null)
|
||||
{
|
||||
if (index < 0) return 0;
|
||||
var serieData = GetDataList(dataZoom);
|
||||
@@ -1561,7 +1627,7 @@ namespace XCharts
|
||||
var value = serieData[index].GetCurrData(1, animation.GetUpdateAnimationDuration());
|
||||
if (showAsPositiveNumber)
|
||||
{
|
||||
value = Mathf.Abs(value);
|
||||
value = Math.Abs(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -1575,7 +1641,7 @@ namespace XCharts
|
||||
/// <param name="yData">对应的数据值</param>
|
||||
/// <param name="dataName">对应的数据名</param>
|
||||
/// <param name="dataZoom">区域缩放</param>
|
||||
public void GetYData(int index, out float yData, out string dataName, DataZoom dataZoom = null)
|
||||
public void GetYData(int index, out double yData, out string dataName, DataZoom dataZoom = null)
|
||||
{
|
||||
yData = 0;
|
||||
dataName = null;
|
||||
@@ -1586,7 +1652,7 @@ namespace XCharts
|
||||
yData = serieData[index].data[1];
|
||||
if (showAsPositiveNumber)
|
||||
{
|
||||
yData = Mathf.Abs(yData);
|
||||
yData = Math.Abs(yData);
|
||||
}
|
||||
dataName = serieData[index].name;
|
||||
}
|
||||
@@ -1608,6 +1674,31 @@ namespace XCharts
|
||||
return null;
|
||||
}
|
||||
|
||||
public SerieData GetSerieData(string id, DataZoom dataZoom = null)
|
||||
{
|
||||
var data = GetDataList(dataZoom);
|
||||
foreach (var serieData in data)
|
||||
{
|
||||
var target = GetSerieData(serieData, id);
|
||||
if (target != null) return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SerieData GetSerieData(SerieData parent, string id)
|
||||
{
|
||||
if (id.Equals(parent.id)) return parent;
|
||||
foreach (var child in parent.children)
|
||||
{
|
||||
var data = GetSerieData(GetSerieData(child), id);
|
||||
if (data != null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定索引的维度X和维度Y的数据
|
||||
/// </summary>
|
||||
@@ -1615,7 +1706,7 @@ namespace XCharts
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <param name="xValue"></param>
|
||||
/// <param name="yVlaue"></param>
|
||||
public void GetXYData(int index, DataZoom dataZoom, out float xValue, out float yVlaue)
|
||||
public void GetXYData(int index, DataZoom dataZoom, out double xValue, out double yVlaue)
|
||||
{
|
||||
xValue = 0;
|
||||
yVlaue = 0;
|
||||
@@ -1628,15 +1719,15 @@ namespace XCharts
|
||||
yVlaue = serieData.data[1];
|
||||
if (showAsPositiveNumber)
|
||||
{
|
||||
xValue = Mathf.Abs(xValue);
|
||||
yVlaue = Mathf.Abs(yVlaue);
|
||||
xValue = Math.Abs(xValue);
|
||||
yVlaue = Math.Abs(yVlaue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float GetDataTotal(int dimension)
|
||||
public double GetDataTotal(int dimension)
|
||||
{
|
||||
float total = 0;
|
||||
double total = 0;
|
||||
foreach (var sdata in data)
|
||||
{
|
||||
if (sdata.show)
|
||||
@@ -1660,7 +1751,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
return runtimeFilterData.Count > 0 ? runtimeFilterData : m_Data;
|
||||
return runtimeSortedData.Count > 0 ? runtimeSortedData : m_Data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1669,7 +1760,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="value"></param>
|
||||
public bool UpdateYData(int index, float value)
|
||||
public bool UpdateYData(int index, double value)
|
||||
{
|
||||
UpdateData(index, 1, value);
|
||||
return true;
|
||||
@@ -1694,7 +1785,7 @@ namespace XCharts
|
||||
/// <param name="index">要更新数据的索引</param>
|
||||
/// <param name="dimension">要更新数据的维数</param>
|
||||
/// <param name="value">新的数据值</param>
|
||||
public bool UpdateData(int index, int dimension, float value)
|
||||
public bool UpdateData(int index, int dimension, double value)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
@@ -1715,7 +1806,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="values"></param>
|
||||
public bool UpdateData(int index, List<float> values)
|
||||
public bool UpdateData(int index, List<double> values)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count && values != null)
|
||||
{
|
||||
@@ -1776,60 +1867,6 @@ namespace XCharts
|
||||
else return m_BarWidth * categoryWidth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有数据的图标是否显示
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void SetDataIconActive(bool flag)
|
||||
{
|
||||
foreach (var data in m_Data)
|
||||
{
|
||||
data.iconStyle.show = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标是否显示
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="flag"></param>
|
||||
public void SetDataIconActive(int dataIndex, bool flag)
|
||||
{
|
||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||
{
|
||||
var data = m_Data[dataIndex];
|
||||
data.iconStyle.show = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统一设置图标的尺寸
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetDataIconSize(float width, float height)
|
||||
{
|
||||
foreach (var data in m_Data)
|
||||
{
|
||||
data.iconStyle.width = width;
|
||||
data.iconStyle.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标的图片
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="image"></param>
|
||||
public void SetDataIcon(int dataIndex, Sprite image)
|
||||
{
|
||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||
{
|
||||
var data = m_Data[dataIndex];
|
||||
data.iconStyle.sprite = image;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsIgnoreIndex(int index, int dimension = 1)
|
||||
{
|
||||
var serieData = GetSerieData(index);
|
||||
@@ -1846,9 +1883,9 @@ namespace XCharts
|
||||
return IsIgnoreValue(serieData.GetData(dimension));
|
||||
}
|
||||
|
||||
public bool IsIgnoreValue(float value)
|
||||
public bool IsIgnoreValue(double value)
|
||||
{
|
||||
return m_Ignore && Mathf.Approximately(value, m_IgnoreValue);
|
||||
return m_Ignore && MathUtil.Approximately(value, m_IgnoreValue);
|
||||
}
|
||||
|
||||
public bool IsIgnorePoint(int index)
|
||||
@@ -1910,6 +1947,75 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用或取消初始动画
|
||||
/// </summary>
|
||||
public void AnimationEnable(bool flag)
|
||||
{
|
||||
if (animation.enable) animation.enable = flag;
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.enable = flag;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 渐入动画
|
||||
/// </summary>
|
||||
public void AnimationFadeIn()
|
||||
{
|
||||
if (animation.enable) animation.FadeIn();
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.FadeIn();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 渐出动画
|
||||
/// </summary>
|
||||
public void AnimationFadeOut()
|
||||
{
|
||||
if (animation.enable) animation.FadeOut();
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.FadeOut();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停动画
|
||||
/// </summary>
|
||||
public void AnimationPause()
|
||||
{
|
||||
if (animation.enable) animation.Pause();
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.Pause();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 继续动画
|
||||
/// </summary>
|
||||
public void AnimationResume()
|
||||
{
|
||||
if (animation.enable) animation.Resume();
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.Resume();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置动画
|
||||
/// </summary>
|
||||
public void AnimationReset()
|
||||
{
|
||||
if (animation.enable) animation.Reset();
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.Reset();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
/// <summary>
|
||||
/// 重置动画
|
||||
/// </summary>
|
||||
public void AnimationRestart()
|
||||
{
|
||||
if (animation.enable) animation.Restart();
|
||||
if (markLine.show && markLine.animation.enable) markLine.animation.Restart();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从json中导入数据
|
||||
/// </summary>
|
||||
@@ -1939,8 +2045,8 @@ namespace XCharts
|
||||
for (int j = 0; j < data.Length; j++)
|
||||
{
|
||||
var txt = data[j].Trim().Replace("]", "");
|
||||
float value;
|
||||
var flag = float.TryParse(txt, out value);
|
||||
double value;
|
||||
var flag = double.TryParse(txt, out value);
|
||||
if (flag)
|
||||
{
|
||||
serieData.data.Add(value);
|
||||
@@ -1961,8 +2067,8 @@ namespace XCharts
|
||||
{
|
||||
if (a.StartsWith("value:"))
|
||||
{
|
||||
float value = float.Parse(a.Substring(6, a.Length - 6));
|
||||
serieData.data = new List<float>() { i, value };
|
||||
double value = double.Parse(a.Substring(6, a.Length - 6));
|
||||
serieData.data = new List<double>() { i, value };
|
||||
}
|
||||
else if (a.StartsWith("name:"))
|
||||
{
|
||||
@@ -1983,12 +2089,12 @@ namespace XCharts
|
||||
string[] datas = temp.Split(',');
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
float value;
|
||||
var flag = float.TryParse(datas[i].Trim(), out value);
|
||||
double value;
|
||||
var flag = double.TryParse(datas[i].Trim(), out value);
|
||||
if (flag)
|
||||
{
|
||||
var serieData = new SerieData();
|
||||
serieData.data = new List<float>() { i, value };
|
||||
serieData.data = new List<double>() { i, value };
|
||||
AddSerieDataHeadOrTail(serieData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,9 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void ClearData()
|
||||
{
|
||||
AnimationFadeIn();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
serie.AnimationFadeIn();
|
||||
serie.ClearData();
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace XCharts
|
||||
/// <param name="serieIndex"></param>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <returns></returns>
|
||||
public float GetData(int serieIndex, int dataIndex)
|
||||
public double GetData(int serieIndex, int dataIndex)
|
||||
{
|
||||
if (serieIndex >= 0 && serieIndex < Count)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float GetCurrData(int serieIndex, int dataIndex)
|
||||
public double GetCurrData(int serieIndex, int dataIndex)
|
||||
{
|
||||
if (serieIndex >= 0 && serieIndex < Count)
|
||||
{
|
||||
@@ -228,12 +228,28 @@ namespace XCharts
|
||||
/// 移除指定名字的系列。
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
public void Remove(string serieName)
|
||||
public bool RemoveSerie(string serieName)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
return RemoveSerie(serie);
|
||||
}
|
||||
|
||||
public bool RemoveSerie(int serieIndex)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
return RemoveSerie(serie);
|
||||
}
|
||||
|
||||
public bool RemoveSerie(Serie serie)
|
||||
{
|
||||
if (serie != null && m_Series.Remove(serie))
|
||||
{
|
||||
m_Series.Remove(serie);
|
||||
SetVerticesDirty();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +259,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public void RemoveAll()
|
||||
{
|
||||
AnimationFadeIn();
|
||||
foreach(var serie in m_Series) serie.AnimationFadeIn();
|
||||
m_Series.Clear();
|
||||
}
|
||||
|
||||
@@ -255,6 +271,16 @@ namespace XCharts
|
||||
/// <param name="show"></param>
|
||||
/// <returns></returns>
|
||||
public Serie AddSerie(SerieType type, string serieName, bool show = true, bool addToHead = false)
|
||||
{
|
||||
return InsertSerie(-1, type, serieName, show, addToHead);
|
||||
}
|
||||
|
||||
public Serie InsertSerie(int index, SerieType type, string serieName, bool show = true)
|
||||
{
|
||||
return InsertSerie(index, type, serieName, show, false);
|
||||
}
|
||||
|
||||
private Serie InsertSerie(int index, SerieType type, string serieName, bool show = true, bool addToHead = false)
|
||||
{
|
||||
var serie = new Serie();
|
||||
serie.type = type;
|
||||
@@ -276,8 +302,9 @@ namespace XCharts
|
||||
{
|
||||
serie.symbol.show = false;
|
||||
}
|
||||
serie.animation.Restart();
|
||||
serie.AnimationRestart();
|
||||
if (addToHead) m_Series.Insert(0, serie);
|
||||
else if (index >= 0) m_Series.Insert(index, serie);
|
||||
else m_Series.Add(serie);
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
@@ -294,7 +321,7 @@ namespace XCharts
|
||||
/// <param name="value"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns>添加成功返回SerieData,否则返回null</returns>
|
||||
public SerieData AddData(string serieName, float value, string dataName = null)
|
||||
public SerieData AddData(string serieName, double value, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -311,7 +338,7 @@ namespace XCharts
|
||||
/// <param name="value"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns>添加成功返回SerieData,否则返回null</returns>
|
||||
public SerieData AddData(int index, float value, string dataName = null)
|
||||
public SerieData AddData(int index, double value, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
@@ -331,7 +358,7 @@ namespace XCharts
|
||||
/// <param name="heighest"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns></returns>
|
||||
public SerieData AddData(int index, float open, float close, float lowest, float heighest, string dataName = null)
|
||||
public SerieData AddData(int index, double open, double close, double lowest, double heighest, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
@@ -341,7 +368,7 @@ namespace XCharts
|
||||
return null;
|
||||
}
|
||||
|
||||
public SerieData AddData(string serieName, float open, float close, float lowest, float heighest, string dataName = null)
|
||||
public SerieData AddData(string serieName, double open, double close, double lowest, double heighest, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -358,7 +385,7 @@ namespace XCharts
|
||||
/// <param name="multidimensionalData"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns>添加成功返回SerieData,否则返回null</returns>
|
||||
public SerieData AddData(string serieName, List<float> multidimensionalData, string dataName = null)
|
||||
public SerieData AddData(string serieName, List<double> multidimensionalData, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -375,7 +402,7 @@ namespace XCharts
|
||||
/// <param name="multidimensionalData"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns>添加成功返回SerieData,否则返回null</returns>
|
||||
public SerieData AddData(int serieIndex, List<float> multidimensionalData, string dataName = null)
|
||||
public SerieData AddData(int serieIndex, List<double> multidimensionalData, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
@@ -393,7 +420,7 @@ namespace XCharts
|
||||
/// <param name="yValue"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns>添加成功返回SerieData,否则返回null</returns>
|
||||
public SerieData AddXYData(string serieName, float xValue, float yValue, string dataName = null)
|
||||
public SerieData AddXYData(string serieName, double xValue, double yValue, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -411,7 +438,7 @@ namespace XCharts
|
||||
/// <param name="yValue"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns>添加成功返回SerieData,否则返回null</returns>
|
||||
public SerieData AddXYData(int index, float xValue, float yValue, string dataName = null)
|
||||
public SerieData AddXYData(int index, double xValue, double yValue, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
@@ -427,7 +454,7 @@ namespace XCharts
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="dataIndex"></param>
|
||||
public bool UpdateData(string serieName, int dataIndex, float value)
|
||||
public bool UpdateData(string serieName, int dataIndex, double value)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -475,7 +502,7 @@ namespace XCharts
|
||||
/// <param name="serieIndex"></param>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
public bool UpdateData(int serieIndex, int dataIndex, float value)
|
||||
public bool UpdateData(int serieIndex, int dataIndex, double value)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
@@ -485,7 +512,7 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool UpdateData(string serieName, int dataIndex, List<float> values)
|
||||
public bool UpdateData(string serieName, int dataIndex, List<double> values)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -494,7 +521,7 @@ namespace XCharts
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool UpdateData(int serieIndex, int dataIndex, List<float> values)
|
||||
public bool UpdateData(int serieIndex, int dataIndex, List<double> values)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
@@ -511,7 +538,7 @@ namespace XCharts
|
||||
/// <param name="dataIndex">数据项</param>
|
||||
/// <param name="dimension">数据维数,从0开始</param>
|
||||
/// <param name="value">值</param>
|
||||
public bool UpdateData(int serieIndex, int dataIndex, int dimension, float value)
|
||||
public bool UpdateData(int serieIndex, int dataIndex, int dimension, double value)
|
||||
{
|
||||
var serie = GetSerie(serieIndex);
|
||||
if (serie != null)
|
||||
@@ -528,7 +555,7 @@ namespace XCharts
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="dimension">数据维数,从0开始</param>
|
||||
/// <param name="value"></param>
|
||||
public bool UpdateData(string serieName, int dataIndex, int dimension, float value)
|
||||
public bool UpdateData(string serieName, int dataIndex, int dimension, double value)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
@@ -635,8 +662,8 @@ namespace XCharts
|
||||
if (serie != null)
|
||||
{
|
||||
serie.show = active;
|
||||
serie.animation.Reset();
|
||||
if (active) serie.animation.FadeIn();
|
||||
serie.AnimationReset();
|
||||
if (active) serie.AnimationFadeIn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,74 +692,5 @@ namespace XCharts
|
||||
serie.symbol.selectedSizeCallback = selectedSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用或取消初始动画
|
||||
/// </summary>
|
||||
public void AnimationEnable(bool flag)
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
serie.animation.enable = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 渐入动画
|
||||
/// </summary>
|
||||
public void AnimationFadeIn()
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (serie.animation.enable)
|
||||
{
|
||||
serie.animation.FadeIn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 渐出动画
|
||||
/// </summary>
|
||||
public void AnimationFadeOut()
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
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()
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (serie.animation.enable) serie.animation.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
/******************************************/
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
@@ -67,6 +65,7 @@ namespace XCharts
|
||||
[SerializeField] private Sprite m_BackgroundImage;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
|
||||
private DelegateTooltipPosition m_PositionFunction;
|
||||
|
||||
private GameObject m_GameObject;
|
||||
private GameObject m_Content;
|
||||
@@ -103,6 +102,7 @@ namespace XCharts
|
||||
/// {b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
|
||||
/// {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
|
||||
/// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
|
||||
/// {e} is the name of the data item serieData that is currently indicated or whose index is 0.
|
||||
/// {.1} represents a dot from serie corresponding color that specifies index as 1.
|
||||
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
|
||||
/// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
|
||||
@@ -117,6 +117,7 @@ namespace XCharts
|
||||
/// {b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。
|
||||
/// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。
|
||||
/// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。
|
||||
/// {e}为当前所指示或index为0的serie的数据项serieData的name。
|
||||
/// {.1}表示指定index为1的serie对应颜色的圆点。
|
||||
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。
|
||||
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。
|
||||
@@ -257,14 +258,14 @@ namespace XCharts
|
||||
/// the value for x indicator label.
|
||||
/// 指示器X轴上要显示的值。
|
||||
/// </summary>
|
||||
public float[] runtimeXValues { get { return m_RuntimeXValue; } internal set { m_RuntimeXValue = value; } }
|
||||
private float[] m_RuntimeXValue = new float[2] { -1, -1 };
|
||||
public double[] runtimeXValues { get { return m_RuntimeXValue; } internal set { m_RuntimeXValue = value; } }
|
||||
private double[] m_RuntimeXValue = new double[2] { -1, -1 };
|
||||
/// <summary>
|
||||
/// the value for y indicator label.
|
||||
/// 指示器Y轴上要显示的值。
|
||||
/// </summary>
|
||||
public float[] runtimeYValues { get { return m_RuntimeYValue; } internal set { m_RuntimeYValue = value; } }
|
||||
private float[] m_RuntimeYValue = new float[2] { -1, -1 };
|
||||
public double[] runtimeYValues { get { return m_RuntimeYValue; } internal set { m_RuntimeYValue = value; } }
|
||||
private double[] m_RuntimeYValue = new double[2] { -1, -1 };
|
||||
/// <summary>
|
||||
/// the current pointer position.
|
||||
/// 当前鼠标位置。
|
||||
@@ -300,6 +301,12 @@ namespace XCharts
|
||||
public int runtimeGridIndex { get; internal set; }
|
||||
public int runtimePolarIndex { get; internal set; }
|
||||
|
||||
public DelegateTooltipPosition positionFunction
|
||||
{
|
||||
get { return m_PositionFunction; }
|
||||
set { m_PositionFunction = value; }
|
||||
}
|
||||
|
||||
public static Tooltip defaultTooltip
|
||||
{
|
||||
get
|
||||
@@ -449,7 +456,12 @@ namespace XCharts
|
||||
public void UpdateContentPos(Vector2 pos)
|
||||
{
|
||||
if (m_Content)
|
||||
m_Content.transform.localPosition = pos;
|
||||
{
|
||||
if (m_PositionFunction != null)
|
||||
m_Content.transform.localPosition = m_PositionFunction(pos);
|
||||
else
|
||||
m_Content.transform.localPosition = pos;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -53,19 +53,19 @@ namespace XCharts
|
||||
[System.Serializable]
|
||||
public class Pieces
|
||||
{
|
||||
[SerializeField] private float m_Min;
|
||||
[SerializeField] private float m_Max;
|
||||
[SerializeField] private double m_Min;
|
||||
[SerializeField] private double m_Max;
|
||||
[SerializeField] private string m_Label;
|
||||
[SerializeField] private Color32 m_Color;
|
||||
|
||||
/// <summary>
|
||||
/// 范围最小值
|
||||
/// </summary>
|
||||
public float min { get { return m_Min; } set { m_Min = value; } }
|
||||
public double min { get { return m_Min; } set { m_Min = value; } }
|
||||
/// <summary>
|
||||
/// 范围最大值
|
||||
/// </summary>
|
||||
public float max { get { return m_Max; } set { m_Max = value; } }
|
||||
public double max { get { return m_Max; } set { m_Max = value; } }
|
||||
/// <summary>
|
||||
/// 文字描述
|
||||
/// </summary>
|
||||
@@ -75,10 +75,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Color32 color { get { return m_Color; } set { m_Color = value; } }
|
||||
|
||||
public bool Contains(float value, float minMaxRange)
|
||||
public bool Contains(double value, double minMaxRange)
|
||||
{
|
||||
var cmin = Mathf.Abs(m_Min) < 1 ? minMaxRange * m_Min : m_Min;
|
||||
var cmax = Mathf.Abs(m_Max) < 1 ? minMaxRange * m_Max : m_Max;
|
||||
var cmin = System.Math.Abs(m_Min) < 1 ? minMaxRange * m_Min : m_Min;
|
||||
var cmax = System.Math.Abs(m_Max) < 1 ? minMaxRange * m_Max : m_Max;
|
||||
return value >= cmin && value < cmax;
|
||||
}
|
||||
}
|
||||
@@ -87,10 +87,10 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Type m_Type = Type.Continuous;
|
||||
[SerializeField] private SelectedMode m_SelectedMode = SelectedMode.Multiple;
|
||||
[SerializeField] private float m_Min = 0;
|
||||
[SerializeField] private float m_Max = 100f;
|
||||
[SerializeField] private double m_Min = 0;
|
||||
[SerializeField] private double m_Max = 100;
|
||||
|
||||
[SerializeField] private float[] m_Range = new float[2] { 0, 100f };
|
||||
[SerializeField] private double[] m_Range = new double[2] { 0, 100 };
|
||||
[SerializeField] private string[] m_Text = new string[2] { "", "" };
|
||||
[SerializeField] private float[] m_TextGap = new float[2] { 10f, 10f };
|
||||
[SerializeField] private int m_SplitNumber = 5;
|
||||
@@ -156,7 +156,7 @@ namespace XCharts
|
||||
///
|
||||
/// 允许的最小值。`autoMinMax`为`false`时必须指定。[visualMap.min, visualMap.max] 形成了视觉映射的『定义域』。
|
||||
/// </summary>
|
||||
public float min
|
||||
public double min
|
||||
{
|
||||
get { return m_Min; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
|
||||
@@ -166,7 +166,7 @@ namespace XCharts
|
||||
///
|
||||
/// 允许的最大值。`autoMinMax`为`false`时必须指定。[visualMap.min, visualMax.max] 形成了视觉映射的『定义域』。
|
||||
/// </summary>
|
||||
public float max
|
||||
public double max
|
||||
{
|
||||
get { return m_Max; }
|
||||
set { m_Max = (value < min ? min + 1 : value); SetVerticesDirty(); }
|
||||
@@ -176,7 +176,7 @@ namespace XCharts
|
||||
///
|
||||
/// 指定手柄对应数值的位置。range 应在[min,max]范围内。
|
||||
/// </summary>
|
||||
public float[] range { get { return m_Range; } }
|
||||
public double[] range { get { return m_Range; } }
|
||||
/// <summary>
|
||||
/// Text on both ends.
|
||||
/// 两端的文本,如 ['High', 'Low']。
|
||||
@@ -356,14 +356,14 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int runtimeSelectedIndex { get; set; }
|
||||
public float runtimeSelectedValue { get; set; }
|
||||
public double runtimeSelectedValue { get; set; }
|
||||
/// <summary>
|
||||
/// the current pointer position.
|
||||
/// 当前鼠标位置。
|
||||
/// </summary>
|
||||
public Vector2 runtimePointerPos { get; set; }
|
||||
public bool runtimeIsVertical { get { return orient == Orient.Vertical; } }
|
||||
public float rangeMin
|
||||
public double rangeMin
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -376,7 +376,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float rangeMax
|
||||
public double rangeMax
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -398,8 +398,8 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float runtimeRangeMinHeight { get { return (rangeMin - min) / (max - min) * itemHeight; } }
|
||||
public float runtimeRangeMaxHeight { get { return (rangeMax - min) / (max - min) * itemHeight; } }
|
||||
public float runtimeRangeMinHeight { get { return (float)((rangeMin - min) / (max - min) * itemHeight); } }
|
||||
public float runtimeRangeMaxHeight { get { return (float)((rangeMax - min) / (max - min) * itemHeight); } }
|
||||
public bool runtimeMinDrag { get; internal set; }
|
||||
public bool runtimeMaxDrag { get; internal set; }
|
||||
|
||||
@@ -440,7 +440,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var rate = (rtValue - inValue) / diff1;
|
||||
var rate = (float)((rtValue - inValue) / diff1);
|
||||
m_RtInRange.Add(Color32.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate));
|
||||
}
|
||||
}
|
||||
@@ -450,7 +450,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public Color32 GetColor(float value)
|
||||
public Color32 GetColor(double value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -463,7 +463,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private Color32 GetPiecesColor(float value)
|
||||
private Color32 GetPiecesColor(double value)
|
||||
{
|
||||
foreach (var piece in m_Pieces)
|
||||
{
|
||||
@@ -476,7 +476,7 @@ namespace XCharts
|
||||
else return ChartConst.clearColor32;
|
||||
}
|
||||
|
||||
private Color32 GetContinuousColor(float value)
|
||||
private Color32 GetContinuousColor(double value)
|
||||
{
|
||||
if (value < m_Min || value > m_Max)
|
||||
{
|
||||
@@ -498,15 +498,15 @@ namespace XCharts
|
||||
var nowMin = m_Min + index * diff;
|
||||
var rate = (value - nowMin) / diff;
|
||||
if (index == splitNumber - 1) return runtimeInRange[index];
|
||||
else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], rate);
|
||||
else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], (float)rate);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetIndex(float value)
|
||||
public int GetIndex(double value)
|
||||
{
|
||||
int splitNumber = runtimeInRange.Count;
|
||||
if (splitNumber <= 0) return -1;
|
||||
value = Mathf.Clamp(value, m_Min, m_Max);
|
||||
value = MathUtil.Clamp(value, m_Min, m_Max);
|
||||
|
||||
var diff = (m_Max - m_Min) / (splitNumber - 1);
|
||||
var index = -1;
|
||||
@@ -526,7 +526,7 @@ namespace XCharts
|
||||
return m_Type == VisualMap.Type.Piecewise;
|
||||
}
|
||||
|
||||
public bool IsInSelectedValue(float value)
|
||||
public bool IsInSelectedValue(double value)
|
||||
{
|
||||
if (runtimeSelectedIndex < 0) return true;
|
||||
else
|
||||
@@ -535,7 +535,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float GetValue(Vector3 pos, Rect chartRect)
|
||||
public double GetValue(Vector3 pos, Rect chartRect)
|
||||
{
|
||||
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
|
||||
var pos1 = centerPos + (runtimeIsVertical ? Vector3.down : Vector3.left) * itemHeight / 2;
|
||||
@@ -726,7 +726,7 @@ namespace XCharts
|
||||
var halfHig = visualMap.itemHeight / 2;
|
||||
var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight);
|
||||
var selectedIndex = -1;
|
||||
var value = 0f;
|
||||
double value = 0;
|
||||
switch (visualMap.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
@@ -928,7 +928,6 @@ namespace XCharts
|
||||
var halfWid = visualMap.itemWidth / 2;
|
||||
var halfHig = visualMap.itemHeight / 2;
|
||||
var splitNum = visualMap.runtimeInRange.Count;
|
||||
var splitWid = visualMap.itemHeight / (splitNum - 1);
|
||||
var colors = visualMap.runtimeInRange;
|
||||
switch (visualMap.orient)
|
||||
{
|
||||
|
||||
@@ -90,6 +90,7 @@ namespace XCharts
|
||||
public float runtimeY { get; private set; }
|
||||
public float runtimeWidth { get; private set; }
|
||||
public float runtimeHeight { get; private set; }
|
||||
public Vector3 runtimePosition { get; private set; }
|
||||
|
||||
internal void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
|
||||
{
|
||||
@@ -101,6 +102,7 @@ namespace XCharts
|
||||
runtimeY = chartY + runtimeBottom;
|
||||
runtimeWidth = chartWidth - runtimeLeft - runtimeRight;
|
||||
runtimeHeight = chartHeight - runtimeTop - runtimeBottom;
|
||||
runtimePosition = new Vector3(runtimeX, runtimeY);
|
||||
}
|
||||
|
||||
public static Grid defaultGrid
|
||||
|
||||
@@ -28,8 +28,11 @@ namespace XCharts
|
||||
[SerializeField] private bool m_OnZero = false;
|
||||
[SerializeField] private float m_Width = 0f;
|
||||
[SerializeField] private float m_Height = 0f;
|
||||
[SerializeField] private bool m_ShowStartLabel = true;
|
||||
[SerializeField] private bool m_ShowEndLabel = true;
|
||||
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
private DelegateAxisLabelFormatter m_FormatterFunction;
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent the axis label from appearing.
|
||||
@@ -124,7 +127,24 @@ namespace XCharts
|
||||
get { return m_Height; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to display the first label.
|
||||
/// 是否显示第一个文本。
|
||||
/// </summary>
|
||||
public bool showStartLabel
|
||||
{
|
||||
get { return m_ShowStartLabel; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowStartLabel, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to display the last label.
|
||||
/// 是否显示最后一个文本。
|
||||
/// </summary>
|
||||
public bool showEndLabel
|
||||
{
|
||||
get { return m_ShowEndLabel; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 文本限制。
|
||||
/// </summary>
|
||||
@@ -144,6 +164,11 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
public DelegateAxisLabelFormatter formatterFunction
|
||||
{
|
||||
set { m_FormatterFunction = value; }
|
||||
}
|
||||
|
||||
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
|
||||
public override void ClearComponentDirty()
|
||||
{
|
||||
@@ -177,6 +202,8 @@ namespace XCharts
|
||||
axisLabel.numericFormatter = numericFormatter;
|
||||
axisLabel.width = width;
|
||||
axisLabel.height = height;
|
||||
axisLabel.showStartLabel = showStartLabel;
|
||||
axisLabel.showEndLabel = showEndLabel;
|
||||
axisLabel.textLimit = textLimit.Clone();
|
||||
axisLabel.textStyle.Copy(textStyle);
|
||||
return axisLabel;
|
||||
@@ -192,6 +219,8 @@ namespace XCharts
|
||||
numericFormatter = axisLabel.numericFormatter;
|
||||
width = axisLabel.width;
|
||||
height = axisLabel.height;
|
||||
showStartLabel = axisLabel.showStartLabel;
|
||||
showEndLabel = axisLabel.showEndLabel;
|
||||
textLimit.Copy(axisLabel.textLimit);
|
||||
textStyle.Copy(axisLabel.textStyle);
|
||||
}
|
||||
@@ -201,8 +230,12 @@ namespace XCharts
|
||||
m_TextLimit.SetRelatedText(txt, labelWidth);
|
||||
}
|
||||
|
||||
public string GetFormatterContent(string category)
|
||||
public string GetFormatterContent(int labelIndex, string category)
|
||||
{
|
||||
if (m_FormatterFunction != null)
|
||||
{
|
||||
return m_FormatterFunction(labelIndex, 0, category);
|
||||
}
|
||||
if (string.IsNullOrEmpty(category)) return category;
|
||||
if (string.IsNullOrEmpty(m_Formatter))
|
||||
{
|
||||
@@ -216,11 +249,15 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false)
|
||||
public string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false)
|
||||
{
|
||||
if (showAsPositiveNumber && value < 0)
|
||||
{
|
||||
value = Mathf.Abs(value);
|
||||
value = Math.Abs(value);
|
||||
}
|
||||
if (m_FormatterFunction != null)
|
||||
{
|
||||
return m_FormatterFunction(labelIndex, value, null);
|
||||
}
|
||||
if (string.IsNullOrEmpty(m_Formatter))
|
||||
{
|
||||
@@ -246,8 +283,14 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFormatterDateTime(DateTime dateTime)
|
||||
public string GetFormatterDateTime(int labelIndex, double value)
|
||||
{
|
||||
if (m_FormatterFunction != null)
|
||||
{
|
||||
return m_FormatterFunction(labelIndex, value, null);
|
||||
}
|
||||
var timestamp = (int)value;
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp);
|
||||
var format = string.IsNullOrEmpty(numericFormatter) ? "yyyy/M/d" : numericFormatter;
|
||||
if (!string.IsNullOrEmpty(m_Formatter))
|
||||
{
|
||||
|
||||
@@ -20,11 +20,13 @@ namespace XCharts
|
||||
}
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private Layer m_Layer;
|
||||
[SerializeField] private Align m_Align = Align.Left;
|
||||
[SerializeField] private Sprite m_Sprite;
|
||||
[SerializeField] private Color m_Color = Color.white;
|
||||
[SerializeField] private float m_Width = 20;
|
||||
[SerializeField] private float m_Height = 20;
|
||||
[SerializeField] private Vector3 m_Offset;
|
||||
[SerializeField] private bool m_AutoHideWhenLabelEmpty = false;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
@@ -35,6 +37,7 @@ namespace XCharts
|
||||
m_Width = 20;
|
||||
m_Height = 20;
|
||||
m_Offset = Vector3.zero;
|
||||
m_AutoHideWhenLabelEmpty = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether the data icon is show.
|
||||
@@ -66,7 +69,14 @@ namespace XCharts
|
||||
/// 图标偏移。
|
||||
/// </summary>
|
||||
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// 水平方向对齐方式。
|
||||
/// </summary>
|
||||
public Align align { get { return m_Align; } set { m_Align = value; } }
|
||||
/// <summary>
|
||||
/// 当label内容为空时是否自动隐藏图标
|
||||
/// </summary>
|
||||
public bool autoHideWhenLabelEmpty { get { return m_AutoHideWhenLabelEmpty; } set { m_AutoHideWhenLabelEmpty = value; } }
|
||||
public IconStyle Clone()
|
||||
{
|
||||
var iconStyle = new IconStyle();
|
||||
@@ -77,6 +87,8 @@ namespace XCharts
|
||||
iconStyle.width = width;
|
||||
iconStyle.height = height;
|
||||
iconStyle.offset = offset;
|
||||
iconStyle.align = align;
|
||||
iconStyle.autoHideWhenLabelEmpty = autoHideWhenLabelEmpty;
|
||||
return iconStyle;
|
||||
}
|
||||
|
||||
@@ -89,6 +101,8 @@ namespace XCharts
|
||||
width = iconStyle.width;
|
||||
height = iconStyle.height;
|
||||
offset = iconStyle.offset;
|
||||
align = iconStyle.align;
|
||||
autoHideWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
646
Assets/XCharts/Runtime/Component/Sub/MarkLine.cs
Normal file
646
Assets/XCharts/Runtime/Component/Sub/MarkLine.cs
Normal file
@@ -0,0 +1,646 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 标线类型
|
||||
/// </summary>
|
||||
public enum MarkLineType
|
||||
{
|
||||
None,
|
||||
/// <summary>
|
||||
/// 最小值。
|
||||
/// </summary>
|
||||
Min,
|
||||
/// <summary>
|
||||
/// 最大值。
|
||||
/// </summary>
|
||||
Max,
|
||||
/// <summary>
|
||||
/// 平均值。
|
||||
/// </summary>
|
||||
Average,
|
||||
/// <summary>
|
||||
/// 中位数。
|
||||
/// </summary>
|
||||
Median
|
||||
}
|
||||
/// <summary>
|
||||
/// Data of marking line.
|
||||
/// 图表标线的数据。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MarkLineData : SubComponent
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private MarkLineType m_Type = MarkLineType.None;
|
||||
[SerializeField] private int m_Dimension = 1;
|
||||
[SerializeField] private float m_XPosition;
|
||||
[SerializeField] private float m_YPosition;
|
||||
[SerializeField] private double m_XValue;
|
||||
[SerializeField] private double m_YValue;
|
||||
[SerializeField] private int m_Group = 0;
|
||||
[SerializeField] private bool m_ZeroPosition = false;
|
||||
|
||||
[SerializeField] private SerieSymbol m_StartSymbol = new SerieSymbol();
|
||||
[SerializeField] private SerieSymbol m_EndSymbol = new SerieSymbol();
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
//[SerializeField] private Emphasis m_Emphasis = new Emphasis();
|
||||
|
||||
public int index { get; set; }
|
||||
public Vector3 runtimeStartPosition { get; internal set; }
|
||||
public Vector3 runtimeEndPosition { get; internal set; }
|
||||
public Vector3 runtimeCurrentEndPosition { get; internal set; }
|
||||
public ChartLabel runtimeLabel { get; internal set; }
|
||||
public double runtimeValue { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the marker, which will display as a label.
|
||||
/// 标线名称,将会作为文字显示。label的formatter可通过{b}显示名称,通过{c}显示数值。
|
||||
/// </summary>
|
||||
public string name
|
||||
{
|
||||
get { return m_Name; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Special label types, are used to label maximum value, minimum value and so on.
|
||||
/// 特殊的标线类型,用于标注最大值最小值等。
|
||||
/// </summary>
|
||||
public MarkLineType type
|
||||
{
|
||||
get { return m_Type; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// From which dimension of data to calculate the maximum and minimum value and so on.
|
||||
/// 从哪个维度的数据计算最大最小值等。
|
||||
/// </summary>
|
||||
public int dimension
|
||||
{
|
||||
get { return m_Dimension; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The x coordinate relative to the origin, in pixels.
|
||||
/// 相对原点的 x 坐标,单位像素。当type为None时有效。
|
||||
/// </summary>
|
||||
public float xPosition
|
||||
{
|
||||
get { return m_XPosition; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_XPosition, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The y coordinate relative to the origin, in pixels.
|
||||
/// 相对原点的 y 坐标,单位像素。当type为None时有效。
|
||||
/// </summary>
|
||||
public float yPosition
|
||||
{
|
||||
get { return m_YPosition; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_YPosition, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The value specified on the X-axis. A value specified when the X-axis is the category axis represents the index of the category axis data, otherwise a specific value.
|
||||
/// X轴上的指定值。当X轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
|
||||
/// </summary>
|
||||
public double xValue
|
||||
{
|
||||
get { return m_XValue; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_XValue, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// That's the value on the Y-axis. The value specified when the Y axis is the category axis represents the index of the category axis data, otherwise the specific value.
|
||||
/// Y轴上的指定值。当Y轴为类目轴时指定值表示类目轴数据的索引,否则为具体的值。当type为None时有效。
|
||||
/// </summary>
|
||||
public double yValue
|
||||
{
|
||||
get { return m_YValue; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_YValue, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Grouping. When the group is not 0, it means that this data is the starting point or end point of the marking line. Data consistent with the group form a marking line.
|
||||
/// 分组。当group不为0时,表示这个data是标线的起点或终点,group一致的data组成一条标线。
|
||||
/// </summary>
|
||||
public int group
|
||||
{
|
||||
get { return m_Group; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Group, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Is the origin of the coordinate system.
|
||||
/// 是否为坐标系原点。
|
||||
/// </summary>
|
||||
public bool zeroPosition
|
||||
{
|
||||
get { return m_ZeroPosition; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ZeroPosition, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The symbol of the start point of markline.
|
||||
/// 起始点的图形标记。
|
||||
/// </summary>
|
||||
public SerieSymbol startSymbol
|
||||
{
|
||||
get { return m_StartSymbol; }
|
||||
set { if (PropertyUtil.SetClass(ref m_StartSymbol, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The symbol of the end point of markline.
|
||||
/// 结束点的图形标记。
|
||||
/// </summary>
|
||||
public SerieSymbol endSymbol
|
||||
{
|
||||
get { return m_EndSymbol; }
|
||||
set { if (PropertyUtil.SetClass(ref m_EndSymbol, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The line style of markline.
|
||||
/// 标线样式。
|
||||
/// </summary>
|
||||
public LineStyle lineStyle
|
||||
{
|
||||
get { return m_LineStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Text styles of label. You can set position to Start, Middle, and End to display text in different locations.
|
||||
/// 文本样式。可设置position为Start、Middle和End在不同的位置显示文本。
|
||||
/// </summary>
|
||||
public SerieLabel label
|
||||
{
|
||||
get { return m_Label; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Label, value)) SetVerticesDirty(); }
|
||||
}
|
||||
// public Emphasis emphasis
|
||||
// {
|
||||
// get { return m_Emphasis; }
|
||||
// set { if (PropertyUtil.SetClass(ref m_Emphasis, value)) SetVerticesDirty(); }
|
||||
// }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use a line in the chart to illustrate.
|
||||
/// 图表标线。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MarkLine : SubComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private SerieAnimation m_Animation = new SerieAnimation();
|
||||
[SerializeField] private List<MarkLineData> m_Data = new List<MarkLineData>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to display the marking line.
|
||||
/// 是否显示标线。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The animation of markline.
|
||||
/// 标线的动画样式。
|
||||
/// </summary>
|
||||
public SerieAnimation animation
|
||||
{
|
||||
get { return m_Animation; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Animation, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// A list of marked data. When the group of data item is 0, each data item represents a line;
|
||||
/// When the group is not 0, two data items of the same group represent the starting point and
|
||||
/// the ending point of the line respectively to form a line. In this case, the relevant style
|
||||
/// parameters of the line are the parameters of the starting point.
|
||||
/// 标线的数据列表。当数据项的group为0时,每个数据项表示一条标线;当group不为0时,相同group的两个数据项分别表
|
||||
/// 示标线的起始点和终止点来组成一条标线,此时标线的相关样式参数取起始点的参数。
|
||||
/// </summary>
|
||||
public List<MarkLineData> data
|
||||
{
|
||||
get { return m_Data; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Data, value)) SetVerticesDirty(); }
|
||||
}
|
||||
public static MarkLine defaultMarkLine
|
||||
{
|
||||
get
|
||||
{
|
||||
var markLine = new MarkLine
|
||||
{
|
||||
m_Show = false,
|
||||
m_Data = new List<MarkLineData>()
|
||||
};
|
||||
var data = new MarkLineData();
|
||||
data.name = "average";
|
||||
data.type = MarkLineType.Average;
|
||||
data.lineStyle.type = LineStyle.Type.Dashed;
|
||||
data.lineStyle.color = Color.blue;
|
||||
data.startSymbol.show = true;
|
||||
data.startSymbol.type = SerieSymbolType.Circle;
|
||||
data.endSymbol.show = true;
|
||||
data.endSymbol.type = SerieSymbolType.Arrow;
|
||||
data.label.show = true;
|
||||
data.label.numericFormatter = "f1";
|
||||
data.label.formatter = "{c}";
|
||||
markLine.data.Add(data);
|
||||
return markLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class MarkLineHandler : IComponentHandler
|
||||
{
|
||||
public CoordinateChart chart;
|
||||
private GameObject m_MarkLineLabelRoot;
|
||||
|
||||
public MarkLineHandler(CoordinateChart chart)
|
||||
{
|
||||
this.chart = chart;
|
||||
}
|
||||
|
||||
public void DrawBase(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
public void DrawTop(VertexHelper vh)
|
||||
{
|
||||
DrawMarkLine(vh);
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
m_MarkLineLabelRoot = ChartHelper.AddObject("markline", chart.transform, chart.chartMinAnchor,
|
||||
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
|
||||
m_MarkLineLabelRoot.hideFlags = chart.chartHideFlags;
|
||||
ChartHelper.HideAllObject(m_MarkLineLabelRoot);
|
||||
foreach (var serie in chart.series.list) InitMarkLine(serie);
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
var show = serie.show && serie.markLine.show;
|
||||
foreach (var data in serie.markLine.data)
|
||||
{
|
||||
if (data.runtimeLabel != null)
|
||||
{
|
||||
if (data.runtimeLabel.gameObject.activeSelf != show)
|
||||
data.runtimeLabel.gameObject.SetActive(show);
|
||||
if (show)
|
||||
{
|
||||
data.runtimeLabel.SetPosition(MarkLineHelper.GetLabelPosition(data));
|
||||
data.runtimeLabel.SetText(MarkLineHelper.GetFormatterContent(serie, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitMarkLine(Serie serie)
|
||||
{
|
||||
if (!serie.show || !serie.markLine.show) return;
|
||||
ResetTempMarkLineGroupData(serie.markLine);
|
||||
var serieColor = (Color)chart.theme.GetColor(chart.GetLegendRealShowNameIndex(serie.name));
|
||||
if (m_TempGroupData.Count > 0)
|
||||
{
|
||||
foreach (var kv in m_TempGroupData)
|
||||
{
|
||||
if (kv.Value.Count >= 2)
|
||||
{
|
||||
var data = kv.Value[0];
|
||||
InitMarkLineLabel(serie, data, serieColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var data in serie.markLine.data)
|
||||
{
|
||||
if (data.group != 0) continue;
|
||||
InitMarkLineLabel(serie, data, serieColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitMarkLineLabel(Serie serie, MarkLineData data, Color serieColor)
|
||||
{
|
||||
data.painter = chart.m_PainterTop;
|
||||
data.refreshComponent = delegate ()
|
||||
{
|
||||
var label = data.label;
|
||||
var textName = string.Format("markLine_{0}_{1}", serie.index, data.index);
|
||||
var color = !ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color : chart.theme.axis.textColor;
|
||||
var element = ChartHelper.AddSerieLabel(textName, m_MarkLineLabelRoot.transform, label.backgroundWidth,
|
||||
label.backgroundHeight, color, label.textStyle, chart.theme);
|
||||
var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0;
|
||||
var item = new ChartLabel();
|
||||
item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom);
|
||||
item.SetIconActive(false);
|
||||
item.SetActive(data.label.show);
|
||||
item.SetPosition(MarkLineHelper.GetLabelPosition(data));
|
||||
item.SetText(MarkLineHelper.GetFormatterContent(serie, data));
|
||||
data.runtimeLabel = item;
|
||||
};
|
||||
data.refreshComponent();
|
||||
}
|
||||
|
||||
private void DrawMarkLine(VertexHelper vh)
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
DrawMarkLine(vh, serie);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<int, List<MarkLineData>> m_TempGroupData = new Dictionary<int, List<MarkLineData>>();
|
||||
private void DrawMarkLine(VertexHelper vh, Serie serie)
|
||||
{
|
||||
if (!serie.show || !serie.markLine.show) return;
|
||||
if (serie.markLine.data.Count == 0) return;
|
||||
var yAxis = chart.GetSerieYAxisOrDefault(serie);
|
||||
var xAxis = chart.GetSerieXAxisOrDefault(serie);
|
||||
var grid = chart.GetSerieGridOrDefault(serie);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, chart.dataZooms);
|
||||
var animation = serie.markLine.animation;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
var sp = Vector3.zero;
|
||||
var ep = Vector3.zero;
|
||||
var colorIndex = chart.GetLegendRealShowNameIndex(serie.name);
|
||||
var serieColor = SerieHelper.GetLineColor(serie, chart.theme, colorIndex, false);
|
||||
animation.InitProgress(1, 0, 1f);
|
||||
ResetTempMarkLineGroupData(serie.markLine);
|
||||
if (m_TempGroupData.Count > 0)
|
||||
{
|
||||
foreach (var kv in m_TempGroupData)
|
||||
{
|
||||
if (kv.Value.Count >= 2)
|
||||
{
|
||||
sp = GetSinglePos(xAxis, yAxis, grid, serie, dataZoom, kv.Value[0], showData.Count);
|
||||
ep = GetSinglePos(xAxis, yAxis, grid, serie, dataZoom, kv.Value[1], showData.Count);
|
||||
kv.Value[0].runtimeStartPosition = sp;
|
||||
kv.Value[1].runtimeEndPosition = ep;
|
||||
DrawMakLineData(vh, kv.Value[0], animation, serie, grid, serieColor, sp, ep);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var data in serie.markLine.data)
|
||||
{
|
||||
if (data.group != 0) continue;
|
||||
switch (data.type)
|
||||
{
|
||||
case MarkLineType.Min:
|
||||
data.runtimeValue = SerieHelper.GetMinData(serie, data.dimension, dataZoom);
|
||||
GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
|
||||
break;
|
||||
case MarkLineType.Max:
|
||||
data.runtimeValue = SerieHelper.GetMaxData(serie, data.dimension, dataZoom);
|
||||
GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
|
||||
break;
|
||||
case MarkLineType.Average:
|
||||
data.runtimeValue = SerieHelper.GetAverageData(serie, data.dimension, dataZoom);
|
||||
GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
|
||||
break;
|
||||
case MarkLineType.Median:
|
||||
data.runtimeValue = SerieHelper.GetMedianData(serie, data.dimension, dataZoom);
|
||||
GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
|
||||
break;
|
||||
case MarkLineType.None:
|
||||
if (data.xPosition != 0)
|
||||
{
|
||||
data.runtimeValue = data.xPosition;
|
||||
var pX = grid.runtimeX + data.xPosition;
|
||||
sp = new Vector3(pX, grid.runtimeY);
|
||||
ep = new Vector3(pX, grid.runtimeY + grid.runtimeHeight);
|
||||
}
|
||||
else if (data.yPosition != 0)
|
||||
{
|
||||
data.runtimeValue = data.yPosition;
|
||||
var pY = grid.runtimeY + data.yPosition;
|
||||
sp = new Vector3(grid.runtimeX, pY);
|
||||
ep = new Vector3(grid.runtimeX + grid.runtimeWidth, pY);
|
||||
}
|
||||
else if (data.yValue != 0)
|
||||
{
|
||||
data.runtimeValue = data.yValue;
|
||||
if (yAxis.IsCategory())
|
||||
{
|
||||
var pY = AxisHelper.GetAxisPosition(grid, yAxis, data.yValue, showData.Count, dataZoom);
|
||||
sp = new Vector3(grid.runtimeX, pY);
|
||||
ep = new Vector3(grid.runtimeX + grid.runtimeWidth, pY);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetStartEndPos(xAxis, yAxis, grid, data.yValue, ref sp, ref ep);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data.runtimeValue = data.xValue;
|
||||
if (xAxis.IsCategory())
|
||||
{
|
||||
var pX = AxisHelper.GetAxisPosition(grid, xAxis, data.xValue, showData.Count, dataZoom);
|
||||
sp = new Vector3(pX, grid.runtimeY);
|
||||
ep = new Vector3(pX, grid.runtimeY + grid.runtimeHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetStartEndPos(xAxis, yAxis, grid, data.xValue, ref sp, ref ep);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
data.runtimeStartPosition = sp;
|
||||
data.runtimeEndPosition = ep;
|
||||
DrawMakLineData(vh, data, animation, serie, grid, serieColor, sp, ep);
|
||||
}
|
||||
if (!animation.IsFinish())
|
||||
{
|
||||
animation.CheckProgress(1f);
|
||||
chart.RefreshTopPainter();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetTempMarkLineGroupData(MarkLine markLine)
|
||||
{
|
||||
m_TempGroupData.Clear();
|
||||
for (int i = 0; i < markLine.data.Count; i++)
|
||||
{
|
||||
var data = markLine.data[i];
|
||||
data.index = i;
|
||||
if (data.group == 0) continue;
|
||||
if (!m_TempGroupData.ContainsKey(data.group))
|
||||
{
|
||||
m_TempGroupData[data.group] = new List<MarkLineData>();
|
||||
}
|
||||
m_TempGroupData[data.group].Add(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMakLineData(VertexHelper vh, MarkLineData data, SerieAnimation animation, Serie serie,
|
||||
Grid grid, Color32 serieColor, Vector3 sp, Vector3 ep)
|
||||
{
|
||||
if (!animation.IsFinish())
|
||||
ep = Vector3.Lerp(sp, ep, animation.GetCurrDetail());
|
||||
data.runtimeCurrentEndPosition = ep;
|
||||
if (sp != Vector3.zero || ep != Vector3.zero)
|
||||
{
|
||||
chart.ClampInChart(ref sp);
|
||||
chart.ClampInChart(ref ep);
|
||||
var theme = chart.theme.axis;
|
||||
var lineColor = ChartHelper.IsClearColor(data.lineStyle.color) ? serieColor : data.lineStyle.color;
|
||||
var lineWidth = data.lineStyle.width == 0 ? theme.lineWidth : data.lineStyle.width;
|
||||
ChartDrawer.DrawLineStyle(vh, data.lineStyle, sp, ep, lineWidth, LineStyle.Type.Dashed, lineColor, lineColor);
|
||||
if (data.startSymbol != null && data.startSymbol.show)
|
||||
{
|
||||
DrawMarkLineSymbol(vh, data.startSymbol, serie, grid, chart.theme, sp, sp, lineColor);
|
||||
}
|
||||
if (data.endSymbol != null && data.endSymbol.show)
|
||||
{
|
||||
DrawMarkLineSymbol(vh, data.endSymbol, serie, grid, chart.theme, ep, sp, lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMarkLineSymbol(VertexHelper vh, SerieSymbol symbol, Serie serie, Grid grid, ChartTheme theme,
|
||||
Vector3 pos, Vector3 startPos, Color32 lineColor)
|
||||
{
|
||||
var symbolSize = symbol.GetSize(null, theme.serie.lineSymbolSize);
|
||||
var tickness = SerieHelper.GetSymbolBorder(serie, null, theme, false);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, null, false);
|
||||
chart.Internal_CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, tickness, pos, lineColor, lineColor,
|
||||
ColorUtil.clearColor32, symbol.gap, true, cornerRadius, grid, startPos);
|
||||
}
|
||||
|
||||
private void GetStartEndPos(Axis xAxis, Axis yAxis, Grid grid, double value, ref Vector3 sp, ref Vector3 ep)
|
||||
{
|
||||
if (xAxis.IsCategory())
|
||||
{
|
||||
var pY = AxisHelper.GetAxisPosition(grid, yAxis, value);
|
||||
sp = new Vector3(grid.runtimeX, pY);
|
||||
ep = new Vector3(grid.runtimeX + grid.runtimeWidth, pY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pX = AxisHelper.GetAxisPosition(grid, xAxis, value);
|
||||
sp = new Vector3(pX, grid.runtimeY);
|
||||
ep = new Vector3(pX, grid.runtimeY + grid.runtimeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetAxisPosition(Grid grid, Axis axis, DataZoom dataZoom, int dataCount, double value)
|
||||
{
|
||||
return AxisHelper.GetAxisPosition(grid, axis, value, dataCount, dataZoom);
|
||||
}
|
||||
|
||||
private Vector3 GetSinglePos(Axis xAxis, Axis yAxis, Grid grid, Serie serie, DataZoom dataZoom, MarkLineData data,
|
||||
int serieDataCount)
|
||||
{
|
||||
switch (data.type)
|
||||
{
|
||||
case MarkLineType.Min:
|
||||
var serieData = SerieHelper.GetMinSerieData(serie, data.dimension, dataZoom);
|
||||
data.runtimeValue = serieData.GetData(data.dimension);
|
||||
var pX = GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, serieData.index);
|
||||
var pY = GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.runtimeValue);
|
||||
return new Vector3(pX, pY);
|
||||
case MarkLineType.Max:
|
||||
serieData = SerieHelper.GetMaxSerieData(serie, data.dimension, dataZoom);
|
||||
data.runtimeValue = serieData.GetData(data.dimension);
|
||||
pX = GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, serieData.index);
|
||||
pY = GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.runtimeValue);
|
||||
return new Vector3(pX, pY);
|
||||
case MarkLineType.None:
|
||||
if (data.zeroPosition)
|
||||
{
|
||||
data.runtimeValue = 0;
|
||||
return grid.runtimePosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
pX = data.xPosition != 0 ? grid.runtimeX + data.xPosition :
|
||||
GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, data.xValue);
|
||||
pY = data.yPosition != 0 ? grid.runtimeY + data.yPosition :
|
||||
GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.yValue);
|
||||
data.runtimeValue = data.yValue;
|
||||
return new Vector3(pX, pY);
|
||||
}
|
||||
default:
|
||||
return grid.runtimePosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class MarkLineHelper
|
||||
{
|
||||
public static string GetFormatterContent(Serie serie, MarkLineData data)
|
||||
{
|
||||
var serieLabel = data.label;
|
||||
var numericFormatter = serieLabel.numericFormatter;
|
||||
if (serieLabel.formatterFunction != null)
|
||||
{
|
||||
return serieLabel.formatterFunction(data.index, data.runtimeValue);
|
||||
}
|
||||
if (string.IsNullOrEmpty(serieLabel.formatter))
|
||||
return ChartCached.NumberToStr(data.runtimeValue, numericFormatter);
|
||||
else
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, data.runtimeValue,
|
||||
0, serie.name, data.name, Color.clear);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetLabelPosition(MarkLineData data)
|
||||
{
|
||||
if (!data.label.show) return Vector3.zero;
|
||||
var dir = (data.runtimeEndPosition - data.runtimeStartPosition).normalized;
|
||||
var horizontal = Mathf.Abs(Vector3.Dot(dir, Vector3.right)) == 1;
|
||||
var labelWidth = data.runtimeLabel == null ? 50 : data.runtimeLabel.GetLabelWidth();
|
||||
var labelHeight = data.runtimeLabel == null ? 20 : data.runtimeLabel.GetLabelHeight();
|
||||
switch (data.label.position)
|
||||
{
|
||||
case SerieLabel.Position.Start:
|
||||
if (horizontal) return data.runtimeStartPosition + data.label.offset + labelWidth / 2 * Vector3.left;
|
||||
else return data.runtimeStartPosition + data.label.offset + labelHeight / 2 * Vector3.down;
|
||||
case SerieLabel.Position.Middle:
|
||||
var center = (data.runtimeStartPosition + data.runtimeCurrentEndPosition) / 2;
|
||||
if (horizontal) return center + data.label.offset + labelHeight / 2 * Vector3.up;
|
||||
else return center + data.label.offset + labelWidth / 2 * Vector3.right;
|
||||
default:
|
||||
if (horizontal) return data.runtimeCurrentEndPosition + data.label.offset + labelWidth / 2 * Vector3.right;
|
||||
else return data.runtimeCurrentEndPosition + data.label.offset + labelHeight / 2 * Vector3.up;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Runtime/Component/Sub/MarkLine.cs.meta
Normal file
11
Assets/XCharts/Runtime/Component/Sub/MarkLine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd9631fa54e73444884c717bd04765a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -35,6 +35,7 @@ namespace XCharts
|
||||
[SerializeField] private bool m_DataChangeEnable = true;
|
||||
[SerializeField] private float m_DataChangeDuration = 500;
|
||||
[SerializeField] private float m_ActualDuration;
|
||||
[SerializeField] private bool m_AlongWithLinePath;
|
||||
/// <summary>
|
||||
/// 自定义渐入动画延时函数。返回ms值。
|
||||
/// </summary>
|
||||
@@ -101,6 +102,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public float dataChangeDuration { get { return m_DataChangeDuration; } set { m_DataChangeDuration = value < 0 ? 0 : value; } }
|
||||
/// <summary>
|
||||
/// 是否沿着线的轨迹进行匀速动画。
|
||||
/// </summary>
|
||||
public bool alongWithLinePath { get { return m_AlongWithLinePath; } set { m_AlongWithLinePath = value; } }
|
||||
/// <summary>
|
||||
/// 渐入动画完成回调
|
||||
/// </summary>
|
||||
public Action fadeInFinishCallback { get; set; }
|
||||
@@ -123,6 +128,8 @@ namespace XCharts
|
||||
[SerializeField] private float m_CurrDetailProgress;
|
||||
[SerializeField] private float m_DestDetailProgress;
|
||||
private float m_CurrSymbolProgress;
|
||||
private Vector3 m_LinePathLastPos;
|
||||
private float m_LinePathCurrTotalDist = 0f;
|
||||
|
||||
public void FadeIn()
|
||||
{
|
||||
@@ -343,11 +350,29 @@ namespace XCharts
|
||||
return !IsFinish() && detail > m_CurrDetailProgress;
|
||||
}
|
||||
|
||||
public void SetLinePathStartPos(Vector3 pos)
|
||||
{
|
||||
if (m_AlongWithLinePath)
|
||||
{
|
||||
m_LinePathLastPos = pos;
|
||||
m_LinePathCurrTotalDist = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckDetailBreak(Vector3 pos, bool isYAxis)
|
||||
{
|
||||
if (IsFinish()) return false;
|
||||
if (isYAxis) return pos.y > m_CurrDetailProgress;
|
||||
else return pos.x > m_CurrDetailProgress;
|
||||
if (m_AlongWithLinePath)
|
||||
{
|
||||
m_LinePathCurrTotalDist += Vector3.Distance(pos, m_LinePathLastPos);
|
||||
m_LinePathLastPos = pos;
|
||||
return CheckDetailBreak(m_LinePathCurrTotalDist);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isYAxis) return pos.y > m_CurrDetailProgress;
|
||||
else return pos.x > m_CurrDetailProgress;
|
||||
}
|
||||
}
|
||||
|
||||
public bool NeedAnimation(int dataIndex)
|
||||
@@ -358,14 +383,14 @@ namespace XCharts
|
||||
else return dataIndex <= m_CurrDataProgress;
|
||||
}
|
||||
|
||||
internal void CheckProgress(float total)
|
||||
internal void CheckProgress(double total)
|
||||
{
|
||||
if (IsFinish()) return;
|
||||
if (!m_IsInit || m_IsPause || m_IsEnd) return;
|
||||
if (IsInDelay()) return;
|
||||
m_ActualDuration = (int)((Time.time - startTime) * 1000) - fadeInDelay;
|
||||
var duration = GetCurrAnimationDuration();
|
||||
var delta = total / duration * Time.deltaTime;
|
||||
var delta = (float)(total / duration * Time.deltaTime);
|
||||
if (m_FadeOut)
|
||||
{
|
||||
m_CurrDetailProgress -= delta;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -17,10 +18,14 @@ namespace XCharts
|
||||
[System.Serializable]
|
||||
public class SerieData : SubComponent
|
||||
{
|
||||
[SerializeField] private int m_Index;
|
||||
[SerializeField] private int m_ParentIndex = -1;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Id;
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private bool m_Ignore = false;
|
||||
[SerializeField] private float m_Radius;
|
||||
[SerializeField] private bool m_EnableIconStyle = false;
|
||||
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||
[SerializeField] private bool m_EnableLabel = false;
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
@@ -30,20 +35,26 @@ namespace XCharts
|
||||
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
|
||||
[SerializeField] private bool m_EnableSymbol = false;
|
||||
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
||||
[SerializeField] private List<float> m_Data = new List<float>();
|
||||
[SerializeField] private List<double> m_Data = new List<double>();
|
||||
[SerializeField] private List<int> m_Children = new List<int>();
|
||||
|
||||
public ChartLabel labelObject { get; set; }
|
||||
|
||||
private bool m_Show = true;
|
||||
private float m_RtPieOutsideRadius;
|
||||
|
||||
public int index { get; set; }
|
||||
public int index { get { return m_Index; } set { m_Index = value; } }
|
||||
public int parentIndex { get { return m_ParentIndex; } set { m_ParentIndex = value; } }
|
||||
/// <summary>
|
||||
/// the name of data item.
|
||||
/// 数据项名称。
|
||||
/// </summary>
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
/// <summary>
|
||||
/// 数据项的唯一id。唯一id不是必须设置的。
|
||||
/// </summary>
|
||||
public string id { get { return m_Id; } set { m_Id = value; } }
|
||||
/// <summary>
|
||||
/// 数据项图例名称。当数据项名称不为空时,图例名称即为系列名称;反之则为索引index。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
@@ -58,6 +69,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
/// <summary>
|
||||
/// 是否启用单个数据项的图标设置。
|
||||
/// </summary>
|
||||
public bool enableIconStyle { get { return m_EnableIconStyle; } set { m_EnableIconStyle = value; } }
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// 数据项图标样式。
|
||||
/// </summary>
|
||||
@@ -106,7 +121,8 @@ namespace XCharts
|
||||
/// An arbitrary dimension data list of data item.
|
||||
/// 可指定任意维数的数值列表。
|
||||
/// </summary>
|
||||
public List<float> data { get { return m_Data; } set { m_Data = value; } }
|
||||
public List<double> data { get { return m_Data; } set { m_Data = value; } }
|
||||
public List<int> children { get { return m_Children; } set { m_Children = value; } }
|
||||
/// <summary>
|
||||
/// [default:true] Whether the data item is showed.
|
||||
/// 该数据项是否要显示。
|
||||
@@ -123,40 +139,7 @@ namespace XCharts
|
||||
/// 是否可以显示Label
|
||||
/// </summary>
|
||||
public bool canShowLabel { get { return m_CanShowLabel; } set { m_CanShowLabel = value; } }
|
||||
/// <summary>
|
||||
/// the maxinum value.
|
||||
/// 最大值。
|
||||
/// </summary>
|
||||
public float max
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Data.Count == 0) return 0;
|
||||
float temp = float.MinValue;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
if (m_Data[i] > temp) temp = m_Data[i];
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// the mininum value.
|
||||
/// 最小值。
|
||||
/// </summary>
|
||||
public float min
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Data.Count == 0) return 0;
|
||||
float temp = float.MaxValue;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
if (m_Data[i] < temp) temp = m_Data[i];
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 饼图数据项的开始角度(运行时自动计算)
|
||||
/// </summary>
|
||||
@@ -201,23 +184,35 @@ namespace XCharts
|
||||
/// 绘制区域。
|
||||
/// </summary>
|
||||
public Rect runtimeRect { get; set; }
|
||||
public Rect runtimeSubRect { get; set; }
|
||||
public int runtimeLevel { get; set; }
|
||||
public SerieData runtimeParent { get; set; }
|
||||
public Color32 runtimeColor { get; set; }
|
||||
public double runtimeArea { get; set; }
|
||||
public float runtimeAngle { get; set; }
|
||||
public Vector3 runtiemPieOffsetCenter { get; set; }
|
||||
public float runtimeStackHig { get; set; }
|
||||
private List<float> m_PreviousData = new List<float>();
|
||||
public Image runtimeSymbol { get; set; }
|
||||
public List<SerieData> runtimeChildren { get { return m_RuntimeChildren; } }
|
||||
|
||||
private List<double> m_PreviousData = new List<double>();
|
||||
private List<float> m_DataUpdateTime = new List<float>();
|
||||
private List<bool> m_DataUpdateFlag = new List<bool>();
|
||||
private List<Vector2> m_PolygonPoints = new List<Vector2>();
|
||||
[System.NonSerialized]
|
||||
private List<SerieData> m_RuntimeChildren = new List<SerieData>();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
index = 0;
|
||||
m_ParentIndex = -1;
|
||||
labelObject = null;
|
||||
highlighted = false;
|
||||
m_Name = string.Empty;
|
||||
m_Show = true;
|
||||
m_Selected = false;
|
||||
m_CanShowLabel = true;
|
||||
m_EnableIconStyle = false;
|
||||
m_EnableSymbol = false;
|
||||
m_EnableLabel = false;
|
||||
m_EnableEmphasis = false;
|
||||
@@ -225,6 +220,8 @@ namespace XCharts
|
||||
m_Radius = 0;
|
||||
m_Data.Clear();
|
||||
m_PreviousData.Clear();
|
||||
m_PolygonPoints.Clear();
|
||||
m_RuntimeChildren.Clear();
|
||||
m_DataUpdateTime.Clear();
|
||||
m_DataUpdateFlag.Clear();
|
||||
m_IconStyle.Reset();
|
||||
@@ -233,7 +230,7 @@ namespace XCharts
|
||||
m_Emphasis.Reset();
|
||||
}
|
||||
|
||||
public float GetData(int index, bool inverse = false)
|
||||
public double GetData(int index, bool inverse = false)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
@@ -242,7 +239,7 @@ namespace XCharts
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetData(int index, float min, float max)
|
||||
public double GetData(int index, double min, double max)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
@@ -254,7 +251,7 @@ namespace XCharts
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetPreviousData(int index, bool inverse = false)
|
||||
public double GetPreviousData(int index, bool inverse = false)
|
||||
{
|
||||
if (index >= 0 && index < m_PreviousData.Count)
|
||||
{
|
||||
@@ -263,24 +260,24 @@ namespace XCharts
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetFirstData(float animationDuration = 500f)
|
||||
public double GetFirstData(float animationDuration = 500f)
|
||||
{
|
||||
if (m_Data.Count > 0) return GetCurrData(0, animationDuration);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetLastData()
|
||||
public double GetLastData()
|
||||
{
|
||||
if (m_Data.Count > 0) return m_Data[m_Data.Count - 1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetCurrData(int index, float animationDuration = 500f, bool inverse = false)
|
||||
public double GetCurrData(int index, float animationDuration = 500f, bool inverse = false)
|
||||
{
|
||||
return GetCurrData(index, animationDuration, inverse, 0, 0);
|
||||
}
|
||||
|
||||
public float GetCurrData(int index, float animationDuration, bool inverse, float min, float max)
|
||||
public double GetCurrData(int index, float animationDuration, bool inverse, double min, double max)
|
||||
{
|
||||
if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0)
|
||||
{
|
||||
@@ -292,7 +289,7 @@ namespace XCharts
|
||||
if (rate < 1)
|
||||
{
|
||||
CheckLastData();
|
||||
var curr = Mathf.Lerp(GetPreviousData(index), GetData(index), rate);
|
||||
var curr = MathUtil.Lerp(GetPreviousData(index), GetData(index), rate);
|
||||
if (min != 0 || max != 0)
|
||||
{
|
||||
if (inverse)
|
||||
@@ -328,7 +325,39 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateData(int dimension, float value, bool updateAnimation, float animationDuration = 500f)
|
||||
/// <summary>
|
||||
/// the maxinum value.
|
||||
/// 最大值。
|
||||
/// </summary>
|
||||
public double GetMaxData(bool inverse = false)
|
||||
{
|
||||
if (m_Data.Count == 0) return 0;
|
||||
var temp = double.MinValue;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
var value = GetData(i, inverse);
|
||||
if (value > temp) temp = value;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the mininum value.
|
||||
/// 最小值。
|
||||
/// </summary>
|
||||
public double GetMinData(bool inverse = false)
|
||||
{
|
||||
if (m_Data.Count == 0) return 0;
|
||||
var temp = double.MaxValue;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
var value = GetData(i, inverse);
|
||||
if (value < temp) temp = value;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
public bool UpdateData(int dimension, double value, bool updateAnimation, float animationDuration = 500f)
|
||||
{
|
||||
if (dimension >= 0 && dimension < data.Count)
|
||||
{
|
||||
@@ -343,6 +372,16 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool UpdateData(int dimension, double value)
|
||||
{
|
||||
if (dimension >= 0 && dimension < data.Count)
|
||||
{
|
||||
data[dimension] = value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CheckLastData()
|
||||
{
|
||||
if (m_PreviousData.Count != m_Data.Count)
|
||||
@@ -382,6 +421,10 @@ namespace XCharts
|
||||
{
|
||||
if (labelObject != null) labelObject.SetLabelActive(flag);
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
if (labelObject != null) labelObject.SetIconActive(flag);
|
||||
}
|
||||
|
||||
public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
|
||||
{
|
||||
|
||||
@@ -58,6 +58,21 @@ namespace XCharts
|
||||
/// 图形标志的右边。
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// the start of line.
|
||||
/// 线的起始点。
|
||||
/// </summary>
|
||||
Start,
|
||||
/// <summary>
|
||||
/// the middle of line.
|
||||
/// 线的中点。
|
||||
/// </summary>
|
||||
Middle,
|
||||
/// <summary>
|
||||
/// the end of line.
|
||||
/// 线的结束点。
|
||||
/// </summary>
|
||||
End
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,6 +115,7 @@ namespace XCharts
|
||||
[SerializeField] private string m_NumericFormatter = "";
|
||||
[SerializeField] private bool m_AutoOffset = false;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
private DelegateSerieLabelFormatter m_FormatterFunction;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
@@ -337,6 +353,12 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
|
||||
}
|
||||
|
||||
public DelegateSerieLabelFormatter formatterFunction
|
||||
{
|
||||
get { return m_FormatterFunction; }
|
||||
set { m_FormatterFunction = value; }
|
||||
}
|
||||
|
||||
public bool IsInside()
|
||||
{
|
||||
return position == Position.Inside || position == Position.Center;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -40,6 +41,17 @@ namespace XCharts
|
||||
/// 不显示标记。
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 箭头。
|
||||
/// </summary>
|
||||
Arrow,
|
||||
/// <summary>
|
||||
/// 自定义标记。
|
||||
/// </summary>
|
||||
Custom,
|
||||
EmptyRect,
|
||||
EmptyTriangle,
|
||||
EmptyDiamond
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,7 +82,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public delegate float SymbolSizeCallback(List<float> data);
|
||||
public delegate float SymbolSizeCallback(List<double> data);
|
||||
|
||||
/// <summary>
|
||||
/// 系列数据项的标记的图形
|
||||
@@ -92,6 +104,12 @@ namespace XCharts
|
||||
[SerializeField] private int m_Interval;
|
||||
[SerializeField] private bool m_ForceShowLast = false;
|
||||
[SerializeField] private float m_Gap = 0;
|
||||
[SerializeField] private float m_Width = 0f;
|
||||
[SerializeField] private float m_Height = 0f;
|
||||
[SerializeField] private bool m_Repeat = false;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
[SerializeField] private Sprite m_Image;
|
||||
[SerializeField] private Image.Type m_ImageType;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
@@ -109,6 +127,12 @@ namespace XCharts
|
||||
m_Interval = 0;
|
||||
m_ForceShowLast = false;
|
||||
m_Gap = 0;
|
||||
m_Width = 0f;
|
||||
m_Height = 0f;
|
||||
m_Repeat = false;
|
||||
m_Offset = Vector2.zero;
|
||||
m_Image = null;
|
||||
m_ImageType = Image.Type.Simple;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -237,6 +261,52 @@ namespace XCharts
|
||||
get { return m_Gap; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图形的宽。
|
||||
/// </summary>
|
||||
public float width
|
||||
{
|
||||
get { return m_Width; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图形的高。
|
||||
/// </summary>
|
||||
public float height
|
||||
{
|
||||
get { return m_Height; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图形是否重复。
|
||||
/// </summary>
|
||||
public bool repeat
|
||||
{
|
||||
get { return m_Repeat; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Repeat, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 自定义的标记图形。
|
||||
/// </summary>
|
||||
public Sprite image
|
||||
{
|
||||
get { return m_Image; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Image, value)) SetAllDirty(); }
|
||||
}
|
||||
public Image.Type imageType
|
||||
{
|
||||
get { return m_ImageType; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图形的偏移。
|
||||
/// </summary>
|
||||
public Vector2 offset
|
||||
{
|
||||
get { return m_Offset; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
|
||||
}
|
||||
public Vector3 offset3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
|
||||
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
|
||||
/// <summary>
|
||||
/// the setting for effect scatter.
|
||||
@@ -249,7 +319,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public float GetSize(List<float> data, float themeSize)
|
||||
public float GetSize(List<double> data, float themeSize)
|
||||
{
|
||||
switch (m_SizeType)
|
||||
{
|
||||
@@ -258,7 +328,7 @@ namespace XCharts
|
||||
case SerieSymbolSizeType.FromData:
|
||||
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
|
||||
{
|
||||
return data[dataIndex] * m_DataScale;
|
||||
return (float)data[dataIndex] * m_DataScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -276,7 +346,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public float GetSelectedSize(List<float> data, float themeSelectedSize)
|
||||
public float GetSelectedSize(List<double> data, float themeSelectedSize)
|
||||
{
|
||||
switch (m_SizeType)
|
||||
{
|
||||
@@ -285,7 +355,7 @@ namespace XCharts
|
||||
case SerieSymbolSizeType.FromData:
|
||||
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
|
||||
{
|
||||
return data[dataIndex] * m_SelectedDataScale;
|
||||
return (float)data[dataIndex] * m_SelectedDataScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace XCharts
|
||||
[Serializable]
|
||||
public class TextLimit : SubComponent
|
||||
{
|
||||
[SerializeField] private bool m_Enable = true;
|
||||
[SerializeField] private bool m_Enable = false;
|
||||
[SerializeField] private float m_MaxWidth = 0;
|
||||
[SerializeField] private float m_Gap = 1;
|
||||
[SerializeField] private string m_Suffix = "...";
|
||||
|
||||
@@ -47,6 +47,10 @@ namespace XCharts
|
||||
{
|
||||
[SerializeField] private Theme m_Theme = Theme.Default;
|
||||
[SerializeField] private string m_ThemeName = Theme.Default.ToString();
|
||||
[SerializeField] private string m_FontName;
|
||||
[SerializeField] private string m_TMPFontName;
|
||||
[SerializeField] private int m_FontInstacneId;
|
||||
[SerializeField] private int m_TMPFontInstanceId;
|
||||
[SerializeField] private Font m_Font;
|
||||
#if dUI_TextMeshPro
|
||||
[SerializeField] private TMP_FontAsset m_TMPFont;
|
||||
@@ -75,6 +79,12 @@ namespace XCharts
|
||||
[SerializeField] private VisualMapTheme m_VisualMap;
|
||||
[SerializeField] private SerieTheme m_Serie;
|
||||
|
||||
private ChartTheme()
|
||||
{
|
||||
m_FontName = "Arial";
|
||||
m_TMPFontName = "LiberationSans SDF";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the theme of chart.
|
||||
/// 主题类型。
|
||||
@@ -110,6 +120,27 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public string fontName
|
||||
{
|
||||
get { return m_FontName; }
|
||||
set { if (PropertyUtil.SetClass(ref m_FontName, value)) SetComponentDirty(); }
|
||||
}
|
||||
public int fontInstanceId
|
||||
{
|
||||
get { return m_FontInstacneId; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_FontInstacneId, value)) SetComponentDirty(); }
|
||||
}
|
||||
public string tmpFontName
|
||||
{
|
||||
get { return m_TMPFontName; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TMPFontName, value)) SetComponentDirty(); }
|
||||
}
|
||||
public int tmpFontInstanceId
|
||||
{
|
||||
get { return m_TMPFontInstanceId; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_TMPFontInstanceId, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <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.
|
||||
/// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。
|
||||
@@ -139,11 +170,14 @@ namespace XCharts
|
||||
get { return m_TMPFont; }
|
||||
set
|
||||
{
|
||||
if (PropertyUtil.SetClass(ref m_TMPFont, value))
|
||||
m_TMPFont = value;
|
||||
if(value)
|
||||
{
|
||||
SetComponentDirty();
|
||||
SyncTMPFontToSubComponent();
|
||||
m_TMPFontName = value.name;
|
||||
m_TMPFontInstanceId = value.GetInstanceID();
|
||||
}
|
||||
SetComponentDirty();
|
||||
SyncTMPFontToSubComponent();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -156,11 +190,14 @@ namespace XCharts
|
||||
get { return m_Font; }
|
||||
set
|
||||
{
|
||||
if (PropertyUtil.SetClass(ref m_Font, value))
|
||||
m_Font = value;
|
||||
if (value)
|
||||
{
|
||||
SetComponentDirty();
|
||||
SyncFontToSubComponent();
|
||||
m_FontName = value.name;
|
||||
m_FontInstacneId = value.GetInstanceID();
|
||||
}
|
||||
SetComponentDirty();
|
||||
SyncFontToSubComponent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +227,19 @@ namespace XCharts
|
||||
else return Color.clear;
|
||||
}
|
||||
|
||||
public void SetColorPalette(List<Color32> colorList)
|
||||
{
|
||||
m_ColorPalette = colorList;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
public void SetColorPalette(List<string> hexColorStringList)
|
||||
{
|
||||
m_ColorPalette.Clear();
|
||||
foreach (var hexColor in hexColorStringList)
|
||||
m_ColorPalette.Add(ColorUtil.GetColor(hexColor));
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
public void CheckWarning(StringBuilder sb)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
@@ -262,9 +312,13 @@ namespace XCharts
|
||||
m_Theme = theme.theme;
|
||||
m_ThemeName = theme.themeName;
|
||||
#if dUI_TextMeshPro
|
||||
m_TMPFont = theme.tmpFont;
|
||||
tmpFont = theme.tmpFont;
|
||||
#endif
|
||||
m_Font = theme.m_Font;
|
||||
font = theme.font;
|
||||
m_FontName = theme.fontName;
|
||||
m_FontInstacneId = theme.fontInstanceId;
|
||||
m_TMPFontName = theme.tmpFontName;
|
||||
m_TMPFontInstanceId = theme.tmpFontInstanceId;
|
||||
m_ContrastColor = theme.contrastColor;
|
||||
m_BackgroundColor = theme.m_BackgroundColor;
|
||||
m_Common.Copy(theme.common);
|
||||
@@ -438,6 +492,22 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void SyncFontName()
|
||||
{
|
||||
if (font)
|
||||
{
|
||||
m_FontName = font.name;
|
||||
m_FontInstacneId = font.GetInstanceID();
|
||||
}
|
||||
#if dUI_TextMeshPro
|
||||
if (tmpFont)
|
||||
{
|
||||
m_TMPFontName = tmpFont.name;
|
||||
m_TMPFontInstanceId = tmpFont.GetInstanceID();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SyncFontToSubComponent()
|
||||
{
|
||||
common.font = font;
|
||||
|
||||
@@ -25,13 +25,13 @@ namespace XCharts
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// the font of text。
|
||||
/// the font of text.
|
||||
/// 字体。
|
||||
/// </summary>
|
||||
public Font font
|
||||
{
|
||||
get { return m_Font; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
|
||||
set { m_Font = value; SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
@@ -69,7 +69,7 @@ namespace XCharts
|
||||
public TMP_FontAsset tmpFont
|
||||
{
|
||||
get { return m_TMPFont; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
|
||||
set { m_TMPFont = value; SetComponentDirty(); }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace XCharts
|
||||
var rate = Random.Range(0, 101);
|
||||
if (rate > 70) value = Random.Range(8f, 10f);
|
||||
else value = Random.Range(1f, 8f);
|
||||
var list = new List<float> { i, j, value };
|
||||
var list = new List<double> { i, j, value };
|
||||
AddData(0, list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,14 +112,15 @@ namespace XCharts
|
||||
/// <param name="maxValue"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue,
|
||||
public static string GetLabelName(Axis axis, float coordinateWidth, int index, double minValue, double maxValue,
|
||||
DataZoom dataZoom, bool forcePercent)
|
||||
{
|
||||
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
if (axis.type == Axis.AxisType.Value)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
var value = 0f;
|
||||
if (minValue == 0 && maxValue == 0)
|
||||
maxValue = axis.max != 0 ? axis.max : 1;
|
||||
double value = 0;
|
||||
if (forcePercent) maxValue = 100;
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
@@ -138,7 +139,7 @@ namespace XCharts
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
if (forcePercent) return string.Format("{0}%", (int)value);
|
||||
else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue);
|
||||
else return axis.axisLabel.GetFormatterContent(index, value, minValue, maxValue);
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
@@ -150,12 +151,12 @@ namespace XCharts
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
return axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true);
|
||||
return axis.axisLabel.GetFormatterContent(index, value, minValue, maxValue, true);
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Time)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
var value = 0f;
|
||||
double value = 0;
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (index == split) value = maxValue;
|
||||
@@ -165,9 +166,7 @@ namespace XCharts
|
||||
{
|
||||
value = minValue + (maxValue - minValue) * index / split;
|
||||
}
|
||||
var timestamp = (int)value;
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp);
|
||||
return axis.axisLabel.GetFormatterDateTime(dateTime);
|
||||
return axis.axisLabel.GetFormatterDateTime(index, value);
|
||||
}
|
||||
var showData = axis.GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
@@ -181,12 +180,12 @@ namespace XCharts
|
||||
var residue = (dataCount - 1) - split * rate;
|
||||
var newIndex = residue + (index - 1) * rate;
|
||||
if (newIndex < 0) newIndex = 0;
|
||||
return axis.axisLabel.GetFormatterContent(showData[newIndex]);
|
||||
return axis.axisLabel.GetFormatterContent(newIndex, showData[newIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (axis.boundaryGap && coordinateWidth / dataCount > 5) return string.Empty;
|
||||
else return axis.axisLabel.GetFormatterContent(showData[0]);
|
||||
else return axis.axisLabel.GetFormatterContent(0, showData[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -194,12 +193,12 @@ namespace XCharts
|
||||
int newIndex = index * rate;
|
||||
if (newIndex < dataCount)
|
||||
{
|
||||
return axis.axisLabel.GetFormatterContent(showData[newIndex]);
|
||||
return axis.axisLabel.GetFormatterContent(newIndex, showData[newIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (axis.boundaryGap && coordinateWidth / dataCount > 5) return string.Empty;
|
||||
else return axis.axisLabel.GetFormatterContent(showData[dataCount - 1]);
|
||||
else return axis.axisLabel.GetFormatterContent(dataCount - 1, showData[dataCount - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,17 +214,21 @@ namespace XCharts
|
||||
if (splitNum == 0) return 0;
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
var data = axis.GetDataList(dataZoom);
|
||||
var dataCount = axis.GetDataList(dataZoom).Count;
|
||||
var scaleNum = 0;
|
||||
|
||||
if (axis.boundaryGap)
|
||||
{
|
||||
scaleNum = data.Count % splitNum == 0 ? splitNum + 1 : splitNum + 2;
|
||||
scaleNum = dataCount > 2 && dataCount % splitNum == 0
|
||||
? splitNum + 1
|
||||
: splitNum + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data.Count < splitNum) scaleNum = splitNum;
|
||||
else scaleNum = data.Count % splitNum == 0 ? splitNum : splitNum + 1;
|
||||
if (dataCount < splitNum) scaleNum = splitNum;
|
||||
else scaleNum = dataCount > 2 && dataCount % splitNum == 0
|
||||
? splitNum
|
||||
: splitNum + 1;
|
||||
}
|
||||
return scaleNum;
|
||||
}
|
||||
@@ -325,7 +328,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="minValue"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
public static void AdjustMinMaxValue(Axis axis, ref float minValue, ref float maxValue, bool needFormat, int ceilRate = 0)
|
||||
public static void AdjustMinMaxValue(Axis axis, ref double minValue, ref double maxValue, bool needFormat, int ceilRate = 0)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
@@ -398,7 +401,6 @@ namespace XCharts
|
||||
{
|
||||
if (!axis.show) return false;
|
||||
if (axis.IsCategory() && axis.GetDataList().Count <= 0) return false;
|
||||
else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
@@ -467,5 +469,26 @@ namespace XCharts
|
||||
}
|
||||
txt.SetLocalPosition(pos);
|
||||
}
|
||||
|
||||
public static float GetAxisPosition(Grid grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null)
|
||||
{
|
||||
var gridHeight = axis is YAxis ? grid.runtimeHeight : grid.runtimeWidth;
|
||||
var gridXY = axis is YAxis ? grid.runtimeY : grid.runtimeX;
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
if (dataCount == 0) dataCount = axis.data.Count;
|
||||
var categoryIndex = (int)value;
|
||||
var scaleWid = AxisHelper.GetDataWidth(axis, grid.runtimeHeight, dataCount, dataZoom);
|
||||
float startY = gridXY + (axis.boundaryGap ? scaleWid / 2 : 0);
|
||||
return startY + scaleWid * categoryIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
var yDataHig = (axis.runtimeMinMaxRange == 0) ? 0f :
|
||||
(float)((value - axis.runtimeMinValue) / axis.runtimeMinMaxRange * gridHeight);
|
||||
return gridXY + yDataHig;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,33 +5,81 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class DataZoomHelper
|
||||
{
|
||||
public static DataZoom GetDataZoom(Serie serie, List<DataZoom> dataZooms)
|
||||
public static DataZoom GetAxisRelatedDataZoom(Axis axis, List<DataZoom> dataZooms)
|
||||
{
|
||||
if(serie == null) return null;
|
||||
foreach (var dataZoom in dataZooms)
|
||||
{
|
||||
if (!dataZoom.enable) continue;
|
||||
if (dataZoom.IsContainsXAxis(serie.xAxisIndex)
|
||||
|| dataZoom.IsContainsYAxis(serie.yAxisIndex))
|
||||
{
|
||||
return dataZoom;
|
||||
}
|
||||
if (dataZoom.IsContainsAxis(axis)) return dataZoom;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void GetSerieRelatedDataZoom(Serie serie, List<DataZoom> dataZooms,
|
||||
out DataZoom xDataZoom, out DataZoom yDataZoom)
|
||||
{
|
||||
xDataZoom = null;
|
||||
yDataZoom = null;
|
||||
if (serie == null) return;
|
||||
foreach (var dataZoom in dataZooms)
|
||||
{
|
||||
if (!dataZoom.enable) continue;
|
||||
if (dataZoom.IsContainsXAxis(serie.xAxisIndex))
|
||||
{
|
||||
xDataZoom = dataZoom;
|
||||
}
|
||||
if (dataZoom.IsContainsYAxis(serie.yAxisIndex))
|
||||
{
|
||||
yDataZoom = dataZoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateDataZoomRuntimeStartEndValue(DataZoom dataZoom, Serie serie){
|
||||
if(dataZoom == null || serie == null) return;
|
||||
float min = 0;
|
||||
float max = 0;
|
||||
public static void UpdateDataZoomRuntimeStartEndValue(DataZoom dataZoom, Serie serie)
|
||||
{
|
||||
if (dataZoom == null || serie == null) return;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
SerieHelper.GetMinMaxData(serie, out min, out max, null);
|
||||
dataZoom.runtimeStartValue = min + (max-min) * dataZoom.start / 100;
|
||||
dataZoom.runtimeEndValue = min +(max-min) * dataZoom.end / 100;
|
||||
dataZoom.runtimeStartValue = min + (max - min) * dataZoom.start / 100;
|
||||
dataZoom.runtimeEndValue = min + (max - min) * dataZoom.end / 100;
|
||||
}
|
||||
|
||||
public static void UpdateDataZoomRuntimeStartEndValue(CoordinateChart chart, SerieType serieType)
|
||||
{
|
||||
foreach (var dataZoom in chart.dataZooms)
|
||||
{
|
||||
if (!dataZoom.enable) continue;
|
||||
double min = double.MaxValue;
|
||||
double max = double.MinValue;
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
if (!serie.show || serie.type != serieType) continue;
|
||||
if (!dataZoom.IsContainsXAxis(serie.xAxisIndex)) continue;
|
||||
var axis = chart.GetXAxis(serie.xAxisIndex);
|
||||
|
||||
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
{
|
||||
if (axis.min < min) min = axis.min;
|
||||
if (axis.max > max) max = axis.max;
|
||||
}
|
||||
else
|
||||
{
|
||||
double serieMinValue = 0;
|
||||
double serieMaxValue = 0;
|
||||
SerieHelper.GetMinMaxData(serie, out serieMinValue, out serieMaxValue, null, 2);
|
||||
if (serieMinValue < min) min = serieMinValue;
|
||||
if (serieMaxValue > max) max = serieMaxValue;
|
||||
}
|
||||
}
|
||||
dataZoom.runtimeStartValue = min + (max - min) * dataZoom.start / 100;
|
||||
dataZoom.runtimeEndValue = min + (max - min) * dataZoom.end / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace XCharts
|
||||
public static class FormatterHelper
|
||||
{
|
||||
public const string PH_NN = "\n";
|
||||
private static Regex s_Regex = new Regex(@"{([a-d|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_Regex = new Regex(@"{([a-e|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSub = new Regex(@"(0\.#*)|(\d+-\d+)|(\w+)|(\.)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexN = new Regex(@"^\d+", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexN_N = new Regex(@"\d+-\d+", RegexOptions.IgnoreCase);
|
||||
@@ -23,11 +23,11 @@ namespace XCharts
|
||||
private static Regex s_RegexNewLine = new Regex(@"[\\|/]+n|</br>|<br>|<br/>", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForAxisLabel = new Regex(@"{value(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForAxisLabel = new Regex(@"(value)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-d|\.](:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-d])|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-e|\.](:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-e])|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}。
|
||||
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}。
|
||||
/// </summary>
|
||||
/// <param name="content">要替换的字符串</param>
|
||||
/// <param name="dataIndex">选中的数据项serieData索引</param>
|
||||
@@ -84,15 +84,16 @@ namespace XCharts
|
||||
content = content.Replace(old, serie.name);
|
||||
}
|
||||
}
|
||||
else if (p == 'b' || p == 'B')
|
||||
else if (p == 'b' || p == 'B' || p == 'e' || p == 'E')
|
||||
{
|
||||
var bIndex = dataIndex;
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
var args1Str = args[1].ToString();
|
||||
if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str);
|
||||
if (s_RegexN.IsMatch(args1Str))
|
||||
bIndex = int.Parse(args1Str);
|
||||
}
|
||||
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
|
||||
var needCategory = (p != 'e' && p != 'E') && (serie.type == SerieType.Line || serie.type == SerieType.Bar);
|
||||
if (needCategory)
|
||||
{
|
||||
var category = (chart as CoordinateChart).GetTooltipCategory(dataIndex, serie, dataZoom);
|
||||
@@ -181,7 +182,7 @@ namespace XCharts
|
||||
return s_RegexNewLine.Replace(content.Trim(), PH_NN);
|
||||
}
|
||||
|
||||
public static void ReplaceAxisLabelContent(ref string content, string numericFormatter, float value)
|
||||
public static void ReplaceAxisLabelContent(ref string content, string numericFormatter, double value)
|
||||
{
|
||||
var mc = s_RegexForAxisLabel.Matches(content);
|
||||
foreach (var m in mc)
|
||||
@@ -213,7 +214,7 @@ namespace XCharts
|
||||
content = TrimAndReplaceLine(content);
|
||||
}
|
||||
|
||||
public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, float value, float total,
|
||||
public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, double value, double total,
|
||||
string serieName, string dataName, Color color)
|
||||
{
|
||||
var mc = s_RegexForSerieLabel.Matches(content);
|
||||
@@ -236,7 +237,7 @@ namespace XCharts
|
||||
{
|
||||
content = content.Replace(old, serieName);
|
||||
}
|
||||
else if (p == 'b' || p == 'B')
|
||||
else if (p == 'b' || p == 'B' || p == 'e' || p == 'E')
|
||||
{
|
||||
content = content.Replace(old, dataName);
|
||||
}
|
||||
@@ -245,8 +246,8 @@ namespace XCharts
|
||||
var isPercent = p == 'd' || p == 'D';
|
||||
if (isPercent)
|
||||
{
|
||||
var percent = total == 0 ? 0 : value / total * 100;
|
||||
content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter));
|
||||
if (total != 0)
|
||||
content = content.Replace(old, ChartCached.FloatToStr(value / total * 100, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -11,10 +11,14 @@ namespace XCharts
|
||||
{
|
||||
public static class LegendHelper
|
||||
{
|
||||
public static Color GetContentColor(Legend legend, ChartTheme theme, bool active)
|
||||
public static Color GetContentColor(int legendIndex, Legend legend, ChartTheme theme, bool active)
|
||||
{
|
||||
var textStyle = legend.textStyle;
|
||||
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
||||
if (active)
|
||||
{
|
||||
if (legend.textAutoColor) return theme.GetColor(legendIndex);
|
||||
else return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
||||
}
|
||||
else return theme.legend.unableColor;
|
||||
}
|
||||
|
||||
@@ -34,7 +38,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
|
||||
ChartTheme theme, string content, Color itemColor, bool active)
|
||||
ChartTheme theme, string content, Color itemColor, bool active, int legendIndex)
|
||||
{
|
||||
var objName = i + "_" + legendName;
|
||||
var anchorMin = new Vector2(0, 0.5f);
|
||||
@@ -43,7 +47,7 @@ namespace XCharts
|
||||
var sizeDelta = new Vector2(100, 30);
|
||||
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
|
||||
var textStyle = legend.textStyle;
|
||||
var contentColor = GetContentColor(legend, theme, active);
|
||||
var contentColor = GetContentColor(legendIndex, legend, theme, active);
|
||||
|
||||
var objAnchorMin = new Vector2(0, 1);
|
||||
var objAnchorMax = new Vector2(0, 1);
|
||||
|
||||
@@ -13,6 +13,115 @@ namespace XCharts
|
||||
{
|
||||
public static partial class SerieHelper
|
||||
{
|
||||
public static double GetMinData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
|
||||
{
|
||||
double min = double.MaxValue;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value < min && !serie.IsIgnoreValue(value)) min = value;
|
||||
}
|
||||
}
|
||||
return min == double.MaxValue ? 0 : min;
|
||||
}
|
||||
public static SerieData GetMinSerieData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
|
||||
{
|
||||
double min = double.MaxValue;
|
||||
SerieData minData = null;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value < min && !serie.IsIgnoreValue(value))
|
||||
{
|
||||
min = value;
|
||||
minData = serieData;
|
||||
}
|
||||
}
|
||||
}
|
||||
return minData;
|
||||
}
|
||||
public static double GetMaxData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
|
||||
{
|
||||
double max = double.MinValue;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value > max && !serie.IsIgnoreValue(value)) max = value;
|
||||
}
|
||||
}
|
||||
return max == double.MinValue ? 0 : max;
|
||||
}
|
||||
public static SerieData GetMaxSerieData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
|
||||
{
|
||||
double max = double.MinValue;
|
||||
SerieData maxData = null;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value > max && !serie.IsIgnoreValue(value))
|
||||
{
|
||||
max = value;
|
||||
maxData = serieData;
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxData;
|
||||
}
|
||||
|
||||
public static double GetAverageData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
|
||||
{
|
||||
double total = 0;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (!serie.IsIgnoreValue(value))
|
||||
total += value;
|
||||
}
|
||||
}
|
||||
return total != 0 ? total / dataList.Count : 0;
|
||||
}
|
||||
|
||||
private static List<double> s_TempList = new List<double>();
|
||||
public static double GetMedianData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
|
||||
{
|
||||
s_TempList.Clear();
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (!serie.IsIgnoreValue(value))
|
||||
s_TempList.Add(value);
|
||||
}
|
||||
}
|
||||
s_TempList.Sort();
|
||||
var n = s_TempList.Count;
|
||||
if (n % 2 == 0) return (s_TempList[n / 2] + s_TempList[n / 2 - 1]) / 2;
|
||||
else return s_TempList[n / 2];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum and minimum values of the specified dimension of a serie.
|
||||
/// 获得系列指定维数的最大最小值。
|
||||
@@ -22,11 +131,11 @@ namespace XCharts
|
||||
/// <param name="min">最小值</param>
|
||||
/// <param name="max">最大值</param>
|
||||
/// <param name="dataZoom">缩放组件,默认null</param>
|
||||
public static void GetMinMaxData(Serie serie, int dimension, out float min, out float max,
|
||||
public static void GetMinMaxData(Serie serie, int dimension, out double min, out double max,
|
||||
DataZoom dataZoom = null)
|
||||
{
|
||||
max = float.MinValue;
|
||||
min = float.MaxValue;
|
||||
max = double.MinValue;
|
||||
min = double.MaxValue;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
@@ -34,8 +143,11 @@ namespace XCharts
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
if (!serie.IsIgnoreValue(value))
|
||||
{
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,24 +160,29 @@ namespace XCharts
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
public static void GetMinMaxData(Serie serie, out float min, out float max, DataZoom dataZoom = null)
|
||||
public static void GetMinMaxData(Serie serie, out double min, out double max, DataZoom dataZoom = null, int dimension = 0)
|
||||
{
|
||||
max = float.MinValue;
|
||||
min = float.MaxValue;
|
||||
max = double.MinValue;
|
||||
min = double.MaxValue;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show)
|
||||
{
|
||||
var count = serie.showDataDimension > serieData.data.Count
|
||||
var count = 0;
|
||||
if (dimension > 0) count = dimension;
|
||||
else count = serie.showDataDimension > serieData.data.Count
|
||||
? serieData.data.Count
|
||||
: serie.showDataDimension;
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
var value = serieData.data[j];
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
if (!serie.IsIgnoreValue(value))
|
||||
{
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +235,7 @@ namespace XCharts
|
||||
serie.runtimeHeight = chartHeight - runtimeTop - runtimeBottom;
|
||||
serie.runtimeCenterPos = new Vector3(serie.runtimeX + serie.runtimeWidth / 2,
|
||||
serie.runtimeY + serie.runtimeHeight / 2);
|
||||
serie.runtimeRect = new Rect(serie.runtimeX, serie.runtimeY, serie.runtimeWidth, serie.runtimeHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -126,6 +244,7 @@ namespace XCharts
|
||||
serie.runtimeWidth = chartWidth;
|
||||
serie.runtimeHeight = chartHeight;
|
||||
serie.runtimeCenterPos = chartPosition + new Vector3(chartWidth / 2, chartHeight / 2);
|
||||
serie.runtimeRect = new Rect(serie.runtimeX, serie.runtimeY, serie.runtimeWidth, serie.runtimeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,6 +431,20 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static SerieLabel GetSerieEmphasisLabel(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableEmphasis && serieData.emphasis.show)
|
||||
return serieData.emphasis.label;
|
||||
else if (serie.emphasis.show) return serie.emphasis.label;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static IconStyle GetIconStyle(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (serieData.enableIconStyle) return serieData.iconStyle;
|
||||
else return serie.iconStyle;
|
||||
}
|
||||
|
||||
public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableSymbol) return serieData.symbol;
|
||||
@@ -404,7 +537,7 @@ namespace XCharts
|
||||
/// <returns></returns>
|
||||
public static void UpdateMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null)
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
double min = 0, max = 0;
|
||||
GetMinMaxData(serie, dimension, out min, out max, dataZoom);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
@@ -420,7 +553,7 @@ namespace XCharts
|
||||
|
||||
public static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null)
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
double min = 0, max = 0;
|
||||
GetMinMaxData(serie, out min, out max, dataZoom);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
@@ -446,7 +579,7 @@ namespace XCharts
|
||||
{
|
||||
if (dataZoom.IsXAxisIndexValue(serie.xAxisIndex))
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
double min = 0, max = 0;
|
||||
dataZoom.GetXAxisIndexValue(serie.xAxisIndex, out min, out max);
|
||||
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
|
||||
}
|
||||
@@ -459,7 +592,7 @@ namespace XCharts
|
||||
{
|
||||
if (dataZoom.IsYAxisIndexValue(serie.yAxisIndex))
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
double min = 0, max = 0;
|
||||
dataZoom.GetYAxisIndexValue(serie.yAxisIndex, out min, out max);
|
||||
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
|
||||
}
|
||||
@@ -470,7 +603,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, float min, float max)
|
||||
private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, double min, double max)
|
||||
{
|
||||
var data = serie.data;
|
||||
var startValue = min + (max - min) * dataZoom.start / 100;
|
||||
@@ -504,38 +637,43 @@ namespace XCharts
|
||||
private static void UpdateFilterData_Category(Serie serie, DataZoom dataZoom)
|
||||
{
|
||||
var data = serie.data;
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (endIndex < startIndex) endIndex = startIndex;
|
||||
|
||||
if (startIndex != serie.m_FilterStart || endIndex != serie.m_FilterEnd
|
||||
var range = Mathf.RoundToInt(data.Count * (dataZoom.end - dataZoom.start) / 100);
|
||||
if (range <= 0) range = 1;
|
||||
int start = 0, end = 0;
|
||||
if (dataZoom.runtimeInvert)
|
||||
{
|
||||
end = Mathf.CeilToInt(data.Count * dataZoom.end / 100);
|
||||
start = end - range;
|
||||
if (start < 0) start = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = Mathf.FloorToInt(data.Count * dataZoom.start / 100);
|
||||
end = start + range;
|
||||
if (end > data.Count) end = data.Count;
|
||||
}
|
||||
if (start != serie.m_FilterStart || end != serie.m_FilterEnd
|
||||
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
|
||||
{
|
||||
serie.m_FilterStart = startIndex;
|
||||
serie.m_FilterEnd = endIndex;
|
||||
serie.m_FilterStart = start;
|
||||
serie.m_FilterEnd = end;
|
||||
serie.m_FilterMinShow = dataZoom.minShowNum;
|
||||
serie.m_NeedUpdateFilterData = false;
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (count < dataZoom.minShowNum)
|
||||
{
|
||||
if (dataZoom.minShowNum > data.Count) count = data.Count;
|
||||
else count = dataZoom.minShowNum;
|
||||
}
|
||||
if (data.Count > 0)
|
||||
{
|
||||
if (startIndex + count > data.Count)
|
||||
if (range < dataZoom.minShowNum)
|
||||
{
|
||||
int start = endIndex - count;
|
||||
data = data.GetRange(start < 0 ? 0 : start, count);
|
||||
if (dataZoom.minShowNum > data.Count) range = data.Count;
|
||||
else range = dataZoom.minShowNum;
|
||||
}
|
||||
else serie.m_FilterData = data.GetRange(startIndex, count);
|
||||
serie.m_FilterData = data.GetRange(start, range);
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.m_FilterData = data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
else if (end == 0)
|
||||
{
|
||||
serie.m_FilterData = emptyFilter;
|
||||
}
|
||||
@@ -543,16 +681,16 @@ namespace XCharts
|
||||
|
||||
public static void UpdateSerieRuntimeFilterData(Serie serie, bool filterInvisible = true)
|
||||
{
|
||||
serie.runtimeFilterData.Clear();
|
||||
serie.runtimeSortedData.Clear();
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
if (!filterInvisible || (filterInvisible && serieData.show))
|
||||
serie.runtimeFilterData.Add(serieData);
|
||||
serie.runtimeSortedData.Add(serieData);
|
||||
}
|
||||
switch (serie.dataSortType)
|
||||
{
|
||||
case SerieDataSortType.Ascending:
|
||||
serie.runtimeFilterData.Sort(delegate (SerieData data1, SerieData data2)
|
||||
serie.runtimeSortedData.Sort(delegate (SerieData data1, SerieData data2)
|
||||
{
|
||||
var value1 = data1.GetData(1);
|
||||
var value2 = data2.GetData(1);
|
||||
@@ -562,7 +700,7 @@ namespace XCharts
|
||||
});
|
||||
break;
|
||||
case SerieDataSortType.Descending:
|
||||
serie.runtimeFilterData.Sort(delegate (SerieData data1, SerieData data2)
|
||||
serie.runtimeSortedData.Sort(delegate (SerieData data1, SerieData data2)
|
||||
{
|
||||
var value1 = data1.GetData(1);
|
||||
var value2 = data2.GetData(1);
|
||||
@@ -572,7 +710,6 @@ namespace XCharts
|
||||
});
|
||||
break;
|
||||
case SerieDataSortType.None:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Serie serie, SerieData serieData,
|
||||
float dataValue, float dataTotal, SerieLabel serieLabel, Color color)
|
||||
double dataValue, double dataTotal, SerieLabel serieLabel, Color color)
|
||||
{
|
||||
if (serieLabel == null)
|
||||
{
|
||||
@@ -98,6 +98,10 @@ namespace XCharts
|
||||
var numericFormatter = serieLabel == null ? serie.label.numericFormatter : serieLabel.numericFormatter;
|
||||
var serieName = serie.name;
|
||||
var dataName = serieData != null ? serieData.name : null;
|
||||
if (serieLabel.formatterFunction != null)
|
||||
{
|
||||
return serieLabel.formatterFunction(serieData.index, dataValue);
|
||||
}
|
||||
if (string.IsNullOrEmpty(serieLabel.formatter))
|
||||
return ChartCached.NumberToStr(dataValue, numericFormatter);
|
||||
else
|
||||
@@ -198,7 +202,7 @@ namespace XCharts
|
||||
serieData.labelPosition = serie.runtimeCenterPos;
|
||||
break;
|
||||
case SerieLabel.Position.Inside:
|
||||
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
|
||||
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2 + serieLabel.margin;
|
||||
var labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
|
||||
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
|
||||
serieData.labelPosition = labelCenter;
|
||||
@@ -232,7 +236,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static void AvoidLabelOverlap(Serie serie)
|
||||
public static void AvoidLabelOverlap(Serie serie, ComponentTheme theme)
|
||||
{
|
||||
if (!serie.avoidLabelOverlap) return;
|
||||
var lastCheckPos = Vector3.zero;
|
||||
@@ -249,18 +253,17 @@ namespace XCharts
|
||||
}
|
||||
for (int n = 0; n < splitCount; n++)
|
||||
{
|
||||
var serieData = data[n];
|
||||
CheckSerieDataLabel(serie, serieData, false, ref lastCheckPos);
|
||||
CheckSerieDataLabel(serie, data[n], false, theme, ref lastCheckPos);
|
||||
}
|
||||
lastCheckPos = Vector3.zero;
|
||||
for (int n = data.Count - 1; n >= splitCount; n--)
|
||||
{
|
||||
var serieData = data[n];
|
||||
CheckSerieDataLabel(serie, serieData, true, ref lastCheckPos);
|
||||
CheckSerieDataLabel(serie, data[n], true, theme, ref lastCheckPos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ref Vector3 lastCheckPos)
|
||||
private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ComponentTheme theme,
|
||||
ref Vector3 lastCheckPos)
|
||||
{
|
||||
if (!serieData.canShowLabel)
|
||||
{
|
||||
@@ -269,6 +272,7 @@ namespace XCharts
|
||||
}
|
||||
if (!serieData.show) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var fontSize = serieLabel.textStyle.GetFontSize(theme);
|
||||
if (!serieLabel.show) return;
|
||||
if (serieLabel.position != SerieLabel.Position.Outside) return;
|
||||
if (lastCheckPos == Vector3.zero)
|
||||
@@ -277,11 +281,10 @@ namespace XCharts
|
||||
}
|
||||
else if (serieData.labelPosition.x != 0)
|
||||
{
|
||||
float hig = serieLabel.textStyle.fontSize;
|
||||
if (lastCheckPos.y - serieData.labelPosition.y < hig)
|
||||
if (lastCheckPos.y - serieData.labelPosition.y < fontSize)
|
||||
{
|
||||
var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
||||
var y1 = lastCheckPos.y - hig;
|
||||
var y1 = lastCheckPos.y - fontSize;
|
||||
var cy = serie.runtimeCenterPos.y;
|
||||
var diff = Mathf.Abs(y1 - cy);
|
||||
var diffX = labelRadius * labelRadius - diff * diff;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -410,7 +411,7 @@ namespace XCharts
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
public static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
bool inverse, out double minVaule, out double maxValue, bool isPolar = false)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar);
|
||||
}
|
||||
@@ -423,18 +424,18 @@ namespace XCharts
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
public static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
bool inverse, out double minVaule, out double maxValue, bool isPolar = false)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar);
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
private static Dictionary<int, double> _serieTotalValueForMinMax = new Dictionary<int, double>();
|
||||
public static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
bool inverse, bool yValue, out double minVaule, out double maxValue, bool isPolar = false)
|
||||
{
|
||||
float min = float.MaxValue;
|
||||
float max = float.MinValue;
|
||||
double min = double.MaxValue;
|
||||
double max = double.MinValue;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar);
|
||||
if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue))
|
||||
{
|
||||
@@ -442,29 +443,31 @@ namespace XCharts
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if ((isPolar && serie.polarIndex != axisIndex)
|
||||
|| (!isPolar && serie.yAxisIndex != axisIndex)) continue;
|
||||
if (series.IsActive(i))
|
||||
|| (!isPolar && serie.yAxisIndex != axisIndex)
|
||||
|| !series.IsActive(i)) continue;
|
||||
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
|
||||
{
|
||||
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
|
||||
if (100 > max) max = 100;
|
||||
if (0 < min) min = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
if (100 > max) max = 100;
|
||||
if (0 < min) min = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
var dataMin = data.GetMinData(inverse);
|
||||
var dataMax = data.GetMaxData(inverse);
|
||||
if (dataMax > max) max = dataMax;
|
||||
if (dataMin < min) min = dataMin;
|
||||
}
|
||||
else
|
||||
{
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (!serie.IsIgnoreValue(currData))
|
||||
{
|
||||
var dataMin = data.min;
|
||||
var dataMax = data.max;
|
||||
if (dataMax > max) max = dataMax;
|
||||
if (dataMin < min) min = dataMin;
|
||||
}
|
||||
else
|
||||
{
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
}
|
||||
@@ -499,22 +502,23 @@ namespace XCharts
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
var currData = 0f;
|
||||
double currData = 0;
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
currData = showData[j].max;
|
||||
currData = showData[j].GetMaxData(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
|
||||
}
|
||||
if (inverse) currData = -currData;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
if (!serie.IsIgnoreValue(currData))
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
float tmax = float.MinValue;
|
||||
float tmin = float.MaxValue;
|
||||
double tmax = double.MinValue;
|
||||
double tmin = double.MaxValue;
|
||||
foreach (var tt in _serieTotalValueForMinMax)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
@@ -524,15 +528,15 @@ namespace XCharts
|
||||
if (tmin < min) min = tmin;
|
||||
}
|
||||
}
|
||||
if (max == float.MinValue && min == float.MaxValue)
|
||||
if (max == double.MinValue && min == double.MaxValue)
|
||||
{
|
||||
minVaule = 0;
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minVaule = min > 1 ? Mathf.Floor(min) : min;
|
||||
maxValue = max > 1 ? Mathf.Ceil(max) : max;
|
||||
minVaule = min > 1 ? Math.Floor(min) : min;
|
||||
maxValue = max > 1 ? Math.Ceiling(max) : max;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace XCharts
|
||||
var dataIndex = dataIndexList[i];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float xValue, yValue;
|
||||
double xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
@@ -50,7 +50,7 @@ namespace XCharts
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
|
||||
float value = serieData.GetData(1);
|
||||
var value = serieData.GetData(1);
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
@@ -67,7 +67,7 @@ namespace XCharts
|
||||
{
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float value = serieData.GetFirstData();
|
||||
var value = serieData.GetFirstData();
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
@@ -86,7 +86,7 @@ namespace XCharts
|
||||
if (serie.index != index || serie.type != SerieType.Gauge) return;
|
||||
var serieData = serie.GetSerieData(0);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float value = serieData.data[1];
|
||||
var value = serieData.data[1];
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
@@ -158,8 +158,8 @@ namespace XCharts
|
||||
sb.Append(serieData.name);
|
||||
for (int i = 0; i < radar.indicatorList.Count; i++)
|
||||
{
|
||||
string key = radar.indicatorList[i].name;
|
||||
float value = serieData.GetData(i);
|
||||
var key = radar.indicatorList[i].name;
|
||||
var value = serieData.GetData(i);
|
||||
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append(FormatterHelper.PH_NN);
|
||||
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace XCharts
|
||||
ChartTheme theme, bool isCartesian, DataZoom dataZoom = null)
|
||||
{
|
||||
string key = serie.name;
|
||||
float xValue, yValue;
|
||||
double xValue, yValue;
|
||||
serie.GetXYData(index, dataZoom, out xValue, out yValue);
|
||||
var isIngore = serie.IsIgnorePoint(index);
|
||||
if(isIngore) return;
|
||||
@@ -318,7 +318,7 @@ namespace XCharts
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float xValue, yValue;
|
||||
double xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace XCharts
|
||||
public static void AutoSetLineMinMax(VisualMap visualMap, Serie serie, XAxis xAxis, YAxis yAxis)
|
||||
{
|
||||
if (!IsNeedGradient(visualMap) || !visualMap.autoMinMax) return;
|
||||
float min = 0;
|
||||
float max = 0;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
if (visualMap.dimension == 0)
|
||||
{
|
||||
min = xAxis.IsCategory() ? 0 : xAxis.runtimeMinValue;
|
||||
@@ -31,7 +31,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetMinMax(VisualMap visualMap, float min, float max)
|
||||
public static void SetMinMax(VisualMap visualMap, double min, double max)
|
||||
{
|
||||
if (visualMap.enable && (visualMap.min != min || visualMap.max != max))
|
||||
{
|
||||
@@ -67,9 +67,9 @@ namespace XCharts
|
||||
public static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis,
|
||||
Color32 defaultColor)
|
||||
{
|
||||
float value = 0;
|
||||
var min = 0f;
|
||||
var max = 0f;
|
||||
double value = 0;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
if (visualMap.dimension == 0)
|
||||
{
|
||||
min = axis.runtimeMinValue;
|
||||
@@ -124,7 +124,7 @@ namespace XCharts
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
var rate = (value - min) / (max - min);
|
||||
var color = itemStyle.GetGradientColor(rate, defaultColor);
|
||||
var color = itemStyle.GetGradientColor((float)rate, defaultColor);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
else return color;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace XCharts
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
var rate = (value - min) / (max - min);
|
||||
var color = lineStyle.GetGradientColor(rate, defaultColor);
|
||||
var color = lineStyle.GetGradientColor((float)rate, defaultColor);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
else return color;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace XCharts
|
||||
internal bool m_IsPlayingAnimation = false;
|
||||
internal protected List<string> m_LegendRealShowName = new List<string>();
|
||||
protected List<Painter> m_PainterList = new List<Painter>();
|
||||
protected Painter m_PainterTop;
|
||||
internal Painter m_PainterTop;
|
||||
protected GameObject m_SerieLabelRoot;
|
||||
private Theme m_CheckTheme = 0;
|
||||
|
||||
@@ -120,8 +120,8 @@ namespace XCharts
|
||||
if (m_Tooltips.Count == 0) m_Tooltips = new List<Tooltip>() { Tooltip.defaultTooltip };
|
||||
CheckTheme();
|
||||
base.Awake();
|
||||
m_Series.AnimationReset();
|
||||
m_Series.AnimationFadeIn();
|
||||
AnimationReset();
|
||||
AnimationFadeIn();
|
||||
XChartsMgr.Instance.AddChart(this);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace XCharts
|
||||
foreach (var draw in m_ComponentHandlers) draw.Update();
|
||||
}
|
||||
|
||||
internal Painter GetPainter(int index)
|
||||
public Painter GetPainter(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_PainterList.Count)
|
||||
{
|
||||
@@ -172,11 +172,11 @@ namespace XCharts
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void RefreshBasePainter()
|
||||
public void RefreshBasePainter()
|
||||
{
|
||||
m_Painter.Refresh();
|
||||
}
|
||||
internal void RefreshTopPainter()
|
||||
public void RefreshTopPainter()
|
||||
{
|
||||
m_PainterTop.Refresh();
|
||||
}
|
||||
@@ -201,7 +201,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetPainterActive(int index, bool flag)
|
||||
public void SetPainterActive(int index, bool flag)
|
||||
{
|
||||
var painter = GetPainter(index);
|
||||
if (painter == null) return;
|
||||
@@ -216,10 +216,6 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Theme.font == null)
|
||||
{
|
||||
m_Theme.font = XChartsSettings.font;
|
||||
}
|
||||
if (m_Theme.colorPalette.Count == 0)
|
||||
{
|
||||
m_Theme.ResetTheme();
|
||||
@@ -228,6 +224,9 @@ namespace XCharts
|
||||
{
|
||||
m_CheckTheme = m_Theme.theme;
|
||||
m_Theme.CopyTheme(m_CheckTheme);
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(this);
|
||||
#endif
|
||||
SetAllComponentDirty();
|
||||
OnThemeChanged();
|
||||
}
|
||||
@@ -452,9 +451,9 @@ namespace XCharts
|
||||
string legendName = legend.GetFormatterContent(datas[i]);
|
||||
var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
|
||||
var active = IsActiveByLegend(datas[i]);
|
||||
var bgColor = LegendHelper.GetIconColor(this, readIndex , datas[i], active);
|
||||
var bgColor = LegendHelper.GetIconColor(this, readIndex, datas[i], active);
|
||||
var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, m_Theme,
|
||||
legendName, bgColor, active);
|
||||
legendName, bgColor, active, readIndex);
|
||||
legend.SetButton(legendName, item, totalLegend);
|
||||
ChartHelper.ClearEventListener(item.button.gameObject);
|
||||
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||
@@ -530,22 +529,26 @@ namespace XCharts
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
serieData.index = j;
|
||||
serieData.index = count;
|
||||
serieData.labelObject = null;
|
||||
AddSerieLabel(serie, serieData, count);
|
||||
AddSerieLabel(serie, serieData, ref count);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
SerieLabelHelper.UpdateLabelText(m_Series, m_Theme, m_LegendRealShowName);
|
||||
}
|
||||
|
||||
protected void AddSerieLabel(Serie serie, SerieData serieData, int count = -1)
|
||||
|
||||
protected void AddSerieLabel(Serie serie, SerieData serieData, ref int count)
|
||||
{
|
||||
if (m_SerieLabelRoot == null) return;
|
||||
if (count == -1) count = serie.dataCount;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var serieEmphasisLable = SerieHelper.GetSerieEmphasisLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
if (serie.IsPerformanceMode()) return;
|
||||
if (!serieLabel.show) return;
|
||||
if (!serieLabel.show && (serieEmphasisLable == null || !serieEmphasisLable.show) && !iconStyle.show) return;
|
||||
if (serie.animation.enable && serie.animation.HasFadeOut()) return;
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
@@ -559,14 +562,20 @@ namespace XCharts
|
||||
(Color)m_Theme.GetColor(serie.index);
|
||||
}
|
||||
var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, color,
|
||||
serieData.iconStyle.width, serieData.iconStyle.height, theme);
|
||||
iconStyle.width, iconStyle.height, theme);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
var item = new ChartLabel();
|
||||
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
item.SetIcon(iconImage);
|
||||
item.SetIconActive(false);
|
||||
item.SetIconActive(iconStyle.show);
|
||||
serieData.labelObject = item;
|
||||
|
||||
foreach (var dataIndex in serieData.children)
|
||||
{
|
||||
AddSerieLabel(serie, serie.GetSerieData(dataIndex), ref count);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitSerieTitle()
|
||||
@@ -736,7 +745,7 @@ namespace XCharts
|
||||
if (!m_CheckAnimation)
|
||||
{
|
||||
m_CheckAnimation = true;
|
||||
m_Series.AnimationFadeIn();
|
||||
AnimationFadeIn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,6 +787,10 @@ namespace XCharts
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnDataZoomRangeChanged(DataZoom dataZoom)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
base.OnPointerDown(eventData);
|
||||
@@ -1010,12 +1023,20 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||
float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius)
|
||||
float tickness, Vector3 pos, Color32 color, Color32 toColor, Color32 fillColor, float gap, float[] cornerRadius)
|
||||
{
|
||||
DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, fillColor, gap, cornerRadius, Vector3.zero);
|
||||
}
|
||||
|
||||
public void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||
float tickness, Vector3 pos, Color32 color, Color32 toColor, Color32 fillColor, float gap, float[] cornerRadius, Vector3 startPos)
|
||||
{
|
||||
var backgroundColor = ThemeHelper.GetBackgroundColor(m_Theme, m_Background);
|
||||
if (ChartHelper.IsClearColor(fillColor))
|
||||
fillColor = backgroundColor;
|
||||
var smoothness = settings.cicleSmoothness;
|
||||
ChartDrawer.DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap,
|
||||
cornerRadius, backgroundColor, smoothness);
|
||||
cornerRadius, fillColor, backgroundColor, smoothness, startPos);
|
||||
}
|
||||
|
||||
public void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace XCharts
|
||||
protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } }
|
||||
protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } }
|
||||
protected Vector2 graphPivot { get { return m_GraphPivot; } }
|
||||
internal HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
|
||||
public HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
|
||||
|
||||
private ScrollRect m_ScrollRect;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using XUGL;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -31,6 +32,10 @@ namespace XCharts
|
||||
InitAxisX();
|
||||
InitAxisY();
|
||||
tooltip.UpdateToTop();
|
||||
|
||||
var handler = new MarkLineHandler(this);
|
||||
m_ComponentHandlers.Add(handler);
|
||||
handler.Init();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@@ -75,6 +80,20 @@ namespace XCharts
|
||||
RefreshSeriePainterByGridIndex(grid.index);
|
||||
}
|
||||
|
||||
public override void OnDataZoomRangeChanged(DataZoom dataZoom)
|
||||
{
|
||||
foreach (var index in dataZoom.xAxisIndexs)
|
||||
{
|
||||
var axis = GetXAxis(index);
|
||||
if (axis != null && axis.show) axis.SetAllDirty();
|
||||
}
|
||||
foreach (var index in dataZoom.yAxisIndexs)
|
||||
{
|
||||
var axis = GetYAxis(index);
|
||||
if (axis != null && axis.show) axis.SetAllDirty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DrawPainterBase(VertexHelper vh)
|
||||
{
|
||||
base.DrawPainterBase(vh);
|
||||
@@ -122,8 +141,8 @@ namespace XCharts
|
||||
var lp3 = new Vector3(grid.runtimeX - yLineDiff, m_ChartY + chartHeight);
|
||||
var lp4 = new Vector3(grid.runtimeX - yLineDiff, m_ChartY);
|
||||
UGL.DrawQuadrilateral(vh, lp1, lp2, lp3, lp4, backgroundColor);
|
||||
var rp1 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, m_ChartY);
|
||||
var rp2 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, m_ChartY + chartHeight);
|
||||
var rp1 = new Vector3(grid.runtimeX + grid.runtimeWidth, m_ChartY);
|
||||
var rp2 = new Vector3(grid.runtimeX + grid.runtimeWidth, m_ChartY + chartHeight);
|
||||
var rp3 = new Vector3(m_ChartX + chartWidth, m_ChartY + chartHeight);
|
||||
var rp4 = new Vector3(m_ChartX + chartWidth, m_ChartY);
|
||||
UGL.DrawQuadrilateral(vh, rp1, rp2, rp3, rp4, backgroundColor);
|
||||
@@ -244,7 +263,6 @@ namespace XCharts
|
||||
protected virtual void UpdateTooltipValue(Vector2 local)
|
||||
{
|
||||
var isCartesian = IsValue();
|
||||
var dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
var grid = GetGrid(tooltip.runtimeGridIndex);
|
||||
for (int i = 0; i < m_XAxes.Count; i++)
|
||||
{
|
||||
@@ -273,8 +291,8 @@ namespace XCharts
|
||||
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
|
||||
var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data,
|
||||
m_Theme.serie.lineSymbolSize);
|
||||
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
|
||||
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
|
||||
if (Math.Abs(xValue - xdata) / xRate < symbolSize
|
||||
&& Math.Abs(yValue - ydata) / yRate < symbolSize)
|
||||
{
|
||||
tooltip.runtimeDataIndex[i] = n;
|
||||
RefreshPainter(serie);
|
||||
@@ -289,9 +307,11 @@ namespace XCharts
|
||||
}
|
||||
else if (IsCategory())
|
||||
{
|
||||
for (int j = 0; j < xAxis.GetDataNumber(dataZoom); j++)
|
||||
var dataZoomX = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoomX).Count : 0;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(dataZoomX); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, dataCount, dataZoom);
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, dataCount, dataZoomX);
|
||||
float pX = grid.runtimeX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
@@ -301,9 +321,11 @@ namespace XCharts
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(dataZoom); j++)
|
||||
var dataZoomY = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoomY).Count : 0;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(dataZoomY); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, dataCount, dataZoom);
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, dataCount, dataZoomY);
|
||||
float pY = grid.runtimeY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
@@ -315,6 +337,8 @@ namespace XCharts
|
||||
}
|
||||
else if (xAxis.IsCategory())
|
||||
{
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - grid.runtimeY - yAxis.runtimeZeroYOffset) / grid.runtimeHeight;
|
||||
if (yAxis.runtimeMinValue > 0) value += yAxis.runtimeMinValue;
|
||||
tooltip.runtimeYValues[i] = value;
|
||||
@@ -334,6 +358,8 @@ namespace XCharts
|
||||
}
|
||||
else if (yAxis.IsCategory())
|
||||
{
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
var dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - grid.runtimeX - xAxis.runtimeZeroXOffset) / grid.runtimeWidth;
|
||||
if (xAxis.runtimeMinValue > 0) value += xAxis.runtimeMinValue;
|
||||
tooltip.runtimeXValues[i] = value;
|
||||
@@ -387,6 +413,7 @@ namespace XCharts
|
||||
}
|
||||
UpdateSerieGridIndex();
|
||||
RefreshSeriePainterByGridIndex(grid.index);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(tempAxis, dataZooms);
|
||||
var content = TooltipHelper.GetFormatterContent(tooltip, index, this, dataZoom, isCartesian);
|
||||
TooltipHelper.SetContentAndPosition(tooltip, content, chartRect);
|
||||
tooltip.SetActive(true);
|
||||
@@ -454,6 +481,7 @@ namespace XCharts
|
||||
var labelText = "";
|
||||
var labelPos = Vector2.zero;
|
||||
var grid = GetAxisGridOrDefault(axis);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(axis, dataZooms);
|
||||
if (axis is XAxis)
|
||||
{
|
||||
var posY = axisIndex > 0 ? grid.runtimeY + grid.runtimeHeight : grid.runtimeY;
|
||||
@@ -550,6 +578,8 @@ namespace XCharts
|
||||
ChartHelper.HideAllObject(axisObj);
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
if (grid == null) return;
|
||||
if (!yAxis.show) return;
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
var axisLabelTextStyle = yAxis.axisLabel.textStyle;
|
||||
int splitNumber = AxisHelper.GetScaleNumber(yAxis, grid.runtimeHeight, dataZoom);
|
||||
float totalWidth = 0;
|
||||
@@ -574,20 +604,21 @@ namespace XCharts
|
||||
yAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
||||
if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight()))
|
||||
{
|
||||
txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis);
|
||||
txt = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
|
||||
labelName);
|
||||
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
|
||||
}
|
||||
else
|
||||
{
|
||||
txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis);
|
||||
txt = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
|
||||
labelName);
|
||||
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
|
||||
}
|
||||
var labelWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom);
|
||||
if (i == 0) yAxis.axisLabel.SetRelatedText(txt.label, labelWidth);
|
||||
txt.SetPosition(GetLabelYPosition(totalWidth + gapWidth, i, yAxisIndex, yAxis));
|
||||
txt.SetText(labelName);
|
||||
yAxis.runtimeAxisLabelList.Add(txt);
|
||||
totalWidth += labelWidth;
|
||||
}
|
||||
@@ -674,6 +705,7 @@ namespace XCharts
|
||||
if (grid == null) return;
|
||||
if (!xAxis.show) return;
|
||||
var axisLabelTextStyle = xAxis.axisLabel.textStyle;
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
int splitNumber = AxisHelper.GetScaleNumber(xAxis, grid.runtimeWidth, dataZoom);
|
||||
float totalWidth = 0;
|
||||
float eachWidth = AxisHelper.GetEachWidth(xAxis, grid.runtimeWidth, dataZoom);
|
||||
@@ -693,14 +725,15 @@ namespace XCharts
|
||||
var labelWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom);
|
||||
var inside = xAxis.axisLabel.inside;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
var label = ChartHelper.AddAxisLabelObject(i, ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
|
||||
new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), xAxis, theme.axis);
|
||||
var labelName = AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue,
|
||||
xAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, ChartCached.GetXAxisName(xAxisIndex, i),
|
||||
axisObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
|
||||
new Vector2(textWidth, textHeight), xAxis, theme.axis, labelName);
|
||||
|
||||
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
label.SetPosition(GetLabelXPosition(totalWidth + textWidth / 2 + gapWidth, i, xAxisIndex, xAxis));
|
||||
label.SetText(AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, dataZoom,
|
||||
isPercentStack));
|
||||
label.SetPosition(GetLabelXPosition(totalWidth + gapWidth, i, xAxisIndex, xAxis));
|
||||
xAxis.runtimeAxisLabelList.Add(label);
|
||||
totalWidth += labelWidth;
|
||||
}
|
||||
@@ -872,8 +905,8 @@ namespace XCharts
|
||||
axis.runtimeMaxValue = SeriesHelper.GetMaxSerieDataCount(m_Series) - 1;
|
||||
return;
|
||||
}
|
||||
float tempMinValue = 0;
|
||||
float tempMaxValue = 0;
|
||||
double tempMinValue = 0;
|
||||
double tempMaxValue = 0;
|
||||
GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
|
||||
{
|
||||
@@ -891,15 +924,16 @@ namespace XCharts
|
||||
{
|
||||
axis.runtimeZeroXOffset = axis.runtimeMinValue > 0 ? 0 :
|
||||
axis.runtimeMaxValue < 0 ? grid.runtimeWidth :
|
||||
Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeWidth / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
(float)(Math.Abs(axis.runtimeMinValue) * (grid.runtimeWidth / (Math.Abs(axis.runtimeMinValue) + Math.Abs(axis.runtimeMaxValue))));
|
||||
}
|
||||
if (grid != null && axis is YAxis && axis.IsValue())
|
||||
{
|
||||
axis.runtimeZeroYOffset = axis.runtimeMinValue > 0 ? 0 :
|
||||
axis.runtimeMaxValue < 0 ? grid.runtimeHeight :
|
||||
Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
(float)(Math.Abs(axis.runtimeMinValue) * (grid.runtimeHeight / (Math.Abs(axis.runtimeMinValue) + Math.Abs(axis.runtimeMaxValue))));
|
||||
}
|
||||
}
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(axis, dataZooms);
|
||||
if (dataZoom != null && dataZoom.enable)
|
||||
{
|
||||
if (axis is XAxis) dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
|
||||
@@ -918,7 +952,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out float tempMinValue, out float tempMaxValue)
|
||||
protected virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue)
|
||||
{
|
||||
if (IsValue())
|
||||
{
|
||||
@@ -944,6 +978,7 @@ namespace XCharts
|
||||
if (grid == null || axis == null) return;
|
||||
float runtimeWidth = axis is XAxis ? grid.runtimeWidth : grid.runtimeHeight;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(axis, dataZooms);
|
||||
axis.UpdateLabelText(runtimeWidth, dataZoom, isPercentStack, 500);
|
||||
}
|
||||
|
||||
@@ -1022,6 +1057,7 @@ namespace XCharts
|
||||
{
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
if (grid == null) return;
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
var size = AxisHelper.GetScaleNumber(yAxis, grid.runtimeWidth, dataZoom);
|
||||
var totalWidth = grid.runtimeY;
|
||||
var xAxis = GetRelatedXAxis(yAxis);
|
||||
@@ -1066,6 +1102,7 @@ namespace XCharts
|
||||
if (AxisHelper.NeedShowSplit(yAxis))
|
||||
{
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
var size = AxisHelper.GetScaleNumber(yAxis, grid.runtimeWidth, dataZoom);
|
||||
var totalWidth = grid.runtimeY;
|
||||
for (int i = 0; i < size; i++)
|
||||
@@ -1138,6 +1175,7 @@ namespace XCharts
|
||||
{
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
if (grid == null) return;
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var size = AxisHelper.GetScaleNumber(xAxis, grid.runtimeWidth, dataZoom);
|
||||
var totalWidth = grid.runtimeX;
|
||||
var yAxis = m_YAxes[xAxisIndex];
|
||||
@@ -1182,6 +1220,7 @@ namespace XCharts
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
if (AxisHelper.NeedShowSplit(xAxis))
|
||||
{
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var size = AxisHelper.GetScaleNumber(xAxis, grid.runtimeWidth, dataZoom);
|
||||
var totalWidth = grid.runtimeX;
|
||||
var yAxis = m_YAxes[xAxisIndex];
|
||||
@@ -1286,14 +1325,14 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected void DrawXTooltipIndicator(VertexHelper vh)
|
||||
{
|
||||
if (!tooltip.show || !tooltip.IsSelected()) return;
|
||||
if (tooltip.type == Tooltip.Type.None) return;
|
||||
if (tooltip.runtimeGridIndex < 0) return;
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
|
||||
var grid = GetGrid(tooltip.runtimeGridIndex);
|
||||
if (grid == null) return;
|
||||
var lineType = tooltip.lineStyle.GetType(m_Theme.tooltip.lineType);
|
||||
@@ -1303,13 +1342,15 @@ namespace XCharts
|
||||
var xAxis = m_XAxes[i];
|
||||
if (!xAxis.show) continue;
|
||||
if (tooltip.runtimeXValues[i] < 0) continue;
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
float splitWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, dataCount, dataZoom);
|
||||
switch (tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
case Tooltip.Type.Line:
|
||||
float pX = grid.runtimeX + tooltip.runtimeXValues[i] * splitWidth
|
||||
+ (xAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
float pX = (float)(grid.runtimeX + tooltip.runtimeXValues[i] * splitWidth
|
||||
+ (xAxis.boundaryGap ? splitWidth / 2 : 0));
|
||||
if (xAxis.IsValue()) pX = tooltip.runtimePointerPos.x;
|
||||
Vector2 sp = new Vector2(pX, grid.runtimeY);
|
||||
Vector2 ep = new Vector2(pX, grid.runtimeY + grid.runtimeHeight);
|
||||
@@ -1324,9 +1365,9 @@ namespace XCharts
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
pX = grid.runtimeX + splitWidth * tooltip.runtimeXValues[i] -
|
||||
(xAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
if (xAxis.IsValue()) pX = tooltip.runtimeXValues[i];
|
||||
pX = (float)(grid.runtimeX + splitWidth * tooltip.runtimeXValues[i] -
|
||||
(xAxis.boundaryGap ? 0 : splitWidth / 2));
|
||||
if (xAxis.IsValue()) pX = (float)tooltip.runtimeXValues[i];
|
||||
float pY = grid.runtimeY + grid.runtimeHeight;
|
||||
Vector3 p1 = new Vector3(pX, grid.runtimeY);
|
||||
Vector3 p2 = new Vector3(pX, pY);
|
||||
@@ -1343,7 +1384,7 @@ namespace XCharts
|
||||
if (!tooltip.show || !tooltip.IsSelected()) return;
|
||||
if (tooltip.type == Tooltip.Type.None) return;
|
||||
if (tooltip.runtimeGridIndex < 0) return;
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
|
||||
var grid = GetGrid(tooltip.runtimeGridIndex);
|
||||
if (grid == null) return;
|
||||
var lineType = tooltip.lineStyle.GetType(m_Theme.tooltip.lineType);
|
||||
@@ -1353,12 +1394,14 @@ namespace XCharts
|
||||
var yAxis = m_YAxes[i];
|
||||
if (!yAxis.show) continue;
|
||||
if (tooltip.runtimeYValues[i] < 0) continue;
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
float splitWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, dataCount, dataZoom);
|
||||
switch (tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
case Tooltip.Type.Line:
|
||||
float pY = grid.runtimeY + tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
float pY = (float)(grid.runtimeY + tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0));
|
||||
Vector2 sp = new Vector2(grid.runtimeX, pY);
|
||||
Vector2 ep = new Vector2(grid.runtimeX + grid.runtimeWidth, pY);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, m_Theme);
|
||||
@@ -1373,8 +1416,8 @@ namespace XCharts
|
||||
case Tooltip.Type.Shadow:
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
float pX = grid.runtimeX + grid.runtimeWidth;
|
||||
pY = grid.runtimeY + splitWidth * tooltip.runtimeYValues[i] -
|
||||
(yAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
pY = (float)(grid.runtimeY + splitWidth * tooltip.runtimeYValues[i] -
|
||||
(yAxis.boundaryGap ? 0 : splitWidth / 2));
|
||||
Vector3 p1 = new Vector3(grid.runtimeX, pY);
|
||||
Vector3 p2 = new Vector3(grid.runtimeX, pY + tooltipSplitWid);
|
||||
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
|
||||
@@ -1387,7 +1430,12 @@ namespace XCharts
|
||||
|
||||
private void CheckRaycastTarget()
|
||||
{
|
||||
var ray = (dataZoom != null && dataZoom.enable)
|
||||
var anyDataZoom = false;
|
||||
foreach (var dataZoom in dataZooms)
|
||||
{
|
||||
if (dataZoom.enable) anyDataZoom = true;
|
||||
}
|
||||
var ray = anyDataZoom
|
||||
|| (visualMap != null && visualMap.enable && visualMap.show && visualMap.calculable);
|
||||
if (raycastTarget != ray)
|
||||
{
|
||||
@@ -1416,14 +1464,15 @@ namespace XCharts
|
||||
if (!serie.show) continue;
|
||||
if (serie.IsPerformanceMode()) continue;
|
||||
if (!serie.IsCoordinateSerie()) continue;
|
||||
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
DataZoomHelper.GetSerieRelatedDataZoom(serie, dataZooms, out var xDataZoom, out var yDataZoom);
|
||||
var showData = serie.GetDataList(xDataZoom);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
var serieData = showData[j];
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
serieData.index = j;
|
||||
if ((serieLabel.show || serieData.iconStyle.show) && j < serie.dataPoints.Count)
|
||||
if (serieLabel.show && j < serie.dataPoints.Count)
|
||||
{
|
||||
var pos = serie.dataPoints[j];
|
||||
|
||||
@@ -1434,48 +1483,8 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, n);
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[j];
|
||||
switch (serieLabel.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;
|
||||
}
|
||||
Internal_RefreshLabelPosition(serie, serieData, serieLabel, pos, serie.type == SerieType.Bar, isYAxis);
|
||||
m_RefreshLabel = true;
|
||||
serieData.labelPosition = pos;
|
||||
if (serieLabel.show) DrawLabelBackground(vh, serie, serieData);
|
||||
}
|
||||
}
|
||||
@@ -1487,10 +1496,50 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void Internal_RefreshLabelPosition(Serie serie, SerieData serieData, SerieLabel serieLabel, Vector3 pos, bool IsNeedCheckPosition, bool isYAxis)
|
||||
{
|
||||
if (IsNeedCheckPosition)
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, serie.index);
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[serieData.index];
|
||||
switch (serieLabel.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;
|
||||
}
|
||||
}
|
||||
serieData.labelPosition = pos;
|
||||
}
|
||||
|
||||
protected override void OnRefreshLabel()
|
||||
{
|
||||
base.OnRefreshLabel();
|
||||
var isYAxis = IsAnyYAxisIsCategory();
|
||||
var anyPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
@@ -1498,25 +1547,32 @@ namespace XCharts
|
||||
if (!serie.IsCoordinateSerie()) continue;
|
||||
var total = serie.yTotal;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
DataZoomHelper.GetSerieRelatedDataZoom(serie, dataZooms, out var xDataZoom, out var yDataZoom);
|
||||
var showData = serie.GetDataList(xDataZoom);
|
||||
if (xDataZoom != null)
|
||||
ChartHelper.HideAllObject(m_SerieLabelRoot, "label_" + i);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
var serieData = showData[j];
|
||||
if (serieData.labelObject == null) continue;
|
||||
if (j >= serie.dataPoints.Count)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.SetIconActive(false);
|
||||
continue;
|
||||
}
|
||||
serieData.labelObject.SetActive(true);
|
||||
var pos = serie.dataPoints[j];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var dimension = 1;
|
||||
var isIgnore = serie.IsIgnoreIndex(j);
|
||||
Internal_RefreshLabelPosition(serie, serieData, serieLabel, pos, serie.type == SerieType.Bar, isYAxis);
|
||||
serieData.labelObject.SetPosition(serieData.labelPosition);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel && !isIgnore)
|
||||
{
|
||||
float value = 0f;
|
||||
double value = 0;
|
||||
|
||||
if (serie.type == SerieType.Heatmap)
|
||||
{
|
||||
@@ -1538,7 +1594,7 @@ namespace XCharts
|
||||
content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
|
||||
serieLabel, theme.GetColor(i));
|
||||
}
|
||||
serieData.SetLabelActive(value != 0 && serieData.labelPosition != Vector3.zero);
|
||||
serieData.SetLabelActive(serieData.labelPosition != Vector3.zero);
|
||||
var invert = serieLabel.autoOffset
|
||||
&& serie.type == SerieType.Line
|
||||
&& SerieHelper.IsDownPoint(serie, j)
|
||||
@@ -1631,19 +1687,20 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public void Internal_CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness,
|
||||
Vector3 pos, Color32 color, Color32 toColor, float gap, bool clip, float[] cornerRadius, Grid grid)
|
||||
Vector3 pos, Color32 color, Color32 toColor, Color32 backgroundColor, float gap, bool clip, float[] cornerRadius,
|
||||
Grid grid, Vector3 startPos)
|
||||
{
|
||||
if (!IsInChart(pos)) return;
|
||||
if (!clip || (clip && (IsInGrid(grid, pos))))
|
||||
DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap, cornerRadius);
|
||||
DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, backgroundColor, gap, cornerRadius, startPos);
|
||||
}
|
||||
|
||||
public void Internal_CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth,
|
||||
float zebraGap, Color32 color, bool clip, Grid grid)
|
||||
float zebraGap, Color32 color, Color32 toColor, bool clip, Grid grid)
|
||||
{
|
||||
ClampInChart(ref p1);
|
||||
ClampInChart(ref p2);
|
||||
UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color);
|
||||
UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color, toColor);
|
||||
}
|
||||
|
||||
protected Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos, Grid grid)
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace XCharts
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom);
|
||||
float barGap = Internal_GetBarGap(SerieType.Bar);
|
||||
@@ -43,13 +44,13 @@ namespace XCharts
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
double xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||
double xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
var isAllBarEnd = true;
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
{
|
||||
var serieData = showData[i];
|
||||
if (serie.IsIgnoreValue(serieData))
|
||||
if (!serieData.show || serie.IsIgnoreValue(serieData))
|
||||
{
|
||||
serie.dataPoints.Add(Vector3.zero);
|
||||
continue;
|
||||
@@ -60,7 +61,7 @@ namespace XCharts
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
|
||||
|
||||
serieData.canShowLabel = true;
|
||||
float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue);
|
||||
double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue);
|
||||
float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
float axisLineWidth = value == 0 ? 0
|
||||
@@ -78,11 +79,11 @@ namespace XCharts
|
||||
}
|
||||
|
||||
var barHig = 0f;
|
||||
var valueTotal = 0f;
|
||||
double valueTotal = 0f;
|
||||
if (isPercentStack)
|
||||
{
|
||||
valueTotal = Internal_GetBarSameStackTotalValue(serie.stack, i, SerieType.Bar);
|
||||
barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0;
|
||||
barHig = valueTotal != 0 ? (float)((value / valueTotal * grid.runtimeWidth)) : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,8 +97,8 @@ namespace XCharts
|
||||
{
|
||||
valueTotal = xMaxValue - xMinValue;
|
||||
if (valueTotal != 0)
|
||||
barHig = (xMinValue > 0 ? value - xMinValue : value)
|
||||
/ valueTotal * grid.runtimeWidth;
|
||||
barHig = (float)((xMinValue > 0 ? value - xMinValue : value)
|
||||
/ valueTotal * grid.runtimeWidth);
|
||||
}
|
||||
}
|
||||
serieData.runtimeStackHig = barHig;
|
||||
@@ -170,10 +171,11 @@ namespace XCharts
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar);
|
||||
m_StackSerieData.Clear();
|
||||
if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData);
|
||||
@@ -191,13 +193,13 @@ namespace XCharts
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
double yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||
double yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
var isAllBarEnd = true;
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
{
|
||||
var serieData = showData[i];
|
||||
if (serie.IsIgnoreValue(serieData))
|
||||
if (!serieData.show || serie.IsIgnoreValue(serieData))
|
||||
{
|
||||
serie.dataPoints.Add(Vector3.zero);
|
||||
continue;
|
||||
@@ -206,7 +208,7 @@ namespace XCharts
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted;
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
|
||||
float value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
double value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
float pX = grid.runtimeX + i * categoryWidth;
|
||||
@@ -238,7 +240,7 @@ namespace XCharts
|
||||
if (yAxis.IsLog())
|
||||
{
|
||||
int minIndex = yAxis.runtimeMinLogIndex;
|
||||
float nowIndex = yAxis.GetLogValue(value);
|
||||
var nowIndex = yAxis.GetLogValue(value);
|
||||
barHig = (nowIndex - minIndex) / yAxis.splitNumber * grid.runtimeHeight;
|
||||
}
|
||||
else
|
||||
@@ -327,17 +329,18 @@ namespace XCharts
|
||||
var center = new Vector3((plt.x + prb.x) / 2, (prt.y + plb.y) / 2);
|
||||
if (itemWidth > 0 && itemHeight > 0)
|
||||
{
|
||||
var invert = center.x < plb.x;
|
||||
if (ItemStyleHelper.IsNeedCorner(itemStyle))
|
||||
{
|
||||
UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
|
||||
itemStyle.cornerRadius, isYAxis);
|
||||
itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert);
|
||||
}
|
||||
else
|
||||
{
|
||||
Internal_CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid);
|
||||
}
|
||||
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
|
||||
itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis);
|
||||
itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -354,10 +357,11 @@ namespace XCharts
|
||||
var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
|
||||
if (itemWidth > 0 && itemHeight > 0)
|
||||
{
|
||||
var invert = center.y < plb.y;
|
||||
if (ItemStyleHelper.IsNeedCorner(itemStyle))
|
||||
{
|
||||
UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
|
||||
itemStyle.cornerRadius, isYAxis);
|
||||
itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -365,7 +369,7 @@ namespace XCharts
|
||||
serie.clip, grid);
|
||||
}
|
||||
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
|
||||
itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis);
|
||||
itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,21 +378,22 @@ namespace XCharts
|
||||
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
|
||||
Vector3 prb, bool isYAxis, Grid grid)
|
||||
{
|
||||
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
var barColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
var barToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid);
|
||||
if (isYAxis)
|
||||
{
|
||||
plt = (plb + plt) / 2;
|
||||
prt = (prt + prb) / 2;
|
||||
Internal_CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
|
||||
areaColor, serie.clip, grid);
|
||||
barColor, barToColor, serie.clip, grid);
|
||||
}
|
||||
else
|
||||
{
|
||||
plb = (prb + plb) / 2;
|
||||
plt = (plt + prt) / 2;
|
||||
Internal_CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
|
||||
areaColor, serie.clip, grid);
|
||||
barColor, barToColor, serie.clip, grid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,10 +624,10 @@ namespace XCharts
|
||||
return gap;
|
||||
}
|
||||
|
||||
public float Internal_GetBarSameStackTotalValue(string stack, int dataIndex, SerieType type)
|
||||
public double Internal_GetBarSameStackTotalValue(string stack, int dataIndex, SerieType type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stack)) return 0;
|
||||
float total = 0;
|
||||
double total = 0;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (serie.type == type)
|
||||
|
||||
@@ -17,10 +17,11 @@ namespace XCharts
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float space = (categoryWidth - barWidth) / 2;
|
||||
@@ -30,8 +31,8 @@ namespace XCharts
|
||||
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
double yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||
double yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
var isAllBarEnd = true;
|
||||
var isYAxis = false;
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
@@ -50,7 +51,7 @@ namespace XCharts
|
||||
var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var isRise = close > open;
|
||||
var isRise = yAxis.inverse ? close < open : close > open;
|
||||
var borderWidth = open == 0 ? 0f
|
||||
: (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth
|
||||
: itemStyle.runtimeBorderWidth);
|
||||
|
||||
@@ -40,13 +40,14 @@ namespace XCharts
|
||||
? symbol.GetSelectedSize(serie.data[i].data, m_Theme.serie.lineSymbolSelectedSize)
|
||||
: symbol.GetSize(serie.data[i].data, m_Theme.serie.lineSymbolSize);
|
||||
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, serie.index, highlight);
|
||||
|
||||
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, serie.index, highlight);
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, serie.index, highlight, false);
|
||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
|
||||
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
|
||||
Internal_CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serie.dataPoints[i], symbolColor,
|
||||
symbolToColor, symbol.gap, clip, cornerRadius, grid);
|
||||
symbolToColor, backgroundColor, symbol.gap, clip, cornerRadius, grid,
|
||||
i > 0 ? serie.dataPoints[i - 1] : grid.runtimePosition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +92,10 @@ namespace XCharts
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
var yAxis = GetSerieYAxisOrDefault(serie);
|
||||
var xAxis = GetSerieXAxisOrDefault(serie);
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
if (showData.Count <= 0) return;
|
||||
Color32 lineColor = SerieHelper.GetLineColor(serie, m_Theme, colorIndex, serie.highlighted);
|
||||
@@ -100,9 +105,6 @@ namespace XCharts
|
||||
Color32 highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, true);
|
||||
Color32 areaColor, areaToColor;
|
||||
Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero;
|
||||
var yAxis = GetSerieYAxisOrDefault(serie);
|
||||
var xAxis = GetSerieXAxisOrDefault(serie);
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line);
|
||||
m_StackSerieData.Clear();
|
||||
@@ -133,7 +135,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage,
|
||||
double yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage,
|
||||
i, dataChangeDuration, ref dataChanging, yAxis);
|
||||
showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack,
|
||||
ref np, dataChangeDuration);
|
||||
@@ -154,7 +156,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
|
||||
double yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
|
||||
showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref np,
|
||||
dataChangeDuration);
|
||||
serie.dataPoints.Add(np);
|
||||
@@ -166,15 +168,11 @@ namespace XCharts
|
||||
}
|
||||
var startIndex = 0;
|
||||
var endIndex = serie.dataPoints.Count;
|
||||
var startPos = GetStartPos(serie.dataPoints, ref startIndex);
|
||||
var endPos = GetEndPos(serie.dataPoints, ref endIndex);
|
||||
var startPos = GetStartPos(serie.dataPoints, ref startIndex, serie.ignoreLineBreak);
|
||||
var endPos = GetEndPos(serie.dataPoints, ref endIndex, serie.ignoreLineBreak);
|
||||
lp = startPos;
|
||||
stPos1 = stPos2 = lastDir = lastDnPos = Vector3.zero;
|
||||
smoothStartPosUp = smoothStartPosDn = Vector3.zero;
|
||||
float currDetailProgress = lp.x;
|
||||
float totalDetailProgress = endPos.x;
|
||||
serie.animation.InitProgress(serie.dataPoints.Count, currDetailProgress, totalDetailProgress);
|
||||
serie.animation.SetDataFinish(startIndex);
|
||||
|
||||
Vector3 firstLastPos = Vector3.zero, lastNextPos = Vector3.zero;
|
||||
if (serie.minShow > 0 && serie.minShow < showData.Count)
|
||||
@@ -187,7 +185,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
|
||||
double yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
|
||||
showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref firstLastPos, dataChangeDuration);
|
||||
}
|
||||
}
|
||||
@@ -205,7 +203,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
|
||||
double yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
|
||||
showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref lastNextPos, dataChangeDuration);
|
||||
}
|
||||
}
|
||||
@@ -214,14 +212,41 @@ namespace XCharts
|
||||
lastNextPos = endPos;
|
||||
}
|
||||
VisualMapHelper.AutoSetLineMinMax(visualMap, serie, xAxis, yAxis);
|
||||
|
||||
float currDetailProgress = lp.x;
|
||||
float totalDetailProgress = endPos.x;
|
||||
if (serie.animation.alongWithLinePath)
|
||||
{
|
||||
currDetailProgress = 0;
|
||||
totalDetailProgress = 0;
|
||||
var tempLp = startPos;
|
||||
for (i = startIndex + 1; i < serie.dataPoints.Count; i++)
|
||||
{
|
||||
np = serie.dataPoints[i];
|
||||
if (np != Vector3.zero)
|
||||
{
|
||||
totalDetailProgress += Vector3.Distance(np, tempLp);
|
||||
tempLp = np;
|
||||
}
|
||||
}
|
||||
serie.animation.SetLinePathStartPos(startPos);
|
||||
}
|
||||
serie.animation.InitProgress(serie.dataPoints.Count, currDetailProgress, totalDetailProgress);
|
||||
serie.animation.SetDataFinish(startIndex);
|
||||
for (i = startIndex + 1; i < serie.dataPoints.Count; i++)
|
||||
{
|
||||
np = serie.dataPoints[i];
|
||||
serie.ClearSmoothList(i);
|
||||
var isIgnoreBreak = false;
|
||||
if (np == Vector3.zero)
|
||||
{
|
||||
serie.animation.SetDataFinish(i);
|
||||
continue;
|
||||
if (serie.ignoreLineBreak)
|
||||
isIgnoreBreak = true;
|
||||
else
|
||||
{
|
||||
serie.animation.SetDataFinish(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!serie.animation.NeedAnimation(i)) break;
|
||||
bool isFinish = true;
|
||||
@@ -238,34 +263,54 @@ namespace XCharts
|
||||
switch (serie.lineType)
|
||||
{
|
||||
case LineType.Normal:
|
||||
lp = GetLastPos(serie.dataPoints, i, np);
|
||||
nnp = GetNNPos(serie.dataPoints, i, np);
|
||||
isFinish = DrawNormalLine(vh, serie, xAxis, lp, np, nnp, i, lineColor,
|
||||
areaColor, areaToColor, zeroPos, startIndex);
|
||||
lp = GetLastPos(serie.dataPoints, i, np, serie.ignoreLineBreak);
|
||||
nnp = GetNNPos(serie.dataPoints, i, np, serie.ignoreLineBreak);
|
||||
if (lp == Vector3.zero && serie.ignoreLineBreak) isIgnoreBreak = true;
|
||||
isFinish = DrawNormalLine(vh, serie, xAxis, lp, np, nnp, i,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : lineColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaToColor,
|
||||
zeroPos, startIndex);
|
||||
break;
|
||||
case LineType.Smooth:
|
||||
case LineType.SmoothDash:
|
||||
llp = GetLLPos(serie.dataPoints, i, firstLastPos);
|
||||
nnp = GetNNPos(serie.dataPoints, i, lastNextPos);
|
||||
llp = GetLLPos(serie.dataPoints, i, firstLastPos, serie.ignoreLineBreak);
|
||||
nnp = GetNNPos(serie.dataPoints, i, lastNextPos, serie.ignoreLineBreak);
|
||||
if (lp == Vector3.zero && serie.ignoreLineBreak) isIgnoreBreak = true;
|
||||
isFinish = DrawSmoothLine(vh, serie, xAxis, lp, np, llp, nnp, i,
|
||||
lineColor, areaColor, areaToColor, isStack, zeroPos, startIndex);
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : lineColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaToColor,
|
||||
isStack, zeroPos, startIndex);
|
||||
break;
|
||||
case LineType.StepStart:
|
||||
case LineType.StepMiddle:
|
||||
case LineType.StepEnd:
|
||||
nnp = GetNNPos(serie.dataPoints, i, np);
|
||||
isFinish = DrawStepLine(vh, serie, xAxis, lp, np, nnp, i, lineColor,
|
||||
areaColor, areaToColor, zeroPos);
|
||||
nnp = GetNNPos(serie.dataPoints, i, np, serie.ignoreLineBreak);
|
||||
if (lp == Vector3.zero && serie.ignoreLineBreak) isIgnoreBreak = true;
|
||||
isFinish = DrawStepLine(vh, serie, xAxis, lp, np, nnp, i,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : lineColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaToColor,
|
||||
zeroPos);
|
||||
break;
|
||||
case LineType.Dash:
|
||||
case LineType.Dot:
|
||||
case LineType.DashDot:
|
||||
case LineType.DashDotDot:
|
||||
DrawOtherLine(vh, serie, xAxis, lp, np, i, lineColor, areaColor, areaToColor, zeroPos);
|
||||
if (lp == Vector3.zero && serie.ignoreLineBreak) isIgnoreBreak = true;
|
||||
DrawOtherLine(vh, serie, xAxis, lp, np, i,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : lineColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaColor,
|
||||
isIgnoreBreak ? ColorUtil.clearColor32 : areaToColor,
|
||||
zeroPos);
|
||||
break;
|
||||
}
|
||||
if (isFinish) serie.animation.SetDataFinish(i);
|
||||
if (np != Vector3.zero) lp = np;
|
||||
if (np != Vector3.zero || serie.ignoreLineBreak)
|
||||
{
|
||||
lp = np;
|
||||
}
|
||||
}
|
||||
if (!serie.animation.IsFinish())
|
||||
{
|
||||
@@ -276,22 +321,22 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetNNPos(List<Vector3> dataPoints, int index, Vector3 np)
|
||||
private Vector3 GetNNPos(List<Vector3> dataPoints, int index, Vector3 np, bool ignoreLineBreak)
|
||||
{
|
||||
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];
|
||||
if (dataPoints[i] != Vector3.zero || ignoreLineBreak) return dataPoints[i];
|
||||
}
|
||||
return np;
|
||||
}
|
||||
|
||||
private Vector3 GetStartPos(List<Vector3> dataPoints, ref int start)
|
||||
private Vector3 GetStartPos(List<Vector3> dataPoints, ref int start, bool ignoreLineBreak)
|
||||
{
|
||||
for (int i = 0; i < dataPoints.Count; i++)
|
||||
{
|
||||
if (dataPoints[i] != Vector3.zero)
|
||||
if (dataPoints[i] != Vector3.zero || ignoreLineBreak)
|
||||
{
|
||||
start = i;
|
||||
return dataPoints[i];
|
||||
@@ -300,11 +345,11 @@ namespace XCharts
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
private Vector3 GetEndPos(List<Vector3> dataPoints, ref int end)
|
||||
private Vector3 GetEndPos(List<Vector3> dataPoints, ref int end, bool ignoreLineBreak)
|
||||
{
|
||||
for (int i = dataPoints.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (dataPoints[i] != Vector3.zero)
|
||||
if (dataPoints[i] != Vector3.zero || ignoreLineBreak)
|
||||
{
|
||||
end = i;
|
||||
return dataPoints[i];
|
||||
@@ -313,32 +358,32 @@ namespace XCharts
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
private Vector3 GetLastPos(List<Vector3> dataPoints, int index, Vector3 pos)
|
||||
private Vector3 GetLastPos(List<Vector3> dataPoints, int index, Vector3 pos, bool ignoreLineBreak)
|
||||
{
|
||||
if (index <= 0) return pos;
|
||||
for (int i = index - 1; i >= 0; i--)
|
||||
{
|
||||
if (dataPoints[i] != Vector3.zero) return dataPoints[i];
|
||||
if (dataPoints[i] != Vector3.zero || ignoreLineBreak) return dataPoints[i];
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
private Vector3 GetLLPos(List<Vector3> dataPoints, int index, Vector3 lp)
|
||||
private Vector3 GetLLPos(List<Vector3> dataPoints, int index, Vector3 lp, bool ignoreLineBreak)
|
||||
{
|
||||
if (index <= 1) return lp;
|
||||
for (int i = index - 2; i >= 0; i--)
|
||||
{
|
||||
if (dataPoints[i] != Vector3.zero) return dataPoints[i];
|
||||
if (dataPoints[i] != Vector3.zero || ignoreLineBreak) return dataPoints[i];
|
||||
}
|
||||
return lp;
|
||||
}
|
||||
|
||||
internal float DataAverage(ref List<SerieData> showData, SampleType sampleType, int minCount, int maxCount, int rate)
|
||||
internal double DataAverage(ref List<SerieData> showData, SampleType sampleType, int minCount, int maxCount, int rate)
|
||||
{
|
||||
var totalAverage = 0f;
|
||||
double totalAverage = 0;
|
||||
if (rate > 1 && sampleType == SampleType.Peak)
|
||||
{
|
||||
var total = 0f;
|
||||
double total = 0;
|
||||
for (int i = minCount; i < maxCount; i++)
|
||||
{
|
||||
total += showData[i].data[1];
|
||||
@@ -348,13 +393,13 @@ namespace XCharts
|
||||
return totalAverage;
|
||||
}
|
||||
|
||||
internal float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
|
||||
int minCount, int maxCount, float totalAverage, int index, float dataChangeDuration,
|
||||
internal double SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
|
||||
int minCount, int maxCount, double totalAverage, int index, float dataChangeDuration,
|
||||
ref bool dataChanging, Axis axis)
|
||||
{
|
||||
var inverse = axis.inverse;
|
||||
var minValue = axis.runtimeMinValue;
|
||||
var MaxValue = axis.runtimeMaxValue;
|
||||
double minValue = axis.runtimeMinValue;
|
||||
double MaxValue = axis.runtimeMaxValue;
|
||||
if (rate <= 1 || index == minCount)
|
||||
{
|
||||
if (showData[index].IsDataChanged()) dataChanging = true;
|
||||
@@ -364,7 +409,7 @@ namespace XCharts
|
||||
{
|
||||
case SampleType.Sum:
|
||||
case SampleType.Average:
|
||||
float total = 0;
|
||||
double total = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
total += showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue);
|
||||
@@ -373,7 +418,7 @@ namespace XCharts
|
||||
if (sampleType == SampleType.Average) return total / rate;
|
||||
else return total;
|
||||
case SampleType.Max:
|
||||
float max = float.MinValue;
|
||||
double max = double.MinValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue);
|
||||
@@ -382,7 +427,7 @@ namespace XCharts
|
||||
}
|
||||
return max;
|
||||
case SampleType.Min:
|
||||
float min = float.MaxValue;
|
||||
double min = double.MaxValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue);
|
||||
@@ -391,8 +436,8 @@ namespace XCharts
|
||||
}
|
||||
return min;
|
||||
case SampleType.Peak:
|
||||
max = float.MinValue;
|
||||
min = float.MaxValue;
|
||||
max = double.MinValue;
|
||||
min = double.MaxValue;
|
||||
total = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
@@ -410,7 +455,7 @@ namespace XCharts
|
||||
return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, MaxValue);
|
||||
}
|
||||
|
||||
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i,
|
||||
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, double yValue, float startX, int i,
|
||||
float scaleWid, bool isStack, ref Vector3 np, float duration, bool isIngoreValue = false)
|
||||
{
|
||||
if (isIngoreValue)
|
||||
@@ -419,15 +464,15 @@ namespace XCharts
|
||||
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);
|
||||
double xMinValue = xAxis.GetCurrMinValue(duration);
|
||||
double xMaxValue = xAxis.GetCurrMaxValue(duration);
|
||||
double yMinValue = yAxis.GetCurrMinValue(duration);
|
||||
double yMaxValue = yAxis.GetCurrMaxValue(duration);
|
||||
if (xAxis.IsValue() || xAxis.IsLog())
|
||||
{
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
var axisLineWidth = xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
|
||||
float xValue = i > showData.Count - 1 ? 0 : showData[i].GetData(0, xAxis.inverse);
|
||||
double xValue = i > showData.Count - 1 ? 0 : showData[i].GetData(0, xAxis.inverse);
|
||||
float pX = grid.runtimeX + axisLineWidth;
|
||||
float pY = grid.runtimeY + axisLineWidth;
|
||||
if (isStack)
|
||||
@@ -446,7 +491,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
if ((xMaxValue - xMinValue) <= 0) xDataHig = 0;
|
||||
else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth;
|
||||
else xDataHig = (float)((xValue - xMinValue) / (xMaxValue - xMinValue)) * grid.runtimeWidth;
|
||||
}
|
||||
if (yAxis.IsLog())
|
||||
{
|
||||
@@ -458,7 +503,7 @@ namespace XCharts
|
||||
{
|
||||
double valueTotal = yMaxValue - yMinValue;
|
||||
if (valueTotal <= 0) yDataHig = 0;
|
||||
else yDataHig = (float)((yValue - yMinValue) / valueTotal * grid.runtimeHeight);
|
||||
else yDataHig = (float)((yValue - yMinValue) / valueTotal) * grid.runtimeHeight;
|
||||
}
|
||||
np = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
}
|
||||
@@ -497,7 +542,6 @@ namespace XCharts
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
Vector3 llp = Vector3.zero;
|
||||
@@ -511,6 +555,8 @@ namespace XCharts
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(yAxis, dataZooms);
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
var zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line);
|
||||
m_StackSerieData.Clear();
|
||||
@@ -528,11 +574,11 @@ namespace XCharts
|
||||
if (rate < 1) rate = 1;
|
||||
var dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
double xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||
double xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
for (i = serie.minShow; i < maxCount; i += rate)
|
||||
{
|
||||
float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue);
|
||||
double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue);
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = grid.runtimeX + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
|
||||
if (isStack)
|
||||
@@ -551,7 +597,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth;
|
||||
dataHig = (float)((value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth);
|
||||
}
|
||||
showData[i].runtimeStackHig = dataHig;
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
@@ -565,7 +611,7 @@ namespace XCharts
|
||||
if (maxCount % rate != 0)
|
||||
{
|
||||
i = maxCount - 1;
|
||||
float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue);
|
||||
double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue);
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = grid.runtimeX + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
|
||||
if (isStack)
|
||||
@@ -584,7 +630,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth;
|
||||
dataHig = (float)((value - xMinValue) / (xMaxValue - xMinValue)) * grid.runtimeWidth;
|
||||
}
|
||||
showData[i].runtimeStackHig = dataHig;
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
@@ -616,7 +662,7 @@ namespace XCharts
|
||||
case LineType.Normal:
|
||||
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
|
||||
isFinish = DrawNormalLine(vh, serie, yAxis, lp, np, nnp, i, lineColor,
|
||||
areaColor, areaToColor, zeroPos);
|
||||
areaColor, areaToColor, zeroPos, 0);
|
||||
break;
|
||||
case LineType.Smooth:
|
||||
case LineType.SmoothDash:
|
||||
@@ -633,11 +679,11 @@ namespace XCharts
|
||||
areaColor, areaToColor, zeroPos);
|
||||
break;
|
||||
case LineType.Dash:
|
||||
UGL.DrawDashLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor);
|
||||
UGL.DrawDashLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, lineColor);
|
||||
isFinish = true;
|
||||
break;
|
||||
case LineType.Dot:
|
||||
UGL.DrawDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor);
|
||||
UGL.DrawDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, lineColor);
|
||||
isFinish = true;
|
||||
break;
|
||||
case LineType.DashDot:
|
||||
@@ -662,9 +708,9 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private float GetStackValue(List<List<SerieData>> stackDataList, int dataIndex, float dataChangeDuration, Axis xAxis)
|
||||
private double GetStackValue(List<List<SerieData>> stackDataList, int dataIndex, float dataChangeDuration, Axis xAxis)
|
||||
{
|
||||
float value = 0;
|
||||
double value = 0;
|
||||
foreach (var dataList in stackDataList)
|
||||
{
|
||||
value += dataList[dataIndex].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue);
|
||||
@@ -676,7 +722,7 @@ namespace XCharts
|
||||
private bool lastIsDown;
|
||||
private bool DrawNormalLine(VertexHelper vh, Serie serie, Axis axis, Vector3 lp, Vector3 np, Vector3 nnp,
|
||||
int dataIndex, Color32 lineColor, Color32 areaColor, Color32 areaToColor,
|
||||
Vector3 zeroPos, int startIndex = 0)
|
||||
Vector3 zeroPos, int startIndex)
|
||||
{
|
||||
var defaultLineColor = lineColor;
|
||||
var isSecond = dataIndex == startIndex + 1;
|
||||
@@ -787,7 +833,8 @@ namespace XCharts
|
||||
(!lastIsDown && IsInRightOrUp(isYAxis, lastDnPos, tp1)))
|
||||
{
|
||||
isStart = true;
|
||||
Internal_CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid);
|
||||
if (stPos1 != Vector3.zero && stPos2 != Vector3.zero)
|
||||
Internal_CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -939,8 +986,8 @@ namespace XCharts
|
||||
Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + grid.runtimeHeight) : new Vector3(zeroPos.x + grid.runtimeWidth, zeroPos.y);
|
||||
var sindex = 0;
|
||||
var eindex = 0;
|
||||
var sp = GetStartPos(points, ref sindex);
|
||||
var ep = GetEndPos(points, ref eindex);
|
||||
var sp = GetStartPos(points, ref sindex, serie.ignoreLineBreak);
|
||||
var ep = GetEndPos(points, ref eindex, serie.ignoreLineBreak);
|
||||
var cross = ChartHelper.GetIntersection(lp, np, zeroPos, aep);
|
||||
if (cross == Vector3.zero || smoothDownPoints.Count <= 3)
|
||||
{
|
||||
@@ -1170,10 +1217,10 @@ namespace XCharts
|
||||
switch (serie.lineType)
|
||||
{
|
||||
case LineType.Dash:
|
||||
UGL.DrawDashLine(vh, lp, np, lineWidth, lineColor, 0, 0, posList);
|
||||
UGL.DrawDashLine(vh, lp, np, lineWidth, lineColor, lineColor, 0, 0, posList);
|
||||
break;
|
||||
case LineType.Dot:
|
||||
UGL.DrawDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, posList);
|
||||
UGL.DrawDotLine(vh, lp, np, lineWidth, lineColor, lineColor, 0, 0, posList);
|
||||
break;
|
||||
case LineType.DashDot:
|
||||
UGL.DrawDashDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, 0, posList);
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace XCharts
|
||||
{
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
if (!serie.show) return;
|
||||
DataZoom xDataZoom, yDataZoom;
|
||||
DataZoomHelper.GetSerieRelatedDataZoom(serie, dataZooms, out xDataZoom, out yDataZoom);
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
@@ -26,7 +28,7 @@ namespace XCharts
|
||||
var rate = serie.animation.GetCurrRate();
|
||||
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
var dataChanging = false;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
var dataList = serie.GetDataList(xDataZoom);
|
||||
foreach (var serieData in dataList)
|
||||
{
|
||||
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
|
||||
@@ -34,10 +36,11 @@ namespace XCharts
|
||||
var highlight = serie.highlighted || serieData.highlighted;
|
||||
var color = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, colorIndex, highlight, false);
|
||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
|
||||
float xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
|
||||
float yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
|
||||
double xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
|
||||
double yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
float pX = grid.runtimeX + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
|
||||
float pY = grid.runtimeY + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
|
||||
@@ -65,13 +68,13 @@ namespace XCharts
|
||||
{
|
||||
var nowSize = symbol.animationSize[count];
|
||||
color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
|
||||
DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
|
||||
DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, backgroundColor, symbol.gap, cornerRadius);
|
||||
}
|
||||
RefreshPainter(serie);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
|
||||
DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, color, toColor, backgroundColor, symbol.gap, cornerRadius);
|
||||
}
|
||||
}
|
||||
if (!serie.animation.IsFinish())
|
||||
@@ -86,7 +89,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private float GetDataHig(Axis axis, float value, float totalWidth)
|
||||
private float GetDataHig(Axis axis, double value, float totalWidth)
|
||||
{
|
||||
if (axis.IsLog())
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using XUGL;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -20,6 +21,7 @@ namespace XCharts
|
||||
private static readonly string s_AxisLabelObjectName = "axis_label";
|
||||
private bool m_UpdateTitleText = false;
|
||||
private bool m_UpdateLabelText = false;
|
||||
private Dictionary<int, int> m_LastSplitNumber = new Dictionary<int, int>();
|
||||
|
||||
public DrawSerieGauge(BaseChart chart)
|
||||
{
|
||||
@@ -61,6 +63,21 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
if (serie.type == SerieType.Gauge)
|
||||
{
|
||||
if (!m_LastSplitNumber.TryGetValue(serie.index, out var lastSplitNumber))
|
||||
{
|
||||
m_LastSplitNumber[serie.index] = lastSplitNumber;
|
||||
}
|
||||
else if (serie.splitNumber != lastSplitNumber)
|
||||
{
|
||||
m_LastSplitNumber[serie.index] = serie.splitNumber;
|
||||
InitAxisLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawBase(VertexHelper vh)
|
||||
@@ -196,11 +213,11 @@ namespace XCharts
|
||||
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);
|
||||
DrawProgressBar(vh, serie, (float)currAngle);
|
||||
DrawStageColor(vh, serie);
|
||||
DrawLineStyle(vh, serie);
|
||||
DrawAxisTick(vh, serie);
|
||||
DrawPointer(vh, serie, currAngle);
|
||||
DrawPointer(vh, serie, (float)currAngle);
|
||||
TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText);
|
||||
SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText);
|
||||
CheckAnimation(serie);
|
||||
@@ -325,11 +342,11 @@ namespace XCharts
|
||||
{
|
||||
if (serie.animation.HasFadeOut())
|
||||
{
|
||||
return serie.animation.GetCurrDetail();
|
||||
return (float)serie.animation.GetCurrDetail();
|
||||
}
|
||||
float rangeValue = serie.max - serie.min;
|
||||
float rangeAngle = serie.endAngle - serie.startAngle;
|
||||
float value = 0;
|
||||
double value = 0;
|
||||
float angle = serie.startAngle;
|
||||
if (serie.dataCount > 0)
|
||||
{
|
||||
@@ -337,11 +354,11 @@ namespace XCharts
|
||||
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);
|
||||
value = MathUtil.Clamp(value, serie.min, serie.max);
|
||||
}
|
||||
if (rangeValue > 0)
|
||||
{
|
||||
angle += rangeAngle * value / rangeValue;
|
||||
angle += rangeAngle * (float)(value - serie.min) / rangeValue;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
@@ -382,7 +399,7 @@ namespace XCharts
|
||||
? serie.runtimeInsideRadius * serie.gaugePointer.length
|
||||
: serie.gaugePointer.length;
|
||||
if (Vector3.Distance(local, serie.runtimeCenterPos) > len) continue;
|
||||
var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail();
|
||||
var currAngle = (float)(serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail());
|
||||
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len);
|
||||
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width);
|
||||
var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2);
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace XCharts
|
||||
if (value <= 0) return;
|
||||
var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name);
|
||||
|
||||
var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2;
|
||||
var realHig = (float)((value - serie.min) / (serie.max - serie.min) * radius * 2);
|
||||
serie.animation.InitProgress(1, 0, realHig);
|
||||
|
||||
var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail();
|
||||
@@ -338,7 +338,7 @@ namespace XCharts
|
||||
var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name);
|
||||
|
||||
var realHig = (value - serie.min) / (serie.max - serie.min) * vessel.runtimeHeight;
|
||||
serie.animation.InitProgress(1, 0, realHig);
|
||||
serie.animation.InitProgress(1, 0, (float)realHig);
|
||||
var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail();
|
||||
var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false);
|
||||
var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false);
|
||||
@@ -351,7 +351,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var startY = cenPos.y - vessel.runtimeHeight / 2 + hig;
|
||||
var startY = (float)(cenPos.y - vessel.runtimeHeight / 2 + hig);
|
||||
var waveStartPos = new Vector3(cenPos.x - vessel.runtimeWidth / 2, startY);
|
||||
var waveEndPos = new Vector3(cenPos.x + vessel.runtimeWidth / 2, startY);
|
||||
var startX = waveStartPos.x;
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace XCharts
|
||||
{
|
||||
var serieData = data[n];
|
||||
serieData.index = n;
|
||||
float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
|
||||
var value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
|
||||
serieData.runtimePieStartAngle = startDegree;
|
||||
serieData.runtimePieToAngle = startDegree;
|
||||
serieData.runtimePieHalfAngle = startDegree;
|
||||
@@ -210,12 +210,11 @@ namespace XCharts
|
||||
}
|
||||
float degree = serie.pieRoseType == RoseType.Area
|
||||
? (totalDegree / showdataCount)
|
||||
: (totalDegree * value / dataTotalFilterMinAngle);
|
||||
: (float)(totalDegree * value / dataTotalFilterMinAngle);
|
||||
if (serie.minAngle > 0 && degree < serie.minAngle) degree = serie.minAngle;
|
||||
serieData.runtimePieToAngle = startDegree + degree;
|
||||
serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
|
||||
serie.runtimeInsideRadius +
|
||||
(serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax :
|
||||
serie.runtimeInsideRadius + (float)((serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax) :
|
||||
serie.runtimeOutsideRadius;
|
||||
if (serieData.highlighted)
|
||||
{
|
||||
@@ -263,10 +262,10 @@ namespace XCharts
|
||||
startDegree = serieData.runtimePieToAngle;
|
||||
SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
|
||||
}
|
||||
SerieLabelHelper.AvoidLabelOverlap(serie);
|
||||
SerieLabelHelper.AvoidLabelOverlap(serie, chart.theme.common);
|
||||
}
|
||||
|
||||
private float GetTotalAngle(Serie serie, float dataTotal, ref float totalAngle)
|
||||
private double GetTotalAngle(Serie serie, double dataTotal, ref float totalAngle)
|
||||
{
|
||||
totalAngle = 360f;
|
||||
if (serie.minAngle > 0)
|
||||
@@ -414,6 +413,7 @@ namespace XCharts
|
||||
|
||||
private void DrawPieLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
|
||||
{
|
||||
if (serie.animation.enable && serie.animation.HasFadeOut()) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (serieLabel.show
|
||||
&& serieLabel.position == SerieLabel.Position.Outside
|
||||
@@ -497,12 +497,13 @@ namespace XCharts
|
||||
private void DrawPieLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor)
|
||||
{
|
||||
if (serieData.labelObject == null) return;
|
||||
if (serie.animation.enable && serie.animation.HasFadeOut()) return;
|
||||
var currAngle = serieData.runtimePieHalfAngle;
|
||||
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
|
||||
|
||||
if (showLabel || serieData.iconStyle.show)
|
||||
if (showLabel)
|
||||
{
|
||||
serieData.SetLabelActive(showLabel);
|
||||
float rotate = 0;
|
||||
@@ -559,14 +560,15 @@ namespace XCharts
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
}
|
||||
|
||||
protected int GetPiePosIndex(Serie serie, Vector2 local)
|
||||
{
|
||||
if (serie.type != SerieType.Pie) return -1;
|
||||
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
|
||||
if (dist < serie.runtimeInsideRadius || dist > serie.runtimeOutsideRadius) return -1;
|
||||
var maxRadius = serie.runtimeOutsideRadius + 3 * chart.theme.serie.pieSelectedOffset;
|
||||
if (dist < serie.runtimeInsideRadius || dist > maxRadius) return -1;
|
||||
Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y);
|
||||
float angle = ChartHelper.GetAngle360(Vector2.up, dir);
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
@@ -574,7 +576,12 @@ namespace XCharts
|
||||
var serieData = serie.data[i];
|
||||
if (angle >= serieData.runtimePieStartAngle && angle <= serieData.runtimePieToAngle)
|
||||
{
|
||||
return i;
|
||||
var ndist = !serieData.selected ? dist :
|
||||
Vector2.Distance(local, serieData.runtiemPieOffsetCenter);
|
||||
if (ndist >= serieData.runtimePieInsideRadius && ndist <= serieData.runtimePieOutsideRadius)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -88,13 +88,14 @@ namespace XCharts
|
||||
var serieData = serie.data[n];
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var labelPos = serieData.labelPosition;
|
||||
if (serieLabel.margin != 0)
|
||||
{
|
||||
labelPos += serieLabel.margin * (labelPos - center).normalized;
|
||||
}
|
||||
serieData.labelObject.SetPosition(labelPos);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel)
|
||||
{
|
||||
var value = serieData.GetCurrData(1);
|
||||
@@ -334,15 +335,15 @@ namespace XCharts
|
||||
for (int n = 0; n < dataCount; n++)
|
||||
{
|
||||
if (n >= serieData.data.Count) break;
|
||||
float max = radar.GetIndicatorMax(n);
|
||||
float value = serieData.GetCurrData(n, dataChangeDuration);
|
||||
var max = radar.GetIndicatorMax(n);
|
||||
var value = serieData.GetCurrData(n, dataChangeDuration);
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
if (max == 0)
|
||||
{
|
||||
max = serie.runtimeDataMax;
|
||||
}
|
||||
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
||||
: radar.runtimeDataRadius * value / max;
|
||||
var radius = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
||||
: radar.runtimeDataRadius * value / max);
|
||||
var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
|
||||
radius *= rate;
|
||||
if (n == 0)
|
||||
@@ -386,10 +387,11 @@ namespace XCharts
|
||||
: serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize);
|
||||
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
|
||||
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false);
|
||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
|
||||
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
|
||||
symbolToColor, serie.symbol.gap, cornerRadius);
|
||||
symbolToColor, backgroundColor, serie.symbol.gap, cornerRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,6 +440,8 @@ namespace XCharts
|
||||
var startPoint = Vector3.zero;
|
||||
var toPoint = Vector3.zero;
|
||||
var firstPoint = Vector3.zero;
|
||||
var lastColor = ColorUtil.clearColor32;
|
||||
var firstColor = ColorUtil.clearColor32;
|
||||
|
||||
var radar = chart.radars[serie.radarIndex];
|
||||
var indicatorNum = radar.indicatorList.Count;
|
||||
@@ -502,11 +506,13 @@ namespace XCharts
|
||||
var value = serieData.GetCurrData(1, dataChangeDuration);
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
if (max == 0)
|
||||
{
|
||||
max = serie.runtimeDataMax;
|
||||
if (!radar.IsInIndicatorRange(j, serieData.GetData(1)))
|
||||
{
|
||||
lineColor = radar.outRangeColor;
|
||||
}
|
||||
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
||||
: radar.runtimeDataRadius * value / max;
|
||||
var radius = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
||||
: radar.runtimeDataRadius * value / max);
|
||||
var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
|
||||
radius *= rate;
|
||||
if (index == startIndex)
|
||||
@@ -514,6 +520,8 @@ namespace XCharts
|
||||
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
firstPoint = startPoint;
|
||||
lastColor = lineColor;
|
||||
firstColor = lineColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -525,22 +533,28 @@ namespace XCharts
|
||||
}
|
||||
if (serie.lineStyle.show)
|
||||
{
|
||||
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor,
|
||||
chart.theme.serie.lineWidth, LineStyle.Type.Solid);
|
||||
if (radar.connectCenter)
|
||||
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, centerPos,
|
||||
chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
|
||||
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, chart.theme.serie.lineWidth,
|
||||
LineStyle.Type.Solid, radar.lineGradient ? lastColor : lineColor, lineColor);
|
||||
}
|
||||
startPoint = toPoint;
|
||||
lastColor = lineColor;
|
||||
}
|
||||
serieData.labelPosition = startPoint;
|
||||
pointList.Add(startPoint);
|
||||
|
||||
if (serie.areaStyle.show && j == endIndex)
|
||||
{
|
||||
UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
|
||||
}
|
||||
if (serie.lineStyle.show && j == endIndex)
|
||||
{
|
||||
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor,
|
||||
chart.theme.serie.lineWidth, LineStyle.Type.Solid);
|
||||
if (radar.connectCenter)
|
||||
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, centerPos,
|
||||
chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
|
||||
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, chart.theme.serie.lineWidth,
|
||||
LineStyle.Type.Solid, lineColor, radar.lineGradient ? firstColor : lineColor);
|
||||
}
|
||||
}
|
||||
if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None)
|
||||
@@ -557,10 +571,16 @@ namespace XCharts
|
||||
: serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
|
||||
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
|
||||
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false);
|
||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
|
||||
if (!radar.IsInIndicatorRange(j, serieData.GetData(1)))
|
||||
{
|
||||
symbolColor = radar.outRangeColor;
|
||||
symbolToColor = radar.outRangeColor;
|
||||
}
|
||||
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.labelPosition, symbolColor,
|
||||
symbolToColor, serie.symbol.gap, cornerRadius);
|
||||
symbolToColor, backgroundColor, serie.symbol.gap, cornerRadius);
|
||||
}
|
||||
}
|
||||
if (!serie.animation.IsFinish())
|
||||
@@ -601,22 +621,19 @@ namespace XCharts
|
||||
: serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
|
||||
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
|
||||
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false);
|
||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
|
||||
foreach (var point in pointList)
|
||||
{
|
||||
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
|
||||
symbolToColor, serie.symbol.gap, cornerRadius);
|
||||
symbolToColor, backgroundColor, serie.symbol.gap, cornerRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRadar(VertexHelper vh, Radar radar)
|
||||
{
|
||||
if (!radar.splitLine.show && !radar.splitArea.show)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = radar.runtimeRadius / radar.splitNumber;
|
||||
int indicatorNum = radar.indicatorList.Count;
|
||||
@@ -631,7 +648,6 @@ namespace XCharts
|
||||
var splitLineType = radar.splitLine.GetType(chart.theme.radar.splitLineType);
|
||||
for (int i = 0; i < radar.splitNumber; i++)
|
||||
{
|
||||
var isLast = i == radar.splitNumber - 1;
|
||||
var color = radar.splitArea.GetColor(i, chart.theme.radar);
|
||||
outsideRadius = insideRadius + block;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
|
||||
@@ -649,34 +665,27 @@ namespace XCharts
|
||||
}
|
||||
if (radar.splitLine.NeedShow(i))
|
||||
{
|
||||
if (isLast)
|
||||
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p2, p3, lineColor);
|
||||
else
|
||||
ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p2, p3, splitLineColor);
|
||||
ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p2, p3, splitLineColor);
|
||||
}
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
}
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
if (radar.axisLine.show)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
if (radar.splitLine.show)
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p, p3, splitLineColor);
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p, p3, lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCricleRadar(VertexHelper vh, Radar radar)
|
||||
{
|
||||
if (!radar.splitLine.show && !radar.splitArea.show)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = radar.runtimeRadius / radar.splitNumber;
|
||||
int indicatorNum = radar.indicatorList.Count;
|
||||
@@ -684,7 +693,10 @@ namespace XCharts
|
||||
Vector3 p1;
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
var lineColor = radar.axisLine.GetColor(chart.theme.radar.lineColor);
|
||||
var lineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth);
|
||||
var lineWidth = radar.axisLine.GetWidth(chart.theme.radar.lineWidth);
|
||||
var lineType = radar.axisLine.GetType(chart.theme.radar.lineType);
|
||||
var splitLineColor = radar.splitLine.GetColor(chart.theme.radar.splitLineColor);
|
||||
var splitLineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth);
|
||||
for (int i = 0; i < radar.splitNumber; i++)
|
||||
{
|
||||
var color = radar.splitArea.GetColor(i, chart.theme.radiusAxis);
|
||||
@@ -696,19 +708,19 @@ namespace XCharts
|
||||
}
|
||||
if (radar.splitLine.show)
|
||||
{
|
||||
UGL.DrawEmptyCricle(vh, p, outsideRadius, lineWidth, lineColor,
|
||||
UGL.DrawEmptyCricle(vh, p, outsideRadius, splitLineWidth, splitLineColor,
|
||||
Color.clear, chart.settings.cicleSmoothness);
|
||||
}
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
if (radar.axisLine.show)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
if (radar.splitLine.show)
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
UGL.DrawLine(vh, p, p1, lineWidth / 2, lineColor);
|
||||
float currAngle = j * angle;
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p, p1, lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace XCharts
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
var value = serieData.GetFirstData(dataChangeDuration);
|
||||
var max = serieData.GetLastData();
|
||||
var degree = 360 * value / max;
|
||||
var degree = (float)(360 * value / max);
|
||||
var startDegree = GetStartAngle(serie);
|
||||
var toDegree = GetToAngle(serie, degree);
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
|
||||
@@ -104,6 +104,14 @@ namespace XCharts
|
||||
itemStyle.backgroundColor, Color.clear, 0, 360, borderWidth, borderColor, 0,
|
||||
chart.settings.cicleSmoothness, false, serie.clockwise);
|
||||
}
|
||||
var isGradient = !UGLHelper.IsValueEqualsColor(itemColor, itemToColor);
|
||||
if (isGradient)
|
||||
{
|
||||
if (serie.clockwise)
|
||||
itemToColor = Color.Lerp(itemColor, itemToColor, toDegree / (startDegree + 360));
|
||||
else
|
||||
itemToColor = Color.Lerp(itemToColor, itemColor, toDegree / (startDegree + 360));
|
||||
}
|
||||
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, outsideRadius, itemColor, itemToColor,
|
||||
Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness,
|
||||
roundCap, serie.clockwise);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// The delegate function for AxisLabel's formatter. |
|
||||
/// AxisLabel的formatter自定义委托函数。
|
||||
/// </summary>
|
||||
/// <param name="labelIndex">label索引</param>
|
||||
/// <param name="value">当前label对应的数值数据,Value轴或Time轴有效</param>
|
||||
/// <param name="category">当前label对应的类目数据,Category轴有效</param>
|
||||
/// <returns>最终显示的文本内容</returns>
|
||||
public delegate string DelegateAxisLabelFormatter(int labelIndex, double value, string category);
|
||||
/// <summary>
|
||||
/// The delegate function for SerieLabel‘s formatter.
|
||||
/// SerieLabel的formatter自定义委托函数。
|
||||
/// </summary>
|
||||
/// <param name="dataIndex">数据索引</param>
|
||||
/// <param name="value">数值</param>
|
||||
/// <returns>最终显示的文本内容</returns>
|
||||
public delegate string DelegateSerieLabelFormatter(int dataIndex, double value);
|
||||
/// <summary>
|
||||
/// Tooltip的position自定义委托函数。
|
||||
/// </summary>
|
||||
/// <param name="pos">Tooltip的当前坐标</param>
|
||||
/// <returns>Tooltip的最终坐标</returns>
|
||||
public delegate Vector3 DelegateTooltipPosition(Vector3 pos);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d9ec774e2e5b4d9ba407a27f60b6d71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,6 +12,7 @@ namespace XCharts
|
||||
{
|
||||
public class ChartLabel : ChartObject
|
||||
{
|
||||
private bool m_AutoHideIconWhenLabelEmpty = false;
|
||||
private bool m_LabelAutoSize = true;
|
||||
private float m_LabelPaddingLeftRight = 3f;
|
||||
private float m_LabelPaddingTopBottom = 3f;
|
||||
@@ -20,6 +21,7 @@ namespace XCharts
|
||||
private RectTransform m_IconRect;
|
||||
private RectTransform m_ObjectRect;
|
||||
private Vector3 m_IconOffest;
|
||||
private Align m_Align = Align.Left;
|
||||
|
||||
private Image m_IconImage;
|
||||
|
||||
@@ -47,6 +49,9 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public bool autoHideIconWhenLabelEmpty { set { m_AutoHideIconWhenLabelEmpty = value; } }
|
||||
public bool isIconActive { get; private set; }
|
||||
|
||||
public ChartLabel()
|
||||
{
|
||||
}
|
||||
@@ -60,6 +65,7 @@ namespace XCharts
|
||||
m_LabelText = new ChartText(labelObj);
|
||||
m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
|
||||
m_ObjectRect = labelObj.GetComponent<RectTransform>();
|
||||
m_Align = Align.Left;
|
||||
}
|
||||
|
||||
public void SetAutoSize(bool flag)
|
||||
@@ -89,23 +95,21 @@ namespace XCharts
|
||||
public void UpdateIcon(IconStyle iconStyle, Sprite sprite = null)
|
||||
{
|
||||
if (m_IconImage == null) return;
|
||||
SetIconActive(iconStyle.show);
|
||||
if (iconStyle.show)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, true);
|
||||
m_IconImage.sprite = sprite == null ? iconStyle.sprite : sprite;
|
||||
m_IconImage.color = iconStyle.color;
|
||||
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
|
||||
m_IconOffest = iconStyle.offset;
|
||||
m_Align = iconStyle.align;
|
||||
m_AutoHideIconWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
|
||||
AdjustIconPos();
|
||||
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
|
||||
m_IconRect.SetSiblingIndex(0);
|
||||
else
|
||||
m_IconRect.SetSiblingIndex(m_GameObject.transform.childCount - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, false);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLabelWidth()
|
||||
@@ -153,6 +157,7 @@ namespace XCharts
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
isIconActive = flag;
|
||||
if (m_IconImage) ChartHelper.SetActive(m_IconImage, flag);
|
||||
}
|
||||
|
||||
@@ -176,31 +181,60 @@ namespace XCharts
|
||||
return sizeChange;
|
||||
}
|
||||
AdjustIconPos();
|
||||
if (m_AutoHideIconWhenLabelEmpty && isIconActive)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void AdjustIconPos()
|
||||
{
|
||||
if (m_IconImage && m_IconImage.sprite != null && m_IconRect)
|
||||
if (m_IconImage && m_IconRect)
|
||||
{
|
||||
var iconX = 0f;
|
||||
switch (m_LabelText.text.alignment)
|
||||
switch (m_Align)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
case TextAnchor.UpperLeft:
|
||||
case TextAnchor.MiddleLeft:
|
||||
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
|
||||
case Align.Left:
|
||||
switch (m_LabelText.alignment)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
case TextAnchor.UpperLeft:
|
||||
case TextAnchor.MiddleLeft:
|
||||
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
case TextAnchor.UpperRight:
|
||||
case TextAnchor.MiddleRight:
|
||||
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
case TextAnchor.UpperCenter:
|
||||
case TextAnchor.MiddleCenter:
|
||||
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
case TextAnchor.UpperRight:
|
||||
case TextAnchor.MiddleRight:
|
||||
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
case TextAnchor.UpperCenter:
|
||||
case TextAnchor.MiddleCenter:
|
||||
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
|
||||
case Align.Right:
|
||||
switch (m_LabelText.alignment)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
case TextAnchor.UpperLeft:
|
||||
case TextAnchor.MiddleLeft:
|
||||
iconX = m_ObjectRect.sizeDelta.x / 2 + m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
case TextAnchor.UpperRight:
|
||||
case TextAnchor.MiddleRight:
|
||||
iconX = m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
case TextAnchor.UpperCenter:
|
||||
case TextAnchor.MiddleCenter:
|
||||
iconX = m_LabelText.GetPreferredWidth() / 2 + m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
m_IconRect.anchoredPosition = m_IconOffest + new Vector3(iconX, 0);
|
||||
|
||||
@@ -46,6 +46,36 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public TextAnchor alignment
|
||||
{
|
||||
get
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText == null) return TextAnchor.MiddleCenter;
|
||||
switch (m_TMPText.alignment)
|
||||
{
|
||||
case TextAlignmentOptions.Bottom: return TextAnchor.LowerCenter;
|
||||
case TextAlignmentOptions.BottomLeft: return TextAnchor.LowerLeft;
|
||||
case TextAlignmentOptions.BottomRight: return TextAnchor.LowerRight;
|
||||
case TextAlignmentOptions.Center: return TextAnchor.MiddleCenter;
|
||||
case TextAlignmentOptions.Left: return TextAnchor.MiddleLeft;
|
||||
case TextAlignmentOptions.Right: return TextAnchor.MiddleRight;
|
||||
case TextAlignmentOptions.Top: return TextAnchor.UpperCenter;
|
||||
case TextAlignmentOptions.TopLeft: return TextAnchor.UpperLeft;
|
||||
case TextAlignmentOptions.TopRight: return TextAnchor.UpperRight;
|
||||
default: return TextAnchor.MiddleCenter;
|
||||
}
|
||||
#else
|
||||
if (m_Text != null) return m_Text.alignment;
|
||||
else return TextAnchor.MiddleCenter;
|
||||
#endif
|
||||
}
|
||||
set
|
||||
{
|
||||
SetAlignment(alignment);
|
||||
}
|
||||
}
|
||||
|
||||
public ChartText()
|
||||
{
|
||||
}
|
||||
@@ -216,7 +246,12 @@ namespace XCharts
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return 0; // TODO:
|
||||
#else
|
||||
if (m_Text != null) return m_Text.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings);
|
||||
if (m_Text != null)
|
||||
{
|
||||
var tg = m_Text.cachedTextGeneratorForLayout;
|
||||
var setting = m_Text.GetGenerationSettings(Vector2.zero);
|
||||
return tg.GetPreferredWidth(content, setting) / m_Text.pixelsPerUnit;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -240,12 +275,32 @@ namespace XCharts
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if dUI_TextMeshPro
|
||||
public void SetAlignment(TextAlignmentOptions alignment)
|
||||
public string GetPreferredText(string content, string suffix, float maxWidth)
|
||||
{
|
||||
if (m_TMPText != null) m_TMPText.alignment = alignment;
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return content; // TODO:
|
||||
#else
|
||||
if (m_Text != null)
|
||||
{
|
||||
var sourWid = GetPreferredWidth(content);
|
||||
if (sourWid < maxWidth) return content;
|
||||
var suffixWid = GetPreferredWidth(suffix);
|
||||
var textWid = maxWidth - 1.3f * suffixWid;
|
||||
for (int i = content.Length; i > 0; i--)
|
||||
{
|
||||
var temp = content.Substring(0, i);
|
||||
if (GetPreferredWidth(temp) < textWid)
|
||||
{
|
||||
return temp + suffix;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
#if dUI_TextMeshPro
|
||||
|
||||
public void SetFont(TMP_FontAsset font)
|
||||
{
|
||||
if (m_TMPText != null) m_TMPText.font = font;
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace XCharts
|
||||
private static Dictionary<string, string> s_AxisLabel = new Dictionary<string, string>();
|
||||
|
||||
|
||||
private static Dictionary<float, Dictionary<string, string>> s_NumberToStr = new Dictionary<float, Dictionary<string, string>>();
|
||||
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
||||
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
||||
|
||||
public static string FloatToStr(float value, string numericFormatter = "F", int precision = 0)
|
||||
public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0)
|
||||
{
|
||||
if (precision > 0 && numericFormatter.Length == 1)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static string NumberToStr(float value, string formatter)
|
||||
public static string NumberToStr(double value, string formatter)
|
||||
{
|
||||
if (!s_NumberToStr.ContainsKey(value))
|
||||
{
|
||||
|
||||
@@ -15,9 +15,10 @@ namespace XCharts
|
||||
{
|
||||
public static class ChartDrawer
|
||||
{
|
||||
|
||||
public static void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||
float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
|
||||
Color32 backgroundColor, float smoothness)
|
||||
Color32 centerFillColor, Color32 backgroundColor, float smoothness, Vector3 startPos)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -37,11 +38,11 @@ namespace XCharts
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness);
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, centerFillColor, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness);
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, centerFillColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Rect:
|
||||
@@ -55,6 +56,17 @@ namespace XCharts
|
||||
UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.EmptyRect:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Triangle:
|
||||
if (gap > 0)
|
||||
{
|
||||
@@ -66,6 +78,19 @@ namespace XCharts
|
||||
UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.EmptyTriangle:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
UGL.DrawTriangle(vh, pos, symbolSize - tickness, centerFillColor, centerFillColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
UGL.DrawTriangle(vh, pos, symbolSize - tickness, centerFillColor, centerFillColor);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Diamond:
|
||||
if (gap > 0)
|
||||
{
|
||||
@@ -77,31 +102,68 @@ namespace XCharts
|
||||
UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.EmptyDiamond:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
UGL.DrawDiamond(vh, pos, symbolSize - tickness, centerFillColor, centerFillColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
UGL.DrawDiamond(vh, pos, symbolSize - tickness, centerFillColor, centerFillColor);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Arrow:
|
||||
var arrowWidth = symbolSize * 2;
|
||||
var arrowHeight = arrowWidth * 1.5f;
|
||||
var arrowOffset = 0;
|
||||
var arrowDent = arrowWidth / 3.3f;
|
||||
UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight,
|
||||
arrowOffset, arrowDent, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
|
||||
Vector3 startPos, Vector3 endPos, Color32 defaultColor, float themeWidth, LineStyle.Type themeType)
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
|
||||
Color32 defaultColor, float themeWidth, LineStyle.Type themeType)
|
||||
{
|
||||
var type = lineStyle.GetType(themeType);
|
||||
var width = lineStyle.GetWidth(themeWidth);
|
||||
var color = lineStyle.GetColor(defaultColor);
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color);
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color, color);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
|
||||
float themeWidth, LineStyle.Type themeType, Color32 defaultColor, Color32 defaultToColor)
|
||||
{
|
||||
var type = lineStyle.GetType(themeType);
|
||||
var width = lineStyle.GetWidth(themeWidth);
|
||||
var color = lineStyle.GetColor(defaultColor);
|
||||
var toColor = ChartHelper.IsClearColor(defaultToColor) ? color : defaultToColor;
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color, toColor);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
|
||||
Vector3 startPos, Vector3 endPos, Color32 color)
|
||||
{
|
||||
DrawLineStyle(vh, lineType, lineWidth, startPos, endPos, color, color);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
|
||||
Vector3 startPos, Vector3 endPos, Color32 color, Color32 toColor)
|
||||
{
|
||||
switch (lineType)
|
||||
{
|
||||
case LineStyle.Type.Dashed:
|
||||
UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color);
|
||||
UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.Dotted:
|
||||
UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color);
|
||||
UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.Solid:
|
||||
UGL.DrawLine(vh, startPos, endPos, lineWidth, color);
|
||||
UGL.DrawLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.DashDot:
|
||||
UGL.DrawDashDotLine(vh, startPos, endPos, lineWidth, color);
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace XCharts
|
||||
chartText.text.raycastTarget = false;
|
||||
#endif
|
||||
chartText.SetColor(textStyle.GetColor(theme.textColor));
|
||||
chartText.SetFontSize(textStyle.fontSize > 0 ? textStyle.fontSize : theme.fontSize);
|
||||
chartText.SetFontSize(textStyle.GetFontSize(theme));
|
||||
chartText.SetText("Text");
|
||||
chartText.SetLineSpacing(textStyle.lineSpacing);
|
||||
|
||||
@@ -387,7 +387,8 @@ namespace XCharts
|
||||
return ChartHelper.GetOrAddComponent<Painter>(painterObj);
|
||||
}
|
||||
|
||||
public static Image AddIcon(string name, Transform parent, float width, float height)
|
||||
public static Image AddIcon(string name, Transform parent, float width, float height, Sprite sprite = null,
|
||||
Image.Type type = Image.Type.Simple)
|
||||
{
|
||||
var anchorMax = new Vector2(0.5f, 0.5f);
|
||||
var anchorMin = new Vector2(0.5f, 0.5f);
|
||||
@@ -396,11 +397,21 @@ namespace XCharts
|
||||
GameObject iconObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var img = GetOrAddComponent<Image>(iconObj);
|
||||
img.raycastTarget = false;
|
||||
img.type = type;
|
||||
if (sprite != null)
|
||||
{
|
||||
img.sprite = sprite;
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
img.SetNativeSize();
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public static ChartLabel AddAxisLabelObject(int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
||||
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme)
|
||||
public static ChartLabel AddAxisLabelObject(int total, int index, string name, Transform parent,
|
||||
Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme,
|
||||
string content)
|
||||
{
|
||||
var textStyle = axis.axisLabel.textStyle;
|
||||
var iconStyle = axis.iconStyle;
|
||||
@@ -413,11 +424,18 @@ namespace XCharts
|
||||
{
|
||||
GameObject.DestroyImmediate(oldText);
|
||||
}
|
||||
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
|
||||
if (labelShow)
|
||||
{
|
||||
if (!axis.axisLabel.showStartLabel && index == 0) labelShow = false;
|
||||
else if (!axis.axisLabel.showEndLabel && index == total - 1) labelShow = false;
|
||||
}
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme);
|
||||
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height);
|
||||
label.SetAutoSize(false);
|
||||
label.UpdateIcon(iconStyle, axis.GetIcon(index));
|
||||
label.label.SetActive(axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0));
|
||||
label.label.SetActive(labelShow);
|
||||
label.SetText(content);
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -717,7 +735,7 @@ namespace XCharts
|
||||
return (Color32)color;
|
||||
}
|
||||
|
||||
public static float GetMaxDivisibleValue(float max, int ceilRate)
|
||||
public static double GetMaxDivisibleValue(double max, int ceilRate)
|
||||
{
|
||||
if (max == 0) return 0;
|
||||
if (max > -1 && max < 1)
|
||||
@@ -734,20 +752,20 @@ namespace XCharts
|
||||
}
|
||||
if (ceilRate == 0)
|
||||
{
|
||||
var bigger = Mathf.Ceil(Mathf.Abs(max));
|
||||
var bigger = Math.Ceiling(Math.Abs(max));
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
float mm = bigger;
|
||||
double mm = bigger;
|
||||
if (mm > 10 && n < 38)
|
||||
{
|
||||
mm = bigger - bigger % (Mathf.Pow(10, n));
|
||||
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
|
||||
}
|
||||
if (max < 0) return -Mathf.Ceil(mm);
|
||||
else return Mathf.Ceil(mm);
|
||||
if (max < 0) return -Math.Ceiling(mm);
|
||||
else return Math.Ceiling(mm);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -757,7 +775,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetMinDivisibleValue(float min, int ceilRate)
|
||||
public static double GetMinDivisibleValue(double min, int ceilRate)
|
||||
{
|
||||
if (min == 0) return 0;
|
||||
if (min > -1 && min < 1)
|
||||
@@ -774,20 +792,20 @@ namespace XCharts
|
||||
}
|
||||
if (ceilRate == 0)
|
||||
{
|
||||
var bigger = Mathf.Floor(Mathf.Abs(min));
|
||||
var bigger = Math.Floor(Math.Abs(min));
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
float mm = bigger;
|
||||
double mm = bigger;
|
||||
if (mm > 10 && n < 38)
|
||||
{
|
||||
mm = bigger - bigger % (Mathf.Pow(10, n));
|
||||
mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
|
||||
}
|
||||
if (min < 0) return -Mathf.Floor(mm);
|
||||
else return Mathf.Floor(mm);
|
||||
if (min < 0) return -Math.Floor(mm);
|
||||
else return Math.Floor(mm);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -797,11 +815,11 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetMaxLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value <= 0) return 0;
|
||||
float max = 0;
|
||||
double max = 0;
|
||||
while (max < value)
|
||||
{
|
||||
if (isLogBaseE)
|
||||
@@ -817,7 +835,7 @@ namespace XCharts
|
||||
return max;
|
||||
}
|
||||
|
||||
public static float GetMinLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
public static float GetMinLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value > 1) return 1;
|
||||
@@ -837,7 +855,7 @@ namespace XCharts
|
||||
return min;
|
||||
}
|
||||
|
||||
public static int GetFloatAccuracy(float value)
|
||||
public static int GetFloatAccuracy(double value)
|
||||
{
|
||||
if (value > 1 || value < -1) return 0;
|
||||
int count = 1;
|
||||
@@ -1051,5 +1069,10 @@ namespace XCharts
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsInRect(Vector3 pos, float xMin, float xMax, float yMin, float yMax)
|
||||
{
|
||||
return pos.x >= xMin && pos.x <= xMax && pos.y <= yMax && pos.y >= yMin;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Assets/XCharts/Runtime/Internal/Utility/MathUtil.cs
Normal file
52
Assets/XCharts/Runtime/Internal/Utility/MathUtil.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class MathUtil
|
||||
{
|
||||
public static double Abs(double d)
|
||||
{
|
||||
return d > 0 ? d : -d;
|
||||
}
|
||||
|
||||
public static double Clamp(double d, double min, double max)
|
||||
{
|
||||
if (d >= min && d <= max) return d;
|
||||
else if (d < min) return min;
|
||||
else return max;
|
||||
}
|
||||
|
||||
public static bool Approximately(double a, double b)
|
||||
{
|
||||
return Math.Abs(b - a) < Math.Max(0.000001f * Math.Max(Math.Abs(a), Math.Abs(b)), Mathf.Epsilon * 8);
|
||||
}
|
||||
|
||||
public static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0F)
|
||||
return 0F;
|
||||
else if (value > 1F)
|
||||
return 1F;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double Lerp(double a, double b, double t)
|
||||
{
|
||||
return a + (b - a) * Clamp01(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Runtime/Internal/Utility/MathUtil.cs.meta
Normal file
11
Assets/XCharts/Runtime/Internal/Utility/MathUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 094dc7b90e3a049b48f15f990c050db1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,21 +3,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
#if dUI_TextMeshPro
|
||||
using TMPro;
|
||||
#endif
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class XThemeMgr
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 重新加载主题列表
|
||||
/// </summary>
|
||||
public static void ReloadThemeList()
|
||||
{
|
||||
//Debug.Log("LoadThemesFromResources");
|
||||
XChartsMgr.Instance.m_ThemeDict.Clear();
|
||||
XChartsMgr.Instance.m_ThemeNames.Clear();
|
||||
AddTheme(ChartTheme.Default);
|
||||
@@ -28,10 +30,69 @@ namespace XCharts
|
||||
if (json != null && !string.IsNullOrEmpty(json.text))
|
||||
{
|
||||
var theme = JsonUtility.FromJson<ChartTheme>(json.text);
|
||||
theme.font = GetCustomThemeFont(theme);
|
||||
#if dUI_TextMeshPro
|
||||
theme.tmpFont = GetCustomThemeTMPFont(theme);
|
||||
#endif
|
||||
AddTheme(theme);
|
||||
}
|
||||
}
|
||||
//Debug.Log("LoadThemesFromResources DONE: theme count=" + m_ThemeDict.Keys.Count);
|
||||
}
|
||||
|
||||
private static Font GetCustomThemeFont(ChartTheme theme)
|
||||
{
|
||||
Font font = null;
|
||||
#if UNITY_EDITOR
|
||||
if (string.IsNullOrEmpty(theme.fontName)) return null;
|
||||
if (theme.fontName.Equals("Arial")) return Resources.GetBuiltinResource<Font>("Arial.ttf");
|
||||
var guids = AssetDatabase.FindAssets("t:Font");
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var tempFont = AssetDatabase.LoadAssetAtPath<Font>(assetPath);
|
||||
if (tempFont.name.Equals(theme.fontName))
|
||||
{
|
||||
font = tempFont;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
font = FindObjectByInstanceId(theme.fontInstanceId) as Font;
|
||||
#endif
|
||||
return font;
|
||||
}
|
||||
|
||||
#if dUI_TextMeshPro
|
||||
private static TMP_FontAsset GetCustomThemeTMPFont(ChartTheme theme)
|
||||
{
|
||||
TMP_FontAsset font = null;
|
||||
#if UNITY_EDITOR
|
||||
if (!string.IsNullOrEmpty(theme.tmpFontName)){
|
||||
//TODO: how to find TMP_FontAsset asset
|
||||
var guids = AssetDatabase.FindAssets("t:Texture");
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
if(!assetPath.EndsWith(".asset"))continue;
|
||||
var tempFont = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>(assetPath);
|
||||
if (tempFont && tempFont.name.Equals(theme.tmpFontName))
|
||||
{
|
||||
font = tempFont;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
font = FindObjectByInstanceId(theme.fontInstanceId) as TMP_FontAsset;
|
||||
#endif
|
||||
return font;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static Object FindObjectByInstanceId(int instanceId)
|
||||
{
|
||||
return (Object)typeof(Object).GetMethod("FindObjectFromInstanceID",
|
||||
BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { instanceId });
|
||||
}
|
||||
|
||||
public static void AddTheme(ChartTheme theme)
|
||||
@@ -42,10 +103,6 @@ namespace XCharts
|
||||
XChartsMgr.Instance.m_ThemeDict.Add(theme.themeName, theme);
|
||||
XChartsMgr.Instance.m_ThemeNames.Add(theme.themeName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Theme name is exist:" + theme.themeName);
|
||||
}
|
||||
}
|
||||
|
||||
public static ChartTheme GetTheme(string themeName)
|
||||
@@ -62,6 +119,16 @@ namespace XCharts
|
||||
return XChartsMgr.Instance.m_ThemeNames;
|
||||
}
|
||||
|
||||
public static List<ChartTheme> GetThemeList()
|
||||
{
|
||||
var list = new List<ChartTheme>();
|
||||
foreach (var theme in XChartsMgr.Instance.m_ThemeDict.Values)
|
||||
{
|
||||
list.Add(theme);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static bool ContainsTheme(string themeName)
|
||||
{
|
||||
return XChartsMgr.Instance.m_ThemeNames.Contains(themeName);
|
||||
@@ -69,7 +136,6 @@ namespace XCharts
|
||||
|
||||
public static void SwitchTheme(BaseChart chart, string themeName)
|
||||
{
|
||||
Debug.Log("SwitchTheme:" + themeName);
|
||||
#if UNITY_EDITOR
|
||||
if (XChartsMgr.Instance.m_ThemeDict.Count == 0)
|
||||
{
|
||||
@@ -82,8 +148,7 @@ namespace XCharts
|
||||
return;
|
||||
}
|
||||
var target = XChartsMgr.Instance.m_ThemeDict[themeName];
|
||||
chart.theme.CopyTheme(target);
|
||||
chart.RefreshAllComponent();
|
||||
chart.UpdateTheme(target);
|
||||
}
|
||||
|
||||
public static bool ExportTheme(ChartTheme theme, string themeNewName)
|
||||
@@ -94,14 +159,9 @@ namespace XCharts
|
||||
newtheme.theme = Theme.Custom;
|
||||
newtheme.themeName = themeNewName;
|
||||
|
||||
var themeFileName = "XTheme-" + newtheme.themeName;
|
||||
var assetPath = string.Format("Assets/XCharts/Resources/{0}", themeFileName);
|
||||
var filePath = string.Format("{0}/../{1}.json", Application.dataPath, assetPath);
|
||||
var json = JsonUtility.ToJson(newtheme, true);
|
||||
File.WriteAllText(filePath, json);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
var obj = Resources.Load<TextAsset>(themeFileName);
|
||||
ExportTheme(newtheme);
|
||||
var themeAssetName = XChartsSettings.THEME_ASSET_NAME_PREFIX + theme.themeName;
|
||||
var obj = Resources.Load<TextAsset>(themeAssetName);
|
||||
XChartsSettings.AddJsonTheme(obj);
|
||||
ReloadThemeList();
|
||||
return true;
|
||||
@@ -110,9 +170,47 @@ namespace XCharts
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool ExportTheme(ChartTheme theme)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
theme.SyncFontName();
|
||||
var themeAssetName = XChartsSettings.THEME_ASSET_NAME_PREFIX + theme.themeName;
|
||||
var themeAssetPath = Application.dataPath + "/../" + XChartsSettings.THEME_ASSET_FOLDER;
|
||||
if (!Directory.Exists(themeAssetPath))
|
||||
{
|
||||
Directory.CreateDirectory(themeAssetPath);
|
||||
}
|
||||
var themeAssetFilePath = string.Format("{0}/{1}.json", themeAssetPath, themeAssetName);
|
||||
var json = JsonUtility.ToJson(theme, true);
|
||||
File.WriteAllText(themeAssetFilePath, json);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void ExportAllCustomTheme()
|
||||
{
|
||||
var list = new List<ChartTheme>();
|
||||
foreach (var theme in XChartsMgr.Instance.m_ThemeDict.Values)
|
||||
{
|
||||
if (theme.theme == Theme.Custom)
|
||||
{
|
||||
list.Add(theme);
|
||||
}
|
||||
}
|
||||
foreach (var theme in list)
|
||||
{
|
||||
ExportTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetThemeAssetPath(string themeName)
|
||||
{
|
||||
return string.Format("Assets/XCharts/Resources/XTheme-{0}.json", themeName);
|
||||
return string.Format("{0}/{1}{2}.json", XChartsSettings.THEME_ASSET_FOLDER,
|
||||
XChartsSettings.THEME_ASSET_NAME_PREFIX, themeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -76,7 +77,7 @@ namespace XCharts
|
||||
for (int i = 0; i <= 13; i++)
|
||||
{
|
||||
m_AngleAxes[0].AddData("bar" + i);
|
||||
AddData(0, Random.Range(0, 10));
|
||||
AddData(0, UnityEngine.Random.Range(0, 10));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -143,14 +144,15 @@ namespace XCharts
|
||||
* (tickWidth + axis.axisLabel.margin);
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
{
|
||||
float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null);
|
||||
bool inside = axis.axisLabel.inside;
|
||||
var label = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis, theme.axis);
|
||||
if (i == 0) axis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||
var labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null);
|
||||
var inside = axis.axisLabel.inside;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||
null, isPercentStack);
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis, theme.axis,
|
||||
labelName);
|
||||
if (i == 0) axis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||
label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
label.SetText(labelName);
|
||||
var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor;
|
||||
@@ -226,13 +228,12 @@ namespace XCharts
|
||||
{
|
||||
float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i, null);
|
||||
bool inside = axis.axisLabel.inside;
|
||||
|
||||
var label = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis, theme.axis);
|
||||
|
||||
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||
null, isPercentStack);
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis,
|
||||
theme.axis, labelName);
|
||||
label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
label.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||
null, isPercentStack));
|
||||
var pos = ChartHelper.GetPos(cenPos, radius + margin,
|
||||
isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
|
||||
AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero);
|
||||
@@ -268,15 +269,17 @@ namespace XCharts
|
||||
private void UpdateAxisMinMaxValue(Axis axis, bool updateChart = true)
|
||||
{
|
||||
if (axis.IsCategory() || !axis.show) return;
|
||||
float tempMinValue = 0;
|
||||
float tempMaxValue = 0;
|
||||
double tempMinValue = 0;
|
||||
double tempMaxValue = 0;
|
||||
if (axis is RadiusAxis)
|
||||
{
|
||||
SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true);
|
||||
SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue,
|
||||
out tempMaxValue, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SeriesHelper.GetYMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true);
|
||||
SeriesHelper.GetYMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue,
|
||||
out tempMaxValue, true);
|
||||
}
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
|
||||
@@ -455,8 +458,8 @@ namespace XCharts
|
||||
var datas = serie.data;
|
||||
if (datas.Count <= 0) return;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float min = m_RadiusAxis.GetCurrMinValue(dataChangeDuration);
|
||||
float max = m_RadiusAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
double min = m_RadiusAxis.GetCurrMinValue(dataChangeDuration);
|
||||
double max = m_RadiusAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
var firstSerieData = datas[0];
|
||||
var startPos = GetPolarPos(m_Polar, m_AngleAxis, firstSerieData, min, max, radius);
|
||||
var nextPos = Vector3.zero;
|
||||
@@ -507,11 +510,12 @@ namespace XCharts
|
||||
: symbol.GetSize(serieData.data, m_Theme.serie.lineSymbolSize);
|
||||
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, n, highlight);
|
||||
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, n, highlight);
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, n, highlight, false);
|
||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
|
||||
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
|
||||
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
|
||||
DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serieData.runtimePosition, symbolColor,
|
||||
symbolToColor, symbol.gap, cornerRadius);
|
||||
symbolToColor, backgroundColor, symbol.gap, cornerRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,20 +552,20 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetPolarPos(Polar m_Polar, AngleAxis m_AngleAxis, SerieData serieData, float min, float max, float polarRadius)
|
||||
private Vector3 GetPolarPos(Polar m_Polar, AngleAxis m_AngleAxis, SerieData serieData, double min, double max, float polarRadius)
|
||||
{
|
||||
var angle = 0f;
|
||||
if (!m_AngleAxis.clockwise)
|
||||
{
|
||||
angle = m_AngleAxis.runtimeStartAngle - serieData.GetData(1);
|
||||
angle = m_AngleAxis.runtimeStartAngle - (float)serieData.GetData(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
angle = m_AngleAxis.runtimeStartAngle + serieData.GetData(1);
|
||||
angle = m_AngleAxis.runtimeStartAngle + (float)serieData.GetData(1);
|
||||
}
|
||||
angle = (angle + 360) % 360;
|
||||
var value = serieData.GetData(0);
|
||||
var radius = (value - min) / (max - min) * polarRadius;
|
||||
var radius = (float)((value - min) / (max - min) * polarRadius);
|
||||
serieData.runtimeAngle = angle;
|
||||
serieData.runtimePosition = ChartHelper.GetPos(m_Polar.runtimeCenterPos, radius, angle, true);
|
||||
return serieData.runtimePosition;
|
||||
@@ -610,7 +614,7 @@ namespace XCharts
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
var flag = Mathf.Abs(serieData.runtimeAngle - angle) < Mathf.Abs(diff / 2);
|
||||
var flag = Math.Abs(serieData.runtimeAngle - angle) < Math.Abs(diff / 2);
|
||||
if (serieData.highlighted != flag)
|
||||
{
|
||||
refresh = true;
|
||||
@@ -702,9 +706,9 @@ namespace XCharts
|
||||
|
||||
var dist = Vector2.Distance(pointerPos, cenPos);
|
||||
if (dist > radius) dist = radius;
|
||||
float min = m_RadiusAxis.runtimeMinValue;
|
||||
float max = m_RadiusAxis.runtimeMaxValue;
|
||||
var value = (float)(min + dist / radius * m_RadiusAxis.runtimeMinMaxRange);
|
||||
double min = m_RadiusAxis.runtimeMinValue;
|
||||
double max = m_RadiusAxis.runtimeMaxValue;
|
||||
var value = min + dist / radius * m_RadiusAxis.runtimeMinMaxRange;
|
||||
m_RadiusAxis.UpdateTooptipLabelText(ChartCached.FloatToStr(value));
|
||||
m_RadiusAxis.UpdateTooltipLabelPos(ChartHelper.GetPos(cenPos, dist, m_AngleAxis.runtimeStartAngle, true));
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace XCharts
|
||||
serie.symbol.size = 4;
|
||||
serie.symbol.selectedSize = 6;
|
||||
serie.showDataName = true;
|
||||
List<float> data = new List<float>();
|
||||
List<double> data = new List<double>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
data.Add(Random.Range(20, 90));
|
||||
|
||||
@@ -30,14 +30,11 @@ namespace XCharts
|
||||
public string homepage = "";
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
[ExecuteInEditMode]
|
||||
public class XChartsMgr : MonoBehaviour
|
||||
{
|
||||
internal static string _version = "2.2.0";
|
||||
internal static int _versionDate = 20210530;
|
||||
internal static string _version = "2.6.0";
|
||||
internal static int _versionDate = 20211230;
|
||||
public static string version { get { return _version; } }
|
||||
public static int versionDate { get { return _versionDate; } }
|
||||
public static string fullVersion { get { return version + "-" + versionDate; } }
|
||||
@@ -58,7 +55,8 @@ namespace XCharts
|
||||
m_XCharts = FindObjectOfType<XChartsMgr>();
|
||||
if (m_XCharts == null)
|
||||
{
|
||||
GameObject obj = new GameObject("_xcharts_");
|
||||
var obj = GameObject.Find("_xcharts_");
|
||||
if (obj == null) obj = new GameObject("_xcharts_");
|
||||
m_XCharts = obj.AddComponent<XChartsMgr>();
|
||||
}
|
||||
m_XCharts.m_NowVersion = fullVersion;
|
||||
@@ -67,22 +65,13 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private XChartsMgr()
|
||||
{
|
||||
}
|
||||
|
||||
static XChartsMgr()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
var mgr = XChartsMgr.Instance;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (m_XCharts != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(this);
|
||||
return;
|
||||
}
|
||||
SerieLabelPool.ClearAll();
|
||||
m_ChartList.Clear();
|
||||
XThemeMgr.ReloadThemeList();
|
||||
@@ -132,7 +121,7 @@ namespace XCharts
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
yield return web.SendWebRequest();
|
||||
#else
|
||||
yield return web.Send();
|
||||
yield return web.Send();
|
||||
#endif
|
||||
CheckVersionWebRequest(web);
|
||||
}
|
||||
@@ -143,7 +132,7 @@ namespace XCharts
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
yield return web.SendWebRequest();
|
||||
#else
|
||||
yield return web.Send();
|
||||
yield return web.Send();
|
||||
#endif
|
||||
if (!CheckLogWebRequest(web))
|
||||
{
|
||||
@@ -152,7 +141,7 @@ namespace XCharts
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
yield return web.SendWebRequest();
|
||||
#else
|
||||
yield return web.Send();
|
||||
yield return web.Send();
|
||||
#endif
|
||||
CheckLogWebRequest(web);
|
||||
}
|
||||
@@ -348,7 +337,7 @@ namespace XCharts
|
||||
// Search for potential alternative locations in the user project
|
||||
string[] matchingPaths = Directory.GetDirectories(packagePath, "XCharts", SearchOption.AllDirectories);
|
||||
string path = ValidateLocation(matchingPaths, packagePath);
|
||||
if (path != null) return packagePath + path;
|
||||
if (path != null) return Path.Combine(packagePath, path);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -423,6 +412,7 @@ namespace XCharts
|
||||
var addedTMP = false;
|
||||
var removedTMP = false;
|
||||
var tmpName = "\"Unity.TextMeshPro\"";
|
||||
var refCount = 0;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (string.IsNullOrEmpty(line)) continue;
|
||||
@@ -436,6 +426,12 @@ namespace XCharts
|
||||
if (line.Contains("],"))
|
||||
{
|
||||
referencesStart = false;
|
||||
if (refCount > 0)
|
||||
{
|
||||
var old = dest[dest.Count - 1];
|
||||
if (old.EndsWith(","))
|
||||
dest[dest.Count - 1] = old.Substring(0, old.Length - 1);
|
||||
}
|
||||
if (!removeTMP && !refs.Contains(tmpName))
|
||||
{
|
||||
if (refs.Count > 0)
|
||||
@@ -455,8 +451,12 @@ namespace XCharts
|
||||
{
|
||||
if (!line.Contains(tmpName))
|
||||
{
|
||||
removedTMP = true;
|
||||
dest.Add(line);
|
||||
refCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
removedTMP = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -471,7 +471,12 @@ namespace XCharts
|
||||
dest.Add(line);
|
||||
}
|
||||
}
|
||||
if (addedTMP || removedTMP) File.WriteAllText(asmdefPath, string.Join("\n", dest.ToArray()));
|
||||
if (addedTMP || removedTMP)
|
||||
{
|
||||
File.WriteAllText(asmdefPath, string.Join("\n", dest.ToArray()));
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
|
||||
@@ -34,10 +34,14 @@ namespace XCharts
|
||||
GUI.enabled = !m_EssentialResourcesImported;
|
||||
if (GUILayout.Button("Import XCharts Essentials"))
|
||||
{
|
||||
AssetDatabase.importPackageCompleted += ImportCallback;
|
||||
|
||||
string packageFullPath = GetPackageFullPath();
|
||||
AssetDatabase.ImportPackage(packageFullPath + "/Package Resources/XCharts Essential Resources.unitypackage", false);
|
||||
var sourPath = Path.Combine(packageFullPath, "Resources");
|
||||
var destPath = Path.Combine(Application.dataPath, "XCharts/Resources");
|
||||
if (CopyFolder(sourPath, destPath))
|
||||
{
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
GUILayout.Space(5f);
|
||||
GUI.enabled = true;
|
||||
@@ -45,35 +49,40 @@ namespace XCharts
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
{
|
||||
GUILayout.Label("TextMeshPro", EditorStyles.boldLabel);
|
||||
#if dUI_TextMeshPro
|
||||
GUILayout.Label("TextMeshPro is now enabled. You can turn it off by clicking the button below.", new GUIStyle(EditorStyles.label) { wordWrap = true });
|
||||
GUILayout.Space(5f);
|
||||
if (GUILayout.Button("Disable TextMeshPro"))
|
||||
{
|
||||
XChartsMgr.DisableTextMeshPro();
|
||||
}
|
||||
#else
|
||||
GUILayout.Label("TextMeshPro is not active. You can activate it by clicking the button below. Make sure TextMeshPro is already in your project before activating it.", new GUIStyle(EditorStyles.label) { wordWrap = true });
|
||||
GUILayout.Space(5f);
|
||||
if (GUILayout.Button("Enable TextMeshPro"))
|
||||
{
|
||||
XChartsMgr.EnableTextMeshPro();
|
||||
}
|
||||
#endif
|
||||
GUILayout.Space(5f);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(5f);
|
||||
}
|
||||
|
||||
private static bool CopyFolder(string sourPath, string destPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(destPath))
|
||||
{
|
||||
Directory.CreateDirectory(destPath);
|
||||
}
|
||||
var files = Directory.GetFiles(sourPath);
|
||||
foreach (var file in files)
|
||||
{
|
||||
var name = Path.GetFileName(file);
|
||||
var path = Path.Combine(destPath, name);
|
||||
File.Copy(file, path);
|
||||
}
|
||||
var folders = Directory.GetDirectories(sourPath);
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
var name = Path.GetFileName(folder);
|
||||
var path = Path.Combine(destPath, name);
|
||||
CopyFolder(folder, path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("CopyFolder:" + e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal void RegisterResourceImportCallback()
|
||||
{
|
||||
AssetDatabase.importPackageCompleted += ImportCallback;
|
||||
|
||||
@@ -11,6 +11,9 @@ using System.Collections.Generic;
|
||||
#if dUI_TextMeshPro
|
||||
using TMPro;
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -21,6 +24,8 @@ namespace XCharts
|
||||
#endif
|
||||
public class XChartsSettings : ScriptableObject
|
||||
{
|
||||
public readonly static string THEME_ASSET_NAME_PREFIX = "XTheme-";
|
||||
public readonly static string THEME_ASSET_FOLDER = "Assets/XCharts/Resources";
|
||||
|
||||
[SerializeField] private Font m_Font = null;
|
||||
#if dUI_TextMeshPro
|
||||
@@ -145,7 +150,6 @@ namespace XCharts
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return s_Instance;
|
||||
}
|
||||
}
|
||||
@@ -156,6 +160,11 @@ namespace XCharts
|
||||
if (!Instance.m_CustomThemes.Contains(theme))
|
||||
{
|
||||
Instance.m_CustomThemes.Add(theme);
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.SetDirty(Instance);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace XUGL
|
||||
float height, float offset, float dent, Color32 color)
|
||||
{
|
||||
var dir = (arrowPoint - startPoint).normalized;
|
||||
|
||||
var sharpPos = arrowPoint + (offset + height / 2) * dir;
|
||||
var sharpPos = arrowPoint + (offset + height / 4) * dir;
|
||||
var middle = sharpPos + (dent - height) * dir;
|
||||
var diff = Vector3.Cross(dir, Vector3.forward).normalized * width / 2;
|
||||
var left = sharpPos - height * dir + diff;
|
||||
@@ -56,6 +55,20 @@ namespace XUGL
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color)
|
||||
{
|
||||
DrawLine(vh, startPoint, endPoint, width, color, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw a line. 画直线
|
||||
/// </summary>
|
||||
/// <param name="vh"></param>
|
||||
/// <param name="startPoint">起点</param>
|
||||
/// <param name="endPoint">终点</param>
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="toColor">渐变颜色</param>
|
||||
public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color, Color32 toColor)
|
||||
{
|
||||
if (startPoint == endPoint) return;
|
||||
Vector3 v = Vector3.Cross(endPoint - startPoint, Vector3.forward).normalized * width;
|
||||
@@ -66,7 +79,7 @@ namespace XUGL
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
s_Vertex[j].color = color;
|
||||
s_Vertex[j].color = j == 0 || j == 3 ? color : toColor;
|
||||
s_Vertex[j].uv0 = s_ZeroVector2;
|
||||
}
|
||||
vh.AddUIVertexQuad(s_Vertex);
|
||||
@@ -120,12 +133,13 @@ namespace XUGL
|
||||
/// <param name="startPoint">起始点</param>
|
||||
/// <param name="endPoint">结束点</param>
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="color">起始颜色</param>
|
||||
/// <param name="toColor">结束颜色</param>
|
||||
/// <param name="lineLength">实线部分长度,默认为线宽的12倍</param>
|
||||
/// <param name="gapLength">间隙部分长度,默认为线宽的3倍</param>
|
||||
/// <param name="posList">可选,输出的关键点</param>
|
||||
public static void DrawDashLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
|
||||
Color32 color, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null)
|
||||
Color32 color, Color32 toColor, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null)
|
||||
{
|
||||
float dist = Vector3.Distance(startPoint, endPoint);
|
||||
if (dist < 0.1f) return;
|
||||
@@ -134,17 +148,18 @@ namespace XUGL
|
||||
int segment = Mathf.CeilToInt(dist / (lineLength + gapLength));
|
||||
Vector3 dir = (endPoint - startPoint).normalized;
|
||||
Vector3 sp = startPoint, np;
|
||||
var isGradient = !color.Equals(toColor);
|
||||
if (posList != null) posList.Clear();
|
||||
for (int i = 1; i <= segment; i++)
|
||||
{
|
||||
if (posList != null) posList.Add(sp);
|
||||
np = startPoint + dir * dist * i / segment;
|
||||
var dashep = np - dir * gapLength;
|
||||
DrawLine(vh, sp, dashep, width, color);
|
||||
DrawLine(vh, sp, dashep, width, isGradient ? Color32.Lerp(color, toColor, i * 1.0f / segment) : color);
|
||||
sp = np;
|
||||
}
|
||||
if (posList != null) posList.Add(endPoint);
|
||||
DrawLine(vh, sp, endPoint, width, color);
|
||||
DrawLine(vh, sp, endPoint, width, toColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,31 +169,34 @@ namespace XUGL
|
||||
/// <param name="startPoint">起始点</param>
|
||||
/// <param name="endPoint">结束点</param>
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="color">起始颜色</param>
|
||||
/// <param name="toColor">结束颜色</param>
|
||||
/// <param name="lineLength">实线部分长度,默认为线宽的3倍</param>
|
||||
/// <param name="gapLength">间隙部分长度,默认为线宽的3倍</param>
|
||||
/// <param name="posList">可选,输出的关键点</param>
|
||||
public static void DrawDotLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
|
||||
Color32 color, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null)
|
||||
Color32 color, Color32 toColor, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null)
|
||||
{
|
||||
float dist = Vector3.Distance(startPoint, endPoint);
|
||||
var dist = Vector3.Distance(startPoint, endPoint);
|
||||
if (dist < 0.1f) return;
|
||||
if (lineLength == 0) lineLength = 3 * width;
|
||||
if (gapLength == 0) gapLength = 3 * width;
|
||||
int segment = Mathf.CeilToInt(dist / (lineLength + gapLength));
|
||||
Vector3 dir = (endPoint - startPoint).normalized;
|
||||
Vector3 sp = startPoint, np;
|
||||
var segment = Mathf.CeilToInt(dist / (lineLength + gapLength));
|
||||
var dir = (endPoint - startPoint).normalized;
|
||||
var sp = startPoint;
|
||||
var np = Vector3.zero;
|
||||
var isGradient = !color.Equals(toColor);
|
||||
if (posList != null) posList.Clear();
|
||||
for (int i = 1; i <= segment; i++)
|
||||
{
|
||||
if (posList != null) posList.Add(sp);
|
||||
np = startPoint + dir * dist * i / segment;
|
||||
var dashep = np - dir * gapLength;
|
||||
DrawLine(vh, sp, dashep, width, color);
|
||||
DrawLine(vh, sp, dashep, width, isGradient ? Color32.Lerp(color, toColor, i * 1.0f / segment) : color);
|
||||
sp = np;
|
||||
}
|
||||
if (posList != null) posList.Add(endPoint);
|
||||
DrawLine(vh, sp, endPoint, width, color);
|
||||
DrawLine(vh, sp, endPoint, width, toColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -278,11 +296,12 @@ namespace XUGL
|
||||
/// <param name="width">线宽</param>
|
||||
/// <param name="zebraWidth">斑马条纹宽</param>
|
||||
/// <param name="zebraGap">间隙宽</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="color">起始颜色</param>
|
||||
/// <param name="toColor">结束颜色</param>
|
||||
public static void DrawZebraLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width,
|
||||
float zebraWidth, float zebraGap, Color32 color)
|
||||
float zebraWidth, float zebraGap, Color32 color, Color32 toColor)
|
||||
{
|
||||
DrawDotLine(vh, startPoint, endPoint, width, color, zebraWidth, zebraGap);
|
||||
DrawDotLine(vh, startPoint, endPoint, width, color, toColor, zebraWidth, zebraGap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -437,6 +456,20 @@ namespace XUGL
|
||||
DrawQuadrilateral(vh, p1, p2, p3, p4, color, toColor);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(VertexHelper vh, Rect rect, Color32 color)
|
||||
{
|
||||
DrawRectangle(vh, rect, 0, color);
|
||||
}
|
||||
public static void DrawRectangle(VertexHelper vh, Rect rect, float border, Color32 color)
|
||||
{
|
||||
DrawRectangle(vh, rect, border, color, color);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(VertexHelper vh, Rect rect, float border, Color32 color, Color32 toColor)
|
||||
{
|
||||
DrawRectangle(vh, rect.center, rect.width / 2 - border, rect.height / 2 - border, color, toColor, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw a quadrilateral. 画任意的四边形
|
||||
/// </summary>
|
||||
@@ -478,13 +511,34 @@ namespace XUGL
|
||||
}
|
||||
|
||||
private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool horizontal,
|
||||
ref float brLt, ref float brRt, ref float brRb, ref float brLb, ref bool needRound)
|
||||
bool invert, ref float brLt, ref float brRt, ref float brRb, ref float brLb, ref bool needRound)
|
||||
{
|
||||
if (cornerRadius == null) return;
|
||||
brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0;
|
||||
brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0;
|
||||
brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0;
|
||||
brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0;
|
||||
if (invert)
|
||||
{
|
||||
if (horizontal)
|
||||
{
|
||||
brLt = cornerRadius.Length > 0 ? cornerRadius[1] : 0;
|
||||
brRt = cornerRadius.Length > 1 ? cornerRadius[0] : 0;
|
||||
brRb = cornerRadius.Length > 2 ? cornerRadius[3] : 0;
|
||||
brLb = cornerRadius.Length > 3 ? cornerRadius[2] : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
brLt = cornerRadius.Length > 0 ? cornerRadius[3] : 0;
|
||||
brRt = cornerRadius.Length > 1 ? cornerRadius[2] : 0;
|
||||
brRb = cornerRadius.Length > 2 ? cornerRadius[1] : 0;
|
||||
brLb = cornerRadius.Length > 3 ? cornerRadius[0] : 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0;
|
||||
brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0;
|
||||
brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0;
|
||||
brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0;
|
||||
}
|
||||
|
||||
needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0;
|
||||
if (needRound)
|
||||
{
|
||||
@@ -563,18 +617,22 @@ namespace XUGL
|
||||
/// <param name="rectWidth"></param>
|
||||
/// <param name="rectHeight"></param>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="toColor"></param>
|
||||
/// <param name="rotate"></param>
|
||||
/// <param name="cornerRadius"></param>
|
||||
/// <param name="isYAxis"></param>
|
||||
/// <param name="smoothness"></param>
|
||||
/// <param name="invertCorner"></param>
|
||||
public static void DrawRoundRectangle(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
|
||||
Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false,
|
||||
float smoothness = 2)
|
||||
float smoothness = 2, bool invertCorner = false)
|
||||
{
|
||||
var isGradient = !UGLHelper.IsValueEqualsColor(color, toColor);
|
||||
var halfWid = rectWidth / 2;
|
||||
var halfHig = rectHeight / 2;
|
||||
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
|
||||
bool needRound = false;
|
||||
InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb,
|
||||
InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, invertCorner, ref brLt, ref brRt, ref brRb,
|
||||
ref brLb, ref needRound);
|
||||
var tempCenter = Vector3.zero;
|
||||
var lbIn = new Vector3(center.x - halfWid, center.y - halfHig);
|
||||
@@ -806,12 +864,33 @@ namespace XUGL
|
||||
/// <param name="color"></param>
|
||||
/// <param name="rotate"></param>
|
||||
/// <param name="cornerRadius"></param>
|
||||
/// <param name="invertCorner"></param>
|
||||
public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
|
||||
float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null,
|
||||
bool horizontal = false, float smoothness = 1f)
|
||||
bool horizontal = false, float smoothness = 1f, bool invertCorner = false)
|
||||
{
|
||||
DrawBorder(vh, center, rectWidth, rectHeight, borderWidth, color, s_ClearColor32, rotate,
|
||||
cornerRadius, horizontal, smoothness);
|
||||
cornerRadius, horizontal, smoothness, invertCorner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制(圆角)边框
|
||||
/// </summary>
|
||||
/// <param name="vh"></param>
|
||||
/// <param name="rect"></param>
|
||||
/// <param name="borderWidth"></param>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="rotate"></param>
|
||||
/// <param name="cornerRadius"></param>
|
||||
/// <param name="horizontal"></param>
|
||||
/// <param name="smoothness"></param>
|
||||
/// <param name="invertCorner"></param>
|
||||
public static void DrawBorder(VertexHelper vh, Rect rect,
|
||||
float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null,
|
||||
bool horizontal = false, float smoothness = 1f, bool invertCorner = false)
|
||||
{
|
||||
DrawBorder(vh, rect.center, rect.width, rect.height, borderWidth, color, s_ClearColor32, rotate,
|
||||
cornerRadius, horizontal, smoothness, invertCorner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -826,9 +905,12 @@ namespace XUGL
|
||||
/// <param name="toColor"></param>
|
||||
/// <param name="rotate"></param>
|
||||
/// <param name="cornerRadius"></param>
|
||||
/// <param name="horizontal"></param>
|
||||
/// <param name="smoothness"></param>
|
||||
/// <param name="invertCorner"></param>
|
||||
public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
|
||||
float borderWidth, Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null,
|
||||
bool horizontal = false, float smoothness = 1f)
|
||||
bool horizontal = false, float smoothness = 1f, bool invertCorner = false)
|
||||
{
|
||||
if (borderWidth == 0 || UGLHelper.IsClearColor(color)) return;
|
||||
var halfWid = rectWidth / 2;
|
||||
@@ -843,7 +925,7 @@ namespace XUGL
|
||||
var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth);
|
||||
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
|
||||
bool needRound = false;
|
||||
InitCornerRadius(cornerRadius, rectWidth, rectHeight, horizontal, ref brLt, ref brRt, ref brRb,
|
||||
InitCornerRadius(cornerRadius, rectWidth, rectHeight, horizontal, invertCorner, ref brLt, ref brRt, ref brRb,
|
||||
ref brLb, ref needRound);
|
||||
var tempCenter = Vector3.zero;
|
||||
if (UGLHelper.IsClearColor(toColor))
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "com.monitor1394.xcharts",
|
||||
"displayName": "XCharts",
|
||||
"version": "2.2.0",
|
||||
"date": "20210530",
|
||||
"checkdate": "20210530",
|
||||
"version": "2.6.0",
|
||||
"date": "20211230",
|
||||
"checkdate": "20211230",
|
||||
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
|
||||
"unity": "2018.3",
|
||||
"description": "A charting and data visualization library for Unity.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "2.2.0",
|
||||
"date": "20210530",
|
||||
"checkdate": "20210530",
|
||||
"version": "2.6.0",
|
||||
"date": "20211230",
|
||||
"checkdate": "20211230",
|
||||
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
|
||||
"homepage": "https://github.com/monitor1394/unity-ugui-XCharts"
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace XChartsDemo
|
||||
if (chart is RingChart)
|
||||
{
|
||||
var serieData = chart.series.GetSerie(0).GetSerieData(0);
|
||||
chart.UpdateData(0, 0, 0, Random.Range(0, serieData.GetData(1)));
|
||||
chart.UpdateData(0, 0, 0, Random.Range(0, (float)serieData.GetData(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
14
README.md
14
README.md
@@ -24,9 +24,6 @@
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/languages/code-size/monitor1394/unity-ugui-xcharts">
|
||||
</a>
|
||||
<a href="https://www.npmjs.org/package/unity-ugui-xcharts">
|
||||
<img src="https://img.shields.io/npm/dm/unity-ugui-xcharts?label=npm%20downloads%20">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/badge/Unity-5.6+-green">
|
||||
</a>
|
||||
@@ -34,6 +31,17 @@
|
||||
<img src="https://img.shields.io/badge/TextMeshPro-YES-green">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/stars/monitor1394/unity-ugui-XCharts?style=social">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/forks/monitor1394/unity-ugui-XCharts?style=social">
|
||||
</a>
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/github/issues-closed/monitor1394/unity-ugui-XCharts?color=green&label=%20%20%20%20issues&logoColor=green&style=social">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
一款基于`UGUI`的功能强大、易用、参数可配置的数据可视化图表插件。支持折线图、柱状图、饼图、雷达图、散点图、热力图、仪表盘、环形图、极坐标、水位图、K线图等常见图表。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user