mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fixed text overlap on y-axis captions when mouse drag is really fast.
This commit is contained in:
parent
658db59aaf
commit
32df03f08d
3 changed files with 27 additions and 8 deletions
|
@ -103,7 +103,7 @@ void PaintBottomLine(
|
||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
int fullWidth,
|
int fullWidth,
|
||||||
int y) {
|
int y) {
|
||||||
p.setFont(st::statisticsDetailsPopupStyle.font);
|
p.setFont(st::statisticsDetailsBottomCaptionStyle.font);
|
||||||
|
|
||||||
const auto startXIndex = chartData.findStartIndex(
|
const auto startXIndex = chartData.findStartIndex(
|
||||||
xPercentageLimits.min);
|
xPercentageLimits.min);
|
||||||
|
@ -111,7 +111,9 @@ void PaintBottomLine(
|
||||||
startXIndex,
|
startXIndex,
|
||||||
xPercentageLimits.max);
|
xPercentageLimits.max);
|
||||||
|
|
||||||
for (const auto &date : dates) {
|
for (auto k = 0; k < dates.size(); k++) {
|
||||||
|
const auto &date = dates[k];
|
||||||
|
const auto isLast = (k == dates.size() - 1);
|
||||||
const auto resultAlpha = date.alpha;
|
const auto resultAlpha = date.alpha;
|
||||||
const auto step = std::max(date.step, 1);
|
const auto step = std::max(date.step, 1);
|
||||||
|
|
||||||
|
@ -127,6 +129,13 @@ void PaintBottomLine(
|
||||||
|
|
||||||
const auto offset = fullWidth * xPercentageLimits.min;
|
const auto offset = fullWidth * xPercentageLimits.min;
|
||||||
|
|
||||||
|
// 30 ms / 200 ms = 0.15.
|
||||||
|
constexpr auto kFastAlphaSpeed = 0.85;
|
||||||
|
const auto hasFastAlpha = (date.stepRaw < dates.back().stepMinFast);
|
||||||
|
const auto fastAlpha = isLast
|
||||||
|
? 1.
|
||||||
|
: std::max(resultAlpha - kFastAlphaSpeed, 0.);
|
||||||
|
|
||||||
for (auto i = start; i < end; i += step) {
|
for (auto i = start; i < end; i += step) {
|
||||||
if ((i < 0) || (i >= (chartData.x.size() - 1))) {
|
if ((i < 0) || (i >= (chartData.x.size() - 1))) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -134,7 +143,7 @@ void PaintBottomLine(
|
||||||
const auto xPercentage = (chartData.x[i] - chartData.x.front())
|
const auto xPercentage = (chartData.x[i] - chartData.x.front())
|
||||||
/ (chartData.x.back() - chartData.x.front());
|
/ (chartData.x.back() - chartData.x.front());
|
||||||
const auto xPoint = xPercentage * fullWidth - offset;
|
const auto xPoint = xPercentage * fullWidth - offset;
|
||||||
p.setOpacity(resultAlpha);
|
p.setOpacity(hasFastAlpha ? fastAlpha : resultAlpha);
|
||||||
p.drawText(xPoint, y, chartData.getDayString(i));
|
p.drawText(xPoint, y, chartData.getDayString(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,12 +657,12 @@ void ChartWidget::updateBottomDates() {
|
||||||
}
|
}
|
||||||
const auto d = _bottomLine.chartFullWidth * _chartData.oneDayPercentage;
|
const auto d = _bottomLine.chartFullWidth * _chartData.oneDayPercentage;
|
||||||
const auto k = _chartArea->width() / d;
|
const auto k = _chartArea->width() / d;
|
||||||
const auto tempStep = int(k / 6);
|
const auto stepRaw = int(k / 6);
|
||||||
|
|
||||||
const auto isCurrentNull = (_bottomLine.current.stepMinFast == 0);
|
const auto isCurrentNull = (_bottomLine.current.stepMinFast == 0);
|
||||||
if (!isCurrentNull
|
if (!isCurrentNull
|
||||||
&& (tempStep < _bottomLine.current.stepMax)
|
&& (stepRaw < _bottomLine.current.stepMax)
|
||||||
&& (tempStep > _bottomLine.current.stepMin)) {
|
&& (stepRaw > _bottomLine.current.stepMin)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto highestOneBit = [](unsigned int v) {
|
const auto highestOneBit = [](unsigned int v) {
|
||||||
|
@ -667,19 +676,23 @@ void ChartWidget::updateBottomDates() {
|
||||||
}
|
}
|
||||||
return int(r);
|
return int(r);
|
||||||
};
|
};
|
||||||
const auto step = highestOneBit(tempStep) << 1;
|
const auto step = highestOneBit(stepRaw) << 1;
|
||||||
if (!isCurrentNull && (_bottomLine.current.step == step)) {
|
if (!isCurrentNull && (_bottomLine.current.step == step)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto kStepRatio = 0.2;
|
constexpr auto kStepRatio = 0.1;
|
||||||
|
constexpr auto kFastStepOffset = 4;
|
||||||
const auto stepMax = int(step + step * kStepRatio);
|
const auto stepMax = int(step + step * kStepRatio);
|
||||||
const auto stepMin = int(step - step * kStepRatio);
|
const auto stepMin = int(step - step * kStepRatio);
|
||||||
|
const auto stepMinFast = stepMin - kFastStepOffset;
|
||||||
|
|
||||||
auto data = BottomCaptionLineData{
|
auto data = BottomCaptionLineData{
|
||||||
.step = step,
|
.step = step,
|
||||||
.stepMax = stepMax,
|
.stepMax = stepMax,
|
||||||
.stepMin = stepMin,
|
.stepMin = stepMin,
|
||||||
|
.stepMinFast = stepMinFast,
|
||||||
|
.stepRaw = stepRaw,
|
||||||
.alpha = 1.,
|
.alpha = 1.,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ public:
|
||||||
int step = 0;
|
int step = 0;
|
||||||
int stepMax = 0;
|
int stepMax = 0;
|
||||||
int stepMin = 0;
|
int stepMin = 0;
|
||||||
|
int stepMinFast = 0;
|
||||||
|
int stepRaw = 0;
|
||||||
|
|
||||||
float64 alpha = 0.;
|
float64 alpha = 0.;
|
||||||
float64 fixedAlpha = 0.;
|
float64 fixedAlpha = 0.;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,3 +23,6 @@ statisticsChartBottomCaptionSkip: 15px;
|
||||||
statisticsDetailsPopupStyle: TextStyle(defaultTextStyle) {
|
statisticsDetailsPopupStyle: TextStyle(defaultTextStyle) {
|
||||||
font: font(11px);
|
font: font(11px);
|
||||||
}
|
}
|
||||||
|
statisticsDetailsBottomCaptionStyle: TextStyle(defaultTextStyle) {
|
||||||
|
font: font(10px);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue