bar_chart_view.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/statistics_types.h"
  11. #include "statistics/view/abstract_chart_view.h"
  12. #include "ui/effects/animation_value.h"
  13. namespace Data {
  14. struct StatisticalChart;
  15. } // namespace Data
  16. namespace Statistic {
  17. struct Limits;
  18. class BarChartView final : public AbstractChartView {
  19. public:
  20. BarChartView(bool isStack);
  21. ~BarChartView() override final;
  22. void paint(QPainter &p, const PaintContext &c) override;
  23. void paintSelectedXIndex(
  24. QPainter &p,
  25. const PaintContext &c,
  26. int selectedXIndex,
  27. float64 progress) override;
  28. int findXIndexByPosition(
  29. const Data::StatisticalChart &chartData,
  30. const Limits &xPercentageLimits,
  31. const QRect &rect,
  32. float64 x) override;
  33. [[nodiscard]] HeightLimits heightLimits(
  34. Data::StatisticalChart &chartData,
  35. Limits xIndices) override;
  36. private:
  37. void paintChartAndSelected(QPainter &p, const PaintContext &c);
  38. struct {
  39. Limits full;
  40. std::vector<ChartValue> ySum;
  41. SegmentTree ySumSegmentTree;
  42. } _cachedHeightLimits;
  43. const bool _isStack;
  44. DoubleLineRatios _cachedLineRatios; // Non-stack.
  45. Limits _lastPaintedXIndices;
  46. int _lastSelectedXIndex = -1;
  47. float64 _lastSelectedXProgress = 0;
  48. CachedSelectedPoints _selectedPoints; // Non-stack.
  49. };
  50. } // namespace Statistic