Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c2ab58

Browse filesBrowse files
committed
all doc strings + rest of andrew's comments
1 parent 293f2bd commit 9c2ab58
Copy full SHA for 9c2ab58

File tree

2 files changed

+62
-53
lines changed
Filter options

2 files changed

+62
-53
lines changed

‎plotly/dashboard_objs/dashboard_objs.py

Copy file name to clipboardExpand all lines: plotly/dashboard_objs/dashboard_objs.py
+39-41Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(self, content=None):
139139
content = {}
140140

141141
if not content:
142-
self['layout'] = _empty_box()
142+
self['layout'] = None
143143
self['version'] = 2
144144
self['settings'] = {}
145145
else:
@@ -160,7 +160,7 @@ def _compute_box_ids(self):
160160
max_id = max(box_ids_to_path.keys())
161161
except ValueError:
162162
max_id = 0
163-
box_ids_to_path[max_id + 1] = list(node[1])
163+
box_ids_to_path[max_id + 1] = node[1] # list(...)
164164

165165
return box_ids_to_path
166166

@@ -183,14 +183,23 @@ def _insert(self, box_or_container, path):
183183
else:
184184
self['layout'] = box_or_container
185185

186-
def _set_container_sizes(self):
186+
def _make_all_nodes_and_paths(self):
187187
all_nodes = list(node_generator(self['layout']))
188188

189+
# remove path 'second' as it's always an empty box
189190
all_paths = []
190191
for node in all_nodes:
191-
all_paths.append(list(node[1]))
192-
if ['second'] in all_paths:
193-
all_paths.remove(['second'])
192+
all_paths.append(node[1])
193+
path_second = ('second',)
194+
if path_second in all_paths:
195+
all_paths.remove(path_second)
196+
return all_nodes, all_paths
197+
198+
def _set_container_sizes(self):
199+
if self['layout'] is None:
200+
return
201+
202+
all_nodes, all_paths = self._make_all_nodes_and_paths()
194203

195204
# set dashboard_height proportional to max_path_len
196205
max_path_len = max(len(path) for path in all_paths)
@@ -229,13 +238,20 @@ def get_preview(self):
229238
dict. Otherwise, returns an IPython.core.display.HTML display of the
230239
dashboard.
231240
232-
The algorithm - iteratively go through all paths of the dashboards
233-
moving from shorter to longer paths. Checking the box or container
234-
that sits at the end each path, if you find a container, draw a line
235-
to divide the current box into two, and record the top-left
236-
coordinates and box width and height resulting from the two boxes
237-
along with the corresponding path. When the path points to a box,
238-
draw the number associated with that box in the center of the box.
241+
The algorithm used to build the HTML preview involves going through
242+
the paths of the node generator of the dashboard. The paths of the
243+
dashboard are sequenced through from shorter to longer and whether
244+
it's a box or container that lies at the end of the path determines
245+
the action.
246+
247+
If it's a container, draw a line in the figure to divide the current
248+
box into two and store the specs of the resulting two boxes. If the
249+
path points to a terminal box (often containing a plot), then draw
250+
the box id in the center of the box.
251+
252+
It's important to note that these box ids are generated on-the-fly and
253+
they do not necessarily stay assigned to the boxes they were once
254+
assigned to.
239255
"""
240256
if IPython is None:
241257
pprint.pprint(self)
@@ -259,18 +275,12 @@ def get_preview(self):
259275
path_to_box_specs[('first',)] = first_box_specs
260276

261277
# generate all paths
262-
all_nodes = list(node_generator(self['layout']))
263-
264-
all_paths = []
265-
for node in all_nodes:
266-
all_paths.append(list(node[1]))
267-
if ['second'] in all_paths:
268-
all_paths.remove(['second'])
278+
all_nodes, all_paths = self._make_all_nodes_and_paths()
269279

270280
max_path_len = max(len(path) for path in all_paths)
271281
for path_len in range(1, max_path_len + 1):
272282
for path in [path for path in all_paths if len(path) == path_len]:
273-
current_box_specs = path_to_box_specs[tuple(path)]
283+
current_box_specs = path_to_box_specs[path]
274284

275285
if self._path_to_box(path)['type'] == 'split':
276286
html_figure = _draw_line_through_box(
@@ -316,8 +326,8 @@ def get_preview(self):
316326
'box_h': new_box_h
317327
}
318328

319-
path_to_box_specs[tuple(path) + ('first',)] = box_1_specs
320-
path_to_box_specs[tuple(path) + ('second',)] = box_2_specs
329+
path_to_box_specs[path + ('first',)] = box_1_specs
330+
path_to_box_specs[path + ('second',)] = box_2_specs
321331

322332
elif self._path_to_box(path)['type'] == 'box':
323333
for box_id in box_ids_to_path:
@@ -326,10 +336,10 @@ def get_preview(self):
326336

327337
html_figure = _add_html_text(
328338
html_figure, number,
329-
path_to_box_specs[tuple(path)]['top_left_x'],
330-
path_to_box_specs[tuple(path)]['top_left_y'],
331-
path_to_box_specs[tuple(path)]['box_w'],
332-
path_to_box_specs[tuple(path)]['box_h'],
339+
path_to_box_specs[path]['top_left_x'],
340+
path_to_box_specs[path]['top_left_y'],
341+
path_to_box_specs[path]['box_w'],
342+
path_to_box_specs[path]['box_h'],
333343
)
334344

335345
# display HTML representation
@@ -347,22 +357,10 @@ def insert(self, box, side='above', box_id=None):
347357
the insertion of the box.
348358
"""
349359
box_ids_to_path = self._compute_box_ids()
350-
init_box = {
351-
'type': 'box',
352-
'boxType': 'plot',
353-
'fileId': '',
354-
'shareKey': None,
355-
'title': ''
356-
}
357-
358-
# force box to have all valid box keys
359-
for key in init_box.keys():
360-
if key not in box.keys():
361-
box[key] = init_box[key]
362360

363361
# doesn't need box_id or side specified for first box
364-
if 'first' not in self['layout']:
365-
self._insert(_container(box, _empty_box()), [])
362+
if self['layout'] is None:
363+
self['layout'] = _container(box, _empty_box())
366364
else:
367365
if box_id is None:
368366
raise exceptions.PlotlyError(

‎plotly/plotly/plotly.py

Copy file name to clipboardExpand all lines: plotly/plotly/plotly.py
+23-12Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,12 +1354,21 @@ class dashboard_ops:
13541354
@classmethod
13551355
def upload(cls, dashboard, filename, sharing='public', auto_open=True):
13561356
"""
1357-
BETA function for uploading dashboards to Plotly.
1358-
1359-
:param (dict) dashboard:
1360-
:param (str) filename:
1361-
:param (str) sharing:
1362-
:param (bool) auto_open:
1357+
BETA function for uploading/overwriting dashboards to Plotly.
1358+
1359+
:param (dict) dashboard: the JSON dashboard to be uploaded. Use
1360+
plotly.dashboard_objs.dashboard_objs to create a Dashboard
1361+
object.
1362+
:param (str) filename: the name of the dashboard to be saved in
1363+
your Plotly account. Will overwrite a dashboard of the same
1364+
name if it already exists in your files.
1365+
:param (str) sharing: can be set to either 'public', 'private'
1366+
or 'secret'. If 'public', your dashboard will be viewable by
1367+
all other users. If 'secret', only you can see your dashboard.
1368+
If 'secret', the url will be returned with a sharekey appended
1369+
to the url. Anyone with the url may view the dashboard.
1370+
:param (bool) auto_open: automatically opens the dashboard in the
1371+
browser.
13631372
"""
13641373
if sharing == 'public':
13651374
world_readable = True
@@ -1374,16 +1383,18 @@ def upload(cls, dashboard, filename, sharing='public', auto_open=True):
13741383
'world_readable': world_readable
13751384
}
13761385

1377-
# check if pre-existing filename already exists
1378-
filenames = cls.get_dashboard_names()
1379-
if filename in filenames:
1386+
# lookup if pre-existing filename already exists
1387+
try:
1388+
v2.files.lookup(filename)
13801389
matching_dashboard = cls._get_dashboard_json(
13811390
filename, False
13821391
)
1383-
fid = matching_dashboard['fid']
1384-
res = v2.dashboards.update(fid, data)
13851392

1386-
else:
1393+
if matching_dashboard['filetype'] == 'dashboard':
1394+
old_fid = matching_dashboard['fid']
1395+
res = v2.dashboards.update(old_fid, data)
1396+
1397+
except exceptions.PlotlyRequestError:
13871398
res = v2.dashboards.create(data)
13881399
res.raise_for_status()
13891400

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.