From 468b8448f518fd2c9bf583a0cda7aa27d6b0421f Mon Sep 17 00:00:00 2001 From: Chris Parmer Date: Wed, 27 Jun 2018 14:05:14 -0400 Subject: [PATCH 1/4] Add `plotlyServerUrl` to `baseUrl` Fixes https://github.com/plotly/plotly.js/issues/2759#issuecomment-400776193 --- src/plots/plots.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 404e347ed6e..7b56ac12d34 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -214,7 +214,11 @@ 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 && window.PLOTLYENV.BASE_URL) || + (gd.framework.getConfig().plotlyServerUrl) || + 'https://plot.ly' + ); var hiddenformDiv = d3.select(gd) .append('div') From cacc76b0193f2b541598e52b78f8c6549091557e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 27 Jun 2018 15:09:01 -0400 Subject: [PATCH 2/4] fixups & :lock: for plotlyServerUrl --- src/plot_api/plot_config.js | 4 ++++ src/plots/plots.js | 6 +----- test/jasmine/tests/config_test.js | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index 7971cd2ef8d..4ce23c749f8 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 7b56ac12d34..12527feef34 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -214,11 +214,7 @@ function positionPlayWithData(gd, container) { plots.sendDataToCloud = function(gd) { gd.emit('plotly_beforeexport'); - var baseUrl = ( - (window.PLOTLYENV && window.PLOTLYENV.BASE_URL) || - (gd.framework.getConfig().plotlyServerUrl) || - '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..886ad464256 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -470,7 +470,33 @@ describe('config argument', function() { var editBox = document.getElementsByClassName('plugin-editable editable')[0]; expect(editBox).toBeUndefined(); }); + }); + + describe('plotlyServerUrl:', function() { + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + afterEach(destroyGraphDiv); + it('should default to plotly cloud', function(done) { + Plotly.plot(gd, [], {}) + .then(function() { + expect(gd._context.plotlyServerUrl).toBe('https://plot.ly'); + }) + .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'); + }) + .catch(failTest) + .then(done); + }); }); }); From 79f93b92afc1675b765f79c8c8a601e941d13a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 27 Jun 2018 16:17:34 -0400 Subject: [PATCH 3/4] improve plotlyServerUrl test --- test/jasmine/tests/config_test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index 886ad464256..bf7114893b6 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -474,9 +474,13 @@ describe('config argument', function() { describe('plotlyServerUrl:', function() { var gd; + var form; beforeEach(function() { gd = createGraphDiv(); + spyOn(HTMLFormElement.prototype, 'submit').and.callFake(function() { + form = this; + }); }); afterEach(destroyGraphDiv); @@ -485,6 +489,10 @@ describe('config argument', function() { 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); @@ -494,9 +502,31 @@ describe('config argument', function() { 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(); + }); + }); }); }); From 928949d8912d89bc31e490a965ecc9e2834f7ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 27 Jun 2018 16:21:34 -0400 Subject: [PATCH 4/4] rename plotlyServerUrl -> plotlyServerURL ... to match topojsonURL config option --- src/plot_api/plot_config.js | 4 ++-- src/plots/plots.js | 2 +- test/jasmine/tests/config_test.js | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index 4ce23c749f8..30c2a2b68c8 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -21,9 +21,9 @@ module.exports = { // no interactivity, for export or image generation staticPlot: false, - // base url for the 'Edit in Chart Studio' (aka sendDataToCloud) mode bar button + // base URL for the 'Edit in Chart Studio' (aka sendDataToCloud) mode bar button // and the showLink/sendData on-graph link - plotlyServerUrl: 'https://plot.ly', + plotlyServerURL: 'https://plot.ly', /* * we can edit titles, move annotations, etc - sets all pieces of `edits` diff --git a/src/plots/plots.js b/src/plots/plots.js index 12527feef34..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 || {}).BASE_URL || gd._context.plotlyServerUrl; + 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 bf7114893b6..041aa96ae82 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -472,7 +472,7 @@ describe('config argument', function() { }); }); - describe('plotlyServerUrl:', function() { + describe('plotlyServerURL:', function() { var gd; var form; @@ -488,7 +488,7 @@ describe('config argument', function() { it('should default to plotly cloud', function(done) { Plotly.plot(gd, [], {}) .then(function() { - expect(gd._context.plotlyServerUrl).toBe('https://plot.ly'); + expect(gd._context.plotlyServerURL).toBe('https://plot.ly'); Plotly.Plots.sendDataToCloud(gd); expect(form.action).toBe('https://plot.ly/external'); @@ -499,9 +499,9 @@ describe('config argument', function() { }); it('can be set to other base urls', function(done) { - Plotly.plot(gd, [], {}, {plotlyServerUrl: 'dummy'}) + Plotly.plot(gd, [], {}, {plotlyServerURL: 'dummy'}) .then(function() { - expect(gd._context.plotlyServerUrl).toBe('dummy'); + expect(gd._context.plotlyServerURL).toBe('dummy'); Plotly.Plots.sendDataToCloud(gd); expect(form.action).toContain('/dummy/external'); @@ -514,9 +514,9 @@ describe('config argument', function() { it('has lesser priotiy then window env', function(done) { window.PLOTLYENV = {BASE_URL: 'yo'}; - Plotly.plot(gd, [], {}, {plotlyServerUrl: 'dummy'}) + Plotly.plot(gd, [], {}, {plotlyServerURL: 'dummy'}) .then(function() { - expect(gd._context.plotlyServerUrl).toBe('dummy'); + expect(gd._context.plotlyServerURL).toBe('dummy'); Plotly.Plots.sendDataToCloud(gd); expect(form.action).toContain('/yo/external');