From f1f2ea78befba6271cfbb7d95a3943f3691d6e3f Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 9 Aug 2022 08:29:06 +0800 Subject: [PATCH] [feature][AreaStyle] support `innerFill` --- CHANGELOG.md | 10 +++++----- Documentation/XChartsAPI-EN.md | 1 + Documentation/XChartsAPI-ZH.md | 1 + Documentation/XChartsConfiguration-EN.md | 1 + Documentation/XChartsConfiguration-ZH.md | 1 + Editor/ChildComponents/AreaStyleDrawer.cs | 1 + Runtime/Component/Child/AreaStyle.cs | 10 ++++++++++ Runtime/Serie/Line/LineHelper.cs | 18 ++++++++++++------ Runtime/Serie/SerieHelper.cs | 10 ++++++++++ 9 files changed, 42 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eda4176d..15f48089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,9 +57,9 @@ ## master -* (2022.08.09) 修复`Serie`的数据项索引异常引起的其他问题 -* (2022.08.08) 优化`Serie`的数据项索引维护,增加检测和修复功能 -* (2022.07.29) 修复在某些`Unity`版本导入后图表创建异常的问题 +* (2022.08.09) 增加`AreaStyle`的`innerFill`参数支持填充凸多边形 +* (2022.08.08) 优化`Serie`的数据项索引维护,增加检测和修复功能,修复相关问题 +* (2022.07.29) 修复`Unity`版本兼容:在某些版本导入后图表创建异常的问题 * (2022.07.29) 增加`Axis`为`Time`时间轴时,支持次刻度和次分割线 * (2022.07.28) 优化`Radar`雷达图效果 * (2022.07.28) 增加`Serie`的`colorBy`参数配置取色策略 @@ -69,7 +69,7 @@ * (2022.07.22) 增加`Serie`的三种状态`EmphasisStyle`,`BlurStyle`,`SelectStyle` * (2022.07.22) 去掉`AreaStyle`的`highlightColor`和`highlightToColor`参数 * (2022.07.22) 去掉`Emphasis`,`EmphasisItemStyle`,`EmphasisLabelStyle`,`EmphasisLabelLine`组件 -* (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持 +* (2022.07.20) 增加`Since`特性对类的支持 * (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 * (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线 * (2022.07.19) 增加`Axis`的`MinorTick`设置坐标轴次刻度 @@ -107,7 +107,7 @@ * (2022.06.25) 修复`DataZoom`开启时`Tooltip`显示数据不一致的问题 (#203) * (2022.06.25) 修复`Toolip`在类目轴无数据时绘制异常的问题 (#204) * (2022.06.25) 优化`Serie`设置`PlaceHolder`时的`Tooltip`表现 -* (2022.06.25) 增加`Since`标识配置参数从哪个版本开始支持 +* (2022.06.25) 增加`Since`特效用于标识配置参数从哪个版本开始支持 * (2022.06.24) 优化`Painter`绘制层,`Top`层细分为`Upper`和`Top`层 * (2022.06.24) 增加`Legend`对`Background`和`Padding`的支持 * (2022.06.21) 增加`TextStyle`对`TextMeshPro`的`Sprite Asset`支持 (#201) diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md index 5b9c870b..81f8c569 100644 --- a/Documentation/XChartsAPI-EN.md +++ b/Documentation/XChartsAPI-EN.md @@ -255,6 +255,7 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `RemoveSerie()` |public void RemoveSerie(Serie serie)
| | `RemoveSerie()` |public void RemoveSerie(string serieName)
| | `ReplaceSerie()` |public bool ReplaceSerie(Serie oldSerie, Serie newSerie)
| +| `ResetDataIndex()` |public bool ResetDataIndex(int serieIndex)
重置serie的数据项索引。避免数据项索引异常。 | | `SetBasePainterMaterial()` |public void SetBasePainterMaterial(Material material)
设置Base Painter的材质球 | | `SetMaxCache()` |public void SetMaxCache(int maxCache)
设置可缓存的最大数据量。当数据量超过该值时,会自动删除第一个值再加入最新值。 | | `SetPainterActive()` |public void SetPainterActive(int index, bool flag)
| diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md index 60546735..02984b29 100644 --- a/Documentation/XChartsAPI-ZH.md +++ b/Documentation/XChartsAPI-ZH.md @@ -255,6 +255,7 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `RemoveSerie()` |public void RemoveSerie(Serie serie)
| | `RemoveSerie()` |public void RemoveSerie(string serieName)
| | `ReplaceSerie()` |public bool ReplaceSerie(Serie oldSerie, Serie newSerie)
| +| `ResetDataIndex()` |public bool ResetDataIndex(int serieIndex)
重置serie的数据项索引。避免数据项索引异常。 | | `SetBasePainterMaterial()` |public void SetBasePainterMaterial(Material material)
设置Base Painter的材质球 | | `SetMaxCache()` |public void SetMaxCache(int maxCache)
设置可缓存的最大数据量。当数据量超过该值时,会自动删除第一个值再加入最新值。 | | `SetPainterActive()` |public void SetPainterActive(int index, bool flag)
| diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index 35f7d9ee..f3834748 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -215,6 +215,7 @@ The style of area. |`color`|||the color of area,default use serie color. |`toColor`|||Gradient color, start color to toColor. |`opacity`|0.6f||Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0. +|`fill`|true|v3.2.0|Whether to fill only polygonal areas. Currently, only convex polygons are supported. ## `ArrowStyle` diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index a291fa8d..4a42b6a8 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -215,6 +215,7 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent |`color`|||区域填充的颜色,如果toColor不是默认值,则表示渐变色的起点颜色。 |`toColor`|||渐变色的终点颜色。 |`opacity`|0.6f||图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 +|`fill`|true|v3.2.0|是否只填充多边形区域。目前只支持凸多边形。 ## `ArrowStyle` diff --git a/Editor/ChildComponents/AreaStyleDrawer.cs b/Editor/ChildComponents/AreaStyleDrawer.cs index f586e226..d26457fd 100644 --- a/Editor/ChildComponents/AreaStyleDrawer.cs +++ b/Editor/ChildComponents/AreaStyleDrawer.cs @@ -18,6 +18,7 @@ namespace XCharts.Editor PropertyField(prop, "m_Color"); PropertyField(prop, "m_ToColor"); PropertyField(prop, "m_Opacity"); + PropertyField(prop, "m_InnerFill"); --EditorGUI.indentLevel; } } diff --git a/Runtime/Component/Child/AreaStyle.cs b/Runtime/Component/Child/AreaStyle.cs index a035f95a..66984923 100644 --- a/Runtime/Component/Child/AreaStyle.cs +++ b/Runtime/Component/Child/AreaStyle.cs @@ -37,6 +37,7 @@ namespace XCharts.Runtime [SerializeField] private Color32 m_Color; [SerializeField] private Color32 m_ToColor; [SerializeField][Range(0, 1)] private float m_Opacity = 0.6f; + [SerializeField][Since("v3.2.0")] private bool m_InnerFill; /// /// Set this to false to prevent the areafrom showing. @@ -83,6 +84,15 @@ namespace XCharts.Runtime get { return m_Opacity; } set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } + /// + /// Whether to fill only polygonal areas. Currently, only convex polygons are supported. + /// |是否只填充多边形区域。目前只支持凸多边形。 + /// + public bool innerFill + { + get { return m_InnerFill; } + set { if (PropertyUtil.SetStruct(ref m_InnerFill, value)) SetVerticesDirty(); } + } public Color32 GetColor() { diff --git a/Runtime/Serie/Line/LineHelper.cs b/Runtime/Serie/Line/LineHelper.cs index 20942d18..59ef4ece 100644 --- a/Runtime/Serie/Line/LineHelper.cs +++ b/Runtime/Serie/Line/LineHelper.cs @@ -24,11 +24,17 @@ namespace XCharts.Runtime public static void DrawSerieLineArea(VertexHelper vh, Serie serie, Serie lastStackSerie, ThemeStyle theme, VisualMap visualMap, bool isY, Axis axis, Axis relativedAxis, GridCoord grid) { - Color32 srcAreaColor, srcAreaToColor; - if (!SerieHelper.GetAreaColor(out srcAreaColor, out srcAreaToColor, serie, null, theme, serie.context.colorIndex)) + Color32 areaColor, areaToColor; + bool innerFill; + if (!SerieHelper.GetAreaColor(out areaColor, out areaToColor, out innerFill, serie, null, theme, serie.context.colorIndex)) { return; } + if (innerFill) + { + UGL.DrawPolygon(vh, serie.context.dataPoints, areaColor); + return; + } var gridXY = (isY ? grid.context.x : grid.context.y); if (lastStackSerie == null) { @@ -36,8 +42,8 @@ namespace XCharts.Runtime gridXY + relativedAxis.context.offset, gridXY, gridXY + (isY ? grid.context.width : grid.context.height), - srcAreaColor, - srcAreaToColor, + areaColor, + areaToColor, visualMap, axis, relativedAxis, @@ -49,8 +55,8 @@ namespace XCharts.Runtime gridXY + relativedAxis.context.offset, gridXY, gridXY + (isY ? grid.context.width : grid.context.height), - srcAreaColor, - srcAreaToColor, + areaColor, + areaToColor, visualMap); } } diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index e889a2f8..ea5cff22 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -531,15 +531,24 @@ namespace XCharts.Runtime public static bool GetAreaColor(out Color32 color, out Color32 toColor, Serie serie, SerieData serieData, ThemeStyle theme, int index) + { + bool fill; + return GetAreaColor(out color, out toColor, out fill,serie, serieData, theme, index); + } + + public static bool GetAreaColor(out Color32 color, out Color32 toColor, out bool innerFill, + Serie serie, SerieData serieData, ThemeStyle theme, int index) { color = ChartConst.clearColor32; toColor = ChartConst.clearColor32; + innerFill = false; var state = GetSerieState(serie, serieData); var stateStyle = GetStateStyle(serie, serieData, state); if (stateStyle == null) { var areaStyle = GetAreaStyle(serie, serieData); if (areaStyle == null || !areaStyle.show) return false; + innerFill = areaStyle.innerFill; GetColor(ref color, areaStyle.color, serie.itemStyle.color, areaStyle.opacity, theme, index); GetColor(ref toColor, areaStyle.toColor, color, areaStyle.opacity, theme, index); switch (state) @@ -564,6 +573,7 @@ namespace XCharts.Runtime { if (stateStyle.areaStyle.show) { + innerFill = stateStyle.areaStyle.innerFill; GetColor(ref color, stateStyle.areaStyle.color, stateStyle.itemStyle.color, stateStyle.areaStyle.opacity, theme, index); GetColor(ref color, stateStyle.areaStyle.toColor, color, stateStyle.areaStyle.opacity, theme, index); }