Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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;
Copy link
Contributor

Choose a reason for hiding this comment

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

thank you @alexcjohnson for the tip!

});
});

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');
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests aren't great, but I couldn't find an easy way to mock the form submit in

plots.sendDataToCloud = function(gd) {
gd.emit('plotly_beforeexport');
var baseUrl = (window.PLOTLYENV && window.PLOTLYENV.BASE_URL) || 'https://plot.ly';
var hiddenformDiv = d3.select(gd)
.append('div')
.attr('id', 'hiddenform')
.style('display', 'none');
var hiddenform = hiddenformDiv
.append('form')
.attr({
action: baseUrl + '/external',
method: 'post',
target: '_blank'
});
var hiddenformInput = hiddenform
.append('input')
.attr({
type: 'text',
name: 'data'
});
hiddenformInput.node().value = plots.graphJson(gd, false, 'keepdata');
hiddenform.node().submit();
hiddenformDiv.remove();
gd.emit('plotly_afterexport');
return false;
};


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();
});
});
});
});