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 5 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
14 changes: 9 additions & 5 deletions src/chart/animator/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

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

namespace Vizzu::Anim
{

Animation::Animation(const Gen::PlotPtr &plot) :
Animation::Animation(const Data::DataTable &dataTable,
schaumb marked this conversation as resolved.
Show resolved Hide resolved
const Gen::PlotPtr &plot) :
::Anim::Control(static_cast<Controllable &>(*this)),
dataTable(dataTable),
source(plot),
target(plot)
{
Expand Down Expand Up @@ -162,7 +165,7 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
template <class Modifier>
Gen::PlotPtr Animation::getIntermediate(const Gen::PlotPtr &base,
const Gen::PlotPtr &other,
Modifier &&modifier)
Modifier &&modifier) const
{
Gen::PlotPtr res;

Expand All @@ -173,9 +176,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 @@ -189,6 +192,7 @@ void Animation::addKeyframe(const Gen::PlotPtr &source,
{
::Anim::Sequence::addKeyframe(std::make_shared<Keyframe>(source,
target,
dataTable,
&options,
isInstant));
}
Expand Down
8 changes: 5 additions & 3 deletions src/chart/animator/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Animation : public ::Anim::Sequence, public ::Anim::Control

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

explicit Animation(const Gen::PlotPtr &plot);
Animation(const Data::DataTable &dataTable,
const Gen::PlotPtr &plot);

void addKeyframe(const Gen::PlotPtr &next,
const Options::Keyframe &options);
Expand All @@ -27,14 +28,15 @@ class Animation : public ::Anim::Sequence, public ::Anim::Control
OnComplete &&onThisCompletes);

private:
const Data::DataTable &dataTable;
OnComplete completionCallback;
Gen::PlotPtr source;
Gen::PlotPtr target;

template <class Modifier>
static Gen::PlotPtr getIntermediate(const Gen::PlotPtr &base,
Gen::PlotPtr getIntermediate(const Gen::PlotPtr &base,
const Gen::PlotPtr &other,
Modifier &&modifier);
Modifier &&modifier) const;

void addKeyframe(const Gen::PlotPtr &source,
const Gen::PlotPtr &target,
Expand Down
13 changes: 9 additions & 4 deletions src/chart/animator/animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
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>(dataTable, Gen::PlotPtr())),
nextAnimation(
std::make_shared<Animation>(dataTable, Gen::PlotPtr()))
{}

void Animator::addKeyframe(const Gen::PlotPtr &plot,
Expand All @@ -36,7 +40,8 @@ void Animator::animate(const ::Anim::Control::Option &options,
onThisCompletes.attach(
[this](const Gen::PlotPtr &plot, const bool &)
{
nextAnimation = std::make_shared<Animation>(plot);
nextAnimation =
std::make_shared<Animation>(dataTable, plot);
this->running = false;
});

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::mergeMarkersWithCellInfo(*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