@@ -787,7 +787,7 @@ def create(object_name, *args, **kwargs):
787
787
788
788
# We patch Figure and Data, so they actually require the subclass.
789
789
class_name = graph_reference .OBJECT_NAME_TO_CLASS_NAME .get (object_name )
790
- if class_name in ['Figure' , 'Data' ]:
790
+ if class_name in ['Figure' , 'Data' , 'Frames' ]:
791
791
return globals ()[class_name ](* args , ** kwargs )
792
792
else :
793
793
kwargs ['_name' ] = object_name
@@ -1097,7 +1097,7 @@ class Figure(PlotlyDict):
1097
1097
"""
1098
1098
Valid attributes for 'figure' at path [] under parents ():
1099
1099
1100
- ['data', 'layout']
1100
+ ['data', 'frames', ' layout']
1101
1101
1102
1102
Run `<figure-object>.help('attribute')` on any of the above.
1103
1103
'<figure-object>' is the object at []
@@ -1108,22 +1108,7 @@ class Figure(PlotlyDict):
1108
1108
def __init__ (self , * args , ** kwargs ):
1109
1109
super (Figure , self ).__init__ (* args , ** kwargs )
1110
1110
if 'data' not in self :
1111
- self .data = GraphObjectFactory .create ('data' , _parent = self ,
1112
- _parent_key = 'data' )
1113
-
1114
- # TODO better integrate frames into Figure - #604
1115
- def __setitem__ (self , key , value , ** kwargs ):
1116
- if key == 'frames' :
1117
- super (PlotlyDict , self ).__setitem__ (key , value )
1118
- else :
1119
- super (Figure , self ).__setitem__ (key , value , ** kwargs )
1120
-
1121
- def _get_valid_attributes (self ):
1122
- super (Figure , self )._get_valid_attributes ()
1123
- # TODO better integrate frames into Figure - #604
1124
- if 'frames' not in self ._valid_attributes :
1125
- self ._valid_attributes .add ('frames' )
1126
- return self ._valid_attributes
1111
+ self .data = Data (_parent = self , _parent_key = 'data' )
1127
1112
1128
1113
def get_data (self , flatten = False ):
1129
1114
"""
@@ -1241,8 +1226,45 @@ class Font(PlotlyDict):
1241
1226
_name = 'font'
1242
1227
1243
1228
1244
- class Frames (dict ):
1245
- pass
1229
+ class Frames (PlotlyList ):
1230
+ """
1231
+ Valid items for 'frames' at path [] under parents ():
1232
+ ['dict']
1233
+
1234
+ """
1235
+ _name = 'frames'
1236
+
1237
+ def _value_to_graph_object (self , index , value , _raise = True ):
1238
+ if isinstance (value , six .string_types ):
1239
+ return value
1240
+ return super (Frames , self )._value_to_graph_object (index , value ,
1241
+ _raise = _raise )
1242
+
1243
+ def to_string (self , level = 0 , indent = 4 , eol = '\n ' ,
1244
+ pretty = True , max_chars = 80 ):
1245
+ """Get formatted string by calling `to_string` on children items."""
1246
+ if not len (self ):
1247
+ return "{name}()" .format (name = self ._get_class_name ())
1248
+ string = "{name}([{eol}{indent}" .format (
1249
+ name = self ._get_class_name (),
1250
+ eol = eol ,
1251
+ indent = ' ' * indent * (level + 1 ))
1252
+ for index , entry in enumerate (self ):
1253
+ if isinstance (entry , six .string_types ):
1254
+ string += repr (entry )
1255
+ else :
1256
+ string += entry .to_string (level = level + 1 ,
1257
+ indent = indent ,
1258
+ eol = eol ,
1259
+ pretty = pretty ,
1260
+ max_chars = max_chars )
1261
+ if index < len (self ) - 1 :
1262
+ string += ",{eol}{indent}" .format (
1263
+ eol = eol ,
1264
+ indent = ' ' * indent * (level + 1 ))
1265
+ string += (
1266
+ "{eol}{indent}])" ).format (eol = eol , indent = ' ' * indent * level )
1267
+ return string
1246
1268
1247
1269
1248
1270
class Heatmap (PlotlyDict ):
0 commit comments