Skip to content

Commit 2482efd

Browse files
authoredDec 27, 2018
Update config options and disable show_link by default (#1377)
* 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 * Add missing config options for 1.43.0 * 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.
1 parent 802609d commit 2482efd

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed
 

‎plotly/offline/offline.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,14 @@ def _build_mathjax_script(url):
114114

115115

116116
def _get_jconfig(config):
117-
# TODO: The get_config 'source of truth' should
118-
# really be somewhere other than plotly.plotly
119-
config = config if config else plotly.plotly.get_config()
120117

121118
configkeys = (
122119
'staticPlot',
123120
'plotlyServerURL',
124121
'editable',
125122
'edits',
126123
'autosizable',
124+
'responsive',
127125
'queueLength',
128126
'fillFrame',
129127
'frameMargins',
@@ -134,6 +132,7 @@ def _get_jconfig(config):
134132
'showAxisRangeEntryBoxes',
135133
'showLink',
136134
'sendData',
135+
'showSendToCloud',
137136
'linkText',
138137
'showSources',
139138
'displayModeBar',
@@ -142,6 +141,7 @@ def _get_jconfig(config):
142141
'modeBarButtons',
143142
'toImageButtonOptions',
144143
'displaylogo',
144+
'watermark',
145145
'plotGlPixelRatio',
146146
'setBackground',
147147
'topojsonURL',
@@ -152,7 +152,21 @@ def _get_jconfig(config):
152152
'locales',
153153
)
154154

155-
clean_config = dict((k, config[k]) for k in configkeys if k in config)
155+
if config and isinstance(config, dict):
156+
# Warn user on unrecognized config options. We make this a warning
157+
# rather than an error since we don't have code generation logic in
158+
# place yet to guarantee that the config options in plotly.py are up
159+
# to date
160+
bad_config = [k for k in config if k not in configkeys]
161+
if bad_config:
162+
warnings.warn("""
163+
Unrecognized config options supplied: {bad_config}"""
164+
.format(bad_config=bad_config))
165+
166+
clean_config = config
167+
else:
168+
config = plotly.plotly.get_config()
169+
clean_config = dict((k, config[k]) for k in configkeys if k in config)
156170

157171
# TODO: The get_config 'source of truth' should
158172
# really be somewhere other than plotly.plotly
@@ -381,7 +395,7 @@ def _plot_html(figure_or_data, config, validate, default_width,
381395
return plotly_html_div, plotdivid, width, height
382396

383397

384-
def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
398+
def iplot(figure_or_data, show_link=False, link_text='Export to plot.ly',
385399
validate=True, image=None, filename='plot_image', image_width=800,
386400
image_height=600, config=None):
387401
"""
@@ -397,7 +411,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
397411
graph descriptions.
398412
399413
Keyword arguments:
400-
show_link (default=True) -- display a link in the bottom-right corner of
414+
show_link (default=False) -- display a link in the bottom-right corner of
401415
of the chart that will export the chart to
402416
Plotly Cloud or Plotly Enterprise
403417
link_text (default='Export to plot.ly') -- the text of export link
@@ -497,7 +511,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
497511
ipython_display.display(ipython_display.HTML(script))
498512

499513

500-
def plot(figure_or_data, show_link=True, link_text='Export to plot.ly',
514+
def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
501515
validate=True, output_type='file', include_plotlyjs=True,
502516
filename='temp-plot.html', auto_open=True, image=None,
503517
image_filename='plot_image', image_width=800, image_height=600,
@@ -523,7 +537,7 @@ def plot(figure_or_data, show_link=True, link_text='Export to plot.ly',
523537
graph descriptions.
524538
525539
Keyword arguments:
526-
show_link (default=True) -- display a link in the bottom-right corner of
540+
show_link (default=False) -- display a link in the bottom-right corner of
527541
of the chart that will export the chart to Plotly Cloud or
528542
Plotly Enterprise
529543
link_text (default='Export to plot.ly') -- the text of export link
@@ -742,7 +756,7 @@ def plot(figure_or_data, show_link=True, link_text='Export to plot.ly',
742756

743757

744758
def plot_mpl(mpl_fig, resize=False, strip_style=False,
745-
verbose=False, show_link=True, link_text='Export to plot.ly',
759+
verbose=False, show_link=False, link_text='Export to plot.ly',
746760
validate=True, output_type='file', include_plotlyjs=True,
747761
filename='temp-plot.html', auto_open=True,
748762
image=None, image_filename='plot_image',
@@ -762,7 +776,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False,
762776
resize (default=False) -- allow plotly to choose the figure size.
763777
strip_style (default=False) -- allow plotly to choose style options.
764778
verbose (default=False) -- print message.
765-
show_link (default=True) -- display a link in the bottom-right corner of
779+
show_link (default=False) -- display a link in the bottom-right corner of
766780
of the chart that will export the chart to Plotly Cloud or
767781
Plotly Enterprise
768782
link_text (default='Export to plot.ly') -- the text of export link
@@ -824,7 +838,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False,
824838

825839

826840
def iplot_mpl(mpl_fig, resize=False, strip_style=False,
827-
verbose=False, show_link=True,
841+
verbose=False, show_link=False,
828842
link_text='Export to plot.ly', validate=True,
829843
image=None, image_filename='plot_image',
830844
image_height=600, image_width=800):
@@ -847,7 +861,7 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
847861
resize (default=False) -- allow plotly to choose the figure size.
848862
strip_style (default=False) -- allow plotly to choose style options.
849863
verbose (default=False) -- print message.
850-
show_link (default=True) -- display a link in the bottom-right corner of
864+
show_link (default=False) -- display a link in the bottom-right corner of
851865
of the chart that will export the chart to
852866
Plotly Cloud or Plotly Enterprise
853867
link_text (default='Export to plot.ly') -- the text of export link
@@ -888,7 +902,7 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
888902

889903

890904
def enable_mpl_offline(resize=False, strip_style=False,
891-
verbose=False, show_link=True,
905+
verbose=False, show_link=False,
892906
link_text='Export to plot.ly', validate=True):
893907
"""
894908
Convert mpl plots to locally hosted HTML documents.

‎plotly/tests/test_core/test_offline/test_offline.py

+15
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,28 @@ def test_autoresizing_div(self):
292292

293293
def test_config(self):
294294
config = dict(linkText='Plotly rocks!',
295+
showLink=True,
295296
editable=True)
296297
html = self._read_html(plotly.offline.plot(fig, config=config,
297298
auto_open=False))
298299
self.assertIn('"linkText": "Plotly rocks!"', html)
299300
self.assertIn('"showLink": true', html)
300301
self.assertIn('"editable": true', html)
301302

303+
def test_config_bad_options(self):
304+
config = dict(bogus=42)
305+
306+
def get_html():
307+
return self._read_html(plotly.offline.plot(
308+
fig, config=config, auto_open=False))
309+
310+
# Attempts to validate warning ran into
311+
# https://bugs.python.org/issue29620, don't check warning for now.
312+
# Revisit when we move to pytest
313+
html = get_html()
314+
315+
self.assertIn('"bogus": 42', html)
316+
302317
def test_plotlyjs_version(self):
303318
with open('js/package.json', 'rt') as f:
304319
package_json = json.load(f)

0 commit comments

Comments
 (0)
Please sign in to comment.