26
26
27
27
import warnings
28
28
import six
29
- import sys
30
29
from plotly .graph_objs import graph_objs_tools
30
+ from plotly .graph_objs .graph_objs_tools import INFO , KEY_TO_NAME , NAME_TO_KEY
31
31
import copy
32
32
from plotly import exceptions
33
- from plotly import utils
34
-
33
+ import sys
35
34
if sys .version [:3 ] == '2.6' :
36
35
from ordereddict import OrderedDict
37
- import simplejson as json
38
36
else :
39
37
from collections import OrderedDict
40
- import json
41
-
42
- __all__ = ["Data" ,
43
- "Annotations" ,
44
- "Area" ,
45
- "Bar" ,
46
- "Box" ,
47
- "Contour" ,
48
- "Heatmap" ,
49
- "Histogram" ,
50
- "Histogram2d" ,
51
- "Histogram2dContour" ,
52
- "Scatter" ,
53
- "Annotation" ,
54
- "AngularAxis" ,
55
- "ColorBar" ,
56
- "Contours" ,
57
- "ErrorX" ,
58
- "ErrorY" ,
59
- "Figure" ,
60
- "Font" ,
61
- "Layout" ,
62
- "Legend" ,
63
- "Line" ,
64
- "Margin" ,
65
- "Marker" ,
66
- "RadialAxis" ,
67
- "Stream" ,
68
- "Trace" ,
69
- "XAxis" ,
70
- "XBins" ,
71
- "YAxis" ,
72
- "YBins" ]
73
-
74
- # TODO: BIG ONE, how should exceptions bubble up in this inheritance scheme?
75
- # TODO: related, WHAT exceptions should bubble up?
76
-
77
- from pkg_resources import resource_string
78
- s = resource_string ('plotly' ,
79
- 'graph_reference/graph_objs_meta.json' ).decode ('utf-8' )
80
- INFO = json .loads (s , object_pairs_hook = OrderedDict )
81
-
82
- INFO = utils .decode_unicode (INFO )
83
-
84
- # define how to map from keys in INFO to a class
85
- # mapping: (n->m, m < n)
86
- KEY_TO_NAME = dict (
87
- plotlylist = 'PlotlyList' ,
88
- data = 'Data' ,
89
- angularaxis = 'AngularAxis' ,
90
- annotations = 'Annotations' ,
91
- area = 'Area' ,
92
- plotlydict = 'PlotlyDict' ,
93
- plotlytrace = 'PlotlyTrace' ,
94
- bar = 'Bar' ,
95
- box = 'Box' ,
96
- contour = 'Contour' ,
97
- heatmap = 'Heatmap' ,
98
- histogram = 'Histogram' ,
99
- histogram2d = 'Histogram2d' ,
100
- histogram2dcontour = 'Histogram2dContour' ,
101
- scatter = 'Scatter' ,
102
- annotation = 'Annotation' ,
103
- colorbar = 'ColorBar' ,
104
- contours = 'Contours' ,
105
- error_x = 'ErrorX' ,
106
- error_y = 'ErrorY' ,
107
- figure = 'Figure' ,
108
- font = 'Font' ,
109
- layout = 'Layout' ,
110
- legend = 'Legend' ,
111
- line = 'Line' ,
112
- margin = 'Margin' ,
113
- marker = 'Marker' ,
114
- radialaxis = 'RadialAxis' ,
115
- stream = 'Stream' ,
116
- trace = 'Trace' ,
117
- textfont = 'Font' ,
118
- tickfont = 'Font' ,
119
- titlefont = 'Font' ,
120
- xaxis = 'XAxis' ,
121
- xbins = 'XBins' ,
122
- yaxis = 'YAxis' ,
123
- ybins = 'YBins'
124
- )
125
-
126
- # define how to map from a class name to a key name in INFO
127
- # mapping: (n->n)
128
- NAME_TO_KEY = dict (
129
- PlotlyList = 'plotlylist' ,
130
- Data = 'data' ,
131
- AngularAxis = 'angularaxis' ,
132
- Annotations = 'annotations' ,
133
- PlotlyDict = 'plotlydict' ,
134
- PlotlyTrace = 'plotlytrace' ,
135
- Area = 'area' ,
136
- Bar = 'bar' ,
137
- Box = 'box' ,
138
- Contour = 'contour' ,
139
- Heatmap = 'heatmap' ,
140
- Histogram = 'histogram' ,
141
- Histogram2d = 'histogram2d' ,
142
- Histogram2dContour = 'histogram2dcontour' ,
143
- Scatter = 'scatter' ,
144
- Annotation = 'annotation' ,
145
- ColorBar = 'colorbar' ,
146
- Contours = 'contours' ,
147
- ErrorX = 'error_x' ,
148
- ErrorY = 'error_y' ,
149
- Figure = 'figure' ,
150
- Font = 'font' ,
151
- Layout = 'layout' ,
152
- Legend = 'legend' ,
153
- Line = 'line' ,
154
- Margin = 'margin' ,
155
- Marker = 'marker' ,
156
- RadialAxis = 'radialaxis' ,
157
- Stream = 'stream' ,
158
- Trace = 'trace' ,
159
- XAxis = 'xaxis' ,
160
- XBins = 'xbins' ,
161
- YAxis = 'yaxis' ,
162
- YBins = 'ybins'
163
- )
164
38
165
39
166
40
class PlotlyList (list ):
@@ -219,7 +93,7 @@ def to_graph_objs(self, caller=True):
219
93
if isinstance (entry , PlotlyDict ):
220
94
try :
221
95
entry .to_graph_objs (caller = False )
222
- except ( exceptions .PlotlyGraphObjectError ) as err :
96
+ except exceptions .PlotlyGraphObjectError as err :
223
97
err .add_to_error_path (index )
224
98
err .prepare ()
225
99
raise # re-raise current exception
@@ -228,7 +102,6 @@ def to_graph_objs(self, caller=True):
228
102
index = index ,
229
103
entry = entry )
230
104
231
-
232
105
def update (self , changes , make_copies = False ):
233
106
"""Update current list with changed_list, which must be iterable.
234
107
The 'changes' should be a list of dictionaries, however,
@@ -255,7 +128,6 @@ def update(self, changes, make_copies=False):
255
128
else :
256
129
self [index ].update (update )
257
130
258
-
259
131
def strip_style (self ):
260
132
"""Strip style from the current representation.
261
133
@@ -374,7 +246,6 @@ def get_ordered(self, caller=True):
374
246
ordered_list += [entry .get_ordered ()]
375
247
return ordered_list
376
248
377
-
378
249
def force_clean (self , caller = True ):
379
250
"""Attempts to convert to graph_objs and calls force_clean() on entries.
380
251
@@ -398,6 +269,7 @@ def force_clean(self, caller=True):
398
269
del self [index - del_ct ]
399
270
del_ct += 1
400
271
272
+
401
273
class PlotlyDict (dict ):
402
274
"""A base dict class for all objects that style a figure in plotly.
403
275
@@ -743,7 +615,6 @@ def get_ordered(self, caller=True):
743
615
ordered_dict [key ] = self [key ]
744
616
return ordered_dict
745
617
746
-
747
618
def force_clean (self , caller = True ):
748
619
"""Attempts to convert to graph_objs and call force_clean() on values.
749
620
@@ -1131,12 +1002,12 @@ def _factory(name, *args, **kwargs):
1131
1002
# bases are the base classes that the new class inherits from
1132
1003
# dict holds attributes for the new class, e.g., __doc__
1133
1004
# why? because __doc__ isn't writeable after-the-fact!
1134
- for obj in graph_objs_tools .NAME_TO_BASE :
1005
+ for obj in graph_objs_tools .OBJ_MAP :
1135
1006
if obj not in globals ():
1136
- basename = graph_objs_tools .NAME_TO_BASE [obj ]
1137
- if basename == 'PlotlyList' :
1007
+ base_name = graph_objs_tools .OBJ_MAP [obj ][ 'base_name' ]
1008
+ if base_name == 'PlotlyList' :
1138
1009
doc = graph_objs_tools .make_list_doc (obj )
1139
1010
else :
1140
1011
doc = graph_objs_tools .make_dict_doc (obj )
1141
- base = globals ()[basename ]
1012
+ base = globals ()[base_name ]
1142
1013
globals ()[obj ] = type (obj , (base ,), {'__doc__' : doc , '__name__' : obj })
0 commit comments