mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Fixed display of bottom captions in chart view with long date strings.
This commit is contained in:
parent
59099a8d46
commit
1a856e359f
4 changed files with 17 additions and 6 deletions
|
@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_statistics_chart.h"
|
||||
|
||||
#include "statistics/statistics_format_values.h"
|
||||
#include "styles/style_basic.h"
|
||||
#include "styles/style_statistics.h"
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QLocale>
|
||||
|
@ -46,6 +48,11 @@ void StatisticalChart::measure() {
|
|||
const auto dateCount = int((end - start) / timeStep) + 10;
|
||||
daysLookup.reserve(dateCount);
|
||||
constexpr auto kOneDay = 3600 * 24 * 1000;
|
||||
|
||||
// View data.
|
||||
auto maxWidth = 0;
|
||||
const auto &defaultFont = st::statisticsDetailsBottomCaptionStyle.font;
|
||||
|
||||
for (auto i = 0; i < dateCount; i++) {
|
||||
const auto r = (start + (i * timeStep)) / 1000;
|
||||
if (timeStep == 1) {
|
||||
|
@ -59,7 +66,9 @@ void StatisticalChart::measure() {
|
|||
} else {
|
||||
daysLookup.push_back(Statistic::LangDayMonth(r));
|
||||
}
|
||||
maxWidth = std::max(maxWidth, defaultFont->width(daysLookup.back()));
|
||||
}
|
||||
dayStringMaxWidth = maxWidth;
|
||||
|
||||
oneDayPercentage = timeStep / float64(end - start);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,9 @@ struct StatisticalChart {
|
|||
bool hasPercentages = false;
|
||||
bool weekFormat = false;
|
||||
|
||||
// View data.
|
||||
int dayStringMaxWidth = 0;
|
||||
|
||||
};
|
||||
|
||||
struct StatisticalGraph final {
|
||||
|
|
|
@ -107,7 +107,8 @@ void PaintBottomLine(
|
|||
startXIndex,
|
||||
xPercentageLimits.max);
|
||||
|
||||
const auto edgeAlphaSize = st::statisticsChartBottomCaptionMaxWidth / 4.;
|
||||
const auto captionMaxWidth = chartData.dayStringMaxWidth;
|
||||
const auto edgeAlphaSize = captionMaxWidth / 4.;
|
||||
|
||||
for (auto k = 0; k < dates.size(); k++) {
|
||||
const auto &date = dates[k];
|
||||
|
@ -145,9 +146,9 @@ void PaintBottomLine(
|
|||
/ float64(chartData.x.back() - chartData.x.front());
|
||||
const auto xPoint = xPercentage * fullWidth - offset;
|
||||
const auto r = QRectF(
|
||||
xPoint - st::statisticsChartBottomCaptionMaxWidth / 2.,
|
||||
xPoint - captionMaxWidth / 2.,
|
||||
y,
|
||||
st::statisticsChartBottomCaptionMaxWidth,
|
||||
captionMaxWidth,
|
||||
st::statisticsChartBottomCaptionHeight);
|
||||
const auto edgeAlpha = (r.x() < 0)
|
||||
? std::max(
|
||||
|
@ -1018,7 +1019,7 @@ void ChartWidget::updateBottomDates() {
|
|||
|
||||
const auto by = int(_chartArea->width() / float64(_chartData.x.size()));
|
||||
_bottomLine.captionIndicesOffset = 0
|
||||
+ st::statisticsChartBottomCaptionMaxWidth / std::max(by, 1);
|
||||
+ _chartData.dayStringMaxWidth / std::max(by, 1);
|
||||
|
||||
const auto isCurrentNull = (_bottomLine.current.stepMinFast == 0);
|
||||
if (!isCurrentNull
|
||||
|
|
|
@ -37,8 +37,6 @@ statisticsChartRulerCaptionSkip: 4px;
|
|||
statisticsChartBottomCaptionHeight: 15px;
|
||||
statisticsChartBottomCaptionSkip: 6px;
|
||||
|
||||
statisticsChartBottomCaptionMaxWidth: 44px;
|
||||
|
||||
statisticsChartFlatCheckboxMargins: margins(4px, 3px, 4px, 5px);
|
||||
statisticsChartFlatCheckboxCheckWidth: 3px;
|
||||
statisticsChartFlatCheckboxShrinkkWidth: 4px;
|
||||
|
|
Loading…
Add table
Reference in a new issue