diff --git a/Telegram/SourceFiles/data/data_statistics_chart.h b/Telegram/SourceFiles/data/data_statistics_chart.h index 5eebf0e07..9fd644cd7 100644 --- a/Telegram/SourceFiles/data/data_statistics_chart.h +++ b/Telegram/SourceFiles/data/data_statistics_chart.h @@ -64,6 +64,7 @@ struct StatisticalChart { bool isFooterHidden = false; bool hasPercentages = false; + bool weekFormat = false; }; diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index 88e484dab..2669f196c 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -200,10 +200,10 @@ void FillStatistic( stats.supergroup.dayGraph, tr::lng_chart_title_group_day(), Type::Linear); - // addChart( - // stats.supergroup.weekGraph, - // tr::lng_chart_title_group_week(), - // Type::StackLinear); + addChart( + stats.supergroup.weekGraph, + tr::lng_chart_title_group_week(), + Type::StackLinear); } else if (stats.message) { addChart( stats.message.messageInteractionGraph, diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 333408379..72f6e0cb1 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -76,11 +76,13 @@ void FillLineColorsByKey(Data::StatisticalChart &chartData) { const auto leftDateTime = QDateTime::fromSecsSinceEpoch( leftTimestamp / 1000); const auto leftText = QLocale().toString(leftDateTime.date(), formatter); - if (xIndexMin == xIndexMax) { + if ((xIndexMin == xIndexMax) && !chartData.weekFormat) { return leftText; } else { - const auto rightDateTime = QDateTime::fromSecsSinceEpoch( - chartData.x[xIndexMax] / 1000); + constexpr auto kSevenDays = 3600 * 24 * 7; + const auto rightDateTime = QDateTime::fromSecsSinceEpoch(0 + + (chartData.x[xIndexMax] / 1000) + + (chartData.weekFormat ? kSevenDays : 0)); return leftText + ' ' + QChar(8212) diff --git a/Telegram/SourceFiles/statistics/point_details_widget.cpp b/Telegram/SourceFiles/statistics/point_details_widget.cpp index 305d31b6b..c9431f965 100644 --- a/Telegram/SourceFiles/statistics/point_details_widget.cpp +++ b/Telegram/SourceFiles/statistics/point_details_widget.cpp @@ -33,6 +33,22 @@ namespace { } } +[[nodiscard]] QString FormatWeek(float64 timestamp) { + constexpr auto kSevenDays = 3600 * 24 * 7; + const auto leftFormatter = u"d MMM"_q; + const auto rightFormatter = u"d MMM yyyy"_q; + timestamp /= 1000; + return QLocale().toString( + QDateTime::fromSecsSinceEpoch(timestamp).date(), + leftFormatter) + + ' ' + + QChar(8212) + + ' ' + + QLocale().toString( + QDateTime::fromSecsSinceEpoch(timestamp + kSevenDays).date(), + rightFormatter); +} + void PaintShadow(QPainter &p, int radius, const QRect &r) { constexpr auto kHorizontalOffset = 1; constexpr auto kHorizontalOffset2 = 2; @@ -185,10 +201,12 @@ PointDetailsWidget::PointDetailsWidget( { const auto maxHeaderText = Ui::Text::String( _headerStyle, - FormatTimestamp( - _chartData.x.front(), - _longFormat, - _shortFormat)); + _chartData.weekFormat + ? FormatWeek(_chartData.x.front()) + : FormatTimestamp( + _chartData.x.front(), + _longFormat, + _shortFormat)); maxNameTextWidth = std::max( maxHeaderText.maxWidth() + st::statisticsDetailsPopupPadding.left(), @@ -252,6 +270,8 @@ void PointDetailsWidget::setXIndex(int xIndex) { _headerStyle, (timestamp < kOneDay) ? _chartData.getDayString(xIndex) + : _chartData.weekFormat + ? FormatWeek(timestamp) : FormatTimestamp(timestamp, _longFormat, _shortFormat)); } diff --git a/Telegram/SourceFiles/statistics/statistics_data_deserialize.cpp b/Telegram/SourceFiles/statistics/statistics_data_deserialize.cpp index 96234faf5..09fb3aa93 100644 --- a/Telegram/SourceFiles/statistics/statistics_data_deserialize.cpp +++ b/Telegram/SourceFiles/statistics/statistics_data_deserialize.cpp @@ -125,6 +125,13 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) { } } } + { + const auto tooltipFormatIt = root.constFind(u"xTooltipFormatter"_q); + if (tooltipFormatIt != root.constEnd()) { + const auto tooltipFormat = tooltipFormatIt->toString(); + result.weekFormat = tooltipFormat.contains(u"'week'"_q); + } + } const auto colors = root.value(u"colors"_q).toObject(); const auto names = root.value(u"names"_q).toObject();