Skip to content

Commit a96c298

Browse files
authored
Merge pull request #1049 from plotly/cartesian-relayout-fix
Cartesian subplot fixes
2 parents a74b0f7 + 57cc9ca commit a96c298

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

src/plot_api/plot_api.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,16 @@ Plotly.plot = function(gd, data, layout, config) {
196196
return Plots.previousPromises(gd);
197197
}
198198

199+
// in case the margins changed, draw margin pushers again
199200
function marginPushersAgain() {
200-
// in case the margins changed, draw margin pushers again
201201
var seq = JSON.stringify(fullLayout._size) === oldmargins ?
202202
[] :
203203
[marginPushers, subroutines.layoutStyles];
204204

205+
// re-initialize cartesian interaction,
206+
// which are sometimes cleared during marginPushers
207+
seq = seq.concat(Fx.init);
208+
205209
return Lib.syncOrAsync(seq, gd);
206210
}
207211

src/plots/plots.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ plots.supplyDefaults = function(gd) {
402402
// clean subplots and other artifacts from previous plot calls
403403
plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout);
404404

405+
// relink / initialize subplot axis objects
406+
plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout);
407+
405408
// relink functions and _ attributes to promote consistency between plots
406409
relinkPrivateKeys(newFullLayout, oldFullLayout);
407410

@@ -416,9 +419,6 @@ plots.supplyDefaults = function(gd) {
416419
ax.setScale();
417420
}
418421

419-
// relink / initialize subplot axis objects
420-
plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout);
421-
422422
// update object references in calcdata
423423
if((gd.calcdata || []).length === newFullData.length) {
424424
for(i = 0; i < newFullData.length; i++) {

test/jasmine/tests/hover_label_test.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Lib = require('@src/lib');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var mouseEvent = require('../assets/mouse_event');
11+
var click = require('../assets/click');
1112
var doubleClick = require('../assets/double_click');
1213

1314
describe('hover info', function() {
@@ -630,6 +631,16 @@ describe('hover after resizing', function() {
630631

631632
afterEach(destroyGraphDiv);
632633

634+
function _click(pos) {
635+
return new Promise(function(resolve) {
636+
click(pos[0], pos[1]);
637+
638+
setTimeout(function() {
639+
resolve();
640+
}, constants.HOVERMINTIME);
641+
});
642+
}
643+
633644
function assertLabelCount(pos, cnt, msg) {
634645
return new Promise(function(resolve) {
635646
mouseEvent('mousemove', pos[0], pos[1]);
@@ -652,22 +663,36 @@ describe('hover after resizing', function() {
652663
pos1 = [401, 122];
653664

654665
Plotly.plot(gd, data, layout).then(function() {
666+
667+
// to test https://github.com/plotly/plotly.js/issues/1044
668+
669+
return _click(pos0);
670+
})
671+
.then(function() {
655672
return assertLabelCount(pos0, 1, 'before resize, showing pt label');
656-
}).then(function() {
673+
})
674+
.then(function() {
657675
return assertLabelCount(pos1, 0, 'before resize, not showing blank spot');
658-
}).then(function() {
676+
})
677+
.then(function() {
659678
return Plotly.relayout(gd, 'width', 500);
660-
}).then(function() {
679+
})
680+
.then(function() {
661681
return assertLabelCount(pos0, 0, 'after resize, not showing blank spot');
662-
}).then(function() {
682+
})
683+
.then(function() {
663684
return assertLabelCount(pos1, 1, 'after resize, showing pt label');
664-
}).then(function() {
685+
})
686+
.then(function() {
665687
return Plotly.relayout(gd, 'width', 600);
666-
}).then(function() {
688+
})
689+
.then(function() {
667690
return assertLabelCount(pos0, 1, 'back to initial, showing pt label');
668-
}).then(function() {
691+
})
692+
.then(function() {
669693
return assertLabelCount(pos1, 0, 'back to initial, not showing blank spot');
670-
}).then(done);
694+
})
695+
.then(done);
671696
});
672697
});
673698

test/jasmine/tests/plots_test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ describe('Test Plots', function() {
248248
describe('Plots.resize', function() {
249249
var gd;
250250

251-
beforeEach(function(done) {
251+
beforeAll(function(done) {
252252
gd = createGraphDiv();
253253

254254
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {})
@@ -287,6 +287,17 @@ describe('Test Plots', function() {
287287
expect(svgHeight).toBe(400);
288288
}
289289
});
290+
291+
it('should update the axis scales', function() {
292+
var fullLayout = gd._fullLayout,
293+
plotinfo = fullLayout._plots.xy;
294+
295+
expect(fullLayout.xaxis._length).toEqual(240);
296+
expect(fullLayout.yaxis._length).toEqual(220);
297+
298+
expect(plotinfo.xaxis._length).toEqual(240);
299+
expect(plotinfo.yaxis._length).toEqual(220);
300+
});
290301
});
291302

292303
describe('Plots.purge', function() {

0 commit comments

Comments
 (0)