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

Wrong y axis label position for line/circle in case of both axis dimension #511

Merged
merged 6 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- next() can be called multiple times from Plugin hooks
- Line and circle chats with only dimensions on x, and y axes the markers were off the axis labels.

### Added

Expand Down
16 changes: 16 additions & 0 deletions src/chart/animator/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ bool Planner::needVertical() const
!= target->dimensionAxises.at(
Gen::ChannelId::size)))
|| source->anyAxisSet != target->anyAxisSet
|| (source->markerConnectionOrientation
!= target->markerConnectionOrientation
&& ((source->markerConnectionOrientation.value_or(
Gen::Orientation::horizontal)
== Gen::Orientation::vertical)
|| (target->markerConnectionOrientation.value_or(
Gen::Orientation::horizontal)
== Gen::Orientation::vertical)))
|| anyMarker(
[&](const auto &source, const auto &target)
{
Expand All @@ -434,6 +442,14 @@ bool Planner::needHorizontal() const
!= target->guides.at(Gen::ChannelId::x)
|| source->anyAxisSet != target->anyAxisSet
|| source->keepAspectRatio != target->keepAspectRatio
|| (source->markerConnectionOrientation
!= target->markerConnectionOrientation
&& ((source->markerConnectionOrientation.value_or(
Gen::Orientation::vertical)
== Gen::Orientation::horizontal)
|| (target->markerConnectionOrientation.value_or(
Gen::Orientation::vertical)
== Gen::Orientation::horizontal)))
|| anyMarker(
[&](const auto &source, const auto &target)
{
Expand Down
30 changes: 17 additions & 13 deletions src/chart/generator/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ Marker::Marker(const Options &options,
}

auto horizontal = options.isHorizontal();
auto lineOrCircle = options.geometry == ShapeType::line
|| options.geometry == ShapeType::circle;
auto polar = options.coordSystem.get() == CoordSystem::polar;

position.x = size.x = getValueForChannel(channels,
ChannelId::x,
data,
stats,
options.subAxisOf(ChannelId::x),
!horizontal && stackInhibitingShape);

spacing.x = (horizontal && options.getChannels().anyAxisSet()
&& channels.at(ChannelId::x).isDimension())
spacing.x = (horizontal || (lineOrCircle && !polar))
&& options.getChannels().anyAxisSet()
&& channels.at(ChannelId::x).isDimension()
? 1
: 0;

Expand All @@ -83,8 +88,9 @@ Marker::Marker(const Options &options,
options.subAxisOf(ChannelId::y),
horizontal && stackInhibitingShape);

spacing.y = (!horizontal && options.getChannels().anyAxisSet()
&& channels.at(ChannelId::y).isDimension())
spacing.y = (!horizontal || lineOrCircle)
&& options.getChannels().anyAxisSet()
&& channels.at(ChannelId::y).isDimension()
? 1
: 0;

Expand All @@ -110,20 +116,18 @@ Marker::Marker(const Options &options,
}

void Marker::setNextMarker(uint64_t itemId,
Marker *marker,
Marker &marker,
bool horizontal,
bool main)
{
if (marker) {
(main ? nextMainMarkerIdx : nextSubMarkerIdx) = marker->idx;
(main ? nextMainMarkerIdx : nextSubMarkerIdx) = marker.idx;

if (main) marker->prevMainMarkerIdx = idx;
if (main) marker.prevMainMarkerIdx = idx;

if (itemId != 0) {
double Geom::Point::*const coord =
horizontal ? &Geom::Point::x : &Geom::Point::y;
marker->position.*coord += position.*coord;
}
if (itemId != 0) {
double Geom::Point::*const coord =
horizontal ? &Geom::Point::x : &Geom::Point::y;
marker.position.*coord += position.*coord;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Marker
::Anim::Interpolated<uint64_t> nextSubMarkerIdx;

void setNextMarker(uint64_t itemId,
Marker *marker,
Marker &marker,
bool horizontal,
bool main);
void resetSize(bool horizontal);
Expand Down
18 changes: 15 additions & 3 deletions src/chart/generator/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,15 @@ void Plot::generateMarkers(const Data::DataTable &table)
}
clearEmptyBuckets(mainBuckets, true);
clearEmptyBuckets(subBuckets, false);
linkMarkers(mainBuckets, true);
auto conn = linkMarkers(mainBuckets, true);
schaumb marked this conversation as resolved.
Show resolved Hide resolved
linkMarkers(subBuckets, false);

if (conn && options->geometry.get() == ShapeType::line
&& options->getChannels().at(ChannelId::x).isDimension()
&& options->getChannels().at(ChannelId::y).isDimension()) {
markerConnectionOrientation.emplace(
*options->orientation.get());
}
}

void Plot::generateMarkersInfo()
Expand Down Expand Up @@ -232,10 +239,11 @@ void Plot::clearEmptyBuckets(const Buckets &buckets, bool main)
}
}

void Plot::linkMarkers(const Buckets &buckets, bool main)
bool Plot::linkMarkers(const Buckets &buckets, bool main)
{
auto sorted = sortedBuckets(buckets, main);

bool hasConnection{};
for (const auto &pair : buckets) {
const auto &bucket = pair.second;

Expand All @@ -246,12 +254,16 @@ void Plot::linkMarkers(const Buckets &buckets, bool main)
auto iNext = (i + 1) % sorted.size();
auto idNext = sorted[iNext].first;
auto indexNext = bucket.at(idNext);
auto &next = markers[indexNext];
act.setNextMarker(iNext,
&markers[indexNext],
next,
options->isHorizontal() == main,
main);
if (act.enabled && next.enabled && indexAct != indexNext)
hasConnection = true;
}
}
return hasConnection;
}

void Plot::normalizeXY()
Expand Down
3 changes: 2 additions & 1 deletion src/chart/generator/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Plot
Guides guides;
DimensionAxises dimensionAxises;
Math::FuzzyBool keepAspectRatio;
std::optional<Orientation> markerConnectionOrientation;

Plot(const Plot &other) = default;
Plot(PlotOptionsPtr options, const Plot &other);
Expand Down Expand Up @@ -124,7 +125,7 @@ class Plot

void generateMarkers(const Data::DataTable &table);
void generateMarkersInfo();
void linkMarkers(const Buckets &buckets, bool main);
bool linkMarkers(const Buckets &buckets, bool main);
void normalizeXY();
void calcMeasureAxises(const Data::DataTable &dataTable);
void calcMeasureAxis(ChannelId type,
Expand Down
Loading