Skip to content

Commit dab7d83

Browse files
authored
Merge pull request #4096 from plotly/gl3d-pick-opacity-depth
Gl3d hover bug fix - pick most recent point if two share identical position
2 parents 6a3245b + e1e759b commit dab7d83

File tree

5 files changed

+150
-14
lines changed

5 files changed

+150
-14
lines changed

package-lock.json

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"gl-mat4": "^1.2.0",
8181
"gl-mesh3d": "^2.1.1",
8282
"gl-plot2d": "^1.4.2",
83-
"gl-plot3d": "^2.2.1",
83+
"gl-plot3d": "^2.2.2",
8484
"gl-pointcloud2d": "^1.0.2",
8585
"gl-scatter3d": "^1.2.2",
8686
"gl-select-box": "^1.0.3",
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
0,
6+
1,
7+
1,
8+
0,
9+
0,
10+
1,
11+
1,
12+
0
13+
],
14+
"y": [
15+
0,
16+
0,
17+
1,
18+
1,
19+
0,
20+
0,
21+
1,
22+
1
23+
],
24+
"z": [
25+
0,
26+
0,
27+
0,
28+
0,
29+
0,
30+
0,
31+
0,
32+
0
33+
],
34+
"text": [
35+
"first below",
36+
"second below",
37+
"third below",
38+
"fourth below",
39+
"first above",
40+
"second above",
41+
"third above",
42+
"fourth above"
43+
],
44+
"type": "scatter3d",
45+
"opacity": 0.5,
46+
"marker": {
47+
"opacity": 0.5,
48+
"size": 50
49+
}
50+
},
51+
{
52+
"x": [
53+
0,
54+
1,
55+
1,
56+
0,
57+
0,
58+
1,
59+
1,
60+
0
61+
],
62+
"y": [
63+
0,
64+
0,
65+
1,
66+
1,
67+
0,
68+
0,
69+
1,
70+
1
71+
],
72+
"z": [
73+
1,
74+
1,
75+
1,
76+
1,
77+
1,
78+
1,
79+
1,
80+
1
81+
],
82+
"text": [
83+
"first below",
84+
"second below",
85+
"third below",
86+
"fourth below",
87+
"first above",
88+
"second above",
89+
"third above",
90+
"fourth above"
91+
],
92+
"type": "scatter3d",
93+
"opacity": 0.5,
94+
"marker": {
95+
"opacity": 0.5,
96+
"size": 50
97+
}
98+
}
99+
],
100+
"layout": {
101+
"width": 400,
102+
"height": 400,
103+
"title": {
104+
"text": "hover should generally pick latest<br>points on the same position<br>and display above not below"
105+
}
106+
}
107+
}

test/jasmine/tests/gl3d_hover_click_test.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mock2.data[0].surfaceaxis = 2;
2424
mock2.layout.showlegend = true;
2525

2626
var mock3 = require('@mocks/gl3d_autocolorscale');
27+
var mock4 = require('@mocks/gl3d_transparent_same-depth.json');
2728

2829
describe('Test gl3d trace click/hover:', function() {
2930
var gd, ptData;
@@ -39,13 +40,16 @@ describe('Test gl3d trace click/hover:', function() {
3940
destroyGraphDiv();
4041
});
4142

42-
function assertHoverText(xLabel, yLabel, zLabel, textLabel) {
43+
function assertHoverText(xLabel, yLabel, zLabel, textLabel, traceName) {
4344
var content = [];
4445
if(xLabel) content.push(xLabel);
4546
if(yLabel) content.push(yLabel);
4647
if(zLabel) content.push(zLabel);
4748
if(textLabel) content.push(textLabel);
48-
assertHoverLabelContent({nums: content.join('\n')});
49+
assertHoverLabelContent({
50+
name: traceName,
51+
nums: content.join('\n')
52+
});
4953
}
5054

5155
function assertEventData(x, y, z, curveNumber, pointNumber, extra) {
@@ -539,4 +543,29 @@ describe('Test gl3d trace click/hover:', function() {
539543
.catch(failTest)
540544
.then(done);
541545
});
546+
547+
it('@gl should pick latest & closest points on hover if two points overlap', function(done) {
548+
var _mock = Lib.extendDeep({}, mock4);
549+
550+
function _hover() {
551+
mouseEvent('mouseover', 0, 0);
552+
mouseEvent('mouseover', 200, 200);
553+
}
554+
555+
Plotly.plot(gd, _mock)
556+
.then(delay(20))
557+
.then(function() {
558+
gd.on('plotly_hover', function(eventData) {
559+
ptData = eventData.points[0];
560+
});
561+
})
562+
.then(delay(20))
563+
.then(_hover)
564+
.then(delay(20))
565+
.then(function() {
566+
assertHoverText('x: 1', 'y: 1', 'z: 1', 'third above', 'trace 1');
567+
})
568+
.catch(failTest)
569+
.then(done);
570+
});
542571
});

0 commit comments

Comments
 (0)