diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index dba05456ba..b1d4a10be5 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -1267,15 +1267,31 @@ void ChartWidget::processLocalZoom(int xIndex) { zoomOutButton->moveToLeft(0, 0); - const auto finish = [=](const Limits &zoomLimit) { + const auto finish = [=](const Limits &zoomLimitIndices) { _footer->xPercentageLimitsChange( ) | rpl::start_with_next([=](const Limits &l) { - const auto result = FindNearestElements( + const auto zoomLimit = Limits{ + _chartData.xPercentage[zoomLimitIndices.min], + _chartData.xPercentage[zoomLimitIndices.max], + }; + const auto offset = (zoomLimit.max == 1.) ? 0 : -1; + const auto minIt = ranges::upper_bound( _chartData.xPercentage, - Limits{ - anim::interpolateF(zoomLimit.min, zoomLimit.max, l.min), - anim::interpolateF(zoomLimit.min, zoomLimit.max, l.max), - }); + anim::interpolateF(zoomLimit.min, zoomLimit.max, l.min)); + const auto maxIt = ranges::upper_bound( + _chartData.xPercentage, + anim::interpolateF(zoomLimit.min, zoomLimit.max, l.max)); + const auto start = begin(_chartData.xPercentage); + const auto result = Limits{ + .min = std::clamp( + float64(std::distance(start, minIt) + offset), + zoomLimitIndices.min, + zoomLimitIndices.max), + .max = std::clamp( + float64(std::distance(start, maxIt) + offset), + zoomLimitIndices.min, + zoomLimitIndices.max), + }; header->setRightInfo(HeaderRightInfo(_chartData, result)); header->update(); }, header->lifetime()); @@ -1301,7 +1317,7 @@ void ChartWidget::processLocalZoom(int xIndex) { if (lifetime) { lifetime->destroy(); } - finish(zoom.limit); + finish(zoom.limitIndices); } }, 0., 1., kFooterZoomDuration, anim::easeOutCirc); } diff --git a/Telegram/SourceFiles/statistics/view/abstract_chart_view.h b/Telegram/SourceFiles/statistics/view/abstract_chart_view.h index f892ff822f..b54c9d4d7e 100644 --- a/Telegram/SourceFiles/statistics/view/abstract_chart_view.h +++ b/Telegram/SourceFiles/statistics/view/abstract_chart_view.h @@ -62,7 +62,7 @@ public: struct LocalZoomResult final { bool hasZoom = false; - Limits limit; + Limits limitIndices; Limits range; }; diff --git a/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp b/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp index d81a52e589..54d8c5372a 100644 --- a/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp +++ b/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp @@ -972,7 +972,7 @@ auto StackLinearChartView::maybeLocalZoom( _transition.zoomedInLimit.max, _transition.zoomedInRange.max), }; - return { true, _transition.zoomedInLimit, resultRange }; + return { true, _transition.zoomedInLimitXIndices, resultRange }; } void StackLinearChartView::tick(crl::time now) {