Skip to content

Add plotlyServerUrl to baseUrl #2760

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

Merged
merged 4 commits into from
Jun 27, 2018
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
4 changes: 4 additions & 0 deletions src/plot_api/plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module.exports = {
// no interactivity, for export or image generation
staticPlot: false,

// base URL for the 'Edit in Chart Studio' (aka sendDataToCloud) mode bar button
// and the showLink/sendData on-graph link
plotlyServerURL: 'https://plot.ly',

/*
* we can edit titles, move annotations, etc - sets all pieces of `edits`
* unless a separate `edits` config item overrides individual parts
Expand Down
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function positionPlayWithData(gd, container) {
plots.sendDataToCloud = function(gd) {
gd.emit('plotly_beforeexport');

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

var hiddenformDiv = d3.select(gd)
.append('div')
Expand Down
56 changes: 56 additions & 0 deletions test/jasmine/tests/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,63 @@ describe('config argument', function() {
var editBox = document.getElementsByClassName('plugin-editable editable')[0];
expect(editBox).toBeUndefined();
});
});

describe('plotlyServerURL:', function() {
var gd;
var form;

beforeEach(function() {
gd = createGraphDiv();
spyOn(HTMLFormElement.prototype, 'submit').and.callFake(function() {
form = this;
});
});

afterEach(destroyGraphDiv);

it('should default to plotly cloud', function(done) {
Plotly.plot(gd, [], {})
.then(function() {
expect(gd._context.plotlyServerURL).toBe('https://plot.ly');

Plotly.Plots.sendDataToCloud(gd);
expect(form.action).toBe('https://plot.ly/external');
expect(form.method).toBe('post');
})
.catch(failTest)
.then(done);
});

it('can be set to other base urls', function(done) {
Plotly.plot(gd, [], {}, {plotlyServerURL: 'dummy'})
.then(function() {
expect(gd._context.plotlyServerURL).toBe('dummy');

Plotly.Plots.sendDataToCloud(gd);
expect(form.action).toContain('/dummy/external');
expect(form.method).toBe('post');
})
.catch(failTest)
.then(done);
});

it('has lesser priotiy then window env', function(done) {
window.PLOTLYENV = {BASE_URL: 'yo'};

Plotly.plot(gd, [], {}, {plotlyServerURL: 'dummy'})
.then(function() {
expect(gd._context.plotlyServerURL).toBe('dummy');

Plotly.Plots.sendDataToCloud(gd);
expect(form.action).toContain('/yo/external');
expect(form.method).toBe('post');
})
.catch(failTest)
.then(function() {
delete window.PLOTLY_ENV;
done();
});
});
});
});