Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add back ordering #341

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 2 commits into from
Oct 28, 2015
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
31 changes: 18 additions & 13 deletions plotly/graph_objs/graph_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
from __future__ import absolute_import

import copy

import re
import six
import warnings
from collections import OrderedDict

import six

from plotly import exceptions, graph_reference
from plotly.graph_objs import graph_objs_tools
Expand Down Expand Up @@ -113,17 +114,6 @@ def validate(self):
"""Everything is *always* validated now. keep for backwards compat."""
pass

def get_ordered(self, **kwargs):
"""
We have no way to order things anymore. Keep for backwards compat.

See https://github.com/plotly/python-api/issues/290.

:return: (PlotlyBase)

"""
return self


class PlotlyList(list, PlotlyBase):
"""
Expand Down Expand Up @@ -311,6 +301,10 @@ def get_data(self, flatten=False):
else:
return l

def get_ordered(self, **kwargs):
"""All children are already validated. Just use get_ordered on them."""
return [child.get_ordered for child in self]

def to_string(self, level=0, indent=4, eol='\n',
pretty=True, max_chars=80):
"""Get formatted string by calling `to_string` on children items."""
Expand Down Expand Up @@ -668,6 +662,17 @@ def get_data(self, flatten=False):
del d[key]
return d

def get_ordered(self, **kwargs):
"""Return a predictable, OrderedDict version of self."""
keys = sorted(self.keys(), key=graph_objs_tools.sort_keys)
ordered = OrderedDict()
for key in keys:
if isinstance(self[key], PlotlyBase):
ordered[key] = self[key].get_ordered()
else:
ordered[key] = self[key]
return ordered

def to_string(self, level=0, indent=4, eol='\n',
pretty=True, max_chars=80):
"""
Expand Down
2 changes: 1 addition & 1 deletion plotly/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.8.9'
__version__ = '1.8.10'