1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <private/boxwhiskersanimation_p.h>
5#include <private/boxplotanimation_p.h>
6#include <private/boxplotchartitem_p.h>
7#include <private/boxwhiskersdata_p.h>
8
9
10QT_BEGIN_NAMESPACE
11
12BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation,
13 int duration, QEasingCurve &curve)
14 : ChartAnimation(box),
15 m_box(box),
16 m_changeAnimation(false),
17 m_boxPlotAnimation(boxPlotAnimation)
18{
19 setDuration(duration);
20 setEasingCurve(curve);
21}
22
23BoxWhiskersAnimation::~BoxWhiskersAnimation()
24{
25 if (m_boxPlotAnimation)
26 m_boxPlotAnimation->removeBoxAnimation(box: m_box);
27}
28
29QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
30{
31 BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(v: from);
32 BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(v: to);
33 BoxWhiskersData result;
34
35 if (m_changeAnimation) {
36 result.m_lowerExtreme = startData.m_lowerExtreme + progress * (endData.m_lowerExtreme - startData.m_lowerExtreme);
37 result.m_lowerQuartile = startData.m_lowerQuartile + progress * (endData.m_lowerQuartile - startData.m_lowerQuartile);
38 result.m_median = startData.m_median + progress * (endData.m_median - startData.m_median);
39 result.m_upperQuartile = startData.m_upperQuartile + progress * (endData.m_upperQuartile - startData.m_upperQuartile);
40 result.m_upperExtreme = startData.m_upperExtreme + progress * (endData.m_upperExtreme - startData.m_upperExtreme);
41 } else {
42 result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median);
43 result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median);
44 result.m_median = endData.m_median;
45 result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median);
46 result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median);
47 }
48 result.m_index = endData.m_index;
49 result.m_boxItems = endData.m_boxItems;
50
51 result.m_maxX = endData.m_maxX;
52 result.m_minX = endData.m_minX;
53 result.m_maxY = endData.m_maxY;
54 result.m_minY = endData.m_minY;
55 result.m_seriesIndex = endData.m_seriesIndex;
56 result.m_seriesCount = endData.m_seriesCount;
57
58 return QVariant::fromValue(value: result);
59}
60
61void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value)
62{
63 const BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(v: value);
64 m_box->setLayout(data);
65}
66
67void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData)
68{
69 setKeyValueAt(step: 0.0, value: QVariant::fromValue(value: startData));
70 setKeyValueAt(step: 1.0, value: QVariant::fromValue(value: endData));
71}
72
73void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData)
74{
75 if (state() != QAbstractAnimation::Stopped)
76 stop();
77
78 setEndValue(QVariant::fromValue(value: endData));
79}
80
81void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData)
82{
83 if (state() != QAbstractAnimation::Stopped)
84 stop();
85
86 setStartValue(QVariant::fromValue(value: endData));
87}
88
89QT_END_NAMESPACE
90
91#include "moc_boxwhiskersanimation_p.cpp"
92

source code of qtcharts/src/charts/animations/boxwhiskersanimation.cpp