diff --git a/Telegram/SourceFiles/statistics/view/stack_chart_common.cpp b/Telegram/SourceFiles/statistics/view/stack_chart_common.cpp index f1a8b00729..82a1143fe0 100644 --- a/Telegram/SourceFiles/statistics/view/stack_chart_common.cpp +++ b/Telegram/SourceFiles/statistics/view/stack_chart_common.cpp @@ -44,28 +44,43 @@ Limits FindStackXIndicesFromRawXPercentages( // This reduces the number of displayed points by 1, // but allows the last point to be displayed. const auto offset = (zoomLimit.max == 1.) ? 0 : -1; - const auto minIt = ranges::upper_bound( - chartData.xPercentage, + const auto rightShrink = (rawXPercentageLimits.max == 1.) + ? ((zoomLimit.max == 1.) ? 0 : 1) + : 0; + const auto n = chartData.xPercentage.size(); + auto minIt = -1; + auto maxIt = n; + const auto zoomedIn = Limits{ anim::interpolateF( zoomLimit.min, zoomLimit.max, - rawXPercentageLimits.min)); - const auto maxIt = ranges::upper_bound( - chartData.xPercentage, + rawXPercentageLimits.min), anim::interpolateF( zoomLimit.min, zoomLimit.max, - rawXPercentageLimits.max)); - const auto start = begin(chartData.xPercentage); + rawXPercentageLimits.max), + }; + for (auto i = int(0); i < n; i++) { + if (minIt < 0) { + if (chartData.xPercentage[i] > zoomedIn.min) { + minIt = i; + } + } + if (maxIt >= n) { + if (chartData.xPercentage[i] > zoomedIn.max) { + maxIt = i; + } + } + } return { .min = std::clamp( - float64(std::distance(start, minIt) + offset), + float64(minIt + offset), zoomedInLimitXIndices.min, - zoomedInLimitXIndices.max), + zoomedInLimitXIndices.max - rightShrink), .max = std::clamp( - float64(std::distance(start, maxIt) + offset), + float64(maxIt + offset), zoomedInLimitXIndices.min, - zoomedInLimitXIndices.max), + zoomedInLimitXIndices.max - rightShrink), }; } diff --git a/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp b/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp index 86a56e3831..cfed870270 100644 --- a/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp +++ b/Telegram/SourceFiles/statistics/view/stack_linear_chart_view.cpp @@ -938,7 +938,7 @@ auto StackLinearChartView::maybeLocalZoom( // 1 day in middle of limits. constexpr auto kRangeLength = int(0); constexpr auto kLeftSide = int(kLimitLength / 2 + kRangeLength); - constexpr auto kRightSide = int(kLimitLength / 2); + constexpr auto kRightSide = int(kLimitLength / 2) + int(1); _transition.progress = args.progress; if (args.type == LocalZoomArgs::Type::SkipCalculation) { @@ -963,7 +963,7 @@ auto StackLinearChartView::maybeLocalZoom( float64(localRangeIndex + kRangeLength), }; _transition.zoomedInLimitXIndices = (xIndex < kLeftSide) - ? Limits{ 0, kLimitLength + kRangeLength } + ? Limits{ 0, kLeftSide + kRightSide } : (xIndex > (backIndex - kRightSide - kRangeLength)) ? Limits{ float64(backIndex - kLimitLength), float64(backIndex) } : Limits{ float64(xIndex - kLeftSide), float64(xIndex + kRightSide) };