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_stats_title" = "Statistics";
|
||||
"lng_stats_zoom_out" = "Zoom Out";
|
||||
|
||||
"lng_chart_title_member_count" = "Growth";
|
||||
"lng_chart_title_join" = "Followers";
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/effects/show_animation.h"
|
||||
#include "base/qt/qt_key_modifiers.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "statistics/chart_lines_filter_widget.h"
|
||||
#include "statistics/linear_chart_view.h"
|
||||
#include "statistics/point_details_widget.h"
|
||||
|
@ -223,6 +224,8 @@ void ChartWidget::Header::setRightInfo(QString rightInfo) {
|
|||
void ChartWidget::Header::paintEvent(QPaintEvent *e) {
|
||||
auto p = Painter(this);
|
||||
|
||||
p.fillRect(rect(), st::boxBg);
|
||||
|
||||
p.setPen(st::boxTextFg);
|
||||
const auto top = (height()
|
||||
- st::statisticsHeaderTitleTextStyle.font->height) / 2;
|
||||
|
@ -1317,7 +1320,9 @@ void ChartWidget::setTitle(rpl::producer<QString> &&title) {
|
|||
}, _header->lifetime());
|
||||
}
|
||||
|
||||
void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
||||
void ChartWidget::setZoomedChartData(
|
||||
Data::StatisticalChart chartData,
|
||||
float64 x) {
|
||||
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
||||
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
||||
_zoomedChartWidget->setChartData(std::move(chartData));
|
||||
|
@ -1328,13 +1333,21 @@ void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
|||
_zoomedChartWidget->show();
|
||||
_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>(
|
||||
_zoomedChartWidget.get(),
|
||||
rpl::single(QString("Zoom Out")),
|
||||
st::defaultActiveButton);
|
||||
Ui::Animations::ShowWidgets({ _zoomedChartWidget.get(), zoomOutButton });
|
||||
Ui::Animations::HideWidgets({ this });
|
||||
zoomOutButton->moveToLeft(0, 0);
|
||||
customHeader,
|
||||
tr::lng_stats_zoom_out(),
|
||||
st::statisticsHeaderButton);
|
||||
zoomOutButton->setTextTransform(
|
||||
Ui::RoundButton::TextTransform::NoTransform);
|
||||
zoomOutButton->setClickedCallback([=] {
|
||||
shownValue(
|
||||
) | rpl::start_with_next([=](bool shown) {
|
||||
|
@ -1345,6 +1358,12 @@ void ChartWidget::setZoomedChartData(Data::StatisticalChart chartData) {
|
|||
Ui::Animations::ShowWidgets({ this });
|
||||
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) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
void setChartData(Data::StatisticalChart chartData);
|
||||
void setTitle(rpl::producer<QString> &&title);
|
||||
void setZoomedChartData(Data::StatisticalChart chartData);
|
||||
void setZoomedChartData(Data::StatisticalChart chartData, float64 x);
|
||||
void addHorizontalLine(Limits newHeight, bool animated);
|
||||
|
||||
[[nodiscard]] rpl::producer<float64> zoomRequests();
|
||||
|
|
|
@ -48,3 +48,9 @@ statisticsHeaderTitleTextStyle: TextStyle(defaultTextStyle) {
|
|||
statisticsHeaderDatesTextStyle: TextStyle(defaultTextStyle) {
|
||||
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([=](
|
||||
const Data::StatisticalGraph &graph) {
|
||||
if (graph.chart) {
|
||||
widget->setZoomedChartData(graph.chart);
|
||||
widget->setZoomedChartData(graph.chart, x);
|
||||
} else if (!graph.error.isEmpty()) {
|
||||
Ui::Toast::Show(
|
||||
box->uiShow()->toastParent(),
|
||||
|
|
Loading…
Reference in a new issue