2023-09-12 08:35:09 +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 "statistics/segment_tree.h"
|
|
|
|
#include "statistics/statistics_common.h"
|
|
|
|
#include "statistics/view/abstract_chart_view.h"
|
2023-10-05 15:45:48 +00:00
|
|
|
#include "statistics/view/stack_linear_chart_common.h"
|
2023-09-15 01:46:28 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2023-09-12 08:35:09 +00:00
|
|
|
#include "ui/effects/animation_value.h"
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
struct StatisticalChart;
|
|
|
|
} // namespace Data
|
|
|
|
|
|
|
|
namespace Statistic {
|
|
|
|
|
|
|
|
struct Limits;
|
|
|
|
|
|
|
|
class StackLinearChartView final : public AbstractChartView {
|
|
|
|
public:
|
|
|
|
StackLinearChartView();
|
|
|
|
~StackLinearChartView() override final;
|
|
|
|
|
2023-09-19 10:02:50 +00:00
|
|
|
void paint(QPainter &p, const PaintContext &c) override;
|
2023-09-12 08:35:09 +00:00
|
|
|
|
|
|
|
void paintSelectedXIndex(
|
|
|
|
QPainter &p,
|
2023-09-19 10:02:50 +00:00
|
|
|
const PaintContext &c,
|
2023-09-12 08:35:09 +00:00
|
|
|
int selectedXIndex,
|
|
|
|
float64 progress) override;
|
|
|
|
|
|
|
|
int findXIndexByPosition(
|
|
|
|
const Data::StatisticalChart &chartData,
|
|
|
|
const Limits &xPercentageLimits,
|
|
|
|
const QRect &rect,
|
|
|
|
float64 x) override;
|
|
|
|
|
|
|
|
[[nodiscard]] HeightLimits heightLimits(
|
|
|
|
Data::StatisticalChart &chartData,
|
|
|
|
Limits xIndices) override;
|
|
|
|
|
2023-09-25 12:20:43 +00:00
|
|
|
LocalZoomResult maybeLocalZoom(const LocalZoomArgs &args) override final;
|
|
|
|
|
2023-09-15 01:46:28 +00:00
|
|
|
void handleMouseMove(
|
|
|
|
const Data::StatisticalChart &chartData,
|
2023-09-26 20:09:44 +00:00
|
|
|
const QRect &rect,
|
|
|
|
const QPoint &p) override;
|
2023-09-15 01:46:28 +00:00
|
|
|
|
2023-09-12 08:35:09 +00:00
|
|
|
private:
|
2023-09-25 12:20:43 +00:00
|
|
|
enum class TransitionStep {
|
|
|
|
PrepareToZoomIn,
|
|
|
|
PrepareToZoomOut,
|
|
|
|
ZoomedOut,
|
|
|
|
};
|
2023-09-19 10:02:50 +00:00
|
|
|
void paintChartOrZoomAnimation(QPainter &p, const PaintContext &c);
|
2023-09-12 08:35:09 +00:00
|
|
|
|
2023-09-19 10:02:50 +00:00
|
|
|
void paintZoomed(QPainter &p, const PaintContext &c);
|
|
|
|
void paintZoomedFooter(QPainter &p, const PaintContext &c);
|
|
|
|
void paintPieText(QPainter &p, const PaintContext &c);
|
2023-09-14 13:16:51 +00:00
|
|
|
|
2023-09-15 14:05:45 +00:00
|
|
|
[[nodiscard]] bool skipSelectedTranslation() const;
|
|
|
|
|
2023-09-25 12:20:43 +00:00
|
|
|
void prepareZoom(const PaintContext &c, TransitionStep step);
|
|
|
|
|
|
|
|
void saveZoomRange(const PaintContext &c);
|
|
|
|
void savePieTextParts(const PaintContext &c);
|
2023-10-05 15:45:48 +00:00
|
|
|
void applyParts(const std::vector<PiePartData::Part> &parts);
|
2023-09-25 12:20:43 +00:00
|
|
|
|
2023-09-12 08:35:09 +00:00
|
|
|
struct SelectedPoints final {
|
|
|
|
int lastXIndex = -1;
|
|
|
|
Limits lastHeightLimits;
|
|
|
|
Limits lastXLimits;
|
2023-09-26 14:16:37 +00:00
|
|
|
float64 xPoint = 0.;
|
2023-09-12 08:35:09 +00:00
|
|
|
};
|
|
|
|
SelectedPoints _selectedPoints;
|
|
|
|
|
2023-09-12 14:24:46 +00:00
|
|
|
struct Transition {
|
|
|
|
struct TransitionLine {
|
|
|
|
QPointF start;
|
|
|
|
QPointF end;
|
|
|
|
float64 angle = 0.;
|
|
|
|
float64 sum = 0.;
|
|
|
|
};
|
|
|
|
std::vector<TransitionLine> lines;
|
2023-09-25 15:14:28 +00:00
|
|
|
float64 progress = 0;
|
|
|
|
|
|
|
|
bool pendingPrepareToZoomIn = false;
|
|
|
|
|
2023-09-25 12:20:43 +00:00
|
|
|
Limits zoomedOutXIndices;
|
2023-09-26 16:24:10 +00:00
|
|
|
Limits zoomedOutXIndicesAdditional;
|
|
|
|
Limits zoomedOutXPercentage;
|
2023-09-25 15:14:28 +00:00
|
|
|
Limits zoomedInLimit;
|
|
|
|
Limits zoomedInLimitXIndices;
|
|
|
|
Limits zoomedInRange;
|
|
|
|
Limits zoomedInRangeXIndices;
|
|
|
|
|
2023-10-05 15:45:48 +00:00
|
|
|
std::vector<PiePartData::Part> textParts;
|
2023-09-25 15:14:28 +00:00
|
|
|
} _transition;
|
2023-09-12 14:24:46 +00:00
|
|
|
|
|
|
|
std::vector<bool> _skipPoints;
|
|
|
|
|
2023-09-15 01:46:28 +00:00
|
|
|
class PiePartController final {
|
|
|
|
public:
|
|
|
|
using LineId = int;
|
|
|
|
bool set(LineId id);
|
2023-09-19 14:37:20 +00:00
|
|
|
[[nodiscard]] float64 progress(LineId id) const;
|
|
|
|
[[nodiscard]] QPointF offset(LineId id, float64 angle) const;
|
2023-09-15 09:41:14 +00:00
|
|
|
[[nodiscard]] LineId selected() const;
|
2023-09-19 14:37:20 +00:00
|
|
|
[[nodiscard]] bool isFinished() const;
|
2023-09-15 01:46:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void update(LineId id);
|
|
|
|
|
|
|
|
base::flat_map<LineId, crl::time> _startedAt;
|
|
|
|
LineId _selected = -1;
|
|
|
|
|
|
|
|
};
|
|
|
|
PiePartController _piePartController;
|
|
|
|
Ui::Animations::Basic _piePartAnimation;
|
2023-09-26 01:11:18 +00:00
|
|
|
bool _pieHasSinglePart = false;
|
2023-09-15 01:46:28 +00:00
|
|
|
|
2023-09-12 08:35:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Statistic
|