From a762fe3c6a52760ddefa15928987c3159685cdfc Mon Sep 17 00:00:00 2001 From: Tom Chandler Date: Thu, 28 Jan 2016 16:29:17 -0500 Subject: [PATCH 1/4] Added promise returns to Plotly.plot --- src/plot_api/plot_api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 8c708da5d7d..808f88245bc 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -59,7 +59,7 @@ Plotly.plot = function(gd, data, layout, config) { Events.init(gd); var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]); - if(okToPlot===false) return; + if(okToPlot===false) return new Promise.reject(); // if there's no data or layout, and this isn't yet a plotly plot // container, log a warning to help plotly.js users debug @@ -112,7 +112,7 @@ Plotly.plot = function(gd, data, layout, config) { // signal to drag handler that after everything else is done // we need to replot, because something has changed gd._replotPending = true; - return; + return new Promise.reject(); } else { // we're going ahead with a replot now gd._replotPending = false; From 06c4894f96a7b6f7ace1b7465cdd7d64a51ac81d Mon Sep 17 00:00:00 2001 From: Tom Chandler Date: Fri, 29 Jan 2016 17:46:41 -0500 Subject: [PATCH 2/4] Fixed invalid Promise syntax in Plotly.plot --- src/plot_api/plot_api.js | 4 +- test/jasmine/tests/plot_promise_test.js | 59 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 808f88245bc..64d67161f97 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -59,7 +59,7 @@ Plotly.plot = function(gd, data, layout, config) { Events.init(gd); var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]); - if(okToPlot===false) return new Promise.reject(); + if(okToPlot===false) return Promise.reject(); // if there's no data or layout, and this isn't yet a plotly plot // container, log a warning to help plotly.js users debug @@ -112,7 +112,7 @@ Plotly.plot = function(gd, data, layout, config) { // signal to drag handler that after everything else is done // we need to replot, because something has changed gd._replotPending = true; - return new Promise.reject(); + return Promise.reject(); } else { // we're going ahead with a replot now gd._replotPending = false; diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index b42af7044db..6cd9e284c3b 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -1,4 +1,5 @@ var Plotly = require('@src/plotly'); +var Events = require('@src/lib/events'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); @@ -29,6 +30,64 @@ describe('Plotly.___ methods', function() { }); }); + describe('Plotly.plot promise', function() { + var gd, + promise, + promiseRejected = false; + + beforeEach(function(done) { + var data = [{ x: [1,2,3], y: [4,5,6] }]; + + gd = createGraphDiv(); + + Events.init(gd); + + gd.on('plotly_beforeplot', function() { + return false; + }); + + promise = Plotly.plot(gd, data, {}); + + promise.then(null, function(){ + promiseRejected = true; + done(); + }); + }); + + afterEach(destroyGraphDiv); + + it('should be rejected when plotly_beforeplot event handlers return false', function() { + expect(promiseRejected).toBe(true); + }); + }); + + describe('Plotly.plot promise', function() { + var gd, + promise, + promiseRejected = false; + + beforeEach(function(done) { + var data = [{ x: [1,2,3], y: [4,5,6] }]; + + gd = createGraphDiv(); + + gd._dragging = true; + + promise = Plotly.plot(gd, data, {}); + + promise.then(null, function(){ + promiseRejected = true; + done(); + }); + }); + + afterEach(destroyGraphDiv); + + it('should reject the promise when graph is being dragged', function() { + expect(promiseRejected).toBe(true); + }); + }); + describe('Plotly.redraw promise', function() { var promise, promiseGd; From 212ca7f464179e24fec66801225afe8ce233f5e4 Mon Sep 17 00:00:00 2001 From: Tom Chandler Date: Fri, 29 Jan 2016 17:52:22 -0500 Subject: [PATCH 3/4] Fixed invalid Promise syntax in Plotly.restyle --- src/plot_api/plot_api.js | 2 +- test/jasmine/tests/plot_promise_test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 64d67161f97..63cab509616 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1572,7 +1572,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { } else { console.log('restyle fail',astr,val,traces); - return new Promise.reject(); + return Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index 6cd9e284c3b..c92dcbb3920 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -331,6 +331,30 @@ describe('Plotly.___ methods', function() { }); }); + describe('Plotly.restyle promise', function() { + var promise, + promiseRejected = false; + + beforeEach(function(done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.restyle(initialDiv, undefined, ''); + + promise.then(null, function(){ + promiseRejected = true; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be rejected when the attribute is missing', function() { + expect(promiseRejected).toBe(true); + }); + }); + describe('Plotly.relayout promise', function() { var promise, promiseGd; From a6ddc7358a2cda796afdb17a648cce501300f506 Mon Sep 17 00:00:00 2001 From: Tom Chandler Date: Fri, 29 Jan 2016 17:52:35 -0500 Subject: [PATCH 4/4] Fixed invalid Promise syntax in Plotly.relayout --- src/plot_api/plot_api.js | 4 +- test/jasmine/tests/plot_promise_test.js | 86 ++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 63cab509616..740e5789d9a 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2095,7 +2095,7 @@ Plotly.relayout = function relayout(gd, astr, val) { gd = getGraphDiv(gd); if(gd.framework && gd.framework.isPolar) { - return new Promise.resolve(gd); + return Promise.resolve(gd); } var layout = gd.layout, @@ -2113,7 +2113,7 @@ Plotly.relayout = function relayout(gd, astr, val) { else if(Lib.isPlainObject(astr)) aobj = astr; else { console.log('relayout fail',astr,val); - return new Promise.reject(); + return Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index c92dcbb3920..56b822b3915 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -361,11 +361,12 @@ describe('Plotly.___ methods', function() { beforeEach(function(done) { var data = [{ x: [1,2,3], y: [4,5,6] }], + layout = {hovermode:'closest'}, initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.plot(initialDiv, data, layout); - promise = Plotly.restyle(initialDiv, 'title', 'Promise test!'); + promise = Plotly.relayout(initialDiv, 'hovermode', false); promise.then(function(gd){ promiseGd = gd; @@ -382,4 +383,85 @@ describe('Plotly.___ methods', function() { }); }); + describe('Plotly.relayout promise', function() { + var promise, + promiseGd; + + beforeEach(function(done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + layout = {hovermode:'closest'}, + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, layout); + + promise = Plotly.relayout(initialDiv, 'hovermode', false); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function() { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.relayout promise', function() { + var promise, + promiseGd; + + beforeEach(function(done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + layout = {hovermode:'closest'}, + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, layout); + + initialDiv.framework = { isPolar: true }; + promise = Plotly.relayout(initialDiv, 'hovermode', false); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div unchanged when the framework is polar', function() { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.changed).toBeFalsy(); + }); + }); + + describe('Plotly.relayout promise', function() { + var promise, + promiseRejected = false; + + beforeEach(function(done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + layout = {hovermode:'closest'}, + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, layout); + + promise = Plotly.relayout(initialDiv, undefined, false); + + promise.then(null, function(){ + promiseRejected = true; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be rejected when the attribute is missing', function() { + expect(promiseRejected).toBe(true); + }); + }); + });