mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Removed chart line view context.
This commit is contained in:
@@ -1284,8 +1284,6 @@ PRIVATE
|
|||||||
settings/settings_websites.h
|
settings/settings_websites.h
|
||||||
statistics/chart_horizontal_lines_data.cpp
|
statistics/chart_horizontal_lines_data.cpp
|
||||||
statistics/chart_horizontal_lines_data.h
|
statistics/chart_horizontal_lines_data.h
|
||||||
statistics/chart_line_view_context.cpp
|
|
||||||
statistics/chart_line_view_context.h
|
|
||||||
statistics/chart_widget.cpp
|
statistics/chart_widget.cpp
|
||||||
statistics/chart_widget.h
|
statistics/chart_widget.h
|
||||||
statistics/linear_chart_view.cpp
|
statistics/linear_chart_view.cpp
|
||||||
|
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of Telegram Desktop,
|
|
||||||
the official desktop application for the Telegram messaging service.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
||||||
*/
|
|
||||||
#include "statistics/chart_line_view_context.h"
|
|
||||||
|
|
||||||
namespace Statistic {
|
|
||||||
namespace {
|
|
||||||
constexpr auto kAlphaDuration = float64(350);
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void ChartLineViewContext::setEnabled(int id, bool enabled, crl::time now) {
|
|
||||||
const auto it = _entries.find(id);
|
|
||||||
if (it == end(_entries)) {
|
|
||||||
_entries[id] = Entry{ .enabled = enabled, .startedAt = now };
|
|
||||||
} else if (it->second.enabled != enabled) {
|
|
||||||
auto &entry = it->second;
|
|
||||||
entry.enabled = enabled;
|
|
||||||
entry.startedAt = now
|
|
||||||
- kAlphaDuration * (enabled ? entry.alpha : (1. - entry.alpha));
|
|
||||||
}
|
|
||||||
_isFinished = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChartLineViewContext::isFinished() const {
|
|
||||||
return _isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChartLineViewContext::isEnabled(int id) const {
|
|
||||||
const auto it = _entries.find(id);
|
|
||||||
return (it == end(_entries)) ? true : it->second.enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
float64 ChartLineViewContext::alpha(int id) const {
|
|
||||||
const auto it = _entries.find(id);
|
|
||||||
return (it == end(_entries)) ? 1. : it->second.alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChartLineViewContext::tick(crl::time now) {
|
|
||||||
auto finishedCount = 0;
|
|
||||||
auto idsToRemove = std::vector<int>();
|
|
||||||
for (auto &[id, entry] : _entries) {
|
|
||||||
if (!entry.startedAt) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto progress = (now - entry.startedAt) / kAlphaDuration;
|
|
||||||
entry.alpha = std::clamp(
|
|
||||||
entry.enabled ? progress : (1. - progress),
|
|
||||||
0.,
|
|
||||||
1.);
|
|
||||||
if (entry.alpha == 1.) {
|
|
||||||
idsToRemove.push_back(id);
|
|
||||||
}
|
|
||||||
if (progress >= 1.) {
|
|
||||||
finishedCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_isFinished = (finishedCount == _entries.size());
|
|
||||||
for (const auto &id : idsToRemove) {
|
|
||||||
_entries.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Statistic
|
|
@@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of Telegram Desktop,
|
|
||||||
the official desktop application for the Telegram messaging service.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Statistic {
|
|
||||||
|
|
||||||
class ChartLineViewContext final {
|
|
||||||
public:
|
|
||||||
ChartLineViewContext() = default;
|
|
||||||
|
|
||||||
void setEnabled(int id, bool enabled, crl::time now);
|
|
||||||
[[nodiscard]] bool isEnabled(int id) const;
|
|
||||||
[[nodiscard]] bool isFinished() const;
|
|
||||||
[[nodiscard]] float64 alpha(int id) const;
|
|
||||||
|
|
||||||
void tick(crl::time now);
|
|
||||||
|
|
||||||
float64 factor = 1.;
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Entry final {
|
|
||||||
bool enabled = false;
|
|
||||||
crl::time startedAt = 0;
|
|
||||||
float64 alpha = 1.;
|
|
||||||
};
|
|
||||||
|
|
||||||
base::flat_map<int, Entry> _entries;
|
|
||||||
bool _isFinished = true;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Statistic
|
|
@@ -479,11 +479,11 @@ ChartWidget::ChartAnimationController::ChartAnimationController(
|
|||||||
void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
||||||
Data::StatisticalChart &chartData,
|
Data::StatisticalChart &chartData,
|
||||||
Limits xPercentageLimits,
|
Limits xPercentageLimits,
|
||||||
const ChartLineViewContext &chartLinesViewContext,
|
const std::unique_ptr<LinearChartView> &linearChartView,
|
||||||
crl::time now) {
|
crl::time now) {
|
||||||
if ((_animationValueXMin.to() == xPercentageLimits.min)
|
if ((_animationValueXMin.to() == xPercentageLimits.min)
|
||||||
&& (_animationValueXMax.to() == xPercentageLimits.max)
|
&& (_animationValueXMax.to() == xPercentageLimits.max)
|
||||||
&& chartLinesViewContext.isFinished()) {
|
&& linearChartView->isFinished()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
start();
|
start();
|
||||||
@@ -505,7 +505,7 @@ void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
|||||||
auto minValueFull = std::numeric_limits<int>::max();
|
auto minValueFull = std::numeric_limits<int>::max();
|
||||||
auto maxValueFull = 0;
|
auto maxValueFull = 0;
|
||||||
for (auto &l : chartData.lines) {
|
for (auto &l : chartData.lines) {
|
||||||
if (!chartLinesViewContext.isEnabled(l.id)) {
|
if (!linearChartView->isEnabled(l.id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto lineMax = l.segmentTree.rMaxQ(startXIndex, endXIndex);
|
const auto lineMax = l.segmentTree.rMaxQ(startXIndex, endXIndex);
|
||||||
@@ -521,7 +521,7 @@ void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
|||||||
if (!_previousFullHeightLimits.max) {
|
if (!_previousFullHeightLimits.max) {
|
||||||
_previousFullHeightLimits = _finalHeightLimits;
|
_previousFullHeightLimits = _finalHeightLimits;
|
||||||
}
|
}
|
||||||
if (!chartLinesViewContext.isFinished()) {
|
if (!linearChartView->isFinished()) {
|
||||||
_animationValueFooterHeightMin = anim::value(
|
_animationValueFooterHeightMin = anim::value(
|
||||||
_animationValueFooterHeightMin.current(),
|
_animationValueFooterHeightMin.current(),
|
||||||
minValueFull);
|
minValueFull);
|
||||||
@@ -565,7 +565,7 @@ void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
|||||||
_dtHeight.currentAlpha = 0.;
|
_dtHeight.currentAlpha = 0.;
|
||||||
_addHorizontalLineRequests.fire({});
|
_addHorizontalLineRequests.fire({});
|
||||||
}
|
}
|
||||||
_dtHeight.speed = (!chartLinesViewContext.isFinished())
|
_dtHeight.speed = (!linearChartView->isFinished())
|
||||||
? kDtHeightSpeedFilter
|
? kDtHeightSpeedFilter
|
||||||
: (k > kDtHeightSpeedThreshold1)
|
: (k > kDtHeightSpeedThreshold1)
|
||||||
? kDtHeightSpeed1
|
? kDtHeightSpeed1
|
||||||
@@ -611,7 +611,7 @@ void ChartWidget::ChartAnimationController::tick(
|
|||||||
crl::time now,
|
crl::time now,
|
||||||
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
||||||
std::vector<BottomCaptionLineData> &dateLines,
|
std::vector<BottomCaptionLineData> &dateLines,
|
||||||
ChartLineViewContext &chartLinesViewContext) {
|
const std::unique_ptr<LinearChartView> &linearChartView) {
|
||||||
if (!_animation.animating()) {
|
if (!_animation.animating()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -662,7 +662,7 @@ void ChartWidget::ChartAnimationController::tick(
|
|||||||
const auto footerMinFinished = isFinished(_animationValueFooterHeightMin);
|
const auto footerMinFinished = isFinished(_animationValueFooterHeightMin);
|
||||||
const auto footerMaxFinished = isFinished(_animationValueFooterHeightMax);
|
const auto footerMaxFinished = isFinished(_animationValueFooterHeightMax);
|
||||||
|
|
||||||
chartLinesViewContext.tick(now);
|
linearChartView->tick(now);
|
||||||
|
|
||||||
if (xFinished
|
if (xFinished
|
||||||
&& yFinished
|
&& yFinished
|
||||||
@@ -670,7 +670,7 @@ void ChartWidget::ChartAnimationController::tick(
|
|||||||
&& bottomLineAlphaFinished
|
&& bottomLineAlphaFinished
|
||||||
&& footerMinFinished
|
&& footerMinFinished
|
||||||
&& footerMaxFinished
|
&& footerMaxFinished
|
||||||
&& chartLinesViewContext.isFinished()) {
|
&& linearChartView->isFinished()) {
|
||||||
const auto &lines = horizontalLines.back().lines;
|
const auto &lines = horizontalLines.back().lines;
|
||||||
if ((_finalHeightLimits.min == _animationValueHeightMin.to())
|
if ((_finalHeightLimits.min == _animationValueHeightMin.to())
|
||||||
&& _finalHeightLimits.max == _animationValueHeightMax.to()) {
|
&& _finalHeightLimits.max == _animationValueHeightMax.to()) {
|
||||||
@@ -822,7 +822,7 @@ ChartWidget::ChartWidget(not_null<Ui::RpWidget*> parent)
|
|||||||
, _animationController([=] {
|
, _animationController([=] {
|
||||||
_chartArea->update();
|
_chartArea->update();
|
||||||
if (_animationController.footerAnimating()
|
if (_animationController.footerAnimating()
|
||||||
|| !_animatedChartLines.isFinished()) {
|
|| !_linearChartView.main->isFinished()) {
|
||||||
_footer->update();
|
_footer->update();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -900,7 +900,7 @@ void ChartWidget::setupChartArea() {
|
|||||||
now,
|
now,
|
||||||
_horizontalLines,
|
_horizontalLines,
|
||||||
_bottomLine.dates,
|
_bottomLine.dates,
|
||||||
_animatedChartLines);
|
_linearChartView.main);
|
||||||
|
|
||||||
const auto chartRect = chartAreaRect();
|
const auto chartRect = chartAreaRect();
|
||||||
|
|
||||||
@@ -934,7 +934,7 @@ void ChartWidget::setupChartArea() {
|
|||||||
for (const auto &line : _chartData.lines) {
|
for (const auto &line : _chartData.lines) {
|
||||||
_details.widget->setLineAlpha(
|
_details.widget->setLineAlpha(
|
||||||
line.id,
|
line.id,
|
||||||
_animatedChartLines.alpha(line.id));
|
_linearChartView.main->alpha(line.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -957,7 +957,6 @@ void ChartWidget::setupChartArea() {
|
|||||||
_animationController.currentXLimits(),
|
_animationController.currentXLimits(),
|
||||||
_animationController.currentHeightLimits(),
|
_animationController.currentHeightLimits(),
|
||||||
chartRect,
|
chartRect,
|
||||||
_animatedChartLines,
|
|
||||||
detailsPaintContext);
|
detailsPaintContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1082,7 +1081,6 @@ void ChartWidget::setupFooter() {
|
|||||||
fullXLimits,
|
fullXLimits,
|
||||||
_animationController.currentFooterHeightLimits(),
|
_animationController.currentFooterHeightLimits(),
|
||||||
r,
|
r,
|
||||||
_animatedChartLines,
|
|
||||||
detailsPaintContext);
|
detailsPaintContext);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1099,7 +1097,7 @@ void ChartWidget::setupFooter() {
|
|||||||
_animationController.setXPercentageLimits(
|
_animationController.setXPercentageLimits(
|
||||||
_chartData,
|
_chartData,
|
||||||
xPercentageLimits,
|
xPercentageLimits,
|
||||||
_animatedChartLines,
|
_linearChartView.main,
|
||||||
now);
|
now);
|
||||||
updateChartFullWidth(_chartArea->width());
|
updateChartFullWidth(_chartArea->width());
|
||||||
updateBottomDates();
|
updateBottomDates();
|
||||||
@@ -1194,26 +1192,6 @@ void ChartWidget::setupFilterButtons() {
|
|||||||
}
|
}
|
||||||
_filterButtons = base::make_unique_q<ChartLinesFilterWidget>(this);
|
_filterButtons = base::make_unique_q<ChartLinesFilterWidget>(this);
|
||||||
|
|
||||||
const auto asd = Ui::CreateChild<Ui::AbstractButton>(_filterButtons.get());
|
|
||||||
asd->paintRequest(
|
|
||||||
) | rpl::start_with_next([=](QRect r) {
|
|
||||||
auto p = QPainter(asd);
|
|
||||||
p.setOpacity(0.3);
|
|
||||||
p.fillRect(r, Qt::darkRed);
|
|
||||||
p.setOpacity(1.0);
|
|
||||||
p.setFont(st::statisticsDetailsBottomCaptionStyle.font);
|
|
||||||
p.setPen(st::boxTextFg);
|
|
||||||
p.drawText(asd->rect(), QString::number(_animatedChartLines.factor * 100) + "%", style::al_center);
|
|
||||||
}, asd->lifetime());
|
|
||||||
asd->setClickedCallback([=] {
|
|
||||||
_animatedChartLines.factor -= 0.1;
|
|
||||||
if (_animatedChartLines.factor <= 0) {
|
|
||||||
_animatedChartLines.factor = 1.0;
|
|
||||||
}
|
|
||||||
asd->update();
|
|
||||||
});
|
|
||||||
asd->resize(50, 50);
|
|
||||||
|
|
||||||
sizeValue(
|
sizeValue(
|
||||||
) | rpl::filter([](const QSize &s) {
|
) | rpl::filter([](const QSize &s) {
|
||||||
return s.width() > 0;
|
return s.width() > 0;
|
||||||
@@ -1232,19 +1210,17 @@ void ChartWidget::setupFilterButtons() {
|
|||||||
|
|
||||||
_filterButtons->fillButtons(texts, colors, ids, s.width());
|
_filterButtons->fillButtons(texts, colors, ids, s.width());
|
||||||
resizeHeight();
|
resizeHeight();
|
||||||
asd->raise();
|
|
||||||
asd->moveToRight(0, 0);
|
|
||||||
}, _filterButtons->lifetime());
|
}, _filterButtons->lifetime());
|
||||||
|
|
||||||
_filterButtons->buttonEnabledChanges(
|
_filterButtons->buttonEnabledChanges(
|
||||||
) | rpl::start_with_next([=](const ChartLinesFilterWidget::Entry &e) {
|
) | rpl::start_with_next([=](const ChartLinesFilterWidget::Entry &e) {
|
||||||
const auto now = crl::now();
|
const auto now = crl::now();
|
||||||
_animatedChartLines.setEnabled(e.id, e.enabled, now);
|
_linearChartView.main->setEnabled(e.id, e.enabled, now);
|
||||||
|
|
||||||
_animationController.setXPercentageLimits(
|
_animationController.setXPercentageLimits(
|
||||||
_chartData,
|
_chartData,
|
||||||
_animationController.currentXLimits(),
|
_animationController.currentXLimits(),
|
||||||
_animatedChartLines,
|
_linearChartView.main,
|
||||||
now);
|
now);
|
||||||
}, _filterButtons->lifetime());
|
}, _filterButtons->lifetime());
|
||||||
}
|
}
|
||||||
@@ -1261,7 +1237,7 @@ void ChartWidget::setChartData(Data::StatisticalChart chartData) {
|
|||||||
_animationController.setXPercentageLimits(
|
_animationController.setXPercentageLimits(
|
||||||
_chartData,
|
_chartData,
|
||||||
{ _chartData.xPercentage.front(), _chartData.xPercentage.back() },
|
{ _chartData.xPercentage.front(), _chartData.xPercentage.back() },
|
||||||
_animatedChartLines,
|
_linearChartView.main,
|
||||||
0);
|
0);
|
||||||
updateChartFullWidth(_chartArea->width());
|
updateChartFullWidth(_chartArea->width());
|
||||||
updateBottomDates();
|
updateBottomDates();
|
||||||
|
@@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
|
|
||||||
#include "data/data_statistics.h"
|
#include "data/data_statistics.h"
|
||||||
#include "statistics/chart_horizontal_lines_data.h"
|
#include "statistics/chart_horizontal_lines_data.h"
|
||||||
#include "statistics/chart_line_view_context.h"
|
|
||||||
#include "statistics/statistics_common.h"
|
#include "statistics/statistics_common.h"
|
||||||
#include "ui/effects/animation_value.h"
|
#include "ui/effects/animation_value.h"
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
@@ -50,7 +49,7 @@ private:
|
|||||||
void setXPercentageLimits(
|
void setXPercentageLimits(
|
||||||
Data::StatisticalChart &chartData,
|
Data::StatisticalChart &chartData,
|
||||||
Limits xPercentageLimits,
|
Limits xPercentageLimits,
|
||||||
const ChartLineViewContext &chartLinesViewContext,
|
const std::unique_ptr<LinearChartView> &linearChartView,
|
||||||
crl::time now);
|
crl::time now);
|
||||||
void start();
|
void start();
|
||||||
void finish();
|
void finish();
|
||||||
@@ -60,7 +59,7 @@ private:
|
|||||||
crl::time now,
|
crl::time now,
|
||||||
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
||||||
std::vector<BottomCaptionLineData> &dateLines,
|
std::vector<BottomCaptionLineData> &dateLines,
|
||||||
ChartLineViewContext &chartLinesViewContext);
|
const std::unique_ptr<LinearChartView> &linearChartView);
|
||||||
|
|
||||||
[[nodiscard]] Limits currentXLimits() const;
|
[[nodiscard]] Limits currentXLimits() const;
|
||||||
[[nodiscard]] Limits currentXIndices() const;
|
[[nodiscard]] Limits currentXIndices() const;
|
||||||
@@ -132,7 +131,6 @@ private:
|
|||||||
base::unique_qptr<ChartLinesFilterWidget> _filterButtons;
|
base::unique_qptr<ChartLinesFilterWidget> _filterButtons;
|
||||||
Data::StatisticalChart _chartData;
|
Data::StatisticalChart _chartData;
|
||||||
|
|
||||||
ChartLineViewContext _animatedChartLines;
|
|
||||||
struct {
|
struct {
|
||||||
std::unique_ptr<LinearChartView> main;
|
std::unique_ptr<LinearChartView> main;
|
||||||
std::unique_ptr<LinearChartView> footer;
|
std::unique_ptr<LinearChartView> footer;
|
||||||
|
@@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "statistics/linear_chart_view.h"
|
#include "statistics/linear_chart_view.h"
|
||||||
|
|
||||||
#include "data/data_statistics.h"
|
#include "data/data_statistics.h"
|
||||||
#include "statistics/chart_line_view_context.h"
|
|
||||||
#include "statistics/statistics_common.h"
|
#include "statistics/statistics_common.h"
|
||||||
#include "ui/effects/animation_value_f.h"
|
#include "ui/effects/animation_value_f.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
@@ -18,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
namespace Statistic {
|
namespace Statistic {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kAlphaDuration = float64(350);
|
||||||
|
|
||||||
void PaintChartLine(
|
void PaintChartLine(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
int lineIndex,
|
int lineIndex,
|
||||||
@@ -63,7 +64,6 @@ void LinearChartView::paint(
|
|||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
const Limits &heightLimits,
|
const Limits &heightLimits,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
ChartLineViewContext &lineViewContext,
|
|
||||||
DetailsPaintContext &detailsPaintContext) {
|
DetailsPaintContext &detailsPaintContext) {
|
||||||
|
|
||||||
const auto cacheToken = LinearChartView::CacheToken(
|
const auto cacheToken = LinearChartView::CacheToken(
|
||||||
@@ -74,7 +74,7 @@ void LinearChartView::paint(
|
|||||||
|
|
||||||
for (auto i = 0; i < chartData.lines.size(); i++) {
|
for (auto i = 0; i < chartData.lines.size(); i++) {
|
||||||
const auto &line = chartData.lines[i];
|
const auto &line = chartData.lines[i];
|
||||||
p.setOpacity(lineViewContext.alpha(line.id));
|
p.setOpacity(alpha(line.id));
|
||||||
if (!p.opacity()) {
|
if (!p.opacity()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -128,4 +128,56 @@ void LinearChartView::paint(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinearChartView::setEnabled(int id, bool enabled, crl::time now) {
|
||||||
|
const auto it = _entries.find(id);
|
||||||
|
if (it == end(_entries)) {
|
||||||
|
_entries[id] = Entry{ .enabled = enabled, .startedAt = now };
|
||||||
|
} else if (it->second.enabled != enabled) {
|
||||||
|
auto &entry = it->second;
|
||||||
|
entry.enabled = enabled;
|
||||||
|
entry.startedAt = now
|
||||||
|
- kAlphaDuration * (enabled ? entry.alpha : (1. - entry.alpha));
|
||||||
|
}
|
||||||
|
_isFinished = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinearChartView::isFinished() const {
|
||||||
|
return _isFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinearChartView::isEnabled(int id) const {
|
||||||
|
const auto it = _entries.find(id);
|
||||||
|
return (it == end(_entries)) ? true : it->second.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
float64 LinearChartView::alpha(int id) const {
|
||||||
|
const auto it = _entries.find(id);
|
||||||
|
return (it == end(_entries)) ? 1. : it->second.alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinearChartView::tick(crl::time now) {
|
||||||
|
auto finishedCount = 0;
|
||||||
|
auto idsToRemove = std::vector<int>();
|
||||||
|
for (auto &[id, entry] : _entries) {
|
||||||
|
if (!entry.startedAt) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto progress = (now - entry.startedAt) / kAlphaDuration;
|
||||||
|
entry.alpha = std::clamp(
|
||||||
|
entry.enabled ? progress : (1. - progress),
|
||||||
|
0.,
|
||||||
|
1.);
|
||||||
|
if (entry.alpha == 1.) {
|
||||||
|
idsToRemove.push_back(id);
|
||||||
|
}
|
||||||
|
if (progress >= 1.) {
|
||||||
|
finishedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_isFinished = (finishedCount == _entries.size());
|
||||||
|
for (const auto &id : idsToRemove) {
|
||||||
|
_entries.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
@@ -17,7 +17,6 @@ namespace Statistic {
|
|||||||
|
|
||||||
struct Limits;
|
struct Limits;
|
||||||
struct DetailsPaintContext;
|
struct DetailsPaintContext;
|
||||||
struct ChartLineViewContext;
|
|
||||||
|
|
||||||
class LinearChartView {
|
class LinearChartView {
|
||||||
public:
|
public:
|
||||||
@@ -30,9 +29,15 @@ public:
|
|||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
const Limits &heightLimits,
|
const Limits &heightLimits,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
ChartLineViewContext &lineViewContext,
|
|
||||||
DetailsPaintContext &detailsPaintContext);
|
DetailsPaintContext &detailsPaintContext);
|
||||||
|
|
||||||
|
void setEnabled(int id, bool enabled, crl::time now);
|
||||||
|
[[nodiscard]] bool isEnabled(int id) const;
|
||||||
|
[[nodiscard]] bool isFinished() const;
|
||||||
|
[[nodiscard]] float64 alpha(int id) const;
|
||||||
|
|
||||||
|
void tick(crl::time now);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct CacheToken final {
|
struct CacheToken final {
|
||||||
explicit CacheToken() = default;
|
explicit CacheToken() = default;
|
||||||
@@ -75,6 +80,15 @@ private:
|
|||||||
|
|
||||||
base::flat_map<int, Cache> _caches;
|
base::flat_map<int, Cache> _caches;
|
||||||
|
|
||||||
|
struct Entry final {
|
||||||
|
bool enabled = false;
|
||||||
|
crl::time startedAt = 0;
|
||||||
|
float64 alpha = 1.;
|
||||||
|
};
|
||||||
|
|
||||||
|
base::flat_map<int, Entry> _entries;
|
||||||
|
bool _isFinished = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
Reference in New Issue
Block a user