Skip to content

Commit 9e80091

Browse files
authored
Merge pull request #536 from vizzuhq/fix-marker-behaviour-3
Fix marker behaviour on coordSys change
2 parents 7a1cfd3 + e40756d commit 9e80091

File tree

9 files changed

+57
-19
lines changed

9 files changed

+57
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Add missing canvas change function in htmlcanvas plugin.
1212
- On split charts the first range was not part of the separation calculation.
1313
- When the first marker was disabled it was calculated as an enabled marker on the XY normalization.
14+
- Sorted or reversed marker connections behaved chaotic at coordinate system change.
1415

1516
## [0.11.0] - 2024-05-23
1617

src/chart/animator/morph.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ void Connection::transform(const Marker &source,
176176
target.prevMainMarkerIdx,
177177
factor);
178178

179-
actual.mainId = interpolate(source.mainId, target.mainId, factor);
179+
actual.polarConnection = interpolate(source.polarConnection,
180+
target.polarConnection,
181+
factor);
180182
}
181183

182184
void Vertical::transform(const Gen::Plot &source,

src/chart/animator/planner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ void Planner::calcNeeded()
292292
{
293293
return source.prevMainMarkerIdx
294294
!= target.prevMainMarkerIdx
295-
|| source.mainId != target.mainId;
295+
|| source.polarConnection
296+
!= target.polarConnection;
296297
})
297298
|| srcOpt->isHorizontal() != trgOpt->isHorizontal();
298299
}

src/chart/generator/marker.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Marker::Marker(const Options &options,
7373
data,
7474
stats,
7575
index,
76-
horizontal ? &mainId->value : subAxisId);
76+
horizontal ? &mainId : subAxisId);
7777

7878
auto yChannelRectDim =
7979
channels.at(ChannelId::y).isDimension()
@@ -93,7 +93,7 @@ Marker::Marker(const Options &options,
9393
data,
9494
stats,
9595
index,
96-
!horizontal ? &mainId->value : subAxisId);
96+
!horizontal ? &mainId : subAxisId);
9797

9898
auto xChannelRectDim =
9999
channels.at(ChannelId::x).isDimension()
@@ -127,15 +127,15 @@ void Marker::setNextMarker(bool first,
127127
bool horizontal,
128128
bool main)
129129
{
130-
(main ? nextMainMarkerIdx : nextSubMarkerIdx) = marker.idx;
131-
132130
if (main) marker.prevMainMarkerIdx = idx;
133131

134132
if (!first) {
135133
double Geom::Point::*const coord =
136134
horizontal ? &Geom::Point::x : &Geom::Point::y;
137135
marker.position.*coord += position.*coord;
138136
}
137+
else if (main && this != &marker)
138+
marker.polarConnection = true;
139139
}
140140

141141
void Marker::resetSize(bool horizontal)
@@ -150,10 +150,6 @@ void Marker::setIdOffset(size_t offset)
150150
{
151151
if (prevMainMarkerIdx.hasOneValue())
152152
prevMainMarkerIdx->value += offset;
153-
if (nextMainMarkerIdx.hasOneValue())
154-
nextMainMarkerIdx->value += offset;
155-
if (nextSubMarkerIdx.hasOneValue())
156-
nextSubMarkerIdx->value += offset;
157153
}
158154

159155
Conv::JSONObj &&Marker::appendToJSON(Conv::JSONObj &&jsonObj) const

src/chart/generator/marker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ class Marker
5454

5555
using Id = Data::MarkerId;
5656

57-
::Anim::Interpolated<Id> mainId;
57+
Id mainId;
5858
Id subId;
5959
Id sizeId;
6060

6161
MarkerIndex idx;
6262
::Anim::Interpolated<MarkerIndex> prevMainMarkerIdx;
63-
::Anim::Interpolated<MarkerIndex> nextMainMarkerIdx;
64-
::Anim::Interpolated<MarkerIndex> nextSubMarkerIdx;
63+
::Anim::Interpolated<bool> polarConnection;
6564

6665
void setNextMarker(bool first,
6766
Marker &marker,

src/chart/generator/plotbuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ Buckets PlotBuilder::generateMarkers(std::size_t &mainBucketSize)
9797
markerId,
9898
needInfo);
9999

100-
mainBuckets[marker.mainId.get().seriesId]
101-
[marker.mainId.get().itemId] = &marker;
100+
mainBuckets[marker.mainId.seriesId][marker.mainId.itemId] =
101+
&marker;
102102
subBuckets[marker.subId.seriesId][marker.subId.itemId] =
103103
&marker;
104104

@@ -339,7 +339,7 @@ void PlotBuilder::calcDimensionAxis(ChannelId type)
339339
const auto &id =
340340
(type == ChannelId::x)
341341
== plot->getOptions()->isHorizontal()
342-
? marker.mainId.get()
342+
? marker.mainId
343343
: marker.subId;
344344

345345
if (const auto &slice = id.label)

src/chart/rendering/markers/connectingmarker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
4343
enabled && (marker.enabled || prev->enabled);
4444
connected =
4545
connected && (prev->enabled || marker.enabled);
46-
if (prev->mainId.get_or_first(lineIndex).value.itemId
47-
> marker.mainId.get_or_first(lineIndex)
48-
.value.itemId) {
46+
if (marker.polarConnection.get_or_first(lineIndex)
47+
.value) {
4948
linear = linear || polar.more();
5049
connected = connected && polar.more() && horizontal;
5150
enabled = enabled && polar && horizontal;

test/e2e/tests/fixes.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"530": {
3232
"refs": ["1ad4684"]
3333
},
34+
"536": {
35+
"refs": ["05d387c"]
36+
},
3437
"32303048": {
3538
"refs": ["b5d95ea"]
3639
},

test/e2e/tests/fixes/536.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const testSteps = [
2+
(chart) =>
3+
chart.animate({
4+
data: {
5+
series: [
6+
{ name: 'Foo', values: ['Alice', 'Bob', 'Ted', 'Jonas'] },
7+
{ name: 'Bar', values: [15, 32, 12, 55] }
8+
]
9+
}
10+
}),
11+
(chart) =>
12+
chart.animate({
13+
channels: {
14+
x: 'Foo',
15+
y: 'Bar'
16+
},
17+
geometry: 'area',
18+
reverse: true
19+
}),
20+
21+
(chart) =>
22+
chart.animate({
23+
coordSystem: 'polar'
24+
}),
25+
(chart) =>
26+
chart.animate({
27+
coordSystem: 'cartesian',
28+
geometry: 'line',
29+
sort: 'byValue'
30+
}),
31+
(chart) =>
32+
chart.animate({
33+
reverse: false
34+
})
35+
]
36+
37+
export default testSteps

0 commit comments

Comments
 (0)