Added ability to hide charts without data in statistics box.

This commit is contained in:
23rd 2023-09-29 00:14:40 +03:00 committed by John Preston
parent 5b67f4ac9b
commit 23868bf9cc

View file

@ -32,6 +32,11 @@ struct Descriptor final {
not_null<QWidget*> toastParent; not_null<QWidget*> toastParent;
}; };
struct AnyStats final {
Data::ChannelStatistics channel;
Data::SupergroupStatistics supergroup;
};
void ProcessZoom( void ProcessZoom(
const Descriptor &d, const Descriptor &d,
not_null<Statistic::ChartWidget*> widget, not_null<Statistic::ChartWidget*> widget,
@ -61,12 +66,15 @@ void ProcessZoom(
void ProcessChart( void ProcessChart(
const Descriptor &d, const Descriptor &d,
not_null<Ui::SlideWrap<Ui::VerticalLayout>*> wrap,
not_null<Statistic::ChartWidget*> widget, not_null<Statistic::ChartWidget*> widget,
const Data::StatisticalGraph &graphData, const Data::StatisticalGraph &graphData,
rpl::producer<QString> &&title, rpl::producer<QString> &&title,
Statistic::ChartViewType type) { Statistic::ChartViewType type) {
wrap->toggle(false, anim::type::instant);
if (graphData.chart) { if (graphData.chart) {
widget->setChartData(graphData.chart, type); widget->setChartData(graphData.chart, type);
wrap->toggle(true, anim::type::instant);
ProcessZoom(d, widget, graphData.zoomToken, type); ProcessZoom(d, widget, graphData.zoomToken, type);
widget->setTitle(std::move(title)); widget->setTitle(std::move(title));
} else if (!graphData.zoomToken.isEmpty()) { } else if (!graphData.zoomToken.isEmpty()) {
@ -78,6 +86,7 @@ void ProcessChart(
const Data::StatisticalGraph &graph) { const Data::StatisticalGraph &graph) {
if (graph.chart) { if (graph.chart) {
widget->setChartData(graph.chart, type); widget->setChartData(graph.chart, type);
wrap->toggle(true, anim::type::normal);
ProcessZoom(d, widget, graph.zoomToken, type); ProcessZoom(d, widget, graph.zoomToken, type);
widget->setTitle(rpl::duplicate(title)); widget->setTitle(rpl::duplicate(title));
} else if (!graph.error.isEmpty()) { } else if (!graph.error.isEmpty()) {
@ -89,151 +98,108 @@ void ProcessChart(
} }
} }
void FillChannelStatistic( void FillStatistic(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
const Descriptor &descriptor, const Descriptor &descriptor,
const Data::ChannelStatistics &stats) { const AnyStats &stats) {
using Type = Statistic::ChartViewType; using Type = Statistic::ChartViewType;
const auto &padding = st::statisticsChartEntryPadding; const auto &padding = st::statisticsChartEntryPadding;
const auto addSkip = [&] { const auto &m = st::boxRowPadding;
Settings::AddSkip(box->verticalLayout(), padding.bottom()); const auto addSkip = [&](not_null<Ui::VerticalLayout*> c) {
Settings::AddDivider(box->verticalLayout()); Settings::AddSkip(c, padding.bottom());
Settings::AddSkip(box->verticalLayout(), padding.top()); Settings::AddDivider(c);
Settings::AddSkip(c, padding.top());
}; };
addSkip(); const auto addChart = [&](
const Data::StatisticalGraph &graphData,
rpl::producer<QString> &&title,
Statistic::ChartViewType type) {
const auto wrap = box->addRow(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
box,
object_ptr<Ui::VerticalLayout>(box)),
{});
ProcessChart( ProcessChart(
descriptor, descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)), wrap,
stats.memberCountGraph, wrap->entity()->add(object_ptr<Statistic::ChartWidget>(box), m),
graphData,
std::move(title),
type);
addSkip(wrap->entity());
};
addSkip(box->verticalLayout());
if (const auto s = stats.channel) {
addChart(
s.memberCountGraph,
tr::lng_chart_title_member_count(), tr::lng_chart_title_member_count(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.joinGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.joinGraph,
tr::lng_chart_title_join(), tr::lng_chart_title_join(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.muteGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.muteGraph,
tr::lng_chart_title_mute(), tr::lng_chart_title_mute(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.viewCountByHourGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.viewCountByHourGraph,
tr::lng_chart_title_view_count_by_hour(), tr::lng_chart_title_view_count_by_hour(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.viewCountBySourceGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.viewCountBySourceGraph,
tr::lng_chart_title_view_count_by_source(), tr::lng_chart_title_view_count_by_source(),
Type::Stack); Type::Stack);
addSkip(); addChart(
ProcessChart( s.joinBySourceGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.joinBySourceGraph,
tr::lng_chart_title_join_by_source(), tr::lng_chart_title_join_by_source(),
Type::Stack); Type::Stack);
addSkip(); addChart(
ProcessChart( s.languageGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.languageGraph,
tr::lng_chart_title_language(), tr::lng_chart_title_language(),
Type::StackLinear); Type::StackLinear);
addSkip(); addChart(
ProcessChart( s.messageInteractionGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.messageInteractionGraph,
tr::lng_chart_title_message_interaction(), tr::lng_chart_title_message_interaction(),
Type::DoubleLinear); Type::DoubleLinear);
addSkip(); addChart(
ProcessChart( s.instantViewInteractionGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.instantViewInteractionGraph,
tr::lng_chart_title_instant_view_interaction(), tr::lng_chart_title_instant_view_interaction(),
Type::DoubleLinear); Type::DoubleLinear);
addSkip(); } else if (const auto s = stats.supergroup) {
} addChart(
s.memberCountGraph,
void FillSupergroupStatistic(
not_null<Ui::GenericBox*> 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<Statistic::ChartWidget>(box)),
stats.memberCountGraph,
tr::lng_chart_title_member_count(), tr::lng_chart_title_member_count(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.joinGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.joinGraph,
tr::lng_chart_title_group_join(), tr::lng_chart_title_group_join(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.joinBySourceGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.joinBySourceGraph,
tr::lng_chart_title_group_join_by_source(), tr::lng_chart_title_group_join_by_source(),
Type::Stack); Type::Stack);
addSkip(); addChart(
ProcessChart( s.languageGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.languageGraph,
tr::lng_chart_title_group_language(), tr::lng_chart_title_group_language(),
Type::StackLinear); Type::StackLinear);
addSkip(); addChart(
ProcessChart( s.messageContentGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.messageContentGraph,
tr::lng_chart_title_group_message_content(), tr::lng_chart_title_group_message_content(),
Type::Stack); Type::Stack);
addSkip(); addChart(
ProcessChart( s.actionGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.actionGraph,
tr::lng_chart_title_group_action(), tr::lng_chart_title_group_action(),
Type::DoubleLinear); Type::DoubleLinear);
addSkip(); addChart(
ProcessChart( s.dayGraph,
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.dayGraph,
tr::lng_chart_title_group_day(), tr::lng_chart_title_group_day(),
Type::Linear); Type::Linear);
addSkip(); // addChart(
// ProcessChart( // s.weekGraph,
// descriptor,
// box->addRow(object_ptr<Statistic::ChartWidget>(box)),
// stats.weekGraph,
// tr::lng_chart_title_group_week(), // tr::lng_chart_title_group_week(),
// Type::StackLinear); // Type::StackLinear);
// addSkip(); }
} }
void FillLoading( void FillLoading(
@ -277,13 +243,11 @@ void FillLoading(
Settings::AddSkip(content, st::settingsBlockedListIconPadding.top()); Settings::AddSkip(content, st::settingsBlockedListIconPadding.top());
} }
void FillOverview( void FillOverview(not_null<Ui::GenericBox*> box, const AnyStats &stats) {
not_null<Ui::GenericBox*> box,
const Descriptor &descriptor,
const Data::ChannelStatistics &channel,
const Data::SupergroupStatistics &supergroup) {
using Value = Data::StatisticalValue; using Value = Data::StatisticalValue;
const auto &channel = stats.channel;
const auto &supergroup = stats.supergroup;
const auto startDate = channel ? channel.startDate : supergroup.startDate; const auto startDate = channel ? channel.startDate : supergroup.startDate;
const auto endDate = channel ? channel.endDate : supergroup.endDate; const auto endDate = channel ? channel.endDate : supergroup.endDate;
@ -357,7 +321,7 @@ void FillOverview(
}; };
auto height = 0; auto height = 0;
if (const auto s = channel; s) { if (const auto &s = channel) {
const auto memberCount = addPrimary(s.memberCount); const auto memberCount = addPrimary(s.memberCount);
const auto enabledNotifications = Ui::CreateChild<Ui::FlatLabel>( const auto enabledNotifications = Ui::CreateChild<Ui::FlatLabel>(
container, container,
@ -393,7 +357,7 @@ void FillOverview(
}, container->lifetime()); }, container->lifetime());
height = memberCount->height() * 5; height = memberCount->height() * 5;
} else if (const auto s = supergroup; s) { } else if (const auto &s = supergroup) {
const auto memberCount = addPrimary(s.memberCount); const auto memberCount = addPrimary(s.memberCount);
const auto messageCount = addPrimary(s.messageCount); const auto messageCount = addPrimary(s.messageCount);
const auto viewerCount = addPrimary(s.viewerCount); const auto viewerCount = addPrimary(s.viewerCount);
@ -449,15 +413,15 @@ void StatisticsBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
descriptor.api->request( descriptor.api->request(
descriptor.peer descriptor.peer
) | rpl::start_with_done([=] { ) | rpl::start_with_done([=] {
if (const auto stats = descriptor.api->supergroupStats(); stats) { const auto anyStats = AnyStats{
FillOverview(box, descriptor, {}, stats); descriptor.api->channelStats(),
FillSupergroupStatistic(box, descriptor, stats); descriptor.api->supergroupStats(),
} else if (const auto stats = descriptor.api->channelStats(); stats) { };
FillOverview(box, descriptor, stats, {}); if (!anyStats.channel && !anyStats.supergroup) {
FillChannelStatistic(box, descriptor, stats);
} else {
return; return;
} }
FillOverview(box, anyStats);
FillStatistic(box, descriptor, anyStats);
loaded->fire(true); loaded->fire(true);
box->verticalLayout()->resizeToWidth(box->width()); box->verticalLayout()->resizeToWidth(box->width());
box->showChildren(); box->showChildren();