Replace Simple with Basic for animation of chart y-axis captions.
This commit is contained in:
parent
695542cfd2
commit
658db59aaf
|
@ -382,9 +382,16 @@ void ChartWidget::ChartAnimationController::resetAlpha() {
|
|||
_animValueYAlpha = anim::value(0., 1.);
|
||||
}
|
||||
|
||||
void ChartWidget::ChartAnimationController::restartBottomLineAlpha() {
|
||||
_bottomLineAlphaAnimationStartedAt = crl::now();
|
||||
_animValueBottomLineAlpha = anim::value(0., 1.);
|
||||
start();
|
||||
}
|
||||
|
||||
void ChartWidget::ChartAnimationController::tick(
|
||||
crl::time now,
|
||||
std::vector<ChartHorizontalLinesData> &horizontalLines) {
|
||||
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
||||
std::vector<BottomCaptionLineData> &dateLines) {
|
||||
if (!_animation.animating()) {
|
||||
return;
|
||||
}
|
||||
|
@ -409,6 +416,9 @@ void ChartWidget::ChartAnimationController::tick(
|
|||
const auto dtAlpha = std::min(
|
||||
(now - _alphaAnimationStartedAt) / kAlphaExpandingDuration,
|
||||
1.);
|
||||
const auto dtBottomLineAlpha = std::min(
|
||||
(now - _bottomLineAlphaAnimationStartedAt) / kAlphaExpandingDuration,
|
||||
1.);
|
||||
|
||||
const auto isFinished = [](const anim::value &anim) {
|
||||
return anim.current() == anim.to();
|
||||
|
@ -419,8 +429,10 @@ void ChartWidget::ChartAnimationController::tick(
|
|||
const auto yFinished = isFinished(_animationValueHeightMin)
|
||||
&& isFinished(_animationValueHeightMax);
|
||||
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;
|
||||
if ((lines.front().absoluteValue == _animationValueHeightMin.to())
|
||||
&& lines.back().absoluteValue == _animationValueHeightMax.to()) {
|
||||
|
@ -434,6 +446,14 @@ void ChartWidget::ChartAnimationController::tick(
|
|||
_animationValueXMin.update(dtX, anim::linear);
|
||||
_animationValueXMax.update(dtX, anim::linear);
|
||||
}
|
||||
if (bottomLineAlphaFinished) {
|
||||
_animValueBottomLineAlpha.finish();
|
||||
_bottomLineAlphaAnimationStartedAt = 0;
|
||||
} else {
|
||||
_animValueBottomLineAlpha.update(
|
||||
dtBottomLineAlpha,
|
||||
anim::easeInCubic);
|
||||
}
|
||||
if (_heightAnimationStarted) {
|
||||
_animationValueHeightMin.update(_dtCurrent.min, 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) {
|
||||
_alphaAnimationStartedAt = 0;
|
||||
_heightAnimationStarted = false;
|
||||
|
@ -550,7 +584,7 @@ void ChartWidget::setupChartArea() {
|
|||
|
||||
const auto now = crl::now();
|
||||
|
||||
_animationController.tick(now, _horizontalLines);
|
||||
_animationController.tick(now, _horizontalLines, _bottomLine.dates);
|
||||
|
||||
const auto chartRect = chartAreaRect();
|
||||
|
||||
|
@ -638,10 +672,6 @@ void ChartWidget::updateBottomDates() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (_bottomLine.animation.animating()) {
|
||||
_bottomLine.animation.stop();
|
||||
}
|
||||
|
||||
constexpr auto kStepRatio = 0.2;
|
||||
const auto stepMax = 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.animation.start(
|
||||
[=](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);
|
||||
_animationController.restartBottomLineAlpha();
|
||||
}
|
||||
|
||||
void ChartWidget::setupFooter() {
|
||||
|
|
|
@ -48,9 +48,11 @@ private:
|
|||
void start();
|
||||
void finish();
|
||||
void resetAlpha();
|
||||
void restartBottomLineAlpha();
|
||||
void tick(
|
||||
crl::time now,
|
||||
std::vector<ChartHorizontalLinesData> &horizontalLines);
|
||||
std::vector<ChartHorizontalLinesData> &horizontalLines,
|
||||
std::vector<BottomCaptionLineData> &dateLines);
|
||||
|
||||
[[nodiscard]] Limits currentXLimits() const;
|
||||
[[nodiscard]] Limits finalXLimits() const;
|
||||
|
@ -66,6 +68,7 @@ private:
|
|||
|
||||
crl::time _lastUserInteracted = 0;
|
||||
crl::time _alphaAnimationStartedAt = 0;
|
||||
crl::time _bottomLineAlphaAnimationStartedAt = 0;
|
||||
bool _heightAnimationStarted = false;
|
||||
|
||||
anim::value _animationValueXMin;
|
||||
|
@ -75,6 +78,8 @@ private:
|
|||
|
||||
anim::value _animValueYAlpha;
|
||||
|
||||
anim::value _animValueBottomLineAlpha;
|
||||
|
||||
Limits _finalHeightLimits;
|
||||
|
||||
float _dtHeightSpeed = 0.;
|
||||
|
@ -104,7 +109,6 @@ private:
|
|||
struct {
|
||||
BottomCaptionLineData current;
|
||||
std::vector<BottomCaptionLineData> dates;
|
||||
Ui::Animations::Simple animation;
|
||||
int chartFullWidth = 0;
|
||||
} _bottomLine;
|
||||
|
||||
|
|
Loading…
Reference in New Issue