Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,6 @@ Plotly.plot = function(gd, data, layout, config) {
// so that the caller doesn't care which route we took
return Promise.all(gd._promises).then(function() {
return gd;
}, function() {
// clear the promise queue if one of them got rejected
Lib.log('Clearing previous rejected promises from queue.');
gd._promises = [];
});
};

Expand All @@ -355,6 +351,12 @@ function getGraphDiv(gd) {
return gd; // otherwise assume that gd is a DOM element
}

// clear the promise queue if one of them got rejected
function clearPromiseQueue(gd) {
Lib.log('Clearing previous rejected promises from queue.');
gd._promises = [];
}

function opaqueSetBackground(gd, bgColor) {
gd._fullLayout._paperdiv.style('background', 'white');
Plotly.defaultConfig.setBackground(gd, bgColor);
Expand Down Expand Up @@ -1536,6 +1538,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) {
// style files that want to specify cyclical default values).
Plotly.restyle = function restyle(gd, astr, val, traces) {
gd = getGraphDiv(gd);
clearPromiseQueue(gd);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, clear the gd._promises on restyle and relayout instead.


var i, fullLayout = gd._fullLayout,
aobj = {};
Expand Down Expand Up @@ -2076,6 +2079,7 @@ function swapXYData(trace) {
// allows setting multiple attributes simultaneously
Plotly.relayout = function relayout(gd, astr, val) {
gd = getGraphDiv(gd);
clearPromiseQueue(gd);

if(gd.framework && gd.framework.isPolar) {
return Promise.resolve(gd);
Expand Down
25 changes: 17 additions & 8 deletions test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,26 @@ describe('mapbox credentials', function() {
});

it('should throw error if token is invalid', function(done) {
var cnt = 0;

Plotly.plot(gd, [{
type: 'scattermapbox',
lon: [10, 20, 30],
lat: [10, 20, 30]
}], {}, {
mapboxAccessToken: dummyToken
}).catch(function(err) {
cnt++;
expect(err).toEqual(new Error(constants.mapOnErrorMsg));
Copy link
Contributor Author

@etpinard etpinard Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion ⏫ did not get evaluated before. That is this it didn't test anything.

I wish jasmine had the something similar to TAP's t.plan.

}).then(done);
}).then(function() {
expect(cnt).toEqual(1);
done();
});
});

it('should use access token in mapbox layout options if present', function(done) {
var cnt = 0;

Plotly.plot(gd, [{
type: 'scattermapbox',
lon: [10, 20, 30],
Expand All @@ -202,7 +210,10 @@ describe('mapbox credentials', function() {
}
}, {
mapboxAccessToken: dummyToken
}).catch(function() {
cnt++;
}).then(function() {
expect(cnt).toEqual(0);
expect(gd._fullLayout.mapbox.accesstoken).toEqual(MAPBOX_ACCESS_TOKEN);
done();
});
Expand Down Expand Up @@ -493,21 +504,19 @@ describe('mapbox plots', function() {
});

it('should be able to update the access token', function(done) {
var promise = Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work');

promise.catch(function(err) {
Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work').catch(function(err) {
expect(gd._fullLayout.mapbox.accesstoken).toEqual('wont-work');
expect(err).toEqual(new Error(constants.mapOnErrorMsg));
});
expect(gd._promises.length).toEqual(1);

promise.then(function() {
return Plotly.relayout(gd, 'mapbox.accesstoken', MAPBOX_ACCESS_TOKEN);
}).then(function() {
expect(gd._fullLayout.mapbox.accesstoken).toEqual(MAPBOX_ACCESS_TOKEN);
}).then(done);
expect(gd._promises.length).toEqual(0);
done();
});
});


it('should be able to update traces', function(done) {
function assertDataPts(lengths) {
var lines = getGeoJsonData(gd, 'lines'),
Expand Down