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

Skip to content

Commit 987749a

Browse files
committed
Merge pull request plotly#341 from plotly/add-back-ordering
Add back ordering
2 parents dc27258 + 0d4ce5a commit 987749a

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
from __future__ import absolute_import
2626

2727
import copy
28-
2928
import re
30-
import six
3129
import warnings
30+
from collections import OrderedDict
31+
32+
import six
3233

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

116-
def get_ordered(self, **kwargs):
117-
"""
118-
We have no way to order things anymore. Keep for backwards compat.
119-
120-
See https://github.com/plotly/python-api/issues/290.
121-
122-
:return: (PlotlyBase)
123-
124-
"""
125-
return self
126-
127117

128118
class PlotlyList(list, PlotlyBase):
129119
"""
@@ -311,6 +301,10 @@ def get_data(self, flatten=False):
311301
else:
312302
return l
313303

304+
def get_ordered(self, **kwargs):
305+
"""All children are already validated. Just use get_ordered on them."""
306+
return [child.get_ordered for child in self]
307+
314308
def to_string(self, level=0, indent=4, eol='\n',
315309
pretty=True, max_chars=80):
316310
"""Get formatted string by calling `to_string` on children items."""
@@ -668,6 +662,17 @@ def get_data(self, flatten=False):
668662
del d[key]
669663
return d
670664

665+
def get_ordered(self, **kwargs):
666+
"""Return a predictable, OrderedDict version of self."""
667+
keys = sorted(self.keys(), key=graph_objs_tools.sort_keys)
668+
ordered = OrderedDict()
669+
for key in keys:
670+
if isinstance(self[key], PlotlyBase):
671+
ordered[key] = self[key].get_ordered()
672+
else:
673+
ordered[key] = self[key]
674+
return ordered
675+
671676
def to_string(self, level=0, indent=4, eol='\n',
672677
pretty=True, max_chars=80):
673678
"""

plotly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.8.9'
1+
__version__ = '1.8.10'

0 commit comments

Comments
 (0)