diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 640912f281b..2975f9ec50e 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -196,12 +196,16 @@ Plotly.plot = function(gd, data, layout, config) { return Plots.previousPromises(gd); } + // in case the margins changed, draw margin pushers again function marginPushersAgain() { - // in case the margins changed, draw margin pushers again var seq = JSON.stringify(fullLayout._size) === oldmargins ? [] : [marginPushers, subroutines.layoutStyles]; + // re-initialize cartesian interaction, + // which are sometimes cleared during marginPushers + seq = seq.concat(Fx.init); + return Lib.syncOrAsync(seq, gd); } diff --git a/src/plots/plots.js b/src/plots/plots.js index 2610eff994d..277a3b8211a 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -402,6 +402,9 @@ plots.supplyDefaults = function(gd) { // clean subplots and other artifacts from previous plot calls plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout); + // relink / initialize subplot axis objects + plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout); + // relink functions and _ attributes to promote consistency between plots relinkPrivateKeys(newFullLayout, oldFullLayout); @@ -416,9 +419,6 @@ plots.supplyDefaults = function(gd) { ax.setScale(); } - // relink / initialize subplot axis objects - plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout); - // update object references in calcdata if((gd.calcdata || []).length === newFullData.length) { for(i = 0; i < newFullData.length; i++) { diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index 7904e62a8de..e89d92f8a43 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -8,6 +8,7 @@ var Lib = require('@src/lib'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); +var click = require('../assets/click'); var doubleClick = require('../assets/double_click'); describe('hover info', function() { @@ -630,6 +631,16 @@ describe('hover after resizing', function() { afterEach(destroyGraphDiv); + function _click(pos) { + return new Promise(function(resolve) { + click(pos[0], pos[1]); + + setTimeout(function() { + resolve(); + }, constants.HOVERMINTIME); + }); + } + function assertLabelCount(pos, cnt, msg) { return new Promise(function(resolve) { mouseEvent('mousemove', pos[0], pos[1]); @@ -652,22 +663,36 @@ describe('hover after resizing', function() { pos1 = [401, 122]; Plotly.plot(gd, data, layout).then(function() { + + // to test https://github.com/plotly/plotly.js/issues/1044 + + return _click(pos0); + }) + .then(function() { return assertLabelCount(pos0, 1, 'before resize, showing pt label'); - }).then(function() { + }) + .then(function() { return assertLabelCount(pos1, 0, 'before resize, not showing blank spot'); - }).then(function() { + }) + .then(function() { return Plotly.relayout(gd, 'width', 500); - }).then(function() { + }) + .then(function() { return assertLabelCount(pos0, 0, 'after resize, not showing blank spot'); - }).then(function() { + }) + .then(function() { return assertLabelCount(pos1, 1, 'after resize, showing pt label'); - }).then(function() { + }) + .then(function() { return Plotly.relayout(gd, 'width', 600); - }).then(function() { + }) + .then(function() { return assertLabelCount(pos0, 1, 'back to initial, showing pt label'); - }).then(function() { + }) + .then(function() { return assertLabelCount(pos1, 0, 'back to initial, not showing blank spot'); - }).then(done); + }) + .then(done); }); }); diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index f2495a778bd..c3c967a5ab0 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -248,7 +248,7 @@ describe('Test Plots', function() { describe('Plots.resize', function() { var gd; - beforeEach(function(done) { + beforeAll(function(done) { gd = createGraphDiv(); Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {}) @@ -287,6 +287,17 @@ describe('Test Plots', function() { expect(svgHeight).toBe(400); } }); + + it('should update the axis scales', function() { + var fullLayout = gd._fullLayout, + plotinfo = fullLayout._plots.xy; + + expect(fullLayout.xaxis._length).toEqual(240); + expect(fullLayout.yaxis._length).toEqual(220); + + expect(plotinfo.xaxis._length).toEqual(240); + expect(plotinfo.yaxis._length).toEqual(220); + }); }); describe('Plots.purge', function() {