Skip to content

Commit 8331adc

Browse files
authored
Merge pull request #528 from vizzuhq/plot_separation
Plot simplification
2 parents 033bb07 + 2b41cc4 commit 8331adc

29 files changed

+835
-827
lines changed

src/base/refl/auto_enum.h

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ struct EnumArray : std::array<V, std::size(enum_names<E>)>
173173
{
174174
return base_array::at(static_cast<std::size_t>(value));
175175
}
176+
177+
bool operator==(const EnumArray &) const = default;
176178
};
177179

178180
template <class E, class... Args>

src/chart/animator/animation.cpp

+24-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "chart/animator/keyframe.h"
66
#include "chart/generator/plot.h"
7+
#include "chart/generator/plotbuilder.h"
78

89
namespace Vizzu::Anim
910
{
@@ -36,6 +37,7 @@ Animation::Animation(const Gen::PlotPtr &plot) :
3637
}
3738

3839
void Animation::addKeyframe(const Gen::PlotPtr &next,
40+
const Data::DataTable &dataTable,
3941
const Options::Keyframe &options)
4042
{
4143
if (isRunning())
@@ -61,9 +63,11 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
6163
{
6264
base.drilldownTo(other);
6365
};
64-
intermediate0 = getIntermediate(target, next, drilldown);
66+
intermediate0 =
67+
getIntermediate(target, next, dataTable, drilldown);
6568

66-
intermediate1 = getIntermediate(next, target, drilldown);
69+
intermediate1 =
70+
getIntermediate(next, target, dataTable, drilldown);
6771
}
6872
else if (strategy == RegroupStrategy::aggregate) {
6973
auto &&targetAxisSet =
@@ -98,10 +102,14 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
98102

99103
const auto &base = basedOnSource ? target : next;
100104
const auto &other = basedOnSource ? next : target;
101-
intermediate0 =
102-
getIntermediate(base, other, getModifier(basedOnSource));
103-
intermediate1 =
104-
getIntermediate(base, other, getModifier(!basedOnSource));
105+
intermediate0 = getIntermediate(base,
106+
other,
107+
dataTable,
108+
getModifier(basedOnSource));
109+
intermediate1 = getIntermediate(base,
110+
other,
111+
dataTable,
112+
getModifier(!basedOnSource));
105113
}
106114

107115
auto &&intermediate0Instant = intermediate0
@@ -137,6 +145,7 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
137145
if (intermediate0) {
138146
addKeyframe(begin,
139147
intermediate0,
148+
dataTable,
140149
real_options,
141150
intermediate0Instant);
142151
begin = intermediate0;
@@ -147,21 +156,23 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
147156
if (intermediate1) {
148157
addKeyframe(begin,
149158
intermediate1,
159+
dataTable,
150160
real_options,
151161
intermediate1Instant);
152162
begin = intermediate1;
153163

154164
if (!intermediate1Instant)
155165
real_options.all.delay = ::Anim::Duration(0);
156166
}
157-
addKeyframe(begin, next, real_options, nextInstant);
167+
addKeyframe(begin, next, dataTable, real_options, nextInstant);
158168

159169
target = next;
160170
}
161171

162172
template <class Modifier>
163173
Gen::PlotPtr Animation::getIntermediate(const Gen::PlotPtr &base,
164174
const Gen::PlotPtr &other,
175+
const Data::DataTable &dataTable,
165176
Modifier &&modifier)
166177
{
167178
Gen::PlotPtr res;
@@ -173,9 +184,9 @@ Gen::PlotPtr Animation::getIntermediate(const Gen::PlotPtr &base,
173184

174185
if (*extOptions != *other->getOptions()
175186
&& *extOptions != *base->getOptions()) {
176-
res = std::make_shared<Gen::Plot>(base->getTable(),
177-
extOptions,
178-
base->getStyle());
187+
res =
188+
Gen::PlotBuilder{dataTable, extOptions, base->getStyle()}
189+
.build();
179190

180191
res->keepAspectRatio = base->keepAspectRatio;
181192
}
@@ -184,11 +195,13 @@ Gen::PlotPtr Animation::getIntermediate(const Gen::PlotPtr &base,
184195

185196
void Animation::addKeyframe(const Gen::PlotPtr &source,
186197
const Gen::PlotPtr &target,
198+
const Data::DataTable &dataTable,
187199
const Options::Keyframe &options,
188200
bool isInstant)
189201
{
190-
::Anim::Sequence::addKeyframe(std::make_shared<Keyframe>(source,
202+
Sequence::addKeyframe(std::make_shared<Keyframe>(source,
191203
target,
204+
dataTable,
192205
&options,
193206
isInstant));
194207
}

src/chart/animator/animation.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class Animation : public ::Anim::Sequence, public ::Anim::Control
1818

1919
Util::Event<const Gen::PlotPtr> onPlotChanged;
2020

21-
explicit Animation(const Gen::PlotPtr &plot);
21+
explicit Animation(const Gen::PlotPtr &plot = {});
2222

2323
void addKeyframe(const Gen::PlotPtr &next,
24+
const Data::DataTable &dataTable,
2425
const Options::Keyframe &options);
2526

2627
void animate(const ::Anim::Control::Option &options,
@@ -34,10 +35,12 @@ class Animation : public ::Anim::Sequence, public ::Anim::Control
3435
template <class Modifier>
3536
static Gen::PlotPtr getIntermediate(const Gen::PlotPtr &base,
3637
const Gen::PlotPtr &other,
38+
const Data::DataTable &dataTable,
3739
Modifier &&modifier);
3840

3941
void addKeyframe(const Gen::PlotPtr &source,
4042
const Gen::PlotPtr &target,
43+
const Data::DataTable &dataTable,
4144
const Options::Keyframe &options,
4245
bool isInstant);
4346
};

src/chart/animator/animator.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
namespace Vizzu::Anim
66
{
77

8-
Animator::Animator(const Util::EventDispatcher::Event &onBegin,
8+
Animator::Animator(const Data::DataTable &dataTable,
9+
const Util::EventDispatcher::Event &onBegin,
910
const Util::EventDispatcher::Event &onComplete) :
11+
dataTable(dataTable),
1012
onBegin(onBegin),
1113
onComplete(onComplete),
12-
actAnimation(std::make_shared<Animation>(Gen::PlotPtr())),
13-
nextAnimation(std::make_shared<Animation>(Gen::PlotPtr()))
14+
actAnimation(std::make_shared<Animation>()),
15+
nextAnimation(std::make_shared<Animation>())
1416
{}
1517

1618
void Animator::addKeyframe(const Gen::PlotPtr &plot,
@@ -19,7 +21,7 @@ void Animator::addKeyframe(const Gen::PlotPtr &plot,
1921
if (running)
2022
throw std::logic_error("animation already in progress");
2123

22-
nextAnimation->addKeyframe(plot, options);
24+
nextAnimation->addKeyframe(plot, dataTable, options);
2325
}
2426

2527
void Animator::setAnimation(const Anim::AnimationPtr &animation)

src/chart/animator/animator.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace Vizzu::Anim
1515
class Animator
1616
{
1717
public:
18-
Animator(const Util::EventDispatcher::Event &onBegin,
18+
Animator(const Data::DataTable &dataTable,
19+
const Util::EventDispatcher::Event &onBegin,
1920
const Util::EventDispatcher::Event &onComplete);
2021

2122
void addKeyframe(const Gen::PlotPtr &plot,
@@ -26,6 +27,7 @@ class Animator
2627
void animate(const ::Anim::Control::Option &options,
2728
Animation::OnComplete &&onThisCompletes);
2829

30+
const Data::DataTable &dataTable;
2931
Util::Event<const Gen::PlotPtr> onDraw;
3032
Util::Event<> onProgress;
3133
std::reference_wrapper<const Util::EventDispatcher::Event>

src/chart/animator/keyframe.cpp

+14-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "keyframe.h"
22

3+
#include <chart/generator/plotbuilder.h>
34
#include <utility>
45

56
#include "chart/generator/plot.h"
@@ -9,18 +10,20 @@ namespace Vizzu::Anim
910

1011
Keyframe::Keyframe(Gen::PlotPtr src,
1112
const Gen::PlotPtr &trg,
13+
const Data::DataTable &dataTable,
1214
const Options::Keyframe *options,
1315
bool isInstant) :
1416
options(*options),
1517
source(std::move(src))
1618
{
1719
if (isInstant) this->options.all.duration = ::Anim::Duration(0);
18-
init(trg);
20+
init(trg, dataTable);
1921
prepareActual();
2022
createPlan(*source, *target, *actual, this->options);
2123
}
2224

23-
void Keyframe::init(const Gen::PlotPtr &plot)
25+
void Keyframe::init(const Gen::PlotPtr &plot,
26+
const Data::DataTable &dataTable)
2427
{
2528
if (!plot) return;
2629

@@ -37,9 +40,9 @@ void Keyframe::init(const Gen::PlotPtr &plot)
3740
if (auto &&caption = source->getOptions()->caption.get())
3841
emptyOpt->caption = caption;
3942
}
40-
source = std::make_shared<Gen::Plot>(plot->getTable(),
41-
emptyOpt,
42-
plot->getStyle());
43+
source =
44+
Gen::PlotBuilder{dataTable, emptyOpt, plot->getStyle()}
45+
.build();
4346
source->keepAspectRatio = plot->keepAspectRatio;
4447
}
4548
target = plot;
@@ -49,25 +52,19 @@ void Keyframe::init(const Gen::PlotPtr &plot)
4952
void Keyframe::prepareActual()
5053
{
5154
if (Gen::Plot::dimensionMatch(*source, *target)) {
52-
addMissingMarkers(source, target);
53-
54-
mergeMarkerCellInfo(source, target);
55-
56-
prepareActualMarkersInfo();
55+
if (Gen::Plot::hasMarkerChange(*source, *target))
56+
copyTarget();
57+
Gen::Plot::mergeMarkersAndCellInfo(*source, *target);
5758
}
5859
else {
5960
copyTarget();
60-
6161
target->prependMarkers(*source);
6262
source->appendMarkers(*targetCopy);
63-
64-
prepareActualMarkersInfo();
6563
}
64+
prepareActualMarkersInfo();
6665

67-
auto options =
68-
std::make_shared<Gen::Options>(*source->getOptions());
69-
70-
actual = std::make_shared<Gen::Plot>(options, *source);
66+
actual = std::make_shared<Gen::Plot>(*source);
67+
actual->detachOptions();
7168
}
7269

7370
void Keyframe::prepareActualMarkersInfo()
@@ -83,34 +80,6 @@ void Keyframe::prepareActualMarkersInfo()
8380
smi.insert(std::pair{item.first, Gen::Plot::MarkerInfo{}});
8481
}
8582

86-
void Keyframe::addMissingMarkers(const Gen::PlotPtr &source,
87-
const Gen::PlotPtr &target)
88-
{
89-
auto &&smarkers = source->markers;
90-
auto &&tmarkers = target->markers;
91-
auto &&ssize = smarkers.size();
92-
auto &&tsize = tmarkers.size();
93-
for (auto i = ssize; i < tsize; ++i)
94-
smarkers.emplace_back(tmarkers[i]).enabled = false;
95-
96-
if (tsize < ssize) copyTarget();
97-
for (auto i = tsize; i < ssize; ++i)
98-
target->markers.emplace_back(smarkers[i]).enabled = false;
99-
}
100-
101-
void Keyframe::mergeMarkerCellInfo(const Gen::PlotPtr &source,
102-
const Gen::PlotPtr &target)
103-
{
104-
const auto markers_size = source->markers.size();
105-
for (std::size_t ix{}; ix < markers_size; ++ix)
106-
if (auto &scell = source->markers[ix].cellInfo,
107-
&tcell = target->markers[ix].cellInfo;
108-
scell && !tcell)
109-
tcell = scell;
110-
else if (!scell && tcell)
111-
scell = tcell;
112-
}
113-
11483
void Keyframe::copyTarget()
11584
{
11685
if (!targetCopy) {

src/chart/animator/keyframe.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Keyframe : public Planner
1414
public:
1515
Keyframe(Gen::PlotPtr src,
1616
const Gen::PlotPtr &trg,
17+
const Data::DataTable &dataTable,
1718
const Options::Keyframe *options,
1819
bool isInstant);
1920

@@ -29,13 +30,10 @@ class Keyframe : public Planner
2930
Gen::PlotPtr actual;
3031
Gen::PlotPtr targetCopy;
3132

32-
void init(const Gen::PlotPtr &plot);
33+
void init(const Gen::PlotPtr &plot,
34+
const Data::DataTable &dataTable);
3335
void prepareActual();
3436
void prepareActualMarkersInfo();
35-
void addMissingMarkers(const Gen::PlotPtr &source,
36-
const Gen::PlotPtr &target);
37-
static void mergeMarkerCellInfo(const Gen::PlotPtr &source,
38-
const Gen::PlotPtr &target);
3937
void copyTarget();
4038
};
4139

0 commit comments

Comments
 (0)