Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb committed May 22, 2024
1 parent adc126d commit 2b41cc4
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 63 deletions.
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
33 changes: 21 additions & 12 deletions src/chart/animator/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
namespace Vizzu::Anim
{

Animation::Animation(const Data::DataTable &dataTable,
const Gen::PlotPtr &plot) :
Animation::Animation(const Gen::PlotPtr &plot) :
::Anim::Control(static_cast<Controllable &>(*this)),
dataTable(dataTable),
source(plot),
target(plot)
{
Expand All @@ -39,6 +37,7 @@ Animation::Animation(const Data::DataTable &dataTable,
}

void Animation::addKeyframe(const Gen::PlotPtr &next,
const Data::DataTable &dataTable,
const Options::Keyframe &options)
{
if (isRunning())
Expand All @@ -64,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 @@ -101,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 @@ -140,6 +145,7 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
if (intermediate0) {
addKeyframe(begin,
intermediate0,
dataTable,
real_options,
intermediate0Instant);
begin = intermediate0;
Expand All @@ -150,22 +156,24 @@ 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,
Modifier &&modifier) const
const Data::DataTable &dataTable,
Modifier &&modifier)
{
Gen::PlotPtr res;

Expand All @@ -187,10 +195,11 @@ 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,
Expand Down
11 changes: 6 additions & 5 deletions src/chart/animator/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ class Animation : public ::Anim::Sequence, public ::Anim::Control

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

Animation(const Data::DataTable &dataTable,
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,
OnComplete &&onThisCompletes);

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

template <class Modifier>
Gen::PlotPtr getIntermediate(const Gen::PlotPtr &base,
static Gen::PlotPtr getIntermediate(const Gen::PlotPtr &base,
const Gen::PlotPtr &other,
Modifier &&modifier) const;
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
11 changes: 4 additions & 7 deletions src/chart/animator/animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ Animator::Animator(const Data::DataTable &dataTable,
dataTable(dataTable),
onBegin(onBegin),
onComplete(onComplete),
actAnimation(
std::make_shared<Animation>(dataTable, Gen::PlotPtr())),
nextAnimation(
std::make_shared<Animation>(dataTable, Gen::PlotPtr()))
actAnimation(std::make_shared<Animation>()),
nextAnimation(std::make_shared<Animation>())
{}

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

Expand Down
2 changes: 1 addition & 1 deletion src/chart/animator/keyframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Keyframe::prepareActual()
if (Gen::Plot::dimensionMatch(*source, *target)) {
if (Gen::Plot::hasMarkerChange(*source, *target))
copyTarget();
Gen::Plot::mergeMarkersWithCellInfo(*source, *target);
Gen::Plot::mergeMarkersAndCellInfo(*source, *target);
}
else {
copyTarget();
Expand Down
48 changes: 23 additions & 25 deletions src/chart/generator/axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,6 @@

namespace Vizzu::Gen
{

template <typename Type> struct AbstractAxises
{
Refl::EnumArray<ChannelId, Type> axises;

[[nodiscard]] const Type &at(ChannelId channelType) const
{
return axises.at(channelType);
}

Type &at(ChannelId channelType) { return axises.at(channelType); }

[[nodiscard]] const Type &other(ChannelId channelType) const
{
return channelType == ChannelId::x ? axises.at(ChannelId::y)
: channelType == ChannelId::y
? axises.at(ChannelId::x)
: throw std::logic_error("not an axis channel");
}

[[nodiscard]] bool operator==(
const AbstractAxises &other) const = default;
};

struct CommonAxis
{
::Anim::String title;
Expand Down Expand Up @@ -168,9 +144,31 @@ struct Axis
DimensionAxis dimension;
};

struct Axises : AbstractAxises<Axis>
struct Axises
{
Refl::EnumArray<ChannelId, Axis> axises;
[[nodiscard]] const Axis &at(ChannelId channelType) const
{
return axises.at(channelType);
}

[[nodiscard]] Axis &at(ChannelId channelType)
{
return axises.at(channelType);
}

[[nodiscard]] const Axis &other(ChannelId channelType) const
{
return channelType == ChannelId::x ? axises.at(ChannelId::y)
: channelType == ChannelId::y
? axises.at(ChannelId::x)
: throw std::logic_error("not an axis channel");
}

[[nodiscard]] Geom::Point origo() const;

[[nodiscard]] bool operator==(
const Axises &other) const = default;
};

}
Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool Plot::hasMarkerChange(const Plot &source, const Plot &target)
return source.markers.size() != target.markers.size()
|| source.markersInfo != target.markersInfo;
}
void Plot::mergeMarkersWithCellInfo(Plot &source, Plot &target)
void Plot::mergeMarkersAndCellInfo(Plot &source, Plot &target)
{
auto &&smarkers = source.markers;
auto &&tmarkers = target.markers;
Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Plot
static bool dimensionMatch(const Plot &a, const Plot &b);
static bool hasMarkerChange(const Plot &source,
const Plot &target);
static void mergeMarkersWithCellInfo(Plot &source, Plot &target);
static void mergeMarkersAndCellInfo(Plot &source, Plot &target);

private:
PlotOptionsPtr options;
Expand Down
44 changes: 33 additions & 11 deletions src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ PlotBuilder::PlotBuilder(const Data::DataTable &dataTable,
dataCube(dataTable, *options),
plot(std::make_shared<Plot>(options, style))
{
for (const Channel &ch :
plot->options->getChannels().getChannels())
if (ch.isDimension())
plot->axises.at(ch.type).dimension.trackedValues =
std::make_shared<
std::vector<std::optional<Data::SliceIndex>>>(
dataCube.combinedSizeOf(ch.dimensions()).second);
initDimensionTrackers();

std::size_t mainBucketSize{};
auto &&subBuckets = generateMarkers(mainBucketSize);

Expand All @@ -43,10 +38,28 @@ PlotBuilder::PlotBuilder(const Data::DataTable &dataTable,
addAlignment(subBuckets);
}

resetDimensionTrackers();
}

void PlotBuilder::initDimensionTrackers() const
{
for (const Channel &ch :
plot->options->getChannels().getChannels())
if (ch.isDimension())
plot->axises.at(ch.type).dimension.trackedValues.reset();
plot->options->getChannels().getChannels()) {
if (!ch.isDimension()) continue;
plot->axises.at(ch.type).dimension.trackedValues =
std::make_shared<
std::vector<std::optional<Data::SliceIndex>>>(
dataCube.combinedSizeOf(ch.dimensions()).second);
}
}

void PlotBuilder::resetDimensionTrackers() const
{
for (const Channel &ch :
plot->options->getChannels().getChannels()) {
if (!ch.isDimension()) continue;
plot->axises.at(ch.type).dimension.trackedValues.reset();
}
}

Buckets PlotBuilder::generateMarkers(std::size_t &mainBucketSize)
Expand Down Expand Up @@ -131,7 +144,16 @@ PlotBuilder::sortedBuckets(const Buckets &buckets, bool main) const
}

if (main && plot->getOptions()->sort == Sort::byValue)
std::sort(sorted.begin(), sorted.end());
std::sort(sorted.begin(),
sorted.end(),
[](const std::pair<double, std::size_t> &lhs,
const std::pair<double, std::size_t> &rhs)
{
if (auto ord = std::weak_order(lhs.first, rhs.first);
!std::is_eq(ord))
return std::is_lt(ord);
return lhs.second < rhs.second;
});

if (main && plot->getOptions()->reverse)
std::reverse(sorted.begin(), sorted.end());
Expand Down
2 changes: 2 additions & 0 deletions src/chart/generator/plotbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class PlotBuilder
Data::DataCube dataCube;
PlotPtr plot;

void initDimensionTrackers() const;
void resetDimensionTrackers() const;
Buckets generateMarkers(std::size_t &mainBucketSize);
[[nodiscard]] bool linkMarkers(const Buckets &buckets,
bool main) const;
Expand Down

0 comments on commit 2b41cc4

Please sign in to comment.