From 6e839487f165dddbd7dad9d0ebedd4c05e7f5ae5 Mon Sep 17 00:00:00 2001 From: John Stowers Date: Tue, 24 Nov 2015 10:48:04 +0100 Subject: [PATCH 1/2] Remove unused code --- plotly/offline/offline.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 24e08340bee..7d97bac7f6c 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -131,13 +131,6 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', plotly_platform_url = session.get_session_config().get('plotly_domain', 'https://plot.ly') - if (plotly_platform_url != 'https://plot.ly' and - link_text == 'Export to plot.ly'): - - link_domain = plotly_platform_url\ - .replace('https://', '')\ - .replace('http://', '') - link_text = link_text.replace('plot.ly', link_domain) display(HTML( '')) +def plot(figure_or_data, html_style='standalone', show_link=True, link_text='Export to plot.ly', validate=True): + """ Configured to work with localhost Plotly graph viewer + """ + EMBED_TYPES = ('standalone', 'body', 'div') + if html_style not in EMBED_TYPES: + raise ValueError('html_style must be one of %s' % ', '.join(EMBED_TYPES)) + + html = "" + if html_style == 'standalone': + html += '' + elif html_style == 'body': + html += '' + + figure = tools.return_figure_from_figure_or_data(figure_or_data, validate) + + width = figure.get('layout', {}).get('width', '100%') + height = figure.get('layout', {}).get('height', 525) + try: + float(width) + except (ValueError, TypeError): + pass + else: + width = str(width) + 'px' + + try: + float(width) + except (ValueError, TypeError): + pass + else: + width = str(width) + 'px' + + plotdivid = uuid.uuid4() + jdata = json.dumps(figure.get('data', []), cls=utils.PlotlyJSONEncoder) + jlayout = json.dumps(figure.get('layout', {}), cls=utils.PlotlyJSONEncoder) + + config = {} + config['showLink'] = show_link + config['linkText'] = link_text + jconfig = json.dumps(config) + + script = '\n'.join([ + 'Plotly.plot("{id}", {data}, {layout}, {config}).then(function() {{', + ' $(".{id}.loading").remove();', + '}})' + ]).format(id=plotdivid, + data=jdata, + layout=jlayout, + config=jconfig) + + html += '
'\ + 'Drawing...
'\ + '
'\ + '
'\ + ''\ + ''.format(id=plotdivid, script=script, + height=height, width=width) + + if html_style == 'body': + html += '' + elif html_style == 'standalone': + html += '' + + return html + + def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True): """ @@ -102,32 +170,6 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', raise ImportError('`iplot` can only run inside an IPython Notebook.') from IPython.display import HTML, display - figure = tools.return_figure_from_figure_or_data(figure_or_data, validate) - - width = figure.get('layout', {}).get('width', '100%') - height = figure.get('layout', {}).get('height', 525) - try: - float(width) - except (ValueError, TypeError): - pass - else: - width = str(width) + 'px' - - try: - float(width) - except (ValueError, TypeError): - pass - else: - width = str(width) + 'px' - - plotdivid = uuid.uuid4() - jdata = json.dumps(figure.get('data', []), cls=utils.PlotlyJSONEncoder) - jlayout = json.dumps(figure.get('layout', {}), cls=utils.PlotlyJSONEncoder) - - config = {} - config['showLink'] = show_link - config['linkText'] = link_text - jconfig = json.dumps(config) plotly_platform_url = session.get_session_config().get('plotly_domain', 'https://plot.ly') @@ -139,30 +181,8 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', '' )) - script = '\n'.join([ - 'Plotly.plot("{id}", {data}, {layout}, {config}).then(function() {{', - ' $(".{id}.loading").remove();', - '}})' - ]).format(id=plotdivid, - data=jdata, - layout=jlayout, - config=jconfig) - - display(HTML('' - '
' - 'Drawing...
' - '
' - '
' - '' - ''.format(id=plotdivid, script=script, - height=height, width=width))) - - -def plot(): - """ Configured to work with localhost Plotly graph viewer - """ - raise NotImplementedError - + display(HTML(plot(figure_or_data, + html_style='div', + show_link=show_link, + link_text=link_text, + validate=validate)))