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

Refactor marker connections 2 #549

Merged
merged 30 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
763d06c
reduce to 19 failing tcs
schaumb Jun 14, 2024
4d011ad
fix of fixes
schaumb Jun 27, 2024
3ca3826
separate polar connection + remain 13 tcs
schaumb Jun 27, 2024
140ac0b
Fix UT's
schaumb Jun 27, 2024
192d569
reduce to 19 failing tcs
schaumb Jun 14, 2024
e55e34b
separate polar connection + remain 13 tcs
schaumb Jun 27, 2024
9331995
Fix UT's
schaumb Jun 27, 2024
fb18432
Sunburst examples fixed.
simzer Jun 29, 2024
da8cbfc
Merge remote-tracking branch 'origin/sunburst-tests-fixed'
schaumb Jul 1, 2024
fc3f34a
reverify testcases
schaumb Jul 2, 2024
ede0d09
Changelog + fix 13_d-p_r-l-r
schaumb Jul 2, 2024
9fcf4d4
Remove sunburst hack comment.
schaumb Jul 2, 2024
727d415
Unify area and line chart connection drawing. 13 failing tcs
schaumb Jul 2, 2024
0a02de8
Connection when all the 2 markers are enabled
schaumb Jul 2, 2024
9234111
Move safe interpolation to interpolation
schaumb Jul 2, 2024
1f66a2b
Fix remaining testcases
schaumb Jul 2, 2024
aeba6bb
fix testcases format
schaumb Jul 2, 2024
012d343
Add default no rectangle spacing on heatmap and coxcomb
schaumb Jul 2, 2024
8d58b02
self review
schaumb Jul 4, 2024
cba5e5f
Fix unit tests -> changed markers count
schaumb Jul 4, 2024
6e2eb17
Fix MarkerInfo crash
schaumb Jul 5, 2024
f75c036
Merge remote-tracking branch 'origin/main'
schaumb Jul 9, 2024
c687460
fix changelog
schaumb Jul 9, 2024
c5ac060
fix mekko charts
schaumb Jul 9, 2024
a6a5cf8
Fix mekko testcases
schaumb Jul 10, 2024
1cc7145
fix clang-tidy
schaumb Jul 10, 2024
d8d2ce8
Fix ConvexQuad::Isosceles on same point + some refactor
schaumb Jul 10, 2024
d3b1eaf
fix area connection
schaumb Jul 10, 2024
7b3f473
dataframe get if empty data
schaumb Jul 11, 2024
824e5f1
constness + query only once the subIds at markergen.
schaumb Jul 11, 2024
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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

## [Unreleased]

### Fixed

- First marker alpha was different to other marker's alpha
- Make some transactions clearer. (rectangle-line first marker)
schaumb marked this conversation as resolved.
Show resolved Hide resolved

### Added

- New data handling implemented: Not generating big cube

## [0.11.4] - 2024-07-09

## Fixed
### Fixed

- Add default no rectangle spacing on heatmap and coxcomb.
- Crash fix on special (meas-meas) area bar mekko charts.
Expand Down
10 changes: 6 additions & 4 deletions src/apps/weblib/cinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ const Value *record_getValue(const Vizzu::Data::RowWrapper *record,
{
thread_local Value val{{}, {}};
if (auto &&cval = Interface::getRecordValue(*record, column);
(val.dimension = cval.index()))
new (&val.dimensionValue) const char *{
std::get_if<std::string_view>(&cval)->data()};
(val.dimension = cval.index())) {
auto &&dim = *std::get_if<const std::string *>(&cval);
new (&val.dimensionValue)
const char *{dim ? dim->c_str() : nullptr};
}
else
new (&val.measureValue) double{*std::get_if<double>(&cval)};
return &val;
Expand Down Expand Up @@ -301,7 +303,7 @@ void data_addMeasure(APIHandles::Chart chart,
}

void data_addRecord(APIHandles::Chart chart,
const char **cells,
const char *const *cells,
std::uint32_t count)
{
return Interface::getInstance().addRecord(chart, cells, count);
Expand Down
2 changes: 1 addition & 1 deletion src/apps/weblib/cinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern void data_addMeasure(APIHandles::Chart chart,
const double *values,
std::uint32_t count);
extern void data_addRecord(APIHandles::Chart chart,
const char **cells,
const char *const *cells,
std::uint32_t count);
const char *data_metaInfo(APIHandles::Chart chart);

Expand Down
4 changes: 2 additions & 2 deletions src/apps/weblib/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void Interface::setChartFilter(ObjectRegistryHandle chart,
getChart(chart)->getOptions().dataFilter = {};
}

std::variant<double, std::string_view> Interface::getRecordValue(
std::variant<double, const std::string *> Interface::getRecordValue(
const Data::RowWrapper &record,
const char *column)
{
Expand Down Expand Up @@ -323,7 +323,7 @@ void Interface::addMeasure(ObjectRegistryHandle chart,
}

void Interface::addRecord(ObjectRegistryHandle chart,
const char **cells,
const char *const *cells,
std::uint32_t count)
{
getChart(chart)->getTable().pushRow({cells, count});
Expand Down
4 changes: 2 additions & 2 deletions src/apps/weblib/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Interface
const double *values,
std::uint32_t count);
void addRecord(ObjectRegistryHandle chart,
const char **cells,
const char *const *cells,
std::uint32_t count);
const char *dataMetaInfo(ObjectRegistryHandle chart);
void addEventListener(ObjectRegistryHandle chart,
Expand All @@ -125,7 +125,7 @@ class Interface
const char *path,
const char *value);

static std::variant<double, std::string_view> getRecordValue(
static std::variant<double, const std::string *> getRecordValue(
const Data::RowWrapper &record,
const char *column);

Expand Down
22 changes: 15 additions & 7 deletions src/base/anim/interpolated.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ template <typename Type> class Weighted
Weighted() noexcept(
std::is_nothrow_default_constructible_v<Type>) = default;

explicit Weighted(Type value) :
explicit Weighted(Type value, double weight = 1.0) :
value(std::move(value)),
weight(1.0)
weight(weight)
{}

bool operator==(const Weighted<Type> &other) const
Expand Down Expand Up @@ -175,12 +175,20 @@ template <typename Type> class Interpolated
branch(second, values[1]);
}

template <class T, class Fun> T combine(Fun &&branch) const
template <class U = void,
class Fun,
class T = std::conditional_t<std::is_void_v<U>,
std::invoke_result_t<Fun, Type>,
U>>
T combine(Fun &&branch) const
{
auto res = T{branch(values[0].value)} * values[0].weight;
auto res = static_cast<T>(branch(values[0].value))
* values[0].weight;
if (has_second)
res = res + T{branch(values[1].value)} * values[1].weight;
return T{res};
res = res
+ static_cast<T>(branch(values[1].value))
* values[1].weight;
return static_cast<T>(res);
}

[[nodiscard]] bool contains(const Type &value) const
Expand Down Expand Up @@ -232,7 +240,7 @@ Interpolated<Type> interpolate(const Interpolated<Type> &op0,
double factor)
{
if (factor <= 0.0) return op0;
if (factor >= 1.0) return op1.shifted();
if (factor > 1.0) factor = 1.0;

if (op0.has_second || op1.has_second)
throw std::logic_error("Cannot interpolate Weigthed Pairs");
Expand Down
35 changes: 13 additions & 22 deletions src/base/geom/quadrilateral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
namespace Geom
{

ConvexQuad::ConvexQuad(const Geom::Rect &rect)
ConvexQuad::ConvexQuad(const Rect &rect)
{
points[0] = rect.pos;
points[1] = rect.pos + Point{rect.size.x, 0.0};
points[2] = rect.pos + rect.size;
points[3] = rect.pos + Point{0.0, rect.size.y};
}

Rect ConvexQuad::boundary() const
{
return Geom::Rect::Boundary(points);
}
Rect ConvexQuad::boundary() const { return Rect::Boundary(points); }

ConvexQuad ConvexQuad::Square(Point p0, Point p2)
{
Expand All @@ -29,12 +26,14 @@ ConvexQuad ConvexQuad::Square(Point p0, Point p2)
return ConvexQuad({p0, p1, p2, p3});
}

ConvexQuad ConvexQuad::Isosceles(Geom::Point base0Middle,
Geom::Point base1Middle,
ConvexQuad ConvexQuad::Isosceles(Point base0Middle,
Point base1Middle,
double base0Length,
double base1Length)
{
auto dir = (base1Middle - base0Middle).normalized();
auto dir = base1Middle == base0Middle
? Point{0, 1}
: (base1Middle - base0Middle).normalized();

return ConvexQuad(
{base0Middle + dir.normal(false) * (base0Length / 2),
Expand All @@ -45,26 +44,18 @@ ConvexQuad ConvexQuad::Isosceles(Geom::Point base0Middle,

bool ConvexQuad::contains(const Point &p, double tolerance) const
{
auto boundaryArea =
Triangle(std::array<Point, 3>{points[0], points[1], p}).area()
+ Triangle(std::array<Point, 3>{points[1], points[2], p})
.area()
+ Triangle(std::array<Point, 3>{points[2], points[3], p})
.area()
+ Triangle(std::array<Point, 3>{points[3], points[0], p})
.area();
auto boundaryArea = Triangle{{points[0], points[1], p}}.area()
+ Triangle{{points[1], points[2], p}}.area()
+ Triangle{{points[2], points[3], p}}.area()
+ Triangle{{points[3], points[0], p}}.area();

return Math::AddTolerance(boundaryArea, tolerance) <= area();
}

double ConvexQuad::area() const
{
return Triangle(
std::array<Point, 3>{points[0], points[1], points[2]})
.area()
+ Triangle(
std::array<Point, 3>{points[2], points[3], points[0]})
.area();
return Triangle{{points[0], points[1], points[2]}}.area()
+ Triangle{{points[2], points[3], points[0]}}.area();
}

}
10 changes: 5 additions & 5 deletions src/base/geom/quadrilateral.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class ConvexQuad

ConvexQuad() = default;
explicit ConvexQuad(const Points &points) : points(points) {}
explicit ConvexQuad(const Geom::Rect &rect);
static ConvexQuad Square(Point p0, Point p2);
static ConvexQuad Isosceles(Geom::Point base0Middle,
Geom::Point base1Middle,
explicit ConvexQuad(const Rect &rect);
[[nodiscard]] static ConvexQuad Square(Point p0, Point p2);
[[nodiscard]] static ConvexQuad Isosceles(Point base0Middle,
Point base1Middle,
double base0Length,
double base1Length);
[[nodiscard]] bool contains(const Point &p,
double tolerance = 0.0) const;
[[nodiscard]] double area() const;
[[nodiscard]] Geom::Rect boundary() const;
[[nodiscard]] Rect boundary() const;
};

}
Expand Down
7 changes: 0 additions & 7 deletions src/base/geom/triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
namespace Geom
{

Triangle::Triangle(const Point &p0, const Point &p1, const Point &p2)
{
points[0] = p0;
points[1] = p1;
points[2] = p2;
}

double Triangle::area() const
{
auto A = points[2] - points[1];
Expand Down
5 changes: 0 additions & 5 deletions src/base/geom/triangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class Triangle
public:
std::array<Point, 3> points;

explicit Triangle(const std::array<Point, 3> &points) :
points(points)
{}
Triangle(const Point &p0, const Point &p1, const Point &p2);

[[nodiscard]] double area() const;
};

Expand Down
2 changes: 1 addition & 1 deletion src/base/gfx/pathsampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void PathSampler::path(const Geom::Point &pConv0,
auto i = (i0 + i1) / 2.0;
auto pConv = getPoint(i);

const Geom::Triangle triangle(pConv0, pConv, pConv1);
const Geom::Triangle triangle{{pConv0, pConv, pConv1}};
auto area = triangle.area();
auto height = 2 * area / (pConv1 - pConv0).abs();

Expand Down
33 changes: 28 additions & 5 deletions src/base/refl/auto_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Detail
template <class T> using real_t = std::underlying_type_t<T>;

template <class E, real_t<E> From, real_t<E> To>
requires(!std::same_as<bool, real_t<E>>)
consteval std::pair<real_t<E>, real_t<E>> from_to()
{
if constexpr (std::is_signed_v<real_t<E>>
Expand All @@ -46,20 +47,37 @@ consteval std::pair<real_t<E>, real_t<E>> from_to()
return {From, To};
}

template <class E> consteval real_t<E> count()
template <class E, int, int>
requires(std::same_as<bool, real_t<E>>)
consteval std::pair<real_t<E>, real_t<E>> from_to()
{
return {false, false};
}

template <class E>
requires(!std::same_as<bool, real_t<E>>)
consteval real_t<E> count()
{
auto [from, to] = from_to<E, 0, 0>();
return static_cast<real_t<E>>(to - from);
}

template <class E>
requires(std::same_as<bool, real_t<E>>)
consteval int count()
{
return Name::name<E, static_cast<E>(false)>().empty()
? 0
: 1 + !Name::name<E, static_cast<E>(true)>().empty();
}

template <class E>
concept UniqueNames = requires {
static_cast<std::string_view>(unique_enum_names(E{}));
};

template <class E, real_t<E>... Ix>
consteval auto whole_array(
std::integer_sequence<real_t<E>, Ix...> = {})
template <class E, class F = real_t<E>, F... Ix>
consteval auto whole_array(std::integer_sequence<F, Ix...> = {})
{
if constexpr (UniqueNames<E>) {
constexpr std::string_view pre_res = unique_enum_names(E{});
Expand All @@ -84,11 +102,16 @@ consteval auto whole_array(
}
}

template <class E>
template <class E, bool = std::same_as<bool, Detail::real_t<E>>>
constexpr std::array enum_name_holder = Detail::whole_array<E>(
std::make_integer_sequence<Detail::real_t<E>,
Detail::count<E>()>{});

template <class E>
constexpr std::array enum_name_holder<E, true> =
Detail::whole_array<E, int>(
std::make_integer_sequence<int, Detail::count<E>()>{});

template <class E, std::size_t... Ix>
consteval auto get_names(std::index_sequence<Ix...> = {})
{
Expand Down
10 changes: 4 additions & 6 deletions src/chart/animator/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ void Connection::transform(const Gen::Options &source,
Gen::Options &actual,
double factor) const
{
auto sourceIsConnecting =
Vizzu::Gen::isConnecting(source.geometry.get());
auto targetIsConnecting =
Vizzu::Gen::isConnecting(target.geometry.get());
auto sourceIsConnecting = isConnecting(source.geometry.get());
auto targetIsConnecting = isConnecting(target.geometry.get());

if (sourceIsConnecting && !targetIsConnecting) {
actual.orientation = source.orientation;
Expand All @@ -172,8 +170,8 @@ void Connection::transform(const Marker &source,
Marker &actual,
double factor) const
{
actual.prevMainMarkerIdx = interpolate(source.prevMainMarkerIdx,
target.prevMainMarkerIdx,
actual.prevMainMarker = interpolate(source.prevMainMarker,
target.prevMainMarker,
factor);

actual.polarConnection = interpolate(source.polarConnection,
Expand Down
22 changes: 12 additions & 10 deletions src/chart/animator/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ void Planner::createPlan(const Gen::Plot &source,
}

addMorph(SectionId::connection,
getDuration() - getBaseline());
getDuration() == getBaseline()
? step
: getDuration() - getBaseline());

if (animNeeded[SectionId::style])
Morph::StyleMorphFactory(source.getStyle(),
Expand Down Expand Up @@ -287,15 +289,15 @@ void Planner::calcNeeded()
animNeeded[SectionId::x] = needHorizontal();

animNeeded[SectionId::connection] =
anyMarker(+[](const Gen::Marker &source,
const Gen::Marker &target) -> bool
{
return source.prevMainMarkerIdx
!= target.prevMainMarkerIdx
|| source.polarConnection
!= target.polarConnection;
})
|| srcOpt->isHorizontal() != trgOpt->isHorizontal();
(isConnecting(srcOpt->geometry.get())
|| isConnecting(trgOpt->geometry.get()))
&& (anyMarker(+[](const Gen::Marker &source,
const Gen::Marker &target) -> bool
{
return source.prevMainMarker
!= target.prevMainMarker;
})
|| srcOpt->isHorizontal() != trgOpt->isHorizontal());
}

bool Planner::anyMarker(
Expand Down
Loading