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 b091aaf

Browse filesBrowse files
committed
dashboards now autosize based on GUI
1 parent 8def60c commit b091aaf
Copy full SHA for b091aaf

File tree

Expand file treeCollapse file tree

2 files changed

+21
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-3
lines changed

‎plotly/dashboard_objs/dashboard_objs.py

Copy file name to clipboardExpand all lines: plotly/dashboard_objs/dashboard_objs.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,21 @@ def _path_to_box(self, path):
265265
loc_in_dashboard = loc_in_dashboard[first_second]
266266
return loc_in_dashboard
267267

268+
def _set_dashboard_size(self):
269+
# set dashboard size to keep consistent with GUI
270+
num_of_boxes = len(self._compute_box_ids())
271+
if num_of_boxes == 0:
272+
pass
273+
elif num_of_boxes == 1:
274+
self['layout']['size'] = 800
275+
self['layout']['sizeUnit'] = 'px'
276+
elif num_of_boxes == 2:
277+
self['layout']['size'] = 1500
278+
self['layout']['sizeUnit'] = 'px'
279+
else:
280+
self['layout']['size'] = 1500 + 350 * (num_of_boxes - 2)
281+
self['layout']['sizeUnit'] = 'px'
282+
268283
def get_box(self, box_id):
269284
"""Returns box from box_id number."""
270285
box_ids_to_path = self._compute_box_ids()
@@ -496,6 +511,8 @@ def insert(self, box, side='above', box_id=None, fill_percent=50):
496511
"'above', 'below', 'left', and 'right'."
497512
)
498513

514+
self._set_dashboard_size()
515+
499516
def remove(self, box_id):
500517
"""
501518
Remove a box from the dashboard by its box_id.
@@ -535,6 +552,8 @@ def remove(self, box_id):
535552
else:
536553
self['layout'] = None
537554

555+
self._set_dashboard_size()
556+
538557
def swap(self, box_id_1, box_id_2):
539558
"""
540559
Swap two boxes with their specified ids.

‎plotly/tests/test_core/test_dashboard/test_dashboard.py

Copy file name to clipboardExpand all lines: plotly/tests/test_core/test_dashboard/test_dashboard.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_dashboard_dict(self):
111111
}
112112

113113
dash = dashboard.Dashboard()
114-
dash.insert(my_box, '', 0)
114+
dash.insert(my_box)
115115
dash.insert(my_box, 'above', 1)
116116

117117
expected_dashboard = {
@@ -131,12 +131,11 @@ def test_dashboard_dict(self):
131131
'sizeUnit': '%',
132132
'type': 'split'},
133133
'second': {'boxType': 'empty', 'type': 'box'},
134-
'size': 500,
134+
'size': 1500,
135135
'sizeUnit': 'px',
136136
'type': 'split'},
137137
'settings': {},
138138
'version': 2
139139
}
140140

141-
142141
self.assertEqual(dash['layout'], expected_dashboard['layout'])

0 commit comments

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