mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of weekly range of days to chart views.
This commit is contained in:
parent
0dec803177
commit
c9c82446cb
5 changed files with 41 additions and 11 deletions
|
@ -64,6 +64,7 @@ struct StatisticalChart {
|
||||||
|
|
||||||
bool isFooterHidden = false;
|
bool isFooterHidden = false;
|
||||||
bool hasPercentages = false;
|
bool hasPercentages = false;
|
||||||
|
bool weekFormat = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -200,10 +200,10 @@ void FillStatistic(
|
||||||
stats.supergroup.dayGraph,
|
stats.supergroup.dayGraph,
|
||||||
tr::lng_chart_title_group_day(),
|
tr::lng_chart_title_group_day(),
|
||||||
Type::Linear);
|
Type::Linear);
|
||||||
// addChart(
|
addChart(
|
||||||
// stats.supergroup.weekGraph,
|
stats.supergroup.weekGraph,
|
||||||
// tr::lng_chart_title_group_week(),
|
tr::lng_chart_title_group_week(),
|
||||||
// Type::StackLinear);
|
Type::StackLinear);
|
||||||
} else if (stats.message) {
|
} else if (stats.message) {
|
||||||
addChart(
|
addChart(
|
||||||
stats.message.messageInteractionGraph,
|
stats.message.messageInteractionGraph,
|
||||||
|
|
|
@ -76,11 +76,13 @@ void FillLineColorsByKey(Data::StatisticalChart &chartData) {
|
||||||
const auto leftDateTime = QDateTime::fromSecsSinceEpoch(
|
const auto leftDateTime = QDateTime::fromSecsSinceEpoch(
|
||||||
leftTimestamp / 1000);
|
leftTimestamp / 1000);
|
||||||
const auto leftText = QLocale().toString(leftDateTime.date(), formatter);
|
const auto leftText = QLocale().toString(leftDateTime.date(), formatter);
|
||||||
if (xIndexMin == xIndexMax) {
|
if ((xIndexMin == xIndexMax) && !chartData.weekFormat) {
|
||||||
return leftText;
|
return leftText;
|
||||||
} else {
|
} else {
|
||||||
const auto rightDateTime = QDateTime::fromSecsSinceEpoch(
|
constexpr auto kSevenDays = 3600 * 24 * 7;
|
||||||
chartData.x[xIndexMax] / 1000);
|
const auto rightDateTime = QDateTime::fromSecsSinceEpoch(0
|
||||||
|
+ (chartData.x[xIndexMax] / 1000)
|
||||||
|
+ (chartData.weekFormat ? kSevenDays : 0));
|
||||||
return leftText
|
return leftText
|
||||||
+ ' '
|
+ ' '
|
||||||
+ QChar(8212)
|
+ QChar(8212)
|
||||||
|
|
|
@ -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) {
|
void PaintShadow(QPainter &p, int radius, const QRect &r) {
|
||||||
constexpr auto kHorizontalOffset = 1;
|
constexpr auto kHorizontalOffset = 1;
|
||||||
constexpr auto kHorizontalOffset2 = 2;
|
constexpr auto kHorizontalOffset2 = 2;
|
||||||
|
@ -185,10 +201,12 @@ PointDetailsWidget::PointDetailsWidget(
|
||||||
{
|
{
|
||||||
const auto maxHeaderText = Ui::Text::String(
|
const auto maxHeaderText = Ui::Text::String(
|
||||||
_headerStyle,
|
_headerStyle,
|
||||||
FormatTimestamp(
|
_chartData.weekFormat
|
||||||
_chartData.x.front(),
|
? FormatWeek(_chartData.x.front())
|
||||||
_longFormat,
|
: FormatTimestamp(
|
||||||
_shortFormat));
|
_chartData.x.front(),
|
||||||
|
_longFormat,
|
||||||
|
_shortFormat));
|
||||||
maxNameTextWidth = std::max(
|
maxNameTextWidth = std::max(
|
||||||
maxHeaderText.maxWidth()
|
maxHeaderText.maxWidth()
|
||||||
+ st::statisticsDetailsPopupPadding.left(),
|
+ st::statisticsDetailsPopupPadding.left(),
|
||||||
|
@ -252,6 +270,8 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
||||||
_headerStyle,
|
_headerStyle,
|
||||||
(timestamp < kOneDay)
|
(timestamp < kOneDay)
|
||||||
? _chartData.getDayString(xIndex)
|
? _chartData.getDayString(xIndex)
|
||||||
|
: _chartData.weekFormat
|
||||||
|
? FormatWeek(timestamp)
|
||||||
: FormatTimestamp(timestamp, _longFormat, _shortFormat));
|
: FormatTimestamp(timestamp, _longFormat, _shortFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 colors = root.value(u"colors"_q).toObject();
|
||||||
const auto names = root.value(u"names"_q).toObject();
|
const auto names = root.value(u"names"_q).toObject();
|
||||||
|
|
Loading…
Add table
Reference in a new issue