Skip to content

[wip] - ipyplotly fixes #956

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add support for online/offline plot/iplot methods
It's now possible to execute a fair amount of legacy graph construction and plotting code
  • Loading branch information
Jon M. Mease committed Feb 17, 2018
commit 27f6413eb6b689979d3fbb508eebcd1b40a840a5
6 changes: 6 additions & 0 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,9 @@ def to_dict(self):

return res

def to_plotly_json(self):
return self.to_dict()

def save_html(self, filename, auto_open=False, responsive=False):
data = self.to_dict()
if responsive:
Expand Down Expand Up @@ -1283,6 +1286,9 @@ def _props(self):
# Get data from parent's dict
return self.parent._get_child_props(self)

def to_plotly_json(self):
return deepcopy(self._props)

def _init_props(self):
# Ensure that _data is initialized.
if self._props is not None:
Expand Down
12 changes: 2 additions & 10 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,8 @@ def init_notebook_mode(connected=False):

def _plot_html(figure_or_data, config, validate, default_width,
default_height, global_requirejs):
# force no validation if frames is in the call
# TODO - add validation for frames in call - #605
if 'frames' in figure_or_data:
figure = tools.return_figure_from_figure_or_data(
figure_or_data, False
)
else:
figure = tools.return_figure_from_figure_or_data(
figure_or_data, validate
)

figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)

width = figure.get('layout', {}).get('width', default_width)
height = figure.get('layout', {}).get('height', default_height)
Expand Down
9 changes: 1 addition & 8 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,7 @@ def get(figure_or_data, format='png', width=None, height=None, scale=None):

"""
# TODO: format is a built-in name... we shouldn't really use it
if isinstance(figure_or_data, dict):
figure = figure_or_data
elif isinstance(figure_or_data, list):
figure = {'data': figure_or_data}
else:
raise exceptions.PlotlyEmptyDataError(
"`figure_or_data` must be a dict or a list."
)
figure = tools.return_figure_from_figure_or_data(figure_or_data, True)

if format not in ['png', 'svg', 'jpeg', 'pdf']:
raise exceptions.PlotlyError(
Expand Down
14 changes: 10 additions & 4 deletions plotly/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,18 +1440,24 @@ def _repr_html_(self):

def return_figure_from_figure_or_data(figure_or_data, validate_figure):
from plotly.graph_objs import graph_objs

validated = False
if isinstance(figure_or_data, dict):
figure = figure_or_data
elif isinstance(figure_or_data, list):
figure = {'data': figure_or_data}
elif isinstance(figure_or_data, graph_objs.Figure):
figure = figure_or_data.to_dict()
validated = True
else:
raise exceptions.PlotlyError("The `figure_or_data` positional "
"argument must be either "
"`dict`-like or `list`-like.")
if validate_figure:
"argument must be "
"`dict`-like, `list`-like, or an instance of plotly.graph_objs.Figure")

if validate_figure and not validated:

try:
graph_objs.Figure(figure)
graph_objs.Figure(**figure)
except exceptions.PlotlyError as err:
raise exceptions.PlotlyError("Invalid 'figure_or_data' argument. "
"Plotly will not be able to properly "
Expand Down