From f4ca110ac0b786eed371fa680cdd95c09d5225a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 17 Oct 2016 15:10:22 -0400 Subject: [PATCH 1/3] plots: relink subplot before relink _ keys in fullLayout - so that old axis scale fields (e.g _length, _m, ...) in fullLayout don't get relinked in subplot objects, leading to incorrect relayout / resize. --- src/plots/plots.js | 6 +++--- test/jasmine/tests/plots_test.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) 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/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() { From 2c049940cd7c2678294a21ad6d17bb66c0781f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 17 Oct 2016 16:13:01 -0400 Subject: [PATCH 2/3] lint: space out .then clauses --- test/jasmine/tests/hover_label_test.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index 7904e62a8de..893b7f88578 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -653,21 +653,29 @@ describe('hover after resizing', function() { Plotly.plot(gd, data, layout).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); }); }); From d61b87399f05751e818c1619352c68d3379d161a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 17 Oct 2016 16:30:12 -0400 Subject: [PATCH 3/3] call Fx.init in after marginPushers step - to make sure that subplot nodes have the correct mouse / click handlers. --- src/plot_api/plot_api.js | 6 +++++- test/jasmine/tests/hover_label_test.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index 893b7f88578..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,6 +663,12 @@ 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() {