diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md index 0424493e..599effa0 100644 --- a/Documentation~/en/api.md +++ b/Documentation~/en/api.md @@ -340,7 +340,7 @@ slug: /api |SetSeriePainterMaterial()||public void SetSeriePainterMaterial(Material material)
设置Serie Painter的材质球 | |SetTopPainterMaterial()||public void SetTopPainterMaterial(Material material)
设置Top Painter的材质球 | |SetUpperPainterMaterial()||public void SetUpperPainterMaterial(Material material)
设置Upper Painter的材质球 | -|TriggerTooltip()|v3.7.0|public bool TriggerTooltip(int dataIndex)
trigger tooltip by data index. | +|TriggerTooltip()|v3.7.0|public bool TriggerTooltip(int dataIndex, int serieIndex = 0)
trigger tooltip by data index. | |TriggerTooltip()|v3.7.0|public bool TriggerTooltip(Vector3 localPosition)
trigger tooltip by chart local position. | |TryAddChartComponent()||public bool TryAddChartComponent(Type type)| |TryAddChartComponent<T>()||public bool TryAddChartComponent<T>() where T : MainComponent| diff --git a/Documentation~/en/changelog.md b/Documentation~/en/changelog.md index b964587e..5d64d0f9 100644 --- a/Documentation~/en/changelog.md +++ b/Documentation~/en/changelog.md @@ -2,6 +2,7 @@ # 更新日志 [master](#master) +[v3.8.1](#v381) [v3.8.0](#v380) [v3.7.0](#v370) [v3.6.0](#v360) @@ -63,6 +64,18 @@ ## master +## v3.8.1 + +* (2023.10.02) Release `v3.8.1` version +* (2023.09.29) Fixed issue where `Bar` is set to `Bottom` when horizontal does not take effect +* (2023.09.22) Added support for dashed lines in `Line`'s smooth curves +* (2023.09.16) Fix to `Tooltip` reporting an exception when there is no data in the category axis (#279) +* (2023.09.16) Fix to `Pie` drawing exception with no data (#278) +* (2023.09.12) Added `Pie` `radiusGradient` to set the gradient effect in the radius direction +* (2023.09.05) Improved the performance of LabelLine`s lineEndX in Pie +* (2023.09.05) Fixed `TriggerTooltip()` interface not working for `Ring` +* (2023.09.05) Fixed drawing error when `Radar` data is all zeros + ## v3.8.0 Highlights: diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index 807a7430..1e5c6e26 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -1387,6 +1387,9 @@ The style of line. |width|0||the width of line. |length|0||the length of line. |opacity|1||Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0. +|dashLength|4|v3.8.1|the length of dash line. default value is 0, which means the length of dash line is 12 times of line width. Represents a multiple of the number of segments in a line chart. +|dotLength|2|v3.8.1|the length of dot line. default value is 0, which means the length of dot line is 2 times of line width. Represents a multiple of the number of segments in a line chart. +|gapLength|2|v3.8.1|the length of gap line. default value is 0, which means the length of gap line is 3 times of line width. Represents a multiple of the number of segments in a line chart. ```mdx-code-block @@ -1628,6 +1631,19 @@ Grid component. > XCharts.Runtime.Pie : [Serie](#serie) +```mdx-code-block + +``` + + +|field|default|since|comment| +|--|--|--|--| +|radiusGradient|false|v3.8.1|Whether to use gradient color in pie chart. + +```mdx-code-block + +``` + ## PolarAxisTheme > XCharts.Runtime.PolarAxisTheme : [BaseAxisTheme](#baseaxistheme) diff --git a/Documentation~/en/img/xcharts.png b/Documentation~/en/img/xcharts.png new file mode 100644 index 00000000..91b61248 Binary files /dev/null and b/Documentation~/en/img/xcharts.png differ diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index c89e9ef7..6acc461a 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -340,7 +340,7 @@ slug: /api |SetSeriePainterMaterial()||public void SetSeriePainterMaterial(Material material)
设置Serie Painter的材质球 | |SetTopPainterMaterial()||public void SetTopPainterMaterial(Material material)
设置Top Painter的材质球 | |SetUpperPainterMaterial()||public void SetUpperPainterMaterial(Material material)
设置Upper Painter的材质球 | -|TriggerTooltip()|v3.7.0|public bool TriggerTooltip(int dataIndex)
尝试触发指定数据项的Tooltip. | +|TriggerTooltip()|v3.7.0|public bool TriggerTooltip(int dataIndex, int serieIndex = 0)
尝试触发指定数据项的Tooltip. | |TriggerTooltip()|v3.7.0|public bool TriggerTooltip(Vector3 localPosition)
在指定的位置尝试触发Tooltip. | |TryAddChartComponent()||public bool TryAddChartComponent(Type type)| |TryAddChartComponent<T>()||public bool TryAddChartComponent<T>() where T : MainComponent| diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 9659d0d4..0eb30888 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -6,6 +6,7 @@ slug: /changelog # 更新日志 [master](#master) +[v3.8.1](#v381) [v3.8.0](#v380) [v3.7.0](#v370) [v3.6.0](#v360) @@ -68,6 +69,18 @@ slug: /changelog ## master +## v3.8.1 + +* (2023.10.02) 发布`v3.8.1`版本 +* (2023.09.29) 修复`Bar`在水平方向时`Label`设置为`Bottom`不生效的问题 +* (2023.09.22) 增加`Line`的平滑曲线对`Dash`虚线的支持 +* (2023.09.16) 修复`Tooltip`在类目轴无数据时异常报错的问题 (#279) +* (2023.09.16) 修复`Pie`无数据时绘制异常的问题 (#278) +* (2023.09.12) 增加`Pie`的`radiusGradient`可设置半径方向的渐变效果 +* (2023.09.05) 优化`LabelLine`的`lineEndX`在`Pie`中的表现 +* (2023.09.05) 修复`TriggerTooltip()`接口对`Ring`无效的问题 +* (2023.09.05) 修复`Radar`数据全为0时绘制报错的问题 + ## v3.8.0 版本要点: diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index 69c6ccf9..4ef05de9 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -1387,6 +1387,9 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart |width|0||线宽。 |length|0||线长。 |opacity|1||线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 +|dashLength|4|v3.8.1|虚线的长度。默认0时为线条宽度的12倍。在折线图中代表分割段数的倍数。 +|dotLength|2|v3.8.1|点线的长度。默认0时为线条宽度的3倍。在折线图中代表分割段数的倍数。 +|gapLength|2|v3.8.1|点线的长度。默认0时为线条宽度的3倍。在折线图中代表分割段数的倍数。 ```mdx-code-block @@ -1628,6 +1631,19 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart > XCharts.Runtime.Pie : [Serie](#serie) +```mdx-code-block + +``` + + +|field|default|since|comment| +|--|--|--|--| +|radiusGradient|false|v3.8.1|是否开启半径方向的渐变效果。 + +```mdx-code-block + +``` + ## PolarAxisTheme > XCharts.Runtime.PolarAxisTheme : [BaseAxisTheme](#baseaxistheme) diff --git a/Documentation~/zh/img/xcharts.png b/Documentation~/zh/img/xcharts.png new file mode 100644 index 00000000..91b61248 Binary files /dev/null and b/Documentation~/zh/img/xcharts.png differ diff --git a/Documentation~/zh/support.md b/Documentation~/zh/support.md index 6a186d64..c981872a 100644 --- a/Documentation~/zh/support.md +++ b/Documentation~/zh/support.md @@ -29,16 +29,16 @@ slug: /support | ----- |--|--|--|--|--|--| | 订阅费用 | -- | `98`¥ | `298`¥ | 首年`1298`¥
后续`298¥`* | 首年`1698`¥
后续`298¥`* | `联系我们` | | 订阅时长 | -- | `7`天* | `1`年 | `1`年 | `1`年 | `1`年 | -| 订阅席位 | -- | `1`个席位 | `1`个席位 |`1`个席位|`1`个席位|`5`个以上席位| -| 订阅条件 | -- | | Github帐号 | Github帐号 |Github帐号
企业银行帐号|Github帐号
企业银行帐号| +| 拥有席位 | -- | `1`个席位 | `1`个席位 |`1`个席位|`1`个席位|`5`个以上席位| +| 增加席位 | -- | -- | -- | -- |支持|支持| | __`服务方式:`__| | 官方QQ群交流 | √ | √ | √ | √ | √ | √ | | QQ一对一交流 | | √ | √ | √ | √ | √ | -| 专属VIP群交流 | | | √ | √ | √ | | +| 专属VIP群交流 | | | √ | √ | √ | √ | | 微信交流 | | | | | √ | √(企业专属群) | +| 电话交流 | | | | | | √ | | __`服务内容:`__| -| 可商用 | √ | √ | √ | √ | √ | √ | -| 可二次开发 | √ | √ | √ | √ | √ | √ | +| 可商用可二次开发 | √ | √ | √ | √ | √ | √ | | 有问即答 | | √ | √ | √ | √ | √ | | 新手入门指导 | | √ | √ | √ | √ | √ | | 开发优化指导 | | √ | √ | √ | √ | √ | @@ -48,7 +48,8 @@ slug: /support | 可另付费定制 | | | √ | √ | √ | √ | | 可另付费加急 | | | √ | √ | √ | √ | | 扩展UI组件 | | | √ | √ | √ | √ | -| 付费方式 | | | 二维码 | 二维码 | __对公转账__* | __对公转账__* | +| 首页赞助展示 | | | | | | √ | +| 付费方式 | | | 二维码 | 二维码 | __公对公转账__* | __公对公转账__* | | 支持开发票 | | | 普票 | 普票 | __专票__ | __专票__ | | 扩展图表购买 | | | 按需购买 | __全部免费__* | __全部免费__* | __全部免费__* | | 扩展图表源码 | | | 永久持有 | 永久持有 | 永久持有 | 永久持有 | @@ -61,6 +62,7 @@ slug: /support >*__`扩展图表`__ 购买后代码可永久持有和商用,1年的更新和技术支持。可继续订阅VIP延长服务时间。 >*__`全部免费`__ 是指在订阅期间的`个人SVIP`和`企业VIP`的订阅用户,可免费使用全部的扩展图表。 >*__`次年付费`__ 个人SVIP和企业VIP的首年和次年付费不一样,次年付费都是`298¥`。 +>*__`增加席位`__ 企业VIP支持增加席位,每个席位`298¥`一年。 >*__`对公转账`__ 有开专票需求时,可用企业银行帐号进行公对公转账支付。二维码支付不支持开专票,只能开普票。发票默认都是电子发票。 >*__`登记资料`__ 订阅成功后,需提供手机号和Github帐号进行登记,手机号用于确认归属,Github帐号用于下载源码。 @@ -68,7 +70,7 @@ slug: /support 扩展图表为另付费购买图表,只对订阅了`VIP`服务的用户开放购买。对于`个人SVIP`和`企业VIP`的订阅用户,所有扩展图表仓库在订阅期间可全部免费使用,不用再单独购买。 -对所有已购买的扩展图表,源码可永久持有,并获得持续一年的更新支持和技术服务,一年后如需更新支持服务,可再继续订阅`VIP`服务。 +对所有已购买的扩展图表,源码可永久持有但不能传播,并获得持续一年的更新支持和技术服务,一年后如需更新支持等服务,可再继续订阅`VIP`服务。 |编号|扩展图表|扩展图表|价格| |--|--|--|--| diff --git a/Editor/ChildComponents/LineStyleDrawer.cs b/Editor/ChildComponents/LineStyleDrawer.cs index 17d6facb..7607c38c 100644 --- a/Editor/ChildComponents/LineStyleDrawer.cs +++ b/Editor/ChildComponents/LineStyleDrawer.cs @@ -21,6 +21,9 @@ namespace XCharts.Editor PropertyField(prop, "m_Width"); PropertyField(prop, "m_Length"); PropertyField(prop, "m_Opacity"); + PropertyField(prop, "m_DashLength"); + PropertyField(prop, "m_DotLength"); + PropertyField(prop, "m_GapLength"); --EditorGUI.indentLevel; } } diff --git a/Editor/Series/PieEditor.cs b/Editor/Series/PieEditor.cs index 34e8633f..22df5cc3 100644 --- a/Editor/Series/PieEditor.cs +++ b/Editor/Series/PieEditor.cs @@ -22,6 +22,7 @@ namespace XCharts.Editor PropertyField("m_Ignore"); PropertyField("m_IgnoreValue"); PropertyField("m_ClickOffset"); + PropertyField("m_RadiusGradient"); }); PropertyField("m_ItemStyle"); PropertyField("m_Animation"); diff --git a/README-en.md b/README-en.md index 3c0f8a23..e7b0b9f1 100644 --- a/README-en.md +++ b/README-en.md @@ -43,6 +43,8 @@

+![XCharts](Documentation~/zh/img/xcharts.png) + A powerful and easy-to-use data visualization library for Unity. It supports more than ten built-in charts, including line, bar, pie, radar, scatter, heatmap, ring, candlestick, polar, parallel coordinates, as well as extended charts such as 3d pie, 3d bar, 3d pyramid, funnel, gauge, liquid, pictorialbar, gantt, and treemap. [XCharts3.0 Homepage](https://xcharts-team.github.io) diff --git a/README.md b/README.md index 19a276ad..a597108b 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@

+![XCharts](Documentation~/zh/img/xcharts.png) + 一款基于`UGUI`的功能强大、简单易用的数据可视化图表插件。支持`折线图`、`柱状图`、`饼图`、`雷达图`、`散点图`、`热力图`、`环形图`、`K线图`、`极坐标`、`平行坐标`等十多种内置图表,以及`3D饼图`、`3D柱图`、`3D金字塔`、`漏斗图`、`仪表盘`、`水位图`、`象形柱图`、`甘特图`、`矩形树图`等扩展图表。 [XCharts 官方主页](https://xcharts-team.github.io) diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 4651da8a..21cb690e 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -38,7 +38,7 @@ namespace XCharts return; if (!grid.context.isPointerEnter) { - axis.context.pointerValue = double.NaN; + axis.context.pointerValue = double.PositiveInfinity; } else { diff --git a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs index a72e17c5..970ecfeb 100644 --- a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs +++ b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs @@ -34,7 +34,7 @@ namespace XCharts.Runtime if (!polar.context.isPointerEnter) { - axis.context.pointerValue = double.NaN; + axis.context.pointerValue = double.PositiveInfinity; return; } diff --git a/Runtime/Component/Child/LineStyle.cs b/Runtime/Component/Child/LineStyle.cs index d8909a6a..23f868d4 100644 --- a/Runtime/Component/Child/LineStyle.cs +++ b/Runtime/Component/Child/LineStyle.cs @@ -47,6 +47,9 @@ namespace XCharts.Runtime [SerializeField] private float m_Width = 0; [SerializeField] private float m_Length = 0; [SerializeField][Range(0, 1)] private float m_Opacity = 1; + [SerializeField][Since("v3.8.1")] private float m_DashLength = 4; + [SerializeField][Since("v3.8.1")] private float m_DotLength = 2; + [SerializeField][Since("v3.8.1")] private float m_GapLength = 2; /// /// Whether show line. @@ -121,6 +124,39 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } + /// + /// the length of dash line. default value is 0, which means the length of dash line is 12 times of line width. + /// Represents a multiple of the number of segments in a line chart. + /// |虚线的长度。默认0时为线条宽度的12倍。在折线图中代表分割段数的倍数。 + /// + public float dashLength + { + get { return m_DashLength; } + set { if (PropertyUtil.SetStruct(ref m_DashLength, value)) SetVerticesDirty(); } + } + + /// + /// the length of dot line. default value is 0, which means the length of dot line is 2 times of line width. + /// Represents a multiple of the number of segments in a line chart. + /// |点线的长度。默认0时为线条宽度的3倍。在折线图中代表分割段数的倍数。 + /// + public float dotLength + { + get { return m_DotLength; } + set { if (PropertyUtil.SetStruct(ref m_DotLength, value)) SetVerticesDirty(); } + } + + /// + /// the length of gap line. default value is 0, which means the length of gap line is 3 times of line width. + /// Represents a multiple of the number of segments in a line chart. + /// |点线的长度。默认0时为线条宽度的3倍。在折线图中代表分割段数的倍数。 + /// + public float gapLength + { + get { return m_GapLength; } + set { if (PropertyUtil.SetStruct(ref m_GapLength, value)) SetVerticesDirty(); } + } + public LineStyle() { } @@ -150,6 +186,9 @@ namespace XCharts.Runtime lineStyle.toColor2 = toColor2; lineStyle.width = width; lineStyle.opacity = opacity; + lineStyle.dashLength = dashLength; + lineStyle.dotLength = dotLength; + lineStyle.gapLength = gapLength; return lineStyle; } @@ -162,6 +201,14 @@ namespace XCharts.Runtime toColor2 = lineStyle.toColor2; width = lineStyle.width; opacity = lineStyle.opacity; + dashLength = lineStyle.dashLength; + dotLength = lineStyle.dotLength; + gapLength = lineStyle.gapLength; + } + + public bool IsNotSolidLine() + { + return type != Type.Solid && type != Type.None; } public Color32 GetColor() @@ -170,7 +217,7 @@ namespace XCharts.Runtime return m_Color; var color = m_Color; - color.a = (byte) (color.a * m_Opacity); + color.a = (byte)(color.a * m_Opacity); return color; } @@ -201,7 +248,7 @@ namespace XCharts.Runtime } if (m_Opacity != 1) { - color.a = (byte) (color.a * m_Opacity); + color.a = (byte)(color.a * m_Opacity); } return color; } @@ -230,7 +277,7 @@ namespace XCharts.Runtime else { var color = themeColor; - color.a = (byte) (color.a * opacity); + color.a = (byte)(color.a * opacity); return color; } } diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index c1d4de97..6c502c28 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -671,11 +671,12 @@ namespace XCharts.Runtime /// |尝试触发指定数据项的Tooltip. /// /// 数据项索引 + /// Serie索引,默认为第0个Serie /// [Since("v3.7.0")] - public bool TriggerTooltip(int dataIndex) + public bool TriggerTooltip(int dataIndex, int serieIndex = 0) { - var serie = GetSerie(0); + var serie = GetSerie(serieIndex); if (serie == null) return false; var dataPoints = serie.context.dataPoints; var dataPoint = Vector3.zero; diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index afddde51..a791524c 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -21,8 +21,8 @@ namespace XCharts.Runtime [ExecuteInEditMode] public static class XChartsMgr { - public static readonly string version = "3.8.0"; - public static readonly int versionDate = 20230903; + public static readonly string version = "3.8.1"; + public static readonly int versionDate = 20231001; public static string fullVersion { get { return version + "-" + versionDate; } } internal static List chartList = new List(); diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index 0cc1faa3..3de86ccc 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -67,7 +67,10 @@ namespace XCharts.Runtime { case LabelStyle.Position.Bottom: var center = serieData.context.rect.center; - return new Vector3(center.x, center.y - serieData.context.rect.height / 2); + if(serie.context.isHorizontal) + return new Vector3(center.x - serieData.context.rect.width/2, center.y); + else + return new Vector3(center.x, center.y - serieData.context.rect.height / 2); case LabelStyle.Position.Center: case LabelStyle.Position.Inside: return serieData.context.rect.center; @@ -193,6 +196,7 @@ namespace XCharts.Runtime var areaToColor = ColorUtil.clearColor32; var interacting = false; + serie.context.isHorizontal = isY; serie.containerIndex = m_SerieGrid.index; serie.containterInstanceId = m_SerieGrid.instanceId; serie.animation.InitProgress(axisXY, axisXY + axisLength); diff --git a/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Runtime/Serie/Line/LineHandler.GridCoord.cs index 5694aa3b..e05a559e 100644 --- a/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -296,6 +296,7 @@ namespace XCharts.Runtime var lineWidth = LineHelper.GetLineWidth(ref interacting, serie, chart.theme.serie.lineWidth); axis.context.scaleWidth = scaleWid; + serie.context.isHorizontal = isY; serie.containerIndex = m_SerieGrid.index; serie.containterInstanceId = m_SerieGrid.instanceId; diff --git a/Runtime/Serie/Line/LineHelper.cs b/Runtime/Serie/Line/LineHelper.cs index d188a0d8..d53eb7a2 100644 --- a/Runtime/Serie/Line/LineHelper.cs +++ b/Runtime/Serie/Line/LineHelper.cs @@ -285,8 +285,11 @@ namespace XCharts.Runtime var lineColor = SerieHelper.GetLineColor(serie, null, theme, serie.context.colorIndex); var lastDataIsIgnore = datas[0].isIgnoreBreak; - var smooth = serie.lineType == LineType.Smooth; var firstInGridPointIndex = serie.clip ? -1 : 1; + var segmentCount = 0; + var dashLength = serie.lineStyle.dashLength; + var gapLength = serie.lineStyle.gapLength; + var dotLength = serie.lineStyle.dotLength; for (int i = 1; i < dataCount; i++) { var cdata = datas[i]; @@ -315,31 +318,45 @@ namespace XCharts.Runtime firstInGridPointIndex = i; if (isClip) isIgnore = true; } - if (!smooth) + if (serie.lineStyle.type == LineStyle.Type.None) { + handled = true; + break; + } + { + segmentCount++; + var index = 0f; switch (serie.lineStyle.type) { case LineStyle.Type.Dashed: - UGL.DrawDashLine(vh, lp, cp, lineWidth, lineColor, lineColor, 0, 0); - handled = true; + index = segmentCount % (dashLength + gapLength); + if (index >= dashLength) + isIgnore = true; break; case LineStyle.Type.Dotted: - UGL.DrawDotLine(vh, lp, cp, lineWidth, lineColor, lineColor, 0, 0); - handled = true; + index = segmentCount % (dotLength + gapLength); + if (index >= dotLength) + isIgnore = true; break; case LineStyle.Type.DashDot: - UGL.DrawDashDotLine(vh, lp, cp, lineWidth, lineColor, 0, 0, 0); - handled = true; + index = segmentCount % (dashLength + dotLength + 2 * gapLength); + if (index >= dashLength && index < dashLength + gapLength) + isIgnore = true; + else if (index >= dashLength + gapLength + dotLength) + isIgnore = true; break; case LineStyle.Type.DashDotDot: - UGL.DrawDashDotDotLine(vh, lp, cp, lineWidth, lineColor, 0, 0, 0); - handled = true; - break; - case LineStyle.Type.None: - handled = true; + index = segmentCount % (dashLength + 2 * dotLength + 3 * gapLength); + if (index >= dashLength && index < dashLength + gapLength) + isIgnore = true; + else if (index >= dashLength + gapLength + dotLength && index < dashLength + dotLength + 2 * gapLength) + isIgnore = true; + else if (index >= dashLength + 2 * gapLength + 2 * dotLength) + isIgnore = true; break; } } + if (handled) { lastDataIsIgnore = isIgnore; @@ -476,7 +493,7 @@ namespace XCharts.Runtime private static void UpdateNormalLineDrawPoints(Serie serie, Settings setting, VisualMap visualMap) { var isVisualMapGradient = VisualMapHelper.IsNeedGradient(visualMap); - if (isVisualMapGradient || serie.clip) + if (isVisualMapGradient || serie.clip || (serie.lineStyle.IsNotSolidLine())) { var dataPoints = serie.context.dataPoints; if (dataPoints.Count > 1) diff --git a/Runtime/Serie/Pie/Pie.cs b/Runtime/Serie/Pie/Pie.cs index 9d173270..864b0023 100644 --- a/Runtime/Serie/Pie/Pie.cs +++ b/Runtime/Serie/Pie/Pie.cs @@ -1,3 +1,5 @@ +using UnityEngine; + namespace XCharts.Runtime { [System.Serializable] @@ -9,9 +11,21 @@ namespace XCharts.Runtime [SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")] public class Pie : Serie { + [SerializeField][Since("v3.8.1")] private bool m_RadiusGradient = false; + public override SerieColorBy defaultColorBy { get { return SerieColorBy.Data; } } public override bool titleJustForSerie { get { return true; } } + /// + /// Whether to use gradient color in pie chart. + /// | 是否开启半径方向的渐变效果。 + /// + public bool radiusGradient + { + get { return m_RadiusGradient; } + set { if (PropertyUtil.SetStruct(ref m_RadiusGradient, value)) { SetVerticesDirty(); } } + } + public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie(serieName); diff --git a/Runtime/Serie/Pie/PieHandler.cs b/Runtime/Serie/Pie/PieHandler.cs index 2284d958..00fa2b43 100644 --- a/Runtime/Serie/Pie/PieHandler.cs +++ b/Runtime/Serie/Pie/PieHandler.cs @@ -333,7 +333,7 @@ namespace XCharts.Runtime } } - private void DrawPie(VertexHelper vh, Serie serie) + private void DrawPie(VertexHelper vh, Pie serie) { if (!serie.show || serie.animation.HasFadeOut()) { @@ -348,6 +348,16 @@ namespace XCharts.Runtime && !serie.animation.IsFadeIn() && !serie.animation.IsFadeOut(); var data = serie.data; serie.animation.InitProgress(0, 360); + if (data.Count == 0) + { + var itemStyle = SerieHelper.GetItemStyle(serie, null); + var fillColor = ChartHelper.IsClearColor(itemStyle.backgroundColor) ? + (Color32)chart.theme.legend.unableColor : itemStyle.backgroundColor; + UGL.DrawDoughnut(vh, serie.context.center, serie.context.insideRadius, + serie.context.outsideRadius, fillColor, fillColor, Color.clear, 0, + 360, itemStyle.borderWidth, itemStyle.borderColor, serie.gap / 2, chart.settings.cicleSmoothness, + false, true, serie.radiusGradient); + } for (int n = 0; n < data.Count; n++) { var serieData = data[n]; @@ -387,7 +397,7 @@ namespace XCharts.Runtime UGL.DrawDoughnut(vh, offsetCenter, insideRadius, outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, drawEndDegree, borderWidth, borderColor, serie.gap / 2, chart.settings.cicleSmoothness, - needRoundCap, true); + needRoundCap, true, serie.radiusGradient); DrawPieCenter(vh, serie, itemStyle, insideRadius); if (serie.animation.CheckDetailBreak(serieData.context.toAngle)) @@ -461,7 +471,7 @@ namespace XCharts.Runtime : pos2 + dire * lineLength2 + labelLine.GetEndSymbolOffset(); if (labelLine.lineEndX != 0) { - pos5.x = isLeft ? -Mathf.Abs(labelLine.lineEndX) : Mathf.Abs(labelLine.lineEndX); + pos5.x = serie.context.center.x + (isLeft ? -Mathf.Abs(labelLine.lineEndX) : Mathf.Abs(labelLine.lineEndX)); } serieData.context.labelLinePosition2 = pos2; serieData.context.labelPosition = pos5; diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 6f32edfb..fbd56eb4 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -283,7 +283,8 @@ namespace XCharts.Runtime max = serie.context.dataMax; } } - var radius = (float)(m_RadarCoord.context.dataRadius * (value - min) / (max - min)); + if (max - min == 0) continue; + var radius = (float) (m_RadarCoord.context.dataRadius * (value - min) / (max - min)); var currAngle = startAngle + (n + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle; radius *= rate; if (n == 0) @@ -414,7 +415,7 @@ namespace XCharts.Runtime { lineColor = m_RadarCoord.outRangeColor; } - var radius = (float)(max < 0 ? m_RadarCoord.context.dataRadius - m_RadarCoord.context.dataRadius * value / max : + var radius = (float) (max < 0 ? m_RadarCoord.context.dataRadius - m_RadarCoord.context.dataRadius * value / max : m_RadarCoord.context.dataRadius * value / max); var currAngle = startAngle + (index + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle; radius *= rate; diff --git a/Runtime/Serie/Ring/RingHandler.cs b/Runtime/Serie/Ring/RingHandler.cs index 9ca6ccc9..40fc8c40 100644 --- a/Runtime/Serie/Ring/RingHandler.cs +++ b/Runtime/Serie/Ring/RingHandler.cs @@ -99,7 +99,7 @@ namespace XCharts.Runtime param.color = color; param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); param.itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); - param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); ; + param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); param.columns.Clear(); param.columns.Add(param.marker); @@ -111,7 +111,7 @@ namespace XCharts.Runtime private Vector3 GetLabelLineEndPosition(Serie serie, SerieData serieData, LabelLine labelLine) { - if (labelLine == null || !labelLine.show) + if (labelLine == null || !labelLine.show) return serieData.context.labelLinePosition; var isRight = !serie.clockwise; var dire = isRight ? Vector3.right : Vector3.left; @@ -207,10 +207,13 @@ namespace XCharts.Runtime var startDegree = GetStartAngle(serie); var toDegree = GetToAngle(serie, degree); var insideRadius = outsideRadius - ringWidth; + var halfAngle = startDegree + (toDegree - startDegree) / 2; + var halfRadius = (outsideRadius + insideRadius) / 2; serieData.context.startAngle = startDegree; serieData.context.toAngle = toDegree; serieData.context.insideRadius = insideRadius; serieData.context.outsideRadius = serieData.radius > 0 ? serieData.radius : outsideRadius; + serieData.context.position = ChartHelper.GetPosition(serie.context.center, halfAngle, halfRadius); UpdateLabelPosition(serieData); } AvoidLabelOverlap(); diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs index fe642286..624e0d9e 100644 --- a/Runtime/Serie/SerieContext.cs +++ b/Runtime/Serie/SerieContext.cs @@ -119,5 +119,9 @@ namespace XCharts.Runtime public Tooltip.Type tooltipType; public Tooltip.Trigger tooltipTrigger; public int totalDataIndex; + /// + /// 水平方向的 + /// + public bool isHorizontal; } } \ No newline at end of file diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 039aae40..01419756 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -201,6 +201,7 @@ namespace XCharts.Runtime /// public static bool IsAllZeroValue(Serie serie, int dimension = 1) { + if (serie.dataCount == 0) return false; foreach (var serieData in serie.data) { if (serieData.GetData(dimension) != 0) return false; diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 5e74590e..ee8bb548 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -1590,7 +1590,7 @@ namespace XUGL public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, Color32 color, Color32 toColor, Color32 emptyColor, float startDegree, float toDegree, float borderWidth, - Color32 borderColor, float gap, float smoothness, bool roundCap = false, bool clockwise = true) + Color32 borderColor, float gap, float smoothness, bool roundCap = false, bool clockwise = true, bool radiusGradient = true) { if (toDegree - startDegree == 0) return; if (gap > 0 && Mathf.Abs(toDegree - startDegree) >= 360) gap = 0; @@ -1785,10 +1785,19 @@ namespace XUGL center.y + insideRadius * Mathf.Cos(currAngle)); if (isGradient) { - var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments); - if (i == 0 && (needSpace || needBorder)) - UGL.DrawTriangle(vh, p1, p2, p3, color, tcolor, tcolor); - AddVertToVertexHelper(vh, p3, p4, tcolor, tcolor, i > 0); + if (radiusGradient) + { + if (i == 0 && (needSpace || needBorder)) + UGL.DrawTriangle(vh, p1, p2, p3, color, toColor, toColor); + AddVertToVertexHelper(vh, p3, p4, color, toColor, i > 0); + } + else + { + var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments); + if (i == 0 && (needSpace || needBorder)) + UGL.DrawTriangle(vh, p1, p2, p3, color, tcolor, tcolor); + AddVertToVertexHelper(vh, p3, p4, tcolor, tcolor, i > 0); + } } else { diff --git a/package.json b/package.json index bc13bf59..00bfca79 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "com.monitor1394.xcharts", "displayName": "XCharts", - "version": "3.8.0", - "date": "20230903", - "checkdate": "20230903", + "version": "3.8.1", + "date": "20231001", + "checkdate": "20231001", "desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!", "unity": "2018.3", "description": "A charting and data visualization library for Unity.",