mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Slightly improved format of dates on charts.
This commit is contained in:
parent
c20bd17029
commit
6109ec70b8
4 changed files with 39 additions and 18 deletions
|
@ -43,7 +43,7 @@ void StatisticalChart::measure() {
|
|||
const auto dateCount = int((end - start) / timeStep) + 10;
|
||||
daysLookup.reserve(dateCount);
|
||||
constexpr auto kOneDay = 3600 * 24 * 1000;
|
||||
const auto formatter = u"MMM d"_q;
|
||||
const auto formatter = u"d MMM"_q;
|
||||
for (auto i = 0; i < dateCount; i++) {
|
||||
const auto r = (start + (i * timeStep)) / 1000;
|
||||
const auto dateTime = QDateTime::fromSecsSinceEpoch(r);
|
||||
|
|
|
@ -268,7 +268,7 @@ void FillOverview(
|
|||
st::statisticsLayerMargins + st::statisticsChartHeaderPadding);
|
||||
header->resizeToWidth(header->width());
|
||||
header->setTitle(tr::lng_stats_overview_title(tr::now));
|
||||
const auto formatter = u"MMM d"_q;
|
||||
const auto formatter = u"d MMM yyyy"_q;
|
||||
const auto from = QDateTime::fromSecsSinceEpoch(startDate);
|
||||
const auto to = QDateTime::fromSecsSinceEpoch(endDate);
|
||||
header->setRightInfo(QLocale().toString(from.date(), formatter)
|
||||
|
|
|
@ -65,14 +65,28 @@ void FillLineColorsByKey(Data::StatisticalChart &chartData) {
|
|||
|
||||
[[nodiscard]] QString HeaderRightInfo(
|
||||
const Data::StatisticalChart &chartData,
|
||||
const Limits &limits) {
|
||||
return (limits.min == limits.max)
|
||||
? chartData.getDayString(limits.min)
|
||||
: chartData.getDayString(limits.min)
|
||||
int xIndexMin,
|
||||
int xIndexMax) {
|
||||
constexpr auto kOneDay = 3600 * 24 * 1000;
|
||||
const auto leftTimestamp = chartData.x[xIndexMin];
|
||||
if (leftTimestamp < kOneDay) {
|
||||
return {};
|
||||
}
|
||||
const auto formatter = u"d MMM yyyy"_q;
|
||||
const auto leftDateTime = QDateTime::fromSecsSinceEpoch(
|
||||
leftTimestamp / 1000);
|
||||
const auto leftText = QLocale().toString(leftDateTime.date(), formatter);
|
||||
if (xIndexMin == xIndexMax) {
|
||||
return leftText;
|
||||
} else {
|
||||
const auto rightDateTime = QDateTime::fromSecsSinceEpoch(
|
||||
chartData.x[xIndexMax] / 1000);
|
||||
return leftText
|
||||
+ ' '
|
||||
+ QChar(8212)
|
||||
+ ' '
|
||||
+ chartData.getDayString(limits.max);
|
||||
+ QLocale().toString(rightDateTime.date(), formatter);
|
||||
}
|
||||
}
|
||||
|
||||
void PaintBottomLine(
|
||||
|
@ -1057,8 +1071,8 @@ void ChartWidget::updateHeader() {
|
|||
if (!_chartData) {
|
||||
return;
|
||||
}
|
||||
const auto indices = _animationController.currentXIndices();
|
||||
_header->setRightInfo(HeaderRightInfo(_chartData, indices));
|
||||
const auto i = _animationController.currentXIndices();
|
||||
_header->setRightInfo(HeaderRightInfo(_chartData, i.min, i.max));
|
||||
_header->update();
|
||||
}
|
||||
|
||||
|
@ -1261,7 +1275,7 @@ void ChartWidget::processLocalZoom(int xIndex) {
|
|||
header->setGeometry(g);
|
||||
}, header->lifetime());
|
||||
header->setTitle(_header->title());
|
||||
header->setRightInfo(_chartData.getDayString(xIndex));
|
||||
header->setRightInfo(HeaderRightInfo(_chartData, xIndex, xIndex));
|
||||
|
||||
const auto enableMouse = [=](bool value) {
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents, !value);
|
||||
|
@ -1332,11 +1346,11 @@ void ChartWidget::processLocalZoom(int xIndex) {
|
|||
createMouseTracking();
|
||||
_footer->xPercentageLimitsChange(
|
||||
) | rpl::start_with_next([=](const Limits &l) {
|
||||
const auto result = FindStackXIndicesFromRawXPercentages(
|
||||
const auto r = FindStackXIndicesFromRawXPercentages(
|
||||
_chartData,
|
||||
l,
|
||||
zoomLimitIndices);
|
||||
header->setRightInfo(HeaderRightInfo(_chartData, result));
|
||||
header->setRightInfo(HeaderRightInfo(_chartData, r.min, r.max));
|
||||
header->update();
|
||||
}, header->lifetime());
|
||||
};
|
||||
|
@ -1468,7 +1482,8 @@ void ChartWidget::setZoomedChartData(
|
|||
ranges::find(_chartData.x, x));
|
||||
customHeader->setTitle(_header->title());
|
||||
if ((xIndex >= 0) && (xIndex < _chartData.x.size())) {
|
||||
customHeader->setRightInfo(_chartData.getDayString(xIndex));
|
||||
customHeader->setRightInfo(
|
||||
HeaderRightInfo(_chartData, xIndex, xIndex));
|
||||
}
|
||||
const auto &headerPadding = st::statisticsChartHeaderPadding;
|
||||
customHeader->moveToLeft(headerPadding.left(), headerPadding.top());
|
||||
|
|
|
@ -127,8 +127,8 @@ PointDetailsWidget::PointDetailsWidget(
|
|||
, _chartData(chartData)
|
||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
||||
, _longFormat(u"ddd, MMM d hh:mm"_q)
|
||||
, _shortFormat(u"ddd, MMM d"_q) {
|
||||
, _longFormat(u"ddd, d MMM hh:mm"_q)
|
||||
, _shortFormat(u"ddd, d MMM yyyy"_q) {
|
||||
|
||||
if (zoomEnabled) {
|
||||
rpl::single(rpl::empty_value()) | rpl::then(
|
||||
|
@ -232,9 +232,15 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
|||
if (xIndex < 0) {
|
||||
return;
|
||||
}
|
||||
_header.setText(
|
||||
_headerStyle,
|
||||
FormatTimestamp(_chartData.x[xIndex], _longFormat, _shortFormat));
|
||||
{
|
||||
constexpr auto kOneDay = 3600 * 24 * 1000;
|
||||
const auto timestamp = _chartData.x[xIndex];
|
||||
_header.setText(
|
||||
_headerStyle,
|
||||
(timestamp < kOneDay)
|
||||
? _chartData.getDayString(xIndex)
|
||||
: FormatTimestamp(timestamp, _longFormat, _shortFormat));
|
||||
}
|
||||
|
||||
_lines.clear();
|
||||
_lines.reserve(_chartData.lines.size());
|
||||
|
|
Loading…
Add table
Reference in a new issue