From 17fdef7d9e74d6ccff98635dc9c425d95b756035 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 28 Sep 2023 23:21:11 +0300 Subject: [PATCH] Added chart widgets for statistic of supergroups. --- Telegram/Resources/langs/lang.strings | 8 ++ .../SourceFiles/statistics/statistics_box.cpp | 81 ++++++++++++++++++- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index c8ff0cce0..b1c1d5301 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4087,6 +4087,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_chart_title_message_interaction" = "Interactions"; "lng_chart_title_instant_view_interaction" = "IV Interactions"; +"lng_chart_title_group_join" = "Group members"; +"lng_chart_title_group_join_by_source" = "New members by source"; +"lng_chart_title_group_language" = "Members's primary language"; +"lng_chart_title_group_message_content" = "Messages"; +"lng_chart_title_group_action" = "Actions"; +"lng_chart_title_group_day" = "Views by hours"; +"lng_chart_title_group_week" = "Top days of week"; + // Wnd specific "lng_wnd_choose_program_menu" = "Choose Default Program..."; diff --git a/Telegram/SourceFiles/statistics/statistics_box.cpp b/Telegram/SourceFiles/statistics/statistics_box.cpp index 4b05d8680..a4811c247 100644 --- a/Telegram/SourceFiles/statistics/statistics_box.cpp +++ b/Telegram/SourceFiles/statistics/statistics_box.cpp @@ -166,6 +166,76 @@ void FillChannelStatistic( addSkip(); } +void FillSupergroupStatistic( + not_null box, + const Descriptor &descriptor, + const Data::SupergroupStatistics &stats) { + using Type = Statistic::ChartViewType; + const auto &padding = st::statisticsChartEntryPadding; + const auto addSkip = [&] { + Settings::AddSkip(box->verticalLayout(), padding.bottom()); + Settings::AddDivider(box->verticalLayout()); + Settings::AddSkip(box->verticalLayout(), padding.top()); + }; + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.memberCountGraph, + tr::lng_chart_title_member_count(), + Type::Linear); + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.joinGraph, + tr::lng_chart_title_group_join(), + Type::Linear); + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.joinBySourceGraph, + tr::lng_chart_title_group_join_by_source(), + Type::Stack); + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.languageGraph, + tr::lng_chart_title_group_language(), + Type::StackLinear); + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.messageContentGraph, + tr::lng_chart_title_group_message_content(), + Type::Stack); + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.actionGraph, + tr::lng_chart_title_group_action(), + Type::DoubleLinear); + addSkip(); + ProcessChart( + descriptor, + box->addRow(object_ptr(box)), + stats.dayGraph, + tr::lng_chart_title_group_day(), + Type::Linear); + addSkip(); + // ProcessChart( + // descriptor, + // box->addRow(object_ptr(box)), + // stats.weekGraph, + // tr::lng_chart_title_group_week(), + // Type::StackLinear); + // addSkip(); +} + void FillLoading( not_null box, rpl::producer toggleOn) { @@ -338,12 +408,15 @@ void StatisticsBox(not_null box, not_null peer) { descriptor.api->request( descriptor.peer ) | rpl::start_with_done([=] { - const auto stats = descriptor.api->channelStats(); - if (!stats) { + if (const auto stats = descriptor.api->supergroupStats(); stats) { + // FillSupergroupOverview(box, descriptor, stats); + FillSupergroupStatistic(box, descriptor, stats); + } else if (const auto stats = descriptor.api->channelStats(); stats) { + FillChannelOverview(box, descriptor, stats); + FillChannelStatistic(box, descriptor, stats); + } else { return; } - FillChannelOverview(box, descriptor, stats); - FillChannelStatistic(box, descriptor, stats); loaded->fire(true); box->verticalLayout()->resizeToWidth(box->width()); box->showChildren();