|
25 | 25 | from __future__ import absolute_import
|
26 | 26 |
|
27 | 27 | import copy
|
28 |
| - |
29 | 28 | import re
|
30 |
| -import six |
31 | 29 | import warnings
|
| 30 | +from collections import OrderedDict |
| 31 | + |
| 32 | +import six |
32 | 33 |
|
33 | 34 | from plotly import exceptions, graph_reference
|
34 | 35 | from plotly.graph_objs import graph_objs_tools
|
@@ -113,17 +114,6 @@ def validate(self):
|
113 | 114 | """Everything is *always* validated now. keep for backwards compat."""
|
114 | 115 | pass
|
115 | 116 |
|
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 |
| - |
127 | 117 |
|
128 | 118 | class PlotlyList(list, PlotlyBase):
|
129 | 119 | """
|
@@ -311,6 +301,10 @@ def get_data(self, flatten=False):
|
311 | 301 | else:
|
312 | 302 | return l
|
313 | 303 |
|
| 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 | + |
314 | 308 | def to_string(self, level=0, indent=4, eol='\n',
|
315 | 309 | pretty=True, max_chars=80):
|
316 | 310 | """Get formatted string by calling `to_string` on children items."""
|
@@ -668,6 +662,17 @@ def get_data(self, flatten=False):
|
668 | 662 | del d[key]
|
669 | 663 | return d
|
670 | 664 |
|
| 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 | + |
671 | 676 | def to_string(self, level=0, indent=4, eol='\n',
|
672 | 677 | pretty=True, max_chars=80):
|
673 | 678 | """
|
|
0 commit comments