Skip to content

Commit

Permalink
Merge pull request #584 from vizzuhq/align_axis_fix
Browse files Browse the repository at this point in the history
Align axis fix
  • Loading branch information
schaumb authored Oct 2, 2024
2 parents d4576d6 + c1b7514 commit a91de27
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fix line-rectangle polar connection linearity.
- Fix all polar connection interpolation (except fading).
- Remove unwanted line connections from line-circle + orientation changed anim.
- Move axis to the center on align: center charts.

## [0.13.0] - 2024-09-13

Expand Down
14 changes: 7 additions & 7 deletions src/chart/animator/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool Planner::needColor() const
}

size_t Planner::dimensionCount(const Gen::Plot *plot,
Gen::ChannelId type)
Gen::AxisId type)
{
return plot->getOptions()
->getChannels()
Expand All @@ -401,15 +401,15 @@ bool Planner::verticalBeforeHorizontal() const
|| !srcOpt->getChannels().anyAxisSet()
|| !trgOpt->getChannels().anyAxisSet()) {
if (srcOpt->getChannels().anyAxisSet())
return srcOpt->subAxisType() == Gen::ChannelId::y;
return srcOpt->subAxisType() == Gen::AxisId::y;
if (trgOpt->getChannels().anyAxisSet())
return trgOpt->mainAxisType() == Gen::ChannelId::y;
return trgOpt->mainAxisType() == Gen::AxisId::y;
}

auto srcXcnt = dimensionCount(source, Gen::ChannelId::x);
auto srcYcnt = dimensionCount(source, Gen::ChannelId::y);
auto trgXcnt = dimensionCount(target, Gen::ChannelId::x);
auto trgYcnt = dimensionCount(target, Gen::ChannelId::y);
auto srcXcnt = dimensionCount(source, Gen::AxisId::x);
auto srcYcnt = dimensionCount(source, Gen::AxisId::y);
auto trgXcnt = dimensionCount(target, Gen::AxisId::x);
auto trgYcnt = dimensionCount(target, Gen::AxisId::y);

if ((trgYcnt != srcYcnt) || (trgXcnt != srcXcnt)) {
return (trgYcnt > srcYcnt) || (trgXcnt < srcXcnt);
Expand Down
2 changes: 1 addition & 1 deletion src/chart/animator/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Planner : public ::Anim::Group
[[nodiscard]] bool positionMorphNeeded() const;
[[nodiscard]] bool verticalBeforeHorizontal() const;
static size_t dimensionCount(const Gen::Plot *plot,
Gen::ChannelId type);
Gen::AxisId type);

[[nodiscard]] bool isAnyLegend(Gen::ChannelId type) const;

Expand Down
19 changes: 13 additions & 6 deletions src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,23 @@ void PlotBuilder::addAlignment(const Buckets &subBuckets) const
{
if (static_cast<bool>(plot->getOptions()->split)) return;

if (std::signbit(
plot->axises.at(plot->getOptions()->subAxisType())
.measure.range.getMin())
|| std::signbit(
plot->axises.at(plot->getOptions()->subAxisType())
.measure.range.getMax()))
auto &subAxisRange =
plot->axises.at(plot->getOptions()->subAxisType())
.measure.range;
if (std::signbit(subAxisRange.getMin())
|| std::signbit(subAxisRange.getMax()))
return;

if (plot->getOptions()->align == Base::Align::Type::none) return;

if (plot->getOptions()->align == Base::Align::Type::center) {
auto &&halfSize = subAxisRange.size() / 2.0;
if (!Math::Floating::is_zero(halfSize))
subAxisRange = Math::Range<double>::Raw(
subAxisRange.getMin() - halfSize,
subAxisRange.getMax() - halfSize);
}

auto &&vectical = !plot->getOptions()->isHorizontal();
const Base::Align align{plot->getOptions()->align,
Math::Range(0.0, 1.0)};
Expand Down
5 changes: 5 additions & 0 deletions src/chart/options/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ ChannelId asChannel(AxisId type)
return static_cast<ChannelId>(static_cast<ChannelIdType>(type));
}

bool operator==(const AxisId &axis, const ChannelId &channel)
{
return asChannel(axis) == channel;
}

Channel Channel::makeChannel(Type id)
{
switch (id) {
Expand Down
3 changes: 3 additions & 0 deletions src/chart/options/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class Channel
std::optional<AxisId> asAxis(ChannelId type);
ChannelId asChannel(AxisId type);

[[nodiscard]] bool operator==(const AxisId &axis,
const ChannelId &channel);

}

#endif
11 changes: 10 additions & 1 deletion src/chart/options/channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ class Channels
const std::span<const ChannelId> &channelTypes) const;

[[nodiscard]] const Channel &at(const ChannelId &id) const;
Channel &at(const ChannelId &id);
[[nodiscard]] Channel &at(const ChannelId &id);

[[nodiscard]] const Channel &at(const AxisId &id) const
{
return at(asChannel(id));
}
[[nodiscard]] Channel &at(const AxisId &id)
{
return at(asChannel(id));
}

void removeSeries(const Data::SeriesIndex &index);

Expand Down
4 changes: 2 additions & 2 deletions src/chart/options/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ChannelId Options::stackChannelType() const
if (channels.anyAxisSet()) {
switch (geometry.get()) {
case ShapeType::area:
case ShapeType::rectangle: return subAxisType();
case ShapeType::rectangle: return asChannel(subAxisType());
default:
case ShapeType::circle:
case ShapeType::line: return ChannelId::size;
Expand All @@ -93,7 +93,7 @@ ChannelId Options::stackChannelType() const
std::optional<ChannelId> Options::secondaryStackType() const
{
if (channels.anyAxisSet() && geometry == ShapeType::line)
return subAxisType();
return asChannel(subAxisType());

return std::nullopt;
}
Expand Down
10 changes: 5 additions & 5 deletions src/chart/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class Options

void reset();

[[nodiscard]] ChannelId mainAxisType() const
[[nodiscard]] AxisId mainAxisType() const
{
return isHorizontal() ? ChannelId::x : ChannelId::y;
return isHorizontal() ? AxisId::x : AxisId::y;
}

[[nodiscard]] bool isHorizontal() const
Expand All @@ -79,9 +79,9 @@ class Options
== Gen::Orientation::horizontal;
}

[[nodiscard]] ChannelId subAxisType() const
[[nodiscard]] AxisId subAxisType() const
{
return isHorizontal() ? ChannelId::y : ChannelId::x;
return isHorizontal() ? AxisId::y : AxisId::x;
}

[[nodiscard]] const Channel &mainAxis() const
Expand Down Expand Up @@ -116,7 +116,7 @@ class Options
[[nodiscard]] bool isSplit() const
{
return split
&& (stackChannelType() != subAxisType() || isStacked());
&& (subAxisType() != stackChannelType() || isStacked());
}

Heading title{std::nullopt};
Expand Down
26 changes: 13 additions & 13 deletions test/e2e/test_cases/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"refs": ["69db5d4"]
},
"basic_animations/someOtherTests/merge_split_area_stream_2dis_1con": {
"refs": ["b1e67de"]
"refs": ["e331f23"]
},
"basic_animations/someOtherTests/total_time_area_bar": {
"refs": ["d908ab5"]
Expand Down Expand Up @@ -506,7 +506,7 @@
"refs": ["08e742c"]
},
"web_content/analytical_operations/compare/stream_stacked": {
"refs": ["8200148"]
"refs": ["845f43a"]
},
"web_content/analytical_operations/compare/waterfall": {
"refs": ["6c43732"]
Expand Down Expand Up @@ -620,10 +620,10 @@
"refs": ["dcff220"]
},
"web_content/analytical_operations/filter/stream_1": {
"refs": ["2710f78"]
"refs": ["4f827d6"]
},
"web_content/analytical_operations/filter/stream_2": {
"refs": ["75719ee"]
"refs": ["9793ec1"]
},
"web_content/analytical_operations/misc/donut_to_coxcomb": {
"refs": ["76f76c6"]
Expand Down Expand Up @@ -770,7 +770,7 @@
"refs": ["4e1f1e8"]
},
"web_content/analytical_operations/sum/stream_stacked": {
"refs": ["9f4e0b4"]
"refs": ["9d0aeee"]
},
"web_content/analytical_operations/sum/treemap": {
"refs": ["d8a8b1c"]
Expand Down Expand Up @@ -800,7 +800,7 @@
"refs": ["bf2c4b9"]
},
"web_content_removed/animated/merge_split_area_stream_3dis_1con": {
"refs": ["305f396"]
"refs": ["c9c9175"]
},
"web_content_removed/animated/merge_split_bar": {
"refs": ["cf60e63"]
Expand Down Expand Up @@ -923,10 +923,10 @@
"refs": ["4bebc47"]
},
"web_content/presets/graph/stream": {
"refs": ["1be4e97"]
"refs": ["83e8724"]
},
"web_content/presets/graph/stream_vertical": {
"refs": ["cc443a6"]
"refs": ["15b5f83"]
},
"web_content/presets/graph/violin": {
"refs": ["683b150"]
Expand Down Expand Up @@ -1037,7 +1037,7 @@
"refs": ["c1a8d39"]
},
"web_content/static/graph/stream_stacked": {
"refs": ["843591b"]
"refs": ["3ab1f0c"]
},
"web_content/static/chart/waterfall": {
"refs": ["2aeab23"]
Expand Down Expand Up @@ -2738,7 +2738,7 @@
"refs": ["9efe1ec"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/circle/08_d-w_cir_2c": {
"refs": ["ac16890"]
"refs": ["940bc39"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/circle_V1/03_d-w_cir_V1": {
"refs": ["327ca16"]
Expand All @@ -2765,7 +2765,7 @@
"refs": ["30f4ada"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/circle_V1/08_d-w_cir_V1_2c": {
"refs": ["1a81ceb"]
"refs": ["cc6ba1d"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/line-rectangle/02_d-d_lin": {
"refs": ["64361fc"]
Expand Down Expand Up @@ -3065,10 +3065,10 @@
"refs": ["52a2da9"]
},
"ww_samples_for_presets/cartesian_coo_sys/32_C_A_stream_graph": {
"refs": ["9d218d6"]
"refs": ["dd86c4e"]
},
"ww_samples_for_presets/cartesian_coo_sys/33_C_A_stream_graph_vert": {
"refs": ["14a0296"]
"refs": ["bd982e1"]
},
"ww_samples_for_presets/cartesian_coo_sys/34_C_A_violin_graph": {
"refs": ["0cddf74"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const testSteps = [
noop: null,
size: { set: ['Year', 'Country'] }
},
title: 'Stack Discs',
align: 'center'
title: 'Stack Discs'
}
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const testSteps = [
noop: null,
size: { set: ['Year', 'Country'] }
},
title: 'Stack Discs',
align: 'center'
title: 'Stack Discs'
}
}),

Expand Down

0 comments on commit a91de27

Please sign in to comment.