Skip to content

Commit 5f36071

Browse files
authored
Merge pull request #1319 from plotly/gl2d-tmpper
Improvement in how gl2d refs to fullLayout are updated
2 parents 5a4f945 + c8b53dd commit 5f36071

File tree

5 files changed

+50
-53
lines changed

5 files changed

+50
-53
lines changed

Diff for: src/plot_api/subroutines.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ exports.doModeBar = function(gd) {
295295
var subplotIds, i;
296296

297297
ModeBar.manage(gd);
298-
Plotly.Fx.supplyLayoutDefaults(gd.layout, gd._fullLayout, gd._fullData);
299298
Plotly.Fx.init(gd);
300299

301300
subplotIds = Plots.getSubplotIds(fullLayout, 'gl3d');
@@ -304,11 +303,8 @@ exports.doModeBar = function(gd) {
304303
scene.updateFx(fullLayout.dragmode, fullLayout.hovermode);
305304
}
306305

307-
subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d');
308-
for(i = 0; i < subplotIds.length; i++) {
309-
var scene2d = fullLayout._plots[subplotIds[i]]._scene2d;
310-
scene2d.updateFx(fullLayout);
311-
}
306+
// no need to do this for gl2d subplots,
307+
// Plots.linkSubplots takes care of it all.
312308

313309
subplotIds = Plots.getSubplotIds(fullLayout, 'geo');
314310
for(i = 0; i < subplotIds.length; i++) {

Diff for: 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

Diff for: src/plots/gl2d/scene2d.js

+24-32
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ function Scene2D(options, fullLayout) {
3434
this.id = options.id;
3535
this.staticPlot = !!options.staticPlot;
3636

37-
this.fullLayout = fullLayout;
3837
this.fullData = null;
39-
this.updateAxes(fullLayout);
38+
this.updateRefs(fullLayout);
4039

4140
this.makeFramework();
4241

@@ -278,45 +277,41 @@ function compareTicks(a, b) {
278277
return false;
279278
}
280279

281-
proto.updateAxes = function(options) {
280+
proto.updateRefs = function(newFullLayout) {
281+
this.fullLayout = newFullLayout;
282+
282283
var spmatch = Axes.subplotMatch,
283284
xaxisName = 'xaxis' + this.id.match(spmatch)[1],
284285
yaxisName = 'yaxis' + this.id.match(spmatch)[2];
285286

286-
this.xaxis = options[xaxisName];
287-
this.yaxis = options[yaxisName];
288-
};
289-
290-
proto.updateFx = function(options) {
291-
var fullLayout = this.fullLayout;
292-
293-
fullLayout.dragmode = options.dragmode;
294-
fullLayout.hovermode = options.hovermode;
295-
296-
this.graphDiv._fullLayout = fullLayout;
287+
this.xaxis = this.fullLayout[xaxisName];
288+
this.yaxis = this.fullLayout[yaxisName];
297289
};
298290

299-
function relayoutCallback(scene) {
300-
var xrange = scene.xaxis.range,
301-
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;
302296

303-
// Update the layout on the DIV
304-
scene.graphDiv.layout.xaxis.autorange = scene.xaxis.autorange;
305-
scene.graphDiv.layout.xaxis.range = xrange.slice(0);
306-
scene.graphDiv.layout.yaxis.autorange = scene.yaxis.autorange;
307-
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);
308302

309-
// 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)
310304
// scene.camera has no many useful projection or scale information
311305
// helps determine which one is the latest input (if async)
312306
var update = {
313-
lastInputTime: scene.camera.lastInputTime
307+
lastInputTime: this.camera.lastInputTime
314308
};
315-
update[scene.xaxis._name] = xrange.slice();
316-
update[scene.yaxis._name] = yrange.slice();
317309

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

321316
proto.cameraChanged = function() {
322317
var camera = this.camera;
@@ -331,8 +326,6 @@ proto.cameraChanged = function() {
331326
this.glplotOptions.dataBox = camera.dataBox;
332327
this.glplot.update(this.glplotOptions);
333328
this.handleAnnotations();
334-
335-
relayoutCallback(this);
336329
}
337330
};
338331

@@ -374,8 +367,7 @@ proto.destroy = function() {
374367
proto.plot = function(fullData, calcData, fullLayout) {
375368
var glplot = this.glplot;
376369

377-
this.fullLayout = fullLayout;
378-
this.updateAxes(fullLayout);
370+
this.updateRefs(fullLayout);
379371
this.updateTraces(fullData, calcData);
380372

381373
var width = fullLayout.width,

Diff for: src/plots/plots.js

+4
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
655655

656656
if(oldSubplot) {
657657
plotinfo = newSubplots[id] = oldSubplot;
658+
659+
if(plotinfo._scene2d) {
660+
plotinfo._scene2d.updateRefs(newFullLayout);
661+
}
658662
}
659663
else {
660664
plotinfo = newSubplots[id] = {};

Diff for: 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)