Skip to content

Make offline.plot/iplot accept a plot config dict #714

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

Merged
merged 3 commits into from
Apr 20, 2017

Conversation

kernc
Copy link
Contributor

@kernc kernc commented Mar 16, 2017

Make plotly.offline.plot() (iplot()) accept a config dictionary so the various configuration options can be passed. Includes unit tests.

Addresses https://community.plot.ly/t/removing-hover-toolbar-and-other-configuration-options-with-the-python-api/374.

Also took liberty to slightly improve surrounding offline tests.

If you find the proposed feature something acceptable, I'd be happy to also amend the docs.

@Kully
Copy link
Contributor

Kully commented Apr 19, 2017

@kernc taking a look right now

config['showLink'] = show_link
config['linkText'] = link_text
config = dict(config) if config else {}
config.setdefault('showLink', show_link)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just write config['showLink] = show_link? It's clearer to me.

Same goes with config.setdefault('linkText', link_text)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for dict.setdefault is that it doesn't set the value if it is already set. This gives user the option to construct the whole view configuration dict beforehand, not needing to worry about having showLink overwritten or needing to pass it separately as show_link. I'd rather go with:

if 'linkText' not in config:
    config['linkText'] = link_text

but I think .setdefault() is pretty standard. Do you insist? The behavior of not overriding the option if it's already set is documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, don't insist. I get the reasoning now.

config['showLink'] = show_link
config['linkText'] = link_text
config = dict(config) if config else {}
config.setdefault('showLink', show_link)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

self.assertTrue(data_json in html) # data is in there
self.assertTrue(layout_json in html) # so is layout
self.assertTrue(PLOTLYJS in html) # and the source code
self.assertIn('Plotly.newPlot', html) # plot command is in there
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic edit! Simplifies the function of the test with the assertIn method

# and it's an <html> doc
self.assertTrue(html.startswith('<html>') and html.endswith('</html>'))

def test_including_plotlyjs(self):
html = self._read_html(plotly.offline.plot(fig, include_plotlyjs=False,
auto_open=False))
self.assertTrue(PLOTLYJS not in html)
self.assertNotIn(PLOTLYJS, html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Kully
Copy link
Contributor

Kully commented Apr 19, 2017

@kernc I've reviewed and just have a couple suggestions for improving clarity of code. It's a 💃 from me after that.

kernc added 3 commits April 20, 2017 00:13
The checked strings were never in that file URL. The file needs to
be read.
The benefit is in the more informative context when the tests fail.
@Kully
Copy link
Contributor

Kully commented Apr 20, 2017

💃 from me. (Reminder for myself to update CHANGELOG 🐱 )

@Kully Kully merged commit 3ffe0bb into plotly:master Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants