Skip to content

Commit c8b53dd

Browse files
committed
attach scene2d relayoutCallback onto proto
- call after each mouse-change / wheel-change, as opposed to each time the scene2d ticks changed (which didn't cover all the cases) - make sure gl2d pan test `mouseup` to trigger relayoutCallback
1 parent ce1cc44 commit c8b53dd

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

src/plots/gl2d/camera.js

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function createCamera(scene) {
9191
updateRange(1, result.boxStart[1], result.boxEnd[1]);
9292
unSetAutoRange();
9393
result.boxEnabled = false;
94+
scene.relayoutCallback();
9495
}
9596
break;
9697

@@ -110,11 +111,16 @@ function createCamera(scene) {
110111

111112
scene.setRanges(dataBox);
112113

114+
result.panning = true;
113115
result.lastInputTime = Date.now();
114116
unSetAutoRange();
115117
scene.cameraChanged();
116118
scene.handleAnnotations();
117119
}
120+
else if(result.panning) {
121+
result.panning = false;
122+
scene.relayoutCallback();
123+
}
118124
break;
119125
}
120126

@@ -154,6 +160,7 @@ function createCamera(scene) {
154160
unSetAutoRange();
155161
scene.cameraChanged();
156162
scene.handleAnnotations();
163+
scene.relayoutCallback();
157164
break;
158165
}
159166

src/plots/gl2d/scene2d.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -288,27 +288,30 @@ proto.updateRefs = function(newFullLayout) {
288288
this.yaxis = this.fullLayout[yaxisName];
289289
};
290290

291-
function relayoutCallback(scene) {
292-
var xrange = scene.xaxis.range,
293-
yrange = scene.yaxis.range;
291+
proto.relayoutCallback = function() {
292+
var graphDiv = this.graphDiv,
293+
xaxis = this.xaxis,
294+
yaxis = this.yaxis,
295+
layout = graphDiv.layout;
294296

295-
// Update the layout on the DIV
296-
scene.graphDiv.layout.xaxis.autorange = scene.xaxis.autorange;
297-
scene.graphDiv.layout.xaxis.range = xrange.slice(0);
298-
scene.graphDiv.layout.yaxis.autorange = scene.yaxis.autorange;
299-
scene.graphDiv.layout.yaxis.range = yrange.slice(0);
297+
// update user layout
298+
layout.xaxis.autorange = xaxis.autorange;
299+
layout.xaxis.range = xaxis.range.slice(0);
300+
layout.yaxis.autorange = yaxis.autorange;
301+
layout.yaxis.range = yaxis.range.slice(0);
300302

301-
// Make a meaningful value to be passed on to the possible 'plotly_relayout' subscriber(s)
303+
// make a meaningful value to be passed on to the possible 'plotly_relayout' subscriber(s)
302304
// scene.camera has no many useful projection or scale information
303305
// helps determine which one is the latest input (if async)
304306
var update = {
305-
lastInputTime: scene.camera.lastInputTime
307+
lastInputTime: this.camera.lastInputTime
306308
};
307-
update[scene.xaxis._name] = xrange.slice();
308-
update[scene.yaxis._name] = yrange.slice();
309309

310-
scene.graphDiv.emit('plotly_relayout', update);
311-
}
310+
update[xaxis._name] = xaxis.range.slice(0);
311+
update[yaxis._name] = yaxis.range.slice(0);
312+
313+
graphDiv.emit('plotly_relayout', update);
314+
};
312315

313316
proto.cameraChanged = function() {
314317
var camera = this.camera;
@@ -323,8 +326,6 @@ proto.cameraChanged = function() {
323326
this.glplotOptions.dataBox = camera.dataBox;
324327
this.glplot.update(this.glplotOptions);
325328
this.handleAnnotations();
326-
327-
relayoutCallback(this);
328329
}
329330
};
330331

test/jasmine/tests/gl_plot_interact_test.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ describe('Test gl plot interactions', function() {
236236

237237
it('should respond to drag interactions', function(done) {
238238

239+
function mouseTo(p0, p1) {
240+
mouseEvent('mousemove', p0[0], p0[1]);
241+
mouseEvent('mousedown', p0[0], p0[1], { buttons: 1 });
242+
mouseEvent('mousemove', p1[0], p1[1], { buttons: 1 });
243+
mouseEvent('mouseup', p1[0], p1[1]);
244+
}
245+
239246
jasmine.addMatchers(customMatchers);
240247

241248
var precision = 5;
@@ -263,14 +270,10 @@ describe('Test gl plot interactions', function() {
263270
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
264271

265272
setTimeout(function() {
266-
267-
mouseEvent('mousemove', 200, 200);
268-
269273
relayoutCallback.calls.reset();
270274

271275
// Drag scene along the X axis
272-
273-
mouseEvent('mousemove', 220, 200, {buttons: 1});
276+
mouseTo([200, 200], [220, 200]);
274277

275278
expect(gd.layout.xaxis.autorange).toBe(false);
276279
expect(gd.layout.yaxis.autorange).toBe(false);
@@ -279,36 +282,31 @@ describe('Test gl plot interactions', function() {
279282
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
280283

281284
// Drag scene back along the X axis
282-
283-
mouseEvent('mousemove', 200, 200, {buttons: 1});
285+
mouseTo([220, 200], [200, 200]);
284286

285287
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
286288
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
287289

288290
// Drag scene along the Y axis
289-
290-
mouseEvent('mousemove', 200, 150, {buttons: 1});
291+
mouseTo([200, 200], [200, 150]);
291292

292293
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
293294
expect(gd.layout.yaxis.range).toBeCloseToArray(newY, precision);
294295

295296
// Drag scene back along the Y axis
296-
297-
mouseEvent('mousemove', 200, 200, {buttons: 1});
297+
mouseTo([200, 150], [200, 200]);
298298

299299
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
300300
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
301301

302302
// Drag scene along both the X and Y axis
303-
304-
mouseEvent('mousemove', 220, 150, {buttons: 1});
303+
mouseTo([200, 200], [220, 150]);
305304

306305
expect(gd.layout.xaxis.range).toBeCloseToArray(newX, precision);
307306
expect(gd.layout.yaxis.range).toBeCloseToArray(newY, precision);
308307

309308
// Drag scene back along the X and Y axis
310-
311-
mouseEvent('mousemove', 200, 200, {buttons: 1});
309+
mouseTo([220, 150], [200, 200]);
312310

313311
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
314312
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);

0 commit comments

Comments
 (0)