diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index 7971cd2ef8d..30c2a2b68c8 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -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 diff --git a/src/plots/plots.js b/src/plots/plots.js index 404e347ed6e..fb7db552e37 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -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') diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index 7b7f74ffbec..041aa96ae82 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -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(); + }); + }); }); });