Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot simplification #528

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/base/refl/auto_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ struct EnumArray : std::array<V, std::size(enum_names<E>)>
{
return base_array::at(static_cast<std::size_t>(value));
}

bool operator==(const EnumArray &) const = default;
};

template <class E, class... Args>
Expand Down
35 changes: 24 additions & 11 deletions src/chart/animator/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chart/animator/keyframe.h"
#include "chart/generator/plot.h"
#include "chart/generator/plotbuilder.h"

namespace Vizzu::Anim
{
Expand Down Expand Up @@ -36,6 +37,7 @@ Animation::Animation(const Gen::PlotPtr &plot) :
}

void Animation::addKeyframe(const Gen::PlotPtr &next,
const Data::DataTable &dataTable,
const Options::Keyframe &options)
{
if (isRunning())
Expand All @@ -61,9 +63,11 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
{
base.drilldownTo(other);
};
intermediate0 = getIntermediate(target, next, drilldown);
intermediate0 =
getIntermediate(target, next, dataTable, drilldown);

intermediate1 = getIntermediate(next, target, drilldown);
intermediate1 =
getIntermediate(next, target, dataTable, drilldown);
}
else if (strategy == RegroupStrategy::aggregate) {
auto &&targetAxisSet =
Expand Down Expand Up @@ -98,10 +102,14 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,

const auto &base = basedOnSource ? target : next;
const auto &other = basedOnSource ? next : target;
intermediate0 =
getIntermediate(base, other, getModifier(basedOnSource));
intermediate1 =
getIntermediate(base, other, getModifier(!basedOnSource));
intermediate0 = getIntermediate(base,
other,
dataTable,
getModifier(basedOnSource));
intermediate1 = getIntermediate(base,
other,
dataTable,
getModifier(!basedOnSource));
}

auto &&intermediate0Instant = intermediate0
Expand Down Expand Up @@ -137,6 +145,7 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
if (intermediate0) {
addKeyframe(begin,
intermediate0,
dataTable,
real_options,
intermediate0Instant);
begin = intermediate0;
Expand All @@ -147,21 +156,23 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
if (intermediate1) {
addKeyframe(begin,
intermediate1,
dataTable,
real_options,
intermediate1Instant);
begin = intermediate1;

if (!intermediate1Instant)
real_options.all.delay = ::Anim::Duration(0);
}
addKeyframe(begin, next, real_options, nextInstant);
addKeyframe(begin, next, dataTable, real_options, nextInstant);

target = next;
}

template <class Modifier>
Gen::PlotPtr Animation::getIntermediate(const Gen::PlotPtr &base,
const Gen::PlotPtr &other,
const Data::DataTable &dataTable,
Modifier &&modifier)
{
Gen::PlotPtr res;
Expand All @@ -173,9 +184,9 @@ Gen::PlotPtr Animation::getIntermediate(const Gen::PlotPtr &base,

if (*extOptions != *other->getOptions()
&& *extOptions != *base->getOptions()) {
res = std::make_shared<Gen::Plot>(base->getTable(),
extOptions,
base->getStyle());
res =
Gen::PlotBuilder{dataTable, extOptions, base->getStyle()}
.build();

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

void Animation::addKeyframe(const Gen::PlotPtr &source,
const Gen::PlotPtr &target,
const Data::DataTable &dataTable,
const Options::Keyframe &options,
bool isInstant)
{
::Anim::Sequence::addKeyframe(std::make_shared<Keyframe>(source,
Sequence::addKeyframe(std::make_shared<Keyframe>(source,
target,
dataTable,
&options,
isInstant));
}
Expand Down
5 changes: 4 additions & 1 deletion src/chart/animator/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class Animation : public ::Anim::Sequence, public ::Anim::Control

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

explicit Animation(const Gen::PlotPtr &plot);
explicit Animation(const Gen::PlotPtr &plot = {});

void addKeyframe(const Gen::PlotPtr &next,
const Data::DataTable &dataTable,
const Options::Keyframe &options);

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

void addKeyframe(const Gen::PlotPtr &source,
const Gen::PlotPtr &target,
const Data::DataTable &dataTable,
const Options::Keyframe &options,
bool isInstant);
};
Expand Down
10 changes: 6 additions & 4 deletions src/chart/animator/animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace Vizzu::Anim
{

Animator::Animator(const Util::EventDispatcher::Event &onBegin,
Animator::Animator(const Data::DataTable &dataTable,
const Util::EventDispatcher::Event &onBegin,
const Util::EventDispatcher::Event &onComplete) :
dataTable(dataTable),
onBegin(onBegin),
onComplete(onComplete),
actAnimation(std::make_shared<Animation>(Gen::PlotPtr())),
nextAnimation(std::make_shared<Animation>(Gen::PlotPtr()))
actAnimation(std::make_shared<Animation>()),
nextAnimation(std::make_shared<Animation>())
{}

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

nextAnimation->addKeyframe(plot, options);
nextAnimation->addKeyframe(plot, dataTable, options);
}

void Animator::setAnimation(const Anim::AnimationPtr &animation)
Expand Down
4 changes: 3 additions & 1 deletion src/chart/animator/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Vizzu::Anim
class Animator
{
public:
Animator(const Util::EventDispatcher::Event &onBegin,
Animator(const Data::DataTable &dataTable,
const Util::EventDispatcher::Event &onBegin,
const Util::EventDispatcher::Event &onComplete);

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

const Data::DataTable &dataTable;
Util::Event<const Gen::PlotPtr> onDraw;
Util::Event<> onProgress;
std::reference_wrapper<const Util::EventDispatcher::Event>
Expand Down
59 changes: 14 additions & 45 deletions src/chart/animator/keyframe.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "keyframe.h"

#include <chart/generator/plotbuilder.h>
#include <utility>

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

Keyframe::Keyframe(Gen::PlotPtr src,
const Gen::PlotPtr &trg,
const Data::DataTable &dataTable,
const Options::Keyframe *options,
bool isInstant) :
options(*options),
source(std::move(src))
{
if (isInstant) this->options.all.duration = ::Anim::Duration(0);
init(trg);
init(trg, dataTable);
prepareActual();
createPlan(*source, *target, *actual, this->options);
}

void Keyframe::init(const Gen::PlotPtr &plot)
void Keyframe::init(const Gen::PlotPtr &plot,
const Data::DataTable &dataTable)
{
if (!plot) return;

Expand All @@ -37,9 +40,9 @@ void Keyframe::init(const Gen::PlotPtr &plot)
if (auto &&caption = source->getOptions()->caption.get())
emptyOpt->caption = caption;
}
source = std::make_shared<Gen::Plot>(plot->getTable(),
emptyOpt,
plot->getStyle());
source =
Gen::PlotBuilder{dataTable, emptyOpt, plot->getStyle()}
.build();
source->keepAspectRatio = plot->keepAspectRatio;
}
target = plot;
Expand All @@ -49,25 +52,19 @@ void Keyframe::init(const Gen::PlotPtr &plot)
void Keyframe::prepareActual()
{
if (Gen::Plot::dimensionMatch(*source, *target)) {
addMissingMarkers(source, target);

mergeMarkerCellInfo(source, target);

prepareActualMarkersInfo();
if (Gen::Plot::hasMarkerChange(*source, *target))
copyTarget();
Gen::Plot::mergeMarkersAndCellInfo(*source, *target);
}
else {
copyTarget();

target->prependMarkers(*source);
source->appendMarkers(*targetCopy);

prepareActualMarkersInfo();
}
prepareActualMarkersInfo();

auto options =
std::make_shared<Gen::Options>(*source->getOptions());

actual = std::make_shared<Gen::Plot>(options, *source);
actual = std::make_shared<Gen::Plot>(*source);
actual->detachOptions();
}

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

void Keyframe::addMissingMarkers(const Gen::PlotPtr &source,
const Gen::PlotPtr &target)
{
auto &&smarkers = source->markers;
auto &&tmarkers = target->markers;
auto &&ssize = smarkers.size();
auto &&tsize = tmarkers.size();
for (auto i = ssize; i < tsize; ++i)
smarkers.emplace_back(tmarkers[i]).enabled = false;

if (tsize < ssize) copyTarget();
for (auto i = tsize; i < ssize; ++i)
target->markers.emplace_back(smarkers[i]).enabled = false;
}

void Keyframe::mergeMarkerCellInfo(const Gen::PlotPtr &source,
const Gen::PlotPtr &target)
{
const auto markers_size = source->markers.size();
for (std::size_t ix{}; ix < markers_size; ++ix)
if (auto &scell = source->markers[ix].cellInfo,
&tcell = target->markers[ix].cellInfo;
scell && !tcell)
tcell = scell;
else if (!scell && tcell)
scell = tcell;
}

void Keyframe::copyTarget()
{
if (!targetCopy) {
Expand Down
8 changes: 3 additions & 5 deletions src/chart/animator/keyframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Keyframe : public Planner
public:
Keyframe(Gen::PlotPtr src,
const Gen::PlotPtr &trg,
const Data::DataTable &dataTable,
const Options::Keyframe *options,
bool isInstant);

Expand All @@ -29,13 +30,10 @@ class Keyframe : public Planner
Gen::PlotPtr actual;
Gen::PlotPtr targetCopy;

void init(const Gen::PlotPtr &plot);
void init(const Gen::PlotPtr &plot,
const Data::DataTable &dataTable);
void prepareActual();
void prepareActualMarkersInfo();
void addMissingMarkers(const Gen::PlotPtr &source,
const Gen::PlotPtr &target);
static void mergeMarkerCellInfo(const Gen::PlotPtr &source,
const Gen::PlotPtr &target);
void copyTarget();
};

Expand Down
Loading