stack_linear_chart_view.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "statistics/segment_tree.h"
  9. #include "statistics/statistics_common.h"
  10. #include "statistics/view/abstract_chart_view.h"
  11. #include "statistics/view/stack_linear_chart_common.h"
  12. #include "ui/effects/animations.h"
  13. #include "ui/effects/animation_value.h"
  14. namespace Data {
  15. struct StatisticalChart;
  16. } // namespace Data
  17. namespace Statistic {
  18. struct Limits;
  19. class StackLinearChartView final : public AbstractChartView {
  20. public:
  21. StackLinearChartView();
  22. ~StackLinearChartView() override final;
  23. void paint(QPainter &p, const PaintContext &c) override;
  24. void paintSelectedXIndex(
  25. QPainter &p,
  26. const PaintContext &c,
  27. int selectedXIndex,
  28. float64 progress) override;
  29. int findXIndexByPosition(
  30. const Data::StatisticalChart &chartData,
  31. const Limits &xPercentageLimits,
  32. const QRect &rect,
  33. float64 x) override;
  34. [[nodiscard]] HeightLimits heightLimits(
  35. Data::StatisticalChart &chartData,
  36. Limits xIndices) override;
  37. LocalZoomResult maybeLocalZoom(const LocalZoomArgs &args) override final;
  38. void handleMouseMove(
  39. const Data::StatisticalChart &chartData,
  40. const QRect &rect,
  41. const QPoint &p) override;
  42. private:
  43. enum class TransitionStep {
  44. PrepareToZoomIn,
  45. PrepareToZoomOut,
  46. ZoomedOut,
  47. };
  48. void paintChartOrZoomAnimation(QPainter &p, const PaintContext &c);
  49. void paintZoomed(QPainter &p, const PaintContext &c);
  50. void paintZoomedFooter(QPainter &p, const PaintContext &c);
  51. void paintPieText(QPainter &p, const PaintContext &c);
  52. [[nodiscard]] bool skipSelectedTranslation() const;
  53. void prepareZoom(const PaintContext &c, TransitionStep step);
  54. void saveZoomRange(const PaintContext &c);
  55. void savePieTextParts(const PaintContext &c);
  56. void applyParts(const std::vector<PiePartData::Part> &parts);
  57. struct SelectedPoints final {
  58. int lastXIndex = -1;
  59. Limits lastHeightLimits;
  60. Limits lastXLimits;
  61. float64 xPoint = 0.;
  62. };
  63. SelectedPoints _selectedPoints;
  64. struct Transition {
  65. struct TransitionLine {
  66. QPointF start;
  67. QPointF end;
  68. float64 angle = 0.;
  69. float64 sum = 0.;
  70. };
  71. std::vector<TransitionLine> lines;
  72. float64 progress = 0;
  73. bool pendingPrepareToZoomIn = false;
  74. Limits zoomedOutXIndices;
  75. Limits zoomedOutXIndicesAdditional;
  76. Limits zoomedOutXPercentage;
  77. Limits zoomedInLimit;
  78. Limits zoomedInLimitXIndices;
  79. Limits zoomedInRange;
  80. Limits zoomedInRangeXIndices;
  81. std::vector<PiePartData::Part> textParts;
  82. } _transition;
  83. std::vector<bool> _skipPoints;
  84. class PiePartController final {
  85. public:
  86. using LineId = int;
  87. bool set(LineId id);
  88. [[nodiscard]] float64 progress(LineId id) const;
  89. [[nodiscard]] QPointF offset(LineId id, float64 angle) const;
  90. [[nodiscard]] LineId selected() const;
  91. [[nodiscard]] bool isFinished() const;
  92. private:
  93. void update(LineId id);
  94. base::flat_map<LineId, crl::time> _startedAt;
  95. LineId _selected = -1;
  96. };
  97. class ChangingPiePartController final {
  98. public:
  99. void setParts(
  100. const std::vector<PiePartData::Part> &was,
  101. const std::vector<PiePartData::Part> &now);
  102. void update();
  103. [[nodiscard]] PiePartData current() const;
  104. [[nodiscard]] bool isFinished() const;
  105. private:
  106. crl::time _startedAt = 0;
  107. std::vector<anim::value> _animValues;
  108. PiePartData _current;
  109. bool _isFinished = true;
  110. };
  111. PiePartController _piePartController;
  112. ChangingPiePartController _changingPieController;
  113. Ui::Animations::Basic _piePartAnimation;
  114. bool _pieHasSinglePart = false;
  115. };
  116. } // namespace Statistic