Skip to content

Commit e7f38c0

Browse files
authored
Merge pull request #4539 from plotly/mesh3d-hover-on-face-data
Fix hover of mesh3d traces with face color and face intensity
2 parents 71e87e6 + d1cb618 commit e7f38c0

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

package-lock.json

+3-3
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-heatmap2d": "^1.0.5",
8181
"gl-line3d": "^1.1.11",
8282
"gl-mat4": "^1.2.0",
83-
"gl-mesh3d": "^2.2.1",
83+
"gl-mesh3d": "^2.3.0",
8484
"gl-plot2d": "^1.4.2",
8585
"gl-plot3d": "^2.4.0",
8686
"gl-pointcloud2d": "^1.0.2",

src/traces/mesh3d/convert.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ proto.handlePick = function(selection) {
3434
if(selection.object === this.mesh) {
3535
var selectIndex = selection.index = selection.data.index;
3636

37-
selection.traceCoordinate = [
38-
this.data.x[selectIndex],
39-
this.data.y[selectIndex],
40-
this.data.z[selectIndex]
41-
];
37+
if(selection.data._cellCenter) {
38+
selection.traceCoordinate = selection.data.dataCoordinate;
39+
} else {
40+
selection.traceCoordinate = [
41+
this.data.x[selectIndex],
42+
this.data.y[selectIndex],
43+
this.data.z[selectIndex]
44+
];
45+
}
4246

4347
var text = this.data.hovertext || this.data.text;
4448
if(Array.isArray(text) && text[selectIndex] !== undefined) {

test/image/mocks/gl3d_mesh3d_cell-intensity.json

+1
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,7 @@
20202020
"lighting": {
20212021
"facenormalsepsilon": 0
20222022
},
2023+
"hovertemplate": "x: %{x}<br>y: %{y}<br>z: %{z}<br>cell intensity: %{intensity}",
20232024
"type": "mesh3d"
20242025
}
20252026
],

test/jasmine/tests/gl3d_hover_click_test.js

+43-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
1414

1515
var mock = require('@mocks/gl3d_marker-arrays.json');
1616
var mesh3dcoloringMock = require('@mocks/gl3d_mesh3d_coloring.json');
17+
var mesh3dcellIntensityMock = require('@mocks/gl3d_mesh3d_cell-intensity.json');
1718
var multipleScatter3dMock = require('@mocks/gl3d_multiple-scatter3d-traces.json');
1819

1920
// lines, markers, text, error bars and surfaces each
@@ -554,10 +555,10 @@ describe('Test gl3d trace click/hover:', function() {
554555
.then(delay(20))
555556
.then(function() {
556557
assertHoverText(
557-
'x: 1',
558-
'y: 0',
558+
'x: 0.6666667',
559+
'y: 0.3333333',
559560
'z: 1',
560-
'face color: #0F0',
561+
'face color: #00F',
561562
'face color'
562563
);
563564
})
@@ -566,8 +567,8 @@ describe('Test gl3d trace click/hover:', function() {
566567
.then(function() {
567568
assertHoverText(
568569
'x: 1',
569-
'y: 1',
570-
'z: 1',
570+
'y: 0.3333333',
571+
'z: 0.6666667',
571572
'face color: #0FF',
572573
'face color'
573574
);
@@ -577,27 +578,58 @@ describe('Test gl3d trace click/hover:', function() {
577578
.then(function() {
578579
assertHoverText(
579580
'x: 1',
580-
'y: 1',
581-
'z: 0',
582-
'face color: #00F',
581+
'y: 0.6666667',
582+
'z: 0.3333333',
583+
'face color: #0FF',
583584
'face color'
584585
);
585586
})
586587
.then(function() { mouseEvent('mouseover', 200, 300); })
587588
.then(delay(20))
588589
.then(function() {
589590
assertHoverText(
590-
'x: 0',
591+
'x: 0.6666667',
591592
'y: 0',
592-
'z: 0',
593-
'face color: #000',
593+
'z: 0.3333333',
594+
'face color: #F00',
594595
'face color'
595596
);
596597
})
597598
.catch(failTest)
598599
.then(done);
599600
});
600601

602+
it('@gl should display correct face intensities', function(done) {
603+
var fig = mesh3dcellIntensityMock;
604+
605+
Plotly.newPlot(gd, fig)
606+
.then(delay(20))
607+
.then(function() { mouseEvent('mouseover', 200, 200); })
608+
.then(delay(20))
609+
.then(function() {
610+
assertHoverText(
611+
'x: 0.4666667',
612+
'y: 0.4333333',
613+
'z: 0.01583333',
614+
'cell intensity: 0.16',
615+
'trace 0'
616+
);
617+
})
618+
.then(function() { mouseEvent('mouseover', 200, 300); })
619+
.then(delay(20))
620+
.then(function() {
621+
assertHoverText(
622+
'x: 0.7666667',
623+
'y: 0.1333333',
624+
'z: −0.3305',
625+
'cell intensity: 3.04',
626+
'trace 0'
627+
);
628+
})
629+
.catch(failTest)
630+
.then(done);
631+
});
632+
601633
it('@gl should pick latest & closest points on hover if two points overlap', function(done) {
602634
var _mock = Lib.extendDeep({}, mock4);
603635

0 commit comments

Comments
 (0)