Compare commits

...

40 Commits

Author SHA1 Message Date
monitor1394
a2e790561e v2.6.0 2021-12-30 08:19:48 +08:00
monitor1394
f0e94d35b6 fixed emphasis label 2021-12-21 07:01:54 +08:00
monitor1394
76f640f64d Fixed markline label refresh when serie hide #178 2021-12-17 21:27:14 +08:00
monitor1394
9d8dc80494 Improved radarchart 2021-12-10 13:22:00 +08:00
monitor1394
bc1d2ac095 Fixed y axis does not refresh when serie hidden 2021-12-08 20:53:12 +08:00
monitor1394
913c8e1fb2 optimize emptyRect symbol 2021-12-04 14:12:34 +08:00
monitor1394
634bb45dc4 optimize emptyRect symbol 2021-12-04 14:10:28 +08:00
monitor1394
e4827ac262 Added new symbol type: EmptyRect, EmptyTriangle, EmptyDiamond 2021-12-04 08:46:32 +08:00
monitor1394
9ad8a86ffc set symbol empty area color by itemStyle's backgroundColor 2021-12-04 08:26:56 +08:00
monitor1394
23a8ce52d1 Fixed formatter {c} not work #175 2021-12-03 13:08:20 +08:00
monitor1394
38584f618b Fixed axis boundaryGap display error #174 2021-12-03 08:38:00 +08:00
monitor1394
84c47e0d84 inspector show seriedata.selected 2021-12-01 21:35:08 +08:00
monitor1394
7ff1405de5 Fixed serie ignore display error #173 2021-11-30 21:40:18 +08:00
monitor1394
acae09bf28 v2.5.0 2021-11-27 22:12:08 +08:00
monitor1394
b304bd2033 add tooltip delegate function: positionFunction 2021-11-27 22:06:15 +08:00
monitor1394
72c29235d8 Add Time axis warning 2021-11-03 06:48:45 +08:00
monitor1394
5f18f060e3 Optimized SerieData to support tree data 2021-11-02 21:23:01 +08:00
monitor1394
a281028a22 Removed settings for TextMeshPro when package first imported 2021-10-29 07:26:33 +08:00
monitor1394
fe702f3447 Added support for {e} in Tooltip #170 2021-10-29 07:05:30 +08:00
monitor1394
6888ba96e3 增加Treemap扩展支持 2021-10-24 19:23:17 +08:00
monitor1394
b261ef0573 improve radar chart 2021-09-12 15:01:40 +08:00
monitor1394
64d0b047b3 fix pie chart fade out animation #168 2021-09-07 21:44:05 +08:00
monitor1394
5c395ade25 Fixed bug where GaugeChart does not refresh label when changing splitNumber #167 2021-09-06 21:33:44 +08:00
monitor1394
5149376806 v2.4.0 2021-08-31 22:29:49 +08:00
monitor1394
d8f739cbdf v2.4.0 2021-08-31 21:13:59 +08:00
monitor1394
71fb45af9f 优化RingChart的渐变效果 2021-08-31 21:05:02 +08:00
monitor1394
ca63d041b9 修复DataZoom拖动时SerieLabel不刷新的问题 (#165) 2021-08-31 13:41:46 +08:00
monitor1394
8fccfdb5fc Fixed the problem of displaying exceptions after adding data again when DataZoom is enable (#163) 2021-08-26 20:46:50 +08:00
monitor1394
f08ae794ae 修复Theme主题切换无法保持到场景上的问题 (#166) 2021-08-26 20:42:11 +08:00
monitor1394
8efa8145b1 匀速动画优化 2021-08-25 13:41:41 +08:00
monitor1394
e247ad9e71 增加AnimationalongWithLinePath参数设置折线轨迹匀速动画 2021-08-24 07:21:00 +08:00
monitor1394
645506a6fd Added serie's ignoreLineBreak parameter (#164) 2021-08-22 09:26:14 +08:00
monitor1394
c5ef7e765b Fixed axis label may not be updated when datazoom is turn on (#164) 2021-08-22 07:55:16 +08:00
monitor1394
3949018555 Improved Axis's AxisLabel text rotate setting to avoid inconsistency offset in DataZoom (#163) 2021-08-15 22:36:14 +08:00
monitor1394
34b0a97198 Added Legend's textAutoColor to set the text color match with Serie color (#163) 2021-08-15 22:36:06 +08:00
monitor1394
de3e482687 优化BarChart设置Corner时正负柱条圆角对称 2021-08-12 22:16:36 +08:00
monitor1394
8dbbbd7405 优化Serie的数据全为0时Y轴不显示的问题 2021-08-03 08:23:02 +08:00
monitor1394
3316fce8a5 修复Serie开启ignore时被忽略的数据还会参与计算的问题 (#161) 2021-07-29 08:27:23 +08:00
monitor1394
f85f96a560 完善BarChartZebra斑马柱图渐变支持 2021-07-29 08:05:54 +08:00
monitor1394
8f6f5790b6 修复TextMeshPro Enable时找不到XCharts路径的问题 (#160) 2021-07-26 21:28:13 +08:00
43 changed files with 944 additions and 262 deletions

View File

@@ -1,7 +1,10 @@
# 更新日志
[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)
@@ -37,7 +40,55 @@
[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

View File

@@ -1,7 +1,10 @@
# 更新日志
[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)
@@ -37,7 +40,55 @@
[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

View File

@@ -176,6 +176,9 @@
* `ceilRate`最大最小值向上取整的倍率。默认为0时自动计算。
* `splitNumber`:分割段数。默认为 `5`
* `isAxisTooltip`是否Tooltip显示轴线上的所有数据。只对Mutiple类型的Radar有效。
* `outRangeColor`:数值超出范围时显示的颜色。
* `connectCenter`:数值是否连线到中心点。
* `lineGradient`:数值线段是否渐变。
* `splitLine`:分割线条 [AxisSplitLine](#AxisSplitLine)。
* `splitArea`:分割区域 [AxisSplitArea](#AxisSplitArea)。
* `indicator`:是否显示指示器。
@@ -187,6 +190,7 @@
* `name`:指示器名称。
* `max`:指示器的最大值,默认为 0 无限制。
* `min`:指示器的最小值,默认为 0 无限制。
* `range`:指示器的正常值范围,当数值超出这个范围时显示`Radar``outRangeColor`颜色。
* `textStyle`:文本样式 [TextStyle](#TextStyle)。
## `TextLimit`
@@ -229,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`个数据)。
@@ -810,6 +815,7 @@ K线图系列。
* `fadeOutDuration`:设定的渐出动画时长,单位毫秒。如果要设置单个数据项的渐出时长,可以用代码定制:`customFadeOutDuration`
* `dataChangeEnable`:是否开启数据变更动画。
* `dataChangeDuration`:数据变更动画时长,单位毫秒。
* `alongWithLinePath`:是否沿着线的轨迹进行匀速动画。
## `AreaStyle`

View File

@@ -176,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.
@@ -190,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`
@@ -233,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).

View File

@@ -28,6 +28,7 @@ namespace XCharts
PropertyField(prop, "m_DataChangeEnable");
PropertyField(prop, "m_DataChangeDuration");
PropertyField(prop, "m_ActualDuration");
PropertyField(prop, "m_AlongWithLinePath");
--EditorGUI.indentLevel;
}
}

View File

@@ -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)

View File

@@ -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");

View File

@@ -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;
}

View File

@@ -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");
@@ -401,6 +402,8 @@ 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");
@@ -413,6 +416,10 @@ 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));

View File

@@ -543,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);
}
@@ -643,6 +643,9 @@ namespace XCharts
{
m_Theme.CopyTheme(theme);
SetAllComponentDirty();
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(this);
#endif
}
/// <summary>

View File

@@ -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;

View File

@@ -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}。

View File

@@ -56,6 +56,7 @@ namespace XCharts
[SerializeField] private string m_Name;
[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>
@@ -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,6 +325,12 @@ namespace XCharts
return true;
}
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)

View File

@@ -327,6 +327,7 @@ namespace XCharts
[SerializeField] private bool m_Clip = false;
[SerializeField] private bool m_Ignore = false;
[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;
@@ -362,6 +363,7 @@ namespace XCharts
[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>();
@@ -771,6 +773,15 @@ namespace XCharts
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
@@ -1178,7 +1189,9 @@ namespace XCharts
public float runtimeY { get; internal set; }
public float runtimeWidth { get; internal set; }
public float runtimeHeight { get; internal set; }
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()
@@ -1245,7 +1258,7 @@ namespace XCharts
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];
}
@@ -1264,7 +1277,7 @@ namespace XCharts
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];
}
@@ -1283,7 +1296,7 @@ namespace XCharts
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];
}
@@ -1302,7 +1315,7 @@ namespace XCharts
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];
}
@@ -1321,9 +1334,8 @@ namespace XCharts
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;
}
@@ -1339,7 +1351,7 @@ namespace XCharts
double total = 0;
foreach (var sdata in data)
{
if (sdata.show)
if (sdata.show && !IsIgnoreValue(sdata.data[1]))
total += sdata.data[0];
}
return total;
@@ -1356,6 +1368,7 @@ namespace XCharts
RemoveData(0);
}
m_Data.Clear();
m_NeedUpdateFilterData = true;
SetVerticesDirty();
}
@@ -1389,6 +1402,7 @@ namespace XCharts
m_DownSmoothPoints.Remove(serieData.index);
}
m_Data.RemoveAt(index);
m_NeedUpdateFilterData = true;
}
}
@@ -1417,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)
@@ -1517,6 +1532,32 @@ 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()
{
@@ -1633,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>

View File

@@ -65,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;
@@ -101,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).
@@ -115,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个数据
@@ -298,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
@@ -447,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>

View File

@@ -262,7 +262,6 @@ namespace XCharts
{
public CoordinateChart chart;
private GameObject m_MarkLineLabelRoot;
private bool m_RefreshLabel = false;
public MarkLineHandler(CoordinateChart chart)
{
@@ -309,15 +308,16 @@ namespace XCharts
public void Update()
{
if (m_RefreshLabel)
foreach (var serie in chart.series.list)
{
m_RefreshLabel = false;
foreach (var serie in chart.series.list)
var show = serie.show && serie.markLine.show;
foreach (var data in serie.markLine.data)
{
if (!serie.show || !serie.markLine.show) continue;
foreach (var data in serie.markLine.data)
if (data.runtimeLabel != null)
{
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));
@@ -514,13 +514,12 @@ namespace XCharts
data.runtimeCurrentEndPosition = ep;
if (sp != Vector3.zero || ep != Vector3.zero)
{
m_RefreshLabel = true;
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, lineColor, lineWidth, LineStyle.Type.Dashed);
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);
@@ -539,7 +538,7 @@ namespace XCharts
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,
symbol.gap, true, cornerRadius, grid, startPos);
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)

View File

@@ -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)

View File

@@ -18,7 +18,10 @@ 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;
@@ -33,19 +36,25 @@ namespace XCharts
[SerializeField] private bool m_EnableSymbol = false;
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
[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>
@@ -113,6 +122,7 @@ namespace XCharts
/// 可指定任意维数的数值列表。
/// </summary>
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.
/// 该数据项是否要显示。
@@ -174,18 +184,28 @@ 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; }
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;
@@ -200,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();
@@ -350,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)

View File

@@ -48,7 +48,10 @@ namespace XCharts
/// <summary>
/// 自定义标记。
/// </summary>
Custom
Custom,
EmptyRect,
EmptyTriangle,
EmptyDiamond
}
/// <summary>

View File

@@ -227,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

View File

@@ -118,7 +118,8 @@ namespace XCharts
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (axis.type == Axis.AxisType.Value)
{
if (minValue == 0 && maxValue == 0) return string.Empty;
if (minValue == 0 && maxValue == 0)
maxValue = axis.max != 0 ? axis.max : 1;
double value = 0;
if (forcePercent) maxValue = 100;
if (axis.interval > 0)
@@ -213,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;
}
@@ -396,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;
}

View File

@@ -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);
@@ -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);
}

View File

@@ -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);

View File

@@ -23,7 +23,7 @@ namespace XCharts
if (serieData.show && serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value < min) min = value;
if (value < min && !serie.IsIgnoreValue(value)) min = value;
}
}
return min == double.MaxValue ? 0 : min;
@@ -39,7 +39,7 @@ namespace XCharts
if (serieData.show && serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value < min)
if (value < min && !serie.IsIgnoreValue(value))
{
min = value;
minData = serieData;
@@ -58,7 +58,7 @@ namespace XCharts
if (serieData.show && serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value > max) max = value;
if (value > max && !serie.IsIgnoreValue(value)) max = value;
}
}
return max == double.MinValue ? 0 : max;
@@ -74,7 +74,7 @@ namespace XCharts
if (serieData.show && serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value > max)
if (value > max && !serie.IsIgnoreValue(value))
{
max = value;
maxData = serieData;
@@ -93,7 +93,9 @@ namespace XCharts
var serieData = dataList[i];
if (serieData.show && serieData.data.Count > dimension)
{
total += serieData.data[dimension];
var value = serieData.data[dimension];
if (!serie.IsIgnoreValue(value))
total += value;
}
}
return total != 0 ? total / dataList.Count : 0;
@@ -109,7 +111,9 @@ namespace XCharts
var serieData = dataList[i];
if (serieData.show && serieData.data.Count > dimension)
{
s_TempList.Add(serieData.data[dimension]);
var value = serieData.data[dimension];
if (!serie.IsIgnoreValue(value))
s_TempList.Add(value);
}
}
s_TempList.Sort();
@@ -139,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;
}
}
}
}
@@ -171,8 +178,11 @@ namespace XCharts
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;
}
}
}
}
@@ -225,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
{
@@ -233,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);
}
}
@@ -419,9 +431,17 @@ 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;
if (serieData.enableIconStyle) return serieData.iconStyle;
else return serie.iconStyle;
}
@@ -690,7 +710,6 @@ namespace XCharts
});
break;
case SerieDataSortType.None:
break;
}
}

View File

@@ -443,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.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 (currData > max) max = currData;
if (currData < min) min = currData;
}
@@ -510,7 +512,8 @@ namespace XCharts
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;
}
}
}

View File

@@ -224,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();
}
@@ -450,7 +453,7 @@ namespace XCharts
var active = IsActiveByLegend(datas[i]);
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) =>
@@ -526,23 +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 && !iconStyle.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)
@@ -564,6 +570,12 @@ namespace XCharts
item.SetIcon(iconImage);
item.SetIconActive(iconStyle.show);
serieData.labelObject = item;
foreach (var dataIndex in serieData.children)
{
AddSerieLabel(serie, serie.GetSerieData(dataIndex), ref count);
count++;
}
}
private void InitSerieTitle()
@@ -1011,17 +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, gap, cornerRadius, Vector3.zero);
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, float gap, float[] cornerRadius, Vector3 startPos)
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, startPos);
cornerRadius, fillColor, backgroundColor, smoothness, startPos);
}
public void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)

View File

@@ -728,12 +728,12 @@ namespace XCharts
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, 1), new Vector2(0, 1), new Vector2(1, 0.5f),
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.SetPosition(GetLabelXPosition(totalWidth + gapWidth, i, xAxisIndex, xAxis));
xAxis.runtimeAxisLabelList.Add(label);
totalWidth += labelWidth;
}
@@ -1464,10 +1464,11 @@ 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;
@@ -1546,9 +1547,13 @@ 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)
{
@@ -1556,6 +1561,7 @@ namespace XCharts
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);
@@ -1681,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 startPos)
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, startPos);
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)

View File

@@ -329,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
@@ -356,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
{
@@ -367,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);
}
}
}
@@ -376,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);
}
}

View File

@@ -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, i > 0 ? serie.dataPoints[i - 1] : grid.runtimePosition);
symbolToColor, backgroundColor, symbol.gap, clip, cornerRadius, grid,
i > 0 ? serie.dataPoints[i - 1] : grid.runtimePosition);
}
}
@@ -167,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)
@@ -215,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;
@@ -239,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())
{
@@ -277,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];
@@ -301,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];
@@ -314,22 +358,22 @@ 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;
}
@@ -618,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:
@@ -635,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:
@@ -678,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;
@@ -789,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
@@ -941,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)
{
@@ -1172,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);

View File

@@ -36,6 +36,7 @@ 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);
double xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
@@ -67,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())

View File

@@ -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)

View File

@@ -413,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
@@ -496,6 +497,7 @@ 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);

View File

@@ -387,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);
}
}
}
@@ -439,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;
@@ -503,8 +506,10 @@ 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 = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
: radar.runtimeDataRadius * value / max);
@@ -515,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
{
@@ -526,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)
@@ -558,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())
@@ -602,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;
@@ -632,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));
@@ -650,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;
@@ -685,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);
@@ -697,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);
}
}
}

View File

@@ -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);

View File

@@ -6,11 +6,13 @@
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The delegate function for AxisLabel's formatter. |
/// AxisLabel的formatter自定义委托。
/// AxisLabel的formatter自定义委托函数
/// </summary>
/// <param name="labelIndex">label索引</param>
/// <param name="value">当前label对应的数值数据Value轴或Time轴有效</param>
@@ -19,10 +21,16 @@ namespace XCharts
public delegate string DelegateAxisLabelFormatter(int labelIndex, double value, string category);
/// <summary>
/// The delegate function for SerieLabels formatter.
/// SerieLabel的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);
}

View File

@@ -246,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;
}
@@ -270,6 +275,30 @@ namespace XCharts
return 0;
}
public string GetPreferredText(string content, string suffix, float maxWidth)
{
#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)

View File

@@ -18,7 +18,7 @@ namespace XCharts
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, Vector3 startPos)
Color32 centerFillColor, Color32 backgroundColor, float smoothness, Vector3 startPos)
{
switch (type)
{
@@ -38,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:
@@ -56,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)
{
@@ -67,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)
{
@@ -78,6 +102,19 @@ 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;
@@ -89,28 +126,44 @@ namespace XCharts
}
}
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);

View File

@@ -510,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);
}
}
}

View File

@@ -33,8 +33,8 @@ namespace XCharts
[ExecuteInEditMode]
public class XChartsMgr : MonoBehaviour
{
internal static string _version = "2.3.0";
internal static int _versionDate = 20210724;
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; } }
@@ -337,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;

View File

@@ -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;

View File

@@ -55,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;
@@ -65,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);
@@ -119,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;
@@ -133,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>
@@ -153,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>
@@ -277,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>
@@ -436,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>
@@ -477,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)
{
@@ -562,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);
@@ -805,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>
@@ -825,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;
@@ -842,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))

View File

@@ -1,9 +1,9 @@
{
"name": "com.monitor1394.xcharts",
"displayName": "XCharts",
"version": "2.3.0",
"date": "20210724",
"checkdate": "20210724",
"version": "2.6.0",
"date": "20211230",
"checkdate": "20211230",
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
"unity": "2018.3",
"description": "A charting and data visualization library for Unity.",

View File

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