Added support of weekly range of days to chart views.

This commit is contained in:
23rd 2023-10-11 07:03:49 +03:00 committed by John Preston
parent 0dec803177
commit c9c82446cb
5 changed files with 41 additions and 11 deletions

View File

@ -64,6 +64,7 @@ struct StatisticalChart {
bool isFooterHidden = false;
bool hasPercentages = false;
bool weekFormat = false;
};

View File

@ -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,

View File

@ -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)

View File

@ -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));
}

View File

@ -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();