Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config options and disable show_link by default #1377

Merged
merged 8 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 27 additions & 13 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ 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',
'plotlyServerURL',
'editable',
'edits',
'autosizable',
'responsive',
'queueLength',
'fillFrame',
'frameMargins',
Expand All @@ -134,6 +132,7 @@ def _get_jconfig(config):
'showAxisRangeEntryBoxes',
'showLink',
'sendData',
'showSendToCloud',
'linkText',
'showSources',
'displayModeBar',
Expand All @@ -142,6 +141,7 @@ def _get_jconfig(config):
'modeBarButtons',
'toImageButtonOptions',
'displaylogo',
'watermark',
'plotGlPixelRatio',
'setBackground',
'topojsonURL',
Expand All @@ -152,7 +152,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 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
bad_config = [k for k in config if k not in configkeys]
if bad_config:
warnings.warn("""
Unrecognized 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
Expand Down Expand Up @@ -381,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):
"""
Expand All @@ -397,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
Expand Down Expand Up @@ -497,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,
Expand All @@ -523,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
Expand Down Expand Up @@ -742,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',
Expand All @@ -762,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
Expand Down Expand Up @@ -824,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):
Expand All @@ -847,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
Expand Down Expand Up @@ -888,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.
Expand Down
15 changes: 15 additions & 0 deletions plotly/tests/test_core/test_offline/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,28 @@ 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))
self.assertIn('"linkText": "Plotly rocks!"', html)
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))

# 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)

def test_plotlyjs_version(self):
with open('js/package.json', 'rt') as f:
package_json = json.load(f)
Expand Down