mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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) };
|
_currentXIndices = { float64(startXIndex), float64(endXIndex) };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto minValue = std::numeric_limits<int>::max();
|
const auto heightLimits = chartView->heightLimits(
|
||||||
auto maxValue = 0;
|
chartData,
|
||||||
|
_currentXIndices);
|
||||||
auto minValueFull = std::numeric_limits<int>::max();
|
if (heightLimits.ranged.min == heightLimits.ranged.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) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_previousFullHeightLimits = _finalHeightLimits;
|
_previousFullHeightLimits = _finalHeightLimits;
|
||||||
_finalHeightLimits = { float64(minValue), float64(maxValue) };
|
_finalHeightLimits = heightLimits.ranged;
|
||||||
if (!_previousFullHeightLimits.max) {
|
if (!_previousFullHeightLimits.max) {
|
||||||
_previousFullHeightLimits = _finalHeightLimits;
|
_previousFullHeightLimits = _finalHeightLimits;
|
||||||
}
|
}
|
||||||
if (!chartView->isFinished()) {
|
if (!chartView->isFinished()) {
|
||||||
_animationValueFooterHeightMin = anim::value(
|
_animationValueFooterHeightMin = anim::value(
|
||||||
_animationValueFooterHeightMin.current(),
|
_animationValueFooterHeightMin.current(),
|
||||||
minValueFull);
|
heightLimits.full.min);
|
||||||
_animationValueFooterHeightMax = anim::value(
|
_animationValueFooterHeightMax = anim::value(
|
||||||
_animationValueFooterHeightMax.current(),
|
_animationValueFooterHeightMax.current(),
|
||||||
maxValueFull);
|
heightLimits.full.max);
|
||||||
} else if (!_animationValueFooterHeightMax.to()) {
|
} else if (!_animationValueFooterHeightMax.to()) {
|
||||||
// Will be finished in setChartData.
|
// Will be finished in setChartData.
|
||||||
_animationValueFooterHeightMin = anim::value(0, minValueFull);
|
_animationValueFooterHeightMin = anim::value(
|
||||||
_animationValueFooterHeightMax = anim::value(0, maxValueFull);
|
0,
|
||||||
|
heightLimits.full.min);
|
||||||
|
_animationValueFooterHeightMax = anim::value(
|
||||||
|
0,
|
||||||
|
heightLimits.full.max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,15 @@ public:
|
||||||
[[nodiscard]] virtual bool isFinished() const = 0;
|
[[nodiscard]] virtual bool isFinished() const = 0;
|
||||||
[[nodiscard]] virtual float64 alpha(int id) 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;
|
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;
|
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) {
|
void LinearChartView::tick(crl::time now) {
|
||||||
auto finishedCount = 0;
|
auto finishedCount = 0;
|
||||||
auto idsToRemove = std::vector<int>();
|
auto idsToRemove = std::vector<int>();
|
||||||
|
|
|
@ -45,6 +45,10 @@ public:
|
||||||
[[nodiscard]] bool isFinished() const override;
|
[[nodiscard]] bool isFinished() const override;
|
||||||
[[nodiscard]] float64 alpha(int id) const override;
|
[[nodiscard]] float64 alpha(int id) const override;
|
||||||
|
|
||||||
|
[[nodiscard]] HeightLimits heightLimits(
|
||||||
|
Data::StatisticalChart &chartData,
|
||||||
|
Limits xIndices) override;
|
||||||
|
|
||||||
void tick(crl::time now) override;
|
void tick(crl::time now) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue