Skip to content

Commit c86fd28

Browse files
committed
removed extra definitions.
1 parent 90f12c4 commit c86fd28

File tree

3 files changed

+98
-363
lines changed

3 files changed

+98
-363
lines changed

plotly/graph_objs/__init__.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,9 @@
99
"""
1010
from __future__ import absolute_import
1111

12-
from plotly.graph_objs.graph_objs import *
12+
from plotly.graph_objs.graph_objs import * # import everything...
1313

14-
__all__ = ["Data",
15-
"Annotations",
16-
"Area",
17-
"Bar",
18-
"Box",
19-
"Contour",
20-
"Heatmap",
21-
"Histogram",
22-
"Histogram2d",
23-
"Histogram2dContour",
24-
"Scatter",
25-
"Annotation",
26-
"AngularAxis",
27-
"ColorBar",
28-
"Contours",
29-
"ErrorX",
30-
"ErrorY",
31-
"Figure",
32-
"Font",
33-
"Layout",
34-
"Legend",
35-
"Line",
36-
"Margin",
37-
"Marker",
38-
"RadialAxis",
39-
"Stream",
40-
"Trace",
41-
"XAxis",
42-
"XBins",
43-
"YAxis",
44-
"YBins"]
14+
from plotly.graph_objs.graph_objs_tools import OBJ_MAP
15+
16+
__all__ = [name for name in OBJ_MAP # ... but, only expose certain objects
17+
if name not in ['PlotlyList', 'PlotlyDict', 'PlotlyTrace']]

plotly/graph_objs/graph_objs.py

Lines changed: 8 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -26,141 +26,15 @@
2626

2727
import warnings
2828
import six
29-
import sys
3029
from plotly.graph_objs import graph_objs_tools
30+
from plotly.graph_objs.graph_objs_tools import INFO, KEY_TO_NAME, NAME_TO_KEY
3131
import copy
3232
from plotly import exceptions
33-
from plotly import utils
34-
33+
import sys
3534
if sys.version[:3] == '2.6':
3635
from ordereddict import OrderedDict
37-
import simplejson as json
3836
else:
3937
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-
)
16438

16539

16640
class PlotlyList(list):
@@ -219,7 +93,7 @@ def to_graph_objs(self, caller=True):
21993
if isinstance(entry, PlotlyDict):
22094
try:
22195
entry.to_graph_objs(caller=False)
222-
except (exceptions.PlotlyGraphObjectError) as err:
96+
except exceptions.PlotlyGraphObjectError as err:
22397
err.add_to_error_path(index)
22498
err.prepare()
22599
raise # re-raise current exception
@@ -228,7 +102,6 @@ def to_graph_objs(self, caller=True):
228102
index=index,
229103
entry=entry)
230104

231-
232105
def update(self, changes, make_copies=False):
233106
"""Update current list with changed_list, which must be iterable.
234107
The 'changes' should be a list of dictionaries, however,
@@ -255,7 +128,6 @@ def update(self, changes, make_copies=False):
255128
else:
256129
self[index].update(update)
257130

258-
259131
def strip_style(self):
260132
"""Strip style from the current representation.
261133
@@ -374,7 +246,6 @@ def get_ordered(self, caller=True):
374246
ordered_list += [entry.get_ordered()]
375247
return ordered_list
376248

377-
378249
def force_clean(self, caller=True):
379250
"""Attempts to convert to graph_objs and calls force_clean() on entries.
380251
@@ -398,6 +269,7 @@ def force_clean(self, caller=True):
398269
del self[index - del_ct]
399270
del_ct += 1
400271

272+
401273
class PlotlyDict(dict):
402274
"""A base dict class for all objects that style a figure in plotly.
403275
@@ -743,7 +615,6 @@ def get_ordered(self, caller=True):
743615
ordered_dict[key] = self[key]
744616
return ordered_dict
745617

746-
747618
def force_clean(self, caller=True):
748619
"""Attempts to convert to graph_objs and call force_clean() on values.
749620
@@ -1131,12 +1002,12 @@ def _factory(name, *args, **kwargs):
11311002
# bases are the base classes that the new class inherits from
11321003
# dict holds attributes for the new class, e.g., __doc__
11331004
# 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:
11351006
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':
11381009
doc = graph_objs_tools.make_list_doc(obj)
11391010
else:
11401011
doc = graph_objs_tools.make_dict_doc(obj)
1141-
base = globals()[basename]
1012+
base = globals()[base_name]
11421013
globals()[obj] = type(obj, (base,), {'__doc__': doc, '__name__': obj})

0 commit comments

Comments
 (0)