Skip to content

Commit a91de27

Browse files
authored
Merge pull request #584 from vizzuhq/align_axis_fix
Align axis fix
2 parents d4576d6 + c1b7514 commit a91de27

File tree

12 files changed

+62
-39
lines changed

12 files changed

+62
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix line-rectangle polar connection linearity.
1313
- Fix all polar connection interpolation (except fading).
1414
- Remove unwanted line connections from line-circle + orientation changed anim.
15+
- Move axis to the center on align: center charts.
1516

1617
## [0.13.0] - 2024-09-13
1718

src/chart/animator/planner.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ bool Planner::needColor() const
383383
}
384384

385385
size_t Planner::dimensionCount(const Gen::Plot *plot,
386-
Gen::ChannelId type)
386+
Gen::AxisId type)
387387
{
388388
return plot->getOptions()
389389
->getChannels()
@@ -401,15 +401,15 @@ bool Planner::verticalBeforeHorizontal() const
401401
|| !srcOpt->getChannels().anyAxisSet()
402402
|| !trgOpt->getChannels().anyAxisSet()) {
403403
if (srcOpt->getChannels().anyAxisSet())
404-
return srcOpt->subAxisType() == Gen::ChannelId::y;
404+
return srcOpt->subAxisType() == Gen::AxisId::y;
405405
if (trgOpt->getChannels().anyAxisSet())
406-
return trgOpt->mainAxisType() == Gen::ChannelId::y;
406+
return trgOpt->mainAxisType() == Gen::AxisId::y;
407407
}
408408

409-
auto srcXcnt = dimensionCount(source, Gen::ChannelId::x);
410-
auto srcYcnt = dimensionCount(source, Gen::ChannelId::y);
411-
auto trgXcnt = dimensionCount(target, Gen::ChannelId::x);
412-
auto trgYcnt = dimensionCount(target, Gen::ChannelId::y);
409+
auto srcXcnt = dimensionCount(source, Gen::AxisId::x);
410+
auto srcYcnt = dimensionCount(source, Gen::AxisId::y);
411+
auto trgXcnt = dimensionCount(target, Gen::AxisId::x);
412+
auto trgYcnt = dimensionCount(target, Gen::AxisId::y);
413413

414414
if ((trgYcnt != srcYcnt) || (trgXcnt != srcXcnt)) {
415415
return (trgYcnt > srcYcnt) || (trgXcnt < srcXcnt);

src/chart/animator/planner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Planner : public ::Anim::Group
5050
[[nodiscard]] bool positionMorphNeeded() const;
5151
[[nodiscard]] bool verticalBeforeHorizontal() const;
5252
static size_t dimensionCount(const Gen::Plot *plot,
53-
Gen::ChannelId type);
53+
Gen::AxisId type);
5454

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

src/chart/generator/plotbuilder.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,23 @@ void PlotBuilder::addAlignment(const Buckets &subBuckets) const
477477
{
478478
if (static_cast<bool>(plot->getOptions()->split)) return;
479479

480-
if (std::signbit(
481-
plot->axises.at(plot->getOptions()->subAxisType())
482-
.measure.range.getMin())
483-
|| std::signbit(
484-
plot->axises.at(plot->getOptions()->subAxisType())
485-
.measure.range.getMax()))
480+
auto &subAxisRange =
481+
plot->axises.at(plot->getOptions()->subAxisType())
482+
.measure.range;
483+
if (std::signbit(subAxisRange.getMin())
484+
|| std::signbit(subAxisRange.getMax()))
486485
return;
487486

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

489+
if (plot->getOptions()->align == Base::Align::Type::center) {
490+
auto &&halfSize = subAxisRange.size() / 2.0;
491+
if (!Math::Floating::is_zero(halfSize))
492+
subAxisRange = Math::Range<double>::Raw(
493+
subAxisRange.getMin() - halfSize,
494+
subAxisRange.getMax() - halfSize);
495+
}
496+
490497
auto &&vectical = !plot->getOptions()->isHorizontal();
491498
const Base::Align align{plot->getOptions()->align,
492499
Math::Range(0.0, 1.0)};

src/chart/options/channel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ ChannelId asChannel(AxisId type)
2929
return static_cast<ChannelId>(static_cast<ChannelIdType>(type));
3030
}
3131

32+
bool operator==(const AxisId &axis, const ChannelId &channel)
33+
{
34+
return asChannel(axis) == channel;
35+
}
36+
3237
Channel Channel::makeChannel(Type id)
3338
{
3439
switch (id) {

src/chart/options/channel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Channel
9393
std::optional<AxisId> asAxis(ChannelId type);
9494
ChannelId asChannel(AxisId type);
9595

96+
[[nodiscard]] bool operator==(const AxisId &axis,
97+
const ChannelId &channel);
98+
9699
}
97100

98101
#endif

src/chart/options/channels.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ class Channels
3131
const std::span<const ChannelId> &channelTypes) const;
3232

3333
[[nodiscard]] const Channel &at(const ChannelId &id) const;
34-
Channel &at(const ChannelId &id);
34+
[[nodiscard]] Channel &at(const ChannelId &id);
35+
36+
[[nodiscard]] const Channel &at(const AxisId &id) const
37+
{
38+
return at(asChannel(id));
39+
}
40+
[[nodiscard]] Channel &at(const AxisId &id)
41+
{
42+
return at(asChannel(id));
43+
}
3544

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

src/chart/options/options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ChannelId Options::stackChannelType() const
8181
if (channels.anyAxisSet()) {
8282
switch (geometry.get()) {
8383
case ShapeType::area:
84-
case ShapeType::rectangle: return subAxisType();
84+
case ShapeType::rectangle: return asChannel(subAxisType());
8585
default:
8686
case ShapeType::circle:
8787
case ShapeType::line: return ChannelId::size;
@@ -93,7 +93,7 @@ ChannelId Options::stackChannelType() const
9393
std::optional<ChannelId> Options::secondaryStackType() const
9494
{
9595
if (channels.anyAxisSet() && geometry == ShapeType::line)
96-
return subAxisType();
96+
return asChannel(subAxisType());
9797

9898
return std::nullopt;
9999
}

src/chart/options/options.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class Options
6666

6767
void reset();
6868

69-
[[nodiscard]] ChannelId mainAxisType() const
69+
[[nodiscard]] AxisId mainAxisType() const
7070
{
71-
return isHorizontal() ? ChannelId::x : ChannelId::y;
71+
return isHorizontal() ? AxisId::x : AxisId::y;
7272
}
7373

7474
[[nodiscard]] bool isHorizontal() const
@@ -79,9 +79,9 @@ class Options
7979
== Gen::Orientation::horizontal;
8080
}
8181

82-
[[nodiscard]] ChannelId subAxisType() const
82+
[[nodiscard]] AxisId subAxisType() const
8383
{
84-
return isHorizontal() ? ChannelId::y : ChannelId::x;
84+
return isHorizontal() ? AxisId::y : AxisId::x;
8585
}
8686

8787
[[nodiscard]] const Channel &mainAxis() const
@@ -116,7 +116,7 @@ class Options
116116
[[nodiscard]] bool isSplit() const
117117
{
118118
return split
119-
&& (stackChannelType() != subAxisType() || isStacked());
119+
&& (subAxisType() != stackChannelType() || isStacked());
120120
}
121121

122122
Heading title{std::nullopt};

test/e2e/test_cases/test_cases.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"refs": ["69db5d4"]
114114
},
115115
"basic_animations/someOtherTests/merge_split_area_stream_2dis_1con": {
116-
"refs": ["b1e67de"]
116+
"refs": ["e331f23"]
117117
},
118118
"basic_animations/someOtherTests/total_time_area_bar": {
119119
"refs": ["d908ab5"]
@@ -506,7 +506,7 @@
506506
"refs": ["08e742c"]
507507
},
508508
"web_content/analytical_operations/compare/stream_stacked": {
509-
"refs": ["8200148"]
509+
"refs": ["845f43a"]
510510
},
511511
"web_content/analytical_operations/compare/waterfall": {
512512
"refs": ["6c43732"]
@@ -620,10 +620,10 @@
620620
"refs": ["dcff220"]
621621
},
622622
"web_content/analytical_operations/filter/stream_1": {
623-
"refs": ["2710f78"]
623+
"refs": ["4f827d6"]
624624
},
625625
"web_content/analytical_operations/filter/stream_2": {
626-
"refs": ["75719ee"]
626+
"refs": ["9793ec1"]
627627
},
628628
"web_content/analytical_operations/misc/donut_to_coxcomb": {
629629
"refs": ["76f76c6"]
@@ -770,7 +770,7 @@
770770
"refs": ["4e1f1e8"]
771771
},
772772
"web_content/analytical_operations/sum/stream_stacked": {
773-
"refs": ["9f4e0b4"]
773+
"refs": ["9d0aeee"]
774774
},
775775
"web_content/analytical_operations/sum/treemap": {
776776
"refs": ["d8a8b1c"]
@@ -800,7 +800,7 @@
800800
"refs": ["bf2c4b9"]
801801
},
802802
"web_content_removed/animated/merge_split_area_stream_3dis_1con": {
803-
"refs": ["305f396"]
803+
"refs": ["c9c9175"]
804804
},
805805
"web_content_removed/animated/merge_split_bar": {
806806
"refs": ["cf60e63"]
@@ -923,10 +923,10 @@
923923
"refs": ["4bebc47"]
924924
},
925925
"web_content/presets/graph/stream": {
926-
"refs": ["1be4e97"]
926+
"refs": ["83e8724"]
927927
},
928928
"web_content/presets/graph/stream_vertical": {
929-
"refs": ["cc443a6"]
929+
"refs": ["15b5f83"]
930930
},
931931
"web_content/presets/graph/violin": {
932932
"refs": ["683b150"]
@@ -1037,7 +1037,7 @@
10371037
"refs": ["c1a8d39"]
10381038
},
10391039
"web_content/static/graph/stream_stacked": {
1040-
"refs": ["843591b"]
1040+
"refs": ["3ab1f0c"]
10411041
},
10421042
"web_content/static/chart/waterfall": {
10431043
"refs": ["2aeab23"]
@@ -2738,7 +2738,7 @@
27382738
"refs": ["9efe1ec"]
27392739
},
27402740
"ww_noFade/wNoFade_cases/2_des_pol-without/circle/08_d-w_cir_2c": {
2741-
"refs": ["ac16890"]
2741+
"refs": ["940bc39"]
27422742
},
27432743
"ww_noFade/wNoFade_cases/2_des_pol-without/circle_V1/03_d-w_cir_V1": {
27442744
"refs": ["327ca16"]
@@ -2765,7 +2765,7 @@
27652765
"refs": ["30f4ada"]
27662766
},
27672767
"ww_noFade/wNoFade_cases/2_des_pol-without/circle_V1/08_d-w_cir_V1_2c": {
2768-
"refs": ["1a81ceb"]
2768+
"refs": ["cc6ba1d"]
27692769
},
27702770
"ww_noFade/wNoFade_cases/2_des_pol-without/line-rectangle/02_d-d_lin": {
27712771
"refs": ["64361fc"]
@@ -3065,10 +3065,10 @@
30653065
"refs": ["52a2da9"]
30663066
},
30673067
"ww_samples_for_presets/cartesian_coo_sys/32_C_A_stream_graph": {
3068-
"refs": ["9d218d6"]
3068+
"refs": ["dd86c4e"]
30693069
},
30703070
"ww_samples_for_presets/cartesian_coo_sys/33_C_A_stream_graph_vert": {
3071-
"refs": ["14a0296"]
3071+
"refs": ["bd982e1"]
30723072
},
30733073
"ww_samples_for_presets/cartesian_coo_sys/34_C_A_violin_graph": {
30743074
"refs": ["0cddf74"]

0 commit comments

Comments
 (0)