Improved limits of zoomed in slider in footer for stack linear chart.

This commit is contained in:
23rd 2023-10-02 16:09:22 +03:00 committed by John Preston
parent cb4c629178
commit f8e80bc266
2 changed files with 28 additions and 13 deletions

View file

@ -44,28 +44,43 @@ Limits FindStackXIndicesFromRawXPercentages(
// This reduces the number of displayed points by 1, // This reduces the number of displayed points by 1,
// but allows the last point to be displayed. // but allows the last point to be displayed.
const auto offset = (zoomLimit.max == 1.) ? 0 : -1; const auto offset = (zoomLimit.max == 1.) ? 0 : -1;
const auto minIt = ranges::upper_bound( const auto rightShrink = (rawXPercentageLimits.max == 1.)
chartData.xPercentage, ? ((zoomLimit.max == 1.) ? 0 : 1)
: 0;
const auto n = chartData.xPercentage.size();
auto minIt = -1;
auto maxIt = n;
const auto zoomedIn = Limits{
anim::interpolateF( anim::interpolateF(
zoomLimit.min, zoomLimit.min,
zoomLimit.max, zoomLimit.max,
rawXPercentageLimits.min)); rawXPercentageLimits.min),
const auto maxIt = ranges::upper_bound(
chartData.xPercentage,
anim::interpolateF( anim::interpolateF(
zoomLimit.min, zoomLimit.min,
zoomLimit.max, zoomLimit.max,
rawXPercentageLimits.max)); rawXPercentageLimits.max),
const auto start = begin(chartData.xPercentage); };
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 { return {
.min = std::clamp( .min = std::clamp(
float64(std::distance(start, minIt) + offset), float64(minIt + offset),
zoomedInLimitXIndices.min, zoomedInLimitXIndices.min,
zoomedInLimitXIndices.max), zoomedInLimitXIndices.max - rightShrink),
.max = std::clamp( .max = std::clamp(
float64(std::distance(start, maxIt) + offset), float64(maxIt + offset),
zoomedInLimitXIndices.min, zoomedInLimitXIndices.min,
zoomedInLimitXIndices.max), zoomedInLimitXIndices.max - rightShrink),
}; };
} }

View file

@ -938,7 +938,7 @@ auto StackLinearChartView::maybeLocalZoom(
// 1 day in middle of limits. // 1 day in middle of limits.
constexpr auto kRangeLength = int(0); constexpr auto kRangeLength = int(0);
constexpr auto kLeftSide = int(kLimitLength / 2 + kRangeLength); 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; _transition.progress = args.progress;
if (args.type == LocalZoomArgs::Type::SkipCalculation) { if (args.type == LocalZoomArgs::Type::SkipCalculation) {
@ -963,7 +963,7 @@ auto StackLinearChartView::maybeLocalZoom(
float64(localRangeIndex + kRangeLength), float64(localRangeIndex + kRangeLength),
}; };
_transition.zoomedInLimitXIndices = (xIndex < kLeftSide) _transition.zoomedInLimitXIndices = (xIndex < kLeftSide)
? Limits{ 0, kLimitLength + kRangeLength } ? Limits{ 0, kLeftSide + kRightSide }
: (xIndex > (backIndex - kRightSide - kRangeLength)) : (xIndex > (backIndex - kRightSide - kRangeLength))
? Limits{ float64(backIndex - kLimitLength), float64(backIndex) } ? Limits{ float64(backIndex - kLimitLength), float64(backIndex) }
: Limits{ float64(xIndex - kLeftSide), float64(xIndex + kRightSide) }; : Limits{ float64(xIndex - kLeftSide), float64(xIndex + kRightSide) };