Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6255f6d

Browse filesBrowse files
authored
Merge pull request #1598 from plotly/mapbox-to-image-context
Mapbox to image context
2 parents b32c21d + 6dd25e2 commit 6255f6d
Copy full SHA for 6255f6d

File tree

4 files changed

+86
-7
lines changed
Filter options

4 files changed

+86
-7
lines changed

‎src/snapshot/cloneplot.js

Copy file name to clipboardExpand all lines: src/snapshot/cloneplot.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = function clonePlot(graphObj, options) {
7070
var oldLayout = graphObj.layout;
7171
var newData = extendDeep([], oldData);
7272
var newLayout = extendDeep({}, oldLayout, cloneLayoutOverride(options.tileClass));
73+
var context = graphObj._context || {};
7374

7475
if(options.width) newLayout.width = options.width;
7576
if(options.height) newLayout.height = options.height;
@@ -153,7 +154,8 @@ module.exports = function clonePlot(graphObj, options) {
153154
options.plotGlPixelRatio,
154155
displaylogo: options.displaylogo || false,
155156
showLink: options.showLink || false,
156-
showTips: options.showTips || false
157+
showTips: options.showTips || false,
158+
mapboxAccessToken: context.mapboxAccessToken
157159
}
158160
};
159161

‎test/jasmine/tests/mapbox_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/mapbox_test.js
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,5 +964,78 @@ describe('@noCI, mapbox plots', function() {
964964
}, MOUSE_DELAY);
965965
});
966966
}
967+
});
968+
969+
describe('@noCI, mapbox toImage', function() {
970+
var MINIMUM_LENGTH = 1e5;
971+
972+
var gd;
973+
974+
beforeEach(function() {
975+
gd = createGraphDiv();
976+
});
977+
978+
afterEach(function() {
979+
Plotly.purge(gd);
980+
Plotly.setPlotConfig({ mapboxAccessToken: null });
981+
destroyGraphDiv();
982+
});
983+
984+
it('should generate image data with global credentials', function(done) {
985+
Plotly.setPlotConfig({
986+
mapboxAccessToken: MAPBOX_ACCESS_TOKEN
987+
});
988+
989+
Plotly.newPlot(gd, [{
990+
type: 'scattermapbox',
991+
lon: [0, 10, 20],
992+
lat: [-10, 10, -10]
993+
}])
994+
.then(function() {
995+
return Plotly.toImage(gd);
996+
})
997+
.then(function(imgData) {
998+
expect(imgData.length).toBeGreaterThan(MINIMUM_LENGTH);
999+
})
1000+
.catch(failTest)
1001+
.then(done);
1002+
}, LONG_TIMEOUT_INTERVAL);
1003+
1004+
it('should generate image data with config credentials', function(done) {
1005+
Plotly.newPlot(gd, [{
1006+
type: 'scattermapbox',
1007+
lon: [0, 10, 20],
1008+
lat: [-10, 10, -10]
1009+
}], {}, {
1010+
mapboxAccessToken: MAPBOX_ACCESS_TOKEN
1011+
})
1012+
.then(function() {
1013+
return Plotly.toImage(gd);
1014+
})
1015+
.then(function(imgData) {
1016+
expect(imgData.length).toBeGreaterThan(MINIMUM_LENGTH);
1017+
})
1018+
.catch(failTest)
1019+
.then(done);
1020+
}, LONG_TIMEOUT_INTERVAL);
9671021

1022+
it('should generate image data with layout credentials', function(done) {
1023+
Plotly.newPlot(gd, [{
1024+
type: 'scattermapbox',
1025+
lon: [0, 10, 20],
1026+
lat: [-10, 10, -10]
1027+
}], {
1028+
mapbox: {
1029+
accesstoken: MAPBOX_ACCESS_TOKEN
1030+
}
1031+
})
1032+
.then(function() {
1033+
return Plotly.toImage(gd);
1034+
})
1035+
.then(function(imgData) {
1036+
expect(imgData.length).toBeGreaterThan(MINIMUM_LENGTH);
1037+
})
1038+
.catch(failTest)
1039+
.then(done);
1040+
}, LONG_TIMEOUT_INTERVAL);
9681041
});

‎test/jasmine/tests/scattermapbox_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/scattermapbox_test.js
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ function move(fromX, fromY, toX, toY, delay) {
2424
});
2525
}
2626

27-
Plotly.setPlotConfig({
28-
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
29-
});
30-
31-
3227
describe('scattermapbox defaults', function() {
3328
'use strict';
3429

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

339+
Plotly.setPlotConfig({
340+
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
341+
});
342+
344343
gd = createGraphDiv();
345344

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

522+
Plotly.setPlotConfig({
523+
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
524+
});
525+
523526
gd = createGraphDiv();
524527
mockCopy = Lib.extendDeep({}, mock);
525528

‎test/jasmine/tests/snapshot_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/snapshot_test.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ describe('Plotly.Snapshot', function() {
8080
displaylogo: false,
8181
showLink: false,
8282
showTips: false,
83-
setBackground: 'opaque'
83+
setBackground: 'opaque',
84+
mapboxAccessToken: undefined
8485
};
8586

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.