2023-05-24 15:30:30 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
|
|
|
#include "data/data_statistics.h"
|
2023-09-11 14:14:07 +00:00
|
|
|
#include "statistics/view/chart_horizontal_lines_view.h"
|
2023-05-26 13:04:33 +00:00
|
|
|
#include "statistics/statistics_common.h"
|
2023-06-08 12:18:19 +00:00
|
|
|
#include "ui/effects/animation_value.h"
|
2023-05-24 15:30:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
|
|
|
|
namespace Statistic {
|
|
|
|
|
2023-07-06 16:16:02 +00:00
|
|
|
class RpMouseWidget;
|
2023-07-07 08:28:50 +00:00
|
|
|
class PointDetailsWidget;
|
2023-07-14 03:51:11 +00:00
|
|
|
class ChartLinesFilterWidget;
|
2023-08-27 21:16:48 +00:00
|
|
|
class AbstractChartView;
|
2023-07-06 16:16:02 +00:00
|
|
|
|
2023-05-24 15:30:30 +00:00
|
|
|
class ChartWidget : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
ChartWidget(not_null<Ui::RpWidget*> parent);
|
|
|
|
|
2023-09-08 13:27:29 +00:00
|
|
|
void setChartData(Data::StatisticalChart chartData, ChartViewType type);
|
2023-08-24 20:01:39 +00:00
|
|
|
void setTitle(rpl::producer<QString> &&title);
|
2023-09-08 13:27:29 +00:00
|
|
|
void setZoomedChartData(
|
|
|
|
Data::StatisticalChart chartData,
|
|
|
|
float64 x,
|
|
|
|
ChartViewType type);
|
2023-06-15 14:59:38 +00:00
|
|
|
void addHorizontalLine(Limits newHeight, bool animated);
|
2023-05-24 15:30:30 +00:00
|
|
|
|
2023-07-27 04:08:05 +00:00
|
|
|
[[nodiscard]] rpl::producer<float64> zoomRequests();
|
|
|
|
|
2023-07-07 15:17:09 +00:00
|
|
|
struct BottomCaptionLineData final {
|
|
|
|
int step = 0;
|
|
|
|
int stepMax = 0;
|
|
|
|
int stepMin = 0;
|
2023-07-10 14:29:52 +00:00
|
|
|
int stepMinFast = 0;
|
|
|
|
int stepRaw = 0;
|
|
|
|
|
2023-07-07 15:17:09 +00:00
|
|
|
float64 alpha = 0.;
|
|
|
|
float64 fixedAlpha = 0.;
|
|
|
|
};
|
|
|
|
|
2023-07-27 04:06:36 +00:00
|
|
|
protected:
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
2023-05-24 15:30:30 +00:00
|
|
|
private:
|
2023-08-24 20:01:39 +00:00
|
|
|
class Header;
|
2023-05-26 11:58:43 +00:00
|
|
|
class Footer;
|
2023-05-24 15:30:30 +00:00
|
|
|
|
2023-07-01 07:50:53 +00:00
|
|
|
class ChartAnimationController final {
|
|
|
|
public:
|
|
|
|
ChartAnimationController(Fn<void()> &&updateCallback);
|
|
|
|
|
|
|
|
void setXPercentageLimits(
|
|
|
|
Data::StatisticalChart &chartData,
|
|
|
|
Limits xPercentageLimits,
|
2023-08-27 21:16:48 +00:00
|
|
|
const std::unique_ptr<AbstractChartView> &AbstractChartView,
|
2023-07-01 07:50:53 +00:00
|
|
|
crl::time now);
|
|
|
|
void start();
|
2023-07-01 08:44:56 +00:00
|
|
|
void finish();
|
2023-07-01 07:50:53 +00:00
|
|
|
void resetAlpha();
|
2023-07-10 01:06:49 +00:00
|
|
|
void restartBottomLineAlpha();
|
2023-07-01 07:50:53 +00:00
|
|
|
void tick(
|
|
|
|
crl::time now,
|
2023-09-11 14:14:07 +00:00
|
|
|
ChartHorizontalLinesView &horizontalLinesView,
|
2023-07-14 00:45:59 +00:00
|
|
|
std::vector<BottomCaptionLineData> &dateLines,
|
2023-08-27 21:16:48 +00:00
|
|
|
const std::unique_ptr<AbstractChartView> &AbstractChartView);
|
2023-07-01 07:50:53 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Limits currentXLimits() const;
|
2023-07-11 23:28:56 +00:00
|
|
|
[[nodiscard]] Limits currentXIndices() const;
|
2023-07-07 08:28:50 +00:00
|
|
|
[[nodiscard]] Limits finalXLimits() const;
|
2023-07-01 07:50:53 +00:00
|
|
|
[[nodiscard]] Limits currentHeightLimits() const;
|
2023-07-14 17:13:42 +00:00
|
|
|
[[nodiscard]] Limits currentFooterHeightLimits() const;
|
2023-07-01 07:50:53 +00:00
|
|
|
[[nodiscard]] Limits finalHeightLimits() const;
|
2023-07-07 11:41:30 +00:00
|
|
|
[[nodiscard]] bool animating() const;
|
2023-07-14 17:13:42 +00:00
|
|
|
[[nodiscard]] bool footerAnimating() const;
|
2023-07-13 21:59:10 +00:00
|
|
|
[[nodiscard]] bool isFPSSlow() const;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
2023-07-14 22:56:47 +00:00
|
|
|
[[nodiscard]] rpl::producer<> addHorizontalLineRequests() const;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Ui::Animations::Basic _animation;
|
|
|
|
|
|
|
|
crl::time _lastUserInteracted = 0;
|
2023-07-10 01:06:49 +00:00
|
|
|
crl::time _bottomLineAlphaAnimationStartedAt = 0;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
2023-07-01 09:18:33 +00:00
|
|
|
anim::value _animationValueXMin;
|
|
|
|
anim::value _animationValueXMax;
|
|
|
|
anim::value _animationValueHeightMin;
|
|
|
|
anim::value _animationValueHeightMax;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
2023-07-14 17:13:42 +00:00
|
|
|
anim::value _animationValueFooterHeightMin;
|
|
|
|
anim::value _animationValueFooterHeightMax;
|
|
|
|
|
2023-07-14 22:56:47 +00:00
|
|
|
anim::value _animationValueHeightAlpha;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
2023-07-10 01:06:49 +00:00
|
|
|
anim::value _animValueBottomLineAlpha;
|
|
|
|
|
2023-07-01 07:50:53 +00:00
|
|
|
Limits _finalHeightLimits;
|
2023-07-11 23:28:56 +00:00
|
|
|
Limits _currentXIndices;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
2023-07-14 22:56:47 +00:00
|
|
|
struct {
|
|
|
|
float speed = 0.;
|
|
|
|
Limits current;
|
|
|
|
|
|
|
|
float64 currentAlpha = 0.;
|
|
|
|
} _dtHeight;
|
|
|
|
Limits _previousFullHeightLimits;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
2023-07-13 21:59:10 +00:00
|
|
|
struct {
|
|
|
|
crl::time lastTickedAt = 0;
|
|
|
|
bool lastFPSSlow = false;
|
|
|
|
} _benchmark;
|
|
|
|
|
2023-07-14 22:56:47 +00:00
|
|
|
rpl::event_stream<> _addHorizontalLineRequests;
|
2023-07-01 07:50:53 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-07-07 08:28:50 +00:00
|
|
|
[[nodiscard]] QRect chartAreaRect() const;
|
|
|
|
|
|
|
|
void setupChartArea();
|
|
|
|
void setupFooter();
|
|
|
|
void setupDetails();
|
2023-07-14 03:51:11 +00:00
|
|
|
void setupFilterButtons();
|
2023-07-07 08:28:50 +00:00
|
|
|
|
2023-07-07 15:17:09 +00:00
|
|
|
void updateBottomDates();
|
2023-08-24 20:01:39 +00:00
|
|
|
void updateHeader();
|
2023-07-07 15:17:09 +00:00
|
|
|
|
2023-07-14 18:09:55 +00:00
|
|
|
void updateChartFullWidth(int w);
|
2023-07-14 03:51:11 +00:00
|
|
|
|
2023-07-07 08:28:50 +00:00
|
|
|
const base::unique_qptr<RpMouseWidget> _chartArea;
|
2023-08-24 20:01:39 +00:00
|
|
|
const std::unique_ptr<Header> _header;
|
2023-07-07 08:28:50 +00:00
|
|
|
const std::unique_ptr<Footer> _footer;
|
2023-07-14 03:51:11 +00:00
|
|
|
base::unique_qptr<ChartLinesFilterWidget> _filterButtons;
|
2023-05-24 15:30:30 +00:00
|
|
|
Data::StatisticalChart _chartData;
|
|
|
|
|
2023-07-27 04:08:05 +00:00
|
|
|
base::unique_qptr<ChartWidget> _zoomedChartWidget;
|
|
|
|
|
2023-08-27 21:16:48 +00:00
|
|
|
std::unique_ptr<AbstractChartView> _chartView;
|
2023-07-14 00:45:59 +00:00
|
|
|
|
2023-07-07 08:28:50 +00:00
|
|
|
struct {
|
|
|
|
base::unique_qptr<PointDetailsWidget> widget;
|
2023-09-05 14:03:08 +00:00
|
|
|
Ui::Animations::Basic animation;
|
|
|
|
bool hideOnAnimationEnd = false;
|
2023-07-07 08:28:50 +00:00
|
|
|
} _details;
|
|
|
|
|
2023-07-07 15:17:09 +00:00
|
|
|
struct {
|
|
|
|
BottomCaptionLineData current;
|
|
|
|
std::vector<BottomCaptionLineData> dates;
|
|
|
|
int chartFullWidth = 0;
|
2023-07-10 22:30:09 +00:00
|
|
|
int captionIndicesOffset = 0;
|
2023-07-07 15:17:09 +00:00
|
|
|
} _bottomLine;
|
|
|
|
|
2023-05-24 15:30:30 +00:00
|
|
|
bool _useMinHeight = false;
|
|
|
|
|
2023-07-01 07:50:53 +00:00
|
|
|
ChartAnimationController _animationController;
|
2023-05-24 15:30:30 +00:00
|
|
|
crl::time _lastHeightLimitsChanged = 0;
|
|
|
|
|
2023-09-11 14:14:07 +00:00
|
|
|
ChartHorizontalLinesView _horizontalLinesView;
|
2023-05-24 15:30:30 +00:00
|
|
|
|
2023-07-27 04:08:05 +00:00
|
|
|
bool _zoomEnabled = false;
|
|
|
|
rpl::event_stream<float64> _zoomRequests;
|
|
|
|
|
2023-05-24 15:30:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Statistic
|