Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapbox to image context #1598

Merged
merged 2 commits into from
Apr 14, 2017
Merged
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
4 changes: 3 additions & 1 deletion src/snapshot/cloneplot.js
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ module.exports = function clonePlot(graphObj, options) {
var oldLayout = graphObj.layout;
var newData = extendDeep([], oldData);
var newLayout = extendDeep({}, oldLayout, cloneLayoutOverride(options.tileClass));
var context = graphObj._context || {};

if(options.width) newLayout.width = options.width;
if(options.height) newLayout.height = options.height;
@@ -153,7 +154,8 @@ module.exports = function clonePlot(graphObj, options) {
options.plotGlPixelRatio,
displaylogo: options.displaylogo || false,
showLink: options.showLink || false,
showTips: options.showTips || false
showTips: options.showTips || false,
mapboxAccessToken: context.mapboxAccessToken
}
};

73 changes: 73 additions & 0 deletions test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
@@ -964,5 +964,78 @@ describe('@noCI, mapbox plots', function() {
}, MOUSE_DELAY);
});
}
});

describe('@noCI, mapbox toImage', function() {
var MINIMUM_LENGTH = 1e5;

var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(function() {
Plotly.purge(gd);
Plotly.setPlotConfig({ mapboxAccessToken: null });
destroyGraphDiv();
});

it('should generate image data with global credentials', function(done) {
Plotly.setPlotConfig({
mapboxAccessToken: MAPBOX_ACCESS_TOKEN
});

Plotly.newPlot(gd, [{
type: 'scattermapbox',
lon: [0, 10, 20],
lat: [-10, 10, -10]
}])
.then(function() {
return Plotly.toImage(gd);
})
.then(function(imgData) {
expect(imgData.length).toBeGreaterThan(MINIMUM_LENGTH);
})
.catch(failTest)
.then(done);
}, LONG_TIMEOUT_INTERVAL);

it('should generate image data with config credentials', function(done) {
Plotly.newPlot(gd, [{
type: 'scattermapbox',
lon: [0, 10, 20],
lat: [-10, 10, -10]
}], {}, {
mapboxAccessToken: MAPBOX_ACCESS_TOKEN
})
.then(function() {
return Plotly.toImage(gd);
})
.then(function(imgData) {
expect(imgData.length).toBeGreaterThan(MINIMUM_LENGTH);
})
.catch(failTest)
.then(done);
}, LONG_TIMEOUT_INTERVAL);

it('should generate image data with layout credentials', function(done) {
Plotly.newPlot(gd, [{
type: 'scattermapbox',
lon: [0, 10, 20],
lat: [-10, 10, -10]
}], {
mapbox: {
accesstoken: MAPBOX_ACCESS_TOKEN
}
})
.then(function() {
return Plotly.toImage(gd);
})
.then(function(imgData) {
expect(imgData.length).toBeGreaterThan(MINIMUM_LENGTH);
})
.catch(failTest)
.then(done);
}, LONG_TIMEOUT_INTERVAL);
});
13 changes: 8 additions & 5 deletions test/jasmine/tests/scattermapbox_test.js
Original file line number Diff line number Diff line change
@@ -24,11 +24,6 @@ function move(fromX, fromY, toX, toY, delay) {
});
}

Plotly.setPlotConfig({
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
});


describe('scattermapbox defaults', function() {
'use strict';

@@ -341,6 +336,10 @@ describe('@noCI scattermapbox hover', function() {
beforeAll(function(done) {
jasmine.addMatchers(customMatchers);

Plotly.setPlotConfig({
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
});

gd = createGraphDiv();

var data = [{
@@ -520,6 +519,10 @@ describe('@noCI Test plotly events on a scattermapbox plot:', function() {
beforeAll(function(done) {
jasmine.addMatchers(customMatchers);

Plotly.setPlotConfig({
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
});

gd = createGraphDiv();
mockCopy = Lib.extendDeep({}, mock);

3 changes: 2 additions & 1 deletion test/jasmine/tests/snapshot_test.js
Original file line number Diff line number Diff line change
@@ -80,7 +80,8 @@ describe('Plotly.Snapshot', function() {
displaylogo: false,
showLink: false,
showTips: false,
setBackground: 'opaque'
setBackground: 'opaque',
mapboxAccessToken: undefined
};

var themeTile = Plotly.Snapshot.clone(dummyGraphObj, themeOptions);