mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Added support of custom header in chart widget with zoomed chart.
This commit is contained in:
parent
ae81373cff
commit
361d269bf3
5 changed files with 35 additions and 9 deletions
|
@ -4066,6 +4066,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_stories_link_invalid" = "This link is broken or has expired.";
|
"lng_stories_link_invalid" = "This link is broken or has expired.";
|
||||||
|
|
||||||
"lng_stats_title" = "Statistics";
|
"lng_stats_title" = "Statistics";
|
||||||
|
"lng_stats_zoom_out" = "Zoom Out";
|
||||||
|
|
||||||
"lng_chart_title_member_count" = "Growth";
|
"lng_chart_title_member_count" = "Growth";
|
||||||
"lng_chart_title_join" = "Followers";
|
"lng_chart_title_join" = "Followers";
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "ui/effects/show_animation.h"
|
#include "ui/effects/show_animation.h"
|
||||||
#include "base/qt/qt_key_modifiers.h"
|
#include "base/qt/qt_key_modifiers.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
#include "statistics/chart_lines_filter_widget.h"
|
#include "statistics/chart_lines_filter_widget.h"
|
||||||
#include "statistics/linear_chart_view.h"
|
#include "statistics/linear_chart_view.h"
|
||||||
#include "statistics/point_details_widget.h"
|
#include "statistics/point_details_widget.h"
|
||||||
|
@ -223,6 +224,8 @@ void ChartWidget::Header::setRightInfo(QString rightInfo) {
|
||||||
void ChartWidget::Header::paintEvent(QPaintEvent *e) {
|
void ChartWidget::Header::paintEvent(QPaintEvent *e) {
|
||||||
auto p = Painter(this);
|
auto p = Painter(this);
|
||||||
|
|
||||||
|
p.fillRect(rect(), st::boxBg);
|
||||||
|
|
||||||
p.setPen(st::boxTextFg);
|
p.setPen(st::boxTextFg);
|
||||||
const auto top = (height()
|
const auto top = (height()
|
||||||
- st::statisticsHeaderTitleTextStyle.font->height) / 2;
|
- st::statisticsHeaderTitleTextStyle.font->height) / 2;
|
||||||
|
@ -1317,7 +1320,9 @@ void ChartWidget::setTitle(rpl::producer<QString> &&title) {
|
||||||
}, _header->lifetime());
|
}, _header->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
void ChartWidget::setZoomedChartData(
|
||||||
|
Data::StatisticalChart chartData,
|
||||||
|
float64 x) {
|
||||||
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
||||||
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
||||||
_zoomedChartWidget->setChartData(std::move(chartData));
|
_zoomedChartWidget->setChartData(std::move(chartData));
|
||||||
|
@ -1328,13 +1333,21 @@ void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
||||||
_zoomedChartWidget->show();
|
_zoomedChartWidget->show();
|
||||||
_zoomedChartWidget->resizeToWidth(width());
|
_zoomedChartWidget->resizeToWidth(width());
|
||||||
|
|
||||||
|
const auto customHeader = Ui::CreateChild<Header>(
|
||||||
|
_zoomedChartWidget.get());
|
||||||
|
const auto xIndex = std::distance(
|
||||||
|
begin(_chartData.x),
|
||||||
|
ranges::find(_chartData.x, x));
|
||||||
|
if ((xIndex >= 0) && (xIndex < _chartData.x.size())) {
|
||||||
|
customHeader->setRightInfo(_chartData.getDayString(xIndex));
|
||||||
|
}
|
||||||
|
|
||||||
const auto zoomOutButton = Ui::CreateChild<Ui::RoundButton>(
|
const auto zoomOutButton = Ui::CreateChild<Ui::RoundButton>(
|
||||||
_zoomedChartWidget.get(),
|
customHeader,
|
||||||
rpl::single(QString("Zoom Out")),
|
tr::lng_stats_zoom_out(),
|
||||||
st::defaultActiveButton);
|
st::statisticsHeaderButton);
|
||||||
Ui::Animations::ShowWidgets({ _zoomedChartWidget.get(), zoomOutButton });
|
zoomOutButton->setTextTransform(
|
||||||
Ui::Animations::HideWidgets({ this });
|
Ui::RoundButton::TextTransform::NoTransform);
|
||||||
zoomOutButton->moveToLeft(0, 0);
|
|
||||||
zoomOutButton->setClickedCallback([=] {
|
zoomOutButton->setClickedCallback([=] {
|
||||||
shownValue(
|
shownValue(
|
||||||
) | rpl::start_with_next([=](bool shown) {
|
) | rpl::start_with_next([=](bool shown) {
|
||||||
|
@ -1345,6 +1358,12 @@ void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
||||||
Ui::Animations::ShowWidgets({ this });
|
Ui::Animations::ShowWidgets({ this });
|
||||||
Ui::Animations::HideWidgets({ _zoomedChartWidget.get() });
|
Ui::Animations::HideWidgets({ _zoomedChartWidget.get() });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Ui::Animations::ShowWidgets({ _zoomedChartWidget.get(), customHeader });
|
||||||
|
Ui::Animations::HideWidgets({ this });
|
||||||
|
|
||||||
|
customHeader->setGeometry(0, 0, width(), st::statisticsChartHeaderHeight);
|
||||||
|
zoomOutButton->moveToLeft(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartWidget::addHorizontalLine(Limits newHeight, bool animated) {
|
void ChartWidget::addHorizontalLine(Limits newHeight, bool animated) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
void setChartData(Data::StatisticalChart chartData);
|
void setChartData(Data::StatisticalChart chartData);
|
||||||
void setTitle(rpl::producer<QString> &&title);
|
void setTitle(rpl::producer<QString> &&title);
|
||||||
void setZoomedChartData(Data::StatisticalChart chartData);
|
void setZoomedChartData(Data::StatisticalChart chartData, float64 x);
|
||||||
void addHorizontalLine(Limits newHeight, bool animated);
|
void addHorizontalLine(Limits newHeight, bool animated);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<float64> zoomRequests();
|
[[nodiscard]] rpl::producer<float64> zoomRequests();
|
||||||
|
|
|
@ -48,3 +48,9 @@ statisticsHeaderTitleTextStyle: TextStyle(defaultTextStyle) {
|
||||||
statisticsHeaderDatesTextStyle: TextStyle(defaultTextStyle) {
|
statisticsHeaderDatesTextStyle: TextStyle(defaultTextStyle) {
|
||||||
font: font(11px semibold);
|
font: font(11px semibold);
|
||||||
}
|
}
|
||||||
|
statisticsHeaderButton: RoundButton(defaultLightButton) {
|
||||||
|
width: -14px;
|
||||||
|
height: statisticsChartHeaderHeight;
|
||||||
|
textTop: 2px;
|
||||||
|
font: font(11px semibold);
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ void StatisticsBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
||||||
) | rpl::start_with_next_error_done([=](
|
) | rpl::start_with_next_error_done([=](
|
||||||
const Data::StatisticalGraph &graph) {
|
const Data::StatisticalGraph &graph) {
|
||||||
if (graph.chart) {
|
if (graph.chart) {
|
||||||
widget->setZoomedChartData(graph.chart);
|
widget->setZoomedChartData(graph.chart, x);
|
||||||
} else if (!graph.error.isEmpty()) {
|
} else if (!graph.error.isEmpty()) {
|
||||||
Ui::Toast::Show(
|
Ui::Toast::Show(
|
||||||
box->uiShow()->toastParent(),
|
box->uiShow()->toastParent(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue