mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of chart titles to Data and API classes for statistics.
This commit is contained in:
parent
1dc57afbe1
commit
160794b26c
4 changed files with 92 additions and 2 deletions
|
@ -192,6 +192,51 @@ void RpMouseWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
_mouseStateChanged.fire({ e->pos(), QEvent::MouseButtonRelease });
|
_mouseStateChanged.fire({ e->pos(), QEvent::MouseButtonRelease });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ChartWidget::Header final : public RpWidget {
|
||||||
|
public:
|
||||||
|
using RpWidget::RpWidget;
|
||||||
|
|
||||||
|
void setTitle(QString title);
|
||||||
|
void setRightInfo(QString rightInfo);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::Text::String _title;
|
||||||
|
Ui::Text::String _rightInfo;
|
||||||
|
int _titleWidth = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void ChartWidget::Header::setTitle(QString title) {
|
||||||
|
_titleWidth = st::statisticsHeaderTitleTextStyle.font->width(title);
|
||||||
|
_title.setText(st::statisticsHeaderTitleTextStyle, std::move(title));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChartWidget::Header::setRightInfo(QString rightInfo) {
|
||||||
|
_rightInfo.setText(
|
||||||
|
st::statisticsHeaderDatesTextStyle,
|
||||||
|
std::move(rightInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChartWidget::Header::paintEvent(QPaintEvent *e) {
|
||||||
|
auto p = Painter(this);
|
||||||
|
|
||||||
|
p.setPen(st::boxTextFg);
|
||||||
|
const auto top = (height()
|
||||||
|
- st::statisticsHeaderTitleTextStyle.font->height) / 2;
|
||||||
|
_title.drawLeftElided(p, 0, top, width(), width());
|
||||||
|
_rightInfo.drawRightElided(
|
||||||
|
p,
|
||||||
|
0,
|
||||||
|
top,
|
||||||
|
width() - _titleWidth,
|
||||||
|
width(),
|
||||||
|
1,
|
||||||
|
style::al_right);
|
||||||
|
}
|
||||||
|
|
||||||
class ChartWidget::Footer final : public RpMouseWidget {
|
class ChartWidget::Footer final : public RpMouseWidget {
|
||||||
public:
|
public:
|
||||||
using PaintCallback = Fn<void(QPainter &, const QRect &)>;
|
using PaintCallback = Fn<void(QPainter &, const QRect &)>;
|
||||||
|
@ -823,6 +868,7 @@ bool ChartWidget::ChartAnimationController::isFPSSlow() const {
|
||||||
ChartWidget::ChartWidget(not_null<Ui::RpWidget*> parent)
|
ChartWidget::ChartWidget(not_null<Ui::RpWidget*> parent)
|
||||||
: Ui::RpWidget(parent)
|
: Ui::RpWidget(parent)
|
||||||
, _chartArea(base::make_unique_q<RpMouseWidget>(this))
|
, _chartArea(base::make_unique_q<RpMouseWidget>(this))
|
||||||
|
, _header(std::make_unique<Header>(this))
|
||||||
, _footer(std::make_unique<Footer>(this))
|
, _footer(std::make_unique<Footer>(this))
|
||||||
, _animationController([=] {
|
, _animationController([=] {
|
||||||
_chartArea->update();
|
_chartArea->update();
|
||||||
|
@ -857,8 +903,14 @@ int ChartWidget::resizeGetHeight(int newWidth) {
|
||||||
const auto resultHeight = st::statisticsChartHeight
|
const auto resultHeight = st::statisticsChartHeight
|
||||||
+ st::statisticsChartFooterHeight
|
+ st::statisticsChartFooterHeight
|
||||||
+ st::statisticsChartFooterSkip
|
+ st::statisticsChartFooterSkip
|
||||||
+ filtersHeight;
|
+ filtersHeight
|
||||||
|
+ st::statisticsChartHeaderHeight;
|
||||||
{
|
{
|
||||||
|
_header->setGeometry(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
newWidth,
|
||||||
|
st::statisticsChartHeaderHeight);
|
||||||
_footer->setGeometry(
|
_footer->setGeometry(
|
||||||
0,
|
0,
|
||||||
resultHeight - st::statisticsChartFooterHeight - filtersHeight,
|
resultHeight - st::statisticsChartFooterHeight - filtersHeight,
|
||||||
|
@ -870,7 +922,7 @@ int ChartWidget::resizeGetHeight(int newWidth) {
|
||||||
}
|
}
|
||||||
_chartArea->setGeometry(
|
_chartArea->setGeometry(
|
||||||
0,
|
0,
|
||||||
0,
|
st::statisticsChartHeaderHeight,
|
||||||
newWidth,
|
newWidth,
|
||||||
resultHeight
|
resultHeight
|
||||||
- st::statisticsChartFooterHeight
|
- st::statisticsChartFooterHeight
|
||||||
|
@ -1070,6 +1122,19 @@ void ChartWidget::updateBottomDates() {
|
||||||
_animationController.restartBottomLineAlpha();
|
_animationController.restartBottomLineAlpha();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChartWidget::updateHeader() {
|
||||||
|
if (!_chartData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto indices = _animationController.currentXIndices();
|
||||||
|
_header->setRightInfo(_chartData.getDayString(indices.min)
|
||||||
|
+ ' '
|
||||||
|
+ QChar(8212)
|
||||||
|
+ ' '
|
||||||
|
+ _chartData.getDayString(indices.max));
|
||||||
|
_header->update();
|
||||||
|
}
|
||||||
|
|
||||||
void ChartWidget::setupFooter() {
|
void ChartWidget::setupFooter() {
|
||||||
_footer->setPaintChartCallback([=, fullXLimits = Limits{ 0., 1. }](
|
_footer->setPaintChartCallback([=, fullXLimits = Limits{ 0., 1. }](
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
|
@ -1108,6 +1173,7 @@ void ChartWidget::setupFooter() {
|
||||||
now);
|
now);
|
||||||
updateChartFullWidth(_chartArea->width());
|
updateChartFullWidth(_chartArea->width());
|
||||||
updateBottomDates();
|
updateBottomDates();
|
||||||
|
updateHeader();
|
||||||
if ((now - _lastHeightLimitsChanged) < kHeightLimitsUpdateTimeout) {
|
if ((now - _lastHeightLimitsChanged) < kHeightLimitsUpdateTimeout) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1233,6 +1299,7 @@ void ChartWidget::setChartData(Data::StatisticalChart chartData) {
|
||||||
_linearChartView,
|
_linearChartView,
|
||||||
0);
|
0);
|
||||||
updateChartFullWidth(_chartArea->width());
|
updateChartFullWidth(_chartArea->width());
|
||||||
|
updateHeader();
|
||||||
updateBottomDates();
|
updateBottomDates();
|
||||||
_animationController.finish();
|
_animationController.finish();
|
||||||
addHorizontalLine(_animationController.finalHeightLimits(), false);
|
addHorizontalLine(_animationController.finalHeightLimits(), false);
|
||||||
|
@ -1240,6 +1307,15 @@ void ChartWidget::setChartData(Data::StatisticalChart chartData) {
|
||||||
_footer->update();
|
_footer->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChartWidget::setTitle(rpl::producer<QString> &&title) {
|
||||||
|
std::move(
|
||||||
|
title
|
||||||
|
) | rpl::start_with_next([=](QString t) {
|
||||||
|
_header->setTitle(std::move(t));
|
||||||
|
_header->update();
|
||||||
|
}, _header->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
||||||
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
||||||
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
ChartWidget(not_null<Ui::RpWidget*> parent);
|
ChartWidget(not_null<Ui::RpWidget*> parent);
|
||||||
|
|
||||||
void setChartData(Data::StatisticalChart chartData);
|
void setChartData(Data::StatisticalChart chartData);
|
||||||
|
void setTitle(rpl::producer<QString> &&title);
|
||||||
void setZoomedChartData(Data::StatisticalChart chartData);
|
void setZoomedChartData(Data::StatisticalChart chartData);
|
||||||
void addHorizontalLine(Limits newHeight, bool animated);
|
void addHorizontalLine(Limits newHeight, bool animated);
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ protected:
|
||||||
int resizeGetHeight(int newWidth) override;
|
int resizeGetHeight(int newWidth) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class Header;
|
||||||
class Footer;
|
class Footer;
|
||||||
|
|
||||||
class ChartAnimationController final {
|
class ChartAnimationController final {
|
||||||
|
@ -128,10 +130,12 @@ private:
|
||||||
void setupFilterButtons();
|
void setupFilterButtons();
|
||||||
|
|
||||||
void updateBottomDates();
|
void updateBottomDates();
|
||||||
|
void updateHeader();
|
||||||
|
|
||||||
void updateChartFullWidth(int w);
|
void updateChartFullWidth(int w);
|
||||||
|
|
||||||
const base::unique_qptr<RpMouseWidget> _chartArea;
|
const base::unique_qptr<RpMouseWidget> _chartArea;
|
||||||
|
const std::unique_ptr<Header> _header;
|
||||||
const std::unique_ptr<Footer> _footer;
|
const std::unique_ptr<Footer> _footer;
|
||||||
base::unique_qptr<ChartLinesFilterWidget> _filterButtons;
|
base::unique_qptr<ChartLinesFilterWidget> _filterButtons;
|
||||||
Data::StatisticalChart _chartData;
|
Data::StatisticalChart _chartData;
|
||||||
|
|
|
@ -40,3 +40,11 @@ statisticsDetailsPopupStyle: TextStyle(defaultTextStyle) {
|
||||||
statisticsDetailsBottomCaptionStyle: TextStyle(defaultTextStyle) {
|
statisticsDetailsBottomCaptionStyle: TextStyle(defaultTextStyle) {
|
||||||
font: font(10px);
|
font: font(10px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statisticsChartHeaderHeight: 20px;
|
||||||
|
statisticsHeaderTitleTextStyle: TextStyle(defaultTextStyle) {
|
||||||
|
font: font(12px semibold);
|
||||||
|
}
|
||||||
|
statisticsHeaderDatesTextStyle: TextStyle(defaultTextStyle) {
|
||||||
|
font: font(11px semibold);
|
||||||
|
}
|
||||||
|
|
|
@ -55,6 +55,8 @@ void StatisticsBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
||||||
) | rpl::start_with_done([=] {
|
) | rpl::start_with_done([=] {
|
||||||
if (const auto stats = api->channelStats()) {
|
if (const auto stats = api->channelStats()) {
|
||||||
chartWidget->setChartData(stats.memberCountGraph.chart);
|
chartWidget->setChartData(stats.memberCountGraph.chart);
|
||||||
|
processZoom(chartWidget, stats.memberCountGraph.zoomToken);
|
||||||
|
chartWidget->setTitle(tr::lng_chart_title_member_count());
|
||||||
}
|
}
|
||||||
}, chartWidget->lifetime());
|
}, chartWidget->lifetime());
|
||||||
box->setTitle(tr::lng_stats_title());
|
box->setTitle(tr::lng_stats_title());
|
||||||
|
|
Loading…
Add table
Reference in a new issue