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 = [&](
ProcessChart( const Data::StatisticalGraph &graphData,
descriptor, rpl::producer<QString> &&title,
box->addRow(object_ptr<Statistic::ChartWidget>(box)), Statistic::ChartViewType type) {
stats.memberCountGraph, const auto wrap = box->addRow(
tr::lng_chart_title_member_count(), object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
Type::Linear); box,
addSkip(); object_ptr<Ui::VerticalLayout>(box)),
ProcessChart( {});
descriptor, ProcessChart(
box->addRow(object_ptr<Statistic::ChartWidget>(box)), descriptor,
stats.joinGraph, wrap,
tr::lng_chart_title_join(), wrap->entity()->add(object_ptr<Statistic::ChartWidget>(box), m),
Type::Linear); graphData,
addSkip(); std::move(title),
ProcessChart( type);
descriptor, addSkip(wrap->entity());
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.muteGraph,
tr::lng_chart_title_mute(),
Type::Linear);
addSkip();
ProcessChart(
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.viewCountByHourGraph,
tr::lng_chart_title_view_count_by_hour(),
Type::Linear);
addSkip();
ProcessChart(
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.viewCountBySourceGraph,
tr::lng_chart_title_view_count_by_source(),
Type::Stack);
addSkip();
ProcessChart(
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.joinBySourceGraph,
tr::lng_chart_title_join_by_source(),
Type::Stack);
addSkip();
ProcessChart(
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.languageGraph,
tr::lng_chart_title_language(),
Type::StackLinear);
addSkip();
ProcessChart(
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.messageInteractionGraph,
tr::lng_chart_title_message_interaction(),
Type::DoubleLinear);
addSkip();
ProcessChart(
descriptor,
box->addRow(object_ptr<Statistic::ChartWidget>(box)),
stats.instantViewInteractionGraph,
tr::lng_chart_title_instant_view_interaction(),
Type::DoubleLinear);
addSkip();
}
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(); addSkip(box->verticalLayout());
ProcessChart( if (const auto s = stats.channel) {
descriptor, addChart(
box->addRow(object_ptr<Statistic::ChartWidget>(box)), s.memberCountGraph,
stats.memberCountGraph, tr::lng_chart_title_member_count(),
tr::lng_chart_title_member_count(), Type::Linear);
Type::Linear); addChart(
addSkip(); s.joinGraph,
ProcessChart( tr::lng_chart_title_join(),
descriptor, Type::Linear);
box->addRow(object_ptr<Statistic::ChartWidget>(box)), addChart(
stats.joinGraph, s.muteGraph,
tr::lng_chart_title_group_join(), tr::lng_chart_title_mute(),
Type::Linear); Type::Linear);
addSkip(); addChart(
ProcessChart( s.viewCountByHourGraph,
descriptor, tr::lng_chart_title_view_count_by_hour(),
box->addRow(object_ptr<Statistic::ChartWidget>(box)), Type::Linear);
stats.joinBySourceGraph, addChart(
tr::lng_chart_title_group_join_by_source(), s.viewCountBySourceGraph,
Type::Stack); tr::lng_chart_title_view_count_by_source(),
addSkip(); Type::Stack);
ProcessChart( addChart(
descriptor, s.joinBySourceGraph,
box->addRow(object_ptr<Statistic::ChartWidget>(box)), tr::lng_chart_title_join_by_source(),
stats.languageGraph, Type::Stack);
tr::lng_chart_title_group_language(), addChart(
Type::StackLinear); s.languageGraph,
addSkip(); tr::lng_chart_title_language(),
ProcessChart( Type::StackLinear);
descriptor, addChart(
box->addRow(object_ptr<Statistic::ChartWidget>(box)), s.messageInteractionGraph,
stats.messageContentGraph, tr::lng_chart_title_message_interaction(),
tr::lng_chart_title_group_message_content(), Type::DoubleLinear);
Type::Stack); addChart(
addSkip(); s.instantViewInteractionGraph,
ProcessChart( tr::lng_chart_title_instant_view_interaction(),
descriptor, Type::DoubleLinear);
box->addRow(object_ptr<Statistic::ChartWidget>(box)), } else if (const auto s = stats.supergroup) {
stats.actionGraph, addChart(
tr::lng_chart_title_group_action(), s.memberCountGraph,
Type::DoubleLinear); tr::lng_chart_title_member_count(),
addSkip(); Type::Linear);
ProcessChart( addChart(
descriptor, s.joinGraph,
box->addRow(object_ptr<Statistic::ChartWidget>(box)), tr::lng_chart_title_group_join(),
stats.dayGraph, Type::Linear);
tr::lng_chart_title_group_day(), addChart(
Type::Linear); s.joinBySourceGraph,
addSkip(); tr::lng_chart_title_group_join_by_source(),
// ProcessChart( Type::Stack);
// descriptor, addChart(
// box->addRow(object_ptr<Statistic::ChartWidget>(box)), s.languageGraph,
// stats.weekGraph, tr::lng_chart_title_group_language(),
// tr::lng_chart_title_group_week(), Type::StackLinear);
// Type::StackLinear); addChart(
// addSkip(); s.messageContentGraph,
tr::lng_chart_title_group_message_content(),
Type::Stack);
addChart(
s.actionGraph,
tr::lng_chart_title_group_action(),
Type::DoubleLinear);
addChart(
s.dayGraph,
tr::lng_chart_title_group_day(),
Type::Linear);
// addChart(
// s.weekGraph,
// tr::lng_chart_title_group_week(),
// Type::StackLinear);
}
} }
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();