Skip to content

Commit

Permalink
Merge pull request #536 from vizzuhq/fix-marker-behaviour-3
Browse files Browse the repository at this point in the history
Fix marker behaviour on coordSys change
  • Loading branch information
schaumb authored May 31, 2024
2 parents 7a1cfd3 + e40756d commit 9e80091
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Add missing canvas change function in htmlcanvas plugin.
- On split charts the first range was not part of the separation calculation.
- When the first marker was disabled it was calculated as an enabled marker on the XY normalization.
- Sorted or reversed marker connections behaved chaotic at coordinate system change.

## [0.11.0] - 2024-05-23

Expand Down
4 changes: 3 additions & 1 deletion src/chart/animator/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ void Connection::transform(const Marker &source,
target.prevMainMarkerIdx,
factor);

actual.mainId = interpolate(source.mainId, target.mainId, factor);
actual.polarConnection = interpolate(source.polarConnection,
target.polarConnection,
factor);
}

void Vertical::transform(const Gen::Plot &source,
Expand Down
3 changes: 2 additions & 1 deletion src/chart/animator/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ void Planner::calcNeeded()
{
return source.prevMainMarkerIdx
!= target.prevMainMarkerIdx
|| source.mainId != target.mainId;
|| source.polarConnection
!= target.polarConnection;
})
|| srcOpt->isHorizontal() != trgOpt->isHorizontal();
}
Expand Down
12 changes: 4 additions & 8 deletions src/chart/generator/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Marker::Marker(const Options &options,
data,
stats,
index,
horizontal ? &mainId->value : subAxisId);
horizontal ? &mainId : subAxisId);

auto yChannelRectDim =
channels.at(ChannelId::y).isDimension()
Expand All @@ -93,7 +93,7 @@ Marker::Marker(const Options &options,
data,
stats,
index,
!horizontal ? &mainId->value : subAxisId);
!horizontal ? &mainId : subAxisId);

auto xChannelRectDim =
channels.at(ChannelId::x).isDimension()
Expand Down Expand Up @@ -127,15 +127,15 @@ void Marker::setNextMarker(bool first,
bool horizontal,
bool main)
{
(main ? nextMainMarkerIdx : nextSubMarkerIdx) = marker.idx;

if (main) marker.prevMainMarkerIdx = idx;

if (!first) {
double Geom::Point::*const coord =
horizontal ? &Geom::Point::x : &Geom::Point::y;
marker.position.*coord += position.*coord;
}
else if (main && this != &marker)
marker.polarConnection = true;
}

void Marker::resetSize(bool horizontal)
Expand All @@ -150,10 +150,6 @@ void Marker::setIdOffset(size_t offset)
{
if (prevMainMarkerIdx.hasOneValue())
prevMainMarkerIdx->value += offset;
if (nextMainMarkerIdx.hasOneValue())
nextMainMarkerIdx->value += offset;
if (nextSubMarkerIdx.hasOneValue())
nextSubMarkerIdx->value += offset;
}

Conv::JSONObj &&Marker::appendToJSON(Conv::JSONObj &&jsonObj) const
Expand Down
5 changes: 2 additions & 3 deletions src/chart/generator/marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ class Marker

using Id = Data::MarkerId;

::Anim::Interpolated<Id> mainId;
Id mainId;
Id subId;
Id sizeId;

MarkerIndex idx;
::Anim::Interpolated<MarkerIndex> prevMainMarkerIdx;
::Anim::Interpolated<MarkerIndex> nextMainMarkerIdx;
::Anim::Interpolated<MarkerIndex> nextSubMarkerIdx;
::Anim::Interpolated<bool> polarConnection;

void setNextMarker(bool first,
Marker &marker,
Expand Down
6 changes: 3 additions & 3 deletions src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Buckets PlotBuilder::generateMarkers(std::size_t &mainBucketSize)
markerId,
needInfo);

mainBuckets[marker.mainId.get().seriesId]
[marker.mainId.get().itemId] = &marker;
mainBuckets[marker.mainId.seriesId][marker.mainId.itemId] =
&marker;
subBuckets[marker.subId.seriesId][marker.subId.itemId] =
&marker;

Expand Down Expand Up @@ -339,7 +339,7 @@ void PlotBuilder::calcDimensionAxis(ChannelId type)
const auto &id =
(type == ChannelId::x)
== plot->getOptions()->isHorizontal()
? marker.mainId.get()
? marker.mainId
: marker.subId;

if (const auto &slice = id.label)
Expand Down
5 changes: 2 additions & 3 deletions src/chart/rendering/markers/connectingmarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
enabled && (marker.enabled || prev->enabled);
connected =
connected && (prev->enabled || marker.enabled);
if (prev->mainId.get_or_first(lineIndex).value.itemId
> marker.mainId.get_or_first(lineIndex)
.value.itemId) {
if (marker.polarConnection.get_or_first(lineIndex)
.value) {
linear = linear || polar.more();
connected = connected && polar.more() && horizontal;
enabled = enabled && polar && horizontal;
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/tests/fixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"530": {
"refs": ["1ad4684"]
},
"536": {
"refs": ["05d387c"]
},
"32303048": {
"refs": ["b5d95ea"]
},
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/tests/fixes/536.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const testSteps = [
(chart) =>
chart.animate({
data: {
series: [
{ name: 'Foo', values: ['Alice', 'Bob', 'Ted', 'Jonas'] },
{ name: 'Bar', values: [15, 32, 12, 55] }
]
}
}),
(chart) =>
chart.animate({
channels: {
x: 'Foo',
y: 'Bar'
},
geometry: 'area',
reverse: true
}),

(chart) =>
chart.animate({
coordSystem: 'polar'
}),
(chart) =>
chart.animate({
coordSystem: 'cartesian',
geometry: 'line',
sort: 'byValue'
}),
(chart) =>
chart.animate({
reverse: false
})
]

export default testSteps

0 comments on commit 9e80091

Please sign in to comment.