Skip to content

Commit 0673823

Browse files
authored
Merge pull request #2760 from plotly/chriddyp-patch-1
Add `plotlyServerUrl` to `baseUrl`
2 parents bcab36e + 928949d commit 0673823

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/plot_api/plot_config.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ module.exports = {
2121
// no interactivity, for export or image generation
2222
staticPlot: false,
2323

24+
// base URL for the 'Edit in Chart Studio' (aka sendDataToCloud) mode bar button
25+
// and the showLink/sendData on-graph link
26+
plotlyServerURL: 'https://plot.ly',
27+
2428
/*
2529
* we can edit titles, move annotations, etc - sets all pieces of `edits`
2630
* unless a separate `edits` config item overrides individual parts

src/plots/plots.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function positionPlayWithData(gd, container) {
214214
plots.sendDataToCloud = function(gd) {
215215
gd.emit('plotly_beforeexport');
216216

217-
var baseUrl = (window.PLOTLYENV && window.PLOTLYENV.BASE_URL) || 'https://plot.ly';
217+
var baseUrl = (window.PLOTLYENV || {}).BASE_URL || gd._context.plotlyServerURL;
218218

219219
var hiddenformDiv = d3.select(gd)
220220
.append('div')

test/jasmine/tests/config_test.js

+56
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,63 @@ describe('config argument', function() {
470470
var editBox = document.getElementsByClassName('plugin-editable editable')[0];
471471
expect(editBox).toBeUndefined();
472472
});
473+
});
474+
475+
describe('plotlyServerURL:', function() {
476+
var gd;
477+
var form;
478+
479+
beforeEach(function() {
480+
gd = createGraphDiv();
481+
spyOn(HTMLFormElement.prototype, 'submit').and.callFake(function() {
482+
form = this;
483+
});
484+
});
473485

486+
afterEach(destroyGraphDiv);
487+
488+
it('should default to plotly cloud', function(done) {
489+
Plotly.plot(gd, [], {})
490+
.then(function() {
491+
expect(gd._context.plotlyServerURL).toBe('https://plot.ly');
492+
493+
Plotly.Plots.sendDataToCloud(gd);
494+
expect(form.action).toBe('https://plot.ly/external');
495+
expect(form.method).toBe('post');
496+
})
497+
.catch(failTest)
498+
.then(done);
499+
});
474500

501+
it('can be set to other base urls', function(done) {
502+
Plotly.plot(gd, [], {}, {plotlyServerURL: 'dummy'})
503+
.then(function() {
504+
expect(gd._context.plotlyServerURL).toBe('dummy');
505+
506+
Plotly.Plots.sendDataToCloud(gd);
507+
expect(form.action).toContain('/dummy/external');
508+
expect(form.method).toBe('post');
509+
})
510+
.catch(failTest)
511+
.then(done);
512+
});
513+
514+
it('has lesser priotiy then window env', function(done) {
515+
window.PLOTLYENV = {BASE_URL: 'yo'};
516+
517+
Plotly.plot(gd, [], {}, {plotlyServerURL: 'dummy'})
518+
.then(function() {
519+
expect(gd._context.plotlyServerURL).toBe('dummy');
520+
521+
Plotly.Plots.sendDataToCloud(gd);
522+
expect(form.action).toContain('/yo/external');
523+
expect(form.method).toBe('post');
524+
})
525+
.catch(failTest)
526+
.then(function() {
527+
delete window.PLOTLY_ENV;
528+
done();
529+
});
530+
});
475531
});
476532
});

0 commit comments

Comments
 (0)