From 5f16685b649692b4457e67ce4732ecd532000453 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 29 Aug 2022 23:02:03 +0800 Subject: [PATCH] [improve][serie] improve min-max data range --- CHANGELOG.md | 2 ++ .../Axis/AngleAxis/AngleAxisHandler.cs | 2 +- .../Axis/RadiusAxis/RadiusAxisHandler.cs | 2 +- Runtime/Component/DataZoom/DataZoomHandler.cs | 4 ++-- Runtime/Internal/BaseChart.Component.cs | 16 +++++++++++++ Runtime/Internal/BaseChart.Custom.cs | 9 ++++---- Runtime/Serie/SeriesHelper.cs | 23 +++++++++++-------- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a53a262..6f794c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,8 @@ ## master +* (2022.08.29) 优化`BarChart`在数据过密时的默认表现 +* (2022.08.29) 优化`DataZoom`下Y轴的最大最小值计算 * (2022.08.29) 优化`CandlestickChart`大量数据绘制 * (2022.08.28) 修复`LineChart`在堆叠和自定义Y轴范围的情况下显示不正常的问题 * (2022.08.26) 增加`Legend`新图标类型`Candlestick` diff --git a/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs b/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs index b57b5a4d..b2c02b48 100644 --- a/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs +++ b/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs @@ -29,7 +29,7 @@ namespace XCharts.Runtime if (axis.IsCategory() || !axis.show) return; double tempMinValue = 0; double tempMaxValue = 0; - SeriesHelper.GetYMinMaxValue(chart.series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, + SeriesHelper.GetYMinMaxValue(chart, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true); AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue) diff --git a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs index 4e295923..4ea89808 100644 --- a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs +++ b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs @@ -50,7 +50,7 @@ namespace XCharts.Runtime if (axis.IsCategory() || !axis.show) return; double tempMinValue = 0; double tempMaxValue = 0; - SeriesHelper.GetXMinMaxValue(chart.series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, + SeriesHelper.GetXMinMaxValue(chart, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true); AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue) diff --git a/Runtime/Component/DataZoom/DataZoomHandler.cs b/Runtime/Component/DataZoom/DataZoomHandler.cs index aa9e7644..be6854ad 100644 --- a/Runtime/Component/DataZoom/DataZoomHandler.cs +++ b/Runtime/Component/DataZoom/DataZoomHandler.cs @@ -464,7 +464,7 @@ namespace XCharts.Runtime Vector3 np = Vector3.zero; double minValue = 0; double maxValue = 0; - SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue); + SeriesHelper.GetYMinMaxValue(chart, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue, false, false); AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true); int rate = 1; @@ -553,7 +553,7 @@ namespace XCharts.Runtime Vector3 np = Vector3.zero; double minValue = 0; double maxValue = 0; - SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue); + SeriesHelper.GetYMinMaxValue(chart, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue); AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true); int rate = 1; diff --git a/Runtime/Internal/BaseChart.Component.cs b/Runtime/Internal/BaseChart.Component.cs index 8e19c4d5..fdf14c28 100644 --- a/Runtime/Internal/BaseChart.Component.cs +++ b/Runtime/Internal/BaseChart.Component.cs @@ -349,6 +349,22 @@ namespace XCharts.Runtime } } + public DataZoom GetXDataZoomOfSerie(Serie serie) + { + if (serie == null) return null; + foreach (var component in m_Components) + { + if (component is DataZoom) + { + var dataZoom = component as DataZoom; + if (!dataZoom.enable) continue; + if (dataZoom.IsContainsXAxis(serie.xAxisIndex)) + return dataZoom; + } + } + return null; + } + /// /// reutrn true when all the show axis is `Value` type. /// |纯数值坐标轴(数值轴或对数轴)。 diff --git a/Runtime/Internal/BaseChart.Custom.cs b/Runtime/Internal/BaseChart.Custom.cs index cbd04dad..f9c110fb 100644 --- a/Runtime/Internal/BaseChart.Custom.cs +++ b/Runtime/Internal/BaseChart.Custom.cs @@ -6,8 +6,7 @@ namespace XCharts.Runtime { public partial class BaseChart { - public virtual void InitAxisRuntimeData(Axis axis) - { } + public virtual void InitAxisRuntimeData(Axis axis) { } public virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue) { @@ -15,16 +14,16 @@ namespace XCharts.Runtime { if (axis is XAxis) { - SeriesHelper.GetXMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetXMinMaxValue(this, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); } else { - SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetYMinMaxValue(this, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); } } else { - SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetYMinMaxValue(this, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue); } AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); } diff --git a/Runtime/Serie/SeriesHelper.cs b/Runtime/Serie/SeriesHelper.cs index 3e969355..c2bb721f 100644 --- a/Runtime/Serie/SeriesHelper.cs +++ b/Runtime/Serie/SeriesHelper.cs @@ -300,10 +300,10 @@ namespace XCharts.Runtime /// /// /// - public static void GetXMinMaxValue(List series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, out double minVaule, out double maxValue, bool isPolar = false) + public static void GetXMinMaxValue(BaseChart chart, int axisIndex, bool isValueAxis, + bool inverse, out double minVaule, out double maxValue, bool isPolar = false, bool filterByDataZoom = true) { - GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar); + GetMinMaxValue(chart, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar, filterByDataZoom); } /// @@ -313,19 +313,22 @@ namespace XCharts.Runtime /// /// /// - public static void GetYMinMaxValue(List series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, out double minVaule, out double maxValue, bool isPolar = false) + public static void GetYMinMaxValue(BaseChart chart, int axisIndex, bool isValueAxis, + bool inverse, out double minVaule, out double maxValue, bool isPolar = false, bool filterByDataZoom = true) { - GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar); + GetMinMaxValue(chart, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar, filterByDataZoom); } private static Dictionary> _stackSeriesForMinMax = new Dictionary>(); private static Dictionary _serieTotalValueForMinMax = new Dictionary(); - public static void GetMinMaxValue(List series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, bool yValue, out double minVaule, out double maxValue, bool isPolar = false) + private static DataZoom xDataZoom, yDataZoom; + public static void GetMinMaxValue(BaseChart chart, int axisIndex, bool isValueAxis, + bool inverse, bool yValue, out double minVaule, out double maxValue, bool isPolar = false, + bool filterByDataZoom = true) { double min = double.MaxValue; double max = double.MinValue; + var series = chart.series; var isPercentStack = SeriesHelper.IsPercentStack(series); if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue)) { @@ -343,7 +346,7 @@ namespace XCharts.Runtime } else { - var showData = serie.GetDataList(dataZoom); + var showData = serie.GetDataList(filterByDataZoom?chart.GetXDataZoomOfSerie(serie) : null); if (serie is Candlestick || serie is SimplifiedCandlestick) { foreach (var data in showData) @@ -381,7 +384,7 @@ namespace XCharts.Runtime if ((isPolar && serie.polarIndex != axisIndex) || (!isPolar && serie.yAxisIndex != axisIndex) || !serie.show) continue; - var showData = serie.GetDataList(dataZoom); + var showData = serie.GetDataList(filterByDataZoom?chart.GetXDataZoomOfSerie(serie) : null); if (SeriesHelper.IsPercentStack(series, serie.stack)) { for (int j = 0; j < showData.Count; j++)