Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6ddc73

Browse files
author
Tom Chandler
committed
Fixed invalid Promise syntax in Plotly.relayout
1 parent 212ca7f commit a6ddc73

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

src/plot_api/plot_api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
20952095
gd = getGraphDiv(gd);
20962096

20972097
if(gd.framework && gd.framework.isPolar) {
2098-
return new Promise.resolve(gd);
2098+
return Promise.resolve(gd);
20992099
}
21002100

21012101
var layout = gd.layout,
@@ -2113,7 +2113,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
21132113
else if(Lib.isPlainObject(astr)) aobj = astr;
21142114
else {
21152115
console.log('relayout fail',astr,val);
2116-
return new Promise.reject();
2116+
return Promise.reject();
21172117
}
21182118

21192119
if(Object.keys(aobj).length) gd.changed = true;

test/jasmine/tests/plot_promise_test.js

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,12 @@ describe('Plotly.___ methods', function() {
361361

362362
beforeEach(function(done) {
363363
var data = [{ x: [1,2,3], y: [4,5,6] }],
364+
layout = {hovermode:'closest'},
364365
initialDiv = createGraphDiv();
365366

366-
Plotly.plot(initialDiv, data, {});
367+
Plotly.plot(initialDiv, data, layout);
367368

368-
promise = Plotly.restyle(initialDiv, 'title', 'Promise test!');
369+
promise = Plotly.relayout(initialDiv, 'hovermode', false);
369370

370371
promise.then(function(gd){
371372
promiseGd = gd;
@@ -382,4 +383,85 @@ describe('Plotly.___ methods', function() {
382383
});
383384
});
384385

386+
describe('Plotly.relayout promise', function() {
387+
var promise,
388+
promiseGd;
389+
390+
beforeEach(function(done) {
391+
var data = [{ x: [1,2,3], y: [4,5,6] }],
392+
layout = {hovermode:'closest'},
393+
initialDiv = createGraphDiv();
394+
395+
Plotly.plot(initialDiv, data, layout);
396+
397+
promise = Plotly.relayout(initialDiv, 'hovermode', false);
398+
399+
promise.then(function(gd){
400+
promiseGd = gd;
401+
done();
402+
});
403+
});
404+
afterEach(destroyGraphDiv);
405+
406+
it('should be returned with the graph div as an argument', function() {
407+
expect(promiseGd).toBeDefined();
408+
expect(typeof promiseGd).toBe('object');
409+
expect(promiseGd.data).toBeDefined();
410+
expect(promiseGd.layout).toBeDefined();
411+
});
412+
});
413+
414+
describe('Plotly.relayout promise', function() {
415+
var promise,
416+
promiseGd;
417+
418+
beforeEach(function(done) {
419+
var data = [{ x: [1,2,3], y: [4,5,6] }],
420+
layout = {hovermode:'closest'},
421+
initialDiv = createGraphDiv();
422+
423+
Plotly.plot(initialDiv, data, layout);
424+
425+
initialDiv.framework = { isPolar: true };
426+
promise = Plotly.relayout(initialDiv, 'hovermode', false);
427+
428+
promise.then(function(gd){
429+
promiseGd = gd;
430+
done();
431+
});
432+
});
433+
afterEach(destroyGraphDiv);
434+
435+
it('should be returned with the graph div unchanged when the framework is polar', function() {
436+
expect(promiseGd).toBeDefined();
437+
expect(typeof promiseGd).toBe('object');
438+
expect(promiseGd.changed).toBeFalsy();
439+
});
440+
});
441+
442+
describe('Plotly.relayout promise', function() {
443+
var promise,
444+
promiseRejected = false;
445+
446+
beforeEach(function(done) {
447+
var data = [{ x: [1,2,3], y: [4,5,6] }],
448+
layout = {hovermode:'closest'},
449+
initialDiv = createGraphDiv();
450+
451+
Plotly.plot(initialDiv, data, layout);
452+
453+
promise = Plotly.relayout(initialDiv, undefined, false);
454+
455+
promise.then(null, function(){
456+
promiseRejected = true;
457+
done();
458+
});
459+
});
460+
afterEach(destroyGraphDiv);
461+
462+
it('should be rejected when the attribute is missing', function() {
463+
expect(promiseRejected).toBe(true);
464+
});
465+
});
466+
385467
});

0 commit comments

Comments
 (0)