@@ -44,9 +44,11 @@ def _box(fileId='', shareKey=None, title=''):
4444 }
4545 return box
4646
47-
48- def _container (box_1 = None , box_2 = None , size = MASTER_HEIGHT ,
49- sizeUnit = 'px' , direction = 'vertical' ):
47+ # old values
48+ # size=MASTER_HEIGHT, sizeUnit='px',
49+ def _container (box_1 = None , box_2 = None ,
50+ size = 50 , sizeUnit = '%' ,
51+ direction = 'vertical' ):
5052 if box_1 is None :
5153 box_1 = _empty_box ()
5254 if box_2 is None :
@@ -60,6 +62,7 @@ def _container(box_1=None, box_2=None, size=MASTER_HEIGHT,
6062 'first' : box_1 ,
6163 'second' : box_2
6264 }
65+
6366 return container
6467
6568dashboard_html = ("""
@@ -260,6 +263,8 @@ def _make_all_nodes_and_paths(self):
260263 all_paths .remove (path_second )
261264 return all_nodes , all_paths
262265
266+ # TODO: get rid by the end of PR
267+ # change name to init_container_size ?
263268 def _set_container_sizes (self ):
264269 if self ['layout' ] is None :
265270 return
@@ -273,10 +278,9 @@ def _set_container_sizes(self):
273278 self ['layout' ]['sizeUnit' ] = 'px'
274279
275280 for path in all_paths :
276- if len (path ) != 0 :
277- if self ._path_to_box (path )['type' ] == 'split' :
278- self ._path_to_box (path )['size' ] = 50
279- self ._path_to_box (path )['sizeUnit' ] = '%'
281+ if len (path ) != 0 and self ._path_to_box (path )['type' ] == 'split' :
282+ self ._path_to_box (path )['size' ] = 50
283+ self ._path_to_box (path )['sizeUnit' ] = '%'
280284
281285 def _path_to_box (self , path ):
282286 loc_in_dashboard = self ['layout' ]
@@ -295,6 +299,12 @@ def get_box(self, box_id):
295299 loc_in_dashboard = loc_in_dashboard [first_second ]
296300 return loc_in_dashboard
297301
302+ def set_height (self , dashboard_height ):
303+ """Sets the height (in pixels) of dashboard"""
304+ # problem when no box is inserted
305+ self ['layout' ]['size' ] = dashboard_height
306+ self ['layout' ]['sizeUnit' ] = 'px'
307+
298308 def get_preview (self ):
299309 """
300310 Returns JSON or HTML respresentation of the dashboard.
@@ -413,7 +423,7 @@ def get_preview(self):
413423 # display HTML representation
414424 return IPython .display .HTML (html_figure )
415425
416- def insert (self , box , side = 'above' , box_id = None ):
426+ def insert (self , box , side = 'above' , box_id = None , fill_percent = 50 ):
417427 """
418428 Insert a box into your dashboard layout.
419429
@@ -423,7 +433,11 @@ def insert(self, box, side='above', box_id=None):
423433 'left', and 'right'.
424434 :param (int) box_id: the box id which is used as the reference box for
425435 the insertion of the box.
426-
436+ :param (float) fill_percent: specifies the percentage of the box area
437+ which the new box is occupying. The default is `fill_percent=50`
438+ which splits the region into two equally sized pieces with `box`
439+ and the box corresponding to `box_id` in this area of the layout.
440+
427441 Example:
428442 ```
429443 import plotly.dashboard_objs as dashboard
@@ -449,7 +463,9 @@ def insert(self, box, side='above', box_id=None):
449463
450464 # doesn't need box_id or side specified for first box
451465 if self ['layout' ] is None :
452- self ['layout' ] = _container (box , _empty_box ())
466+ self ['layout' ] = _container (
467+ box , _empty_box (), size = MASTER_HEIGHT , sizeUnit = 'px'
468+ )
453469 else :
454470 if box_id is None :
455471 raise exceptions .PlotlyError (
@@ -458,28 +474,38 @@ def insert(self, box, side='above', box_id=None):
458474 )
459475 if box_id not in box_ids_to_path :
460476 raise exceptions .PlotlyError (ID_NOT_VALID_MESSAGE )
477+
478+ if fill_percent < 0 or fill_percent > 100 :
479+ raise exceptions .PlotlyError (
480+ 'fill_percent must be a number between 0 and 100 '
481+ 'inclusive'
482+ )
461483 if side == 'above' :
462484 old_box = self .get_box (box_id )
463485 self ._insert (
464- _container (box , old_box , direction = 'vertical' ),
486+ _container (box , old_box , direction = 'vertical' ,
487+ size = fill_percent ),
465488 box_ids_to_path [box_id ]
466489 )
467490 elif side == 'below' :
468491 old_box = self .get_box (box_id )
469492 self ._insert (
470- _container (old_box , box , direction = 'vertical' ),
493+ _container (old_box , box , direction = 'vertical' ,
494+ size = 100 - fill_percent ),
471495 box_ids_to_path [box_id ]
472496 )
473497 elif side == 'left' :
474498 old_box = self .get_box (box_id )
475499 self ._insert (
476- _container (box , old_box , direction = 'horizontal' ),
500+ _container (box , old_box , direction = 'horizontal' ,
501+ size = fill_percent ),
477502 box_ids_to_path [box_id ]
478503 )
479504 elif side == 'right' :
480505 old_box = self .get_box (box_id )
481506 self ._insert (
482- _container (old_box , box , direction = 'horizontal' ),
507+ _container (old_box , box , direction = 'horizontal' ,
508+ size = 100 - fill_percent ),
483509 box_ids_to_path [box_id ]
484510 )
485511 else :
@@ -489,8 +515,6 @@ def insert(self, box, side='above', box_id=None):
489515 "'above', 'below', 'left', and 'right'."
490516 )
491517
492- self ._set_container_sizes ()
493-
494518 def remove (self , box_id ):
495519 """
496520 Remove a box from the dashboard by its box_id.
@@ -530,8 +554,6 @@ def remove(self, box_id):
530554 else :
531555 self ['layout' ] = None
532556
533- self ._set_container_sizes ()
534-
535557 def swap (self , box_id_1 , box_id_2 ):
536558 """
537559 Swap two boxes with their specified ids.
@@ -580,5 +602,3 @@ def swap(self, box_id_1, box_id_2):
580602 for first_second in pairs [0 ][:- 1 ]:
581603 loc_in_dashboard = loc_in_dashboard [first_second ]
582604 loc_in_dashboard [pairs [0 ][- 1 ]] = pairs [1 ]
583-
584- self ._set_container_sizes ()
0 commit comments