From aee49322b7ed4ea58897496449023fc268e2c181 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 15 Jul 2022 08:37:14 +0800 Subject: [PATCH 01/27] [feature][datazoom] support time axis --- CHANGELOG.md | 13 +++++ Runtime/Component/Axis/AxisHandler.cs | 18 +++--- Runtime/Component/DataZoom/DataZoom.cs | 80 ++++++++++++++------------ Runtime/Serie/SerieHelper.cs | 5 +- 4 files changed, 69 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5175d041..bed08747 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,8 +57,21 @@ ## master +* (2022.07.15) 增加`DataZoom`对`Time`时间轴的支持 + ## 3.1.0 +### 版本要点 + +* 优化`Axis` +* 优化`Tooltip` +* 优化平滑曲线算法 +* 优化代码动态创建图表 +* 完善配置项手册 +* 修复若干问题 + +### 日志详情 + * (2022.07.12) 发布`v3.1.0`版本 * (2022.07.12) 修复`Serie`的`ignoreLineBreak`不生效的问题 * (2022.07.07) 优化`Axis`的`minMaxType`指定为`MinMax`时支持精确到小数 diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 96456755..aa290a88 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -144,6 +144,15 @@ namespace XCharts double tempMaxValue = 0; chart.GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue); + var dataZoom = chart.GetDataZoomOfAxis(axis); + if (dataZoom != null && dataZoom.enable) + { + if (axis is XAxis) + dataZoom.SetXAxisIndexValueInfo(axisIndex, ref tempMinValue, ref tempMaxValue); + else + dataZoom.SetYAxisIndexValueInfo(axisIndex, ref tempMinValue, ref tempMaxValue); + } + if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue || m_LastInterval != axis.interval || @@ -189,14 +198,7 @@ namespace XCharts axis.context.zeroY = grid.context.y - (float) (axis.context.minValue * grid.context.height / axis.context.minMaxRange); } } - var dataZoom = chart.GetDataZoomOfAxis(axis); - if (dataZoom != null && dataZoom.enable) - { - if (axis is XAxis) - dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue); - else - dataZoom.SetYAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue); - } + if (updateChart) { UpdateAxisLabelText(axis); diff --git a/Runtime/Component/DataZoom/DataZoom.cs b/Runtime/Component/DataZoom/DataZoom.cs index 33692b66..14b72be9 100644 --- a/Runtime/Component/DataZoom/DataZoom.cs +++ b/Runtime/Component/DataZoom/DataZoom.cs @@ -366,6 +366,8 @@ namespace XCharts.Runtime class AxisIndexValueInfo { + public double rawMin; + public double rawMax; public double min; public double max; } @@ -617,38 +619,36 @@ namespace XCharts.Runtime context.height = chartHeight - runtimeTop - runtimeBottom; } - internal void SetXAxisIndexValueInfo(int xAxisIndex, double min, double max) + internal void SetXAxisIndexValueInfo(int xAxisIndex, ref double min, ref double max) { - if (!m_XAxisIndexInfos.ContainsKey(xAxisIndex)) + AxisIndexValueInfo info; + if (!m_XAxisIndexInfos.TryGetValue(xAxisIndex, out info)) { - m_XAxisIndexInfos[xAxisIndex] = new AxisIndexValueInfo() - { - min = min, - max = max - }; - } - else - { - m_XAxisIndexInfos[xAxisIndex].min = min; - m_XAxisIndexInfos[xAxisIndex].max = max; + info = new AxisIndexValueInfo(); + m_XAxisIndexInfos[xAxisIndex] = info; } + info.rawMin = min; + info.rawMax = max; + info.min = min + (max - min) * start / 100; + info.max = min + (max - min) * end / 100; + min = info.min; + max = info.max; } - internal void SetYAxisIndexValueInfo(int yAxisIndex, double min, double max) + internal void SetYAxisIndexValueInfo(int yAxisIndex, ref double min, ref double max) { - if (!m_YAxisIndexInfos.ContainsKey(yAxisIndex)) + AxisIndexValueInfo info; + if (!m_YAxisIndexInfos.TryGetValue(yAxisIndex, out info)) { - m_YAxisIndexInfos[yAxisIndex] = new AxisIndexValueInfo() - { - min = min, - max = max - }; - } - else - { - m_YAxisIndexInfos[yAxisIndex].min = min; - m_YAxisIndexInfos[yAxisIndex].max = max; + info = new AxisIndexValueInfo(); + m_YAxisIndexInfos[yAxisIndex] = info; } + info.rawMin = min; + info.rawMax = max; + info.min = min + (max - min) * start / 100; + info.max = min + (max - min) * end / 100; + min = info.min; + max = info.max; } internal bool IsXAxisIndexValue(int axisIndex) @@ -663,24 +663,32 @@ namespace XCharts.Runtime internal void GetXAxisIndexValue(int axisIndex, out double min, out double max) { - min = 0; - max = 0; - if (m_XAxisIndexInfos.ContainsKey(axisIndex)) + AxisIndexValueInfo info; + if (m_XAxisIndexInfos.TryGetValue(axisIndex, out info)) { - var info = m_XAxisIndexInfos[axisIndex]; - min = info.min; - max = info.max; + var range = info.rawMax - info.rawMin; + min = info.rawMin + range * m_Start / 100; + max = info.rawMin + range * m_End / 100; + } + else + { + min = 0; + max = 0; } } internal void GetYAxisIndexValue(int axisIndex, out double min, out double max) { - min = 0; - max = 0; - if (m_YAxisIndexInfos.ContainsKey(axisIndex)) + AxisIndexValueInfo info; + if (m_YAxisIndexInfos.TryGetValue(axisIndex, out info)) { - var info = m_YAxisIndexInfos[axisIndex]; - min = info.min; - max = info.max; + var range = info.rawMax - info.rawMin; + min = info.rawMin + range * m_Start / 100; + max = info.rawMin + range * m_End / 100; + } + else + { + min = 0; + max = 0; } } } diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index c611f9c1..073326ff 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -644,10 +644,9 @@ namespace XCharts.Runtime private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, double min, double max) { var data = serie.data; - var startValue = min + (max - min) * dataZoom.start / 100; - var endValue = min + (max - min) * dataZoom.end / 100; + var startValue = min; + var endValue = max; if (endValue < startValue) endValue = startValue; - if (startValue != serie.m_FilterStartValue || endValue != serie.m_FilterEndValue || dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData) { From eedafa70115ec4a443081f71fbd395966f67d720 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 17 Jul 2022 20:57:38 +0800 Subject: [PATCH 02/27] [feature][radar] support smooth line --- Editor/MainComponents/RadarCoordEditor.cs | 2 +- Editor/Series/RadarEditor.cs | 1 + .../Axis/RadiusAxis/RadiusAxisHandler.cs | 2 +- Runtime/Component/Tooltip/TooltipHandler.cs | 2 +- Runtime/Internal/Attributes/SinceAttribute.cs | 2 +- Runtime/Serie/Parallel/ParallelHandler.cs | 8 +- Runtime/Serie/Radar/Radar.cs | 14 ++- Runtime/Serie/Radar/RadarHandler.cs | 37 ++++++-- Runtime/XUGL/UGL.cs | 85 ++++++++++++++----- Runtime/XUGL/UGLHelper.cs | 10 +-- 10 files changed, 120 insertions(+), 43 deletions(-) diff --git a/Editor/MainComponents/RadarCoordEditor.cs b/Editor/MainComponents/RadarCoordEditor.cs index 752ec816..2d5b9b40 100644 --- a/Editor/MainComponents/RadarCoordEditor.cs +++ b/Editor/MainComponents/RadarCoordEditor.cs @@ -24,7 +24,7 @@ namespace XCharts.Editor PropertyField("m_AxisName"); PropertyField("m_SplitLine"); PropertyField("m_SplitArea"); - PropertyField("m_IndicatorList"); + PropertyListField("m_IndicatorList"); --EditorGUI.indentLevel; } } diff --git a/Editor/Series/RadarEditor.cs b/Editor/Series/RadarEditor.cs index aedf9832..969c7436 100644 --- a/Editor/Series/RadarEditor.cs +++ b/Editor/Series/RadarEditor.cs @@ -9,6 +9,7 @@ namespace XCharts.Editor { PropertyField("m_RadarType"); PropertyField("m_RadarIndex"); + PropertyField("m_Smooth"); PropertyField("m_Symbol"); PropertyField("m_LineStyle"); diff --git a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs index 630a0612..4e295923 100644 --- a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs +++ b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs @@ -32,7 +32,7 @@ namespace XCharts.Runtime if (!polar.context.isPointerEnter) { - axis.context.pointerValue = double.PositiveInfinity; + axis.context.pointerValue = double.NaN; return; } diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index e06b11cc..67bac520 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -180,7 +180,7 @@ namespace XCharts.Runtime private void SetTooltipIndicatorLabel(Tooltip tooltip, Axis axis, ChartLabel label) { if (label == null) return; - if (double.IsPositiveInfinity(axis.context.pointerValue)) return; + if (double.IsNaN(axis.context.pointerValue)) return; label.SetActive(true); label.SetTextActive(true); label.SetPosition(axis.context.pointerLabelPosition); diff --git a/Runtime/Internal/Attributes/SinceAttribute.cs b/Runtime/Internal/Attributes/SinceAttribute.cs index 958d5ad2..1e3499e9 100644 --- a/Runtime/Internal/Attributes/SinceAttribute.cs +++ b/Runtime/Internal/Attributes/SinceAttribute.cs @@ -2,7 +2,7 @@ using System; namespace XCharts.Runtime { - [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.All, AllowMultiple = false)] public class Since : Attribute { public readonly string version; diff --git a/Runtime/Serie/Parallel/ParallelHandler.cs b/Runtime/Serie/Parallel/ParallelHandler.cs index 38a64534..c56c4d41 100644 --- a/Runtime/Serie/Parallel/ParallelHandler.cs +++ b/Runtime/Serie/Parallel/ParallelHandler.cs @@ -21,8 +21,7 @@ namespace XCharts.Runtime DrawParallelSerie(vh, serie); } - private void UpdateSerieContext() - { } + private void UpdateSerieContext() { } private void DrawParallelSerie(VertexHelper vh, Parallel serie) { @@ -116,7 +115,10 @@ namespace XCharts.Runtime lp = pos; } if (isSmooth) - UGL.DrawCurves(vh, m_Points, lineWidth, lineColor, chart.settings.lineSmoothness, currProgress, isHorizonal); + UGL.DrawCurves(vh, m_Points, lineWidth, lineColor, + chart.settings.lineSmoothStyle, + chart.settings.lineSmoothness, + UGL.Direction.XAxis, currProgress, isHorizonal); else UGL.DrawLine(vh, m_Points, lineWidth, lineColor, isSmooth); } diff --git a/Runtime/Serie/Radar/Radar.cs b/Runtime/Serie/Radar/Radar.cs index 8af45a95..dc44ec02 100644 --- a/Runtime/Serie/Radar/Radar.cs +++ b/Runtime/Serie/Radar/Radar.cs @@ -11,9 +11,21 @@ namespace XCharts.Runtime [SerieDataExtraField()] public class Radar : Serie, INeedSerieContainer { + [SerializeField][Since("3.2.0")] private bool m_Smooth = false; + + /// + /// Whether use smooth curve. + /// |是否平滑曲线。平滑曲线时不支持区域填充颜色。 + /// + public bool smooth + { + get { return m_Smooth; } + set { if (PropertyUtil.SetStruct(ref m_Smooth, value)) { SetVerticesDirty(); } } + } + public int containerIndex { get; internal set; } public int containterInstanceId { get; internal set; } - public override bool useDataNameForColor { get { return true; } } + public override bool useDataNameForColor { get { return radarType == RadarType.Multiple; } } public override bool multiDimensionLabel { get { return radarType == RadarType.Multiple; } } public static Serie AddDefaultSerie(BaseChart chart, string serieName) diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 374455db..5bda0afb 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -262,11 +262,11 @@ namespace XCharts.Runtime { toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle), centerPos.y + radius * Mathf.Cos(currAngle)); - if (areaStyle != null && areaStyle.show) + if (areaStyle != null && areaStyle.show && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor); } - if (lineStyle.show) + if (lineStyle.show && !serie.smooth) { ChartDrawer.DrawLineStyle(vh, lineStyle.type, lineWidth, startPoint, toPoint, lineColor); } @@ -274,14 +274,24 @@ namespace XCharts.Runtime } serieData.context.dataPoints.Add(startPoint); } - if (areaStyle != null && areaStyle.show) + if (areaStyle != null && areaStyle.show && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); } - if (lineStyle.show) + if (lineStyle.show && !serie.smooth) { ChartDrawer.DrawLineStyle(vh, lineStyle.type, lineWidth, startPoint, firstPoint, lineColor); } + + if (serie.smooth) + { + UGL.DrawCurves(vh, serieData.context.dataPoints, lineWidth, lineColor, + chart.settings.lineSmoothStyle, + chart.settings.lineSmoothness, + UGL.Direction.Random, + float.NaN, true); + } + if (symbol.show && symbol.type != SymbolType.None) { for (int m = 0; m < serieData.context.dataPoints.Count; m++) @@ -394,11 +404,11 @@ namespace XCharts.Runtime { toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); - if (areaStyle != null && areaStyle.show) + if (areaStyle != null && areaStyle.show && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor); } - if (lineStyle.show) + if (lineStyle.show && !serie.smooth) { if (radar.connectCenter) ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos, @@ -409,14 +419,15 @@ namespace XCharts.Runtime startPoint = toPoint; lastColor = lineColor; } + serie.context.dataPoints.Add(startPoint); serieData.context.position = startPoint; serieData.context.labelPosition = startPoint; - if (areaStyle != null && areaStyle.show && j == endIndex) + if (areaStyle != null && areaStyle.show && j == endIndex && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); } - if (lineStyle.show && j == endIndex) + if (lineStyle.show && j == endIndex && !serie.smooth) { if (radar.connectCenter) ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos, @@ -425,6 +436,16 @@ namespace XCharts.Runtime LineStyle.Type.Solid, lineColor, radar.lineGradient ? firstColor : lineColor); } } + if (serie.smooth) + { + var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); + var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex, false); + UGL.DrawCurves(vh, serie.context.dataPoints, lineWidth, lineColor, + chart.settings.lineSmoothStyle, + chart.settings.lineSmoothness, + UGL.Direction.Random, + float.NaN, true); + } if (serie.symbol.show && serie.symbol.type != SymbolType.None) { for (int j = 0; j < serie.data.Count; j++) diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index b260a52e..595342f3 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -10,6 +10,24 @@ namespace XUGL /// public static class UGL { + /// + /// 曲线方向 + /// + public enum Direction + { + /// + /// 沿X轴方向 + /// + XAxis, + /// + /// 沿Y轴方向 + /// + YAxis, + /// + /// 随机无序的。如一个闭合的环状曲线。 + /// + Random + } private static readonly Color32 s_ClearColor32 = new Color32(0, 0, 0, 0); private static readonly Vector2 s_ZeroVector2 = Vector2.zero; private static UIVertex[] s_Vertex = new UIVertex[4]; @@ -134,7 +152,7 @@ namespace XUGL } else if (smooth) { - DrawCurves(vh, points, width, color, 2); + DrawCurves(vh, points, width, color, 2, 2, Direction.XAxis, float.NaN, closepath); } else { @@ -1752,42 +1770,67 @@ namespace XUGL /// 曲线宽 /// 曲线颜色 public static void DrawCurves(VertexHelper vh, Vector3 sp, Vector3 ep, Vector3 cp1, Vector3 cp2, - float lineWidth, Color32 lineColor, float smoothness) + float lineWidth, Color32 lineColor, float smoothness, Direction dire = Direction.XAxis) { var dist = Vector3.Distance(sp, ep); var segment = (int) (dist / (smoothness <= 0 ? 2f : smoothness)); UGLHelper.GetBezierList2(ref s_CurvesPosList, sp, ep, segment, cp1, cp2); - DrawCurvesInternal(vh, s_CurvesPosList, lineWidth, lineColor); + DrawCurvesInternal(vh, s_CurvesPosList, lineWidth, lineColor, dire); } + /// + /// 画贝塞尔曲线 + /// + /// + /// 坐标点列表 + /// 曲线宽 + /// 曲线颜色 + /// 曲线样式 + /// 平滑度 + /// 曲线方向 + /// 当前绘制进度 + /// 曲线是否闭合 public static void DrawCurves(VertexHelper vh, List points, float width, Color32 color, - float smoothness, float currProgress = float.PositiveInfinity, bool isYAxis = false) + float smoothStyle, float smoothness, Direction dire, float currProgress = float.NaN, + bool closed = false) { - for (int i = 0; i < points.Count - 1; i++) + var count = points.Count; + var size = (closed?count : count - 1); + if (closed) + dire = Direction.Random; + for (int i = 0; i < size; i++) { var sp = points[i]; - var ep = points[i + 1]; - var lsp = i > 0 ? points[i - 1] : sp; - var nep = i < points.Count - 2 ? points[i + 2] : ep; + var ep = closed?(i == size - 1 ? points[0] : points[i + 1]) : points[i + 1]; + var lsp = i > 0 ? points[i - 1] : (closed?points[count - 1] : sp); + var nep = i < points.Count - 2 ? points[i + 2] : (closed?points[(i + 2) % count] : ep); var smoothness2 = smoothness; - if (currProgress != float.PositiveInfinity) + if (currProgress != float.NaN) { - if (isYAxis) - smoothness2 = ep.y <= currProgress ? smoothness : smoothness * 0.5f; - else - smoothness2 = ep.x <= currProgress ? smoothness : smoothness * 0.5f; + switch (dire) + { + case Direction.XAxis: + smoothness2 = ep.x <= currProgress ? smoothness : smoothness * 0.5f; + break; + case Direction.YAxis: + smoothness2 = ep.y <= currProgress ? smoothness : smoothness * 0.5f; + break; + case Direction.Random: + smoothness2 = smoothness * 0.5f; + break; + } } - if (isYAxis) - UGLHelper.GetBezierListVertical(ref s_CurvesPosList, sp, ep, smoothness2); + if (dire == Direction.YAxis) + UGLHelper.GetBezierListVertical(ref s_CurvesPosList, sp, ep, smoothness2, smoothStyle); else - UGLHelper.GetBezierList(ref s_CurvesPosList, sp, ep, lsp, nep, smoothness2); + UGLHelper.GetBezierList(ref s_CurvesPosList, sp, ep, lsp, nep, smoothness2, smoothStyle); - DrawCurvesInternal(vh, s_CurvesPosList, width, color, currProgress, isYAxis); + DrawCurvesInternal(vh, s_CurvesPosList, width, color, dire, currProgress); } } private static void DrawCurvesInternal(VertexHelper vh, List curvesPosList, float lineWidth, - Color32 lineColor, float currProgress = float.PositiveInfinity, bool isYAxis = false) + Color32 lineColor, Direction dire, float currProgress = float.NaN) { if (curvesPosList.Count > 1) { @@ -1805,11 +1848,11 @@ namespace XUGL for (int i = 1; i < curvesPosList.Count; i++) { to = curvesPosList[i]; - if (currProgress != float.PositiveInfinity) + if (currProgress != float.NaN) { - if (isYAxis && to.y > currProgress) + if (dire == Direction.YAxis && to.y > currProgress) break; - if (!isYAxis && to.x > currProgress) + if (dire == Direction.XAxis && to.x > currProgress) break; } diff --git a/Runtime/XUGL/UGLHelper.cs b/Runtime/XUGL/UGLHelper.cs index 2f7166cb..4076b525 100644 --- a/Runtime/XUGL/UGLHelper.cs +++ b/Runtime/XUGL/UGLHelper.cs @@ -110,22 +110,21 @@ namespace XUGL public static void GetBezierList(ref List posList, Vector3 sp, Vector3 ep, Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f, bool limit = false) { - float dist = Mathf.Abs(sp.x - ep.x); + var dist = Vector3.Distance(sp, ep); Vector3 cp1, cp2; var dir = (ep - sp).normalized; var diff = dist / k; if (lsp == sp) { - cp1 = sp + dist / k * dir * 1; - cp1.y = sp.y; - cp1 = sp; + cp1 = sp + (nep - ep).normalized * diff; + if (limit) + cp1.y = sp.y; } else { cp1 = sp + (ep - lsp).normalized * diff; if (limit) cp1.y = sp.y; - } if (nep == ep) { @@ -137,7 +136,6 @@ namespace XUGL if (limit) cp2.y = ep.y; } - dist = Vector3.Distance(sp, ep); int segment = (int) (dist / (smoothness <= 0 ? 2f : smoothness)); if (segment < 1) segment = (int) (dist / 0.5f); if (segment < 4) segment = 4; From 0355e3ed460456490b969d9b226d315fc2b63065 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 19 Jul 2022 08:22:42 +0800 Subject: [PATCH 03/27] [feature][axis] support minor tick and minor split line --- CHANGELOG.md | 3 + Documentation/XChartsAPI-EN.md | 3 + Documentation/XChartsAPI-ZH.md | 3 + Documentation/XChartsConfiguration-EN.md | 32 ++- Documentation/XChartsConfiguration-ZH.md | 30 +++ Editor/ChildComponents/LineDrawer.cs | 24 ++ Editor/MainComponents/AxisEditor.cs | 18 +- Runtime/Component/Axis/Axis.cs | 53 ++++- Runtime/Component/Axis/AxisContext.cs | 17 ++ Runtime/Component/Axis/AxisHandler.cs | 211 ++++++++++++++---- Runtime/Component/Axis/AxisHelper.cs | 44 +++- Runtime/Component/Axis/AxisMinorSplitLine.cs | 61 +++++ .../Component/Axis/AxisMinorSplitLine.cs.meta | 11 + Runtime/Component/Axis/AxisMinorTick.cs | 63 ++++++ Runtime/Component/Axis/AxisMinorTick.cs.meta | 11 + .../Axis/ParallelAxis/ParallelAxisHander.cs | 3 +- .../Axis/SingleAxis/SingleAxisHandler.cs | 2 +- Runtime/Component/Axis/XAxis/XAxis.cs | 1 + Runtime/Component/Axis/XAxis/XAxisHander.cs | 26 ++- Runtime/Component/Axis/YAxis/YAxisHander.cs | 25 ++- Runtime/Theme/AxisTheme.cs | 55 +++-- Runtime/Utilities/ColorUtil.cs | 10 +- 22 files changed, 597 insertions(+), 109 deletions(-) create mode 100644 Runtime/Component/Axis/AxisMinorSplitLine.cs create mode 100644 Runtime/Component/Axis/AxisMinorSplitLine.cs.meta create mode 100644 Runtime/Component/Axis/AxisMinorTick.cs create mode 100644 Runtime/Component/Axis/AxisMinorTick.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index bed08747..4d4eadcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,9 @@ ## master +* (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线 +* (2022.07.19) 增加`Axis`的`MinorTick`设置坐标轴次刻度 +* (2022.07.17) 增加`Radar`的`smooth`参数设置平滑曲线 * (2022.07.15) 增加`DataZoom`对`Time`时间轴的支持 ## 3.1.0 diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md index 0b26bdc4..ea59ea32 100644 --- a/Documentation/XChartsAPI-EN.md +++ b/Documentation/XChartsAPI-EN.md @@ -130,11 +130,14 @@ Inherits or Implemented: [MainComponentHandler](#MainComponentHandler) | `GetAxisValueDistance()` |public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleWidth, double value)
获得数值value在坐标轴上相对起点的距离 | | `GetAxisValueLength()` |public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value)
获得数值value在坐标轴上对应的长度 | | `GetAxisValuePosition()` |public static float GetAxisValuePosition(GridCoord grid, Axis axis, float scaleWidth, double value)
获得数值value在坐标轴上的坐标位置 | +| `GetAxisXOrY()` |public static float GetAxisXOrY(GridCoord grid, Axis axis, Axis relativedAxis)
| | `GetDataWidth()` |public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)
获得一个类目数据在坐标系中代表的宽度 | | `GetEachWidth()` |public static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
| | `GetScaleNumber()` |public static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
获得分割线条数 | | `GetScaleWidth()` |public static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
获得分割段宽度 | | `GetSplitNumber()` |public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom)
获得分割段数 | +| `GetXAxisXOrY()` |public static float GetXAxisXOrY(GridCoord grid, Axis xAxis, Axis relativedAxis)
| +| `GetYAxisXOrY()` |public static float GetYAxisXOrY(GridCoord grid, Axis yAxis, Axis relativedAxis)
| | `NeedShowSplit()` |public static bool NeedShowSplit(Axis axis)
| ## `BarChart` diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md index bfba19fd..9d8218e4 100644 --- a/Documentation/XChartsAPI-ZH.md +++ b/Documentation/XChartsAPI-ZH.md @@ -130,11 +130,14 @@ Inherits or Implemented: [MainComponentHandler](#MainComponentHandler) | `GetAxisValueDistance()` |public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleWidth, double value)
获得数值value在坐标轴上相对起点的距离 | | `GetAxisValueLength()` |public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value)
获得数值value在坐标轴上对应的长度 | | `GetAxisValuePosition()` |public static float GetAxisValuePosition(GridCoord grid, Axis axis, float scaleWidth, double value)
获得数值value在坐标轴上的坐标位置 | +| `GetAxisXOrY()` |public static float GetAxisXOrY(GridCoord grid, Axis axis, Axis relativedAxis)
| | `GetDataWidth()` |public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)
获得一个类目数据在坐标系中代表的宽度 | | `GetEachWidth()` |public static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
| | `GetScaleNumber()` |public static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
获得分割线条数 | | `GetScaleWidth()` |public static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
获得分割段宽度 | | `GetSplitNumber()` |public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom)
获得分割段数 | +| `GetXAxisXOrY()` |public static float GetXAxisXOrY(GridCoord grid, Axis xAxis, Axis relativedAxis)
| +| `GetYAxisXOrY()` |public static float GetYAxisXOrY(GridCoord grid, Axis yAxis, Axis relativedAxis)
| | `NeedShowSplit()` |public static bool NeedShowSplit(Axis axis)
| ## `BarChart` diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index f1cdde1e..6af10094 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -76,6 +76,8 @@ - [ArrowStyle](#ArrowStyle) - [AxisLabel](#AxisLabel) - [AxisLine](#AxisLine) +- [AxisMinorSplitLine](#AxisMinorSplitLine) +- [AxisMinorTick](#AxisMinorTick) - [AxisName](#AxisName) - [AxisSplitArea](#AxisSplitArea) - [AxisSplitLine](#AxisSplitLine) @@ -263,8 +265,10 @@ The axis in rectangular coordinate. |`axisLine`|||axis Line. [AxisLine](#AxisLine)| |`axisName`|||axis name. [AxisName](#AxisName)| |`axisTick`|||axis tick. [AxisTick](#AxisTick)| +|`minorTick`|||axis minor tick. [AxisMinorTick](#AxisMinorTick)| |`axisLabel`|||axis label. [AxisLabel](#AxisLabel)| |`splitLine`|||axis split line. [AxisSplitLine](#AxisSplitLine)| +|`minorSplitLine`|||axis minor split line. [AxisMinorSplitLine](#AxisMinorSplitLine)| |`splitArea`|||axis split area. [AxisSplitArea](#AxisSplitArea)| ## `AxisLabel` @@ -295,6 +299,28 @@ Settings related to axis line. |`showArrow`|||Whether to show the arrow symbol of axis. |`arrow`|||the arrow of line. [ArrowStyle](#ArrowStyle)| +## `AxisMinorSplitLine` + +Inherits or Implemented: [BaseLine](#BaseLine) + +Minor split line of axis in grid area. + +|field|default|since|comment| +|--|--|--|--| +|`distance`|||The distance between the split line and axis line. +|`autoColor`|||auto color. + +## `AxisMinorTick` + +Inherits or Implemented: [BaseLine](#BaseLine) + +Settings related to axis minor tick. + +|field|default|since|comment| +|--|--|--|--| +|`splitNumber`|5||Number of segments that the axis is split into. +|`autoColor`||| + ## `AxisName` Inherits or Implemented: [ChildComponent](#ChildComponent) @@ -384,7 +410,8 @@ Inherits or Implemented: [ComponentTheme](#ComponentTheme) |`splitLineType`|||the type of split line.
`LineStyle.Type`:
- `Solid`: 实线
- `Dashed`: 虚线
- `Dotted`: 点线
- `DashDot`: 点划线
- `DashDotDot`: 双点划线
- `None`: 双点划线
| |`splitLineWidth`|1f||the width of split line. |`splitLineLength`|0f||the length of split line. -|`splitLineColor`|||the color of line. +|`splitLineColor`|||the color of split line. +|`minorSplitLineColor`|||the color of minor split line. |`tickWidth`|1f||the width of tick. |`tickLength`|5f||the length of tick. |`tickColor`|||the color of tick. @@ -994,6 +1021,9 @@ Polar coordinate can be used in scatter and line chart. Every polar coordinate h Inherits or Implemented: [Serie](#Serie),[INeedSerieContainer](#INeedSerieContainer) +|field|default|since|comment| +|--|--|--|--| +|`smooth`|false|3.2.0|Whether use smooth curve. ## `RadarAxisTheme` diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index 78aad72c..42e46a7e 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -76,6 +76,8 @@ - [ArrowStyle](#ArrowStyle) - [AxisLabel](#AxisLabel) - [AxisLine](#AxisLine) +- [AxisMinorSplitLine](#AxisMinorSplitLine) +- [AxisMinorTick](#AxisMinorTick) - [AxisName](#AxisName) - [AxisSplitArea](#AxisSplitArea) - [AxisSplitLine](#AxisSplitLine) @@ -263,8 +265,10 @@ Inherits or Implemented: [MainComponent](#MainComponent) |`axisLine`|||坐标轴轴线。 [AxisLine](#AxisLine)| |`axisName`|||坐标轴名称。 [AxisName](#AxisName)| |`axisTick`|||坐标轴刻度。 [AxisTick](#AxisTick)| +|`minorTick`|||坐标轴次刻度。 [AxisMinorTick](#AxisMinorTick)| |`axisLabel`|||坐标轴刻度标签。 [AxisLabel](#AxisLabel)| |`splitLine`|||坐标轴分割线。 [AxisSplitLine](#AxisSplitLine)| +|`minorSplitLine`|||坐标轴次分割线。 [AxisMinorSplitLine](#AxisMinorSplitLine)| |`splitArea`|||坐标轴分割区域。 [AxisSplitArea](#AxisSplitArea)| ## `AxisLabel` @@ -295,6 +299,28 @@ Inherits or Implemented: [BaseLine](#BaseLine) |`showArrow`|||是否显示箭头。 |`arrow`|||轴线箭头。 [ArrowStyle](#ArrowStyle)| +## `AxisMinorSplitLine` + +Inherits or Implemented: [BaseLine](#BaseLine) + +坐标轴在 grid 区域中的次分隔线。次分割线会对齐次刻度线 minorTick。 + +|field|default|since|comment| +|--|--|--|--| +|`distance`|||刻度线与轴线的距离。 +|`autoColor`|||自动设置颜色。 + +## `AxisMinorTick` + +Inherits or Implemented: [BaseLine](#BaseLine) + +坐标轴次刻度相关设置。注意:次刻度无法再类目轴中使用。 + +|field|default|since|comment| +|--|--|--|--| +|`splitNumber`|5||分隔线之间分割的刻度数。 +|`autoColor`||| + ## `AxisName` Inherits or Implemented: [ChildComponent](#ChildComponent) @@ -385,6 +411,7 @@ Inherits or Implemented: [ComponentTheme](#ComponentTheme) |`splitLineWidth`|1f||分割线线宽。 |`splitLineLength`|0f||分割线线长。 |`splitLineColor`|||分割线线颜色。 +|`minorSplitLineColor`|||次分割线线颜色。 |`tickWidth`|1f||刻度线线宽。 |`tickLength`|5f||刻度线线长。 |`tickColor`|||坐标轴线颜色。 @@ -994,6 +1021,9 @@ Inherits or Implemented: [CoordSystem](#CoordSystem),[ISerieContainer](#ISerieCo Inherits or Implemented: [Serie](#Serie),[INeedSerieContainer](#INeedSerieContainer) +|field|default|since|comment| +|--|--|--|--| +|`smooth`|false|3.2.0|是否平滑曲线。平滑曲线时不支持区域填充颜色。 ## `RadarAxisTheme` diff --git a/Editor/ChildComponents/LineDrawer.cs b/Editor/ChildComponents/LineDrawer.cs index b3d4896d..002d520c 100644 --- a/Editor/ChildComponents/LineDrawer.cs +++ b/Editor/ChildComponents/LineDrawer.cs @@ -47,6 +47,18 @@ namespace XCharts.Editor } } + [CustomPropertyDrawer(typeof(AxisMinorSplitLine), true)] + public class AxisMinorSplitLineDrawer : BaseLineDrawer + { + public override string ClassName { get { return "MinorSplitLine"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + //PropertyField(prop, "m_Distance"); + //PropertyField(prop, "m_AutoColor"); + } + } + [CustomPropertyDrawer(typeof(AxisTick), true)] public class AxisTickDrawer : BaseLineDrawer { @@ -63,4 +75,16 @@ namespace XCharts.Editor PropertyField(prop, "m_AutoColor"); } } + + [CustomPropertyDrawer(typeof(AxisMinorTick), true)] + public class AxisMinorTickDrawer : BaseLineDrawer + { + public override string ClassName { get { return "MinorTick"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_SplitNumber"); + //PropertyField(prop, "m_AutoColor"); + } + } } \ No newline at end of file diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs index 47868ac1..46e1bac4 100644 --- a/Editor/MainComponents/AxisEditor.cs +++ b/Editor/MainComponents/AxisEditor.cs @@ -70,7 +70,6 @@ namespace XCharts.Editor else { PropertyField("m_Interval"); - PropertyField("m_BoundaryGap"); } DrawExtendeds(); PropertyField("m_AxisLine"); @@ -79,6 +78,11 @@ namespace XCharts.Editor PropertyField("m_AxisLabel"); PropertyField("m_SplitLine"); PropertyField("m_SplitArea"); + if (type != Axis.AxisType.Category) + { + PropertyField("m_MinorTick"); + PropertyField("m_MinorSplitLine"); + } PropertyListField("m_Icons", true); if (type == Axis.AxisType.Category) { @@ -93,12 +97,10 @@ namespace XCharts.Editor } [ComponentEditor(typeof(XAxis))] - public class XAxisEditor : AxisEditor - { } + public class XAxisEditor : AxisEditor { } [ComponentEditor(typeof(YAxis))] - public class YAxisEditor : AxisEditor - { } + public class YAxisEditor : AxisEditor { } [ComponentEditor(typeof(SingleAxis))] public class SingleAxisEditor : AxisEditor @@ -128,12 +130,10 @@ namespace XCharts.Editor } [ComponentEditor(typeof(RadiusAxis))] - public class RadiusAxisEditor : AxisEditor - { } + public class RadiusAxisEditor : AxisEditor { } [ComponentEditor(typeof(ParallelAxis))] - public class ParallelAxisEditor : AxisEditor - { } + public class ParallelAxisEditor : AxisEditor { } [CustomPropertyDrawer(typeof(AxisLabel), true)] public class AxisLabelDrawer : BasePropertyDrawer diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index b51f9461..fe42a520 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -98,8 +98,10 @@ namespace XCharts.Runtime [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; [SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName; [SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick; + [SerializeField] protected AxisMinorTick m_MinorTick = AxisMinorTick.defaultMinorTick; [SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel; [SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine; + [SerializeField] protected AxisMinorSplitLine m_MinorSplitLine = AxisMinorSplitLine.defaultMinorSplitLine; [SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea; public AxisContext context = new AxisContext(); @@ -352,6 +354,24 @@ namespace XCharts.Runtime set { if (value != null) { m_SplitArea = value; SetVerticesDirty(); } } } /// + /// axis minor tick. + /// |坐标轴次刻度。 + /// + public AxisMinorTick minorTick + { + get { return m_MinorTick; } + set { if (value != null) { m_MinorTick = value; SetVerticesDirty(); } } + } + /// + /// axis minor split line. + /// |坐标轴次分割线。 + /// + public AxisMinorSplitLine minorSplitLine + { + get { return m_MinorSplitLine; } + set { if (value != null) { m_MinorSplitLine = value; SetVerticesDirty(); } } + } + /// /// Whether to add new data at the head or at the end of the list. /// |添加新数据时是在列表的头部还是尾部加入。 /// @@ -369,7 +389,9 @@ namespace XCharts.Runtime axisLine.anyDirty || axisTick.anyDirty || splitLine.anyDirty || - splitArea.anyDirty; + splitArea.anyDirty || + minorTick.anyDirty || + minorSplitLine.anyDirty; } } @@ -398,6 +420,8 @@ namespace XCharts.Runtime axisTick.ClearVerticesDirty(); splitLine.ClearVerticesDirty(); splitArea.ClearVerticesDirty(); + minorTick.ClearVerticesDirty(); + minorSplitLine.ClearVerticesDirty(); } public override void SetComponentDirty() @@ -429,6 +453,8 @@ namespace XCharts.Runtime axis.axisLabel = axisLabel.Clone(); axis.splitLine = splitLine.Clone(); axis.splitArea = splitArea.Clone(); + axis.minorTick = minorTick.Clone(); + axis.minorSplitLine = minorSplitLine.Clone(); axis.icons = new List(); axis.data = new List(); ChartHelper.CopyList(axis.data, data); @@ -457,6 +483,8 @@ namespace XCharts.Runtime axisLabel.Copy(axis.axisLabel); splitLine.Copy(axis.splitLine); splitArea.Copy(axis.splitArea); + minorTick.Copy(axis.minorTick); + minorSplitLine.Copy(axis.minorSplitLine); ChartHelper.CopyList(data, axis.data); ChartHelper.CopyList(icons, axis.icons); } @@ -664,6 +692,18 @@ namespace XCharts.Runtime } } + public float GetValueLength(double value, float axisLength) + { + if (context.minMaxRange > 0) + { + return axisLength * ((float) (value / context.minMaxRange)); + } + else + { + return 0; + } + } + /// /// 获得指定区域缩放的类目数据列表 /// @@ -788,5 +828,16 @@ namespace XCharts.Runtime else return 0; } + + public void UpdateZeroOffset(float axisLength) + { + context.offset = context.minValue > 0 || context.minMaxRange == 0? + 0 : + (context.maxValue < 0 ? + axisLength : + (float) (Math.Abs(context.minValue) * (axisLength / + (Math.Abs(context.minValue) + Math.Abs(context.maxValue)))) + ); + } } } \ No newline at end of file diff --git a/Runtime/Component/Axis/AxisContext.cs b/Runtime/Component/Axis/AxisContext.cs index 37fcf14e..5a50c1e4 100644 --- a/Runtime/Component/Axis/AxisContext.cs +++ b/Runtime/Component/Axis/AxisContext.cs @@ -7,9 +7,21 @@ namespace XCharts.Runtime public class AxisContext : MainComponentContext { public Orient orient; + /// + /// 坐标轴的起点X + /// public float x; + /// + /// 坐标轴的起点Y + /// public float y; + /// + /// 坐标轴原点X + /// public float zeroX; + /// + /// 坐标轴原点Y + /// public float zeroY; public float width; public float height; @@ -34,6 +46,11 @@ namespace XCharts.Runtime /// public float offset; public double minMaxRange; + /// + /// the tick value of value axis. + /// |数值轴时每个tick的数值。 + /// + public double tickValue; public float scaleWidth; public float startAngle; public double pointerValue; diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index aa290a88..3e1a4de5 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -24,7 +24,7 @@ namespace XCharts return Vector3.zero; } - protected virtual float GetAxisLineXOrY() + internal virtual float GetAxisLineXOrY() { return 0; } @@ -38,7 +38,7 @@ namespace XCharts return; if (!grid.context.isPointerEnter) { - axis.context.pointerValue = double.PositiveInfinity; + axis.context.pointerValue = double.NaN; } else { @@ -171,31 +171,11 @@ namespace XCharts var grid = chart.GetChartComponent(axis.gridIndex); if (grid != null && axis is XAxis && axis.IsValue()) { - axis.context.offset = axis.context.minValue > 0 ? - 0 : - (axis.context.maxValue < 0 ? - grid.context.width : - (float) (Math.Abs(axis.context.minValue) * (grid.context.width / - (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue)))) - ); - axis.context.x = grid.context.x; - axis.context.y = GetAxisLineXOrY(); - axis.context.zeroY = grid.context.y; - axis.context.zeroX = grid.context.x - (float) (axis.context.minValue * grid.context.width / axis.context.minMaxRange); + axis.UpdateZeroOffset(grid.context.width); } if (grid != null && axis is YAxis && axis.IsValue()) { - axis.context.offset = axis.context.minValue > 0 ? - 0 : - (axis.context.maxValue < 0 ? - grid.context.height : - (float) (Math.Abs(axis.context.minValue) * (grid.context.height / - (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue)))) - ); - axis.context.x = GetAxisLineXOrY(); - axis.context.y = grid.context.y; - axis.context.zeroX = grid.context.x; - axis.context.zeroY = grid.context.y - (float) (axis.context.minValue * grid.context.height / axis.context.minMaxRange); + axis.UpdateZeroOffset(grid.context.height); } } @@ -260,6 +240,7 @@ namespace XCharts } } var value = 0d; + axis.context.tickValue = tick; if (Mathf.Approximately((float) (axis.context.minValue % tick), 0)) { value = axis.context.minValue; @@ -581,24 +562,21 @@ namespace XCharts if (AxisHelper.NeedShowSplit(axis)) { var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom); - - var current = orient == Orient.Horizonal ? - startX : - startY; - + var tickWidth = axis.axisTick.GetWidth(theme.tickWidth); + var tickColor = axis.axisTick.GetColor(theme.tickColor); + var current = orient == Orient.Horizonal ? startX : startY; + var lastTickX = 0f; + var lastTickY = 0f; + var minorTickSplitNumber = axis.minorTick.splitNumber <= 0 ? 5 : axis.minorTick.splitNumber; + var minorTickDistance = axis.GetValueLength(axis.context.tickValue / minorTickSplitNumber, axisLength); + var minorTickColor = axis.minorTick.GetColor(theme.tickColor); + var minorTickWidth = axis.minorTick.GetWidth(theme.tickWidth); + var minorTickLength = axis.minorTick.GetLength(theme.tickLength * 0.6f); for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom); - if (i == 0 && (!axis.axisTick.showStartTick || axis.axisTick.alignWithLabel)) - { - current += scaleWidth; - continue; - } - if (i == size - 1 && !axis.axisTick.showEndTick) - { - current += scaleWidth; - continue; - } + var hideTick = (i == 0 && (!axis.axisTick.showStartTick || axis.axisTick.alignWithLabel)) || + (i == size - 1 && !axis.axisTick.showEndTick); if (axis.axisTick.show) { if (orient == Orient.Horizonal) @@ -612,21 +590,44 @@ namespace XCharts var sY = 0f; var eY = 0f; + var mY = 0f; if ((axis.axisTick.inside && axis.IsBottom()) || (!axis.axisTick.inside && axis.IsTop())) { sY = startY + lineWidth; eY = sY + tickLength; + mY = sY + minorTickLength; } else { sY = startY - lineWidth; eY = sY - tickLength; + mY = sY - minorTickLength; } - - UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY), - axis.axisTick.GetWidth(theme.tickWidth), - axis.axisTick.GetColor(theme.tickColor)); + if (!hideTick) + UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY), tickWidth, tickColor); + if (axis.minorTick.show && i > 0 && minorTickDistance > 0) + { + if (lastTickX <= axis.context.zeroX || (i == 1 && pX > axis.context.zeroX)) + { + var tickTotal = pX - minorTickDistance; + while (tickTotal > lastTickX) + { + UGL.DrawLine(vh, new Vector3(tickTotal, sY), new Vector3(tickTotal, mY), minorTickWidth, minorTickColor); + tickTotal -= minorTickDistance; + } + } + else + { + var tickTotal = lastTickX + minorTickDistance; + while (tickTotal < pX) + { + UGL.DrawLine(vh, new Vector3(tickTotal, sY), new Vector3(tickTotal, mY), minorTickWidth, minorTickColor); + tickTotal += minorTickDistance; + } + } + } + lastTickX = pX; } else { @@ -639,21 +640,46 @@ namespace XCharts var sX = 0f; var eX = 0f; + var mX = 0f; if ((axis.axisTick.inside && axis.IsLeft()) || (!axis.axisTick.inside && axis.IsRight())) { sX = startX + lineWidth; eX = sX + tickLength; + mX = sX + minorTickLength; } else { sX = startX - lineWidth; eX = sX - tickLength; + mX = sX - minorTickLength; } + if (!hideTick) + UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY), tickWidth, tickColor); + if (axis.minorTick.show && i > 0 && minorTickDistance > 0) + { + if (lastTickY <= axis.context.zeroY || (i == 1 && pY > axis.context.zeroY)) + { + var tickTotal = pY - minorTickDistance; + while (tickTotal > lastTickY) + { - UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY), - axis.axisTick.GetWidth(theme.tickWidth), - axis.axisTick.GetColor(theme.tickColor)); + UGL.DrawLine(vh, new Vector3(sX, tickTotal), new Vector3(mX, tickTotal), minorTickWidth, minorTickColor); + tickTotal -= minorTickDistance; + } + } + else + { + var tickTotal = lastTickY + minorTickDistance; + while (tickTotal < pY) + { + + UGL.DrawLine(vh, new Vector3(sX, tickTotal), new Vector3(mX, tickTotal), minorTickWidth, minorTickColor); + tickTotal += minorTickDistance; + } + } + } + lastTickY = pY; } } current += scaleWidth; @@ -707,9 +733,12 @@ namespace XCharts } protected void DrawAxisSplit(VertexHelper vh, AxisTheme theme, DataZoom dataZoom, - Orient orient, float startX, float startY, float axisLength, float splitLength, Axis relativedAxis = null) + Orient orient, float startX, float startY, float axisLength, float splitLength, + Axis relativedAxis = null) { Axis axis = component; + var axisLineWidth = axis.axisLine.GetWidth(theme.lineWidth); + splitLength -= axisLineWidth; var lineColor = axis.splitLine.GetColor(theme.splitLineColor); var lineWidth = axis.splitLine.GetWidth(theme.lineWidth); var lineType = axis.splitLine.GetType(theme.splitLineType); @@ -725,6 +754,14 @@ namespace XCharts var current = orient == Orient.Horizonal ? startX : startY; + + var lastSplitX = 0f; + var lastSplitY = 0f; + var minorTickSplitNumber = axis.minorTick.splitNumber <= 0 ? 5 : axis.minorTick.splitNumber; + var minorTickDistance = axis.GetValueLength(axis.context.tickValue / minorTickSplitNumber, axisLength); + var minorSplitLineColor = axis.minorSplitLine.GetColor(theme.minorSplitLineColor); + var minorLineWidth = axis.minorSplitLine.GetWidth(theme.lineWidth); + var minorLineType = axis.minorSplitLine.GetType(theme.splitLineType); for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom); @@ -760,23 +797,99 @@ namespace XCharts { if (orient == Orient.Horizonal) { - if (relativedAxis == null || !MathUtil.Approximately(current, GetAxisLineXOrY())) + if (relativedAxis == null || !MathUtil.Approximately(current, relativedAxis.context.x)) + { ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, new Vector3(current, startY), new Vector3(current, startY + splitLength), lineColor); + } + if (axis.minorSplitLine.show && i > 0 && minorTickDistance > 0) + { + if (lastSplitX <= axis.context.zeroX || (i == 1 && current > axis.context.zeroX)) + { + var tickTotal = current - minorTickDistance; + var count = 0; + while (tickTotal > lastSplitX && count < minorTickSplitNumber - 1) + { + ChartDrawer.DrawLineStyle(vh, + minorLineType, + minorLineWidth, + new Vector3(tickTotal, startY), + new Vector3(tickTotal, startY + splitLength), + minorSplitLineColor); + count++; + tickTotal -= minorTickDistance; + } + } + else + { + var tickTotal = lastSplitX + minorTickDistance; + var count = 0; + while (tickTotal < current && count < minorTickSplitNumber - 1) + { + ChartDrawer.DrawLineStyle(vh, + minorLineType, + minorLineWidth, + new Vector3(tickTotal, startY), + new Vector3(tickTotal, startY + splitLength), + minorSplitLineColor); + count++; + tickTotal += minorTickDistance; + } + } + } + lastSplitX = current; } else { - if (relativedAxis == null || !MathUtil.Approximately(current, GetAxisLineXOrY())) + if (relativedAxis == null || !MathUtil.Approximately(current, relativedAxis.context.y)) + { ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, new Vector3(startX, current), new Vector3(startX + splitLength, current), lineColor); + } + if (axis.minorSplitLine.show && i > 0 && minorTickDistance > 0) + { + if (lastSplitY <= axis.context.zeroY || (i == 1 && current > axis.context.zeroY)) + { + var tickTotal = current - minorTickDistance; + var count = 0; + while (tickTotal > lastSplitY && count < minorTickSplitNumber - 1) + { + ChartDrawer.DrawLineStyle(vh, + minorLineType, + minorLineWidth, + new Vector3(startX, tickTotal), + new Vector3(startX + splitLength, tickTotal), + minorSplitLineColor); + count++; + tickTotal -= minorTickDistance; + } + } + else + { + var tickTotal = lastSplitY + minorTickDistance; + var count = 0; + while (tickTotal < current && count < minorTickSplitNumber - 1) + { + ChartDrawer.DrawLineStyle(vh, + minorLineType, + minorLineWidth, + new Vector3(startX, tickTotal), + new Vector3(startX + splitLength, tickTotal), + minorSplitLineColor); + count++; + tickTotal += minorTickDistance; + } + } + } + lastSplitY = current; } } } diff --git a/Runtime/Component/Axis/AxisHelper.cs b/Runtime/Component/Axis/AxisHelper.cs index 888e30cf..e24be302 100644 --- a/Runtime/Component/Axis/AxisHelper.cs +++ b/Runtime/Component/Axis/AxisHelper.cs @@ -338,8 +338,7 @@ namespace XCharts.Runtime axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit); return; } - if (axis.type == Axis.AxisType.Time) - { } + if (axis.type == Axis.AxisType.Time) { } else if (axis.minMaxType == Axis.AxisMinMaxType.Custom) { if (axis.min != 0 || axis.max != 0) @@ -363,8 +362,7 @@ namespace XCharts.Runtime { case Axis.AxisMinMaxType.Default: - if (minValue == 0 && maxValue == 0) - { } + if (minValue == 0 && maxValue == 0) { } else if (minValue > 0 && maxValue > 0) { minValue = 0; @@ -557,5 +555,43 @@ namespace XCharts.Runtime yDataHig; } } + + public static float GetAxisXOrY(GridCoord grid, Axis axis, Axis relativedAxis) + { + if (axis is XAxis) + return GetXAxisXOrY(grid, axis, relativedAxis); + else if (axis is YAxis) + return GetYAxisXOrY(grid, axis, relativedAxis); + else if (axis is SingleAxis) + return axis.context.y + axis.offset; + else if (axis is ParallelAxis) + return axis.context.y; + else + return axis.context.x; + } + + public static float GetXAxisXOrY(GridCoord grid, Axis xAxis, Axis relativedAxis) + { + var startY = grid.context.y + xAxis.offset; + if (xAxis.IsTop()) + startY += grid.context.height; + else if (xAxis.axisLine.onZero && relativedAxis.IsValue() && relativedAxis.gridIndex == xAxis.gridIndex) + startY += relativedAxis.context.offset; + return startY; + } + + public static float GetYAxisXOrY(GridCoord grid, Axis yAxis, Axis relativedAxis) + { + var startX = grid.context.x + yAxis.offset; + if (yAxis.IsRight()) + startX += grid.context.width; + else if (yAxis.axisLine.onZero && relativedAxis.IsValue() && relativedAxis.gridIndex == yAxis.gridIndex) + startX += relativedAxis.context.offset; + return startX; + } + + public static void UpdateAxisOffset(){ + + } } } \ No newline at end of file diff --git a/Runtime/Component/Axis/AxisMinorSplitLine.cs b/Runtime/Component/Axis/AxisMinorSplitLine.cs new file mode 100644 index 00000000..6716705b --- /dev/null +++ b/Runtime/Component/Axis/AxisMinorSplitLine.cs @@ -0,0 +1,61 @@ +using System; +using UnityEngine; + +namespace XCharts.Runtime +{ + /// + /// Minor split line of axis in grid area. + /// |坐标轴在 grid 区域中的次分隔线。次分割线会对齐次刻度线 minorTick。 + /// + [Serializable] + public class AxisMinorSplitLine : BaseLine + { + [SerializeField] private float m_Distance; + [SerializeField] private bool m_AutoColor; + + /// + /// The distance between the split line and axis line. + /// |刻度线与轴线的距离。 + /// + public float distance { get { return m_Distance; } set { m_Distance = value; } } + /// + /// auto color. + /// |自动设置颜色。 + /// + public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } } + + public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } } + public override void ClearVerticesDirty() + { + base.ClearVerticesDirty(); + m_LineStyle.ClearVerticesDirty(); + } + public static AxisMinorSplitLine defaultMinorSplitLine + { + get + { + return new AxisMinorSplitLine() + { + m_Show = false, + }; + } + } + + public AxisMinorSplitLine Clone() + { + var axisSplitLine = new AxisMinorSplitLine(); + axisSplitLine.show = show; + axisSplitLine.distance = distance; + axisSplitLine.autoColor = autoColor; + axisSplitLine.lineStyle = lineStyle.Clone(); + return axisSplitLine; + } + + public void Copy(AxisMinorSplitLine splitLine) + { + base.Copy(splitLine); + distance = splitLine.distance; + autoColor = splitLine.autoColor; + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Axis/AxisMinorSplitLine.cs.meta b/Runtime/Component/Axis/AxisMinorSplitLine.cs.meta new file mode 100644 index 00000000..d1400a2d --- /dev/null +++ b/Runtime/Component/Axis/AxisMinorSplitLine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7be5a277811c64887a121d7711929aab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Axis/AxisMinorTick.cs b/Runtime/Component/Axis/AxisMinorTick.cs new file mode 100644 index 00000000..67e16f48 --- /dev/null +++ b/Runtime/Component/Axis/AxisMinorTick.cs @@ -0,0 +1,63 @@ +using UnityEngine; + +namespace XCharts.Runtime +{ + /// + /// Settings related to axis minor tick. + /// |坐标轴次刻度相关设置。注意:次刻度无法再类目轴中使用。 + /// + [System.Serializable] + [Since("v3.2.0")] + public class AxisMinorTick : BaseLine + { + [SerializeField] protected int m_SplitNumber = 5; + [SerializeField] private bool m_AutoColor; + + /// + /// Number of segments that the axis is split into. + /// |分隔线之间分割的刻度数。 + /// + public int splitNumber + { + get { return m_SplitNumber; } + set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); } + } + public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } } + + public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } } + public override void ClearVerticesDirty() + { + base.ClearVerticesDirty(); + m_LineStyle.ClearVerticesDirty(); + } + public static AxisMinorTick defaultMinorTick + { + get + { + var tick = new AxisMinorTick + { + m_Show = false + }; + return tick; + } + } + + public AxisMinorTick Clone() + { + var axisTick = new AxisMinorTick(); + axisTick.show = show; + axisTick.splitNumber = splitNumber; + axisTick.autoColor = autoColor; + axisTick.lineStyle = lineStyle.Clone(); + return axisTick; + } + + public void Copy(AxisMinorTick axisTick) + { + show = axisTick.show; + splitNumber = axisTick.splitNumber; + autoColor = axisTick.autoColor; + lineStyle.Copy(axisTick.lineStyle); + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Axis/AxisMinorTick.cs.meta b/Runtime/Component/Axis/AxisMinorTick.cs.meta new file mode 100644 index 00000000..6dda4b2f --- /dev/null +++ b/Runtime/Component/Axis/AxisMinorTick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3bea237f1eccc409ba2635e6f4ca609c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs b/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs index 76152220..0ae6185c 100644 --- a/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs +++ b/Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs @@ -116,7 +116,6 @@ namespace XCharts.Runtime return; var dataZoom = chart.GetDataZoomOfAxis(axis); - DrawAxisSplit(vh, chart.theme.axis, dataZoom, m_Orient, axis.context.x, @@ -159,7 +158,7 @@ namespace XCharts.Runtime } } - protected override float GetAxisLineXOrY() + internal override float GetAxisLineXOrY() { return component.context.y; } diff --git a/Runtime/Component/Axis/SingleAxis/SingleAxisHandler.cs b/Runtime/Component/Axis/SingleAxis/SingleAxisHandler.cs index cea04762..28b33ef8 100644 --- a/Runtime/Component/Axis/SingleAxis/SingleAxisHandler.cs +++ b/Runtime/Component/Axis/SingleAxis/SingleAxisHandler.cs @@ -117,7 +117,7 @@ namespace XCharts.Runtime } } - protected override float GetAxisLineXOrY() + internal override float GetAxisLineXOrY() { return component.context.y + component.offset; } diff --git a/Runtime/Component/Axis/XAxis/XAxis.cs b/Runtime/Component/Axis/XAxis/XAxis.cs index 86059069..448a8395 100644 --- a/Runtime/Component/Axis/XAxis/XAxis.cs +++ b/Runtime/Component/Axis/XAxis/XAxis.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/Component/Axis/XAxis/XAxisHander.cs b/Runtime/Component/Axis/XAxis/XAxisHander.cs index e4020e08..fe701798 100644 --- a/Runtime/Component/Axis/XAxis/XAxisHander.cs +++ b/Runtime/Component/Axis/XAxis/XAxisHander.cs @@ -15,17 +15,32 @@ namespace XCharts.Runtime public override void Update() { + UpdateAxisMinMaxValue(component.index, component); UpdatePointerValue(component); } public override void DrawBase(VertexHelper vh) { + UpdatePosition(component); DrawXAxisSplit(vh, component); DrawXAxisLine(vh, component); DrawXAxisTick(vh, component); } + private void UpdatePosition(XAxis axis) + { + var grid = chart.GetChartComponent(axis.gridIndex); + if (grid != null && axis is XAxis && axis.IsValue()) + { + var relativedAxis = chart.GetChartComponent(axis.gridIndex); + axis.context.x = grid.context.x; + axis.context.y = AxisHelper.GetXAxisXOrY(grid, axis, relativedAxis); + axis.context.zeroY = grid.context.y; + axis.context.zeroX = grid.context.x + axis.context.offset; + } + } + private void InitXAxis(XAxis xAxis) { var theme = chart.theme; @@ -137,16 +152,9 @@ namespace XCharts.Runtime } } - protected override float GetAxisLineXOrY() + internal override float GetAxisLineXOrY() { - var xAxis = component; - var grid = chart.GetChartComponent(xAxis.gridIndex); - var startY = grid.context.y + xAxis.offset; - if (xAxis.IsTop()) - startY += grid.context.height; - else - startY += ComponentHelper.GetXAxisOnZeroOffset(chart.components, xAxis); - return startY; + return component.context.y; } } } \ No newline at end of file diff --git a/Runtime/Component/Axis/YAxis/YAxisHander.cs b/Runtime/Component/Axis/YAxis/YAxisHander.cs index 58041f55..1aa81a67 100644 --- a/Runtime/Component/Axis/YAxis/YAxisHander.cs +++ b/Runtime/Component/Axis/YAxis/YAxisHander.cs @@ -21,11 +21,25 @@ namespace XCharts.Runtime public override void DrawBase(VertexHelper vh) { + UpdatePosition(component); DrawYAxisSplit(vh, component.index, component); DrawYAxisLine(vh, component.index, component); DrawYAxisTick(vh, component.index, component); } + private void UpdatePosition(YAxis axis) + { + var grid = chart.GetChartComponent(axis.gridIndex); + if (grid != null && axis.IsValue()) + { + var relativedAxis = chart.GetChartComponent(axis.gridIndex); + axis.context.x = AxisHelper.GetYAxisXOrY(grid, axis, relativedAxis); + axis.context.y = grid.context.y; + axis.context.zeroX = axis.context.x; + axis.context.zeroY = axis.context.y + axis.context.offset; + } + } + private void InitYAxis(YAxis yAxis) { var theme = chart.theme; @@ -135,16 +149,9 @@ namespace XCharts.Runtime } } - protected override float GetAxisLineXOrY() + internal override float GetAxisLineXOrY() { - var yAxis = component; - var grid = chart.GetChartComponent(yAxis.gridIndex); - var startX = grid.context.x + yAxis.offset; - if (yAxis.IsRight()) - startX += grid.context.width; - else - startX += ComponentHelper.GetYAxisOnZeroOffset(chart.components, yAxis); - return startX; + return component.context.x; } } } \ No newline at end of file diff --git a/Runtime/Theme/AxisTheme.cs b/Runtime/Theme/AxisTheme.cs index ee5d8fdf..1cc388fc 100644 --- a/Runtime/Theme/AxisTheme.cs +++ b/Runtime/Theme/AxisTheme.cs @@ -18,6 +18,7 @@ namespace XCharts.Runtime [SerializeField] protected float m_SplitLineWidth = 1f; [SerializeField] protected float m_SplitLineLength = 0f; [SerializeField] protected Color32 m_SplitLineColor; + [SerializeField] protected Color32 m_MinorSplitLineColor; [SerializeField] protected float m_TickWidth = 1f; [SerializeField] protected float m_TickLength = 5f; [SerializeField] protected Color32 m_TickColor; @@ -87,7 +88,7 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_SplitLineLength, value)) SetVerticesDirty(); } } /// - /// the color of line. + /// the color of split line. /// |分割线线颜色。 /// public Color32 splitLineColor @@ -96,6 +97,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetColor(ref m_SplitLineColor, value)) SetVerticesDirty(); } } /// + /// the color of minor split line. + /// |次分割线线颜色。 + /// + public Color32 minorSplitLineColor + { + get { return ChartHelper.IsClearColor(m_MinorSplitLineColor) ? ColorUtil.GetColor("#F4F7FD") : m_MinorSplitLineColor; } + set { if (PropertyUtil.SetColor(ref m_MinorSplitLineColor, value)) SetVerticesDirty(); } + } + /// /// the length of tick. /// |刻度线线长。 /// @@ -146,33 +156,36 @@ namespace XCharts.Runtime switch (theme) { case ThemeType.Default: - m_LineColor = ColorUtil.GetColor("#514D4D"); - m_TickColor = ColorUtil.GetColor("#514D4D"); - m_SplitLineColor = ColorUtil.GetColor("#51515120"); + m_LineColor = ColorUtil.GetColor("#6E7079"); + m_TickColor = ColorUtil.GetColor("#6E7079"); + m_SplitLineColor = ColorUtil.GetColor("#E0E6F1"); + m_MinorSplitLineColor = ColorUtil.GetColor("#F4F7FD"); m_SplitAreaColors = new List { - new Color32(250, 250, 250, 77), - new Color32(200, 200, 200, 77) + new Color32(250, 250, 250, 51), + new Color32(210, 219, 238, 51) }; break; case ThemeType.Light: - m_LineColor = ColorUtil.GetColor("#514D4D"); - m_TickColor = ColorUtil.GetColor("#514D4D"); - m_SplitLineColor = ColorUtil.GetColor("#51515120"); + m_LineColor = ColorUtil.GetColor("#6E7079"); + m_TickColor = ColorUtil.GetColor("#6E7079"); + m_SplitLineColor = ColorUtil.GetColor("#E0E6F1"); + m_MinorSplitLineColor = ColorUtil.GetColor("#F4F7FD"); m_SplitAreaColors = new List { - new Color32(250, 250, 250, 77), - new Color32(200, 200, 200, 77) + new Color32(250, 250, 250, 51), + new Color32(210, 219, 238, 51) }; break; case ThemeType.Dark: - m_LineColor = ColorUtil.GetColor("#B9B8CE"); - m_TickColor = ColorUtil.GetColor("#B9B8CE"); - m_SplitLineColor = ColorUtil.GetColor("#484753"); + m_LineColor = ColorUtil.GetColor("#6E7079"); + m_TickColor = ColorUtil.GetColor("#6E7079"); + m_SplitLineColor = ColorUtil.GetColor("#E0E6F1"); + m_MinorSplitLineColor = ColorUtil.GetColor("#F4F7FD"); m_SplitAreaColors = new List { new Color32(255, 255, 255, (byte) (0.02f * 255)), - new Color32(255, 255, 255, (byte) (0.05f * 255)) + new Color32(210, 219, 238, (byte) (0.02f * 255)) }; break; } @@ -199,29 +212,25 @@ namespace XCharts.Runtime [Serializable] public class AxisTheme : BaseAxisTheme { - public AxisTheme(ThemeType theme) : base(theme) - { } + public AxisTheme(ThemeType theme) : base(theme) { } } [Serializable] public class RadiusAxisTheme : BaseAxisTheme { - public RadiusAxisTheme(ThemeType theme) : base(theme) - { } + public RadiusAxisTheme(ThemeType theme) : base(theme) { } } [Serializable] public class AngleAxisTheme : BaseAxisTheme { - public AngleAxisTheme(ThemeType theme) : base(theme) - { } + public AngleAxisTheme(ThemeType theme) : base(theme) { } } [Serializable] public class PolarAxisTheme : BaseAxisTheme { - public PolarAxisTheme(ThemeType theme) : base(theme) - { } + public PolarAxisTheme(ThemeType theme) : base(theme) { } } [Serializable] diff --git a/Runtime/Utilities/ColorUtil.cs b/Runtime/Utilities/ColorUtil.cs index ab650e4f..b5809792 100644 --- a/Runtime/Utilities/ColorUtil.cs +++ b/Runtime/Utilities/ColorUtil.cs @@ -1,11 +1,14 @@ +using System.Collections.Generic; using UnityEngine; namespace XCharts.Runtime { public static class ColorUtil { + private static Dictionary s_ColorCached = new Dictionary(); public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0); public static readonly Vector2 zeroVector2 = Vector2.zero; + /// /// Convert the html string to color. /// |将字符串颜色值转成Color。 @@ -14,9 +17,14 @@ namespace XCharts.Runtime /// public static Color32 GetColor(string hexColorStr) { + if (s_ColorCached.ContainsKey(hexColorStr)) + { + return s_ColorCached[hexColorStr]; + } Color color; ColorUtility.TryParseHtmlString(hexColorStr, out color); - return (Color32) color; + s_ColorCached[hexColorStr] = (Color32) color; + return s_ColorCached[hexColorStr]; } } } \ No newline at end of file From 47ee421913d58c49535a86d1ef70b9768dd71918 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 20 Jul 2022 07:38:18 +0800 Subject: [PATCH 04/27] [bug][axis] fix showStartLabel and showEndLabel not work --- CHANGELOG.md | 1 + Runtime/Component/Axis/Axis.cs | 17 ++++++++++++++++- Runtime/Component/Axis/AxisHandler.cs | 8 ++++---- Runtime/Component/Axis/XAxis/XAxisHander.cs | 3 +-- Runtime/Component/Axis/YAxis/YAxisHander.cs | 2 +- Runtime/Internal/Utilities/ChartHelper.cs | 7 +------ 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4eadcf..ed741989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 * (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线 * (2022.07.19) 增加`Axis`的`MinorTick`设置坐标轴次刻度 * (2022.07.17) 增加`Radar`的`smooth`参数设置平滑曲线 diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index fe42a520..221c2e42 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -555,6 +555,21 @@ namespace XCharts.Runtime return m_Position == AxisPosition.Bottom; } + public bool IsNeedShowLabel(int index, int total = 0) + { + if (total == 0) + { + total = context.labelValueList.Count; + } + var labelShow = axisLabel.show && (axisLabel.interval == 0 || index % (axisLabel.interval + 1) == 0); + if (labelShow) + { + if (!axisLabel.showStartLabel && index == 0) labelShow = false; + else if (!axisLabel.showEndLabel && index == total - 1) labelShow = false; + } + return labelShow; + } + public void SetNeedUpdateFilterData() { context.isNeedUpdateFilterData = true; @@ -831,7 +846,7 @@ namespace XCharts.Runtime public void UpdateZeroOffset(float axisLength) { - context.offset = context.minValue > 0 || context.minMaxRange == 0? + context.offset = context.minValue > 0 || context.minMaxRange == 0 ? 0 : (context.maxValue < 0 ? axisLength : diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 3e1a4de5..8831dab5 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -296,12 +296,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).x - pos.x; - label.SetTextActive(dist > label.text.GetPreferredWidth()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.x - GetLabelPosition(0, i - 1).x; - label.SetTextActive(dist > label.text.GetPreferredWidth()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth()); } } else @@ -309,12 +309,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).y - pos.y; - label.SetTextActive(dist > label.text.GetPreferredHeight()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.y - GetLabelPosition(0, i - 1).y; - label.SetTextActive(dist > label.text.GetPreferredHeight()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight()); } } } diff --git a/Runtime/Component/Axis/XAxis/XAxisHander.cs b/Runtime/Component/Axis/XAxis/XAxisHander.cs index fe701798..c1b5cf14 100644 --- a/Runtime/Component/Axis/XAxis/XAxisHander.cs +++ b/Runtime/Component/Axis/XAxis/XAxisHander.cs @@ -15,7 +15,6 @@ namespace XCharts.Runtime public override void Update() { - UpdateAxisMinMaxValue(component.index, component); UpdatePointerValue(component); } @@ -31,7 +30,7 @@ namespace XCharts.Runtime private void UpdatePosition(XAxis axis) { var grid = chart.GetChartComponent(axis.gridIndex); - if (grid != null && axis is XAxis && axis.IsValue()) + if (grid != null) { var relativedAxis = chart.GetChartComponent(axis.gridIndex); axis.context.x = grid.context.x; diff --git a/Runtime/Component/Axis/YAxis/YAxisHander.cs b/Runtime/Component/Axis/YAxis/YAxisHander.cs index 1aa81a67..82c54fdd 100644 --- a/Runtime/Component/Axis/YAxis/YAxisHander.cs +++ b/Runtime/Component/Axis/YAxis/YAxisHander.cs @@ -30,7 +30,7 @@ namespace XCharts.Runtime private void UpdatePosition(YAxis axis) { var grid = chart.GetChartComponent(axis.gridIndex); - if (grid != null && axis.IsValue()) + if (grid != null) { var relativedAxis = chart.GetChartComponent(axis.gridIndex); axis.context.x = AxisHelper.GetYAxisXOrY(grid, axis, relativedAxis); diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index abf9ad4f..47c56e04 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -336,12 +336,7 @@ namespace XCharts.Runtime { var textStyle = axis.axisLabel.textStyle; var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment); - var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0); - if (labelShow) - { - if (!axis.axisLabel.showStartLabel && index == 0) labelShow = false; - else if (!axis.axisLabel.showEndLabel && index == total - 1) labelShow = false; - } + var labelShow = axis.IsNeedShowLabel(index, total); label.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index)); label.text.SetActive(labelShow); return label; From 8dde322c040f4eeb1ed7b649300b619acfa15b0e Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 20 Jul 2022 08:15:27 +0800 Subject: [PATCH 05/27] [doc] class doc support since version --- CHANGELOG.md | 1 + Documentation/XChartsConfiguration-EN.md | 8 ++++++-- Documentation/XChartsConfiguration-ZH.md | 10 +++++++--- Runtime/Component/Axis/Axis.cs | 4 ++-- Runtime/Component/Axis/AxisMinorSplitLine.cs | 1 + Runtime/Component/Axis/AxisMinorTick.cs | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed741989..d2e2ad00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持 * (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 * (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线 * (2022.07.19) 增加`Axis`的`MinorTick`设置坐标轴次刻度 diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index 6af10094..f60e4b3c 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -265,11 +265,11 @@ The axis in rectangular coordinate. |`axisLine`|||axis Line. [AxisLine](#AxisLine)| |`axisName`|||axis name. [AxisName](#AxisName)| |`axisTick`|||axis tick. [AxisTick](#AxisTick)| -|`minorTick`|||axis minor tick. [AxisMinorTick](#AxisMinorTick)| |`axisLabel`|||axis label. [AxisLabel](#AxisLabel)| |`splitLine`|||axis split line. [AxisSplitLine](#AxisSplitLine)| -|`minorSplitLine`|||axis minor split line. [AxisMinorSplitLine](#AxisMinorSplitLine)| |`splitArea`|||axis split area. [AxisSplitArea](#AxisSplitArea)| +|`minorTick`||v3.2.0|axis minor tick. [AxisMinorTick](#AxisMinorTick)| +|`minorSplitLine`||v3.2.0|axis minor split line. [AxisMinorSplitLine](#AxisMinorSplitLine)| ## `AxisLabel` @@ -303,6 +303,8 @@ Settings related to axis line. Inherits or Implemented: [BaseLine](#BaseLine) +> Since `v3.2.0` + Minor split line of axis in grid area. |field|default|since|comment| @@ -314,6 +316,8 @@ Minor split line of axis in grid area. Inherits or Implemented: [BaseLine](#BaseLine) +> Since `v3.2.0` + Settings related to axis minor tick. |field|default|since|comment| diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index 42e46a7e..2de92c74 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -265,11 +265,11 @@ Inherits or Implemented: [MainComponent](#MainComponent) |`axisLine`|||坐标轴轴线。 [AxisLine](#AxisLine)| |`axisName`|||坐标轴名称。 [AxisName](#AxisName)| |`axisTick`|||坐标轴刻度。 [AxisTick](#AxisTick)| -|`minorTick`|||坐标轴次刻度。 [AxisMinorTick](#AxisMinorTick)| |`axisLabel`|||坐标轴刻度标签。 [AxisLabel](#AxisLabel)| |`splitLine`|||坐标轴分割线。 [AxisSplitLine](#AxisSplitLine)| -|`minorSplitLine`|||坐标轴次分割线。 [AxisMinorSplitLine](#AxisMinorSplitLine)| |`splitArea`|||坐标轴分割区域。 [AxisSplitArea](#AxisSplitArea)| +|`minorTick`||v3.2.0|坐标轴次刻度。 [AxisMinorTick](#AxisMinorTick)| +|`minorSplitLine`||v3.2.0|坐标轴次分割线。 [AxisMinorSplitLine](#AxisMinorSplitLine)| ## `AxisLabel` @@ -303,6 +303,8 @@ Inherits or Implemented: [BaseLine](#BaseLine) Inherits or Implemented: [BaseLine](#BaseLine) +> 从 `v3.2.0` 开始支持 + 坐标轴在 grid 区域中的次分隔线。次分割线会对齐次刻度线 minorTick。 |field|default|since|comment| @@ -314,7 +316,9 @@ Inherits or Implemented: [BaseLine](#BaseLine) Inherits or Implemented: [BaseLine](#BaseLine) -坐标轴次刻度相关设置。注意:次刻度无法再类目轴中使用。 +> 从 `v3.2.0` 开始支持 + +坐标轴次刻度相关设置。注意:次刻度无法在类目轴中使用。 |field|default|since|comment| |--|--|--|--| diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index 221c2e42..46bbb8e5 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -98,11 +98,11 @@ namespace XCharts.Runtime [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; [SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName; [SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick; - [SerializeField] protected AxisMinorTick m_MinorTick = AxisMinorTick.defaultMinorTick; [SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel; [SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine; - [SerializeField] protected AxisMinorSplitLine m_MinorSplitLine = AxisMinorSplitLine.defaultMinorSplitLine; [SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea; + [SerializeField][Since("v3.2.0")] protected AxisMinorTick m_MinorTick = AxisMinorTick.defaultMinorTick; + [SerializeField][Since("v3.2.0")] protected AxisMinorSplitLine m_MinorSplitLine = AxisMinorSplitLine.defaultMinorSplitLine; public AxisContext context = new AxisContext(); diff --git a/Runtime/Component/Axis/AxisMinorSplitLine.cs b/Runtime/Component/Axis/AxisMinorSplitLine.cs index 6716705b..f44c2fb9 100644 --- a/Runtime/Component/Axis/AxisMinorSplitLine.cs +++ b/Runtime/Component/Axis/AxisMinorSplitLine.cs @@ -8,6 +8,7 @@ namespace XCharts.Runtime /// |坐标轴在 grid 区域中的次分隔线。次分割线会对齐次刻度线 minorTick。 /// [Serializable] + [Since("v3.2.0")] public class AxisMinorSplitLine : BaseLine { [SerializeField] private float m_Distance; diff --git a/Runtime/Component/Axis/AxisMinorTick.cs b/Runtime/Component/Axis/AxisMinorTick.cs index 67e16f48..f8f3fc5e 100644 --- a/Runtime/Component/Axis/AxisMinorTick.cs +++ b/Runtime/Component/Axis/AxisMinorTick.cs @@ -4,7 +4,7 @@ namespace XCharts.Runtime { /// /// Settings related to axis minor tick. - /// |坐标轴次刻度相关设置。注意:次刻度无法再类目轴中使用。 + /// |坐标轴次刻度相关设置。注意:次刻度无法在类目轴中使用。 /// [System.Serializable] [Since("v3.2.0")] From 4f9362866778ded87e0bb70f843c5638775048c8 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 25 Jul 2022 07:46:03 +0800 Subject: [PATCH 06/27] [feature][serie] support EmphasisStle,BlurStyle and SelectStyle --- CHANGELOG.md | 4 + Documentation/XChartsAPI-EN.md | 36 +- Documentation/XChartsAPI-ZH.md | 36 +- Documentation/XChartsConfiguration-EN.md | 97 ++-- Documentation/XChartsConfiguration-ZH.md | 97 ++-- Editor/ChildComponents/AreaStyleDrawer.cs | 2 - Editor/ChildComponents/EmphasisStyleDrawer.cs | 43 -- Editor/ChildComponents/StateStyleDrawer.cs | 54 +++ .../ChildComponents/StateStyleDrawer.cs.meta | 2 +- Editor/Series/SerieEditor.cs | 7 +- Examples/Example60_Heatmap.cs | 8 +- Runtime/Component/Child/AreaStyle.cs | 20 - .../Component/Emphasis/EmphasisItemStyle.cs | 11 - .../Component/Emphasis/EmphasisLabelLine.cs | 11 - .../Component/Emphasis/EmphasisLabelStyle.cs | 11 - .../Emphasis/EmphasisLabelStyle.cs.meta | 11 - Runtime/Component/Mark/MarkAreaHandler.cs | 2 +- Runtime/Component/Mark/MarkLineHandler.cs | 8 +- .../Component/{Emphasis.meta => State.meta} | 2 +- Runtime/Component/State/BlurStyle.cs | 13 + .../Component/State/BlurStyle.cs.meta | 2 +- Runtime/Component/State/EmphasisStyle.cs | 90 ++++ .../EmphasisStyle.cs.meta} | 2 +- Runtime/Component/State/SelectStyle.cs | 13 + .../SelectStyle.cs.meta} | 2 +- .../Emphasis.cs => State/StateStyle.cs} | 55 ++- Runtime/Component/State/StateStyle.cs.meta | 11 + Runtime/Internal/BaseChart.API.cs | 22 +- Runtime/Internal/Basic/BaseSerie.cs | 31 +- Runtime/Internal/Basic/ChildComponent.cs | 22 + Runtime/Internal/Utilities/ChartHelper.cs | 16 + Runtime/Serie/Bar/Bar.cs | 4 +- Runtime/Serie/Bar/BarHandler.cs | 38 +- Runtime/Serie/Bar/SimplifiedBarHandler.cs | 26 +- Runtime/Serie/Candlestick/Candlestick.cs | 2 +- .../Serie/Candlestick/CandlestickHandler.cs | 6 +- .../SimplifiedCandlestickHandler.cs | 2 +- Runtime/Serie/Heatmap/Heatmap.cs | 11 +- Runtime/Serie/Heatmap/HeatmapHandler.cs | 7 +- Runtime/Serie/Line/Line.cs | 12 +- Runtime/Serie/Line/LineHandler.GridCoord.cs | 14 +- Runtime/Serie/Line/LineHandler.PolarCoord.cs | 15 +- Runtime/Serie/Line/LineHelper.cs | 10 +- Runtime/Serie/Parallel/Parallel.cs | 2 +- Runtime/Serie/Parallel/ParallelHandler.cs | 2 +- Runtime/Serie/Pie/Pie.cs | 4 +- Runtime/Serie/Pie/PieHandler.cs | 15 +- Runtime/Serie/Radar/Radar.cs | 4 +- Runtime/Serie/Radar/RadarHandler.cs | 82 ++-- Runtime/Serie/Ring/Ring.cs | 4 +- Runtime/Serie/Ring/RingHandler.cs | 20 +- Runtime/Serie/Scatter/BaseScatterHandler.cs | 27 +- Runtime/Serie/Scatter/EffectScatter.cs | 4 +- Runtime/Serie/Scatter/Scatter.cs | 4 +- Runtime/Serie/Serie.ExtraComponent.cs | 39 +- Runtime/Serie/Serie.cs | 104 +++-- Runtime/Serie/SerieContext.cs | 8 +- Runtime/Serie/SerieData.cs | 133 +++--- Runtime/Serie/SerieHandler.cs | 26 +- Runtime/Serie/SerieHelper.cs | 440 ++++++++++-------- Runtime/Serie/SeriesHelper.cs | 4 +- 61 files changed, 1052 insertions(+), 758 deletions(-) delete mode 100644 Editor/ChildComponents/EmphasisStyleDrawer.cs create mode 100644 Editor/ChildComponents/StateStyleDrawer.cs rename Runtime/Component/Emphasis/Emphasis.cs.meta => Editor/ChildComponents/StateStyleDrawer.cs.meta (83%) delete mode 100644 Runtime/Component/Emphasis/EmphasisItemStyle.cs delete mode 100644 Runtime/Component/Emphasis/EmphasisLabelLine.cs delete mode 100644 Runtime/Component/Emphasis/EmphasisLabelStyle.cs delete mode 100644 Runtime/Component/Emphasis/EmphasisLabelStyle.cs.meta rename Runtime/Component/{Emphasis.meta => State.meta} (77%) create mode 100644 Runtime/Component/State/BlurStyle.cs rename Editor/ChildComponents/EmphasisStyleDrawer.cs.meta => Runtime/Component/State/BlurStyle.cs.meta (83%) create mode 100644 Runtime/Component/State/EmphasisStyle.cs rename Runtime/Component/{Emphasis/EmphasisLabelLine.cs.meta => State/EmphasisStyle.cs.meta} (83%) create mode 100644 Runtime/Component/State/SelectStyle.cs rename Runtime/Component/{Emphasis/EmphasisItemStyle.cs.meta => State/SelectStyle.cs.meta} (83%) rename Runtime/Component/{Emphasis/Emphasis.cs => State/StateStyle.cs} (50%) create mode 100644 Runtime/Component/State/StateStyle.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e2ad00..d2153382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,10 @@ ## master +* (2022.07.24) 增加`Serie`和`SerieData`的`state`设置默认状态 +* (2022.07.22) 增加`Serie`的三种状态`EmphasisStyle`,`BlurStyle`,`SelectStyle` +* (2022.07.22) 去掉`AreaStyle`的`m_HighlightColor`和`m_HighlightToColor`配置 +* (2022.07.22) 去掉`Emphasis`,`EmphasisItemStyle`,`EmphasisLabelStyle`,`EmphasisLabelLine`组件 * (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持 * (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 * (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线 diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md index ea59ea32..3db0e1bb 100644 --- a/Documentation/XChartsAPI-EN.md +++ b/Documentation/XChartsAPI-EN.md @@ -190,8 +190,9 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `GetDataZoomOfSerie()` |public void GetDataZoomOfSerie(Serie serie, out DataZoom xDataZoom, out DataZoom yDataZoom)
| | `GetGrid()` |public GridCoord GetGrid(Vector2 local)
| | `GetGridOfDataZoom()` |public GridCoord GetGridOfDataZoom(DataZoom dataZoom)
| -| `GetItemColor()` |public Color32 GetItemColor(Serie serie, bool highlight = false)
| -| `GetItemColor()` |public Color32 GetItemColor(Serie serie, SerieData serieData, bool highlight = false)
| +| `GetItemColor()` |public Color32 GetItemColor(Serie serie)
| +| `GetItemColor()` |public Color32 GetItemColor(Serie serie, SerieData serieData)
| +| `GetItemColor()` |public Color32 GetItemColor(Serie serie, SerieData serieData, int colorIndex)
| | `GetLegendRealShowNameColor()` |public Color32 GetLegendRealShowNameColor(string name)
| | `GetLegendRealShowNameIndex()` |public int GetLegendRealShowNameIndex(string name)
| | `GetPainter()` |public Painter GetPainter(int index)
| @@ -340,6 +341,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `DestroyAllChildren()` |public static void DestroyAllChildren(Transform parent)
| | `GetActualValue()` |public static float GetActualValue(float valueOrRate, float total, float maxRate = 1.5f)
| | `GetAngle360()` |public static float GetAngle360(Vector2 from, Vector2 to)
获得0-360的角度(12点钟方向为0度) | +| `GetBlurColor()` |public static Color32 GetBlurColor(Color32 color, float a = 0.3f)
| | `GetColor()` |public static Color32 GetColor(string hexColorStr)
| | `GetDire()` |public static Vector3 GetDire(float angle, bool isDegree = false)
| | `GetFloatAccuracy()` |public static int GetFloatAccuracy(double value)
| @@ -353,6 +355,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `GetPointList()` |public static void GetPointList(ref List posList, Vector3 sp, Vector3 ep, float k = 30f)
| | `GetPos()` |public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false)
| | `GetPosition()` |public static Vector3 GetPosition(Vector3 center, float angle, float radius)
| +| `GetSelectColor()` |public static Color32 GetSelectColor(Color32 color, float rate = 0.7f)
| | `GetVertialDire()` |public static Vector3 GetVertialDire(Vector3 dire)
| | `HideAllObject()` |public static void HideAllObject(GameObject obj, string match = null)
| | `HideAllObject()` |public static void HideAllObject(Transform parent, string match = null)
| @@ -828,18 +831,15 @@ Inherits or Implemented: [Attribute](#Attribute) |--|--| | `CopySerie()` |public static void CopySerie(Serie oldSerie, Serie newSerie)
| | `GetAllMinMaxData()` |public static void GetAllMinMaxData(Serie serie, double ceilRate = 0, DataZoom dataZoom = null)
| -| `GetAreaColor()` |public static Color32 GetAreaColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetAreaStyle()` |public static AreaStyle GetAreaStyle(Serie serie, SerieData serieData)
| -| `GetAreaToColor()` |public static Color32 GetAreaToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetAverageData()` |public static double GetAverageData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| -| `GetItemColor()` |public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true)
| -| `GetItemColor0()` |public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor)
| +| `GetBlurStyle()` |public static BlurStyle GetBlurStyle(Serie serie, SerieData serieData)
| +| `GetEmphasisStyle()` |public static EmphasisStyle GetEmphasisStyle(Serie serie, SerieData serieData)
| +| `GetItemColor()` |public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto, bool opacity = true)
| | `GetItemFormatter()` |public static string GetItemFormatter(Serie serie, SerieData serieData, string defaultFormatter = null)
| | `GetItemMarker()` |public static string GetItemMarker(Serie serie, SerieData serieData, string defaultMarker = null)
| -| `GetItemStyle()` |public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
| -| `GetItemStyleEmphasis()` |public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
| -| `GetItemToColor()` |public static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true)
| -| `GetLineColor()` |public static Color32 GetLineColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| +| `GetItemStyle()` |public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetLineColor()` |public static Color32 GetLineColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto)
| | `GetLineStyle()` |public static LineStyle GetLineStyle(Serie serie, SerieData serieData)
| | `GetMaxData()` |public static double GetMaxData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| | `GetMaxSerieData()` |public static SerieData GetMaxSerieData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| @@ -848,14 +848,16 @@ Inherits or Implemented: [Attribute](#Attribute) | `GetMinMaxData()` |public static void GetMinMaxData(Serie serie, out double min, out double max, DataZoom dataZoom = null, int dimension = 0)
Gets the maximum and minimum values of all data in the serie. | | `GetMinSerieData()` |public static SerieData GetMinSerieData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| | `GetNumericFormatter()` |public static string GetNumericFormatter(Serie serie, SerieData serieData, string defaultFormatter = null)
| -| `GetSerieEmphasisLabel()` |public static LabelStyle GetSerieEmphasisLabel(Serie serie, SerieData serieData)
| -| `GetSerieLabel()` |public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
| -| `GetSerieLabelLine()` |public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, bool highlight = false)
| +| `GetSelectStyle()` |public static SelectStyle GetSelectStyle(Serie serie, SerieData serieData)
| +| `GetSerieLabel()` |public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetSerieLabelLine()` |public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetSerieState()` |public static SerieState GetSerieState(Serie serie)
| +| `GetSerieState()` |public static SerieState GetSerieState(Serie serie, SerieData serieData)
| | `GetSerieSymbol()` |public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
| -| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight)
| -| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, float defaultWidth)
| -| `GetSymbolBorderColor()` |public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight)
| -| `GetSymbolCornerRadius()` |public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
| +| `GetStateStyle()` |public static StateStyle GetStateStyle(Serie serie, SerieData serieData, SerieState state)
| +| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| +| `GetSymbolBorderColor()` |public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| +| `GetSymbolCornerRadius()` |public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetTitleStyle()` |public static TitleStyle GetTitleStyle(Serie serie, SerieData serieData)
| | `IsAllZeroValue()` |public static bool IsAllZeroValue(Serie serie, int dimension = 1)
Whether the data for the specified dimension of serie are all 0. | | `IsDownPoint()` |public static bool IsDownPoint(Serie serie, int index)
| diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md index 9d8218e4..abf352a5 100644 --- a/Documentation/XChartsAPI-ZH.md +++ b/Documentation/XChartsAPI-ZH.md @@ -190,8 +190,9 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `GetDataZoomOfSerie()` |public void GetDataZoomOfSerie(Serie serie, out DataZoom xDataZoom, out DataZoom yDataZoom)
| | `GetGrid()` |public GridCoord GetGrid(Vector2 local)
| | `GetGridOfDataZoom()` |public GridCoord GetGridOfDataZoom(DataZoom dataZoom)
| -| `GetItemColor()` |public Color32 GetItemColor(Serie serie, bool highlight = false)
| -| `GetItemColor()` |public Color32 GetItemColor(Serie serie, SerieData serieData, bool highlight = false)
| +| `GetItemColor()` |public Color32 GetItemColor(Serie serie)
| +| `GetItemColor()` |public Color32 GetItemColor(Serie serie, SerieData serieData)
| +| `GetItemColor()` |public Color32 GetItemColor(Serie serie, SerieData serieData, int colorIndex)
| | `GetLegendRealShowNameColor()` |public Color32 GetLegendRealShowNameColor(string name)
| | `GetLegendRealShowNameIndex()` |public int GetLegendRealShowNameIndex(string name)
| | `GetPainter()` |public Painter GetPainter(int index)
| @@ -340,6 +341,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `DestroyAllChildren()` |public static void DestroyAllChildren(Transform parent)
| | `GetActualValue()` |public static float GetActualValue(float valueOrRate, float total, float maxRate = 1.5f)
| | `GetAngle360()` |public static float GetAngle360(Vector2 from, Vector2 to)
获得0-360的角度(12点钟方向为0度) | +| `GetBlurColor()` |public static Color32 GetBlurColor(Color32 color, float a = 0.3f)
| | `GetColor()` |public static Color32 GetColor(string hexColorStr)
| | `GetDire()` |public static Vector3 GetDire(float angle, bool isDegree = false)
| | `GetFloatAccuracy()` |public static int GetFloatAccuracy(double value)
| @@ -353,6 +355,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `GetPointList()` |public static void GetPointList(ref List posList, Vector3 sp, Vector3 ep, float k = 30f)
| | `GetPos()` |public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false)
| | `GetPosition()` |public static Vector3 GetPosition(Vector3 center, float angle, float radius)
| +| `GetSelectColor()` |public static Color32 GetSelectColor(Color32 color, float rate = 0.7f)
| | `GetVertialDire()` |public static Vector3 GetVertialDire(Vector3 dire)
| | `HideAllObject()` |public static void HideAllObject(GameObject obj, string match = null)
| | `HideAllObject()` |public static void HideAllObject(Transform parent, string match = null)
| @@ -828,18 +831,15 @@ Inherits or Implemented: [Attribute](#Attribute) |--|--| | `CopySerie()` |public static void CopySerie(Serie oldSerie, Serie newSerie)
| | `GetAllMinMaxData()` |public static void GetAllMinMaxData(Serie serie, double ceilRate = 0, DataZoom dataZoom = null)
| -| `GetAreaColor()` |public static Color32 GetAreaColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetAreaStyle()` |public static AreaStyle GetAreaStyle(Serie serie, SerieData serieData)
| -| `GetAreaToColor()` |public static Color32 GetAreaToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetAverageData()` |public static double GetAverageData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| -| `GetItemColor()` |public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true)
| -| `GetItemColor0()` |public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor)
| +| `GetBlurStyle()` |public static BlurStyle GetBlurStyle(Serie serie, SerieData serieData)
| +| `GetEmphasisStyle()` |public static EmphasisStyle GetEmphasisStyle(Serie serie, SerieData serieData)
| +| `GetItemColor()` |public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto, bool opacity = true)
| | `GetItemFormatter()` |public static string GetItemFormatter(Serie serie, SerieData serieData, string defaultFormatter = null)
| | `GetItemMarker()` |public static string GetItemMarker(Serie serie, SerieData serieData, string defaultMarker = null)
| -| `GetItemStyle()` |public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
| -| `GetItemStyleEmphasis()` |public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
| -| `GetItemToColor()` |public static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true)
| -| `GetLineColor()` |public static Color32 GetLineColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| +| `GetItemStyle()` |public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetLineColor()` |public static Color32 GetLineColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto)
| | `GetLineStyle()` |public static LineStyle GetLineStyle(Serie serie, SerieData serieData)
| | `GetMaxData()` |public static double GetMaxData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| | `GetMaxSerieData()` |public static SerieData GetMaxSerieData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| @@ -848,14 +848,16 @@ Inherits or Implemented: [Attribute](#Attribute) | `GetMinMaxData()` |public static void GetMinMaxData(Serie serie, out double min, out double max, DataZoom dataZoom = null, int dimension = 0)
获得系列所有数据的最大最小值。 | | `GetMinSerieData()` |public static SerieData GetMinSerieData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| | `GetNumericFormatter()` |public static string GetNumericFormatter(Serie serie, SerieData serieData, string defaultFormatter = null)
| -| `GetSerieEmphasisLabel()` |public static LabelStyle GetSerieEmphasisLabel(Serie serie, SerieData serieData)
| -| `GetSerieLabel()` |public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
| -| `GetSerieLabelLine()` |public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, bool highlight = false)
| +| `GetSelectStyle()` |public static SelectStyle GetSelectStyle(Serie serie, SerieData serieData)
| +| `GetSerieLabel()` |public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetSerieLabelLine()` |public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetSerieState()` |public static SerieState GetSerieState(Serie serie)
| +| `GetSerieState()` |public static SerieState GetSerieState(Serie serie, SerieData serieData)
| | `GetSerieSymbol()` |public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
| -| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight)
| -| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, float defaultWidth)
| -| `GetSymbolBorderColor()` |public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight)
| -| `GetSymbolCornerRadius()` |public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
| +| `GetStateStyle()` |public static StateStyle GetStateStyle(Serie serie, SerieData serieData, SerieState state)
| +| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| +| `GetSymbolBorderColor()` |public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| +| `GetSymbolCornerRadius()` |public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetTitleStyle()` |public static TitleStyle GetTitleStyle(Serie serie, SerieData serieData)
| | `IsAllZeroValue()` |public static bool IsAllZeroValue(Serie serie, int dimension = 1)
系列指定维数的数据是否全部为0。 | | `IsDownPoint()` |public static bool IsDownPoint(Serie serie, int index)
| diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index f60e4b3c..4fabb276 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -85,14 +85,12 @@ - [AxisTick](#AxisTick) - [BaseAxisTheme](#BaseAxisTheme) - [BaseLine](#BaseLine) +- [BlurStyle](#BlurStyle) - [CommentItem](#CommentItem) - [CommentMarkStyle](#CommentMarkStyle) - [ComponentTheme](#ComponentTheme) - [DataZoomTheme](#DataZoomTheme) -- [Emphasis](#Emphasis) -- [EmphasisItemStyle](#EmphasisItemStyle) -- [EmphasisLabelLine](#EmphasisLabelLine) -- [EmphasisLabelStyle](#EmphasisLabelStyle) +- [EmphasisStyle](#EmphasisStyle) - [EndLabelStyle](#EndLabelStyle) - [IconStyle](#IconStyle) - [ImageStyle](#ImageStyle) @@ -111,10 +109,12 @@ - [PolarAxisTheme](#PolarAxisTheme) - [RadarAxisTheme](#RadarAxisTheme) - [RadiusAxisTheme](#RadiusAxisTheme) +- [SelectStyle](#SelectStyle) - [SerieData](#SerieData) - [SerieSymbol](#SerieSymbol) - [SerieTheme](#SerieTheme) - [StageColor](#StageColor) +- [StateStyle](#StateStyle) - [SubTitleTheme](#SubTitleTheme) - [SymbolStyle](#SymbolStyle) - [TextLimit](#TextLimit) @@ -130,28 +130,26 @@ ## ISerieExtraComponent - [AreaStyle](#AreaStyle) -- [Emphasis](#Emphasis) -- [EmphasisItemStyle](#EmphasisItemStyle) -- [EmphasisLabelLine](#EmphasisLabelLine) -- [EmphasisLabelStyle](#EmphasisLabelStyle) +- [BlurStyle](#BlurStyle) +- [EmphasisStyle](#EmphasisStyle) - [ImageStyle](#ImageStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) - [LineArrow](#LineArrow) +- [SelectStyle](#SelectStyle) - [TitleStyle](#TitleStyle) ## ISerieDataComponent - [AreaStyle](#AreaStyle) -- [Emphasis](#Emphasis) -- [EmphasisItemStyle](#EmphasisItemStyle) -- [EmphasisLabelLine](#EmphasisLabelLine) -- [EmphasisLabelStyle](#EmphasisLabelStyle) +- [BlurStyle](#BlurStyle) +- [EmphasisStyle](#EmphasisStyle) - [ImageStyle](#ImageStyle) - [ItemStyle](#ItemStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) - [LineStyle](#LineStyle) +- [SelectStyle](#SelectStyle) - [SerieSymbol](#SerieSymbol) - [TitleStyle](#TitleStyle) @@ -217,8 +215,6 @@ 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. -|`highlightColor`|||the color of area,default use serie color. -|`highlightToColor`|||Gradient color, start highlightColor to highlightToColor. ## `ArrowStyle` @@ -440,6 +436,15 @@ Inherits or Implemented: [Serie](#Serie),[INeedSerieContainer](#INeedSerieContai ## `BaseSerie` +## `BlurStyle` + +Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) + +> Since `v3.2.0` + +Configurations of blur state. + + ## `CalendarCoord` Inherits or Implemented: [CoordSystem](#CoordSystem),[IUpdateRuntimeData](#IUpdateRuntimeData),[ISerieContainer](#ISerieContainer) @@ -581,39 +586,19 @@ Inherits or Implemented: [ComponentTheme](#ComponentTheme) Inherits or Implemented: [BaseScatter](#BaseScatter) -## `Emphasis` +## `EmphasisStyle` -Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) +Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) -高亮的图形样式和文本标签样式。 +> Since `v3.2.0` + +Configurations of emphasis state. |field|default|since|comment| |--|--|--|--| -|`show`|||是否启用高亮样式。 -|`label`|||图形文本标签。 [LabelStyle](#LabelStyle)| -|`labelLine`|||图形文本引导线样式。 [LabelLine](#LabelLine)| -|`itemStyle`|||图形样式。 [ItemStyle](#ItemStyle)| - -## `EmphasisItemStyle` - -Inherits or Implemented: [ItemStyle](#ItemStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) - -高亮的图形样式 - - -## `EmphasisLabelLine` - -Inherits or Implemented: [LabelLine](#LabelLine),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) - -高亮的标签引导线样式 - - -## `EmphasisLabelStyle` - -Inherits or Implemented: [LabelStyle](#LabelStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) - -高亮的标签样式 - +|`scale`|1.1f||Whether to scale to highlight the data in emphasis state. 高亮时的缩放倍数。 +|`focus`|||When the data is highlighted, whether to fade out of other data to focus the highlighted.
`EmphasisStyle.FocusType`:
- `None`: Do not fade out other data, it's by default.
- `Self`: Only focus (not fade out) the element of the currently highlighted data.
- `Series`: Focus on all elements of the series which the currently highlighted data belongs to.
| +|`blurScope`|||The range of fade out when focus is enabled.
`EmphasisStyle.BlurScope`:
- `GridCoord`: coordinate system.
- `Series`: series.
- `Global`: global.
| ## `EndLabelStyle` @@ -1063,6 +1048,15 @@ Inherits or Implemented: [Serie](#Serie) Inherits or Implemented: [BaseScatter](#BaseScatter) +## `SelectStyle` + +Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) + +> Since `v3.2.0` + +Configurations of select state. + + ## `Serie` Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) @@ -1076,6 +1070,7 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) |`coordSystem`|||the chart coord system of serie. |`serieType`|||the type of serie. |`serieName`|||Series name used for displaying in tooltip and filtering with legend. +|`state`||v3.2.0|The default state of a serie.
`SerieState`:
- `Normal`: Normal state.
- `Emphasis`: Emphasis state.
- `Blur`: Blur state.
- `Select`: Select state.
- `Auto`: Auto state.
| |`stack`|||If stack the value. On the same category axis, the series with the same stack name would be put on top of each other. |`xAxisIndex`|0||the index of XAxis. |`yAxisIndex`|0||the index of YAxis. @@ -1153,6 +1148,7 @@ A data item of serie. |`ignore`|||是否忽略数据。当为 true 时,数据不进行绘制。 |`selected`|||Whether the data item is selected. |`radius`|||自定义半径。可用在饼图中自定义某个数据项的半径。 +|`state`||v3.2.0|the state of serie data.
`SerieState`:
- `Normal`: Normal state.
- `Emphasis`: Emphasis state.
- `Blur`: Blur state.
- `Select`: Select state.
- `Auto`: Auto state.
| |`data`|||An arbitrary dimension data list of data item. ## `SerieSymbol` @@ -1261,6 +1257,23 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) |`percent`|||结束位置百分比。 |`color`|||颜色。 +## `StateStyle` + +Inherits or Implemented: [ChildComponent](#ChildComponent) + +> Since `v3.2.0` + +the state style of serie. + +|field|default|since|comment| +|--|--|--|--| +|`show`|true||是否启用高亮样式。 +|`label`|||图形文本标签。 [LabelStyle](#LabelStyle)| +|`labelLine`|||图形文本引导线样式。 [LabelLine](#LabelLine)| +|`itemStyle`|||图形样式。 [ItemStyle](#ItemStyle)| +|`lineStyle`|||折线样式。 [LineStyle](#LineStyle)| +|`areaStyle`|||区域样式。 [AreaStyle](#AreaStyle)| + ## `SubTitleTheme` Inherits or Implemented: [ComponentTheme](#ComponentTheme) diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index 2de92c74..54869840 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -85,14 +85,12 @@ - [AxisTick](#AxisTick) - [BaseAxisTheme](#BaseAxisTheme) - [BaseLine](#BaseLine) +- [BlurStyle](#BlurStyle) - [CommentItem](#CommentItem) - [CommentMarkStyle](#CommentMarkStyle) - [ComponentTheme](#ComponentTheme) - [DataZoomTheme](#DataZoomTheme) -- [Emphasis](#Emphasis) -- [EmphasisItemStyle](#EmphasisItemStyle) -- [EmphasisLabelLine](#EmphasisLabelLine) -- [EmphasisLabelStyle](#EmphasisLabelStyle) +- [EmphasisStyle](#EmphasisStyle) - [EndLabelStyle](#EndLabelStyle) - [IconStyle](#IconStyle) - [ImageStyle](#ImageStyle) @@ -111,10 +109,12 @@ - [PolarAxisTheme](#PolarAxisTheme) - [RadarAxisTheme](#RadarAxisTheme) - [RadiusAxisTheme](#RadiusAxisTheme) +- [SelectStyle](#SelectStyle) - [SerieData](#SerieData) - [SerieSymbol](#SerieSymbol) - [SerieTheme](#SerieTheme) - [StageColor](#StageColor) +- [StateStyle](#StateStyle) - [SubTitleTheme](#SubTitleTheme) - [SymbolStyle](#SymbolStyle) - [TextLimit](#TextLimit) @@ -130,28 +130,26 @@ ## ISerieExtraComponent Serie额外组件 - [AreaStyle](#AreaStyle) -- [Emphasis](#Emphasis) -- [EmphasisItemStyle](#EmphasisItemStyle) -- [EmphasisLabelLine](#EmphasisLabelLine) -- [EmphasisLabelStyle](#EmphasisLabelStyle) +- [BlurStyle](#BlurStyle) +- [EmphasisStyle](#EmphasisStyle) - [ImageStyle](#ImageStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) - [LineArrow](#LineArrow) +- [SelectStyle](#SelectStyle) - [TitleStyle](#TitleStyle) ## ISerieDataComponent SerieData额外组件 - [AreaStyle](#AreaStyle) -- [Emphasis](#Emphasis) -- [EmphasisItemStyle](#EmphasisItemStyle) -- [EmphasisLabelLine](#EmphasisLabelLine) -- [EmphasisLabelStyle](#EmphasisLabelStyle) +- [BlurStyle](#BlurStyle) +- [EmphasisStyle](#EmphasisStyle) - [ImageStyle](#ImageStyle) - [ItemStyle](#ItemStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) - [LineStyle](#LineStyle) +- [SelectStyle](#SelectStyle) - [SerieSymbol](#SerieSymbol) - [TitleStyle](#TitleStyle) @@ -217,8 +215,6 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent |`color`|||区域填充的颜色,如果toColor不是默认值,则表示渐变色的起点颜色。 |`toColor`|||渐变色的终点颜色。 |`opacity`|0.6f||图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 -|`highlightColor`|||高亮时区域填充的颜色,如果highlightToColor不是默认值,则表示渐变色的起点颜色。 -|`highlightToColor`|||高亮时渐变色的终点颜色。 ## `ArrowStyle` @@ -440,6 +436,15 @@ Inherits or Implemented: [Serie](#Serie),[INeedSerieContainer](#INeedSerieContai ## `BaseSerie` +## `BlurStyle` + +Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) + +> 从 `v3.2.0` 开始支持 + +淡出状态样式。 + + ## `CalendarCoord` Inherits or Implemented: [CoordSystem](#CoordSystem),[IUpdateRuntimeData](#IUpdateRuntimeData),[ISerieContainer](#ISerieContainer) @@ -581,39 +586,19 @@ Inherits or Implemented: [ComponentTheme](#ComponentTheme) Inherits or Implemented: [BaseScatter](#BaseScatter) -## `Emphasis` +## `EmphasisStyle` -Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) +Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) -高亮的图形样式和文本标签样式。 +> 从 `v3.2.0` 开始支持 + +高亮状态样式。 |field|default|since|comment| |--|--|--|--| -|`show`|||是否启用高亮样式。 -|`label`|||图形文本标签。 [LabelStyle](#LabelStyle)| -|`labelLine`|||图形文本引导线样式。 [LabelLine](#LabelLine)| -|`itemStyle`|||图形样式。 [ItemStyle](#ItemStyle)| - -## `EmphasisItemStyle` - -Inherits or Implemented: [ItemStyle](#ItemStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) - -高亮的图形样式 - - -## `EmphasisLabelLine` - -Inherits or Implemented: [LabelLine](#LabelLine),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) - -高亮的标签引导线样式 - - -## `EmphasisLabelStyle` - -Inherits or Implemented: [LabelStyle](#LabelStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) - -高亮的标签样式 - +|`scale`|1.1f||Whether to scale to highlight the data in emphasis state. 高亮时的缩放倍数。 +|`focus`|||在高亮图形时,是否淡出其它数据的图形已达到聚焦的效果。
`EmphasisStyle.FocusType`:
- `None`: 不淡出其它图形,默认使用该配置。
- `Self`: 只聚焦(不淡出)当前高亮的数据的图形。
- `Series`: 聚焦当前高亮的数据所在的系列的所有图形。
| +|`blurScope`|||在开启focus的时候,可以通过blurScope配置淡出的范围。
`EmphasisStyle.BlurScope`:
- `GridCoord`: 淡出范围为坐标系,默认使用该配置。
- `Series`: 淡出范围为系列。
- `Global`: 淡出范围为全局。
| ## `EndLabelStyle` @@ -1063,6 +1048,15 @@ Inherits or Implemented: [Serie](#Serie) Inherits or Implemented: [BaseScatter](#BaseScatter) +## `SelectStyle` + +Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) + +> 从 `v3.2.0` 开始支持 + +选中状态样式。 + + ## `Serie` Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) @@ -1076,6 +1070,7 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) |`coordSystem`|||使用的坐标系。 |`serieType`|||系列类型。 |`serieName`|||系列名称,用于 tooltip 的显示,legend 的图例筛选。 +|`state`||v3.2.0|系列的默认状态。
`SerieState`:
- `Normal`: 正常状态。
- `Emphasis`: 高亮状态。
- `Blur`: 淡出状态。
- `Select`: 选中状态。
- `Auto`: 自动保持和父节点一致。一般用在SerieData。
| |`stack`|||数据堆叠,同个类目轴上系列配置相同的stack值后,后一个系列的值会在前一个系列的值上相加。 |`xAxisIndex`|0||使用X轴的index。 |`yAxisIndex`|0||使用Y轴的index。 @@ -1153,6 +1148,7 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) |`ignore`|||是否忽略数据。当为 true 时,数据不进行绘制。 |`selected`|||该数据项是否被选中。 |`radius`|||自定义半径。可用在饼图中自定义某个数据项的半径。 +|`state`||v3.2.0|数据项的默认状态。
`SerieState`:
- `Normal`: 正常状态。
- `Emphasis`: 高亮状态。
- `Blur`: 淡出状态。
- `Select`: 选中状态。
- `Auto`: 自动保持和父节点一致。一般用在SerieData。
| |`data`|||可指定任意维数的数值列表。 ## `SerieSymbol` @@ -1261,6 +1257,23 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) |`percent`|||结束位置百分比。 |`color`|||颜色。 +## `StateStyle` + +Inherits or Implemented: [ChildComponent](#ChildComponent) + +> 从 `v3.2.0` 开始支持 + +Serie的状态样式。Serie的状态有正常,高亮,淡出,选中四种状态。 + +|field|default|since|comment| +|--|--|--|--| +|`show`|true||是否启用高亮样式。 +|`label`|||图形文本标签。 [LabelStyle](#LabelStyle)| +|`labelLine`|||图形文本引导线样式。 [LabelLine](#LabelLine)| +|`itemStyle`|||图形样式。 [ItemStyle](#ItemStyle)| +|`lineStyle`|||折线样式。 [LineStyle](#LineStyle)| +|`areaStyle`|||区域样式。 [AreaStyle](#AreaStyle)| + ## `SubTitleTheme` Inherits or Implemented: [ComponentTheme](#ComponentTheme) diff --git a/Editor/ChildComponents/AreaStyleDrawer.cs b/Editor/ChildComponents/AreaStyleDrawer.cs index 25aa9bc5..f586e226 100644 --- a/Editor/ChildComponents/AreaStyleDrawer.cs +++ b/Editor/ChildComponents/AreaStyleDrawer.cs @@ -17,8 +17,6 @@ namespace XCharts.Editor PropertyField(prop, "m_Origin"); PropertyField(prop, "m_Color"); PropertyField(prop, "m_ToColor"); - PropertyField(prop, "m_HighlightColor"); - PropertyField(prop, "m_HighlightToColor"); PropertyField(prop, "m_Opacity"); --EditorGUI.indentLevel; } diff --git a/Editor/ChildComponents/EmphasisStyleDrawer.cs b/Editor/ChildComponents/EmphasisStyleDrawer.cs deleted file mode 100644 index 89377f3d..00000000 --- a/Editor/ChildComponents/EmphasisStyleDrawer.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; -using XCharts.Runtime; - -namespace XCharts.Editor -{ - [CustomPropertyDrawer(typeof(Emphasis), true)] - public class EmphasisDrawer : BasePropertyDrawer - { - public override string ClassName { get { return "Emphasis"; } } - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show", true)) - { - ++EditorGUI.indentLevel; - PropertyField(prop, "m_Label"); - PropertyField(prop, "m_LabelLine"); - PropertyField(prop, "m_ItemStyle"); - --EditorGUI.indentLevel; - } - } - } - - [CustomPropertyDrawer(typeof(EmphasisItemStyle), true)] - public class EmphasisItemStyleDrawer : ItemStyleDrawer - { - public override string ClassName { get { return "EmphasisItemStyle"; } } - } - - [CustomPropertyDrawer(typeof(EmphasisLabelStyle), true)] - public class EmphasisLabelStyleDrawer : LabelStyleDrawer - { - public override string ClassName { get { return "EmphasisLabel"; } } - } - - [CustomPropertyDrawer(typeof(EmphasisLabelLine), true)] - public class EmphasisLabelLineDrawer : LabelLineDrawer - { - public override string ClassName { get { return "EmphasisLabelLine"; } } - } -} \ No newline at end of file diff --git a/Editor/ChildComponents/StateStyleDrawer.cs b/Editor/ChildComponents/StateStyleDrawer.cs new file mode 100644 index 00000000..ca0f746e --- /dev/null +++ b/Editor/ChildComponents/StateStyleDrawer.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using XCharts.Runtime; + +namespace XCharts.Editor +{ + [CustomPropertyDrawer(typeof(StateStyle), true)] + public class StateStyleDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "StateStyle"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeComponentFoldout(prop, "m_Show", true)) + { + ++EditorGUI.indentLevel; + OnCustomGUI(prop); + PropertyField(prop, "m_ItemStyle"); + PropertyField(prop, "m_Label"); + PropertyField(prop, "m_LabelLine"); + PropertyField(prop, "m_LineStyle"); + PropertyField(prop, "m_AreaStyle"); + --EditorGUI.indentLevel; + } + } + + protected virtual void OnCustomGUI(SerializedProperty prop) { } + } + + [CustomPropertyDrawer(typeof(EmphasisStyle), true)] + public class EmphasisStyleDrawer : StateStyleDrawer + { + public override string ClassName { get { return "EmphasisStyle"; } } + protected override void OnCustomGUI(SerializedProperty prop) + { + PropertyField(prop, "m_Scale"); + PropertyField(prop, "m_Focus"); + PropertyField(prop, "m_BlurScope"); + } + } + + [CustomPropertyDrawer(typeof(BlurStyle), true)] + public class BlurStyleDrawer : StateStyleDrawer + { + public override string ClassName { get { return "BlurStyle"; } } + } + + [CustomPropertyDrawer(typeof(SelectStyle), true)] + public class SelectStyleDrawer : StateStyleDrawer + { + public override string ClassName { get { return "SelectStyle"; } } + } +} \ No newline at end of file diff --git a/Runtime/Component/Emphasis/Emphasis.cs.meta b/Editor/ChildComponents/StateStyleDrawer.cs.meta similarity index 83% rename from Runtime/Component/Emphasis/Emphasis.cs.meta rename to Editor/ChildComponents/StateStyleDrawer.cs.meta index 8aeb0946..38f810f7 100644 --- a/Runtime/Component/Emphasis/Emphasis.cs.meta +++ b/Editor/ChildComponents/StateStyleDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6e0b1690532674b24952a87e0aead6fa +guid: 3aad8ee99115742729ec5a963274fae0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/Series/SerieEditor.cs b/Editor/Series/SerieEditor.cs index 9b410ea8..1d07a793 100644 --- a/Editor/Series/SerieEditor.cs +++ b/Editor/Series/SerieEditor.cs @@ -16,7 +16,6 @@ namespace XCharts.Editor public override void OnInspectorGUI() { ++EditorGUI.indentLevel; - //PropertyField("m_InsertDataToHead"); PropertyField("m_SerieName"); if (m_CoordOptionsNames != null && m_CoordOptionsNames.Count > 1) { @@ -28,6 +27,7 @@ namespace XCharts.Editor serie.coordSystem = m_CoordOptionsDic[typeName].Name; } } + PropertyField("m_State"); OnCustomInspectorGUI(); OnExtraInspectorGUI(); PropertyFieldData(); @@ -189,9 +189,8 @@ namespace XCharts.Editor { EditorGUI.indentLevel++; var serieData = m_Datas.GetArrayElementAtIndex(index); - var m_Name = serieData.FindPropertyRelative("m_Name"); - - PropertyField(m_Name); + PropertyField(serieData.FindPropertyRelative("m_Name")); + PropertyField(serieData.FindPropertyRelative("m_State")); if (serie.GetType().IsDefined(typeof(SerieDataExtraFieldAttribute), false)) { var attribute = serie.GetType().GetAttribute(); diff --git a/Examples/Example60_Heatmap.cs b/Examples/Example60_Heatmap.cs index 96273243..2e89d4c3 100644 --- a/Examples/Example60_Heatmap.cs +++ b/Examples/Example60_Heatmap.cs @@ -47,10 +47,10 @@ namespace XCharts.Example serie.itemStyle.borderColor = Color.clear; //设置高亮样式 - serie.AddExtraComponent(); - serie.emphasisItemStyle.show = true; - serie.emphasisItemStyle.borderWidth = 1; - serie.emphasisItemStyle.borderColor = Color.black; + var emphasisStyle = serie.AddExtraComponent(); + emphasisStyle.itemStyle.show = true; + emphasisStyle.itemStyle.borderWidth = 1; + emphasisStyle.itemStyle.borderColor = Color.black; //设置视觉映射组件 var visualMap = chart.GetChartComponent(); diff --git a/Runtime/Component/Child/AreaStyle.cs b/Runtime/Component/Child/AreaStyle.cs index f7d1e0a4..a035f95a 100644 --- a/Runtime/Component/Child/AreaStyle.cs +++ b/Runtime/Component/Child/AreaStyle.cs @@ -37,8 +37,6 @@ namespace XCharts.Runtime [SerializeField] private Color32 m_Color; [SerializeField] private Color32 m_ToColor; [SerializeField][Range(0, 1)] private float m_Opacity = 0.6f; - [SerializeField] private Color32 m_HighlightColor; - [SerializeField] private Color32 m_HighlightToColor; /// /// Set this to false to prevent the areafrom showing. @@ -85,24 +83,6 @@ namespace XCharts.Runtime get { return m_Opacity; } set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } - /// - /// the color of area,default use serie color. - /// |高亮时区域填充的颜色,如果highlightToColor不是默认值,则表示渐变色的起点颜色。 - /// - public Color32 highlightColor - { - get { return m_HighlightColor; } - set { if (PropertyUtil.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); } - } - /// - /// Gradient color, start highlightColor to highlightToColor. - /// |高亮时渐变色的终点颜色。 - /// - public Color32 highlightToColor - { - get { return m_HighlightToColor; } - set { if (PropertyUtil.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); } - } public Color32 GetColor() { diff --git a/Runtime/Component/Emphasis/EmphasisItemStyle.cs b/Runtime/Component/Emphasis/EmphasisItemStyle.cs deleted file mode 100644 index ca5ad8e4..00000000 --- a/Runtime/Component/Emphasis/EmphasisItemStyle.cs +++ /dev/null @@ -1,11 +0,0 @@ -using UnityEngine; - -namespace XCharts.Runtime -{ - /// - /// 高亮的图形样式 - /// - [System.Serializable] - public class EmphasisItemStyle : ItemStyle, ISerieExtraComponent, ISerieDataComponent - { } -} \ No newline at end of file diff --git a/Runtime/Component/Emphasis/EmphasisLabelLine.cs b/Runtime/Component/Emphasis/EmphasisLabelLine.cs deleted file mode 100644 index 9a132ad9..00000000 --- a/Runtime/Component/Emphasis/EmphasisLabelLine.cs +++ /dev/null @@ -1,11 +0,0 @@ -using UnityEngine; - -namespace XCharts.Runtime -{ - /// - /// 高亮的标签引导线样式 - /// - [System.Serializable] - public class EmphasisLabelLine : LabelLine, ISerieExtraComponent, ISerieDataComponent - { } -} \ No newline at end of file diff --git a/Runtime/Component/Emphasis/EmphasisLabelStyle.cs b/Runtime/Component/Emphasis/EmphasisLabelStyle.cs deleted file mode 100644 index 0279fc6c..00000000 --- a/Runtime/Component/Emphasis/EmphasisLabelStyle.cs +++ /dev/null @@ -1,11 +0,0 @@ -using UnityEngine; - -namespace XCharts.Runtime -{ - /// - /// 高亮的标签样式 - /// - [System.Serializable] - public class EmphasisLabelStyle : LabelStyle, ISerieExtraComponent, ISerieDataComponent - { } -} \ No newline at end of file diff --git a/Runtime/Component/Emphasis/EmphasisLabelStyle.cs.meta b/Runtime/Component/Emphasis/EmphasisLabelStyle.cs.meta deleted file mode 100644 index 77199ddc..00000000 --- a/Runtime/Component/Emphasis/EmphasisLabelStyle.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3e025b0f4be6d4141aa08bdad0102aa7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Mark/MarkAreaHandler.cs b/Runtime/Component/Mark/MarkAreaHandler.cs index f7939418..f4329a68 100644 --- a/Runtime/Component/Mark/MarkAreaHandler.cs +++ b/Runtime/Component/Mark/MarkAreaHandler.cs @@ -62,7 +62,7 @@ namespace XCharts.Runtime UpdateRuntimeData(markArea); var colorIndex = chart.GetLegendRealShowNameIndex(serie.legendName); - var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, false); + var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, SerieState.Normal); var areaColor = markArea.itemStyle.GetColor(serieColor); UGL.DrawRectangle(vh, markArea.runtimeRect, areaColor, areaColor); } diff --git a/Runtime/Component/Mark/MarkLineHandler.cs b/Runtime/Component/Mark/MarkLineHandler.cs index cafbdcf2..813b294e 100644 --- a/Runtime/Component/Mark/MarkLineHandler.cs +++ b/Runtime/Component/Mark/MarkLineHandler.cs @@ -100,7 +100,7 @@ namespace XCharts.Runtime var sp = Vector3.zero; var ep = Vector3.zero; var colorIndex = chart.GetLegendRealShowNameIndex(serie.serieName); - var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, false); + var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, SerieState.Normal); animation.InitProgress(0, 1f); ResetTempMarkLineGroupData(markLine); if (m_TempGroupData.Count > 0) @@ -242,9 +242,9 @@ namespace XCharts.Runtime private void DrawMarkLineSymbol(VertexHelper vh, SymbolStyle symbol, Serie serie, GridCoord grid, ThemeStyle theme, Vector3 pos, Vector3 startPos, Color32 lineColor) { - var tickness = SerieHelper.GetSymbolBorder(serie, null, theme, false); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, null, theme, false); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, null, false); + var tickness = SerieHelper.GetSymbolBorder(serie, null, theme); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, null, theme); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, null); chart.DrawClipSymbol(vh, symbol.type, symbol.size, tickness, pos, lineColor, lineColor, ColorUtil.clearColor32, borderColor, symbol.gap, true, cornerRadius, grid, startPos); } diff --git a/Runtime/Component/Emphasis.meta b/Runtime/Component/State.meta similarity index 77% rename from Runtime/Component/Emphasis.meta rename to Runtime/Component/State.meta index 68dbdad5..1e539fd1 100644 --- a/Runtime/Component/Emphasis.meta +++ b/Runtime/Component/State.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4cd4074bb11fc40059363dd78b9ee98d +guid: ca1088963feb54117bce8be6bceb64de folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Component/State/BlurStyle.cs b/Runtime/Component/State/BlurStyle.cs new file mode 100644 index 00000000..75c0de29 --- /dev/null +++ b/Runtime/Component/State/BlurStyle.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace XCharts.Runtime +{ + /// + /// Configurations of blur state. + /// |淡出状态样式。 + /// + [System.Serializable] + [Since("v3.2.0")] + public class BlurStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent + { } +} \ No newline at end of file diff --git a/Editor/ChildComponents/EmphasisStyleDrawer.cs.meta b/Runtime/Component/State/BlurStyle.cs.meta similarity index 83% rename from Editor/ChildComponents/EmphasisStyleDrawer.cs.meta rename to Runtime/Component/State/BlurStyle.cs.meta index a6cdfc46..545be0c1 100644 --- a/Editor/ChildComponents/EmphasisStyleDrawer.cs.meta +++ b/Runtime/Component/State/BlurStyle.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7de9b5e4c5d474fdd88ebb89f0924305 +guid: 4e3f901db80454f89800a84977289535 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Component/State/EmphasisStyle.cs b/Runtime/Component/State/EmphasisStyle.cs new file mode 100644 index 00000000..e3602d20 --- /dev/null +++ b/Runtime/Component/State/EmphasisStyle.cs @@ -0,0 +1,90 @@ +using UnityEngine; + +namespace XCharts.Runtime +{ + /// + /// Configurations of emphasis state. + /// |高亮状态样式。 + /// + [System.Serializable] + [Since("v3.2.0")] + public class EmphasisStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent + { + /// + /// focus type. + /// |聚焦类型。 + /// + public enum FocusType + { + /// + /// Do not fade out other data, it's by default. + /// |不淡出其它图形,默认使用该配置。 + /// + None, + /// + /// Only focus (not fade out) the element of the currently highlighted data. + /// |只聚焦(不淡出)当前高亮的数据的图形。 + /// + Self, + /// + /// Focus on all elements of the series which the currently highlighted data belongs to. + /// |聚焦当前高亮的数据所在的系列的所有图形。 + /// + Series + } + /// + /// blur scope. + /// |淡出范围。 + /// + public enum BlurScope + { + /// + /// coordinate system. + /// |淡出范围为坐标系,默认使用该配置。 + /// + GridCoord, + /// + /// series. + /// |淡出范围为系列。 + /// + Series, + /// + /// global. + /// |淡出范围为全局。 + /// + Global + } + + [SerializeField] private float m_Scale = 1.1f; + [SerializeField] private FocusType m_Focus = FocusType.None; + [SerializeField] private BlurScope m_BlurScope = BlurScope.GridCoord; + + /// + /// Whether to scale to highlight the data in emphasis state. + /// |高亮时的缩放倍数。 + /// + public float scale + { + get { return m_Scale; } + set { if (PropertyUtil.SetStruct(ref m_Scale, value)) SetVerticesDirty(); } + } + /// + /// When the data is highlighted, whether to fade out of other data to focus the highlighted. + /// |在高亮图形时,是否淡出其它数据的图形已达到聚焦的效果。 + /// + public FocusType focus + { + get { return m_Focus; } + set { if (PropertyUtil.SetStruct(ref m_Focus, value)) SetVerticesDirty(); } + } + /// + /// The range of fade out when focus is enabled. + /// |在开启focus的时候,可以通过blurScope配置淡出的范围。 + /// + public BlurScope blurScope + { + get { return m_BlurScope; } + set { if (PropertyUtil.SetStruct(ref m_BlurScope, value)) SetVerticesDirty(); } + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Emphasis/EmphasisLabelLine.cs.meta b/Runtime/Component/State/EmphasisStyle.cs.meta similarity index 83% rename from Runtime/Component/Emphasis/EmphasisLabelLine.cs.meta rename to Runtime/Component/State/EmphasisStyle.cs.meta index b6bd83fa..c75a637b 100644 --- a/Runtime/Component/Emphasis/EmphasisLabelLine.cs.meta +++ b/Runtime/Component/State/EmphasisStyle.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a0d9ff3b8e09d464e9b5ea996b941314 +guid: 91a31f424478042418811c32bb8aa2d5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Component/State/SelectStyle.cs b/Runtime/Component/State/SelectStyle.cs new file mode 100644 index 00000000..093274ac --- /dev/null +++ b/Runtime/Component/State/SelectStyle.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace XCharts.Runtime +{ + /// + /// Configurations of select state. + /// |选中状态样式。 + /// + [System.Serializable] + [Since("v3.2.0")] + public class SelectStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent + { } +} \ No newline at end of file diff --git a/Runtime/Component/Emphasis/EmphasisItemStyle.cs.meta b/Runtime/Component/State/SelectStyle.cs.meta similarity index 83% rename from Runtime/Component/Emphasis/EmphasisItemStyle.cs.meta rename to Runtime/Component/State/SelectStyle.cs.meta index 73b33639..c4a851cd 100644 --- a/Runtime/Component/Emphasis/EmphasisItemStyle.cs.meta +++ b/Runtime/Component/State/SelectStyle.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5d1095175540449f99bb9da27a5aaf04 +guid: 986a9b6da6fdd48c49a9b665450dd605 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Component/Emphasis/Emphasis.cs b/Runtime/Component/State/StateStyle.cs similarity index 50% rename from Runtime/Component/Emphasis/Emphasis.cs rename to Runtime/Component/State/StateStyle.cs index 90d64640..9c1304ce 100644 --- a/Runtime/Component/Emphasis/Emphasis.cs +++ b/Runtime/Component/State/StateStyle.cs @@ -3,15 +3,19 @@ using UnityEngine; namespace XCharts.Runtime { /// - /// 高亮的图形样式和文本标签样式。 + /// the state style of serie. + /// |Serie的状态样式。Serie的状态有正常,高亮,淡出,选中四种状态。 /// [System.Serializable] - public class Emphasis : ChildComponent, ISerieExtraComponent, ISerieDataComponent + [Since("v3.2.0")] + public class StateStyle : ChildComponent { - [SerializeField] private bool m_Show; + [SerializeField] private bool m_Show = true; [SerializeField] private LabelStyle m_Label = new LabelStyle(); [SerializeField] private LabelLine m_LabelLine = new LabelLine(); [SerializeField] private ItemStyle m_ItemStyle = new ItemStyle(); + [SerializeField] private LineStyle m_LineStyle = new LineStyle(); + [SerializeField] private AreaStyle m_AreaStyle = new AreaStyle(); public void Reset() { @@ -53,22 +57,57 @@ namespace XCharts.Runtime get { return m_ItemStyle; } set { if (PropertyUtil.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); } } + /// + /// 折线样式。 + /// + public LineStyle lineStyle + { + get { return m_LineStyle; } + set { if (PropertyUtil.SetClass(ref m_LineStyle, value, true)) SetVerticesDirty(); } + } + /// + /// 区域样式。 + /// + public AreaStyle areaStyle + { + get { return m_AreaStyle; } + set { if (PropertyUtil.SetClass(ref m_AreaStyle, value, true)) SetVerticesDirty(); } + } - public override bool vertsDirty { get { return m_VertsDirty || label.vertsDirty || itemStyle.vertsDirty; } } + public override bool vertsDirty + { + get + { + return m_VertsDirty || + m_Label.vertsDirty || + m_ItemStyle.vertsDirty || + m_LineStyle.vertsDirty || + m_AreaStyle.vertsDirty; + } + } - public override bool componentDirty { get { return m_ComponentDirty || label.componentDirty; } } + public override bool componentDirty + { + get + { + return m_ComponentDirty || + m_Label.componentDirty; + } + } public override void ClearVerticesDirty() { base.ClearVerticesDirty(); - label.ClearVerticesDirty(); - itemStyle.ClearVerticesDirty(); + m_Label.ClearVerticesDirty(); + m_ItemStyle.ClearVerticesDirty(); + m_LineStyle.ClearVerticesDirty(); + m_AreaStyle.ClearVerticesDirty(); } public override void ClearComponentDirty() { base.ClearComponentDirty(); - label.ClearComponentDirty(); + m_Label.ClearComponentDirty(); } } } \ No newline at end of file diff --git a/Runtime/Component/State/StateStyle.cs.meta b/Runtime/Component/State/StateStyle.cs.meta new file mode 100644 index 00000000..fed3381b --- /dev/null +++ b/Runtime/Component/State/StateStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 921539f841914493a90f748c6c6662dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 3459b54a..7c1c2a2b 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -544,17 +544,25 @@ namespace XCharts.Runtime return theme.GetBackgroundColor(background); } - public Color32 GetItemColor(Serie serie, SerieData serieData, bool highlight = false) + public Color32 GetItemColor(Serie serie, SerieData serieData) { - var colorIndex = serieData == null || !serie.useDataNameForColor ? - GetLegendRealShowNameIndex(serie.legendName) : - GetLegendRealShowNameIndex(serieData.legendName); - return SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight); + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, m_Theme); + return color; } - public Color32 GetItemColor(Serie serie, bool highlight = false) + public Color32 GetItemColor(Serie serie, SerieData serieData, int colorIndex) { - return SerieHelper.GetItemColor(serie, null, m_Theme, serie.context.colorIndex, highlight); + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, m_Theme, colorIndex); + return color; + } + + public Color32 GetItemColor(Serie serie) + { + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, null, m_Theme); + return color; } } } \ No newline at end of file diff --git a/Runtime/Internal/Basic/BaseSerie.cs b/Runtime/Internal/Basic/BaseSerie.cs index 57c992a3..087b4111 100644 --- a/Runtime/Internal/Basic/BaseSerie.cs +++ b/Runtime/Internal/Basic/BaseSerie.cs @@ -27,6 +27,28 @@ namespace XCharts.Runtime public SerieHandler handler { get; set; } + public static void ClearVerticesDirty(ChildComponent component) + { + if (component != null) + component.ClearVerticesDirty(); + } + + public static void ClearComponentDirty(ChildComponent component) + { + if (component != null) + component.ClearComponentDirty(); + } + + public static bool IsVertsDirty(ChildComponent component) + { + return component == null?false : component.vertsDirty; + } + + public static bool IsComponentDirty(ChildComponent component) + { + return component == null?false : component.componentDirty; + } + public virtual void SetVerticesDirty() { m_VertsDirty = true; @@ -47,8 +69,7 @@ namespace XCharts.Runtime m_ComponentDirty = false; } - public virtual void ClearData() - { } + public virtual void ClearData() { } public virtual void ClearDirty() { @@ -68,11 +89,9 @@ namespace XCharts.Runtime handler.RemoveComponent(); } - public virtual void OnDataUpdate() - { } + public virtual void OnDataUpdate() { } - public virtual void OnBeforeSerialize() - { } + public virtual void OnBeforeSerialize() { } public virtual void OnAfterDeserialize() { diff --git a/Runtime/Internal/Basic/ChildComponent.cs b/Runtime/Internal/Basic/ChildComponent.cs index 90bca35c..ce89da2f 100644 --- a/Runtime/Internal/Basic/ChildComponent.cs +++ b/Runtime/Internal/Basic/ChildComponent.cs @@ -28,6 +28,28 @@ namespace XCharts.Runtime public Action refreshComponent { get; set; } public GameObject gameObject { get; set; } + public static void ClearVerticesDirty(ChildComponent component) + { + if (component != null) + component.ClearVerticesDirty(); + } + + public static void ClearComponentDirty(ChildComponent component) + { + if (component != null) + component.ClearComponentDirty(); + } + + public static bool IsVertsDirty(ChildComponent component) + { + return component == null?false : component.vertsDirty; + } + + public static bool IsComponentDirty(ChildComponent component) + { + return component == null?false : component.componentDirty; + } + public virtual void SetVerticesDirty() { m_VertsDirty = true; diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 47c56e04..1c3f8968 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -845,6 +845,22 @@ namespace XCharts.Runtime return newColor; } + public static Color32 GetBlurColor(Color32 color, float a = 0.3f) + { + var newColor = color; + newColor.a = (byte) (a * 255); + return newColor; + } + + public static Color32 GetSelectColor(Color32 color, float rate = 0.7f) + { + var newColor = color; + newColor.r = (byte) (color.r * rate); + newColor.g = (byte) (color.g * rate); + newColor.b = (byte) (color.b * rate); + return newColor; + } + public static bool IsPointInQuadrilateral(Vector3 P, Vector3 A, Vector3 B, Vector3 C, Vector3 D) { Vector3 v0 = Vector3.Cross(A - D, P - D); diff --git a/Runtime/Serie/Bar/Bar.cs b/Runtime/Serie/Bar/Bar.cs index 89ed7024..c02e83cb 100644 --- a/Runtime/Serie/Bar/Bar.cs +++ b/Runtime/Serie/Bar/Bar.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [SerieConvert(typeof(Line), typeof(Pie))] [RequireChartComponent(typeof(GridCoord))] [DefaultAnimation(AnimationType.BottomToTop)] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Ignore")] public class Bar : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index 0e1d4df8..fabb1576 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -81,14 +81,14 @@ namespace XCharts.Runtime return; } m_LastCheckContextFlag = needCheck; + Color32 color, toColor; if (m_LegendEnter) { serie.context.pointerEnter = true; foreach (var serieData in serie.data) { - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme); + serieData.interact.SetColor(ref needInteract, color, toColor); } } else @@ -103,18 +103,14 @@ namespace XCharts.Runtime serie.context.pointerItemDataIndex = serieData.index; serie.context.pointerEnter = true; serieData.context.highlight = true; - - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Emphasis); } else { serieData.context.highlight = false; - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, false); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Normal); } + serieData.interact.SetColor(ref needInteract, color, toColor); } } if (needInteract) @@ -190,18 +186,18 @@ namespace XCharts.Runtime if (serieData.IsDataChanged()) dataChanging = true; - var highlight = serieData.context.highlight || serie.highlight; - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); + var state = SerieHelper.GetSerieState(serie, serieData); + var itemStyle = SerieHelper.GetItemStyle(serie, serieData, state); var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse); var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue); var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth; var borderGap = relativedValue == 0 ? 0 : itemStyle.borderGap; var borderGapAndWidth = borderWidth + borderGap; + var backgroundColor = itemStyle.backgroundColor; if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting)) { - areaColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, highlight); - areaToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, highlight); + SerieHelper.GetItemColor(out areaColor, out areaToColor, serie, serieData, chart.theme); serieData.interact.SetColor(ref interacting, areaColor, areaToColor); } @@ -242,11 +238,11 @@ namespace XCharts.Runtime { case BarType.Normal: case BarType.Capsule: - DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, + DrawNormalBar(vh, serie, serieData, itemStyle, backgroundColor, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor, relativedValue); break; case BarType.Zebra: - DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, + DrawZebraBar(vh, serie, serieData, itemStyle, backgroundColor, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); break; } @@ -366,12 +362,11 @@ namespace XCharts.Runtime } } - private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, + private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, Color32 backgroundColor, + float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor, double value) { var borderWidth = itemStyle.runtimeBorderWidth; - var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false); var cornerRadius = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner() ? m_CapusleDefaultCornerRadius : itemStyle.cornerRadius; @@ -395,11 +390,10 @@ namespace XCharts.Runtime } } - private void DrawZebraBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, + private void DrawZebraBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, Color32 backgroundColor, + float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 barColor, Color32 barToColor) { - var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false); if (!ChartHelper.IsClearColor(backgroundColor)) { UGL.DrawRoundRectangle(vh, serieData.context.backgroundRect, backgroundColor, backgroundColor, 0, diff --git a/Runtime/Serie/Bar/SimplifiedBarHandler.cs b/Runtime/Serie/Bar/SimplifiedBarHandler.cs index fffb5779..ca4a92ce 100644 --- a/Runtime/Serie/Bar/SimplifiedBarHandler.cs +++ b/Runtime/Serie/Bar/SimplifiedBarHandler.cs @@ -37,6 +37,7 @@ namespace XCharts.Runtime var needCheck = (chart.isPointerInChart && m_SerieGrid.IsPointerEnter()) || m_LegendEnter; var needInteract = false; + Color32 color, toColor; if (!needCheck) { if (m_LastCheckContextFlag != needCheck) @@ -46,9 +47,8 @@ namespace XCharts.Runtime serie.context.pointerEnter = false; foreach (var serieData in serie.data) { - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, false); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Normal); + serieData.interact.SetColor(ref needInteract, color, toColor); } if (needInteract) { @@ -63,9 +63,8 @@ namespace XCharts.Runtime serie.context.pointerEnter = true; foreach (var serieData in serie.data) { - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Emphasis); + serieData.interact.SetColor(ref needInteract, color, toColor); } } else @@ -80,16 +79,14 @@ namespace XCharts.Runtime serie.context.pointerEnter = true; serieData.context.highlight = true; - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, true); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Emphasis); + serieData.interact.SetColor(ref needInteract, color, toColor); } else { serieData.context.highlight = false; - var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); - var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, false); - serieData.interact.SetColor(ref needInteract, barColor, barToColor); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Normal); + serieData.interact.SetColor(ref needInteract, color, toColor); } } } @@ -162,15 +159,14 @@ namespace XCharts.Runtime dataChanging = true; var highlight = serieData.context.highlight || serie.highlight; - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); + var itemStyle = SerieHelper.GetItemStyle(serie, serieData); var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse); var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue); var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth; if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting)) { - areaColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, highlight); - areaToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, highlight); + SerieHelper.GetItemColor(out areaColor, out areaToColor, serie, serieData, chart.theme); serieData.interact.SetColor(ref interacting, areaColor, areaToColor); } diff --git a/Runtime/Serie/Candlestick/Candlestick.cs b/Runtime/Serie/Candlestick/Candlestick.cs index 6ac985ec..16da2b14 100644 --- a/Runtime/Serie/Candlestick/Candlestick.cs +++ b/Runtime/Serie/Candlestick/Candlestick.cs @@ -6,7 +6,7 @@ namespace XCharts.Runtime [SerieHandler(typeof(CandlestickHandler), true)] [DefaultAnimation(AnimationType.LeftToRight)] [SerieExtraComponent()] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(EmphasisItemStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Candlestick : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Candlestick/CandlestickHandler.cs b/Runtime/Serie/Candlestick/CandlestickHandler.cs index 7955f60f..3eafef1b 100644 --- a/Runtime/Serie/Candlestick/CandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/CandlestickHandler.cs @@ -29,7 +29,7 @@ namespace XCharts.Runtime title = category; - var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); + var color = chart.GetItemColor(serie, serieData); var newMarker = SerieHelper.GetItemMarker(serie, serieData, marker); var newItemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); var newNumericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); @@ -113,8 +113,8 @@ namespace XCharts.Runtime serie.context.dataPoints.Add(Vector3.zero); continue; } - var highlight = serie.data[i].context.highlight || serie.highlight; - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); + var state = SerieHelper.GetSerieState(serie, serieData); + var itemStyle = SerieHelper.GetItemStyle(serie, serieData, state); var open = serieData.GetCurrData(0, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs index 455f6005..0bbb90dd 100644 --- a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs @@ -29,7 +29,7 @@ namespace XCharts.Runtime title = category; - var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); + var color = chart.GetItemColor(serie, serieData); var newMarker = SerieHelper.GetItemMarker(serie, serieData, marker); var newItemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); var newNumericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); diff --git a/Runtime/Serie/Heatmap/Heatmap.cs b/Runtime/Serie/Heatmap/Heatmap.cs index 9d713569..ea1ccd72 100644 --- a/Runtime/Serie/Heatmap/Heatmap.cs +++ b/Runtime/Serie/Heatmap/Heatmap.cs @@ -6,8 +6,8 @@ namespace XCharts.Runtime [SerieHandler(typeof(HeatmapHandler), true)] [DefaultAnimation(AnimationType.LeftToRight)] [RequireChartComponent(typeof(VisualMap))] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Heatmap : Serie, INeedSerieContainer { @@ -20,10 +20,11 @@ namespace XCharts.Runtime serie.itemStyle.borderWidth = 1; serie.itemStyle.borderColor = Color.clear; - var emphasis = serie.AddExtraComponent(); + var emphasis = serie.AddExtraComponent(); emphasis.show = true; - emphasis.borderWidth = 1; - emphasis.borderColor = Color.black; + emphasis.itemStyle.show = true; + emphasis.itemStyle.borderWidth = 1; + emphasis.itemStyle.borderColor = Color.black; return serie; } } diff --git a/Runtime/Serie/Heatmap/HeatmapHandler.cs b/Runtime/Serie/Heatmap/HeatmapHandler.cs index 517033fa..51aade31 100644 --- a/Runtime/Serie/Heatmap/HeatmapHandler.cs +++ b/Runtime/Serie/Heatmap/HeatmapHandler.cs @@ -130,7 +130,7 @@ namespace XCharts.Runtime xAxis.boundaryGap = true; yAxis.boundaryGap = true; var visualMap = chart.GetVisualMapOfSerie(serie); - var emphasisItemStyle = serie.emphasisItemStyle; + var emphasisStyle = serie.emphasisStyle; var xCount = xAxis.data.Count; var yCount = yAxis.data.Count; var xWidth = m_SerieGrid.context.width / xCount; @@ -209,9 +209,10 @@ namespace XCharts.Runtime { UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor); } - if (visualMap.hoverLink && highlight && emphasisItemStyle != null && - emphasisItemStyle.borderWidth > 0) + if (visualMap.hoverLink && highlight && emphasisStyle != null && + emphasisStyle.itemStyle.borderWidth > 0) { + var emphasisItemStyle = emphasisStyle.itemStyle; var emphasisBorderWidth = emphasisItemStyle.borderWidth; var emphasisBorderColor = emphasisItemStyle.opacity > 0 ? emphasisItemStyle.borderColor : ChartConst.clearColor32; diff --git a/Runtime/Serie/Line/Line.cs b/Runtime/Serie/Line/Line.cs index d504f13c..3b13b9ef 100644 --- a/Runtime/Serie/Line/Line.cs +++ b/Runtime/Serie/Line/Line.cs @@ -12,15 +12,17 @@ namespace XCharts.Runtime typeof(EndLabelStyle), typeof(LineArrow), typeof(AreaStyle), - typeof(EmphasisItemStyle), - typeof(EmphasisLabelStyle))] + typeof(EmphasisStyle), + typeof(BlurStyle), + typeof(SelectStyle))] [SerieDataExtraComponent( typeof(ItemStyle), typeof(LabelStyle), typeof(SerieSymbol), - typeof(EmphasisItemStyle), - typeof(EmphasisLabelStyle))] - [SerieDataExtraField("m_Ignore")] + typeof(EmphasisStyle), + typeof(BlurStyle), + typeof(SelectStyle))] + [SerieDataExtraField("m_State", "m_Ignore")] public class Line : Serie, INeedSerieContainer { public int containerIndex { get; internal set; } diff --git a/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Runtime/Serie/Line/LineHandler.GridCoord.cs index 7c24bf37..f1b6c6f8 100644 --- a/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -187,18 +187,18 @@ namespace XCharts.Runtime serieData.interact.SetValue(ref interacting, symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize); } - var symbolColor = SerieHelper.GetItemColor(serie, serieData, theme, serie.index, highlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, theme, serie.index, highlight); - var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, theme, serie.index, highlight, false); + var state = SerieHelper.GetSerieState(serie, serieData); + Color32 symbolColor, symbolToColor,symbolEmptyColor; + SerieHelper.GetItemColor(out symbolColor, out symbolToColor,out symbolEmptyColor, serie, serieData, theme, serie.index, state); if (isVisualMapGradient) { symbolColor = VisualMapHelper.GetLineGradientColor(visualMap, pos, m_SerieGrid, axis, relativedAxis, symbolColor); symbolToColor = symbolColor; } - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, highlight); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, highlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, state); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, state); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); chart.DrawClipSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, clip, cornerRadius, m_SerieGrid, i > 0 ? serie.context.dataPoints[i - 1] : m_SerieGrid.context.position); @@ -220,7 +220,7 @@ namespace XCharts.Runtime if (serie.context.dataPoints.Count < 2) return; - var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.index, false); + var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.index); var startPos = Vector3.zero; var arrowPos = Vector3.zero; var lineArrow = serie.lineArrow.arrow; diff --git a/Runtime/Serie/Line/LineHandler.PolarCoord.cs b/Runtime/Serie/Line/LineHandler.PolarCoord.cs index ea5b5698..24410e0c 100644 --- a/Runtime/Serie/Line/LineHandler.PolarCoord.cs +++ b/Runtime/Serie/Line/LineHandler.PolarCoord.cs @@ -120,7 +120,7 @@ namespace XCharts.Runtime var firstSerieData = datas[0]; var lp = GetPolarPos(m_SeriePolar, m_AngleAxis, firstSerieData, min, max, radius); var cp = Vector3.zero; - var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.index, serie.highlight); + var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.index); var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); var currDetailProgress = 0f; var totalDetailProgress = datas.Count; @@ -205,6 +205,7 @@ namespace XCharts.Runtime continue; var count = serie.dataCount; + Color32 symbolColor, symbolToColor,symbolEmptyColor; for (int i = 0; i < count; i++) { var serieData = serie.GetSerieData(i); @@ -220,13 +221,11 @@ namespace XCharts.Runtime var symbolSize = highlight ? symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSize) : symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize); - - var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, n, highlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, n, highlight); - var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, n, highlight, false); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, highlight); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, highlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); + var state = SerieHelper.GetSerieState(serie, serieData); + SerieHelper.GetItemColor(out symbolColor, out symbolToColor,out symbolEmptyColor, serie, serieData, chart.theme, n); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, state); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, state); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); symbolSize = serie.animation.GetSysmbolSize(symbolSize); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serieData.context.position, diff --git a/Runtime/Serie/Line/LineHelper.cs b/Runtime/Serie/Line/LineHelper.cs index 831a52b4..d99132a1 100644 --- a/Runtime/Serie/Line/LineHelper.cs +++ b/Runtime/Serie/Line/LineHelper.cs @@ -24,11 +24,11 @@ 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) { - if (serie.areaStyle == null || !serie.areaStyle.show) + Color32 srcAreaColor, srcAreaToColor; + if (!SerieHelper.GetAreaColor(out srcAreaColor, out srcAreaToColor, serie, null, theme, serie.context.colorIndex)) + { return; - - var srcAreaColor = SerieHelper.GetAreaColor(serie, null, theme, serie.context.colorIndex, false); - var srcAreaToColor = SerieHelper.GetAreaToColor(serie, null, theme, serie.context.colorIndex, false); + } var gridXY = (isY ? grid.context.x : grid.context.y); if (lastStackSerie == null) { @@ -263,7 +263,7 @@ namespace XCharts.Runtime var isLineStyleGradient = serie.lineStyle.IsNeedGradient(); //var highlight = serie.highlight || serie.context.pointerEnter; - var lineColor = SerieHelper.GetLineColor(serie, null, theme, serie.context.colorIndex, false); + var lineColor = SerieHelper.GetLineColor(serie, null, theme, serie.context.colorIndex); var lastDataIsIgnore = datas[0].isIgnoreBreak; var smooth = serie.lineType == LineType.Smooth; diff --git a/Runtime/Serie/Parallel/Parallel.cs b/Runtime/Serie/Parallel/Parallel.cs index 9d6b7528..721f9f91 100644 --- a/Runtime/Serie/Parallel/Parallel.cs +++ b/Runtime/Serie/Parallel/Parallel.cs @@ -6,7 +6,7 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(ParallelHandler), true)] [RequireChartComponent(typeof(ParallelCoord))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Parallel : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Parallel/ParallelHandler.cs b/Runtime/Serie/Parallel/ParallelHandler.cs index c56c4d41..717a0ad2 100644 --- a/Runtime/Serie/Parallel/ParallelHandler.cs +++ b/Runtime/Serie/Parallel/ParallelHandler.cs @@ -38,7 +38,7 @@ namespace XCharts.Runtime var animationIndex = serie.animation.GetCurrIndex(); var isHorizonal = parallel.orient == Orient.Horizonal; - var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex, false); + var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex); var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); float currDetailProgress = !isHorizonal ? diff --git a/Runtime/Serie/Pie/Pie.cs b/Runtime/Serie/Pie/Pie.cs index 39278796..fdfb6edb 100644 --- a/Runtime/Serie/Pie/Pie.cs +++ b/Runtime/Serie/Pie/Pie.cs @@ -4,8 +4,8 @@ namespace XCharts.Runtime [SerieConvert(typeof(Line), typeof(Bar))] [SerieHandler(typeof(PieHandler), true)] [DefaultAnimation(AnimationType.Clockwise)] - [SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle), typeof(EmphasisLabelLine))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle), typeof(EmphasisLabelLine))] + [SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")] public class Pie : Serie { diff --git a/Runtime/Serie/Pie/PieHandler.cs b/Runtime/Serie/Pie/PieHandler.cs index b1c545e3..e7ec59bd 100644 --- a/Runtime/Serie/Pie/PieHandler.cs +++ b/Runtime/Serie/Pie/PieHandler.cs @@ -108,6 +108,7 @@ namespace XCharts.Runtime { var needCheck = m_LegendEnter || (chart.isPointerInChart && PointerIsInPieSerie(serie, chart.pointerPos)); var needInteract = false; + Color32 color, toColor; if (!needCheck) { if (m_LastCheckContextFlag != needCheck) @@ -118,8 +119,7 @@ namespace XCharts.Runtime foreach (var serieData in serie.data) { var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); - var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); - var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal); serieData.context.highlight = false; serieData.interact.SetValueAndColor(ref needInteract, serieData.context.outsideRadius, color, toColor); } @@ -142,8 +142,7 @@ namespace XCharts.Runtime serieData.context.highlight = true; var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); - var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, true); - var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, true); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Emphasis); var value = serieData.context.outsideRadius + chart.theme.serie.pieTooltipExtraRadius; serieData.interact.SetValueAndColor(ref needInteract, value, color, toColor); } @@ -151,8 +150,7 @@ namespace XCharts.Runtime { serieData.context.highlight = false; var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); - var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); - var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal); serieData.interact.SetValueAndColor(ref needInteract, serieData.context.outsideRadius, color, toColor); } } @@ -322,7 +320,7 @@ namespace XCharts.Runtime if (serieData.IsDataChanged()) dataChanging = true; - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight); + var itemStyle = SerieHelper.GetItemStyle(serie, serieData); var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); var outsideRadius = 0f; @@ -334,8 +332,7 @@ namespace XCharts.Runtime //if (!serieData.interact.TryGetValueAndColor(ref outsideRadius, ref color, ref toColor, ref interacting)) { - color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); - toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex); outsideRadius = serieData.context.outsideRadius * progress; serieData.interact.SetValueAndColor(ref interacting, outsideRadius, color, toColor); } diff --git a/Runtime/Serie/Radar/Radar.cs b/Runtime/Serie/Radar/Radar.cs index dc44ec02..7271acc7 100644 --- a/Runtime/Serie/Radar/Radar.cs +++ b/Runtime/Serie/Radar/Radar.cs @@ -6,8 +6,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(RadarHandler), true)] [RequireChartComponent(typeof(RadarCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieExtraComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Radar : Serie, INeedSerieContainer { diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 5bda0afb..17c587dc 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -54,7 +54,8 @@ namespace XCharts.Runtime if (serieData == null) return; - var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, dataIndex, false);; + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, dataIndex, SerieState.Normal); title = serieData.name; for (int i = 0; i < serieData.data.Count; i++) { @@ -96,6 +97,7 @@ namespace XCharts.Runtime needHideAll = true; } m_LastCheckContextFlag = needCheck; + serie.highlight = false; serie.context.pointerEnter = false; serie.context.pointerItemDataIndex = -1; var areaStyle = serie.areaStyle; @@ -120,6 +122,7 @@ namespace XCharts.Runtime { if (Vector3.Distance(chart.pointerPos, pos) < symbolSize * 2) { + serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = i; serieData.context.highlight = true; @@ -136,6 +139,7 @@ namespace XCharts.Runtime var p2 = n >= dataPoints.Count - 1 ? dataPoints[0] : dataPoints[n + 1]; if (UGLHelper.IsPointInTriangle(p1, center, p2, chart.pointerPos)) { + serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = i; serieData.context.highlight = true; @@ -154,6 +158,7 @@ namespace XCharts.Runtime serieData.index = i; if (Vector3.Distance(chart.pointerPos, serieData.context.position) < serie.symbol.size * 2) { + serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = i; return; @@ -169,6 +174,7 @@ namespace XCharts.Runtime var p2 = n >= dataPoints.Count - 1 ? dataPoints[0] : dataPoints[n + 1]; if (UGLHelper.IsPointInTriangle(p1.context.position, center, p2.context.position, chart.pointerPos)) { + serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = n; p1.context.highlight = true; @@ -209,6 +215,7 @@ namespace XCharts.Runtime var interacting = false; var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); SerieHelper.GetAllMinMaxData(serie, m_RadarCoord.ceilRate); + Color32 areaColor, areaToColor; for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; @@ -218,13 +225,12 @@ namespace XCharts.Runtime continue; } var lineStyle = SerieHelper.GetLineStyle(serie, serieData); - var areaStyle = SerieHelper.GetAreaStyle(serie, serieData); var symbol = SerieHelper.GetSerieSymbol(serie, serieData); var isHighlight = serieData.context.highlight; + var serieState = SerieHelper.GetSerieState(serie, serieData); var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); - var areaColor = SerieHelper.GetAreaColor(serie, serieData, chart.theme, colorIndex, isHighlight); - var areaToColor = SerieHelper.GetAreaToColor(serie, serieData, chart.theme, colorIndex, isHighlight); - var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex, isHighlight); + var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex); + var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex); var lineWidth = lineStyle.GetWidth(chart.theme.serie.lineWidth); int dataCount = m_RadarCoord.indicatorList.Count; serieData.context.dataPoints.Clear(); @@ -262,7 +268,7 @@ namespace XCharts.Runtime { toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle), centerPos.y + radius * Mathf.Cos(currAngle)); - if (areaStyle != null && areaStyle.show && !serie.smooth) + if (showArea && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor); } @@ -274,7 +280,7 @@ namespace XCharts.Runtime } serieData.context.dataPoints.Add(startPoint); } - if (areaStyle != null && areaStyle.show && !serie.smooth) + if (showArea && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); } @@ -308,12 +314,11 @@ namespace XCharts.Runtime serieData.interact.SetValue(ref interacting, symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize); } - var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, j, isHighlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, isHighlight); - var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, j, isHighlight, false); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, isHighlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); + Color32 symbolColor, symbolToColor, symbolEmptyColor; + SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, j, serieState); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, serieState); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, serieState); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, serieState); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius); } @@ -369,11 +374,9 @@ namespace XCharts.Runtime continue; } var lineStyle = SerieHelper.GetLineStyle(serie, serieData); - var areaStyle = SerieHelper.GetAreaStyle(serie, serieData); - var isHighlight = serie.context.pointerEnter; - var areaColor = SerieHelper.GetAreaColor(serie, serieData, chart.theme, j, isHighlight); - var areaToColor = SerieHelper.GetAreaToColor(serie, serieData, chart.theme, j, isHighlight); - var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, j, isHighlight); + Color32 areaColor, areaToColor; + var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, j); + var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, j); int dataCount = radar.indicatorList.Count; var index = serieData.index; var p = radar.context.center; @@ -404,7 +407,7 @@ namespace XCharts.Runtime { toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); - if (areaStyle != null && areaStyle.show && !serie.smooth) + if (showArea && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor); } @@ -423,7 +426,7 @@ namespace XCharts.Runtime serieData.context.position = startPoint; serieData.context.labelPosition = startPoint; - if (areaStyle != null && areaStyle.show && j == endIndex && !serie.smooth) + if (showArea && j == endIndex && !serie.smooth) { UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); } @@ -439,7 +442,7 @@ namespace XCharts.Runtime if (serie.smooth) { var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); - var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex, false); + var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex); UGL.DrawCurves(vh, serie.context.dataPoints, lineWidth, lineColor, chart.settings.lineSmoothStyle, chart.settings.lineSmoothness, @@ -452,17 +455,16 @@ namespace XCharts.Runtime { var serieData = serie.data[j]; if (!serieData.show) continue; - var isHighlight = serie.highlight || serieData.context.highlight || serie.context.pointerEnter; + var state = SerieHelper.GetSerieState(serie, serieData); var serieIndex = serieData.index; - var symbolSize = isHighlight ? + var symbolSize = state == SerieState.Emphasis ? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize) : 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 symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, isHighlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); + Color32 symbolColor, symbolToColor,symbolEmptyColor; + SerieHelper.GetItemColor(out symbolColor, out symbolToColor,out symbolEmptyColor, serie, serieData, chart.theme, serieIndex, state); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, state); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, state); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); if (!radar.IsInIndicatorRange(j, serieData.GetData(1))) { symbolColor = radar.outRangeColor; @@ -499,27 +501,5 @@ namespace XCharts.Runtime } return 0; } - - private void DrawRadarSymbol(VertexHelper vh, Serie serie, SerieData serieData, int serieIndex, bool isHighlight, - List pointList) - { - if (serie.symbol.show && serie.symbol.type != SymbolType.None) - { - var symbolSize = isHighlight ? - serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize) : - 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 symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight); - var borderColor = SerieHelper.GetSymbolBorderColor(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, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius); - } - } - } } } \ No newline at end of file diff --git a/Runtime/Serie/Ring/Ring.cs b/Runtime/Serie/Ring/Ring.cs index d97cdb40..f448f783 100644 --- a/Runtime/Serie/Ring/Ring.cs +++ b/Runtime/Serie/Ring/Ring.cs @@ -4,8 +4,8 @@ namespace XCharts.Runtime { [System.Serializable] [SerieHandler(typeof(RingHandler), true)] - [SerieExtraComponent(typeof(LabelStyle), typeof(TitleStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(TitleStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieExtraComponent(typeof(LabelStyle), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField()] public class Ring : Serie { diff --git a/Runtime/Serie/Ring/RingHandler.cs b/Runtime/Serie/Ring/RingHandler.cs index 70c5f400..df5a27f1 100644 --- a/Runtime/Serie/Ring/RingHandler.cs +++ b/Runtime/Serie/Ring/RingHandler.cs @@ -86,6 +86,8 @@ namespace XCharts.Runtime var serieData = serie.GetSerieData(dataIndex); if (serieData == null) return; + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, dataIndex); var param = serie.context.param; param.serieName = serie.serieName; @@ -96,7 +98,7 @@ namespace XCharts.Runtime param.dataCount = serie.dataCount; param.value = serieData.GetData(0); param.total = serieData.GetData(1); - param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, dataIndex, false); + param.color = color; param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); param.itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter);; @@ -158,10 +160,10 @@ namespace XCharts.Runtime var degree = (float) (360 * value / max); var startDegree = GetStartAngle(serie); var toDegree = GetToAngle(serie, degree); - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight); + var itemStyle = SerieHelper.GetItemStyle(serie, serieData); var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); - var itemColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); - var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); + Color32 itemColor, itemToColor; + SerieHelper.GetItemColor(out itemColor, out itemToColor, serie, serieData, chart.theme, colorIndex); var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.gap); var insideRadius = outsideRadius - ringWidth; var borderWidth = itemStyle.borderWidth; @@ -214,8 +216,7 @@ namespace XCharts.Runtime chart.RefreshPainter(serie); } - public override void OnPointerDown(PointerEventData eventData) - { } + public override void OnPointerDown(PointerEventData eventData) { } private float GetStartAngle(Serie serie) { @@ -258,7 +259,12 @@ namespace XCharts.Runtime private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); - var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, index, false); + var backgroundColor = itemStyle.backgroundColor; + if (ChartHelper.IsClearColor(backgroundColor)) + { + backgroundColor = chart.theme.GetColor(index); + backgroundColor.a = 50; + } if (itemStyle.backgroundWidth != 0) { var centerRadius = (outsideRadius + insideRadius) / 2; diff --git a/Runtime/Serie/Scatter/BaseScatterHandler.cs b/Runtime/Serie/Scatter/BaseScatterHandler.cs index f8a3aa78..1958afc0 100644 --- a/Runtime/Serie/Scatter/BaseScatterHandler.cs +++ b/Runtime/Serie/Scatter/BaseScatterHandler.cs @@ -36,7 +36,7 @@ namespace XCharts.Runtime param.dimension = 1; param.dataCount = serie.dataCount; param.serieData = serieData; - param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); + param.color = chart.GetItemColor(serie, serieData); param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); param.itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); @@ -151,12 +151,12 @@ namespace XCharts.Runtime continue; var highlight = serie.highlight || serieData.context.highlight; - var color = SerieHelper.GetItemColor(serie, serieData, theme, colorIndex, highlight); - var toColor = SerieHelper.GetItemToColor(serie, serieData, theme, colorIndex, highlight); - var emptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, theme, colorIndex, highlight, false); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, highlight); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, highlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); + var state = SerieHelper.GetSerieState(serie, serieData); + Color32 color, toColor, emptyColor; + SerieHelper.GetItemColor(out color, out toColor, out emptyColor, serie, serieData, chart.theme, colorIndex, state); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, state); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, state); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); double xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse); double yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse); @@ -255,13 +255,12 @@ namespace XCharts.Runtime if (!symbol.ShowSymbol(serieData.index, maxCount)) continue; - var highlight = serie.highlight || serieData.context.highlight; - var color = SerieHelper.GetItemColor(serie, serieData, theme, colorIndex, highlight); - var toColor = SerieHelper.GetItemToColor(serie, serieData, theme, colorIndex, highlight); - var emptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, theme, colorIndex, highlight, false); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, highlight); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, highlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); + var state = SerieHelper.GetSerieState(serie, serieData); + Color32 color, toColor, emptyColor; + SerieHelper.GetItemColor(out color, out toColor, out emptyColor, serie, serieData, chart.theme, colorIndex, state); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, state); + var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, state); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); var xValue = serieData.GetCurrData(0, dataChangeDuration, axis.inverse); if (serieData.IsDataChanged()) diff --git a/Runtime/Serie/Scatter/EffectScatter.cs b/Runtime/Serie/Scatter/EffectScatter.cs index f2219173..55696652 100644 --- a/Runtime/Serie/Scatter/EffectScatter.cs +++ b/Runtime/Serie/Scatter/EffectScatter.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(EffectScatterHandler), true)] [CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Radius")] public class EffectScatter : BaseScatter { diff --git a/Runtime/Serie/Scatter/Scatter.cs b/Runtime/Serie/Scatter/Scatter.cs index f633d74a..daf2ee56 100644 --- a/Runtime/Serie/Scatter/Scatter.cs +++ b/Runtime/Serie/Scatter/Scatter.cs @@ -5,8 +5,8 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(ScatterHandler), true)] [CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))] - [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] - [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))] + [SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] + [SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataExtraField("m_Radius")] public class Scatter : BaseScatter { diff --git a/Runtime/Serie/Serie.ExtraComponent.cs b/Runtime/Serie/Serie.ExtraComponent.cs index 01f21b9d..06eb4726 100644 --- a/Runtime/Serie/Serie.ExtraComponent.cs +++ b/Runtime/Serie/Serie.ExtraComponent.cs @@ -14,9 +14,9 @@ namespace XCharts.Runtime { typeof(LineArrow), "m_LineArrows" }, { typeof(AreaStyle), "m_AreaStyles" }, { typeof(TitleStyle), "m_TitleStyles" }, - { typeof(EmphasisItemStyle), "m_EmphasisItemStyles" }, - { typeof(EmphasisLabelStyle), "m_EmphasisLabels" }, - { typeof(EmphasisLabelLine), "m_EmphasisLabelLines" }, + { typeof(EmphasisStyle), "m_EmphasisStyles" }, + { typeof(BlurStyle), "m_BlurStyles" }, + { typeof(SelectStyle), "m_SelectStyles" }, }; [SerializeField][IgnoreDoc] private List m_Labels = new List(); @@ -25,9 +25,9 @@ namespace XCharts.Runtime [SerializeField][IgnoreDoc] private List m_LineArrows = new List(); [SerializeField][IgnoreDoc] private List m_AreaStyles = new List(); [SerializeField][IgnoreDoc] private List m_TitleStyles = new List(); - [SerializeField][IgnoreDoc] private List m_EmphasisItemStyles = new List(); - [SerializeField][IgnoreDoc] private List m_EmphasisLabels = new List(); - [SerializeField][IgnoreDoc] private List m_EmphasisLabelLines = new List(); + [SerializeField][IgnoreDoc] private List m_EmphasisStyles = new List(); + [SerializeField][IgnoreDoc] private List m_BlurStyles = new List(); + [SerializeField][IgnoreDoc] private List m_SelectStyles = new List(); /// /// The style of area. @@ -51,22 +51,25 @@ namespace XCharts.Runtime /// public LineArrow lineArrow { get { return m_LineArrows.Count > 0 ? m_LineArrows[0] : null; } } /// - /// 高亮的图形样式 - /// - public EmphasisItemStyle emphasisItemStyle { get { return m_EmphasisItemStyles.Count > 0 ? m_EmphasisItemStyles[0] : null; } } - /// - /// 高亮时的标签样式 - /// - public EmphasisLabelStyle emphasisLabel { get { return m_EmphasisLabels.Count > 0 ? m_EmphasisLabels[0] : null; } } - /// - /// 高亮时的标签引导线样式 - /// - public EmphasisLabelLine emphasisLabelLine { get { return m_EmphasisLabelLines.Count > 0 ? m_EmphasisLabelLines[0] : null; } } - /// /// the icon of data. /// |数据项标题样式。 /// public TitleStyle titleStyle { get { return m_TitleStyles.Count > 0 ? m_TitleStyles[0] : null; } } + /// + /// style of emphasis state. + /// |高亮状态的样式。 + /// + public EmphasisStyle emphasisStyle { get { return m_EmphasisStyles.Count > 0 ? m_EmphasisStyles[0] : null; } } + /// + /// style of blur state. + /// |淡出状态的样式。 + /// + public BlurStyle blurStyle { get { return m_BlurStyles.Count > 0 ? m_BlurStyles[0] : null; } } + /// + /// style of select state. + /// |选中状态的样式。 + /// + public SelectStyle selectStyle { get { return m_SelectStyles.Count > 0 ? m_SelectStyles[0] : null; } } public void RemoveAllExtraComponent() { diff --git a/Runtime/Serie/Serie.cs b/Runtime/Serie/Serie.cs index 245b8dca..3673ee8b 100644 --- a/Runtime/Serie/Serie.cs +++ b/Runtime/Serie/Serie.cs @@ -161,6 +161,39 @@ namespace XCharts.Runtime Right } + /// + /// Serie state. Supports normal, emphasis, blur, and select states. + /// |Serie状态。支持正常、高亮、淡出、选中四种状态。 + /// + public enum SerieState + { + /// + /// Normal state. + /// |正常状态。 + /// + Normal, + /// + /// Emphasis state. + /// |高亮状态。 + /// + Emphasis, + /// + /// Blur state. + /// |淡出状态。 + /// + Blur, + /// + /// Select state. + /// |选中状态。 + /// + Select, + /// + /// Auto state. + /// |自动保持和父节点一致。一般用在SerieData。 + /// + Auto + } + /// /// 系列。 /// @@ -172,6 +205,7 @@ namespace XCharts.Runtime [SerializeField] private string m_CoordSystem = "GridCoord"; [SerializeField] private string m_SerieType = ""; [SerializeField] private string m_SerieName; + [SerializeField][Since("v3.2.0")] private SerieState m_State = SerieState.Normal; [SerializeField] private string m_Stack; [SerializeField] private int m_XAxisIndex = 0; [SerializeField] private int m_YAxisIndex = 0; @@ -296,6 +330,15 @@ namespace XCharts.Runtime /// public string legendName { get { return string.IsNullOrEmpty(serieName) ? ChartCached.IntToStr(index) : serieName; } } /// + /// The default state of a serie. + /// |系列的默认状态。 + /// + public SerieState state + { + get { return m_State; } + set { if (PropertyUtil.SetStruct(ref m_State, value)) { SetAllDirty(); } } + } + /// /// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other. /// |数据堆叠,同个类目轴上系列配置相同的stack值后,后一个系列的值会在前一个系列的值上相加。 /// @@ -826,12 +869,14 @@ namespace XCharts.Runtime symbol.vertsDirty || lineStyle.vertsDirty || itemStyle.vertsDirty || - (lineArrow != null && lineArrow.vertsDirty) || - (areaStyle != null && areaStyle.vertsDirty) || - (label != null && label.vertsDirty) || - (labelLine != null && labelLine.vertsDirty) || - (emphasisItemStyle != null && emphasisItemStyle.vertsDirty) || - (titleStyle != null && titleStyle.vertsDirty) || + IsVertsDirty(lineArrow) || + IsVertsDirty(areaStyle) || + IsVertsDirty(label) || + IsVertsDirty(labelLine) || + IsVertsDirty(titleStyle) || + IsVertsDirty(emphasisStyle) || + IsVertsDirty(blurStyle) || + IsVertsDirty(selectStyle) || AnySerieDataVerticesDirty(); } } @@ -842,11 +887,12 @@ namespace XCharts.Runtime { return m_ComponentDirty || symbol.componentDirty || - (titleStyle != null && titleStyle.componentDirty) || - (label != null && label.componentDirty) || - (labelLine != null && labelLine.componentDirty) || - (emphasisLabel != null && emphasisLabel.componentDirty) || - (emphasisLabelLine != null && emphasisLabelLine.componentDirty); + IsComponentDirty(titleStyle) || + IsComponentDirty(label) || + IsComponentDirty(labelLine) || + IsComponentDirty(emphasisStyle) || + IsComponentDirty(blurStyle) || + IsComponentDirty(selectStyle); } } public override void ClearVerticesDirty() @@ -860,16 +906,13 @@ namespace XCharts.Runtime symbol.ClearVerticesDirty(); lineStyle.ClearVerticesDirty(); itemStyle.ClearVerticesDirty(); - if (areaStyle != null) - areaStyle.ClearVerticesDirty(); - if (label != null) - label.ClearVerticesDirty(); - if (emphasisItemStyle != null) - emphasisItemStyle.ClearVerticesDirty(); - if (lineArrow != null) - lineArrow.ClearVerticesDirty(); - if (titleStyle != null) - titleStyle.ClearVerticesDirty(); + ClearVerticesDirty(areaStyle); + ClearVerticesDirty(label); + ClearVerticesDirty(emphasisStyle); + ClearVerticesDirty(blurStyle); + ClearVerticesDirty(selectStyle); + ClearVerticesDirty(lineArrow); + ClearVerticesDirty(titleStyle); } public override void ClearComponentDirty() @@ -883,18 +926,13 @@ namespace XCharts.Runtime symbol.ClearComponentDirty(); lineStyle.ClearComponentDirty(); itemStyle.ClearComponentDirty(); - if (areaStyle != null) - areaStyle.ClearComponentDirty(); - if (label != null) - label.ClearComponentDirty(); - if (emphasisLabel != null) - emphasisLabel.ClearComponentDirty(); - if (emphasisLabelLine != null) - emphasisLabelLine.ClearComponentDirty(); - if (lineArrow != null) - lineArrow.ClearComponentDirty(); - if (titleStyle != null) - titleStyle.ClearComponentDirty(); + ClearComponentDirty(areaStyle); + ClearComponentDirty(label); + ClearComponentDirty(emphasisStyle); + ClearComponentDirty(blurStyle); + ClearComponentDirty(selectStyle); + ClearComponentDirty(lineArrow); + ClearComponentDirty(titleStyle); } public override void SetAllDirty() diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs index a458a528..f996821d 100644 --- a/Runtime/Serie/SerieContext.cs +++ b/Runtime/Serie/SerieContext.cs @@ -84,6 +84,10 @@ namespace XCharts.Runtime /// public int vertCount; /// + /// theme的颜色索引 + /// + public int colorIndex; + /// /// 数据对应的位置坐标。 /// public List dataPoints = new List(); @@ -97,10 +101,6 @@ namespace XCharts.Runtime public List sortedData = new List(); public List rootData = new List(); /// - /// theme的颜色索引 - /// - public int colorIndex; - /// /// 绘制点 /// public List drawPoints = new List(); diff --git a/Runtime/Serie/SerieData.cs b/Runtime/Serie/SerieData.cs index bfa99c19..b61a2653 100644 --- a/Runtime/Serie/SerieData.cs +++ b/Runtime/Serie/SerieData.cs @@ -18,7 +18,7 @@ namespace XCharts.Runtime "m_ParentId", "m_Ignore", "m_Selected", - "m_Radius" + "m_Radius", }; public static Dictionary extraComponentMap = new Dictionary { { typeof(ItemStyle), "m_ItemStyles" }, @@ -28,9 +28,9 @@ namespace XCharts.Runtime { typeof(LineStyle), "m_LineStyles" }, { typeof(AreaStyle), "m_AreaStyles" }, { typeof(TitleStyle), "m_TitleStyles" }, - { typeof(EmphasisItemStyle), "m_EmphasisItemStyles" }, - { typeof(EmphasisLabelStyle), "m_EmphasisLabels" }, - { typeof(EmphasisLabelLine), "m_EmphasisLabelLines" }, + { typeof(EmphasisStyle), "m_EmphasisStyles" }, + { typeof(BlurStyle), "m_BlurStyles" }, + { typeof(SelectStyle), "m_SelectStyles" }, }; [SerializeField] private int m_Index; @@ -40,6 +40,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_Ignore; [SerializeField] private bool m_Selected; [SerializeField] private float m_Radius; + [SerializeField][Since("v3.2.0")] private SerieState m_State = SerieState.Auto; [SerializeField][IgnoreDoc] private List m_ItemStyles = new List(); [SerializeField][IgnoreDoc] private List m_Labels = new List(); [SerializeField][IgnoreDoc] private List m_LabelLines = new List(); @@ -47,9 +48,9 @@ namespace XCharts.Runtime [SerializeField][IgnoreDoc] private List m_LineStyles = new List(); [SerializeField][IgnoreDoc] private List m_AreaStyles = new List(); [SerializeField][IgnoreDoc] private List m_TitleStyles = new List(); - [SerializeField][IgnoreDoc] private List m_EmphasisItemStyles = new List(); - [SerializeField][IgnoreDoc] private List m_EmphasisLabels = new List(); - [SerializeField][IgnoreDoc] private List m_EmphasisLabelLines = new List(); + [SerializeField][IgnoreDoc] private List m_EmphasisStyles = new List(); + [SerializeField][IgnoreDoc] private List m_BlurStyles = new List(); + [SerializeField][IgnoreDoc] private List m_SelectStyles = new List(); [SerializeField] private List m_Data = new List(); [NonSerialized] public SerieDataContext context = new SerieDataContext(); @@ -97,6 +98,11 @@ namespace XCharts.Runtime /// public bool selected { get { return m_Selected; } set { m_Selected = value; } } /// + /// the state of serie data. + /// |数据项的默认状态。 + /// + public SerieState state { get { return m_State; } set { m_State = value; } } + /// /// 数据项图例名称。当数据项名称不为空时,图例名称即为系列名称;反之则为索引index。 /// /// @@ -119,17 +125,17 @@ namespace XCharts.Runtime public AreaStyle areaStyle { get { return m_AreaStyles.Count > 0 ? m_AreaStyles[0] : null; } } public TitleStyle titleStyle { get { return m_TitleStyles.Count > 0 ? m_TitleStyles[0] : null; } } /// - /// 高亮的图形样式 + /// 高亮状态的样式 /// - public EmphasisItemStyle emphasisItemStyle { get { return m_EmphasisItemStyles.Count > 0 ? m_EmphasisItemStyles[0] : null; } } + public EmphasisStyle emphasisStyle { get { return m_EmphasisStyles.Count > 0 ? m_EmphasisStyles[0] : null; } } /// - /// 高亮时的标签样式 + /// 淡出状态的样式。 /// - public EmphasisLabelStyle emphasisLabel { get { return m_EmphasisLabels.Count > 0 ? m_EmphasisLabels[0] : null; } } + public BlurStyle blurStyle { get { return m_BlurStyles.Count > 0 ? m_BlurStyles[0] : null; } } /// - /// 高亮时的标签引导线样式 + /// 选中状态的样式。 /// - public EmphasisLabelLine emphasisLabelLine { get { return m_EmphasisLabelLines.Count > 0 ? m_EmphasisLabelLines[0] : null; } } + public SelectStyle selectStyle { get { return m_SelectStyles.Count > 0 ? m_SelectStyles[0] : null; } } /// /// An arbitrary dimension data list of data item. @@ -152,12 +158,14 @@ namespace XCharts.Runtime get { return m_VertsDirty || - (labelLine != null && labelLine.vertsDirty) || - (itemStyle != null && itemStyle.vertsDirty) || - (symbol != null && symbol.vertsDirty) || - (lineStyle != null && lineStyle.vertsDirty) || - (areaStyle != null && areaStyle.vertsDirty) || - (emphasisItemStyle != null && emphasisItemStyle.vertsDirty); + IsVertsDirty(labelLine) || + IsVertsDirty(itemStyle) || + IsVertsDirty(symbol) || + IsVertsDirty(lineStyle) || + IsVertsDirty(areaStyle) || + IsVertsDirty(emphasisStyle) || + IsVertsDirty(blurStyle) || + IsVertsDirty(selectStyle); } } public override bool componentDirty @@ -165,35 +173,38 @@ namespace XCharts.Runtime get { return m_ComponentDirty || - (labelStyle != null && labelStyle.componentDirty) || - (labelLine != null && labelLine.componentDirty) || - (titleStyle != null && titleStyle.componentDirty) || - (emphasisLabel != null && emphasisLabel.componentDirty) || - (emphasisLabelLine != null && emphasisLabelLine.componentDirty); + IsComponentDirty(labelStyle) || + IsComponentDirty(labelLine) || + IsComponentDirty(titleStyle) || + IsComponentDirty(emphasisStyle) || + IsComponentDirty(blurStyle) || + IsComponentDirty(selectStyle); } } public override void ClearVerticesDirty() { base.ClearVerticesDirty(); - if (labelLine != null) labelLine.ClearVerticesDirty(); - if (itemStyle != null) itemStyle.ClearVerticesDirty(); - if (lineStyle != null) lineStyle.ClearVerticesDirty(); - if (areaStyle != null) areaStyle.ClearVerticesDirty(); - if (symbol != null) symbol.ClearVerticesDirty(); - if (emphasisItemStyle != null) emphasisItemStyle.ClearVerticesDirty(); + ClearVerticesDirty(labelLine); + ClearVerticesDirty(itemStyle); + ClearVerticesDirty(lineStyle); + ClearVerticesDirty(areaStyle); + ClearVerticesDirty(emphasisStyle); + ClearVerticesDirty(blurStyle); + ClearVerticesDirty(selectStyle); } public override void ClearComponentDirty() { base.ClearComponentDirty(); - if (labelLine != null) labelLine.ClearComponentDirty(); - if (itemStyle != null) itemStyle.ClearComponentDirty(); - if (lineStyle != null) lineStyle.ClearComponentDirty(); - if (areaStyle != null) areaStyle.ClearComponentDirty(); - if (symbol != null) symbol.ClearComponentDirty(); - if (emphasisLabel != null) emphasisLabel.ClearComponentDirty(); - if (emphasisLabelLine != null) emphasisLabelLine.ClearComponentDirty(); + ClearComponentDirty(labelLine); + ClearComponentDirty(itemStyle); + ClearComponentDirty(lineStyle); + ClearComponentDirty(areaStyle); + ClearComponentDirty(symbol); + ClearComponentDirty(emphasisStyle); + ClearComponentDirty(blurStyle); + ClearComponentDirty(selectStyle); } public void Reset() @@ -217,9 +228,9 @@ namespace XCharts.Runtime m_LineStyles.Clear(); m_AreaStyles.Clear(); m_TitleStyles.Clear(); - m_EmphasisItemStyles.Clear(); - m_EmphasisLabels.Clear(); - m_EmphasisLabelLines.Clear(); + m_EmphasisStyles.Clear(); + m_BlurStyles.Clear(); + m_SelectStyles.Clear(); } public T GetOrAddComponent() where T : ChildComponent, ISerieDataComponent @@ -247,23 +258,23 @@ namespace XCharts.Runtime m_LabelLines.Add(new LabelLine() { show = true }); return m_LabelLines[0]; } - else if (type == typeof(EmphasisItemStyle)) + else if (type == typeof(EmphasisStyle)) { - if (m_EmphasisItemStyles.Count == 0) - m_EmphasisItemStyles.Add(new EmphasisItemStyle() { show = true }); - return m_EmphasisItemStyles[0]; + if (m_EmphasisStyles.Count == 0) + m_EmphasisStyles.Add(new EmphasisStyle() { show = true }); + return m_EmphasisStyles[0]; } - else if (type == typeof(EmphasisLabelStyle)) + else if (type == typeof(BlurStyle)) { - if (m_EmphasisLabels.Count == 0) - m_EmphasisLabels.Add(new EmphasisLabelStyle() { show = true }); - return m_EmphasisLabels[0]; + if (m_BlurStyles.Count == 0) + m_BlurStyles.Add(new BlurStyle() { show = true }); + return m_BlurStyles[0]; } - else if (type == typeof(EmphasisLabelLine)) + else if (type == typeof(SelectStyle)) { - if (m_EmphasisLabelLines.Count == 0) - m_EmphasisLabelLines.Add(new EmphasisLabelLine() { show = true }); - return m_EmphasisLabelLines[0]; + if (m_SelectStyles.Count == 0) + m_SelectStyles.Add(new SelectStyle() { show = true }); + return m_SelectStyles[0]; } else if (type == typeof(SerieSymbol)) { @@ -301,9 +312,9 @@ namespace XCharts.Runtime m_Labels.Clear(); m_LabelLines.Clear(); m_Symbols.Clear(); - m_EmphasisItemStyles.Clear(); - m_EmphasisLabels.Clear(); - m_EmphasisLabelLines.Clear(); + m_EmphasisStyles.Clear(); + m_BlurStyles.Clear(); + m_SelectStyles.Clear(); m_LineStyles.Clear(); m_AreaStyles.Clear(); m_TitleStyles.Clear(); @@ -322,12 +333,12 @@ namespace XCharts.Runtime m_Labels.Clear(); else if (type == typeof(LabelLine)) m_LabelLines.Clear(); - else if (type == typeof(EmphasisItemStyle)) - m_EmphasisItemStyles.Clear(); - else if (type == typeof(EmphasisLabelStyle)) - m_EmphasisLabels.Clear(); - else if (type == typeof(EmphasisLabelLine)) - m_EmphasisLabelLines.Clear(); + else if (type == typeof(EmphasisStyle)) + m_EmphasisStyles.Clear(); + else if (type == typeof(BlurStyle)) + m_BlurStyles.Clear(); + else if (type == typeof(SelectStyle)) + m_SelectStyles.Clear(); else if (type == typeof(SerieSymbol)) m_Symbols.Clear(); else if (type == typeof(LineStyle)) diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 6f0f8ed9..2053240d 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -240,11 +240,9 @@ namespace XCharts.Runtime if (count == -1) count = serie.dataCount; var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - if (serieLabel == null) + if (serieLabel == null || !serieLabel.show) { - serieLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData); - if (serieLabel == null || !serieLabel.show) - return false; + return false; } var dataAutoColor = GetSerieDataAutoColor(serieData); @@ -375,14 +373,10 @@ namespace XCharts.Runtime { if (serieData.labelObject == null && serieData.context.dataLabels.Count <= 0) continue; - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - var emphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData); - var isHighlight = (serieData.context.highlight && emphasisLabel != null && emphasisLabel.show); + var currLabel = SerieHelper.GetSerieLabel(serie, serieData); var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension); - var currLabel = isHighlight && emphasisLabel != null ? emphasisLabel : serieLabel; if (serie.show && currLabel != null && - (currLabel.show || isHighlight) && serieData.context.canShowLabel && !isIgnore) { @@ -396,7 +390,7 @@ namespace XCharts.Runtime var labelObject = serieData.context.dataLabels[i]; var value = serieData.GetCurrData(i, dataChangeDuration); var content = string.IsNullOrEmpty(currLabel.formatter) ? - ChartCached.NumberToStr(value, serieLabel.numericFormatter) : + ChartCached.NumberToStr(value, currLabel.numericFormatter) : SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, currLabel, color); var offset = GetSerieDataLabelOffset(serieData, currLabel); @@ -418,7 +412,7 @@ namespace XCharts.Runtime var total = serie.GetDataTotal(defaultDimension, serieData); var color = chart.GetItemColor(serie, serieData); var content = string.IsNullOrEmpty(currLabel.formatter) ? - ChartCached.NumberToStr(value, serieLabel.numericFormatter) : + ChartCached.NumberToStr(value, currLabel.numericFormatter) : SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, currLabel, color); serieData.SetLabelActive(!isIgnore); @@ -492,7 +486,9 @@ namespace XCharts.Runtime public virtual Color GetSerieDataAutoColor(SerieData serieData) { var colorIndex = serie.useDataNameForColor ? serieData.index : serie.index; - return (Color) SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false, false); + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal, false); + return (Color) color; } protected void UpdateCoordSerieParams(ref List paramList, ref string title, @@ -522,7 +518,7 @@ namespace XCharts.Runtime param.dataCount = serie.dataCount; param.value = serieData.GetData(1); param.total = serie.yTotal; - param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); + param.color = chart.GetItemColor(serie, serieData); param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); param.itemFormatter = itemFormatter; param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); @@ -554,6 +550,8 @@ namespace XCharts.Runtime return; var colorIndex = chart.GetLegendRealShowNameIndex(serieData.name); + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal); var param = serie.context.param; param.serieName = serie.serieName; @@ -564,7 +562,7 @@ namespace XCharts.Runtime param.dataCount = serie.dataCount; param.value = serieData.GetData(param.dimension); param.total = SerieHelper.GetMaxData(serie, dimension); - param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); + param.color = color; param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); param.itemFormatter = itemFormatter; param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 073326ff..4afbba1a 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -242,105 +242,150 @@ namespace XCharts.Runtime } } + public static SerieState GetSerieState(Serie serie) + { + if (serie.highlight || serie.context.pointerEnter) return SerieState.Emphasis; + return serie.state; + } + + public static SerieState GetSerieState(Serie serie, SerieData serieData) + { + if (serieData == null || serieData.state == SerieState.Auto) return GetSerieState(serie); + if (serieData.context.highlight) return SerieState.Emphasis; + return serieData.state; + } + public static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, - bool highlight, bool useDefault = true) + SerieState state = SerieState.Auto, bool useDefault = false) { var color = ChartConst.clearColor32; - if (highlight) - { - var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData); - if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor)) - { - color = itemStyleEmphasis.backgroundColor; - ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity); - return color; - } - } - var itemStyle = GetItemStyle(serie, serieData); - if (!ChartHelper.IsClearColor(itemStyle.backgroundColor)) - { - color = itemStyle.backgroundColor; - if (highlight) color = ChartHelper.GetHighlightColor(color); - ChartHelper.SetColorOpacity(ref color, itemStyle.opacity); - return color; - } - else if (useDefault) + var stateStyle = GetStateStyle(serie, serieData, state); + if (stateStyle == null) + color = GetItemStyle(serie, serieData, SerieState.Normal).backgroundColor; + else + color = stateStyle.itemStyle.backgroundColor; + if (useDefault && ChartHelper.IsClearColor(color)) { color = theme.GetColor(index); - if (highlight) color = ChartHelper.GetHighlightColor(color); color.a = 50; - return color; } return color; } - public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true) + public static void GetItemColor(out Color32 color, out Color32 toColor, + Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) { - if (serie == null) - return ChartConst.clearColor32; - - ItemStyle itemStyle = null; - if (highlight) - itemStyle = GetItemStyleEmphasis(serie, serieData); - if (itemStyle == null) - itemStyle = GetItemStyle(serie, serieData); - - var color = ChartHelper.IsClearColor(itemStyle.color) ? - theme.GetColor(index) : - itemStyle.color; - - if (highlight) - color = ChartHelper.GetHighlightColor(color); - if (opacity) - ChartHelper.SetColorOpacity(ref color, itemStyle.opacity); - return color; - } - public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor) - { - if (serie == null) - return ChartConst.clearColor32; - - ItemStyle itemStyle = null; - if (highlight) - itemStyle = GetItemStyleEmphasis(serie, serieData); - if (itemStyle == null) - itemStyle = GetItemStyle(serie, serieData); - - var color = ChartHelper.IsClearColor(itemStyle.color0) ? - defaultColor : - itemStyle.color0; - - if (highlight) - color = ChartHelper.GetHighlightColor(color); - - ChartHelper.SetColorOpacity(ref color, itemStyle.opacity); - return color; + GetItemColor(out color, out toColor, serie, serieData, theme, serie.context.colorIndex, state, true); } - public static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true) + public static void GetItemColor(out Color32 color, out Color32 toColor, + Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto, bool opacity = true) { - if (serie == null) - return ChartConst.clearColor32; - - ItemStyle itemStyle = null; - if (highlight) - itemStyle = GetItemStyleEmphasis(serie, serieData); - if (itemStyle == null) - itemStyle = GetItemStyle(serie, serieData); - - var color = itemStyle.toColor; - if (ChartHelper.IsClearColor(color)) + color = ColorUtil.clearColor32; + toColor = ColorUtil.clearColor32; + if (serie == null) return; + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + if (stateStyle == null) { - color = ChartHelper.IsClearColor(itemStyle.color) ? - theme.GetColor(index) : - itemStyle.color; + var style = GetItemStyle(serie, serieData, SerieState.Normal); + GetColor(ref color, style.color, style.color, style.opacity, theme, index, opacity); + GetColor(ref toColor, style.toColor, color, style.opacity, theme, index, opacity); + switch (state) + { + case SerieState.Emphasis: + color = ChartHelper.GetHighlightColor(color); + toColor = ChartHelper.GetHighlightColor(toColor); + break; + case SerieState.Blur: + color = ChartHelper.GetBlurColor(color); + toColor = ChartHelper.GetBlurColor(toColor); + break; + case SerieState.Select: + color = ChartHelper.GetSelectColor(color); + toColor = ChartHelper.GetSelectColor(toColor); + break; + default: + break; + } } + else + { + GetColor(ref color, stateStyle.itemStyle.color, stateStyle.itemStyle.color, stateStyle.itemStyle.opacity, theme, index, opacity); + GetColor(ref toColor, stateStyle.itemStyle.toColor, color, stateStyle.itemStyle.opacity, theme, index, opacity); + } + } - if (highlight) - color = ChartHelper.GetHighlightColor(color); + public static void GetItemColor(out Color32 color, out Color32 toColor, out Color32 backgroundColor, + Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto, bool opacity = true) + { + color = ColorUtil.clearColor32; + toColor = ColorUtil.clearColor32; + backgroundColor = ColorUtil.clearColor32; + if (serie == null) return; + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + if (stateStyle == null) + { + var style = GetItemStyle(serie, serieData, SerieState.Normal); + GetColor(ref color, style.color, style.color, style.opacity, theme, index, opacity); + GetColor(ref toColor, style.toColor, color, style.opacity, theme, index, opacity); + backgroundColor = style.backgroundColor; + switch (state) + { + case SerieState.Emphasis: + color = ChartHelper.GetHighlightColor(color); + toColor = ChartHelper.GetHighlightColor(toColor); + break; + case SerieState.Blur: + color = ChartHelper.GetBlurColor(color); + toColor = ChartHelper.GetBlurColor(toColor); + break; + case SerieState.Select: + color = ChartHelper.GetSelectColor(color); + toColor = ChartHelper.GetSelectColor(toColor); + break; + default: + break; + } + } + else + { + backgroundColor = stateStyle.itemStyle.backgroundColor; + GetColor(ref color, stateStyle.itemStyle.color, stateStyle.itemStyle.color, stateStyle.itemStyle.opacity, theme, index, opacity); + GetColor(ref toColor, stateStyle.itemStyle.toColor, color, stateStyle.itemStyle.opacity, theme, index, opacity); + } + } - if (opacity) - ChartHelper.SetColorOpacity(ref color, itemStyle.opacity); + public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto, bool opacity = true) + { + var color = ColorUtil.clearColor32; + if (serie == null) return color; + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + if (stateStyle == null || !stateStyle.itemStyle.show) + { + var style = GetItemStyle(serie, serieData); + GetColor(ref color, style.color, style.color, style.opacity, theme, index, opacity); + switch (state) + { + case SerieState.Emphasis: + color = ChartHelper.GetHighlightColor(color); + break; + case SerieState.Blur: + color = ChartHelper.GetBlurColor(color); + break; + case SerieState.Select: + color = ChartHelper.GetSelectColor(color); + break; + default: + break; + } + } + else + { + GetColor(ref color, stateStyle.itemStyle.color, stateStyle.itemStyle.color, stateStyle.itemStyle.opacity, theme, index, opacity); + } return color; } @@ -370,66 +415,32 @@ namespace XCharts.Runtime } } - public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false) + public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { - if (highlight) + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + if (state == SerieState.Normal) { - var style = GetItemStyleEmphasis(serie, serieData); - if (style == null) return GetItemStyle(serie, serieData, false); - else return style; - } - else if (serie.IsPerformanceMode()) return serie.itemStyle; - else if (serieData != null && serieData.itemStyle != null) return serieData.itemStyle; - else return serie.itemStyle; - } - - public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData) - { - if (!serie.IsPerformanceMode() && serieData != null && serieData.emphasisItemStyle != null && serieData.emphasisItemStyle.show) - return serieData.emphasisItemStyle; - else if (serie.emphasisItemStyle != null && serie.emphasisItemStyle.show) return serie.emphasisItemStyle; - else return null; - } - - public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false) - { - if (serieData == null) return serie.label; - if (highlight) - { - if (!serie.IsPerformanceMode() && serieData.emphasisLabel != null && serieData.emphasisLabel.show) - return serieData.emphasisLabel; - else if (serie.emphasisLabel != null && serie.emphasisLabel.show) return serie.emphasisLabel; - else return serie.label; + return serieData != null && serieData.itemStyle != null? serieData.itemStyle : serie.itemStyle; } else { - if (!serie.IsPerformanceMode() && serieData.labelStyle != null) return serieData.labelStyle; - else return serie.label; + var stateStyle = GetStateStyle(serie, serieData, state); + return stateStyle == null?serie.itemStyle : stateStyle.itemStyle; } } - public static LabelStyle GetSerieEmphasisLabel(Serie serie, SerieData serieData) + public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { - if (!serie.IsPerformanceMode() && serieData.emphasisLabel != null && serieData.emphasisLabel.show) - return serieData.emphasisLabel; - else if (serie.emphasisLabel != null && serie.emphasisLabel.show) return serie.emphasisLabel; - else return null; + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + return stateStyle == null?serie.label : stateStyle.label; } - public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, bool highlight = false) + public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { - if (highlight) - { - if (!serie.IsPerformanceMode() && serieData.emphasisLabelLine != null && serieData.emphasisLabelLine.show) - return serieData.emphasisLabelLine; - else if (serie.emphasisLabelLine != null && serie.emphasisLabelLine.show) return serie.emphasisLabelLine; - else return serie.labelLine; - } - else - { - if (!serie.IsPerformanceMode() && serieData.labelLine != null) return serieData.labelLine; - else return serie.labelLine; - } + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + return stateStyle == null?serie.labelLine : stateStyle.labelLine; } public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData) @@ -456,92 +467,139 @@ namespace XCharts.Runtime else return serie.titleStyle; } - public static Color32 GetAreaColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight) + public static EmphasisStyle GetEmphasisStyle(Serie serie, SerieData serieData) { - Color32 color = ChartConst.clearColor32; - var areaStyle = GetAreaStyle(serie, serieData); - if (areaStyle == null || !areaStyle.show) - return color; - if (!ChartHelper.IsClearColor(areaStyle.color)) color = areaStyle.color; - else if (!ChartHelper.IsClearColor(serie.itemStyle.color)) color = serie.itemStyle.color; - else color = theme.GetColor(index); - ChartHelper.SetColorOpacity(ref color, areaStyle.opacity); - if (highlight) - { - if (!ChartHelper.IsClearColor(areaStyle.highlightColor)) - color = areaStyle.highlightColor; - else - color = ChartHelper.GetHighlightColor(color); - } - return color; + if (serieData != null && serieData.emphasisStyle != null) return serieData.emphasisStyle; + else return serie.emphasisStyle; } - public static Color32 GetAreaToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight) + public static BlurStyle GetBlurStyle(Serie serie, SerieData serieData) { - Color32 color = ChartConst.clearColor32; - var areaStyle = GetAreaStyle(serie, serieData); - if (areaStyle == null || !areaStyle.show) - return color; - if (!ChartHelper.IsClearColor(areaStyle.toColor)) color = areaStyle.toColor; - else if (!ChartHelper.IsClearColor(serie.itemStyle.toColor)) color = serie.itemStyle.toColor; - else color = theme.GetColor(index); - ChartHelper.SetColorOpacity(ref color, areaStyle.opacity); - if (highlight) - { - if (!ChartHelper.IsClearColor(areaStyle.highlightToColor)) - color = areaStyle.highlightToColor; - else - color = ChartHelper.GetHighlightColor(color); - } - return color; + if (serieData != null && serieData.blurStyle != null) return serieData.blurStyle; + else return serie.blurStyle; + } + public static SelectStyle GetSelectStyle(Serie serie, SerieData serieData) + { + if (serieData != null && serieData.selectStyle != null) return serieData.selectStyle; + else return serie.selectStyle; } - public static Color32 GetLineColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight) + public static StateStyle GetStateStyle(Serie serie, SerieData serieData, SerieState state) { - Color32 color = ChartConst.clearColor32; - var lineStyle = GetLineStyle(serie, serieData); - if (highlight) + switch (state) { - var itemStyleEmphasis = GetItemStyleEmphasis(serie, null); - if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color)) + case SerieState.Emphasis: + return GetEmphasisStyle(serie, serieData); + case SerieState.Blur: + return GetBlurStyle(serie, serieData); + case SerieState.Select: + return GetSelectStyle(serie, serieData); + default: + return null; + } + } + + public static bool GetAreaColor(out Color32 color, out Color32 toColor, + Serie serie, SerieData serieData, ThemeStyle theme, int index) + { + color = ChartConst.clearColor32; + toColor = ChartConst.clearColor32; + 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; + GetColor(ref color, areaStyle.color, serie.itemStyle.color, areaStyle.opacity, theme, index); + GetColor(ref toColor, areaStyle.toColor, color, areaStyle.opacity, theme, index); + switch (state) { - color = itemStyleEmphasis.color; - ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity); - return color; + case SerieState.Emphasis: + color = ChartHelper.GetHighlightColor(color); + toColor = ChartHelper.GetHighlightColor(toColor); + break; + case SerieState.Blur: + color = ChartHelper.GetBlurColor(color); + toColor = ChartHelper.GetBlurColor(toColor); + break; + case SerieState.Select: + color = ChartHelper.GetSelectColor(color); + toColor = ChartHelper.GetSelectColor(toColor); + break; + default: + break; } } - if (!ChartHelper.IsClearColor(lineStyle.color)) color = lineStyle.color; - else if (!ChartHelper.IsClearColor(serie.itemStyle.color)) color = serie.itemStyle.GetColor(); - if (ChartHelper.IsClearColor(color)) color = theme.GetColor(index); - ChartHelper.SetColorOpacity(ref color, lineStyle.opacity); - if (highlight) color = ChartHelper.GetHighlightColor(color); - return color; + else + { + if (stateStyle.areaStyle.show) + { + 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); + } + else + { + return false; + } + } + return true; } - public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight) + public static Color32 GetLineColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto) { - var itemStyle = GetItemStyle(serie, serieData, highlight); + Color32 color = ChartConst.clearColor32; + if (state == SerieState.Auto) + state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + if (stateStyle == null) + { + var lineStyle = GetLineStyle(serie, serieData); + GetColor(ref color, lineStyle.color, serie.itemStyle.color, lineStyle.opacity, theme, index); + switch (state) + { + case SerieState.Emphasis: + return ChartHelper.GetHighlightColor(color); + case SerieState.Blur: + return ChartHelper.GetBlurColor(color); + case SerieState.Select: + return ChartHelper.GetSelectColor(color); + default: + return color; + } + } + else + { + GetColor(ref color, stateStyle.lineStyle.color, stateStyle.itemStyle.color, stateStyle.lineStyle.opacity, theme, index); + return color; + } + } + + private static void GetColor(ref Color32 color, Color32 checkColor, Color32 itemColor, + float opacity, ThemeStyle theme, int colorIndex, bool setOpacity = true) + { + if (!ChartHelper.IsClearColor(checkColor)) color = checkColor; + else if (!ChartHelper.IsClearColor(itemColor)) color = itemColor; + if (ChartHelper.IsClearColor(color)) color = theme.GetColor(colorIndex); + if (setOpacity) ChartHelper.SetColorOpacity(ref color, opacity); + } + + public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) + { + var itemStyle = GetItemStyle(serie, serieData, state); if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth; else return serie.lineStyle.GetWidth(theme.serie.lineWidth) * 2; } - public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight) + public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) { - var itemStyle = GetItemStyle(serie, serieData, highlight); + var itemStyle = GetItemStyle(serie, serieData, state); if (itemStyle != null && !ChartHelper.IsClearColor(itemStyle.borderColor)) return itemStyle.borderColor; else return serie.itemStyle.borderColor; } - public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, float defaultWidth) + public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { - var itemStyle = GetItemStyle(serie, serieData, highlight); - if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth; - else return defaultWidth; - } - - public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight) - { - var itemStyle = GetItemStyle(serie, serieData, highlight); + var itemStyle = GetItemStyle(serie, serieData, state); if (itemStyle != null) return itemStyle.cornerRadius; else return null; } diff --git a/Runtime/Serie/SeriesHelper.cs b/Runtime/Serie/SeriesHelper.cs index 71da5b81..5b191d44 100644 --- a/Runtime/Serie/SeriesHelper.cs +++ b/Runtime/Serie/SeriesHelper.cs @@ -106,7 +106,9 @@ namespace XCharts.Runtime break; } } - return SerieHelper.GetItemColor(destSerie, destSerieData, chart.theme, index, false); + Color32 color, toColor; + SerieHelper.GetItemColor(out color, out toColor, destSerie, destSerieData, chart.theme, index, SerieState.Normal); + return color; } /// From b3b0c0b3aa8cab9077575ad1556098581d4cf270 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 27 Jul 2022 08:00:11 +0800 Subject: [PATCH 07/27] v3.2.0 --- Runtime/Internal/XChartsMgr.cs | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index 9a839481..07b914c7 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -20,7 +20,7 @@ namespace XCharts.Runtime [ExecuteInEditMode] public static class XChartsMgr { - public static readonly string version = "3.1.0"; + public static readonly string version = "3.2.0"; public static readonly int versionDate = 20220712; public static string fullVersion { get { return version + "-" + versionDate; } } diff --git a/package.json b/package.json index 146a1bd0..bc877903 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.monitor1394.xcharts", "displayName": "XCharts", - "version": "3.1.0", + "version": "3.2.0", "date": "20220712", "checkdate": "20220712", "desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!", From 5b2b2d40592508a9134dda83b6cf82a47d7dc840 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 27 Jul 2022 08:00:57 +0800 Subject: [PATCH 08/27] [feature][symbol] support symbol settings for StateStyle --- CHANGELOG.md | 4 +- Editor/ChildComponents/SerieSymbolDrawer.cs | 2 - Editor/ChildComponents/StateStyleDrawer.cs | 1 + Examples/Example50_Scatter.cs | 6 -- Runtime/Component/Child/SerieSymbl.cs | 69 ------------- Runtime/Component/Mark/MarkLineHandler.cs | 7 +- Runtime/Component/State/StateStyle.cs | 15 ++- Runtime/Internal/Utilities/ChartHelper.cs | 4 +- Runtime/Serie/Line/LineHandler.GridCoord.cs | 94 ++++++++--------- Runtime/Serie/Line/LineHandler.PolarCoord.cs | 30 +++--- Runtime/Serie/Line/LineHelper.cs | 2 - Runtime/Serie/Line/SimplifiedLineHandler.cs | 54 +++++----- Runtime/Serie/Radar/RadarHandler.cs | 36 +++---- Runtime/Serie/Scatter/BaseScatterHandler.cs | 48 ++++----- Runtime/Serie/SerieData.cs | 1 + Runtime/Serie/SerieHelper.cs | 101 +++++++++++++++---- 16 files changed, 216 insertions(+), 258 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2153382..3c9e1094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,9 +57,11 @@ ## master +* (2022.07.24) 增加`StateStyle`的`Symbol`用于配置状态下的标记样式 +* (2022.07.24) 去掉`SerieSymbol`的`selectedSize`配置 * (2022.07.24) 增加`Serie`和`SerieData`的`state`设置默认状态 * (2022.07.22) 增加`Serie`的三种状态`EmphasisStyle`,`BlurStyle`,`SelectStyle` -* (2022.07.22) 去掉`AreaStyle`的`m_HighlightColor`和`m_HighlightToColor`配置 +* (2022.07.22) 去掉`AreaStyle`的`highlightColor`和`highlightToColor`配置 * (2022.07.22) 去掉`Emphasis`,`EmphasisItemStyle`,`EmphasisLabelStyle`,`EmphasisLabelLine`组件 * (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持 * (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 diff --git a/Editor/ChildComponents/SerieSymbolDrawer.cs b/Editor/ChildComponents/SerieSymbolDrawer.cs index 0f3e214a..23639c5b 100644 --- a/Editor/ChildComponents/SerieSymbolDrawer.cs +++ b/Editor/ChildComponents/SerieSymbolDrawer.cs @@ -31,12 +31,10 @@ namespace XCharts.Editor { case SymbolSizeType.Custom: PropertyField(prop, "m_Size"); - PropertyField(prop, "m_SelectedSize"); break; case SymbolSizeType.FromData: PropertyField(prop, "m_DataIndex"); PropertyField(prop, "m_DataScale"); - PropertyField(prop, "m_SelectedDataScale"); break; case SymbolSizeType.Function: break; diff --git a/Editor/ChildComponents/StateStyleDrawer.cs b/Editor/ChildComponents/StateStyleDrawer.cs index ca0f746e..31eee8fc 100644 --- a/Editor/ChildComponents/StateStyleDrawer.cs +++ b/Editor/ChildComponents/StateStyleDrawer.cs @@ -16,6 +16,7 @@ namespace XCharts.Editor { ++EditorGUI.indentLevel; OnCustomGUI(prop); + PropertyField(prop, "m_Symbol"); PropertyField(prop, "m_ItemStyle"); PropertyField(prop, "m_Label"); PropertyField(prop, "m_LabelLine"); diff --git a/Examples/Example50_Scatter.cs b/Examples/Example50_Scatter.cs index 74b8d6c3..80f8f967 100644 --- a/Examples/Example50_Scatter.cs +++ b/Examples/Example50_Scatter.cs @@ -18,7 +18,6 @@ namespace XCharts.Example foreach (var serie in chart.series) { serie.symbol.sizeFunction = SymbolSize; - serie.symbol.selectedSizeFunction = SymbolSelectedSize; } } @@ -26,10 +25,5 @@ namespace XCharts.Example { return (float) (Math.Sqrt(data[2]) / 6e2); } - - float SymbolSelectedSize(List data) - { - return (float) (Math.Sqrt(data[2]) / 5e2); - } } } \ No newline at end of file diff --git a/Runtime/Component/Child/SerieSymbl.cs b/Runtime/Component/Child/SerieSymbl.cs index 34865a8d..7cdc1013 100644 --- a/Runtime/Component/Child/SerieSymbl.cs +++ b/Runtime/Component/Child/SerieSymbl.cs @@ -34,12 +34,9 @@ namespace XCharts.Runtime public class SerieSymbol : SymbolStyle, ISerieDataComponent { [SerializeField] private SymbolSizeType m_SizeType = SymbolSizeType.Custom; - [SerializeField] private float m_SelectedSize = 0f; [SerializeField] private int m_DataIndex = 1; [SerializeField] private float m_DataScale = 1; - [SerializeField] private float m_SelectedDataScale = 1.5f; [SerializeField] private SymbolSizeFunction m_SizeFunction; - [SerializeField] private SymbolSizeFunction m_SelectedSizeFunction; [SerializeField] private int m_StartIndex; [SerializeField] private int m_Interval; [SerializeField] private bool m_ForceShowLast = false; @@ -49,12 +46,9 @@ namespace XCharts.Runtime { base.Reset(); m_SizeType = SymbolSizeType.Custom; - m_SelectedSize = 0f; m_DataIndex = 1; m_DataScale = 1; - m_SelectedDataScale = 1.5f; m_SizeFunction = null; - m_SelectedSizeFunction = null; m_StartIndex = 0; m_Interval = 0; m_ForceShowLast = false; @@ -71,15 +65,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); } } /// - /// the size of selected symbol. - /// |被选中的标记的大小。 - /// - public float selectedSize - { - get { return m_SelectedSize; } - set { if (PropertyUtil.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); } - } - /// /// whitch data index is when the sizeType assined as FromData. /// |当sizeType指定为FromData时,指定的数据源索引。 /// @@ -98,15 +83,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); } } /// - /// the scale of selected data when sizeType assined as FromData. - /// |当sizeType指定为FromData时,指定的高亮倍数系数。 - /// - public float selectedDataScale - { - get { return m_SelectedDataScale; } - set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); } - } - /// /// the function of size when sizeType assined as Function. /// |当sizeType指定为Function时,指定的委托函数。 /// @@ -116,15 +92,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetClass(ref m_SizeFunction, value)) SetVerticesDirty(); } } /// - /// the function of size when sizeType assined as Function. - /// |当sizeType指定为Function时,指定的高亮委托函数。 - /// - public SymbolSizeFunction selectedSizeFunction - { - get { return m_SelectedSizeFunction; } - set { if (PropertyUtil.SetClass(ref m_SelectedSizeFunction, value)) SetVerticesDirty(); } - } - /// /// the index start to show symbol. /// |开始显示图形标记的索引。 /// @@ -187,42 +154,6 @@ namespace XCharts.Runtime } } - /// - /// 根据sizeType获得高亮时的标记大小 - /// - /// - /// - public float GetSelectedSize(List data, float themeSelectedSize) - { - switch (m_SizeType) - { - case SymbolSizeType.Custom: - - return selectedSize == 0 ? themeSelectedSize : selectedSize; - - case SymbolSizeType.FromData: - - if (data != null && dataIndex >= 0 && dataIndex < data.Count) - { - return (float) data[dataIndex] * m_SelectedDataScale; - } - else - { - return selectedSize == 0 ? themeSelectedSize : selectedSize; - } - - case SymbolSizeType.Function: - - if (data != null && selectedSizeFunction != null) - return selectedSizeFunction(data); - else - return selectedSize == 0 ? themeSelectedSize : selectedSize; - - default: - return selectedSize == 0 ? themeSelectedSize : selectedSize; - } - } - public bool ShowSymbol(int dataIndex, int dataCount) { if (!show) diff --git a/Runtime/Component/Mark/MarkLineHandler.cs b/Runtime/Component/Mark/MarkLineHandler.cs index 813b294e..55d211df 100644 --- a/Runtime/Component/Mark/MarkLineHandler.cs +++ b/Runtime/Component/Mark/MarkLineHandler.cs @@ -242,9 +242,10 @@ namespace XCharts.Runtime private void DrawMarkLineSymbol(VertexHelper vh, SymbolStyle symbol, Serie serie, GridCoord grid, ThemeStyle theme, Vector3 pos, Vector3 startPos, Color32 lineColor) { - var tickness = SerieHelper.GetSymbolBorder(serie, null, theme); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, null, theme); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, null); + float tickness = 0f; + float[] cornerRadius = null; + Color32 borderColor; + SerieHelper.GetSymbolInfo(out borderColor, out tickness, out cornerRadius, serie, null, chart.theme); chart.DrawClipSymbol(vh, symbol.type, symbol.size, tickness, pos, lineColor, lineColor, ColorUtil.clearColor32, borderColor, symbol.gap, true, cornerRadius, grid, startPos); } diff --git a/Runtime/Component/State/StateStyle.cs b/Runtime/Component/State/StateStyle.cs index 9c1304ce..847108ce 100644 --- a/Runtime/Component/State/StateStyle.cs +++ b/Runtime/Component/State/StateStyle.cs @@ -16,6 +16,7 @@ namespace XCharts.Runtime [SerializeField] private ItemStyle m_ItemStyle = new ItemStyle(); [SerializeField] private LineStyle m_LineStyle = new LineStyle(); [SerializeField] private AreaStyle m_AreaStyle = new AreaStyle(); + [SerializeField] private SerieSymbol m_Symbol = new SerieSymbol(); public void Reset() { @@ -23,6 +24,7 @@ namespace XCharts.Runtime m_Label.Reset(); m_LabelLine.Reset(); m_ItemStyle.Reset(); + m_Symbol.Reset(); } /// @@ -73,6 +75,14 @@ namespace XCharts.Runtime get { return m_AreaStyle; } set { if (PropertyUtil.SetClass(ref m_AreaStyle, value, true)) SetVerticesDirty(); } } + /// + /// 标记样式。 + /// + public SerieSymbol symbol + { + get { return m_Symbol; } + set { if (PropertyUtil.SetClass(ref m_Symbol, value, true)) SetVerticesDirty(); } + } public override bool vertsDirty { @@ -82,7 +92,8 @@ namespace XCharts.Runtime m_Label.vertsDirty || m_ItemStyle.vertsDirty || m_LineStyle.vertsDirty || - m_AreaStyle.vertsDirty; + m_AreaStyle.vertsDirty || + m_Symbol.vertsDirty; } } @@ -102,12 +113,14 @@ namespace XCharts.Runtime m_ItemStyle.ClearVerticesDirty(); m_LineStyle.ClearVerticesDirty(); m_AreaStyle.ClearVerticesDirty(); + m_Symbol.ClearVerticesDirty(); } public override void ClearComponentDirty() { base.ClearComponentDirty(); m_Label.ClearComponentDirty(); + m_Symbol.ClearComponentDirty(); } } } \ No newline at end of file diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 1c3f8968..1ecebe83 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -836,7 +836,7 @@ namespace XCharts.Runtime } } - public static Color32 GetHighlightColor(Color32 color, float rate = 0.8f) + public static Color32 GetHighlightColor(Color32 color, float rate = 1.2f) { var newColor = color; newColor.r = (byte) (color.r * rate); @@ -852,7 +852,7 @@ namespace XCharts.Runtime return newColor; } - public static Color32 GetSelectColor(Color32 color, float rate = 0.7f) + public static Color32 GetSelectColor(Color32 color, float rate = 0.8f) { var newColor = color; newColor.r = (byte) (color.r * rate); diff --git a/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Runtime/Serie/Line/LineHandler.GridCoord.cs index f1b6c6f8..55938982 100644 --- a/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -56,70 +56,62 @@ namespace XCharts.Runtime } m_LastCheckContextFlag = needCheck; var themeSymbolSize = chart.theme.serie.lineSymbolSize; - var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize; var needInteract = false; if (m_LegendEnter) - { - serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate); - for (int i = 0; i < serie.dataCount; i++) - { - var serieData = serie.data[i]; - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - - serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); - } - } - else if (serie.context.isTriggerByAxis) { serie.context.pointerEnter = true; serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate); for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.data[i]; - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSize = symbol.GetSize(serieData.data, themeSymbolSize); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - - if (i == serie.context.pointerItemDataIndex) + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, SerieState.Emphasis); + serieData.context.highlight = true; + serieData.interact.SetValue(ref needInteract, size); + } + } + else if (serie.context.isTriggerByAxis) + { + serie.context.pointerEnter = false; + serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate); + for (int i = 0; i < serie.dataCount; i++) + { + var serieData = serie.data[i]; + var highlight = i == serie.context.pointerItemDataIndex; + serieData.context.highlight = highlight; + var state = SerieHelper.GetSerieState(serie, serieData, true); + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, state); + serieData.interact.SetValue(ref needInteract, size); + if (highlight) { - serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); - } - else - { - serieData.context.highlight = false; - serieData.interact.SetValue(ref needInteract, symbolSize); + serie.context.pointerEnter = true; + serie.context.pointerItemDataIndex = i; } } } else { + var lastIndex = serie.context.pointerItemDataIndex; serie.context.pointerItemDataIndex = -1; serie.context.pointerEnter = false; for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.data[i]; - serieData.index = i; var dist = Vector3.Distance(chart.pointerPos, serieData.context.position); - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSize = symbol.GetSize(serieData.data, themeSymbolSize); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - if (dist <= symbolSelectedSize) + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize); + var highlight = dist <= size; + serieData.context.highlight = highlight; + var state = SerieHelper.GetSerieState(serie, serieData, true); + size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, state); + serieData.interact.SetValue(ref needInteract, size); + if (highlight) { - serie.context.pointerItemDataIndex = serieData.index; serie.context.pointerEnter = true; + serie.context.pointerItemDataIndex = serieData.index; serie.interact.SetValue(ref needInteract, lineWidth, true); - serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); - } - else - { - serieData.context.highlight = false; - serieData.interact.SetValue(ref needInteract, symbolSize); } } + if (lastIndex != serie.context.pointerItemDataIndex) + needInteract = true; } if (needInteract) { @@ -157,8 +149,8 @@ namespace XCharts.Runtime continue; if (serieData.context.isClip) continue; - - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); + var state = SerieHelper.GetSerieState(serie, serieData, true); + var symbol = SerieHelper.GetSerieSymbol(serie, serieData, state); if (!symbol.show || !symbol.ShowSymbol(i, count)) continue; @@ -175,30 +167,24 @@ namespace XCharts.Runtime if (ChartHelper.IsIngore(pos)) continue; - var highlight = serie.data[i].context.highlight || serie.highlight; - var symbolSize = highlight ? - theme.serie.lineSymbolSelectedSize : - theme.serie.lineSymbolSize; + var symbolSize = 0f; if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting)) { - symbolSize = highlight ? - symbol.GetSelectedSize(serieData.data, symbolSize) : - symbol.GetSize(serieData.data, symbolSize); + symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state); serieData.interact.SetValue(ref interacting, symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize); } - var state = SerieHelper.GetSerieState(serie, serieData); - Color32 symbolColor, symbolToColor,symbolEmptyColor; - SerieHelper.GetItemColor(out symbolColor, out symbolToColor,out symbolEmptyColor, serie, serieData, theme, serie.index, state); + float symbolBorder = 0f; + float[] cornerRadius = null; + Color32 symbolColor, symbolToColor, symbolEmptyColor, borderColor; + SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, theme, serie.index); + SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, null, chart.theme, state); if (isVisualMapGradient) { symbolColor = VisualMapHelper.GetLineGradientColor(visualMap, pos, m_SerieGrid, axis, relativedAxis, symbolColor); symbolToColor = symbolColor; } - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, state); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, state); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); chart.DrawClipSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, clip, cornerRadius, m_SerieGrid, i > 0 ? serie.context.dataPoints[i - 1] : m_SerieGrid.context.position); diff --git a/Runtime/Serie/Line/LineHandler.PolarCoord.cs b/Runtime/Serie/Line/LineHandler.PolarCoord.cs index 24410e0c..9b1c5ae9 100644 --- a/Runtime/Serie/Line/LineHandler.PolarCoord.cs +++ b/Runtime/Serie/Line/LineHandler.PolarCoord.cs @@ -47,21 +47,19 @@ namespace XCharts.Runtime } m_LastCheckContextFlag = needCheck; var themeSymbolSize = chart.theme.serie.lineSymbolSize; - var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize; lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); var needInteract = false; if (m_LegendEnter) { + serie.context.pointerEnter = true; serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate); for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.data[i]; - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, SerieState.Emphasis); serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); + serieData.interact.SetValue(ref needInteract, size); } } else @@ -205,27 +203,23 @@ namespace XCharts.Runtime continue; var count = serie.dataCount; - Color32 symbolColor, symbolToColor,symbolEmptyColor; + float symbolBorder = 0f; + float[] cornerRadius = null; + Color32 symbolColor, symbolToColor, symbolEmptyColor, borderColor; for (int i = 0; i < count; i++) { var serieData = serie.GetSerieData(i); - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); + var state = SerieHelper.GetSerieState(serie, serieData, true); + var symbol = SerieHelper.GetSerieSymbol(serie, serieData, state); if (ChartHelper.IsIngore(serieData.context.position)) continue; - bool highlight = serieData.context.highlight || serie.highlight; - if ((!symbol.show || !symbol.ShowSymbol(i, count) || serie.IsPerformanceMode()) && - !serieData.context.highlight) + if (!symbol.show || !symbol.ShowSymbol(i, count)) continue; - var symbolSize = highlight ? - symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSize) : - symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize); - var state = SerieHelper.GetSerieState(serie, serieData); - SerieHelper.GetItemColor(out symbolColor, out symbolToColor,out symbolEmptyColor, serie, serieData, chart.theme, n); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, state); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, state); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); + var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state); + SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, n); + SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, null, chart.theme, state); symbolSize = serie.animation.GetSysmbolSize(symbolSize); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serieData.context.position, diff --git a/Runtime/Serie/Line/LineHelper.cs b/Runtime/Serie/Line/LineHelper.cs index d99132a1..20942d18 100644 --- a/Runtime/Serie/Line/LineHelper.cs +++ b/Runtime/Serie/Line/LineHelper.cs @@ -261,8 +261,6 @@ namespace XCharts.Runtime var isY = axis is YAxis; var isVisualMapGradient = VisualMapHelper.IsNeedLineGradient(visualMap); var isLineStyleGradient = serie.lineStyle.IsNeedGradient(); - - //var highlight = serie.highlight || serie.context.pointerEnter; var lineColor = SerieHelper.GetLineColor(serie, null, theme, serie.context.colorIndex); var lastDataIsIgnore = datas[0].isIgnoreBreak; diff --git a/Runtime/Serie/Line/SimplifiedLineHandler.cs b/Runtime/Serie/Line/SimplifiedLineHandler.cs index 49bb49f0..73c9c82b 100644 --- a/Runtime/Serie/Line/SimplifiedLineHandler.cs +++ b/Runtime/Serie/Line/SimplifiedLineHandler.cs @@ -73,15 +73,14 @@ namespace XCharts.Runtime var needInteract = false; if (m_LegendEnter) { + serie.context.pointerEnter = true; serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate); for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.data[i]; - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, SerieState.Emphasis); serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); + serieData.interact.SetValue(ref needInteract, size); } } else if (serie.context.isTriggerByAxis) @@ -91,47 +90,42 @@ namespace XCharts.Runtime for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.data[i]; - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSize = symbol.GetSize(serieData.data, themeSymbolSize); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - - if (i == serie.context.pointerItemDataIndex) + var highlight = i == serie.context.pointerItemDataIndex; + serieData.context.highlight = highlight; + var state = SerieHelper.GetSerieState(serie, serieData, true); + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, state); + serieData.interact.SetValue(ref needInteract, size); + if (highlight) { - serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); - } - else - { - serieData.context.highlight = false; - serieData.interact.SetValue(ref needInteract, symbolSize); + serie.context.pointerEnter = true; + serie.context.pointerItemDataIndex = i; } } } else { + var lastIndex = serie.context.pointerItemDataIndex; serie.context.pointerItemDataIndex = -1; serie.context.pointerEnter = false; - foreach (var serieData in serie.data) + for (int i = 0; i < serie.dataCount; i++) { + var serieData = serie.data[i]; var dist = Vector3.Distance(chart.pointerPos, serieData.context.position); - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSize = symbol.GetSize(serieData.data, themeSymbolSize); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); - - if (dist <= symbolSelectedSize) + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize); + var highlight = dist <= size; + serieData.context.highlight = highlight; + var state = SerieHelper.GetSerieState(serie, serieData, true); + size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, state); + serieData.interact.SetValue(ref needInteract, size); + if (highlight) { - serie.context.pointerItemDataIndex = serieData.index; serie.context.pointerEnter = true; + serie.context.pointerItemDataIndex = serieData.index; serie.interact.SetValue(ref needInteract, lineWidth, true); - serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); - } - else - { - serieData.context.highlight = false; - serieData.interact.SetValue(ref needInteract, symbolSize); } } + if (lastIndex != serie.context.pointerItemDataIndex) + needInteract = true; } if (needInteract) { diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 17c587dc..3d91c852 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -224,10 +224,10 @@ namespace XCharts.Runtime { continue; } + var serieState = SerieHelper.GetSerieState(serie, serieData, true); var lineStyle = SerieHelper.GetLineStyle(serie, serieData); - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var isHighlight = serieData.context.highlight; - var serieState = SerieHelper.GetSerieState(serie, serieData); + var symbol = SerieHelper.GetSerieSymbol(serie, serieData, serieState); + var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex); var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex); @@ -300,25 +300,21 @@ namespace XCharts.Runtime if (symbol.show && symbol.type != SymbolType.None) { + float symbolBorder = 0f; + float[] cornerRadius = null; + Color32 symbolColor, symbolToColor, symbolEmptyColor, borderColor; for (int m = 0; m < serieData.context.dataPoints.Count; m++) { var point = serieData.context.dataPoints[m]; - var symbolSize = isHighlight ? - symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize) : - symbol.GetSize(null, chart.theme.serie.lineSymbolSize); + var symbolSize = 0f; if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting)) { - symbolSize = isHighlight ? - symbol.GetSelectedSize(serieData.data, symbolSize) : - symbol.GetSize(serieData.data, symbolSize); + symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, serieState); serieData.interact.SetValue(ref interacting, symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize); } - Color32 symbolColor, symbolToColor, symbolEmptyColor; SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, j, serieState); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, serieState); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, serieState); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, serieState); + SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, serieState); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius); } @@ -451,20 +447,18 @@ namespace XCharts.Runtime } if (serie.symbol.show && serie.symbol.type != SymbolType.None) { + float symbolBorder = 0f; + float[] cornerRadius = null; + Color32 symbolColor, symbolToColor, symbolEmptyColor, borderColor; for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; if (!serieData.show) continue; var state = SerieHelper.GetSerieState(serie, serieData); var serieIndex = serieData.index; - var symbolSize = state == SerieState.Emphasis ? - serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize) : - serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize); - Color32 symbolColor, symbolToColor,symbolEmptyColor; - SerieHelper.GetItemColor(out symbolColor, out symbolToColor,out symbolEmptyColor, serie, serieData, chart.theme, serieIndex, state); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, state); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, state); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); + var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state); + SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, serieIndex, state); + SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state); if (!radar.IsInIndicatorRange(j, serieData.GetData(1))) { symbolColor = radar.outRangeColor; diff --git a/Runtime/Serie/Scatter/BaseScatterHandler.cs b/Runtime/Serie/Scatter/BaseScatterHandler.cs index 1958afc0..f1a0cab4 100644 --- a/Runtime/Serie/Scatter/BaseScatterHandler.cs +++ b/Runtime/Serie/Scatter/BaseScatterHandler.cs @@ -82,22 +82,21 @@ namespace XCharts.Runtime for (int i = serie.dataCount - 1; i >= 0; i--) { var serieData = serie.data[i]; - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSize = symbol.GetSize(serieData.data, themeSymbolSize); - var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize); + var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize); if (m_LegendEnter || (!needHideAll && Vector3.Distance(serieData.context.position, chart.pointerPos) <= symbolSize)) { serie.context.pointerItemDataIndex = i; serie.context.pointerEnter = true; serieData.context.highlight = true; - serieData.interact.SetValue(ref needInteract, symbolSelectedSize); } else { serieData.context.highlight = false; - serieData.interact.SetValue(ref needInteract, symbolSize); } + var state = SerieHelper.GetSerieState(serie, serieData, true); + symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize, state); + serieData.interact.SetValue(ref needInteract, symbolSize); } if (needInteract) { @@ -144,19 +143,19 @@ namespace XCharts.Runtime serie.containerIndex = m_Grid.index; serie.containterInstanceId = m_Grid.instanceId; + float symbolBorder = 0f; + float[] cornerRadius = null; + Color32 color, toColor, emptyColor, borderColor; foreach (var serieData in dataList) { var symbol = SerieHelper.GetSerieSymbol(serie, serieData); if (!symbol.ShowSymbol(serieData.index, maxCount)) continue; - var highlight = serie.highlight || serieData.context.highlight; - var state = SerieHelper.GetSerieState(serie, serieData); - Color32 color, toColor, emptyColor; + var state = SerieHelper.GetSerieState(serie, serieData, true); + SerieHelper.GetItemColor(out color, out toColor, out emptyColor, serie, serieData, chart.theme, colorIndex, state); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, state); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, state); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); + SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state); double xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse); double yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse); @@ -175,14 +174,10 @@ namespace XCharts.Runtime serie.context.dataPoints.Add(pos); serieData.context.position = pos; var datas = serieData.data; - var symbolSize = serie.highlight || serieData.context.highlight ? - theme.serie.scatterSymbolSelectedSize : - theme.serie.scatterSymbolSize; + var symbolSize = 0f; if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting)) { - symbolSize = highlight ? - symbol.GetSelectedSize(serieData.data, symbolSize) : - symbol.GetSize(serieData.data, symbolSize); + symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.scatterSymbolSize, state); serieData.interact.SetValue(ref interacting, symbolSize); } @@ -249,24 +244,25 @@ namespace XCharts.Runtime serie.containerIndex = axis.index; serie.containterInstanceId = axis.instanceId; + float symbolBorder = 0f; + float[] cornerRadius = null; + Color32 color, toColor, emptyColor, borderColor; foreach (var serieData in dataList) { var symbol = SerieHelper.GetSerieSymbol(serie, serieData); if (!symbol.ShowSymbol(serieData.index, maxCount)) continue; - var state = SerieHelper.GetSerieState(serie, serieData); - Color32 color, toColor, emptyColor; + var state = SerieHelper.GetSerieState(serie, serieData, true); SerieHelper.GetItemColor(out color, out toColor, out emptyColor, serie, serieData, chart.theme, colorIndex, state); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, state); - var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, state); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, state); - var xValue = serieData.GetCurrData(0, dataChangeDuration, axis.inverse); + SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state); if (serieData.IsDataChanged()) dataChanging = true; var pos = Vector3.zero; + var xValue = serieData.GetCurrData(0, dataChangeDuration, axis.inverse); + if (axis.orient == Orient.Horizonal) { var xDataHig = GetDataHig(axis, xValue, axis.context.width); @@ -283,11 +279,7 @@ namespace XCharts.Runtime serieData.context.position = pos; var datas = serieData.data; - var symbolSize = 0f; - if (serie.highlight || serieData.context.highlight) - symbolSize = symbol.GetSelectedSize(datas, theme.serie.scatterSymbolSelectedSize); - else - symbolSize = symbol.GetSize(datas, theme.serie.scatterSymbolSize); + var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.scatterSymbolSize, state); symbolSize *= rate; if (isEffectScatter) diff --git a/Runtime/Serie/SerieData.cs b/Runtime/Serie/SerieData.cs index b61a2653..950f7473 100644 --- a/Runtime/Serie/SerieData.cs +++ b/Runtime/Serie/SerieData.cs @@ -16,6 +16,7 @@ namespace XCharts.Runtime { "m_Id", "m_ParentId", + "m_State", "m_Ignore", "m_Selected", "m_Radius", diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 4afbba1a..a33d4bee 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -248,13 +248,20 @@ namespace XCharts.Runtime return serie.state; } - public static SerieState GetSerieState(Serie serie, SerieData serieData) + public static SerieState GetSerieState(SerieData serieData) { - if (serieData == null || serieData.state == SerieState.Auto) return GetSerieState(serie); if (serieData.context.highlight) return SerieState.Emphasis; return serieData.state; } + public static SerieState GetSerieState(Serie serie, SerieData serieData, bool defaultSerieState = false) + { + if (serieData == null) return GetSerieState(serie); + if (serieData.context.highlight) return SerieState.Emphasis; + if (serieData.state == SerieState.Auto) return defaultSerieState?serie.state : GetSerieState(serie); + return serieData.state; + } + public static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, SerieState state = SerieState.Auto, bool useDefault = false) { @@ -443,10 +450,18 @@ namespace XCharts.Runtime return stateStyle == null?serie.labelLine : stateStyle.labelLine; } - public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData) + public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { - if (!serie.IsPerformanceMode() && serieData.symbol != null) return serieData.symbol; - else return serie.symbol; + if (state == SerieState.Auto) state = GetSerieState(serie, serieData); + if (state == SerieState.Normal) + { + return serieData != null && serieData.symbol != null? serieData.symbol : serie.symbol; + } + else + { + var stateStyle = GetStateStyle(serie, serieData, state); + return stateStyle == null?serie.symbol : stateStyle.symbol; + } } public static LineStyle GetLineStyle(Serie serie, SerieData serieData) @@ -579,29 +594,73 @@ namespace XCharts.Runtime { if (!ChartHelper.IsClearColor(checkColor)) color = checkColor; else if (!ChartHelper.IsClearColor(itemColor)) color = itemColor; - if (ChartHelper.IsClearColor(color)) color = theme.GetColor(colorIndex); + if (ChartHelper.IsClearColor(color) && colorIndex >= 0) color = theme.GetColor(colorIndex); if (setOpacity) ChartHelper.SetColorOpacity(ref color, opacity); } - public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) + public static void GetSymbolInfo(out Color32 borderColor, out float border, out float[] cornerRadius, + Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) { - var itemStyle = GetItemStyle(serie, serieData, state); - if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth; - else return serie.lineStyle.GetWidth(theme.serie.lineWidth) * 2; + borderColor = ChartConst.clearColor32; + if (state == SerieState.Auto) + state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + if (stateStyle == null) + { + var itemStyle = GetItemStyle(serie, serieData, SerieState.Normal); + border = itemStyle.borderWidth != 0 ? itemStyle.borderWidth : serie.lineStyle.GetWidth(theme.serie.lineWidth); + cornerRadius = itemStyle.cornerRadius; + GetColor(ref borderColor, itemStyle.borderColor, itemStyle.borderColor, 1, theme, -1); + switch (state) + { + case SerieState.Emphasis: + borderColor = ChartHelper.GetHighlightColor(borderColor); + break; + case SerieState.Blur: + borderColor = ChartHelper.GetBlurColor(borderColor); + break; + case SerieState.Select: + borderColor = ChartHelper.GetSelectColor(borderColor); + break; + default: + break; + } + } + else + { + var itemStyle = stateStyle.itemStyle; + border = itemStyle.borderWidth != 0 ? itemStyle.borderWidth : stateStyle.lineStyle.GetWidth(theme.serie.lineWidth); + cornerRadius = itemStyle.cornerRadius; + GetColor(ref borderColor, stateStyle.itemStyle.borderColor, ColorUtil.clearColor32, 1, theme, -1); + } } - public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) + public static float GetSysmbolSize(Serie serie, SerieData serieData, ThemeStyle theme, float defaultSize, SerieState state = SerieState.Auto) { - var itemStyle = GetItemStyle(serie, serieData, state); - if (itemStyle != null && !ChartHelper.IsClearColor(itemStyle.borderColor)) return itemStyle.borderColor; - else return serie.itemStyle.borderColor; - } - - public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) - { - var itemStyle = GetItemStyle(serie, serieData, state); - if (itemStyle != null) return itemStyle.cornerRadius; - else return null; + if (state == SerieState.Auto) + state = GetSerieState(serie, serieData); + var stateStyle = GetStateStyle(serie, serieData, state); + var size = 0f; + if (stateStyle == null) + { + var symbol = GetSerieSymbol(serie, serieData, SerieState.Normal); + size = symbol.GetSize(serieData.data, defaultSize); + switch (state) + { + case SerieState.Emphasis: + case SerieState.Select: + size *= theme.serie.selectedRate; + break; + default: + break; + } + } + else + { + var symbol = stateStyle.symbol; + size = symbol.GetSize(serieData.data, defaultSize); + } + return size; } public static string GetNumericFormatter(Serie serie, SerieData serieData, string defaultFormatter = null) From cdf0bc81e1e1617e7bc5074172a52316e78ebdc9 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 28 Jul 2022 07:21:46 +0800 Subject: [PATCH 09/27] [feature][serie] support the `colorBy` of serie --- CHANGELOG.md | 8 +-- Editor/Series/BarEditor.cs | 1 + Editor/Series/RadarEditor.cs | 1 + Runtime/Internal/Basic/BaseSerie.cs | 5 +- Runtime/Internal/Utilities/ChartHelper.cs | 2 +- Runtime/Serie/Pie/Pie.cs | 2 +- Runtime/Serie/Radar/Radar.cs | 2 +- Runtime/Serie/Radar/RadarHandler.cs | 66 ++++++++++++----------- Runtime/Serie/Ring/Ring.cs | 2 +- Runtime/Serie/Serie.cs | 41 +++++++++++++- Runtime/Serie/SerieHandler.cs | 15 +++--- Runtime/Serie/SerieHelper.cs | 3 +- Runtime/Serie/SeriesHelper.cs | 6 +-- 13 files changed, 103 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c9e1094..80b5664e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,11 +57,13 @@ ## master -* (2022.07.24) 增加`StateStyle`的`Symbol`用于配置状态下的标记样式 -* (2022.07.24) 去掉`SerieSymbol`的`selectedSize`配置 +* (2022.07.28) 优化`Radar`雷达图效果 +* (2022.07.28) 增加`Serie`的`colorBy`参数配置取色策略 +* (2022.07.27) 增加`StateStyle`的`Symbol`用于配置状态下的标记样式 +* (2022.07.27) 去掉`SerieSymbol`的`selectedSize`参数 * (2022.07.24) 增加`Serie`和`SerieData`的`state`设置默认状态 * (2022.07.22) 增加`Serie`的三种状态`EmphasisStyle`,`BlurStyle`,`SelectStyle` -* (2022.07.22) 去掉`AreaStyle`的`highlightColor`和`highlightToColor`配置 +* (2022.07.22) 去掉`AreaStyle`的`highlightColor`和`highlightToColor`参数 * (2022.07.22) 去掉`Emphasis`,`EmphasisItemStyle`,`EmphasisLabelStyle`,`EmphasisLabelLine`组件 * (2022.07.20) 文档支持用`Since`标识类从哪个版本开始支持 * (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 diff --git a/Editor/Series/BarEditor.cs b/Editor/Series/BarEditor.cs index c06a04e0..beb6ecea 100644 --- a/Editor/Series/BarEditor.cs +++ b/Editor/Series/BarEditor.cs @@ -7,6 +7,7 @@ namespace XCharts.Editor { public override void OnCustomInspectorGUI() { + PropertyField("m_ColorBy"); PropertyField("m_Stack"); if (serie.IsUseCoord()) { diff --git a/Editor/Series/RadarEditor.cs b/Editor/Series/RadarEditor.cs index 969c7436..60e5fb43 100644 --- a/Editor/Series/RadarEditor.cs +++ b/Editor/Series/RadarEditor.cs @@ -7,6 +7,7 @@ namespace XCharts.Editor { public override void OnCustomInspectorGUI() { + PropertyField("m_ColorBy"); PropertyField("m_RadarType"); PropertyField("m_RadarIndex"); PropertyField("m_Smooth"); diff --git a/Runtime/Internal/Basic/BaseSerie.cs b/Runtime/Internal/Basic/BaseSerie.cs index 087b4111..16ade89c 100644 --- a/Runtime/Internal/Basic/BaseSerie.cs +++ b/Runtime/Internal/Basic/BaseSerie.cs @@ -10,7 +10,8 @@ namespace XCharts.Runtime { public virtual bool vertsDirty { get { return m_VertsDirty; } } public virtual bool componentDirty { get { return m_ComponentDirty; } } - public virtual bool useDataNameForColor { get { return false; } } + + public virtual SerieColorBy defaultColorBy { get { return SerieColorBy.Serie; } } public virtual bool titleJustForSerie { get { return false; } } public virtual bool useSortData { get { return false; } } public virtual bool multiDimensionLabel { get { return false; } } @@ -27,6 +28,8 @@ namespace XCharts.Runtime public SerieHandler handler { get; set; } + + public static void ClearVerticesDirty(ChildComponent component) { if (component != null) diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 1ecebe83..29370827 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -836,7 +836,7 @@ namespace XCharts.Runtime } } - public static Color32 GetHighlightColor(Color32 color, float rate = 1.2f) + public static Color32 GetHighlightColor(Color32 color, float rate = 0.8f) { var newColor = color; newColor.r = (byte) (color.r * rate); diff --git a/Runtime/Serie/Pie/Pie.cs b/Runtime/Serie/Pie/Pie.cs index fdfb6edb..a86fc07f 100644 --- a/Runtime/Serie/Pie/Pie.cs +++ b/Runtime/Serie/Pie/Pie.cs @@ -9,7 +9,7 @@ namespace XCharts.Runtime [SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")] public class Pie : Serie { - public override bool useDataNameForColor { get { return true; } } + public override SerieColorBy defaultColorBy { get { return SerieColorBy.Data; } } public override bool titleJustForSerie { get { return true; } } public static Serie AddDefaultSerie(BaseChart chart, string serieName) diff --git a/Runtime/Serie/Radar/Radar.cs b/Runtime/Serie/Radar/Radar.cs index 7271acc7..924669e4 100644 --- a/Runtime/Serie/Radar/Radar.cs +++ b/Runtime/Serie/Radar/Radar.cs @@ -25,7 +25,7 @@ namespace XCharts.Runtime public int containerIndex { get; internal set; } public int containterInstanceId { get; internal set; } - public override bool useDataNameForColor { get { return radarType == RadarType.Multiple; } } + public override SerieColorBy defaultColorBy { get { return radarType == RadarType.Multiple?SerieColorBy.Serie : SerieColorBy.Data; } } public override bool multiDimensionLabel { get { return radarType == RadarType.Multiple; } } public static Serie AddDefaultSerie(BaseChart chart, string serieName) diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 3d91c852..68918c14 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -41,8 +41,9 @@ namespace XCharts.Runtime if (serie.radarType == RadarType.Single) { + var colorIndex1 = serie.colorByData ? dataIndex : serie.context.colorIndex; UpdateItemSerieParams(ref paramList, ref title, dataIndex, category, - marker, itemFormatter, numericFormatter); + marker, itemFormatter, numericFormatter, 1, colorIndex1); return; } @@ -55,7 +56,8 @@ namespace XCharts.Runtime return; Color32 color, toColor; - SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, dataIndex, SerieState.Normal); + var colorIndex = serie.colorByData ? chart.GetLegendRealShowNameIndex(serieData.legendName) : serie.context.colorIndex; + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal); title = serieData.name; for (int i = 0; i < serieData.data.Count; i++) { @@ -101,6 +103,7 @@ namespace XCharts.Runtime serie.context.pointerEnter = false; serie.context.pointerItemDataIndex = -1; var areaStyle = serie.areaStyle; + var themeSymbolSize = chart.theme.serie.lineSymbolSize; switch (serie.radarType) { case RadarType.Multiple: @@ -156,12 +159,13 @@ namespace XCharts.Runtime { var serieData = serie.data[i]; serieData.index = i; - if (Vector3.Distance(chart.pointerPos, serieData.context.position) < serie.symbol.size * 2) + var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize); + if (Vector3.Distance(chart.pointerPos, serieData.context.position) < size * 2) { serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = i; - return; + break; } } if (!serie.context.pointerEnter && areaStyle != null) @@ -228,7 +232,7 @@ namespace XCharts.Runtime var lineStyle = SerieHelper.GetLineStyle(serie, serieData); var symbol = SerieHelper.GetSerieSymbol(serie, serieData, serieState); - var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); + var colorIndex = serie.colorByData ? chart.GetLegendRealShowNameIndex(serieData.legendName) : serie.context.colorIndex; var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex); var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex); var lineWidth = lineStyle.GetWidth(chart.theme.serie.lineWidth); @@ -313,7 +317,8 @@ namespace XCharts.Runtime serieData.interact.SetValue(ref interacting, symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize); } - SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, j, serieState); + colorIndex = serie.colorByData ? m : colorIndex; + SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, colorIndex, serieState); SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, serieState); chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius); @@ -333,13 +338,13 @@ namespace XCharts.Runtime private void DrawSingleRadar(VertexHelper vh) { - var radar = chart.GetChartComponent(serie.radarIndex); - if (radar == null) + m_RadarCoord = chart.GetChartComponent(serie.radarIndex); + if (m_RadarCoord == null) return; - var indicatorNum = radar.indicatorList.Count; + var indicatorNum = m_RadarCoord.indicatorList.Count; var angle = 2 * Mathf.PI / indicatorNum; - var centerPos = radar.context.center; + var centerPos = m_RadarCoord.context.center; serie.animation.InitProgress(0, 1); serie.context.dataPoints.Clear(); if (!serie.show || serie.animation.HasFadeOut()) @@ -357,7 +362,7 @@ namespace XCharts.Runtime var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var startIndex = GetStartShowIndex(serie); var endIndex = GetEndShowIndex(serie); - SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate); + SerieHelper.UpdateMinMaxData(serie, 1, m_RadarCoord.ceilRate); for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; @@ -371,25 +376,26 @@ namespace XCharts.Runtime } var lineStyle = SerieHelper.GetLineStyle(serie, serieData); Color32 areaColor, areaToColor; - var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, j); - var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, j); - int dataCount = radar.indicatorList.Count; + var colorIndex = serie.colorByData?j : serie.context.colorIndex; + var showArea = SerieHelper.GetAreaColor(out areaColor, out areaToColor, serie, serieData, chart.theme, colorIndex); + var lineColor = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex); + int dataCount = m_RadarCoord.indicatorList.Count; var index = serieData.index; - var p = radar.context.center; - var max = radar.GetIndicatorMax(index); + var p = m_RadarCoord.context.center; + var max = m_RadarCoord.GetIndicatorMax(index); var value = serieData.GetCurrData(1, dataChangeDuration); if (serieData.IsDataChanged()) dataChanging = true; if (max == 0) { max = serie.context.dataMax; } - if (!radar.IsInIndicatorRange(j, serieData.GetData(1))) + if (!m_RadarCoord.IsInIndicatorRange(j, serieData.GetData(1))) { - lineColor = radar.outRangeColor; + lineColor = m_RadarCoord.outRangeColor; } - var radius = (float) (max < 0 ? radar.context.dataRadius - radar.context.dataRadius * value / max : - radar.context.dataRadius * value / max); - var currAngle = (index + (radar.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle; + var radius = (float) (max < 0 ? m_RadarCoord.context.dataRadius - m_RadarCoord.context.dataRadius * value / max : + m_RadarCoord.context.dataRadius * value / max); + var currAngle = (index + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle; radius *= rate; if (index == startIndex) { @@ -409,11 +415,11 @@ namespace XCharts.Runtime } if (lineStyle.show && !serie.smooth) { - if (radar.connectCenter) + if (m_RadarCoord.connectCenter) ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos, chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor); ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, toPoint, chart.theme.serie.lineWidth, - LineStyle.Type.Solid, radar.lineGradient ? lastColor : lineColor, lineColor); + LineStyle.Type.Solid, m_RadarCoord.lineGradient ? lastColor : lineColor, lineColor); } startPoint = toPoint; lastColor = lineColor; @@ -428,11 +434,11 @@ namespace XCharts.Runtime } if (lineStyle.show && j == endIndex && !serie.smooth) { - if (radar.connectCenter) + if (m_RadarCoord.connectCenter) ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos, chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor); ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, firstPoint, chart.theme.serie.lineWidth, - LineStyle.Type.Solid, lineColor, radar.lineGradient ? firstColor : lineColor); + LineStyle.Type.Solid, lineColor, m_RadarCoord.lineGradient ? firstColor : lineColor); } } if (serie.smooth) @@ -455,14 +461,14 @@ namespace XCharts.Runtime var serieData = serie.data[j]; if (!serieData.show) continue; var state = SerieHelper.GetSerieState(serie, serieData); - var serieIndex = serieData.index; var symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state); - SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, serieIndex, state); + var colorIndex = serie.colorByData ? serieData.index : serie.context.colorIndex; + SerieHelper.GetItemColor(out symbolColor, out symbolToColor, out symbolEmptyColor, serie, serieData, chart.theme, colorIndex, state); SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state); - if (!radar.IsInIndicatorRange(j, serieData.GetData(1))) + if (!m_RadarCoord.IsInIndicatorRange(j, serieData.GetData(1))) { - symbolColor = radar.outRangeColor; - symbolToColor = radar.outRangeColor; + symbolColor = m_RadarCoord.outRangeColor; + symbolToColor = m_RadarCoord.outRangeColor; } chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.context.labelPosition, symbolColor, symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius); diff --git a/Runtime/Serie/Ring/Ring.cs b/Runtime/Serie/Ring/Ring.cs index f448f783..658bd596 100644 --- a/Runtime/Serie/Ring/Ring.cs +++ b/Runtime/Serie/Ring/Ring.cs @@ -9,7 +9,7 @@ namespace XCharts.Runtime [SerieDataExtraField()] public class Ring : Serie { - public override bool useDataNameForColor { get { return true; } } + public override SerieColorBy defaultColorBy { get { return SerieColorBy.Data; } } public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie(serieName); diff --git a/Runtime/Serie/Serie.cs b/Runtime/Serie/Serie.cs index 3673ee8b..06f485e9 100644 --- a/Runtime/Serie/Serie.cs +++ b/Runtime/Serie/Serie.cs @@ -194,6 +194,29 @@ namespace XCharts.Runtime Auto } + /// + /// The policy to take color from theme. + /// |从主题中取色策略。 + /// + public enum SerieColorBy + { + /// + /// Select state. + /// |默认策略。每种Serie都有自己的默认的取颜色策略。比如Line默认是Series策略,Pie默认是Data策略 + /// + Default, + /// + /// assigns the colors in the palette by serie, so that all data in the same series are in the same color;. + /// |按照系列分配调色盘中的颜色,同一系列中的所有数据都是用相同的颜色。 + /// + Serie, + /// + /// assigns colors in the palette according to data items, with each data item using a different color.. + /// |按照数据项分配调色盘中的颜色,每个数据项都使用不同的颜色。 + /// + Data + } + /// /// 系列。 /// @@ -206,6 +229,7 @@ namespace XCharts.Runtime [SerializeField] private string m_SerieType = ""; [SerializeField] private string m_SerieName; [SerializeField][Since("v3.2.0")] private SerieState m_State = SerieState.Normal; + [SerializeField][Since("v3.2.0")] private SerieColorBy m_ColorBy = SerieColorBy.Default; [SerializeField] private string m_Stack; [SerializeField] private int m_XAxisIndex = 0; [SerializeField] private int m_YAxisIndex = 0; @@ -339,6 +363,16 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_State, value)) { SetAllDirty(); } } } /// + /// The policy to take color from theme. + /// |从主题中取色的策略。 + /// + public SerieColorBy colorBy + { + //get { return m_ColorBy; } + get { return m_ColorBy == SerieColorBy.Default?defaultColorBy : m_ColorBy; } + set { if (PropertyUtil.SetStruct(ref m_ColorBy, value)) { SetAllDirty(); } } + } + /// /// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other. /// |数据堆叠,同个类目轴上系列配置相同的stack值后,后一个系列的值会在前一个系列的值上相加。 /// @@ -860,7 +894,10 @@ namespace XCharts.Runtime /// 系列中的数据内容数组。SerieData可以设置1到n维数据。 /// public List data { get { return m_Data; } } - + /// + /// 取色策略是否为按数据项分配。 + /// + public bool colorByData { get { return colorBy == SerieColorBy.Data; } } public override bool vertsDirty { get @@ -1703,7 +1740,7 @@ namespace XCharts.Runtime public bool IsLegendName(string legendName) { - if (useDataNameForColor) + if (colorBy == SerieColorBy.Data) { return IsSerieDataLegendName(legendName) || IsSerieLegendName(legendName); } diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 2053240d..1ff1b82a 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -144,7 +144,7 @@ namespace XCharts.Runtime public override void OnLegendButtonClick(int index, string legendName, bool show) { - if (serie.useDataNameForColor && serie.IsSerieDataLegendName(legendName)) + if (serie.colorByData && serie.IsSerieDataLegendName(legendName)) { LegendHelper.CheckDataShow(serie, legendName, show); chart.UpdateLegendColor(legendName, show); @@ -159,7 +159,7 @@ namespace XCharts.Runtime public override void OnLegendButtonEnter(int index, string legendName) { - if (serie.useDataNameForColor && serie.IsSerieDataLegendName(legendName)) + if (serie.colorByData && serie.IsSerieDataLegendName(legendName)) { LegendHelper.CheckDataHighlighted(serie, legendName, true); chart.RefreshPainter(serie); @@ -173,7 +173,7 @@ namespace XCharts.Runtime public override void OnLegendButtonExit(int index, string legendName) { - if (serie.useDataNameForColor && serie.IsSerieDataLegendName(legendName)) + if (serie.colorByData && serie.IsSerieDataLegendName(legendName)) { LegendHelper.CheckDataHighlighted(serie, legendName, false); chart.RefreshPainter(serie); @@ -485,7 +485,7 @@ namespace XCharts.Runtime public virtual Color GetSerieDataAutoColor(SerieData serieData) { - var colorIndex = serie.useDataNameForColor ? serieData.index : serie.index; + var colorIndex = serie.colorByData ? serieData.index : serie.index; Color32 color, toColor; SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal, false); return (Color) color; @@ -533,7 +533,7 @@ namespace XCharts.Runtime protected void UpdateItemSerieParams(ref List paramList, ref string title, int dataIndex, string category, string marker, - string itemFormatter, string numericFormatter, int dimension = 1) + string itemFormatter, string numericFormatter, int dimension = 1, int colorIndex = -1) { if (dataIndex < 0) dataIndex = serie.context.pointerItemDataIndex; @@ -549,10 +549,11 @@ namespace XCharts.Runtime if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter)) return; - var colorIndex = chart.GetLegendRealShowNameIndex(serieData.name); + if (colorIndex < 0) + colorIndex = serie.colorByData?dataIndex : chart.GetLegendRealShowNameIndex(serieData.name); + Color32 color, toColor; SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal); - var param = serie.context.param; param.serieName = serie.serieName; param.serieIndex = serie.index; diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index a33d4bee..8ad651bb 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -282,7 +282,8 @@ namespace XCharts.Runtime public static void GetItemColor(out Color32 color, out Color32 toColor, Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) { - GetItemColor(out color, out toColor, serie, serieData, theme, serie.context.colorIndex, state, true); + var colorIndex = serie.colorByData? serieData.index : serie.context.colorIndex; + GetItemColor(out color, out toColor, serie, serieData, theme, colorIndex, state, true); } public static void GetItemColor(out Color32 color, out Color32 toColor, diff --git a/Runtime/Serie/SeriesHelper.cs b/Runtime/Serie/SeriesHelper.cs index 5b191d44..a4fd0e6e 100644 --- a/Runtime/Serie/SeriesHelper.cs +++ b/Runtime/Serie/SeriesHelper.cs @@ -24,7 +24,7 @@ namespace XCharts.Runtime { var serie = series[n]; if (serie.placeHolder) continue; - if (serie.useDataNameForColor) + if (serie.colorByData) { for (int i = 0; i < serie.data.Count; i++) { @@ -53,7 +53,7 @@ namespace XCharts.Runtime { var serie = chart.series[n]; if (serie.placeHolder) continue; - if (serie.useDataNameForColor) + if (serie.colorByData) { for (int i = 0; i < serie.data.Count; i++) { @@ -84,7 +84,7 @@ namespace XCharts.Runtime { var serie = series[n]; if (serie.placeHolder) continue; - if (serie.useDataNameForColor) + if (serie.colorByData) { bool found = false; for (int i = 0; i < serie.data.Count; i++) From 44dc1f7b16553546f82d00594f982ad1ae1342c7 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 28 Jul 2022 13:33:38 +0800 Subject: [PATCH 10/27] [feature][UGL] add `UGL.DrawPolyon` API --- Runtime/Serie/Bar/BarHandler.cs | 4 ++-- Runtime/Serie/Line/LineHandler.GridCoord.cs | 1 + Runtime/Serie/Radar/RadarHandler.cs | 11 ++++++++--- Runtime/Serie/SerieHelper.cs | 2 +- Runtime/XUGL/UGL.cs | 20 ++++++++++++++++++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index fabb1576..92b8d54d 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -103,13 +103,13 @@ namespace XCharts.Runtime serie.context.pointerItemDataIndex = serieData.index; serie.context.pointerEnter = true; serieData.context.highlight = true; - SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Emphasis); } else { serieData.context.highlight = false; - SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, SerieState.Normal); } + var state = SerieHelper.GetSerieState(serie, serieData, true); + SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, state); serieData.interact.SetColor(ref needInteract, color, toColor); } } diff --git a/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Runtime/Serie/Line/LineHandler.GridCoord.cs index 55938982..a3f5c193 100644 --- a/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -85,6 +85,7 @@ namespace XCharts.Runtime { serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = i; + needInteract = true; } } } diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 68918c14..5b7b7fc7 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -155,6 +155,7 @@ namespace XCharts.Runtime } break; case RadarType.Single: + needInteract = false; for (int i = 0; i < serie.data.Count; i++) { var serieData = serie.data[i]; @@ -162,10 +163,14 @@ namespace XCharts.Runtime var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize); if (Vector3.Distance(chart.pointerPos, serieData.context.position) < size * 2) { - serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = i; - break; + serieData.context.highlight = true; + needInteract = true; + } + else + { + serieData.context.highlight = false; } } if (!serie.context.pointerEnter && areaStyle != null) @@ -178,10 +183,10 @@ namespace XCharts.Runtime var p2 = n >= dataPoints.Count - 1 ? dataPoints[0] : dataPoints[n + 1]; if (UGLHelper.IsPointInTriangle(p1.context.position, center, p2.context.position, chart.pointerPos)) { - serie.highlight = true; serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = n; p1.context.highlight = true; + needInteract = true; break; } } diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 8ad651bb..696b09af 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -244,7 +244,7 @@ namespace XCharts.Runtime public static SerieState GetSerieState(Serie serie) { - if (serie.highlight || serie.context.pointerEnter) return SerieState.Emphasis; + if (serie.highlight) return SerieState.Emphasis; return serie.state; } diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 595342f3..a5520086 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -1940,5 +1940,25 @@ namespace XUGL angle += smoothness; } } + + /// + /// 填充任意多边形(目前只支持凸多边形) + /// + /// + /// + /// + public static void DrawPolygon(VertexHelper vh, List points, Color32 color) + { + if (points.Count < 3 || UGLHelper.IsClearColor(color)) return; + var cv = vh.currentVertCount; + foreach (var pos in points) + { + vh.AddVert(pos, color, Vector2.zero); + } + for (int i = 2; i < points.Count; i++) + { + vh.AddTriangle(cv, cv + i - 1, cv + i); + } + } } } \ No newline at end of file From 74b078c92699645b43b0fad6b412b52fed0430cb Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 29 Jul 2022 07:49:15 +0800 Subject: [PATCH 11/27] [feature][axis] support `minorTick` and `minorSplitLine` of time axis --- CHANGELOG.md | 1 + Runtime/Component/Axis/AxisHandler.cs | 84 +++++++++++++++++++++------ Runtime/Utilities/DateTimeUtil.cs | 16 +++-- 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80b5664e..65efedbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.07.29) 增加`Axis`为`Time`时间轴时,支持次刻度和次分割线 * (2022.07.28) 优化`Radar`雷达图效果 * (2022.07.28) 增加`Serie`的`colorBy`参数配置取色策略 * (2022.07.27) 增加`StateStyle`的`Symbol`用于配置状态下的标记样式 diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 8831dab5..50e9b3ac 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -205,8 +205,8 @@ namespace XCharts if (axis.IsTime()) { var lastCount = axis.context.labelValueList.Count; - DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList, (int) axis.context.minValue, - (int) axis.context.maxValue, axis.splitNumber); + axis.context.tickValue = DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList, + (int) axis.context.minValue, (int) axis.context.maxValue, axis.splitNumber); if (axis.context.labelValueList.Count != lastCount) axis.SetAllDirty(); @@ -565,13 +565,15 @@ namespace XCharts var tickWidth = axis.axisTick.GetWidth(theme.tickWidth); var tickColor = axis.axisTick.GetColor(theme.tickColor); var current = orient == Orient.Horizonal ? startX : startY; - var lastTickX = 0f; - var lastTickY = 0f; + var maxAxisXY = current + axisLength; + var lastTickX = current; + var lastTickY = current; var minorTickSplitNumber = axis.minorTick.splitNumber <= 0 ? 5 : axis.minorTick.splitNumber; var minorTickDistance = axis.GetValueLength(axis.context.tickValue / minorTickSplitNumber, axisLength); var minorTickColor = axis.minorTick.GetColor(theme.tickColor); var minorTickWidth = axis.minorTick.GetWidth(theme.tickWidth); var minorTickLength = axis.minorTick.GetLength(theme.tickLength * 0.6f); + var minorStartIndex = axis.IsTime() ? 0 : 1; for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom); @@ -606,9 +608,9 @@ namespace XCharts } if (!hideTick) UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY), tickWidth, tickColor); - if (axis.minorTick.show && i > 0 && minorTickDistance > 0) + if (axis.minorTick.show && i >= minorStartIndex && minorTickDistance > 0) { - if (lastTickX <= axis.context.zeroX || (i == 1 && pX > axis.context.zeroX)) + if (lastTickX <= axis.context.zeroX || (i == minorStartIndex && pX > axis.context.zeroX)) { var tickTotal = pX - minorTickDistance; while (tickTotal > lastTickX) @@ -626,6 +628,15 @@ namespace XCharts tickTotal += minorTickDistance; } } + if (i == size - 1) + { + var tickTotal = pX + minorTickDistance; + while (tickTotal < maxAxisXY) + { + UGL.DrawLine(vh, new Vector3(tickTotal, sY), new Vector3(tickTotal, mY), minorTickWidth, minorTickColor); + tickTotal += minorTickDistance; + } + } } lastTickX = pX; } @@ -656,9 +667,9 @@ namespace XCharts } if (!hideTick) UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY), tickWidth, tickColor); - if (axis.minorTick.show && i > 0 && minorTickDistance > 0) + if (axis.minorTick.show && i >= minorStartIndex && minorTickDistance > 0) { - if (lastTickY <= axis.context.zeroY || (i == 1 && pY > axis.context.zeroY)) + if (lastTickY <= axis.context.zeroY || (i == minorStartIndex && pY > axis.context.zeroY)) { var tickTotal = pY - minorTickDistance; while (tickTotal > lastTickY) @@ -678,6 +689,15 @@ namespace XCharts tickTotal += minorTickDistance; } } + if (i == size - 1) + { + var tickTotal = pY + minorTickDistance; + while (tickTotal < maxAxisXY) + { + UGL.DrawLine(vh, new Vector3(sX, tickTotal), new Vector3(mX, tickTotal), minorTickWidth, minorTickColor); + tickTotal += minorTickDistance; + } + } } lastTickY = pY; } @@ -751,10 +771,8 @@ namespace XCharts size += 1; } - var current = orient == Orient.Horizonal ? - startX : - startY; - + var current = orient == Orient.Horizonal ? startX : startY; + var maxAxisXY = current + axisLength; var lastSplitX = 0f; var lastSplitY = 0f; var minorTickSplitNumber = axis.minorTick.splitNumber <= 0 ? 5 : axis.minorTick.splitNumber; @@ -762,6 +780,7 @@ namespace XCharts var minorSplitLineColor = axis.minorSplitLine.GetColor(theme.minorSplitLineColor); var minorLineWidth = axis.minorSplitLine.GetWidth(theme.lineWidth); var minorLineType = axis.minorSplitLine.GetType(theme.splitLineType); + var minorStartIndex = axis.IsTime() ? 0 : 1; for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom); @@ -789,7 +808,6 @@ namespace XCharts new Vector2(startX, current + scaleWidth), axis.splitArea.GetColor(i, theme)); } - } if (axis.splitLine.show) { @@ -806,9 +824,9 @@ namespace XCharts new Vector3(current, startY + splitLength), lineColor); } - if (axis.minorSplitLine.show && i > 0 && minorTickDistance > 0) + if (axis.minorSplitLine.show && i >= minorStartIndex && minorTickDistance > 0) { - if (lastSplitX <= axis.context.zeroX || (i == 1 && current > axis.context.zeroX)) + if (lastSplitX <= axis.context.zeroX || (i == minorStartIndex && current > axis.context.zeroX)) { var tickTotal = current - minorTickDistance; var count = 0; @@ -840,6 +858,22 @@ namespace XCharts tickTotal += minorTickDistance; } } + if (i == size - 1) + { + var tickTotal = current + minorTickDistance; + var count = 0; + while (tickTotal < maxAxisXY && count < minorTickSplitNumber - 1) + { + ChartDrawer.DrawLineStyle(vh, + minorLineType, + minorLineWidth, + new Vector3(tickTotal, startY), + new Vector3(tickTotal, startY + splitLength), + minorSplitLineColor); + count++; + tickTotal += minorTickDistance; + } + } } lastSplitX = current; } @@ -854,9 +888,9 @@ namespace XCharts new Vector3(startX + splitLength, current), lineColor); } - if (axis.minorSplitLine.show && i > 0 && minorTickDistance > 0) + if (axis.minorSplitLine.show && i >= minorStartIndex && minorTickDistance > 0) { - if (lastSplitY <= axis.context.zeroY || (i == 1 && current > axis.context.zeroY)) + if (lastSplitY <= axis.context.zeroY || (i == minorStartIndex && current > axis.context.zeroY)) { var tickTotal = current - minorTickDistance; var count = 0; @@ -888,6 +922,22 @@ namespace XCharts tickTotal += minorTickDistance; } } + if (i == size - 1) + { + var tickTotal = current + minorTickDistance; + var count = 0; + while (tickTotal < maxAxisXY && count < minorTickSplitNumber - 1) + { + ChartDrawer.DrawLineStyle(vh, + minorLineType, + minorLineWidth, + new Vector3(startX, tickTotal), + new Vector3(startX + splitLength, tickTotal), + minorSplitLineColor); + count++; + tickTotal += minorTickDistance; + } + } } lastSplitY = current; } diff --git a/Runtime/Utilities/DateTimeUtil.cs b/Runtime/Utilities/DateTimeUtil.cs index 361218f2..cf97f145 100644 --- a/Runtime/Utilities/DateTimeUtil.cs +++ b/Runtime/Utilities/DateTimeUtil.cs @@ -80,18 +80,20 @@ namespace XCharts.Runtime /// /// /// - internal static void UpdateTimeAxisDateTimeList(List list, int minTimestamp, int maxTimestamp, int splitNumber) + internal static float UpdateTimeAxisDateTimeList(List list, int minTimestamp, int maxTimestamp, int splitNumber) { list.Clear(); var range = maxTimestamp - minTimestamp; - if (range <= 0) return; + if (range <= 0) return 0; if (splitNumber <= 0) splitNumber = 1; var dtMin = DateTimeUtil.GetDateTime(minTimestamp); var dtMax = DateTimeUtil.GetDateTime(maxTimestamp); + int tick = 0; if (range >= ONE_YEAR * MIN_TIME_SPLIT_NUMBER) { var num = Math.Max(range / (splitNumber * ONE_YEAR), 1); var dtStart = new DateTime(dtMin.Year + 1, 1, 1); + tick = num * 365 * 24 * 3600; while (dtStart.Ticks < dtMax.Ticks) { list.Add(DateTimeUtil.GetTimestamp(dtStart)); @@ -102,6 +104,7 @@ namespace XCharts.Runtime { var num = Math.Max(range / (splitNumber * ONE_MONTH), 1); var dtStart = new DateTime(dtMin.Year, dtMin.Month, 1).AddMonths(1); + tick = num * 30 * 24 * 3600; while (dtStart.Ticks < dtMax.Ticks) { list.Add(DateTimeUtil.GetTimestamp(dtStart)); @@ -110,28 +113,29 @@ namespace XCharts.Runtime } else if (range >= ONE_DAY * MIN_TIME_SPLIT_NUMBER) { - var tick = GetTickSecond(range, splitNumber, ONE_DAY); + tick = GetTickSecond(range, splitNumber, ONE_DAY); var startTimestamp = (minTimestamp - minTimestamp % tick) + tick; AddTickTimestamp(list, startTimestamp, maxTimestamp, tick); } else if (range >= ONE_HOUR * MIN_TIME_SPLIT_NUMBER) { - var tick = GetTickSecond(range, splitNumber, ONE_HOUR); + tick = GetTickSecond(range, splitNumber, ONE_HOUR); var startTimestamp = (minTimestamp - minTimestamp % tick) + tick; AddTickTimestamp(list, startTimestamp, maxTimestamp, tick); } else if (range >= ONE_MINUTE * MIN_TIME_SPLIT_NUMBER) { - var tick = GetTickSecond(range, splitNumber, ONE_MINUTE); + tick = GetTickSecond(range, splitNumber, ONE_MINUTE); var startTimestamp = (minTimestamp - minTimestamp % tick) + tick; AddTickTimestamp(list, startTimestamp, maxTimestamp, tick); } else { - var tick = GetTickSecond(range, splitNumber, ONE_SECOND); + tick = GetTickSecond(range, splitNumber, ONE_SECOND); var startTimestamp = (minTimestamp - minTimestamp % tick) + tick; AddTickTimestamp(list, startTimestamp, maxTimestamp, tick); } + return tick; } private static int GetTickSecond(int range, int splitNumber, int tickSecond) From b9812a4f986326e8b1e12d9532f07fb2c4f485d8 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 29 Jul 2022 13:25:05 +0800 Subject: [PATCH 12/27] [feature][bug] fix import packge error --- CHANGELOG.md | 1 + Runtime/Internal/XCThemeMgr.cs | 11 +++++++++-- Runtime/Serie/SerieHelper.cs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65efedbe..0d1898a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.07.29) 修复在某些`Unity`版本导入后图表创建异常的问题 * (2022.07.29) 增加`Axis`为`Time`时间轴时,支持次刻度和次分割线 * (2022.07.28) 优化`Radar`雷达图效果 * (2022.07.28) 增加`Serie`的`colorBy`参数配置取色策略 diff --git a/Runtime/Internal/XCThemeMgr.cs b/Runtime/Internal/XCThemeMgr.cs index 86c239cc..a30148a1 100644 --- a/Runtime/Internal/XCThemeMgr.cs +++ b/Runtime/Internal/XCThemeMgr.cs @@ -56,9 +56,16 @@ namespace XCharts.Runtime { if (!XChartsMgr.themes.ContainsKey(themeName)) { - return null; + ReloadThemeList(); + if (XChartsMgr.themes.ContainsKey(themeName)) + return XChartsMgr.themes[themeName]; + else + return null; + } + else + { + return XChartsMgr.themes[themeName]; } - return XChartsMgr.themes[themeName]; } public static Theme LoadTheme(ThemeType type) diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 696b09af..9373e8fd 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -282,7 +282,7 @@ namespace XCharts.Runtime public static void GetItemColor(out Color32 color, out Color32 toColor, Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto) { - var colorIndex = serie.colorByData? serieData.index : serie.context.colorIndex; + var colorIndex = serieData != null && serie.colorByData? serieData.index : serie.context.colorIndex; GetItemColor(out color, out toColor, serie, serieData, theme, colorIndex, state, true); } From 35220a1026cbd1bfc67afe4d80504b7efc5bb3ec Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 2 Aug 2022 08:01:22 +0800 Subject: [PATCH 13/27] scheduled release date for v3.2.0 --- Documentation/XChartsAPI-EN.md | 12 ++++++------ Documentation/XChartsAPI-ZH.md | 12 ++++++------ Documentation/XChartsConfiguration-EN.md | 7 +++---- Documentation/XChartsConfiguration-ZH.md | 7 +++---- Runtime/Internal/XChartsMgr.cs | 2 +- package.json | 4 ++-- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md index 3db0e1bb..5b9c870b 100644 --- a/Documentation/XChartsAPI-EN.md +++ b/Documentation/XChartsAPI-EN.md @@ -355,7 +355,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `GetPointList()` |public static void GetPointList(ref List posList, Vector3 sp, Vector3 ep, float k = 30f)
| | `GetPos()` |public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false)
| | `GetPosition()` |public static Vector3 GetPosition(Vector3 center, float angle, float radius)
| -| `GetSelectColor()` |public static Color32 GetSelectColor(Color32 color, float rate = 0.7f)
| +| `GetSelectColor()` |public static Color32 GetSelectColor(Color32 color, float rate = 0.8f)
| | `GetVertialDire()` |public static Vector3 GetVertialDire(Vector3 dire)
| | `HideAllObject()` |public static void HideAllObject(GameObject obj, string match = null)
| | `HideAllObject()` |public static void HideAllObject(Transform parent, string match = null)
| @@ -852,12 +852,11 @@ Inherits or Implemented: [Attribute](#Attribute) | `GetSerieLabel()` |public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetSerieLabelLine()` |public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetSerieState()` |public static SerieState GetSerieState(Serie serie)
| -| `GetSerieState()` |public static SerieState GetSerieState(Serie serie, SerieData serieData)
| -| `GetSerieSymbol()` |public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
| +| `GetSerieState()` |public static SerieState GetSerieState(Serie serie, SerieData serieData, bool defaultSerieState = false)
| +| `GetSerieState()` |public static SerieState GetSerieState(SerieData serieData)
| +| `GetSerieSymbol()` |public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetStateStyle()` |public static StateStyle GetStateStyle(Serie serie, SerieData serieData, SerieState state)
| -| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| -| `GetSymbolBorderColor()` |public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| -| `GetSymbolCornerRadius()` |public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetSysmbolSize()` |public static float GetSysmbolSize(Serie serie, SerieData serieData, ThemeStyle theme, float defaultSize, SerieState state = SerieState.Auto)
| | `GetTitleStyle()` |public static TitleStyle GetTitleStyle(Serie serie, SerieData serieData)
| | `IsAllZeroValue()` |public static bool IsAllZeroValue(Serie serie, int dimension = 1)
Whether the data for the specified dimension of serie are all 0. | | `IsDownPoint()` |public static bool IsDownPoint(Serie serie, int index)
| @@ -986,6 +985,7 @@ Inherits or Implemented: [MaskableGraphic](#MaskableGraphic) | `DrawLine()` |public static void DrawLine(VertexHelper vh, List points, float width, Color32 color, bool smooth, bool closepath = false)
| | `DrawLine()` |public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color)
Draw a line. 画直线 | | `DrawLine()` |public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color, Color32 toColor)
Draw a line. 画直线 | +| `DrawPolygon()` |public static void DrawPolygon(VertexHelper vh, List points, Color32 color)
填充任意多边形(目前只支持凸多边形) | | `DrawRectangle()` |public static void DrawRectangle(VertexHelper vh, Rect rect, Color32 color)
| | `DrawRectangle()` |public static void DrawRectangle(VertexHelper vh, Rect rect, Color32 color, Color32 toColor)
| | `DrawRectangle()` |public static void DrawRectangle(VertexHelper vh, Rect rect, float border, Color32 color)
| diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md index abf352a5..60546735 100644 --- a/Documentation/XChartsAPI-ZH.md +++ b/Documentation/XChartsAPI-ZH.md @@ -355,7 +355,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `GetPointList()` |public static void GetPointList(ref List posList, Vector3 sp, Vector3 ep, float k = 30f)
| | `GetPos()` |public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false)
| | `GetPosition()` |public static Vector3 GetPosition(Vector3 center, float angle, float radius)
| -| `GetSelectColor()` |public static Color32 GetSelectColor(Color32 color, float rate = 0.7f)
| +| `GetSelectColor()` |public static Color32 GetSelectColor(Color32 color, float rate = 0.8f)
| | `GetVertialDire()` |public static Vector3 GetVertialDire(Vector3 dire)
| | `HideAllObject()` |public static void HideAllObject(GameObject obj, string match = null)
| | `HideAllObject()` |public static void HideAllObject(Transform parent, string match = null)
| @@ -852,12 +852,11 @@ Inherits or Implemented: [Attribute](#Attribute) | `GetSerieLabel()` |public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetSerieLabelLine()` |public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetSerieState()` |public static SerieState GetSerieState(Serie serie)
| -| `GetSerieState()` |public static SerieState GetSerieState(Serie serie, SerieData serieData)
| -| `GetSerieSymbol()` |public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
| +| `GetSerieState()` |public static SerieState GetSerieState(Serie serie, SerieData serieData, bool defaultSerieState = false)
| +| `GetSerieState()` |public static SerieState GetSerieState(SerieData serieData)
| +| `GetSerieSymbol()` |public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| | `GetStateStyle()` |public static StateStyle GetStateStyle(Serie serie, SerieData serieData, SerieState state)
| -| `GetSymbolBorder()` |public static float GetSymbolBorder(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| -| `GetSymbolBorderColor()` |public static Color32 GetSymbolBorderColor(Serie serie, SerieData serieData, ThemeStyle theme, SerieState state = SerieState.Auto)
| -| `GetSymbolCornerRadius()` |public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, SerieState state = SerieState.Auto)
| +| `GetSysmbolSize()` |public static float GetSysmbolSize(Serie serie, SerieData serieData, ThemeStyle theme, float defaultSize, SerieState state = SerieState.Auto)
| | `GetTitleStyle()` |public static TitleStyle GetTitleStyle(Serie serie, SerieData serieData)
| | `IsAllZeroValue()` |public static bool IsAllZeroValue(Serie serie, int dimension = 1)
系列指定维数的数据是否全部为0。 | | `IsDownPoint()` |public static bool IsDownPoint(Serie serie, int index)
| @@ -986,6 +985,7 @@ Inherits or Implemented: [MaskableGraphic](#MaskableGraphic) | `DrawLine()` |public static void DrawLine(VertexHelper vh, List points, float width, Color32 color, bool smooth, bool closepath = false)
| | `DrawLine()` |public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color)
Draw a line. 画直线 | | `DrawLine()` |public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color, Color32 toColor)
Draw a line. 画直线 | +| `DrawPolygon()` |public static void DrawPolygon(VertexHelper vh, List points, Color32 color)
填充任意多边形(目前只支持凸多边形) | | `DrawRectangle()` |public static void DrawRectangle(VertexHelper vh, Rect rect, Color32 color)
| | `DrawRectangle()` |public static void DrawRectangle(VertexHelper vh, Rect rect, Color32 color, Color32 toColor)
| | `DrawRectangle()` |public static void DrawRectangle(VertexHelper vh, Rect rect, float border, Color32 color)
| diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index 4fabb276..35f7d9ee 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -596,7 +596,7 @@ Configurations of emphasis state. |field|default|since|comment| |--|--|--|--| -|`scale`|1.1f||Whether to scale to highlight the data in emphasis state. 高亮时的缩放倍数。 +|`scale`|1.1f||Whether to scale to highlight the data in emphasis state. |`focus`|||When the data is highlighted, whether to fade out of other data to focus the highlighted.
`EmphasisStyle.FocusType`:
- `None`: Do not fade out other data, it's by default.
- `Self`: Only focus (not fade out) the element of the currently highlighted data.
- `Series`: Focus on all elements of the series which the currently highlighted data belongs to.
| |`blurScope`|||The range of fade out when focus is enabled.
`EmphasisStyle.BlurScope`:
- `GridCoord`: coordinate system.
- `Series`: series.
- `Global`: global.
| @@ -1071,6 +1071,7 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) |`serieType`|||the type of serie. |`serieName`|||Series name used for displaying in tooltip and filtering with legend. |`state`||v3.2.0|The default state of a serie.
`SerieState`:
- `Normal`: Normal state.
- `Emphasis`: Emphasis state.
- `Blur`: Blur state.
- `Select`: Select state.
- `Auto`: Auto state.
| +|`colorBy`||v3.2.0|The policy to take color from theme.
`SerieColorBy`:
- `Default`: Select state.
- `Serie`: assigns the colors in the palette by serie, so that all data in the same series are in the same color;.
- `Data`: assigns colors in the palette according to data items, with each data item using a different color..
| |`stack`|||If stack the value. On the same category axis, the series with the same stack name would be put on top of each other. |`xAxisIndex`|0||the index of XAxis. |`yAxisIndex`|0||the index of YAxis. @@ -1160,12 +1161,9 @@ Inherits or Implemented: [SymbolStyle](#SymbolStyle),[ISerieDataComponent](#ISer |field|default|since|comment| |--|--|--|--| |`sizeType`|||the type of symbol size.
`SymbolSizeType`:
- `Custom`: Specify constant for symbol size.
- `FromData`: Specify the dataIndex and dataScale to calculate symbol size.
- `Function`: Specify function for symbol size.
| -|`selectedSize`|0f||the size of selected symbol. |`dataIndex`|1||whitch data index is when the sizeType assined as FromData. |`dataScale`|1||the scale of data when sizeType assined as FromData. -|`selectedDataScale`|1.5f||the scale of selected data when sizeType assined as FromData. |`sizeFunction`|||the function of size when sizeType assined as Function. -|`selectedSizeFunction`|||the function of size when sizeType assined as Function. |`startIndex`|||the index start to show symbol. |`interval`|||the interval of show symbol. |`forceShowLast`|false||whether to show the last symbol. @@ -1273,6 +1271,7 @@ the state style of serie. |`itemStyle`|||图形样式。 [ItemStyle](#ItemStyle)| |`lineStyle`|||折线样式。 [LineStyle](#LineStyle)| |`areaStyle`|||区域样式。 [AreaStyle](#AreaStyle)| +|`symbol`|||标记样式。 [SerieSymbol](#SerieSymbol)| ## `SubTitleTheme` diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index 54869840..a291fa8d 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -596,7 +596,7 @@ Inherits or Implemented: [StateStyle](#StateStyle),[ISerieExtraComponent](#ISeri |field|default|since|comment| |--|--|--|--| -|`scale`|1.1f||Whether to scale to highlight the data in emphasis state. 高亮时的缩放倍数。 +|`scale`|1.1f||高亮时的缩放倍数。 |`focus`|||在高亮图形时,是否淡出其它数据的图形已达到聚焦的效果。
`EmphasisStyle.FocusType`:
- `None`: 不淡出其它图形,默认使用该配置。
- `Self`: 只聚焦(不淡出)当前高亮的数据的图形。
- `Series`: 聚焦当前高亮的数据所在的系列的所有图形。
| |`blurScope`|||在开启focus的时候,可以通过blurScope配置淡出的范围。
`EmphasisStyle.BlurScope`:
- `GridCoord`: 淡出范围为坐标系,默认使用该配置。
- `Series`: 淡出范围为系列。
- `Global`: 淡出范围为全局。
| @@ -1071,6 +1071,7 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) |`serieType`|||系列类型。 |`serieName`|||系列名称,用于 tooltip 的显示,legend 的图例筛选。 |`state`||v3.2.0|系列的默认状态。
`SerieState`:
- `Normal`: 正常状态。
- `Emphasis`: 高亮状态。
- `Blur`: 淡出状态。
- `Select`: 选中状态。
- `Auto`: 自动保持和父节点一致。一般用在SerieData。
| +|`colorBy`||v3.2.0|从主题中取色的策略。
`SerieColorBy`:
- `Default`: 默认策略。每种Serie都有自己的默认的取颜色策略。比如Line默认是Series策略,Pie默认是Data策略
- `Serie`: 按照系列分配调色盘中的颜色,同一系列中的所有数据都是用相同的颜色。
- `Data`: 按照数据项分配调色盘中的颜色,每个数据项都使用不同的颜色。
| |`stack`|||数据堆叠,同个类目轴上系列配置相同的stack值后,后一个系列的值会在前一个系列的值上相加。 |`xAxisIndex`|0||使用X轴的index。 |`yAxisIndex`|0||使用Y轴的index。 @@ -1160,12 +1161,9 @@ Inherits or Implemented: [SymbolStyle](#SymbolStyle),[ISerieDataComponent](#ISer |field|default|since|comment| |--|--|--|--| |`sizeType`|||标记图形的大小获取方式。
`SymbolSizeType`:
- `Custom`: 自定义大小。
- `FromData`: 通过 dataIndex 从数据中获取,再乘以一个比例系数 dataScale 。
- `Function`: 通过委托函数获取。
| -|`selectedSize`|0f||被选中的标记的大小。 |`dataIndex`|1||当sizeType指定为FromData时,指定的数据源索引。 |`dataScale`|1||当sizeType指定为FromData时,指定的倍数系数。 -|`selectedDataScale`|1.5f||当sizeType指定为FromData时,指定的高亮倍数系数。 |`sizeFunction`|||当sizeType指定为Function时,指定的委托函数。 -|`selectedSizeFunction`|||当sizeType指定为Function时,指定的高亮委托函数。 |`startIndex`|||开始显示图形标记的索引。 |`interval`|||显示图形标记的间隔。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。 |`forceShowLast`|false||是否强制显示最后一个图形标记。 @@ -1273,6 +1271,7 @@ Serie的状态样式。Serie的状态有正常,高亮,淡出,选中四种 |`itemStyle`|||图形样式。 [ItemStyle](#ItemStyle)| |`lineStyle`|||折线样式。 [LineStyle](#LineStyle)| |`areaStyle`|||区域样式。 [AreaStyle](#AreaStyle)| +|`symbol`|||标记样式。 [SerieSymbol](#SerieSymbol)| ## `SubTitleTheme` diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index 07b914c7..a9d29535 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -21,7 +21,7 @@ namespace XCharts.Runtime public static class XChartsMgr { public static readonly string version = "3.2.0"; - public static readonly int versionDate = 20220712; + public static readonly int versionDate = 20220815; public static string fullVersion { get { return version + "-" + versionDate; } } internal static List chartList = new List(); diff --git a/package.json b/package.json index bc877903..b484585f 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "com.monitor1394.xcharts", "displayName": "XCharts", "version": "3.2.0", - "date": "20220712", - "checkdate": "20220712", + "date": "20220815", + "checkdate": "20220815", "desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!", "unity": "2018.3", "description": "A charting and data visualization library for Unity.", From e7f19e72a543463eaa9c5065097d0f490b298b61 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 2 Aug 2022 13:03:33 +0800 Subject: [PATCH 14/27] update serie label --- Runtime/Serie/SerieHelper.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 9373e8fd..e889a2f8 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -440,15 +440,29 @@ namespace XCharts.Runtime public static LabelStyle GetSerieLabel(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { if (state == SerieState.Auto) state = GetSerieState(serie, serieData); - var stateStyle = GetStateStyle(serie, serieData, state); - return stateStyle == null?serie.label : stateStyle.label; + if (state == SerieState.Normal) + { + return serieData != null && serieData.labelStyle != null? serieData.labelStyle : serie.label; + } + else + { + var stateStyle = GetStateStyle(serie, serieData, state); + return stateStyle == null?serie.label : stateStyle.label; + } } public static LabelLine GetSerieLabelLine(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) { if (state == SerieState.Auto) state = GetSerieState(serie, serieData); - var stateStyle = GetStateStyle(serie, serieData, state); - return stateStyle == null?serie.labelLine : stateStyle.labelLine; + if (state == SerieState.Normal) + { + return serieData != null && serieData.labelLine != null? serieData.labelLine : serie.labelLine; + } + else + { + var stateStyle = GetStateStyle(serie, serieData, state); + return stateStyle == null?serie.labelLine : stateStyle.labelLine; + } } public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData, SerieState state = SerieState.Auto) From 19914586aeec57c3c0be92f3d8dbe37be8af7ef2 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 8 Aug 2022 07:43:19 +0800 Subject: [PATCH 15/27] [optimize][serie] optimize index of serieData --- CHANGELOG.md | 1 + Editor/Series/SerieEditor.cs | 9 ++++++--- Editor/Series/SerieListEditor.cs | 7 +++++++ Runtime/Helper/CheckHelper.cs | 22 +++++++++++++++++---- Runtime/Internal/BaseChart.Serie.cs | 12 +++++++++++ Runtime/Serie/Line/LineHandler.GridCoord.cs | 3 +++ Runtime/Serie/Serie.cs | 17 ++++++++++++++++ 7 files changed, 64 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1898a7..432b1b45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.08.08) 优化`Serie`的数据项索引维护,增加检测和修复功能 * (2022.07.29) 修复在某些`Unity`版本导入后图表创建异常的问题 * (2022.07.29) 增加`Axis`为`Time`时间轴时,支持次刻度和次分割线 * (2022.07.28) 优化`Radar`雷达图效果 diff --git a/Editor/Series/SerieEditor.cs b/Editor/Series/SerieEditor.cs index 1d07a793..33f62f68 100644 --- a/Editor/Series/SerieEditor.cs +++ b/Editor/Series/SerieEditor.cs @@ -72,6 +72,7 @@ namespace XCharts.Editor { while (listSize > m_Datas.arraySize) m_Datas.arraySize++; while (listSize < m_Datas.arraySize) m_Datas.arraySize--; + serie.ResetDataIndex(); } if (listSize > 30) // && !XCSettings.editorShowAllListData) { @@ -114,7 +115,9 @@ namespace XCharts.Editor m_DataElementFoldout[index] = false; } var fieldCount = dimension + (showName ? 1 : 0); - m_DataElementFoldout[index] = ChartEditorHelper.DrawHeader("SerieData " + index, flag, false, null, + var serieData = m_Datas.GetArrayElementAtIndex(index); + var dataIndex = serieData.FindPropertyRelative("m_Index").intValue; + m_DataElementFoldout[index] = ChartEditorHelper.DrawHeader("SerieData " + dataIndex, flag, false, null, delegate(Rect drawRect) { //drawRect.width -= 2f; @@ -124,7 +127,7 @@ namespace XCharts.Editor var lastWid = drawRect.width; var lastFieldWid = EditorGUIUtility.fieldWidth; var lastLabelWid = EditorGUIUtility.labelWidth; - var serieData = m_Datas.GetArrayElementAtIndex(index); + //var serieData = m_Datas.GetArrayElementAtIndex(index); var sereName = serieData.FindPropertyRelative("m_Name"); var data = serieData.FindPropertyRelative("m_Data"); #if UNITY_2019_3_OR_NEWER @@ -190,7 +193,7 @@ namespace XCharts.Editor EditorGUI.indentLevel++; var serieData = m_Datas.GetArrayElementAtIndex(index); PropertyField(serieData.FindPropertyRelative("m_Name")); - PropertyField(serieData.FindPropertyRelative("m_State")); + //PropertyField(serieData.FindPropertyRelative("m_State")); if (serie.GetType().IsDefined(typeof(SerieDataExtraFieldAttribute), false)) { var attribute = serie.GetType().GetAttribute(); diff --git a/Editor/Series/SerieListEditor.cs b/Editor/Series/SerieListEditor.cs index 280ee259..02e39e86 100644 --- a/Editor/Series/SerieListEditor.cs +++ b/Editor/Series/SerieListEditor.cs @@ -162,6 +162,13 @@ namespace XCharts.Editor RefreshEditors(); } })); + editor.menus.Add(new HeaderMenuInfo("Reset Data Index", () => + { + if (chart.ResetDataIndex(id)) + { + RefreshEditors(); + } + })); foreach (var type in GetCovertToSerie(editor.serie.GetType())) { editor.menus.Add(new HeaderMenuInfo("Covert to " + type.Name, () => diff --git a/Runtime/Helper/CheckHelper.cs b/Runtime/Helper/CheckHelper.cs index 8ccd886a..f070e5e6 100644 --- a/Runtime/Helper/CheckHelper.cs +++ b/Runtime/Helper/CheckHelper.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Text; using UnityEngine; @@ -67,26 +68,35 @@ namespace XCharts.Runtime // } } - private static void CheckLegend(BaseChart chart, StringBuilder sb) - { } + private static void CheckLegend(BaseChart chart, StringBuilder sb) { } - private static void CheckGrid(BaseChart chart, StringBuilder sb) - { } + private static void CheckGrid(BaseChart chart, StringBuilder sb) { } private static void CheckSerie(BaseChart chart, StringBuilder sb) { var allDataIsEmpty = true; var allDataIsZero = true; var allSerieIsHide = true; + var set = new HashSet(); foreach (var serie in chart.series) { if (serie.show) allSerieIsHide = false; if (serie.dataCount > 0) { allDataIsEmpty = false; + var dataIndexError = 0; + set.Clear(); for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.GetSerieData(i); + if (set.Contains(serieData.index)) + { + dataIndexError++; + } + else + { + set.Add(serieData.index); + } for (int j = 1; j < serieData.data.Count; j++) { if (serieData.GetData(j) != 0) @@ -101,6 +111,10 @@ namespace XCharts.Runtime { sb.AppendFormat("warning:serie {0} serieData.data.count[{1}] not match showDataDimension[{2}]\n", serie.index, dataCount, serie.showDataDimension); } + if (dataIndexError > 0) + { + sb.AppendFormat("error: data index error, count={0}/{1}\n", dataIndexError, serie.dataCount); + } } else { diff --git a/Runtime/Internal/BaseChart.Serie.cs b/Runtime/Internal/BaseChart.Serie.cs index 8d8c0a5e..0acbc8e5 100644 --- a/Runtime/Internal/BaseChart.Serie.cs +++ b/Runtime/Internal/BaseChart.Serie.cs @@ -61,6 +61,18 @@ namespace XCharts.Runtime return true; } + /// + /// 重置serie的数据项索引。避免数据项索引异常。 + /// + /// + public bool ResetDataIndex(int serieIndex) + { + var serie = GetSerie(serieIndex); + if (serie != null) + return serie.ResetDataIndex(); + return false; + } + public bool CanAddSerie() where T : Serie { return CanAddSerie(typeof(T)); diff --git a/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Runtime/Serie/Line/LineHandler.GridCoord.cs index a3f5c193..c2dfb891 100644 --- a/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -57,6 +57,7 @@ namespace XCharts.Runtime m_LastCheckContextFlag = needCheck; var themeSymbolSize = chart.theme.serie.lineSymbolSize; var needInteract = false; + serie.ResetDataIndex(); if (m_LegendEnter) { serie.context.pointerEnter = true; @@ -112,7 +113,9 @@ namespace XCharts.Runtime } } if (lastIndex != serie.context.pointerItemDataIndex) + { needInteract = true; + } } if (needInteract) { diff --git a/Runtime/Serie/Serie.cs b/Runtime/Serie/Serie.cs index 06f485e9..151e9fb9 100644 --- a/Runtime/Serie/Serie.cs +++ b/Runtime/Serie/Serie.cs @@ -1159,6 +1159,23 @@ namespace XCharts.Runtime serieData.interact.Reset(); } + /// + /// 重置数据项索引。避免部分数据项的索引异常。 + /// + public bool ResetDataIndex() + { + var flag = false; + for (int i = 0; i < m_Data.Count; i++) + { + if (m_Data[i].index != i) + { + m_Data[i].index = i; + flag = true; + } + } + return flag; + } + /// /// 清空所有数据 /// From d1f9c7757101aa3e570b0f220cffb9764c6ed634 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 9 Aug 2022 08:01:19 +0800 Subject: [PATCH 16/27] [bug] fix serieData.index error --- CHANGELOG.md | 1 + Runtime/Serie/SerieHandler.cs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 432b1b45..eda4176d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.08.09) 修复`Serie`的数据项索引异常引起的其他问题 * (2022.08.08) 优化`Serie`的数据项索引维护,增加检测和修复功能 * (2022.07.29) 修复在某些`Unity`版本导入后图表创建异常的问题 * (2022.07.29) 增加`Axis`为`Time`时间轴时,支持次刻度和次分割线 diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 1ff1b82a..3c0db474 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -218,7 +218,6 @@ namespace XCharts.Runtime for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; - serieData.index = count; serieData.labelObject = null; if (AddSerieLabel(m_SerieLabelRoot, serieData, ref count)) { From f1f2ea78befba6271cfbb7d95a3943f3691d6e3f Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 9 Aug 2022 08:29:06 +0800 Subject: [PATCH 17/27] [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); } From 9981ce2d23ad66fb5f74648cfc4ca23de4be4782 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 9 Aug 2022 13:38:23 +0800 Subject: [PATCH 18/27] [optimize][axis] optimize minor split line of time axis --- CHANGELOG.md | 1 + Runtime/Component/Axis/AxisHandler.cs | 6 ++++++ Runtime/Utilities/DateTimeUtil.cs | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f48089..bc116733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.08.09) 优化`Axis`的`Time`时间轴的次分割线 * (2022.08.09) 增加`AreaStyle`的`innerFill`参数支持填充凸多边形 * (2022.08.08) 优化`Serie`的数据项索引维护,增加检测和修复功能,修复相关问题 * (2022.07.29) 修复`Unity`版本兼容:在某些版本导入后图表创建异常的问题 diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 50e9b3ac..0a86e596 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -562,6 +562,12 @@ namespace XCharts if (AxisHelper.NeedShowSplit(axis)) { var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom); + if (axis.IsTime()) + { + size += 1; + if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue)) + size += 1; + } var tickWidth = axis.axisTick.GetWidth(theme.tickWidth); var tickColor = axis.axisTick.GetColor(theme.tickColor); var current = orient == Orient.Horizonal ? startX : startY; diff --git a/Runtime/Utilities/DateTimeUtil.cs b/Runtime/Utilities/DateTimeUtil.cs index cf97f145..1ff3fa97 100644 --- a/Runtime/Utilities/DateTimeUtil.cs +++ b/Runtime/Utilities/DateTimeUtil.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using UnityEngine; namespace XCharts.Runtime { @@ -160,7 +161,7 @@ namespace XCharts.Runtime private static void AddTickTimestamp(List list, int startTimestamp, int maxTimestamp, int tickSecond) { - while (startTimestamp < maxTimestamp) + while (startTimestamp <= maxTimestamp) { list.Add(startTimestamp); startTimestamp += tickSecond; From fcc1314f17f0f14a63cd13e2f887eb28c6352347 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 10 Aug 2022 07:22:41 +0800 Subject: [PATCH 19/27] [optimize][axis] set chart default layer to UI --- CHANGELOG.md | 12 ++++++++++++ Editor/Windows/XChartsEditor.cs | 1 + Runtime/Internal/Utilities/ChartHelper.cs | 2 ++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc116733..879a8495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,18 @@ ## master +### 版本要点 + +* `Serie`支持高亮,淡出和选中三状态配置:`EmphasisStyle`,`BlurStyle`和`SelectStyle` +* `Axis`支持坐标轴次刻度和次分割线:`MinorTick`和`MinorSplitLine` +* `Serie`支持不同的取色策略:`colorBy` +* `Radar`支持平滑曲线:`smooth` +* `Line`支持当作凸多边形填充:`AreaStyle`的`innerFill` +* `DataZoom`支持时间轴 + +### 日志详情 + +* (2022.08.10) 优化`Chart`的默认`layer`设置为`UI` * (2022.08.09) 优化`Axis`的`Time`时间轴的次分割线 * (2022.08.09) 增加`AreaStyle`的`innerFill`参数支持填充凸多边形 * (2022.08.08) 优化`Serie`的数据项索引维护,增加检测和修复功能,修复相关问题 diff --git a/Editor/Windows/XChartsEditor.cs b/Editor/Windows/XChartsEditor.cs index eae7e193..6725ae7b 100644 --- a/Editor/Windows/XChartsEditor.cs +++ b/Editor/Windows/XChartsEditor.cs @@ -62,6 +62,7 @@ namespace XCharts.Editor XCThemeMgr.CheckReloadTheme(); var chart = new GameObject(); chart.name = GetName(parent, chartName); + chart.layer = LayerMask.NameToLayer("UI"); var t = chart.AddComponent(); chart.transform.SetParent(parent); chart.transform.localScale = Vector3.one; diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 29370827..b60cbeee 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -209,6 +209,7 @@ namespace XCharts.Runtime obj.transform.SetParent(parent); obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; + obj.layer = parent.gameObject.layer; } RectTransform rect = GetOrAddComponent(obj); rect.localPosition = Vector3.zero; @@ -237,6 +238,7 @@ namespace XCharts.Runtime { GameObject txtObj = AddObject(objectName, parent, anchorMin, anchorMax, pivot, sizeDelta); txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); + txtObj.layer = parent.gameObject.layer; if (chartText == null) chartText = new ChartText(); #if dUI_TextMeshPro From 65d32f7aec0914bfaa0e0ef74738ec847f26fd76 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 10 Aug 2022 08:16:19 +0800 Subject: [PATCH 20/27] [improve][editor] improve editor edit --- CHANGELOG.md | 1 + Editor/MainComponents/ThemeEditor.cs | 35 ++++++++++++++++++++++++---- Editor/Series/SerieEditor.cs | 2 +- Editor/Windows/XChartsEditor.cs | 1 + 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 879a8495..b6783212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ ### 日志详情 +* (2022.08.10) 优化`Theme`的字体同步操作 * (2022.08.10) 优化`Chart`的默认`layer`设置为`UI` * (2022.08.09) 优化`Axis`的`Time`时间轴的次分割线 * (2022.08.09) 增加`AreaStyle`的`innerFill`参数支持填充凸多边形 diff --git a/Editor/MainComponents/ThemeEditor.cs b/Editor/MainComponents/ThemeEditor.cs index 86fcf5f7..76012efe 100644 --- a/Editor/MainComponents/ThemeEditor.cs +++ b/Editor/MainComponents/ThemeEditor.cs @@ -12,8 +12,9 @@ namespace XCharts.Editor { static class Styles { - internal static GUIContent btnReset = new GUIContent("Reset", "Reset to default theme"); - internal static GUIContent btnSync = new GUIContent("Sync Font", "Sync main theme font to sub theme font"); + internal static GUIContent btnReset = new GUIContent("Reset to Default", "Reset to default theme"); + internal static GUIContent btnSyncFontToSubTheme = new GUIContent("Sync Font to Sub Theme", "Sync main theme font to sub theme font"); + internal static GUIContent btnSyncFontFromSetting = new GUIContent("Sync Font from Setting", "Sync main theme font and sub theme font from XCSetting font"); } private Theme m_Theme; @@ -28,11 +29,35 @@ namespace XCharts.Editor base.OnInspectorGUI(); if (GUILayout.Button(Styles.btnReset)) { - m_Theme.ResetTheme(); + if (EditorUtility.DisplayDialog(Styles.btnReset.text, Styles.btnReset.tooltip, "Yes", "Cancel")) + { + m_Theme.ResetTheme(); + Debug.Log("XCharts: Reset Finish."); + } } - if (GUILayout.Button(Styles.btnSync)) + if (GUILayout.Button(Styles.btnSyncFontFromSetting)) { - m_Theme.SyncFontToSubComponent(); + if (EditorUtility.DisplayDialog(Styles.btnSyncFontFromSetting.text, Styles.btnSyncFontFromSetting.tooltip, "Yes", "Cancel")) + { + m_Theme.common.font = XCSettings.font; + m_Theme.SyncFontToSubComponent(); +#if dUI_TextMeshPro + m_Theme.common.tmpFont = XCSettings.tmpFont; + m_Theme.SyncTMPFontToSubComponent(); +#endif + Debug.Log("XCharts: Sync Finish."); + } + } + if (GUILayout.Button(Styles.btnSyncFontToSubTheme)) + { + if (EditorUtility.DisplayDialog(Styles.btnSyncFontToSubTheme.text, Styles.btnSyncFontToSubTheme.tooltip, "Yes", "Cancel")) + { + m_Theme.SyncFontToSubComponent(); +#if dUI_TextMeshPro + m_Theme.SyncTMPFontToSubComponent(); +#endif + Debug.Log("XCharts: Sync Finish."); + } } } } diff --git a/Editor/Series/SerieEditor.cs b/Editor/Series/SerieEditor.cs index 33f62f68..82cfa37d 100644 --- a/Editor/Series/SerieEditor.cs +++ b/Editor/Series/SerieEditor.cs @@ -156,7 +156,7 @@ namespace XCharts.Editor var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap; var dataWidTotal = (currentWidth - (startX + 20.5f + 1)); var dataWid = dataWidTotal / fieldCount; - var xWid = dataWid - 2; + var xWid = dataWid - 0; for (int i = 0; i < dimension; i++) { var dataCount = i < 1 ? 2 : i + 1; diff --git a/Editor/Windows/XChartsEditor.cs b/Editor/Windows/XChartsEditor.cs index 6725ae7b..ed33ec98 100644 --- a/Editor/Windows/XChartsEditor.cs +++ b/Editor/Windows/XChartsEditor.cs @@ -67,6 +67,7 @@ namespace XCharts.Editor chart.transform.SetParent(parent); chart.transform.localScale = Vector3.one; chart.transform.localPosition = Vector3.zero; + chart.transform.localRotation = Quaternion.Euler(0, 0, 0); var rect = chart.GetComponent(); rect.anchorMin = new Vector2(0.5f, 0.5f); rect.anchorMax = new Vector2(0.5f, 0.5f); From 0f31f057dfd360bde144a7b1ecae0891f19df41a Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 10 Aug 2022 13:18:44 +0800 Subject: [PATCH 21/27] [bug] fix rotation --- Runtime/Internal/Utilities/ChartHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index b60cbeee..be19f64a 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -195,6 +195,7 @@ namespace XCharts.Runtime SetActive(obj, true); obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; + obj.transform.localRotation = Quaternion.Euler(0, 0, 0); } else if (replaceIndex >= 0 && replaceIndex < parent.childCount) { @@ -209,6 +210,7 @@ namespace XCharts.Runtime obj.transform.SetParent(parent); obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; + obj.transform.localRotation = Quaternion.Euler(0, 0, 0); obj.layer = parent.gameObject.layer; } RectTransform rect = GetOrAddComponent(obj); From 34b132735da013aa1717d7e00d21b1a5e07d96d1 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 10 Aug 2022 13:19:26 +0800 Subject: [PATCH 22/27] [bug] fix chart.RemoveSerie (#219) --- CHANGELOG.md | 3 +++ Runtime/Internal/BaseChart.Serie.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6783212..a977f428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,9 +65,12 @@ * `Radar`支持平滑曲线:`smooth` * `Line`支持当作凸多边形填充:`AreaStyle`的`innerFill` * `DataZoom`支持时间轴 +* 其他优化和问题修复 ### 日志详情 +* (2022.08.10) 修复`Chart`在3D相机下部分组件显示异常的问题 +* (2022.08.10) 修复`RemoveSerie()`接口不生效的问题 (#219) * (2022.08.10) 优化`Theme`的字体同步操作 * (2022.08.10) 优化`Chart`的默认`layer`设置为`UI` * (2022.08.09) 优化`Axis`的`Time`时间轴的次分割线 diff --git a/Runtime/Internal/BaseChart.Serie.cs b/Runtime/Internal/BaseChart.Serie.cs index 0acbc8e5..4b0a3cec 100644 --- a/Runtime/Internal/BaseChart.Serie.cs +++ b/Runtime/Internal/BaseChart.Serie.cs @@ -141,8 +141,15 @@ namespace XCharts.Runtime for (int i = m_Series.Count - 1; i >= 0; i--) { var serie = m_Series[i]; - if (string.IsNullOrEmpty(serie.serieName) && serie.serieName.Equals(serieName)) + if (string.IsNullOrEmpty(serieName)) + { + if (string.IsNullOrEmpty(serie.serieName)) + RemoveSerie(serie); + } + else if (serieName.Equals(serie.serieName)) + { RemoveSerie(serie); + } } } From ca5470a35127d0c2a7a399afca571ee30c44dd9d Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 11 Aug 2022 08:11:43 +0800 Subject: [PATCH 23/27] [feature][tooltip] support `ignoreDataDefaultContent` --- CHANGELOG.md | 1 + Documentation/XChartsConfiguration-EN.md | 2 +- Documentation/XChartsConfiguration-ZH.md | 4 +-- Runtime/Component/Tooltip/Tooltip.cs | 2 +- Runtime/Component/Tooltip/TooltipHandler.cs | 3 +- Runtime/Component/Tooltip/TooltipView.cs | 6 ++-- Runtime/Serie/Bar/BarHandler.cs | 4 +-- Runtime/Serie/Bar/SimplifiedBarHandler.cs | 4 +-- .../Serie/Candlestick/CandlestickHandler.cs | 2 +- .../SimplifiedCandlestickHandler.cs | 2 +- Runtime/Serie/Heatmap/HeatmapHandler.cs | 2 +- Runtime/Serie/Line/LineHandler.cs | 4 +-- Runtime/Serie/Line/SimplifiedLineHandler.cs | 4 +-- Runtime/Serie/Pie/PieHandler.cs | 4 +-- Runtime/Serie/Radar/RadarHandler.cs | 4 +-- Runtime/Serie/Ring/RingHandler.cs | 2 +- Runtime/Serie/Scatter/BaseScatterHandler.cs | 2 +- Runtime/Serie/SerieHandler.cs | 28 ++++++++++++++----- Runtime/Serie/SerieParams.cs | 1 + 19 files changed, 48 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a977f428..d45b9baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ ### 日志详情 +* (2022.08.11) 优化`Tooltip`支持`ignoreDataDefaultContent` * (2022.08.10) 修复`Chart`在3D相机下部分组件显示异常的问题 * (2022.08.10) 修复`RemoveSerie()`接口不生效的问题 (#219) * (2022.08.10) 优化`Theme`的字体同步操作 diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index f3834748..ed930332 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -215,7 +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. +|`innerFill`||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 4a42b6a8..fbeed47d 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -215,7 +215,7 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent |`color`|||区域填充的颜色,如果toColor不是默认值,则表示渐变色的起点颜色。 |`toColor`|||渐变色的终点颜色。 |`opacity`|0.6f||图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 -|`fill`|true|v3.2.0|是否只填充多边形区域。目前只支持凸多边形。 +|`innerFill`||v3.2.0|是否只填充多边形区域。目前只支持凸多边形。 ## `ArrowStyle` @@ -1433,7 +1433,7 @@ Inherits or Implemented: [MainComponent](#MainComponent) |`paddingLeftRight`|10||左右边距。 |`paddingTopBottom`|10||上下边距。 |`ignoreDataShow`|false||是否显示忽略数据在tooltip上。 -|`ignoreDataDefaultContent`|||被忽略数据的默认显示字符信息。 +|`ignoreDataDefaultContent`|||被忽略数据的默认显示字符信息。如果设置为空,则表示完全不显示忽略数据。 |`showContent`|true||是否显示提示框浮层,默认显示。只需tooltip触发事件或显示axisPointer而不需要显示内容时可配置该项为false。 |`alwayShowContent`|false||是否触发后一直显示提示框浮层。 |`offset`|Vector2(18f, -25f)||提示框相对于鼠标位置的偏移。 diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs index 6b34a910..418c679a 100644 --- a/Runtime/Component/Tooltip/Tooltip.cs +++ b/Runtime/Component/Tooltip/Tooltip.cs @@ -250,7 +250,7 @@ namespace XCharts.Runtime public bool ignoreDataShow { get { return m_IgnoreDataShow; } set { m_IgnoreDataShow = value; } } /// /// The default display character information for ignored data. - /// |被忽略数据的默认显示字符信息。 + /// |被忽略数据的默认显示字符信息。如果设置为空,则表示完全不显示忽略数据。 /// public string ignoreDataDefaultContent { get { return m_IgnoreDataDefaultContent; } set { m_IgnoreDataDefaultContent = value; } } /// diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index 67bac520..4012efd2 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -374,7 +374,7 @@ namespace XCharts.Runtime tooltip.context.pointer = chart.pointerPos; serie.handler.UpdateTooltipSerieParams(serie.context.pointerItemDataIndex, false, null, - tooltip.marker, tooltip.itemFormatter, tooltip.numericFormatter, + tooltip.marker, tooltip.itemFormatter, tooltip.numericFormatter, tooltip.ignoreDataDefaultContent, ref tooltip.context.data.param, ref tooltip.context.data.title); TooltipHelper.ResetTooltipParamsByItemFormatter(tooltip, chart); @@ -423,6 +423,7 @@ namespace XCharts.Runtime serie.context.pointerItemDataIndex = dataIndex; serie.handler.UpdateTooltipSerieParams(dataIndex, showCategory, category, tooltip.marker, tooltip.itemFormatter, tooltip.numericFormatter, + tooltip.ignoreDataDefaultContent, ref tooltip.context.data.param, ref tooltip.context.data.title); } diff --git a/Runtime/Component/Tooltip/TooltipView.cs b/Runtime/Component/Tooltip/TooltipView.cs index 959283c0..3e47f94d 100644 --- a/Runtime/Component/Tooltip/TooltipView.cs +++ b/Runtime/Component/Tooltip/TooltipView.cs @@ -69,6 +69,7 @@ namespace XCharts.Runtime { if (tooltip == null) return; var data = tooltip.context.data; + var ignoreColumn = string.IsNullOrEmpty(tooltip.ignoreDataDefaultContent); var titleActive = !string.IsNullOrEmpty(data.title); if (titleActive != title.gameObject.activeSelf) @@ -80,7 +81,7 @@ namespace XCharts.Runtime { var item = GetItem(i); var param = data.param[i]; - if (param.columns.Count <= 0) + if (param.columns.Count <= 0 || (ignoreColumn && param.ignore)) { item.gameObject.SetActive(false); continue; @@ -112,9 +113,6 @@ namespace XCharts.Runtime m_Items[i].gameObject.SetActive(false); } ResetSize(); - // border.effectColor = data.param.Count == 1 - // ? data.param[0].color - // : tooltip.borderColor; UpdatePosition(tooltip.context.pointer + tooltip.offset); tooltip.gameObject.transform.SetAsLastSibling(); } diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index 92b8d54d..bd0b62a8 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -20,11 +20,11 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { UpdateCoordSerieParams(ref paramList, ref title, dataIndex, showCategory, category, - marker, itemFormatter, numericFormatter); + marker, itemFormatter, numericFormatter, ignoreDataDefaultContent); } public override void DrawSerie(VertexHelper vh) diff --git a/Runtime/Serie/Bar/SimplifiedBarHandler.cs b/Runtime/Serie/Bar/SimplifiedBarHandler.cs index ca4a92ce..fdcf7b01 100644 --- a/Runtime/Serie/Bar/SimplifiedBarHandler.cs +++ b/Runtime/Serie/Bar/SimplifiedBarHandler.cs @@ -18,11 +18,11 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { UpdateCoordSerieParams(ref paramList, ref title, dataIndex, showCategory, category, - marker, itemFormatter, numericFormatter); + marker, itemFormatter, numericFormatter, ignoreDataDefaultContent); } public override void DrawSerie(VertexHelper vh) diff --git a/Runtime/Serie/Candlestick/CandlestickHandler.cs b/Runtime/Serie/Candlestick/CandlestickHandler.cs index 3eafef1b..19d3aaf8 100644 --- a/Runtime/Serie/Candlestick/CandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/CandlestickHandler.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { if (dataIndex < 0) diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs index 0bbb90dd..3b83497b 100644 --- a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs @@ -14,7 +14,7 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { if (dataIndex < 0) diff --git a/Runtime/Serie/Heatmap/HeatmapHandler.cs b/Runtime/Serie/Heatmap/HeatmapHandler.cs index 51aade31..9f9fc7bc 100644 --- a/Runtime/Serie/Heatmap/HeatmapHandler.cs +++ b/Runtime/Serie/Heatmap/HeatmapHandler.cs @@ -24,7 +24,7 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { dataIndex = serie.context.pointerItemDataIndex; diff --git a/Runtime/Serie/Line/LineHandler.cs b/Runtime/Serie/Line/LineHandler.cs index 889fb776..9d9efa1a 100644 --- a/Runtime/Serie/Line/LineHandler.cs +++ b/Runtime/Serie/Line/LineHandler.cs @@ -22,11 +22,11 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { UpdateCoordSerieParams(ref paramList, ref title, dataIndex, showCategory, category, - marker, itemFormatter, numericFormatter); + marker, itemFormatter, numericFormatter, ignoreDataDefaultContent); } public override void DrawSerie(VertexHelper vh) diff --git a/Runtime/Serie/Line/SimplifiedLineHandler.cs b/Runtime/Serie/Line/SimplifiedLineHandler.cs index 73c9c82b..6dc172d2 100644 --- a/Runtime/Serie/Line/SimplifiedLineHandler.cs +++ b/Runtime/Serie/Line/SimplifiedLineHandler.cs @@ -19,11 +19,11 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { UpdateCoordSerieParams(ref paramList, ref title, dataIndex, showCategory, category, - marker, itemFormatter, numericFormatter); + marker, itemFormatter, numericFormatter, ignoreDataDefaultContent); } public override void DrawSerie(VertexHelper vh) diff --git a/Runtime/Serie/Pie/PieHandler.cs b/Runtime/Serie/Pie/PieHandler.cs index e7ec59bd..c06a4a18 100644 --- a/Runtime/Serie/Pie/PieHandler.cs +++ b/Runtime/Serie/Pie/PieHandler.cs @@ -34,11 +34,11 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { UpdateItemSerieParams(ref paramList, ref title, dataIndex, category, - marker, itemFormatter, numericFormatter); + marker, itemFormatter, numericFormatter, ignoreDataDefaultContent); } public override Vector3 GetSerieDataLabelPosition(SerieData serieData, LabelStyle label) diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 5b7b7fc7..403a35fa 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -30,7 +30,7 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { if (!serie.context.pointerEnter) @@ -43,7 +43,7 @@ namespace XCharts.Runtime { var colorIndex1 = serie.colorByData ? dataIndex : serie.context.colorIndex; UpdateItemSerieParams(ref paramList, ref title, dataIndex, category, - marker, itemFormatter, numericFormatter, 1, colorIndex1); + marker, itemFormatter, numericFormatter, ignoreDataDefaultContent, 1, colorIndex1); return; } diff --git a/Runtime/Serie/Ring/RingHandler.cs b/Runtime/Serie/Ring/RingHandler.cs index df5a27f1..643b6711 100644 --- a/Runtime/Serie/Ring/RingHandler.cs +++ b/Runtime/Serie/Ring/RingHandler.cs @@ -74,7 +74,7 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { if (dataIndex < 0) diff --git a/Runtime/Serie/Scatter/BaseScatterHandler.cs b/Runtime/Serie/Scatter/BaseScatterHandler.cs index f1a0cab4..fa703995 100644 --- a/Runtime/Serie/Scatter/BaseScatterHandler.cs +++ b/Runtime/Serie/Scatter/BaseScatterHandler.cs @@ -16,7 +16,7 @@ namespace XCharts.Runtime } public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, - string marker, string itemFormatter, string numericFormatter, + string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { dataIndex = serie.context.pointerItemDataIndex; diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 3c0db474..c8cc95ce 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -33,7 +33,7 @@ namespace XCharts.Runtime public virtual void RefreshLabelInternal() { } public virtual void UpdateTooltipSerieParams(int dataIndex, bool showCategory, string category, string marker, - string itemFormatter, string numericFormatter, + string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, ref List paramList, ref string title) { } public virtual void OnLegendButtonClick(int index, string legendName, bool show) { } public virtual void OnLegendButtonEnter(int index, string legendName) { } @@ -492,8 +492,9 @@ namespace XCharts.Runtime protected void UpdateCoordSerieParams(ref List paramList, ref string title, int dataIndex, bool showCategory, string category, string marker, - string itemFormatter, string numericFormatter) + string itemFormatter, string numericFormatter, string ignoreDataDefaultContent) { + var dimension = 1; if (dataIndex < 0) dataIndex = serie.context.pointerItemDataIndex; @@ -504,6 +505,10 @@ namespace XCharts.Runtime if (serieData == null) return; + var ignore = serie.IsIgnoreValue(serieData, dimension); + if (ignore && string.IsNullOrEmpty(ignoreDataDefaultContent)) + return; + itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter)) return; @@ -512,10 +517,11 @@ namespace XCharts.Runtime param.serieName = serie.serieName; param.serieIndex = serie.index; param.category = category; - param.dimension = 1; + param.dimension = dimension; param.serieData = serieData; param.dataCount = serie.dataCount; - param.value = serieData.GetData(1); + param.value = serieData.GetData(dimension); + param.ignore = ignore; param.total = serie.yTotal; param.color = chart.GetItemColor(serie, serieData); param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); @@ -525,14 +531,15 @@ namespace XCharts.Runtime param.columns.Add(param.marker); param.columns.Add(showCategory ? category : serie.serieName); - param.columns.Add(ChartCached.NumberToStr(param.value, param.numericFormatter)); + param.columns.Add(ignore?ignoreDataDefaultContent : ChartCached.NumberToStr(param.value, param.numericFormatter)); paramList.Add(param); } protected void UpdateItemSerieParams(ref List paramList, ref string title, int dataIndex, string category, string marker, - string itemFormatter, string numericFormatter, int dimension = 1, int colorIndex = -1) + string itemFormatter, string numericFormatter, string ignoreDataDefaultContent, + int dimension = 1, int colorIndex = -1) { if (dataIndex < 0) dataIndex = serie.context.pointerItemDataIndex; @@ -544,6 +551,10 @@ namespace XCharts.Runtime if (serieData == null) return; + var ignore = serie.IsIgnoreValue(serieData, dimension); + if (ignore && string.IsNullOrEmpty(ignoreDataDefaultContent)) + return; + itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter); if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter)) return; @@ -556,11 +567,13 @@ namespace XCharts.Runtime var param = serie.context.param; param.serieName = serie.serieName; param.serieIndex = serie.index; + param.category = category; param.dimension = dimension; param.serieData = serieData; param.dataCount = serie.dataCount; param.value = serieData.GetData(param.dimension); + param.ignore = ignore; param.total = SerieHelper.GetMaxData(serie, dimension); param.color = color; param.marker = SerieHelper.GetItemMarker(serie, serieData, marker); @@ -570,7 +583,8 @@ namespace XCharts.Runtime param.columns.Add(param.marker); param.columns.Add(serieData.name); - param.columns.Add(ChartCached.NumberToStr(param.value, param.numericFormatter)); + + param.columns.Add(ignore?ignoreDataDefaultContent : ChartCached.NumberToStr(param.value, param.numericFormatter)); paramList.Add(param); } diff --git a/Runtime/Serie/SerieParams.cs b/Runtime/Serie/SerieParams.cs index d2948a8c..1118baa8 100644 --- a/Runtime/Serie/SerieParams.cs +++ b/Runtime/Serie/SerieParams.cs @@ -19,6 +19,7 @@ namespace XCharts.Runtime public Color32 color; public string itemFormatter; public string numericFormatter; + public bool ignore; public List columns = new List(); } } \ No newline at end of file From f32808a36dd19e9c2fea7a8c0c878eb6de225de9 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sat, 13 Aug 2022 13:38:02 +0800 Subject: [PATCH 24/27] [bug][datazoom] fix chart display error when datazoom enable. --- CHANGELOG.md | 1 + Runtime/Component/Tooltip/TooltipHandler.cs | 10 ++++++++-- Runtime/Internal/BaseChart.cs | 1 + Runtime/Serie/Bar/BarHandler.cs | 7 ++++++- Runtime/Serie/Bar/SimplifiedBarHandler.cs | 2 ++ Runtime/Serie/Candlestick/CandlestickHandler.cs | 2 ++ .../Candlestick/SimplifiedCandlestickHandler.cs | 2 ++ Runtime/Serie/Heatmap/HeatmapHandler.cs | 4 ++-- Runtime/Serie/Line/LineHandler.GridCoord.cs | 12 ++++++++---- Runtime/Serie/Line/SimplifiedLineHandler.cs | 1 + Runtime/Serie/Parallel/ParallelHandler.cs | 1 - Runtime/Serie/Pie/PieHandler.cs | 1 - Runtime/Serie/Radar/RadarHandler.cs | 5 +---- Runtime/Serie/Ring/RingHandler.cs | 2 -- Runtime/Serie/Scatter/BaseScatterHandler.cs | 2 ++ Runtime/Serie/SerieContext.cs | 4 ++++ Runtime/Serie/SerieData.cs | 4 ++++ Runtime/Serie/SerieHandler.cs | 12 ++++++++---- 18 files changed, 52 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d45b9baf..30e9f5ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ ### 日志详情 +* (2022.08.13) 修复`DataZoom`组件开启时图表显示效果可能不正确的问题 * (2022.08.11) 优化`Tooltip`支持`ignoreDataDefaultContent` * (2022.08.10) 修复`Chart`在3D相机下部分组件显示异常的问题 * (2022.08.10) 修复`RemoveSerie()`接口不生效的问题 (#219) diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index 4012efd2..a03205a6 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -293,7 +293,6 @@ namespace XCharts.Runtime for (int i = 0; i < dataCount; i++) { var serieData = serie.data[i]; - serieData.index = i; serie.context.sortedData.Add(serieData); } serie.context.sortedData.Sort(delegate(SerieData a, SerieData b) @@ -490,7 +489,6 @@ namespace XCharts.Runtime private void DrawXAxisIndicator(VertexHelper vh, Tooltip tooltip, GridCoord grid) { - var xAxes = chart.GetChartComponents(); var lineType = tooltip.lineStyle.GetType(chart.theme.tooltip.lineType); var lineWidth = tooltip.lineStyle.GetWidth(chart.theme.tooltip.lineWidth); @@ -512,6 +510,8 @@ namespace XCharts.Runtime pX += xAxis.IsCategory() ? (float) (xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) : xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width); + if (pX < grid.context.x) + break; Vector2 sp = new Vector2(pX, grid.context.y); Vector2 ep = new Vector2(pX, grid.context.y + grid.context.height); var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme); @@ -529,6 +529,8 @@ namespace XCharts.Runtime float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth; pX = (float) (grid.context.x + splitWidth * xAxis.context.pointerValue - (xAxis.boundaryGap ? 0 : splitWidth / 2)); + if (pX < grid.context.x) + break; float pY = grid.context.y + grid.context.height; Vector3 p1 = new Vector3(pX, grid.context.y); Vector3 p2 = new Vector3(pX, pY); @@ -571,6 +573,8 @@ namespace XCharts.Runtime case Tooltip.Type.Line: float pY = (float) (grid.context.y + yAxis.context.pointerValue * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0)); + if (pY < grid.context.y) + break; Vector2 sp = new Vector2(grid.context.x, pY); Vector2 ep = new Vector2(grid.context.x + grid.context.width, pY); var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme); @@ -589,6 +593,8 @@ namespace XCharts.Runtime float pX = grid.context.x + grid.context.width; pY = (float) (grid.context.y + splitWidth * yAxis.context.pointerValue - (yAxis.boundaryGap ? 0 : splitWidth / 2)); + if (pY < grid.context.y) + break; Vector3 p1 = new Vector3(grid.context.x, pY); Vector3 p2 = new Vector3(grid.context.x, pY + tooltipSplitWid); Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid); diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 266d53d6..fdbf414e 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -575,6 +575,7 @@ namespace XCharts.Runtime var serie = m_Series[i]; serie.context.colorIndex = GetLegendRealShowNameIndex(serie.legendName); serie.context.dataPoints.Clear(); + serie.context.dataIndexs.Clear(); serie.context.dataIgnores.Clear(); serie.animation.context.isAllItemAnimationEnd = true; if (!serie.context.pointerEnter) diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index bd0b62a8..5b4558ff 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -176,10 +176,10 @@ namespace XCharts.Runtime for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; - serieData.index = i; if (!serieData.show || serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); + serie.context.dataIndexs.Add(serieData.index); continue; } @@ -228,9 +228,14 @@ namespace XCharts.Runtime Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength); if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top))) + { serie.context.dataPoints.Add(top); + serie.context.dataIndexs.Add(serieData.index); + } else + { continue; + } if (serie.show && currHig != 0 && !serie.placeHolder) { diff --git a/Runtime/Serie/Bar/SimplifiedBarHandler.cs b/Runtime/Serie/Bar/SimplifiedBarHandler.cs index fdcf7b01..447c48db 100644 --- a/Runtime/Serie/Bar/SimplifiedBarHandler.cs +++ b/Runtime/Serie/Bar/SimplifiedBarHandler.cs @@ -152,6 +152,7 @@ namespace XCharts.Runtime if (!serieData.show || serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); + serie.context.dataIndexs.Add(serieData.index); continue; } @@ -184,6 +185,7 @@ namespace XCharts.Runtime serieData.context.position = top; serieData.context.rect = Rect.MinMaxRect(plb.x, plb.y, prb.x, prt.y); serie.context.dataPoints.Add(top); + serie.context.dataIndexs.Add(serieData.index); DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, false, m_SerieGrid, areaColor, areaToColor); diff --git a/Runtime/Serie/Candlestick/CandlestickHandler.cs b/Runtime/Serie/Candlestick/CandlestickHandler.cs index 19d3aaf8..dcbf690c 100644 --- a/Runtime/Serie/Candlestick/CandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/CandlestickHandler.cs @@ -111,6 +111,7 @@ namespace XCharts.Runtime if (serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); + serie.context.dataIndexs.Add(serieData.index); continue; } var state = SerieHelper.GetSerieState(serie, serieData); @@ -154,6 +155,7 @@ namespace XCharts.Runtime top = chart.ClampInGrid(grid, top); } serie.context.dataPoints.Add(top); + serie.context.dataIndexs.Add(serieData.index); var areaColor = isRise ? itemStyle.GetColor(theme.serie.candlestickColor) : itemStyle.GetColor0(theme.serie.candlestickColor0); diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs index 3b83497b..8266c6be 100644 --- a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs @@ -113,6 +113,7 @@ namespace XCharts.Runtime if (serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); + serie.context.dataIndexs.Add(serieData.index); continue; } var open = serieData.GetCurrData(0, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); @@ -154,6 +155,7 @@ namespace XCharts.Runtime // top = chart.ClampInGrid(grid, top); // } serie.context.dataPoints.Add(top); + serie.context.dataIndexs.Add(serieData.index); var areaColor = isRise ? itemStyle.GetColor(theme.serie.candlestickColor) : itemStyle.GetColor0(theme.serie.candlestickColor0); diff --git a/Runtime/Serie/Heatmap/HeatmapHandler.cs b/Runtime/Serie/Heatmap/HeatmapHandler.cs index 9f9fc7bc..806908b2 100644 --- a/Runtime/Serie/Heatmap/HeatmapHandler.cs +++ b/Runtime/Serie/Heatmap/HeatmapHandler.cs @@ -155,7 +155,6 @@ namespace XCharts.Runtime ChartConst.clearColor32; borderToColor.a = (byte) (borderToColor.a * serie.itemStyle.opacity); - serie.context.dataPoints.Clear(); serie.animation.InitProgress(0, xCount); var animationIndex = serie.animation.GetCurrIndex(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); @@ -165,13 +164,13 @@ namespace XCharts.Runtime for (int n = 0; n < serie.dataCount; n++) { var serieData = serie.data[n]; - serieData.index = n; var i = (int) serieData.GetData(0); var j = (int) serieData.GetData(1); var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count); if (serie.IsIgnoreValue(serieData, dimension)) { serie.context.dataPoints.Add(Vector3.zero); + serie.context.dataIndexs.Add(serieData.index); continue; } var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse, @@ -180,6 +179,7 @@ namespace XCharts.Runtime var pos = new Vector3(zeroX + (i + (xAxis.boundaryGap ? 0.5f : 0)) * xWidth, zeroY + (j + (yAxis.boundaryGap ? 0.5f : 0)) * yWidth); serie.context.dataPoints.Add(pos); + serie.context.dataIndexs.Add(serieData.index); serieData.context.position = pos; serieData.context.canShowLabel = false; diff --git a/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Runtime/Serie/Line/LineHandler.GridCoord.cs index c2dfb891..c3760d1c 100644 --- a/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -109,13 +109,16 @@ namespace XCharts.Runtime { serie.context.pointerEnter = true; serie.context.pointerItemDataIndex = serieData.index; - serie.interact.SetValue(ref needInteract, lineWidth, true); } } if (lastIndex != serie.context.pointerItemDataIndex) { needInteract = true; } + if (serie.context.pointerItemDataIndex >= 0) + serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate); + else + serie.interact.SetValue(ref needInteract, lineWidth); } if (needInteract) { @@ -148,7 +151,8 @@ namespace XCharts.Runtime for (int i = 0; i < count; i++) { - var serieData = serie.GetSerieData(i); + var index = serie.context.dataIndexs[i]; + var serieData = serie.GetSerieData(index); if (serieData == null) continue; if (serieData.context.isClip) @@ -156,7 +160,7 @@ namespace XCharts.Runtime var state = SerieHelper.GetSerieState(serie, serieData, true); var symbol = SerieHelper.GetSerieSymbol(serie, serieData, state); - if (!symbol.show || !symbol.ShowSymbol(i, count)) + if (!symbol.show || !symbol.ShowSymbol(index, count)) continue; var pos = serie.context.dataPoints[i]; @@ -178,7 +182,6 @@ namespace XCharts.Runtime serieData.interact.SetValue(ref interacting, symbolSize); symbolSize = serie.animation.GetSysmbolSize(symbolSize); } - float symbolBorder = 0f; float[] cornerRadius = null; Color32 symbolColor, symbolToColor, symbolEmptyColor, borderColor; @@ -335,6 +338,7 @@ namespace XCharts.Runtime serie.context.dataIgnores.Add(false); serieData.context.position = np; serie.context.dataPoints.Add(np); + serie.context.dataIndexs.Add(serieData.index); lp = np; } } diff --git a/Runtime/Serie/Line/SimplifiedLineHandler.cs b/Runtime/Serie/Line/SimplifiedLineHandler.cs index 6dc172d2..89d15938 100644 --- a/Runtime/Serie/Line/SimplifiedLineHandler.cs +++ b/Runtime/Serie/Line/SimplifiedLineHandler.cs @@ -208,6 +208,7 @@ namespace XCharts.Runtime serieData.context.position = np; serie.context.dataPoints.Add(np); + serie.context.dataIndexs.Add(serieData.index); serie.context.dataIgnores.Add(false); } } diff --git a/Runtime/Serie/Parallel/ParallelHandler.cs b/Runtime/Serie/Parallel/ParallelHandler.cs index 717a0ad2..c126f576 100644 --- a/Runtime/Serie/Parallel/ParallelHandler.cs +++ b/Runtime/Serie/Parallel/ParallelHandler.cs @@ -51,7 +51,6 @@ namespace XCharts.Runtime serie.animation.InitProgress(currDetailProgress, totalDetailProgress); - serie.context.dataPoints.Clear(); serie.containerIndex = parallel.index; serie.containterInstanceId = parallel.instanceId; diff --git a/Runtime/Serie/Pie/PieHandler.cs b/Runtime/Serie/Pie/PieHandler.cs index c06a4a18..966ebe01 100644 --- a/Runtime/Serie/Pie/PieHandler.cs +++ b/Runtime/Serie/Pie/PieHandler.cs @@ -195,7 +195,6 @@ namespace XCharts.Runtime for (int n = 0; n < data.Count; n++) { var serieData = data[n]; - serieData.index = n; var value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration); serieData.context.startAngle = startDegree; serieData.context.toAngle = startDegree; diff --git a/Runtime/Serie/Radar/RadarHandler.cs b/Runtime/Serie/Radar/RadarHandler.cs index 403a35fa..c01e80bf 100644 --- a/Runtime/Serie/Radar/RadarHandler.cs +++ b/Runtime/Serie/Radar/RadarHandler.cs @@ -110,7 +110,6 @@ namespace XCharts.Runtime for (int i = 0; i < serie.data.Count; i++) { var serieData = serie.data[i]; - serieData.index = i; var symbol = SerieHelper.GetSerieSymbol(serie, serieData); var symbolSize = symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize); if (needHideAll || m_LegendEnter) @@ -159,7 +158,6 @@ namespace XCharts.Runtime for (int i = 0; i < serie.data.Count; i++) { var serieData = serie.data[i]; - serieData.index = i; var size = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, themeSymbolSize); if (Vector3.Distance(chart.pointerPos, serieData.context.position) < size * 2) { @@ -351,7 +349,6 @@ namespace XCharts.Runtime var angle = 2 * Mathf.PI / indicatorNum; var centerPos = m_RadarCoord.context.center; serie.animation.InitProgress(0, 1); - serie.context.dataPoints.Clear(); if (!serie.show || serie.animation.HasFadeOut()) { return; @@ -371,7 +368,6 @@ namespace XCharts.Runtime for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; - serieData.index = j; string dataName = serieData.name; if (!serieData.show) @@ -430,6 +426,7 @@ namespace XCharts.Runtime lastColor = lineColor; } serie.context.dataPoints.Add(startPoint); + serie.context.dataIndexs.Add(serieData.index); serieData.context.position = startPoint; serieData.context.labelPosition = startPoint; diff --git a/Runtime/Serie/Ring/RingHandler.cs b/Runtime/Serie/Ring/RingHandler.cs index 643b6711..c4a87e25 100644 --- a/Runtime/Serie/Ring/RingHandler.cs +++ b/Runtime/Serie/Ring/RingHandler.cs @@ -152,7 +152,6 @@ namespace XCharts.Runtime for (int j = 0; j < data.Count; j++) { var serieData = data[j]; - serieData.index = j; if (!serieData.show) continue; if (serieData.IsDataChanged()) dataChanging = true; var value = serieData.GetFirstData(dataChangeDuration); @@ -303,7 +302,6 @@ namespace XCharts.Runtime for (int i = 0; i < serie.data.Count; i++) { var serieData = serie.data[i]; - serieData.index = i; if (dist >= serieData.context.insideRadius && dist <= serieData.context.outsideRadius && angle >= serieData.context.startAngle && diff --git a/Runtime/Serie/Scatter/BaseScatterHandler.cs b/Runtime/Serie/Scatter/BaseScatterHandler.cs index fa703995..0d9be98f 100644 --- a/Runtime/Serie/Scatter/BaseScatterHandler.cs +++ b/Runtime/Serie/Scatter/BaseScatterHandler.cs @@ -172,6 +172,7 @@ namespace XCharts.Runtime continue; serie.context.dataPoints.Add(pos); + serie.context.dataIndexs.Add(serieData.index); serieData.context.position = pos; var datas = serieData.data; var symbolSize = 0f; @@ -276,6 +277,7 @@ namespace XCharts.Runtime pos = new Vector3(axis.context.x + xDataHig, axis.context.y + yDataHig); } serie.context.dataPoints.Add(pos); + serie.context.dataIndexs.Add(serieData.index); serieData.context.position = pos; var datas = serieData.data; diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs index f996821d..4408e499 100644 --- a/Runtime/Serie/SerieContext.cs +++ b/Runtime/Serie/SerieContext.cs @@ -96,6 +96,10 @@ namespace XCharts.Runtime /// public List dataIgnores = new List(); /// + /// 数据对应的index索引。dataIndexs 和 dataPoints 一一对应。 + /// + public List dataIndexs = new List(); + /// /// 排序后的数据 /// public List sortedData = new List(); diff --git a/Runtime/Serie/SerieData.cs b/Runtime/Serie/SerieData.cs index 950f7473..bd43a936 100644 --- a/Runtime/Serie/SerieData.cs +++ b/Runtime/Serie/SerieData.cs @@ -549,6 +549,10 @@ namespace XCharts.Runtime public void SetLabelActive(bool flag) { if (labelObject != null) labelObject.SetActive(flag); + foreach (var labelObject in context.dataLabels) + { + labelObject.SetActive(false); + } } public void SetIconActive(bool flag) { diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index c8cc95ce..ef77c1c1 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -368,10 +368,18 @@ namespace XCharts.Runtime return; var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); + var needCheck = serie.context.dataIndexs.Count > 0; foreach (var serieData in serie.data) { if (serieData.labelObject == null && serieData.context.dataLabels.Count <= 0) + { continue; + } + if (needCheck && !serie.context.dataIndexs.Contains(serieData.index)) + { + serieData.SetLabelActive(false); + continue; + }; var currLabel = SerieHelper.GetSerieLabel(serie, serieData); var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension); if (serie.show && @@ -429,10 +437,6 @@ namespace XCharts.Runtime else { serieData.SetLabelActive(false); - foreach (var labelObject in serieData.context.dataLabels) - { - labelObject.SetActive(false); - } } } } From 99dc2af42a19794565ec667b99197b846968f761 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 15 Aug 2022 07:30:56 +0800 Subject: [PATCH 25/27] [optimize] optimize smooth curve --- CHANGELOG.md | 1 + Runtime/XUGL/UGL.cs | 2 +- Runtime/XUGL/UGLHelper.cs | 15 ++++++--------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30e9f5ab..25fc11a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ ### 日志详情 +* (2022.08.15) 优化`Smooth`贝塞尔曲线算法 * (2022.08.13) 修复`DataZoom`组件开启时图表显示效果可能不正确的问题 * (2022.08.11) 优化`Tooltip`支持`ignoreDataDefaultContent` * (2022.08.10) 修复`Chart`在3D相机下部分组件显示异常的问题 diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index a5520086..d673ef19 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -1823,7 +1823,7 @@ namespace XUGL if (dire == Direction.YAxis) UGLHelper.GetBezierListVertical(ref s_CurvesPosList, sp, ep, smoothness2, smoothStyle); else - UGLHelper.GetBezierList(ref s_CurvesPosList, sp, ep, lsp, nep, smoothness2, smoothStyle); + UGLHelper.GetBezierList(ref s_CurvesPosList, sp, ep, lsp, nep, smoothness2, smoothStyle, false, dire == Direction.Random); DrawCurvesInternal(vh, s_CurvesPosList, width, color, dire, currProgress); } diff --git a/Runtime/XUGL/UGLHelper.cs b/Runtime/XUGL/UGLHelper.cs index 4076b525..a16c831e 100644 --- a/Runtime/XUGL/UGLHelper.cs +++ b/Runtime/XUGL/UGLHelper.cs @@ -108,23 +108,21 @@ namespace XUGL } public static void GetBezierList(ref List posList, Vector3 sp, Vector3 ep, - Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f, bool limit = false) + Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f, bool limit = false, bool randomDire = false) { - var dist = Vector3.Distance(sp, ep); Vector3 cp1, cp2; + var dist = Vector3.Distance(sp, ep); var dir = (ep - sp).normalized; - var diff = dist / k; + var diff = (randomDire ? dist : Mathf.Abs(sp.x - ep.x)) / k; if (lsp == sp) { cp1 = sp + (nep - ep).normalized * diff; - if (limit) - cp1.y = sp.y; + if (limit) cp1.y = sp.y; } else { cp1 = sp + (ep - lsp).normalized * diff; - if (limit) - cp1.y = sp.y; + if (limit) cp1.y = sp.y; } if (nep == ep) { @@ -133,8 +131,7 @@ namespace XUGL else { cp2 = ep - (nep - sp).normalized * diff; - if (limit) - cp2.y = ep.y; + if (limit) cp2.y = ep.y; } int segment = (int) (dist / (smoothness <= 0 ? 2f : smoothness)); if (segment < 1) segment = (int) (dist / 0.5f); From 990c6dad9072e228a4a28d07ccfb292a76600670 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 15 Aug 2022 08:21:28 +0800 Subject: [PATCH 26/27] [API][chart] RemoveAllSerie() --- Documentation/XChartsAPI-EN.md | 5 +++-- Documentation/XChartsAPI-ZH.md | 5 +++-- Runtime/Internal/BaseChart.API.cs | 25 +++++++++++++++++++------ Runtime/Serie/SerieHandler.cs | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md index 81f8c569..f09576c8 100644 --- a/Documentation/XChartsAPI-EN.md +++ b/Documentation/XChartsAPI-EN.md @@ -176,7 +176,7 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `CanMultipleComponent()` |public bool CanMultipleComponent(Type type)
| | `ClampInChart()` |public void ClampInChart(ref Vector3 pos)
| | `ClampInGrid()` |public Vector3 ClampInGrid(GridCoord grid, Vector3 pos)
| -| `ClearData()` |public virtual void ClearData()
Remove all series and legend data. | +| `ClearData()` |public virtual void ClearData()
Clear all components and series data. Note: serie only empties the data and does not remove serie. | | `ClickLegendButton()` |public void ClickLegendButton(int legendIndex, string legendName, bool show)
点击图例按钮 | | `CovertSerie()` |public bool CovertSerie(Serie serie, Type type)
| | `CovertXYAxis()` |public void CovertXYAxis(int index)
转换X轴和Y轴的配置 | @@ -244,12 +244,13 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `RefreshTopPainter()` |public void RefreshTopPainter()
| | `RefreshUpperPainter()` |public void RefreshUpperPainter()
| | `RemoveAllChartComponent()` |public void RemoveAllChartComponent()
| +| `RemoveAllSerie()` |public virtual void RemoveAllSerie()
Remove all of them Serie. This interface is used when Serie needs to be removed only, and RemoveData() is generally used in other cases. | | `RemoveChartComponent()` |public bool RemoveChartComponent(MainComponent component)
| | `RemoveChartComponent()` |public bool RemoveChartComponent(Type type, int index = 0)
| | `RemoveChartComponent()` |public bool RemoveChartComponent(int index = 0)
| | `RemoveChartComponents()` |public int RemoveChartComponents(Type type)
| | `RemoveChartComponents()` |public int RemoveChartComponents()
| -| `RemoveData()` |public virtual void RemoveData()
Remove all data from series and legend. | +| `RemoveData()` |public virtual void RemoveData()
Empty all component data and remove all series. Use the chart again and again to tell the truth. Note: The component only clears the data part, and the parameters are retained and not reset. | | `RemoveData()` |public virtual void RemoveData(string serieName)
Remove legend and serie by name. | | `RemoveSerie()` |public void RemoveSerie(int serieIndex)
| | `RemoveSerie()` |public void RemoveSerie(Serie serie)
| diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md index 02984b29..e2994473 100644 --- a/Documentation/XChartsAPI-ZH.md +++ b/Documentation/XChartsAPI-ZH.md @@ -176,7 +176,7 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `CanMultipleComponent()` |public bool CanMultipleComponent(Type type)
| | `ClampInChart()` |public void ClampInChart(ref Vector3 pos)
| | `ClampInGrid()` |public Vector3 ClampInGrid(GridCoord grid, Vector3 pos)
| -| `ClearData()` |public virtual void ClearData()
It just emptying all of serie's data without emptying the list of series. | +| `ClearData()` |public virtual void ClearData()
清空所有组件和Serie的数据。注意:Serie只是清空数据,不会移除Serie。 | | `ClickLegendButton()` |public void ClickLegendButton(int legendIndex, string legendName, bool show)
点击图例按钮 | | `CovertSerie()` |public bool CovertSerie(Serie serie, Type type)
| | `CovertXYAxis()` |public void CovertXYAxis(int index)
转换X轴和Y轴的配置 | @@ -244,12 +244,13 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver | `RefreshTopPainter()` |public void RefreshTopPainter()
| | `RefreshUpperPainter()` |public void RefreshUpperPainter()
| | `RemoveAllChartComponent()` |public void RemoveAllChartComponent()
| +| `RemoveAllSerie()` |public virtual void RemoveAllSerie()
移除所有的Serie。当确认只需要移除Serie时使用该接口,其他情况下一般用RemoveData()。 | | `RemoveChartComponent()` |public bool RemoveChartComponent(MainComponent component)
| | `RemoveChartComponent()` |public bool RemoveChartComponent(Type type, int index = 0)
| | `RemoveChartComponent()` |public bool RemoveChartComponent(int index = 0)
| | `RemoveChartComponents()` |public int RemoveChartComponents(Type type)
| | `RemoveChartComponents()` |public int RemoveChartComponents()
| -| `RemoveData()` |public virtual void RemoveData()
The series list is also cleared. | +| `RemoveData()` |public virtual void RemoveData()
清空所有组件数据,并移除所有Serie。一般在图表重新初始化时使用。 注意:组件只清空数据部分,参数会保留不会被重置。 | | `RemoveData()` |public virtual void RemoveData(string serieName)
清除指定系列名称的数据。 | | `RemoveSerie()` |public void RemoveSerie(int serieIndex)
| | `RemoveSerie()` |public void RemoveSerie(Serie serie)
| diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 7c1c2a2b..c0034efb 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -172,9 +172,8 @@ namespace XCharts.Runtime } /// - /// Remove all series and legend data. - /// |It just emptying all of serie's data without emptying the list of series. - /// |清除所有数据,系列中只是移除数据,列表会保留。 + /// Clear all components and series data. Note: serie only empties the data and does not remove serie. + /// |清空所有组件和Serie的数据。注意:Serie只是清空数据,不会移除Serie。 /// public virtual void ClearData() { @@ -187,9 +186,10 @@ namespace XCharts.Runtime } /// - /// Remove all data from series and legend. - /// |The series list is also cleared. - /// |清除所有系列和图例数据,系列的列表也会被清除。 + /// Empty all component data and remove all series. Use the chart again and again to tell the truth. + /// Note: The component only clears the data part, and the parameters are retained and not reset. + /// |清空所有组件数据,并移除所有Serie。一般在图表重新初始化时使用。 + /// 注意:组件只清空数据部分,参数会保留不会被重置。 /// public virtual void RemoveData() { @@ -201,6 +201,19 @@ namespace XCharts.Runtime RefreshChart(); } + /// + /// Remove all of them Serie. This interface is used when Serie needs to be removed only, and RemoveData() is generally used in other cases. + /// |移除所有的Serie。当确认只需要移除Serie时使用该接口,其他情况下一般用RemoveData()。 + /// + [Since("v3.2.0")] + public virtual void RemoveAllSerie() + { + m_Series.Clear(); + m_SerieHandlers.Clear(); + m_CheckAnimation = false; + RefreshChart(); + } + /// /// Remove legend and serie by name. /// |清除指定系列名称的数据。 diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index ef77c1c1..520fe7c6 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -212,12 +212,12 @@ namespace XCharts.Runtime chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); m_SerieLabelRoot.hideFlags = chart.chartHideFlags; SerieLabelPool.ReleaseAll(m_SerieLabelRoot.transform); - //ChartHelper.DestroyAllChildren(m_SerieLabelRoot.transform); int count = 0; SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; + serieData.index = j; serieData.labelObject = null; if (AddSerieLabel(m_SerieLabelRoot, serieData, ref count)) { From 9e07fa1db3061447026286b4248702c5ba8b8f31 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 16 Aug 2022 07:43:22 +0800 Subject: [PATCH 27/27] v3.2.0 --- CHANGELOG.md | 8 +++++-- Documentation/CHANGELOG.md | 45 +++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25fc11a5..3f0bc2cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # 更新日志 [master](#master) +[v3.2.0](#v3.2.0) [v3.1.0](#v3.1.0) [v3.0.1](#v3.0.1) [v3.0.0](#v3.0.0) @@ -57,6 +58,8 @@ ## master +## v3.2.0 + ### 版本要点 * `Serie`支持高亮,淡出和选中三状态配置:`EmphasisStyle`,`BlurStyle`和`SelectStyle` @@ -65,10 +68,11 @@ * `Radar`支持平滑曲线:`smooth` * `Line`支持当作凸多边形填充:`AreaStyle`的`innerFill` * `DataZoom`支持时间轴 -* 其他优化和问题修复 +* 其他优化和修复 ### 日志详情 +* (2022.08.16) 发布`v3.2.0`版本 * (2022.08.15) 优化`Smooth`贝塞尔曲线算法 * (2022.08.13) 修复`DataZoom`组件开启时图表显示效果可能不正确的问题 * (2022.08.11) 优化`Tooltip`支持`ignoreDataDefaultContent` @@ -96,7 +100,7 @@ * (2022.07.17) 增加`Radar`的`smooth`参数设置平滑曲线 * (2022.07.15) 增加`DataZoom`对`Time`时间轴的支持 -## 3.1.0 +## v3.1.0 ### 版本要点 diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index cbf39439..8e94df40 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -2,6 +2,7 @@ # 更新日志 [master](#master) +[v3.2.0](#v3.2.0) [v3.1.0](#v3.1.0) [v3.0.1](#v3.0.1) [v3.0.0](#v3.0.0) @@ -57,7 +58,49 @@ ## master -## 3.1.0 +## v3.2.0 + +### Main points + +* `Serie` supports highlighting, EmphasisStyle, EmphasisStyle, BlurStyle, and SelectStyle +* `Axis` supports sub-scale and sub-partition of coordinate axes:`MinorTick` and `MinorSplitLine` +* `Serie` supports different color selection strategies: `colorBy` +* `Radar` supports smooth curves: `smooth` +* `Line` supports filling as a convex polygon: `AreaStyle` `innerFill` +* `DataZoom` supports timeline +* Other optimizations and issue fixes + +### Log details + +* (2022.08.16) Release `v3.2.0` version +* (2022.08.15) optimized `Smooth` Bezier curve algorithm +* (2022.08.13) Fixed an issue where the `DataZoom` component might not display correctly when opened +* (2022.08.11) Optimized Tooltip supports `ignoreDataDefaultContent` +* (2022.08.10) fixed abnormal display of some components of `Chart` under 3D camera +* (2022.08.10) Fix `RemoveSerie()` interface not working (#219) +* (2022.08.10) Optimized font synchronization for Theme +* (2022.08.10) optimizes the default `layer` of Chart to `UI` +* (2022.08.09) optimizes the `Time` timeline of `Axis` +* (2022.08.09) added AreaStyle `innerFill` parameter to support filling convex polygons +* (2022.08.08) Optimized the maintenance of data item indexes in `Serie`, added detection and repair functions, and fixed related problems +* (2022.07.29) Fixed `Unity` version compatibility: Chart creation exception after some versions import +* (2022.07.29) Add `Axis` to` Time `timeline, support sub-scale and sub-divider +* (2022.07.28) optimizes the `Radar` image +* (2022.07.28) increase `Serie` `colorBy` parameter configuration color taking strategy +* (2022.07.27) Adds StateStyle `Symbol` to configure the Symbol style in the state +* (2022.07.27) remove selectedSize from SerieSymbol +* (2022.07.24) adds default state Settings for `Serie` and `SerieData` +* (2022.07.22) add three states` EmphasisStyle `, `EmphasisStyle`, `SelectStyle` of `Serie` +* (2022.07.22) remove `highlightColor` and `highlightToColor` arguments from `AreaStyle` +* (2022.07.22) Omit the `Emphasis`,` EmphasisItemStyle `, `EmphasisLabelStyle`, `EmphasisLabelLine` component +* (2022.07.20) Added `Since` feature support for classes +* (2022.07.20) fixed the `showStartLabel` and `showEndLabel` parameter Settings for `AxisLabel` not taking effect when `Axis` is on the` Value `Axis +* (2022.07.19) added `Axis` to` MinorSplitLine `to set the Axis degree divider +* (2022.07.19) added `Axis` `MinorTick` to set the Axis sub-scale +* (2022.07.17) Add the `smooth` parameter for Radar to set the smooth curve +* (2022.07.15) added DataZoom support for the `Time` timeline + +## v3.1.0 * (2022.07.12) Release `v3.1.0` version * (2022.07.12) Fixed `Serie` `ignoreLineBreak` not working