From 0fce62dd453cc586d6aaf3f5ec5968bb2e03cd66 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 26 Dec 2018 08:31:43 -0500 Subject: [PATCH 1/8] Pass through all user-specified config options to Plotly.js and raise a warning for options that are not known by plotly.py to be valid Previously we would silently drop unrecognized options. This change was done so that if plotly.py falls behind plotly.js in the future, the user still has a way to specify all config options supported by plotly.js --- plotly/offline/offline.py | 19 +++++++++++++++---- .../test_core/test_offline/test_offline.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 297e739810..ccff21e5b9 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -114,9 +114,6 @@ def _build_mathjax_script(url): def _get_jconfig(config): - # TODO: The get_config 'source of truth' should - # really be somewhere other than plotly.plotly - config = config if config else plotly.plotly.get_config() configkeys = ( 'staticPlot', @@ -152,7 +149,21 @@ def _get_jconfig(config): 'locales', ) - clean_config = dict((k, config[k]) for k in configkeys if k in config) + if config and isinstance(config, dict): + # Warn user on unrecognised config options. We make this a warning + # rather than an error since we don't have code generation logic in + # place yet to guarantee that the config options in plotly.py are up + # to date + bad_config = [k for k in config if k not in configkeys] + if bad_config: + warnings.warn(""" +Unrecognised config options supplied: {bad_config}""" + .format(bad_config=bad_config)) + + clean_config = config + else: + config = plotly.plotly.get_config() + clean_config = dict((k, config[k]) for k in configkeys if k in config) # TODO: The get_config 'source of truth' should # really be somewhere other than plotly.plotly diff --git a/plotly/tests/test_core/test_offline/test_offline.py b/plotly/tests/test_core/test_offline/test_offline.py index f79fa8fc30..7aaa00d7f2 100644 --- a/plotly/tests/test_core/test_offline/test_offline.py +++ b/plotly/tests/test_core/test_offline/test_offline.py @@ -12,6 +12,8 @@ import plotly import json +import sys + fig = { 'data': [ @@ -299,6 +301,20 @@ def test_config(self): self.assertIn('"showLink": true', html) self.assertIn('"editable": true', html) + def test_config_bad_options(self): + config = dict(bogus=42) + + def get_html(): + return self._read_html(plotly.offline.plot(fig, config=config, + auto_open=False)) + if sys.version_info > (3, 3): + with self.assertWarnsRegex(UserWarning, "'bogus'"): + html = get_html() + else: + html = get_html() + + self.assertIn('"bogus": 42', html) + def test_plotlyjs_version(self): with open('js/package.json', 'rt') as f: package_json = json.load(f) From ef8df846d52fbf5f8bb999b3e70e1b34cac511ec Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 26 Dec 2018 08:37:54 -0500 Subject: [PATCH 2/8] Spelling --- plotly/offline/offline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index ccff21e5b9..2a6ccade59 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -157,7 +157,7 @@ def _get_jconfig(config): bad_config = [k for k in config if k not in configkeys] if bad_config: warnings.warn(""" -Unrecognised config options supplied: {bad_config}""" +Unrecognized config options supplied: {bad_config}""" .format(bad_config=bad_config)) clean_config = config From 628c76f7ea8c54cc3854905553f8f7ea3290e6d5 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 26 Dec 2018 08:44:29 -0500 Subject: [PATCH 3/8] Add missing config options for 1.43.0 --- plotly/offline/offline.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 2a6ccade59..f20804eb93 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -121,6 +121,7 @@ def _get_jconfig(config): 'editable', 'edits', 'autosizable', + 'responsive', 'queueLength', 'fillFrame', 'frameMargins', @@ -131,6 +132,7 @@ def _get_jconfig(config): 'showAxisRangeEntryBoxes', 'showLink', 'sendData', + 'showSendToCloud', 'linkText', 'showSources', 'displayModeBar', @@ -139,6 +141,7 @@ def _get_jconfig(config): 'modeBarButtons', 'toImageButtonOptions', 'displaylogo', + 'watermark', 'plotGlPixelRatio', 'setBackground', 'topojsonURL', From 9320fd22d8fbf98f260c8f9e83c869506d50feac Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 26 Dec 2018 08:57:50 -0500 Subject: [PATCH 4/8] Change show_link default to False. Along with the change to set `showSendToCloud` to False by default in plotly.js 1.43.0, now the default behavior of plotly.py/plotly.js is that there are no options available by default that will send data off of the local network. --- plotly/offline/offline.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index f20804eb93..2daf3cf98a 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -395,7 +395,7 @@ def _plot_html(figure_or_data, config, validate, default_width, return plotly_html_div, plotdivid, width, height -def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', +def iplot(figure_or_data, show_link=False, link_text='Export to plot.ly', validate=True, image=None, filename='plot_image', image_width=800, image_height=600, config=None): """ @@ -411,7 +411,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', graph descriptions. Keyword arguments: - show_link (default=True) -- display a link in the bottom-right corner of + show_link (default=False) -- display a link in the bottom-right corner of of the chart that will export the chart to Plotly Cloud or Plotly Enterprise link_text (default='Export to plot.ly') -- the text of export link @@ -511,7 +511,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', ipython_display.display(ipython_display.HTML(script)) -def plot(figure_or_data, show_link=True, link_text='Export to plot.ly', +def plot(figure_or_data, show_link=False, link_text='Export to plot.ly', validate=True, output_type='file', include_plotlyjs=True, filename='temp-plot.html', auto_open=True, image=None, image_filename='plot_image', image_width=800, image_height=600, @@ -537,7 +537,7 @@ def plot(figure_or_data, show_link=True, link_text='Export to plot.ly', graph descriptions. Keyword arguments: - show_link (default=True) -- display a link in the bottom-right corner of + show_link (default=False) -- display a link in the bottom-right corner of of the chart that will export the chart to Plotly Cloud or Plotly Enterprise link_text (default='Export to plot.ly') -- the text of export link @@ -756,7 +756,7 @@ def plot(figure_or_data, show_link=True, link_text='Export to plot.ly', def plot_mpl(mpl_fig, resize=False, strip_style=False, - verbose=False, show_link=True, link_text='Export to plot.ly', + verbose=False, show_link=False, link_text='Export to plot.ly', validate=True, output_type='file', include_plotlyjs=True, filename='temp-plot.html', auto_open=True, image=None, image_filename='plot_image', @@ -776,7 +776,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, resize (default=False) -- allow plotly to choose the figure size. strip_style (default=False) -- allow plotly to choose style options. verbose (default=False) -- print message. - show_link (default=True) -- display a link in the bottom-right corner of + show_link (default=False) -- display a link in the bottom-right corner of of the chart that will export the chart to Plotly Cloud or Plotly Enterprise link_text (default='Export to plot.ly') -- the text of export link @@ -838,7 +838,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, def iplot_mpl(mpl_fig, resize=False, strip_style=False, - verbose=False, show_link=True, + verbose=False, show_link=False, link_text='Export to plot.ly', validate=True, image=None, image_filename='plot_image', image_height=600, image_width=800): @@ -861,7 +861,7 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False, resize (default=False) -- allow plotly to choose the figure size. strip_style (default=False) -- allow plotly to choose style options. verbose (default=False) -- print message. - show_link (default=True) -- display a link in the bottom-right corner of + show_link (default=False) -- display a link in the bottom-right corner of of the chart that will export the chart to Plotly Cloud or Plotly Enterprise link_text (default='Export to plot.ly') -- the text of export link @@ -902,7 +902,7 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False, def enable_mpl_offline(resize=False, strip_style=False, - verbose=False, show_link=True, + verbose=False, show_link=False, link_text='Export to plot.ly', validate=True): """ Convert mpl plots to locally hosted HTML documents. From 0a2ad0f33b0a941fc7ec12aac2c2998a1bdbffe5 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 26 Dec 2018 09:53:21 -0500 Subject: [PATCH 5/8] Fix config test --- plotly/tests/test_core/test_offline/test_offline.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plotly/tests/test_core/test_offline/test_offline.py b/plotly/tests/test_core/test_offline/test_offline.py index 7aaa00d7f2..a1a06332e5 100644 --- a/plotly/tests/test_core/test_offline/test_offline.py +++ b/plotly/tests/test_core/test_offline/test_offline.py @@ -294,6 +294,7 @@ def test_autoresizing_div(self): def test_config(self): config = dict(linkText='Plotly rocks!', + showLink=True, editable=True) html = self._read_html(plotly.offline.plot(fig, config=config, auto_open=False)) From 9eb038c80519f07706b48bdfcda3c4ef2b1d2902 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 26 Dec 2018 10:06:41 -0500 Subject: [PATCH 6/8] Remove warning check in config test for now This test was running into a bug in unittest (https://bugs.python.org/issue29620). Revisit this when we move to pytest. --- .../tests/test_core/test_offline/test_offline.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plotly/tests/test_core/test_offline/test_offline.py b/plotly/tests/test_core/test_offline/test_offline.py index a1a06332e5..f1de556ea1 100644 --- a/plotly/tests/test_core/test_offline/test_offline.py +++ b/plotly/tests/test_core/test_offline/test_offline.py @@ -306,13 +306,13 @@ def test_config_bad_options(self): config = dict(bogus=42) def get_html(): - return self._read_html(plotly.offline.plot(fig, config=config, - auto_open=False)) - if sys.version_info > (3, 3): - with self.assertWarnsRegex(UserWarning, "'bogus'"): - html = get_html() - else: - html = get_html() + return self._read_html(plotly.offline.plot( + fig, config=config, auto_open=False)) + + # Attempts to validate warning ran into + # https://bugs.python.org/issue29620, don't check warning for now. + # Revisit when we move to pytest + html = get_html() self.assertIn('"bogus": 42', html) From 23413aa1c721a0f33425dd9077656b3693ddca82 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Thu, 27 Dec 2018 06:19:20 -0500 Subject: [PATCH 7/8] Remove unused sys import --- plotly/tests/test_core/test_offline/test_offline.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plotly/tests/test_core/test_offline/test_offline.py b/plotly/tests/test_core/test_offline/test_offline.py index f1de556ea1..71f6e55dd6 100644 --- a/plotly/tests/test_core/test_offline/test_offline.py +++ b/plotly/tests/test_core/test_offline/test_offline.py @@ -12,8 +12,6 @@ import plotly import json -import sys - fig = { 'data': [ From 2fb3a41c02564ff790664b8054fb4981cc682f50 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Thu, 27 Dec 2018 06:19:49 -0500 Subject: [PATCH 8/8] Spelling --- plotly/offline/offline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 2daf3cf98a..4317febdeb 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -153,7 +153,7 @@ def _get_jconfig(config): ) if config and isinstance(config, dict): - # Warn user on unrecognised config options. We make this a warning + # Warn user on unrecognized config options. We make this a warning # rather than an error since we don't have code generation logic in # place yet to guarantee that the config options in plotly.py are up # to date