mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-22 00:57:09 +02:00
Moved out calculation of height limits to abstract chart view class.
This commit is contained in:
parent
d50aca0d33
commit
11b932707c
4 changed files with 52 additions and 23 deletions
|
@ -550,42 +550,32 @@ void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
|||
_currentXIndices = { float64(startXIndex), float64(endXIndex) };
|
||||
|
||||
{
|
||||
auto minValue = std::numeric_limits<int>::max();
|
||||
auto maxValue = 0;
|
||||
|
||||
auto minValueFull = std::numeric_limits<int>::max();
|
||||
auto maxValueFull = 0;
|
||||
for (auto &l : chartData.lines) {
|
||||
if (!chartView->isEnabled(l.id)) {
|
||||
continue;
|
||||
}
|
||||
const auto lineMax = l.segmentTree.rMaxQ(startXIndex, endXIndex);
|
||||
const auto lineMin = l.segmentTree.rMinQ(startXIndex, endXIndex);
|
||||
maxValue = std::max(lineMax, maxValue);
|
||||
minValue = std::min(lineMin, minValue);
|
||||
|
||||
maxValueFull = std::max(l.maxValue, maxValueFull);
|
||||
minValueFull = std::min(l.minValue, minValueFull);
|
||||
}
|
||||
if (maxValue == minValue) {
|
||||
const auto heightLimits = chartView->heightLimits(
|
||||
chartData,
|
||||
_currentXIndices);
|
||||
if (heightLimits.ranged.min == heightLimits.ranged.max) {
|
||||
return;
|
||||
}
|
||||
_previousFullHeightLimits = _finalHeightLimits;
|
||||
_finalHeightLimits = { float64(minValue), float64(maxValue) };
|
||||
_finalHeightLimits = heightLimits.ranged;
|
||||
if (!_previousFullHeightLimits.max) {
|
||||
_previousFullHeightLimits = _finalHeightLimits;
|
||||
}
|
||||
if (!chartView->isFinished()) {
|
||||
_animationValueFooterHeightMin = anim::value(
|
||||
_animationValueFooterHeightMin.current(),
|
||||
minValueFull);
|
||||
heightLimits.full.min);
|
||||
_animationValueFooterHeightMax = anim::value(
|
||||
_animationValueFooterHeightMax.current(),
|
||||
maxValueFull);
|
||||
heightLimits.full.max);
|
||||
} else if (!_animationValueFooterHeightMax.to()) {
|
||||
// Will be finished in setChartData.
|
||||
_animationValueFooterHeightMin = anim::value(0, minValueFull);
|
||||
_animationValueFooterHeightMax = anim::value(0, maxValueFull);
|
||||
_animationValueFooterHeightMin = anim::value(
|
||||
0,
|
||||
heightLimits.full.min);
|
||||
_animationValueFooterHeightMax = anim::value(
|
||||
0,
|
||||
heightLimits.full.max);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,15 @@ public:
|
|||
[[nodiscard]] virtual bool isFinished() const = 0;
|
||||
[[nodiscard]] virtual float64 alpha(int id) const = 0;
|
||||
|
||||
struct HeightLimits final {
|
||||
Limits full;
|
||||
Limits ranged;
|
||||
};
|
||||
|
||||
[[nodiscard]] virtual HeightLimits heightLimits(
|
||||
Data::StatisticalChart &chartData,
|
||||
Limits xIndices) = 0;
|
||||
|
||||
virtual void tick(crl::time now) = 0;
|
||||
|
||||
};
|
||||
|
|
|
@ -197,6 +197,32 @@ float64 LinearChartView::alpha(int id) const {
|
|||
return (it == end(_entries)) ? 1. : it->second.alpha;
|
||||
}
|
||||
|
||||
AbstractChartView::HeightLimits LinearChartView::heightLimits(
|
||||
Data::StatisticalChart &chartData,
|
||||
Limits xIndices) {
|
||||
auto minValue = std::numeric_limits<int>::max();
|
||||
auto maxValue = 0;
|
||||
|
||||
auto minValueFull = std::numeric_limits<int>::max();
|
||||
auto maxValueFull = 0;
|
||||
for (auto &l : chartData.lines) {
|
||||
if (!isEnabled(l.id)) {
|
||||
continue;
|
||||
}
|
||||
const auto lineMax = l.segmentTree.rMaxQ(xIndices.min, xIndices.max);
|
||||
const auto lineMin = l.segmentTree.rMinQ(xIndices.min, xIndices.max);
|
||||
maxValue = std::max(lineMax, maxValue);
|
||||
minValue = std::min(lineMin, minValue);
|
||||
|
||||
maxValueFull = std::max(l.maxValue, maxValueFull);
|
||||
minValueFull = std::min(l.minValue, minValueFull);
|
||||
}
|
||||
return {
|
||||
.full = Limits{ float64(minValueFull), float64(maxValueFull) },
|
||||
.ranged = Limits{ float64(minValue), float64(maxValue) },
|
||||
};
|
||||
}
|
||||
|
||||
void LinearChartView::tick(crl::time now) {
|
||||
auto finishedCount = 0;
|
||||
auto idsToRemove = std::vector<int>();
|
||||
|
|
|
@ -45,6 +45,10 @@ public:
|
|||
[[nodiscard]] bool isFinished() const override;
|
||||
[[nodiscard]] float64 alpha(int id) const override;
|
||||
|
||||
[[nodiscard]] HeightLimits heightLimits(
|
||||
Data::StatisticalChart &chartData,
|
||||
Limits xIndices) override;
|
||||
|
||||
void tick(crl::time now) override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue