From 684195aa8458b5dc4f1fa3f1a2a7b9b3735c686e Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 23 Jan 2018 12:53:09 -0500 Subject: [PATCH 1/3] Fix resizing layout --- src/plot_api/plot_api.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 9296a02db31..94b973f5c8c 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -225,11 +225,13 @@ Plotly.plot = function(gd, data, layout, config) { 'height': '100%', 'overflow': 'visible', 'pointer-events': 'none' - }) - .attr('width', fullLayout.width) - .attr('height', fullLayout.height); + }); } + fullLayout._glcanvas + .attr('width', fullLayout.width) + .attr('height', fullLayout.height); + return Lib.syncOrAsync([ subroutines.layoutStyles ], gd); From d5f0962d4e1cb71c122e485ae1eab00c97793fec Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 23 Jan 2018 13:11:13 -0500 Subject: [PATCH 2/3] Add canvas width test --- src/plot_api/plot_api.js | 1 + test/jasmine/tests/gl2d_plot_interact_test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 94b973f5c8c..4923d61cdfe 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -232,6 +232,7 @@ Plotly.plot = function(gd, data, layout, config) { .attr('width', fullLayout.width) .attr('height', fullLayout.height); + return Lib.syncOrAsync([ subroutines.layoutStyles ], gd); diff --git a/test/jasmine/tests/gl2d_plot_interact_test.js b/test/jasmine/tests/gl2d_plot_interact_test.js index c311dfca182..625250504ca 100644 --- a/test/jasmine/tests/gl2d_plot_interact_test.js +++ b/test/jasmine/tests/gl2d_plot_interact_test.js @@ -184,6 +184,25 @@ describe('Test gl plot side effects', function() { }) .then(done); }); + + it('should be able to resize canvas properly', function(done) { + var _mock = Lib.extendDeep({}, require('@mocks/gl2d_10.json')); + _mock.data[0].line.width = 5; + + _mock.layout.width = 600; + + Plotly.plot(gd, _mock) + .then(function() { + expect(gd.querySelector('.gl-canvas-context').width).toBe(600); + + Plotly.relayout(gd, {width: 300}); + }) + .then(function() { + expect(gd.querySelector('.gl-canvas-context').width).toBe(300); + }) + .catch(fail) + .then(done); + }); }); describe('Test gl2d plots', function() { From be05b1cb03794ebd19c5cbb75e6f8dbcba43756c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 23 Jan 2018 13:38:42 -0500 Subject: [PATCH 3/3] Gate _glcanvas check --- src/plot_api/plot_api.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 4923d61cdfe..82c815a9fee 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -228,10 +228,11 @@ Plotly.plot = function(gd, data, layout, config) { }); } - fullLayout._glcanvas - .attr('width', fullLayout.width) - .attr('height', fullLayout.height); - + if(fullLayout._glcanvas) { + fullLayout._glcanvas + .attr('width', fullLayout.width) + .attr('height', fullLayout.height); + } return Lib.syncOrAsync([ subroutines.layoutStyles