From aee49322b7ed4ea58897496449023fc268e2c181 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 15 Jul 2022 08:37:14 +0800 Subject: [PATCH] [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) {