Skip to content

Commit 7332d23

Browse files
committed
set selection.index during gl3d trace handlePick
- so that it reflect the user input indices for surface traces (not the refined indices) - use `selection.index` for other gl3d trace type for consistency (even though selection.data.index worked fine) - add hover test for surface traces
1 parent 92de017 commit 7332d23

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

src/plots/gl3d/scene.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function render(scene) {
6868
var pdata = project(scene.glplot.cameraParams, selection.dataCoordinate);
6969
trace = lastPicked.data;
7070
var hoverinfo = trace.hoverinfo;
71+
var ptNumber = selection.index;
7172

7273
var xVal = formatter('xaxis', selection.traceCoordinate[0]),
7374
yVal = formatter('yaxis', selection.traceCoordinate[1]),
@@ -105,7 +106,7 @@ function render(scene) {
105106
data: trace._input,
106107
fullData: trace,
107108
curveNumber: trace.index,
108-
pointNumber: selection.data.index
109+
pointNumber: ptNumber
109110
}]
110111
};
111112

src/traces/mesh3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var proto = Mesh3DTrace.prototype;
3232

3333
proto.handlePick = function(selection) {
3434
if(selection.object === this.mesh) {
35-
var selectIndex = selection.data.index;
35+
var selectIndex = selection.index = selection.data.index;
3636

3737
selection.traceCoordinate = [
3838
this.data.x[selectIndex],

src/traces/scatter3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ proto.handlePick = function(selection) {
6767
}
6868
else selection.textLabel = '';
6969

70-
var selectIndex = selection.data.index;
70+
var selectIndex = selection.index = selection.data.index;
7171
selection.traceCoordinate = [
7272
this.data.x[selectIndex],
7373
this.data.y[selectIndex],

src/traces/surface/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var proto = SurfaceTrace.prototype;
3333

3434
proto.handlePick = function(selection) {
3535
if(selection.object === this.surface) {
36-
var selectIndex = [
36+
var selectIndex = selection.index = [
3737
Math.min(
3838
Math.round(selection.data.index[0] / this.dataScale - 1)|0,
3939
this.data.z[0].length - 1

src/traces/surface/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Surface.plot = require('./convert');
2020
Surface.moduleType = 'trace';
2121
Surface.name = 'surface';
2222
Surface.basePlotModule = require('../../plots/gl3d');
23-
Surface.categories = ['gl3d', 'noOpacity'];
23+
Surface.categories = ['gl3d', '2dMap', 'noOpacity'];
2424
Surface.meta = {
2525
description: [
2626
'The data the describes the coordinates of the surface is set in `z`.',

test/jasmine/tests/gl_plot_interact_test.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ describe('Test gl3d plots', function() {
4242
mock2.data[0].surfaceaxis = 2;
4343
mock2.layout.showlegend = true;
4444

45-
function mouseEventScatter3d(type, opts) {
46-
mouseEvent(type, 605, 271, opts);
47-
}
45+
var mock3 = require('@mocks/gl3d_autocolorscale');
4846

4947
function assertHoverText(xLabel, yLabel, zLabel, textLabel) {
5048
var node = d3.selectAll('g.hovertext');
@@ -83,11 +81,11 @@ describe('Test gl3d plots', function() {
8381
destroyGraphDiv();
8482
});
8583

86-
it('@noCI should display correct hover labels and emit correct event data', function(done) {
84+
it('@noCI should display correct hover labels and emit correct event data (scatter3d case)', function(done) {
8785
var _mock = Lib.extendDeep({}, mock2);
8886

8987
function _hover() {
90-
mouseEventScatter3d('mouseover');
88+
mouseEvent('mouseover', 605, 271);
9189
return delay();
9290
}
9391

@@ -150,16 +148,39 @@ describe('Test gl3d plots', function() {
150148
assertHoverText('x: 二 6, 2017', 'y: c', 'z: 100k', 'Clementine');
151149
})
152150
.then(done);
151+
});
152+
153+
it('@noCI should display correct hover labels and emit correct event data (surface case)', function(done) {
154+
var _mock = Lib.extendDeep({}, mock3);
155+
156+
function _hover() {
157+
mouseEvent('mouseover', 605, 271);
158+
return delay();
159+
}
153160

161+
Plotly.plot(gd, _mock)
162+
.then(delay)
163+
.then(function() {
164+
gd.on('plotly_hover', function(eventData) {
165+
ptData = eventData.points[0];
166+
});
167+
})
168+
.then(_hover)
169+
.then(delay)
170+
.then(function() {
171+
assertHoverText('x: 1', 'y: 2', 'z: 43', 'one two');
172+
assertEventData(1, 2, 43, 0, [1, 2]);
173+
})
174+
.then(done);
154175
});
155176

156-
it('@noCI should emit correct event data on click', function(done) {
177+
it('@noCI should emit correct event data on click (scatter3d case)', function(done) {
157178
var _mock = Lib.extendDeep({}, mock2);
158179

159180
// N.B. gl3d click events are 'mouseover' events
160181
// with button 1 pressed
161182
function _click() {
162-
mouseEventScatter3d('mouseover', {buttons: 1});
183+
mouseEvent('mouseover', 605, 271, {buttons: 1});
163184
return delay();
164185
}
165186

0 commit comments

Comments
 (0)