@@ -144,7 +144,8 @@ def __new__(mcs, name, bases, attrs):
144144 doc += "Quick method reference:\n \n "
145145 doc += "\t {}." .format (name ) + "\n \t {}." .format (name ).join (
146146 ["update(changes)" , "strip_style()" , "get_data()" ,
147- "to_graph_objs()" , "validate()" , "force_clean()" ]) + "\n \n "
147+ "to_graph_objs()" , "validate()" , "to_string()" ,
148+ "force_clean()" ]) + "\n \n "
148149 attrs ['__doc__' ] = doc .expandtabs (tab_size )
149150 return super (ListMeta , mcs ).__new__ (mcs , name , bases , attrs )
150151
@@ -172,8 +173,9 @@ def __new__(mcs, name, bases, attrs):
172173 # Add section header for method list...
173174 doc += "Quick method reference:\n \n "
174175 doc += "\t {}." .format (name ) + "\n \t {}." .format (name ).join (
175- ["update(dict1, **dict2)" , "strip_style()" , "get_data()" ,
176- "to_graph_objs()" , "validate()" , "force_clean()" ]) + "\n \n "
176+ ["update(changes)" , "strip_style()" , "get_data()" ,
177+ "to_graph_objs()" , "validate()" , "to_string()" ,
178+ "force_clean()" ]) + "\n \n "
177179 # Add section header
178180 if len (obj_info ):
179181 doc += "Valid keys:\n \n "
@@ -363,7 +365,7 @@ def validate(self):
363365 "Plotly list-type objects can only contain plotly "
364366 "dict-like objects." )
365367
366- def to_string (self , level = 0 , indent = 4 , eol = '\n ' ):
368+ def to_string (self , level = 0 , indent = 4 , eol = '\n ' , pretty = True ):
367369 """Returns a formatted string showing graph_obj declarations.
368370
369371 Example:
@@ -377,7 +379,10 @@ def to_string(self, level=0, indent=4, eol='\n'):
377379 eol = eol ,
378380 indent = ' ' * indent * (level + 1 ))
379381 for index , entry in enumerate (self ):
380- string += entry .to_string (level = level + 1 , indent = indent , eol = eol )
382+ string += entry .to_string (level = level + 1 ,
383+ indent = indent ,
384+ eol = eol ,
385+ pretty = pretty )
381386 if index < len (self ) - 1 :
382387 string += ",{eol}{indent}" .format (
383388 eol = eol ,
@@ -612,7 +617,7 @@ def validate(self): # TODO: validate values too?
612617 msg += "Couldn't find uses for key: {}\n \n " .format (key )
613618 raise exceptions .PlotlyInvalidKeyError (msg )
614619
615- def to_string (self , level = 0 , indent = 4 , eol = '\n ' ):
620+ def to_string (self , level = 0 , indent = 4 , eol = '\n ' , pretty = True ):
616621 """Returns a formatted string showing graph_obj declarations.
617622
618623 Example:
@@ -633,9 +638,17 @@ def to_string(self, level=0, indent=4, eol='\n'):
633638 try :
634639 string += self [key ].to_string (level = level + 1 ,
635640 indent = indent ,
636- eol = eol )
641+ eol = eol ,
642+ pretty = pretty )
637643 except AttributeError :
638- string += str (repr (self [key ]))
644+ val = self [key ]
645+ try :
646+ if pretty and (len (self [key ]) > 6 ):
647+ if not isinstance (self [key ], str ):
648+ val = self [key ][:4 ] + ['...' ] + [self [key ][- 1 ]]
649+ except TypeError :
650+ pass
651+ string += str (repr (val ))
639652 if index < len (self ) - 1 :
640653 string += ","
641654 index += 1
@@ -809,7 +822,7 @@ def __init__(self, *args, **kwargs):
809822 "dictionary-like plot types.\n It is not meant to be "
810823 "a user interface." )
811824
812- def to_string (self , level = 0 , indent = 4 , eol = '\n ' ):
825+ def to_string (self , level = 0 , indent = 4 , eol = '\n ' , pretty = True ):
813826 """Returns a formatted string showing graph_obj declarations.
814827
815828 Example:
@@ -822,12 +835,14 @@ def to_string(self, level=0, indent=4, eol='\n'):
822835 trace_type = self .pop ('type' )
823836 string = super (PlotlyTrace , self ).to_string (level = level ,
824837 indent = indent ,
825- eol = eol )
838+ eol = eol ,
839+ pretty = pretty )
826840 self ['type' ] = trace_type
827841 else :
828842 string = super (PlotlyTrace , self ).to_string (level = level ,
829843 indent = indent ,
830- eol = eol )
844+ eol = eol ,
845+ pretty = pretty )
831846 return string
832847
833848
@@ -1083,14 +1098,15 @@ def to_graph_objs(self):
10831098 pass
10841099 super (Layout , self ).to_graph_objs ()
10851100
1086- def to_string (self , level = 0 , indent = 4 , eol = '\n ' ): # TODO: can't call super
1101+ def to_string (self , level = 0 , indent = 4 , eol = '\n ' , pretty = True ):
10871102 """Returns a formatted string showing graph_obj declarations.
10881103
10891104 Example:
10901105
10911106 print obj.to_string()
10921107
10931108 """
1109+ # TODO: can't call super
10941110 self .to_graph_objs ()
10951111 string = "{name}(" .format (name = self .__class__ .__name__ )
10961112 index = 0
@@ -1104,9 +1120,17 @@ def to_string(self, level=0, indent=4, eol='\n'): # TODO: can't call super
11041120 try :
11051121 string += self [key ].to_string (level = level + 1 ,
11061122 indent = indent ,
1107- eol = eol )
1123+ eol = eol ,
1124+ pretty = pretty )
11081125 except AttributeError :
1109- string += str (repr (self [key ]))
1126+ val = self [key ]
1127+ try :
1128+ if pretty and (len (self [key ]) > 6 ):
1129+ if not isinstance (self [key ], str ):
1130+ val = self [key ][:4 ] + ['...' ] + [self [key ][- 1 ]]
1131+ except TypeError :
1132+ pass
1133+ string += str (repr (val ))
11101134 if index < len (self ) - 1 :
11111135 string += ","
11121136 index += 1
@@ -1122,7 +1146,8 @@ def to_string(self, level=0, indent=4, eol='\n'): # TODO: can't call super
11221146 try :
11231147 string += self [key ].to_string (level = level + 1 ,
11241148 indent = indent ,
1125- eol = eol )
1149+ eol = eol ,
1150+ pretty = pretty )
11261151 except AttributeError :
11271152 string += str (repr (self [key ]))
11281153 if index < len (self ) - 1 :
0 commit comments