Skip to content

Commit 805e0db

Browse files
committed
allow use of element ID in Plots.resize
and make sure the resize tests actually DO something
1 parent 599dff9 commit 805e0db

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/plots/plots.js

+3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ plots.getSubplotCalcData = function(calcData, type, subplotId) {
191191
// the text is at first, so it needs to draw it,
192192
// then wait a little, then draw it again
193193
plots.redrawText = function(gd) {
194+
gd = Lib.getGraphDiv(gd);
194195

195196
// do not work if polar is present
196197
if((gd.data && gd.data[0] && gd.data[0].r)) return;
@@ -211,6 +212,8 @@ plots.redrawText = function(gd) {
211212

212213
// resize plot about the container size
213214
plots.resize = function(gd) {
215+
gd = Lib.getGraphDiv(gd);
216+
214217
return new Promise(function(resolve, reject) {
215218

216219
function isHidden(gd) {

test/jasmine/tests/plots_test.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var d3 = require('d3');
66
var createGraphDiv = require('../assets/create_graph_div');
77
var destroyGraphDiv = require('../assets/destroy_graph_div');
88
var supplyAllDefaults = require('../assets/supply_defaults');
9+
var failTest = require('../assets/fail_test');
910

1011

1112
describe('Test Plots', function() {
@@ -369,7 +370,7 @@ describe('Test Plots', function() {
369370
.then(done);
370371
});
371372

372-
afterEach(destroyGraphDiv);
373+
afterAll(destroyGraphDiv);
373374

374375
it('should resize the plot clip', function() {
375376
var uid = gd._fullLayout._uid;
@@ -385,6 +386,7 @@ describe('Test Plots', function() {
385386

386387
it('should resize the main svgs', function() {
387388
var mainSvgs = document.getElementsByClassName('main-svg');
389+
expect(mainSvgs.length).toBe(2);
388390

389391
for(var i = 0; i < mainSvgs.length; i++) {
390392
var svg = mainSvgs[i],
@@ -397,6 +399,9 @@ describe('Test Plots', function() {
397399
});
398400

399401
it('should update the axis scales', function() {
402+
var mainSvgs = document.getElementsByClassName('main-svg');
403+
expect(mainSvgs.length).toBe(2);
404+
400405
var fullLayout = gd._fullLayout,
401406
plotinfo = fullLayout._plots.xy;
402407

@@ -406,6 +411,18 @@ describe('Test Plots', function() {
406411
expect(plotinfo.xaxis._length).toEqual(240);
407412
expect(plotinfo.yaxis._length).toEqual(220);
408413
});
414+
415+
it('should allow resizing by plot ID', function(done) {
416+
var mainSvgs = document.getElementsByClassName('main-svg');
417+
expect(mainSvgs.length).toBe(2);
418+
419+
expect(typeof gd.id).toBe('string');
420+
expect(gd.id).toBeTruthy();
421+
422+
Plotly.Plots.resize(gd.id)
423+
.catch(failTest)
424+
.then(done);
425+
});
409426
});
410427

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

0 commit comments

Comments
 (0)