Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dad0121

Browse filesBrowse files
committed
Add a simple ordering at get_ordered.
1 parent dc27258 commit dad0121
Copy full SHA for dad0121

File tree

1 file changed

+18
-13
lines changed
Filter options

1 file changed

+18
-13
lines changed

‎plotly/graph_objs/graph_objs.py

Copy file name to clipboardExpand all lines: plotly/graph_objs/graph_objs.py
+18-13Lines 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
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.