mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Replace Simple with Basic for animation of chart y-axis captions.
This commit is contained in:
parent
695542cfd2
commit
658db59aaf
2 changed files with 44 additions and 24 deletions
|
@ -382,9 +382,16 @@ void ChartWidget::ChartAnimationController::resetAlpha() {
|
||||||
_animValueYAlpha = anim::value(0., 1.);
|
_animValueYAlpha = anim::value(0., 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChartWidget::ChartAnimationController::restartBottomLineAlpha() {
|
||||||
|
_bottomLineAlphaAnimationStartedAt = crl::now();
|
||||||
|
_animValueBottomLineAlpha = anim::value(0., 1.);
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
void ChartWidget::ChartAnimationController::tick(
|
void ChartWidget::ChartAnimationController::tick(
|
||||||
crl::time now,
|
crl::time now,
|
||||||
std::vector<ChartHorizontalLinesData> &horizontalLines) {
|
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
||||||
|
std::vector<BottomCaptionLineData> &dateLines) {
|
||||||
if (!_animation.animating()) {
|
if (!_animation.animating()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -409,6 +416,9 @@ void ChartWidget::ChartAnimationController::tick(
|
||||||
const auto dtAlpha = std::min(
|
const auto dtAlpha = std::min(
|
||||||
(now - _alphaAnimationStartedAt) / kAlphaExpandingDuration,
|
(now - _alphaAnimationStartedAt) / kAlphaExpandingDuration,
|
||||||
1.);
|
1.);
|
||||||
|
const auto dtBottomLineAlpha = std::min(
|
||||||
|
(now - _bottomLineAlphaAnimationStartedAt) / kAlphaExpandingDuration,
|
||||||
|
1.);
|
||||||
|
|
||||||
const auto isFinished = [](const anim::value &anim) {
|
const auto isFinished = [](const anim::value &anim) {
|
||||||
return anim.current() == anim.to();
|
return anim.current() == anim.to();
|
||||||
|
@ -419,8 +429,10 @@ void ChartWidget::ChartAnimationController::tick(
|
||||||
const auto yFinished = isFinished(_animationValueHeightMin)
|
const auto yFinished = isFinished(_animationValueHeightMin)
|
||||||
&& isFinished(_animationValueHeightMax);
|
&& isFinished(_animationValueHeightMax);
|
||||||
const auto alphaFinished = isFinished(_animValueYAlpha);
|
const auto alphaFinished = isFinished(_animValueYAlpha);
|
||||||
|
const auto bottomLineAlphaFinished = isFinished(
|
||||||
|
_animValueBottomLineAlpha);
|
||||||
|
|
||||||
if (xFinished && yFinished && alphaFinished) {
|
if (xFinished && yFinished && alphaFinished && bottomLineAlphaFinished) {
|
||||||
const auto &lines = horizontalLines.back().lines;
|
const auto &lines = horizontalLines.back().lines;
|
||||||
if ((lines.front().absoluteValue == _animationValueHeightMin.to())
|
if ((lines.front().absoluteValue == _animationValueHeightMin.to())
|
||||||
&& lines.back().absoluteValue == _animationValueHeightMax.to()) {
|
&& lines.back().absoluteValue == _animationValueHeightMax.to()) {
|
||||||
|
@ -434,6 +446,14 @@ void ChartWidget::ChartAnimationController::tick(
|
||||||
_animationValueXMin.update(dtX, anim::linear);
|
_animationValueXMin.update(dtX, anim::linear);
|
||||||
_animationValueXMax.update(dtX, anim::linear);
|
_animationValueXMax.update(dtX, anim::linear);
|
||||||
}
|
}
|
||||||
|
if (bottomLineAlphaFinished) {
|
||||||
|
_animValueBottomLineAlpha.finish();
|
||||||
|
_bottomLineAlphaAnimationStartedAt = 0;
|
||||||
|
} else {
|
||||||
|
_animValueBottomLineAlpha.update(
|
||||||
|
dtBottomLineAlpha,
|
||||||
|
anim::easeInCubic);
|
||||||
|
}
|
||||||
if (_heightAnimationStarted) {
|
if (_heightAnimationStarted) {
|
||||||
_animationValueHeightMin.update(_dtCurrent.min, anim::easeInCubic);
|
_animationValueHeightMin.update(_dtCurrent.min, anim::easeInCubic);
|
||||||
_animationValueHeightMax.update(_dtCurrent.max, anim::easeInCubic);
|
_animationValueHeightMax.update(_dtCurrent.max, anim::easeInCubic);
|
||||||
|
@ -465,6 +485,20 @@ void ChartWidget::ChartAnimationController::tick(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bottomLineAlphaFinished) {
|
||||||
|
const auto value = _animValueBottomLineAlpha.current();
|
||||||
|
for (auto &date : dateLines) {
|
||||||
|
date.alpha = (1. - value) * date.fixedAlpha;
|
||||||
|
}
|
||||||
|
dateLines.back().alpha = value;
|
||||||
|
} else {
|
||||||
|
if (dateLines.size() > 1) {
|
||||||
|
const auto data = dateLines.back();
|
||||||
|
dateLines.clear();
|
||||||
|
dateLines.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (yFinished && alphaFinished) {
|
if (yFinished && alphaFinished) {
|
||||||
_alphaAnimationStartedAt = 0;
|
_alphaAnimationStartedAt = 0;
|
||||||
_heightAnimationStarted = false;
|
_heightAnimationStarted = false;
|
||||||
|
@ -550,7 +584,7 @@ void ChartWidget::setupChartArea() {
|
||||||
|
|
||||||
const auto now = crl::now();
|
const auto now = crl::now();
|
||||||
|
|
||||||
_animationController.tick(now, _horizontalLines);
|
_animationController.tick(now, _horizontalLines, _bottomLine.dates);
|
||||||
|
|
||||||
const auto chartRect = chartAreaRect();
|
const auto chartRect = chartAreaRect();
|
||||||
|
|
||||||
|
@ -638,10 +672,6 @@ void ChartWidget::updateBottomDates() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_bottomLine.animation.animating()) {
|
|
||||||
_bottomLine.animation.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto kStepRatio = 0.2;
|
constexpr auto kStepRatio = 0.2;
|
||||||
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);
|
||||||
|
@ -670,21 +700,7 @@ void ChartWidget::updateBottomDates() {
|
||||||
_bottomLine.dates.erase(begin(_bottomLine.dates));
|
_bottomLine.dates.erase(begin(_bottomLine.dates));
|
||||||
}
|
}
|
||||||
|
|
||||||
_bottomLine.animation.start(
|
_animationController.restartBottomLineAlpha();
|
||||||
[=](float64 value) {
|
|
||||||
for (auto &date : _bottomLine.dates) {
|
|
||||||
date.alpha = (1. - value) * date.fixedAlpha;
|
|
||||||
}
|
|
||||||
_bottomLine.dates.back().alpha = value;
|
|
||||||
if (value >= 1.) {
|
|
||||||
_bottomLine.dates.clear();
|
|
||||||
_bottomLine.dates.push_back(data);
|
|
||||||
}
|
|
||||||
_chartArea->update();
|
|
||||||
},
|
|
||||||
0.,
|
|
||||||
1.,
|
|
||||||
200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartWidget::setupFooter() {
|
void ChartWidget::setupFooter() {
|
||||||
|
|
|
@ -48,9 +48,11 @@ private:
|
||||||
void start();
|
void start();
|
||||||
void finish();
|
void finish();
|
||||||
void resetAlpha();
|
void resetAlpha();
|
||||||
|
void restartBottomLineAlpha();
|
||||||
void tick(
|
void tick(
|
||||||
crl::time now,
|
crl::time now,
|
||||||
std::vector<ChartHorizontalLinesData> &horizontalLines);
|
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
||||||
|
std::vector<BottomCaptionLineData> &dateLines);
|
||||||
|
|
||||||
[[nodiscard]] Limits currentXLimits() const;
|
[[nodiscard]] Limits currentXLimits() const;
|
||||||
[[nodiscard]] Limits finalXLimits() const;
|
[[nodiscard]] Limits finalXLimits() const;
|
||||||
|
@ -66,6 +68,7 @@ private:
|
||||||
|
|
||||||
crl::time _lastUserInteracted = 0;
|
crl::time _lastUserInteracted = 0;
|
||||||
crl::time _alphaAnimationStartedAt = 0;
|
crl::time _alphaAnimationStartedAt = 0;
|
||||||
|
crl::time _bottomLineAlphaAnimationStartedAt = 0;
|
||||||
bool _heightAnimationStarted = false;
|
bool _heightAnimationStarted = false;
|
||||||
|
|
||||||
anim::value _animationValueXMin;
|
anim::value _animationValueXMin;
|
||||||
|
@ -75,6 +78,8 @@ private:
|
||||||
|
|
||||||
anim::value _animValueYAlpha;
|
anim::value _animValueYAlpha;
|
||||||
|
|
||||||
|
anim::value _animValueBottomLineAlpha;
|
||||||
|
|
||||||
Limits _finalHeightLimits;
|
Limits _finalHeightLimits;
|
||||||
|
|
||||||
float _dtHeightSpeed = 0.;
|
float _dtHeightSpeed = 0.;
|
||||||
|
@ -104,7 +109,6 @@ private:
|
||||||
struct {
|
struct {
|
||||||
BottomCaptionLineData current;
|
BottomCaptionLineData current;
|
||||||
std::vector<BottomCaptionLineData> dates;
|
std::vector<BottomCaptionLineData> dates;
|
||||||
Ui::Animations::Simple animation;
|
|
||||||
int chartFullWidth = 0;
|
int chartFullWidth = 0;
|
||||||
} _bottomLine;
|
} _bottomLine;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue