15
15
16
16
IPython = optional_imports .get_module ('IPython' )
17
17
18
- # default HTML parameters
19
- MASTER_WIDTH = 400
20
- MASTER_HEIGHT = 400
21
- FONT_SIZE = 10
18
+ # default parameters for HTML preview
19
+ MASTER_WIDTH = 500
20
+ MASTER_HEIGHT = 500
21
+ FONT_SIZE = 8
22
+
22
23
23
24
ID_NOT_VALID_MESSAGE = (
24
25
"Your box_id must be a number in your dashboard. To view a "
@@ -77,7 +78,7 @@ def _container(box_1=None, box_2=None,
77
78
</style>
78
79
</head>
79
80
<body>
80
- <canvas id="myCanvas" width="400 " height="400 "></canvas>
81
+ <canvas id="myCanvas" width="{width} " height="{height} "></canvas>
81
82
<script>
82
83
var canvas = document.getElementById('myCanvas');
83
84
var context = canvas.getContext('2d');
@@ -94,11 +95,13 @@ def _container(box_1=None, box_2=None,
94
95
95
96
96
97
def _draw_line_through_box (dashboard_html , top_left_x , top_left_y , box_w ,
97
- box_h , direction = 'vertical' ):
98
- is_horizontal = (direction == 'horizontal' )
99
-
98
+ box_h , is_horizontal , direction , fill_percent = 50 ):
100
99
if is_horizontal :
101
- new_top_left_x = top_left_x + box_w / 2
100
+ print 'draw it hori'
101
+ print 'fill_percent: {}' .format (fill_percent )
102
+ print (fill_percent / 100. )
103
+ new_top_left_x = box_w * (fill_percent / 100. )
104
+ print new_top_left_x
102
105
new_top_left_y = top_left_y
103
106
new_box_w = 1
104
107
new_box_h = box_h
@@ -299,9 +302,9 @@ def get_box(self, box_id):
299
302
loc_in_dashboard = loc_in_dashboard [first_second ]
300
303
return loc_in_dashboard
301
304
302
- def set_height (self , dashboard_height ):
305
+ def resize (self , dashboard_height ):
303
306
"""Sets the height (in pixels) of dashboard"""
304
- # problem when no box is inserted
307
+ # TODO: problem when no box is inserted
305
308
self ['layout' ]['size' ] = dashboard_height
306
309
self ['layout' ]['sizeUnit' ] = 'px'
307
310
@@ -335,17 +338,17 @@ def get_preview(self):
335
338
elif self ['layout' ] is None :
336
339
return IPython .display .HTML (dashboard_html )
337
340
338
- x = 0
339
- y = 0
341
+ top_left_x = 0
342
+ top_left_y = 0
340
343
box_w = MASTER_WIDTH
341
344
box_h = MASTER_HEIGHT
342
345
html_figure = dashboard_html
343
346
box_ids_to_path = self ._compute_box_ids ()
344
347
# used to store info about box dimensions
345
348
path_to_box_specs = {}
346
349
first_box_specs = {
347
- 'top_left_x' : x ,
348
- 'top_left_y' : y ,
350
+ 'top_left_x' : top_left_x ,
351
+ 'top_left_y' : top_left_y ,
349
352
'box_w' : box_w ,
350
353
'box_h' : box_h
351
354
}
@@ -361,57 +364,66 @@ def get_preview(self):
361
364
current_box_specs = path_to_box_specs [path ]
362
365
363
366
if self ._path_to_box (path )['type' ] == 'split' :
364
- html_figure = _draw_line_through_box (
365
- html_figure ,
366
- current_box_specs ['top_left_x' ],
367
- current_box_specs ['top_left_y' ],
368
- current_box_specs ['box_w' ],
369
- current_box_specs ['box_h' ],
370
- direction = self ._path_to_box (path )['direction' ]
371
- )
367
+ print path
368
+ fill_percent = self ._path_to_box (path )['size' ]
369
+ direction = self ._path_to_box (path )['direction' ]
370
+ is_horizontal = (direction == 'horizontal' )
372
371
373
- # determine the specs for resulting two boxes from split
374
- is_horizontal = (
375
- self ._path_to_box (path )['direction' ] == 'horizontal'
376
- )
377
- x = current_box_specs ['top_left_x' ]
378
- y = current_box_specs ['top_left_y' ]
372
+ top_left_x = current_box_specs ['top_left_x' ]
373
+ top_left_y = current_box_specs ['top_left_y' ]
379
374
box_w = current_box_specs ['box_w' ]
380
375
box_h = current_box_specs ['box_h' ]
381
376
377
+ html_figure = _draw_line_through_box (
378
+ html_figure , top_left_x , top_left_y , box_w , box_h ,
379
+ is_horizontal = is_horizontal , direction = direction ,
380
+ fill_percent = fill_percent
381
+ )
382
+
383
+ # determine the specs for resulting two box split
382
384
if is_horizontal :
383
- new_box_w = box_w / 2
385
+ print 'is horizontal'
386
+ new_top_left_x = top_left_x
387
+ new_top_left_y = top_left_y
388
+ new_box_w = box_w * ((fill_percent ) / 100. )
384
389
new_box_h = box_h
385
- new_top_left_x = x + box_w / 2
386
- new_top_left_y = y
387
390
391
+ new_top_left_x_2 = top_left_x + new_box_w
392
+ new_top_left_y_2 = top_left_y
393
+ new_box_w_2 = box_w * ((100 - fill_percent ) / 100. )
394
+ new_box_h_2 = box_h
388
395
else :
396
+ print 'is vertical'
397
+ #new_box_w = box_w
398
+ #new_box_h = box_h / 2
399
+ #new_top_left_x = top_left_x
400
+ #new_top_left_y = top_left_y + box_h / 2
401
+
389
402
new_box_w = box_w
390
- new_box_h = box_h / 2
391
- new_top_left_x = x
392
- new_top_left_y = y + box_h / 2
403
+ new_box_h = box_h * ( fill_percent / 100. )
404
+ new_top_left_x = top_left_x
405
+ new_top_left_y = top_left_y + box_h * ( fill_percent / 100. )
393
406
394
- box_1_specs = {
395
- 'top_left_x' : x ,
396
- 'top_left_y' : y ,
407
+ first_box_specs = {
408
+ 'top_left_x' : top_left_x ,
409
+ 'top_left_y' : top_left_y ,
397
410
'box_w' : new_box_w ,
398
411
'box_h' : new_box_h
399
412
}
400
- box_2_specs = {
401
- 'top_left_x' : new_top_left_x ,
402
- 'top_left_y' : new_top_left_y ,
403
- 'box_w' : new_box_w ,
404
- 'box_h' : new_box_h
413
+ second_box_specs = {
414
+ 'top_left_x' : new_top_left_x_2 ,
415
+ 'top_left_y' : new_top_left_y_2 ,
416
+ 'box_w' : new_box_w_2 ,
417
+ 'box_h' : new_box_h_2
405
418
}
406
419
407
- path_to_box_specs [path + ('first' ,)] = box_1_specs
408
- path_to_box_specs [path + ('second' ,)] = box_2_specs
420
+ path_to_box_specs [path + ('first' ,)] = first_box_specs
421
+ path_to_box_specs [path + ('second' ,)] = second_box_specs
409
422
410
423
elif self ._path_to_box (path )['type' ] == 'box' :
411
424
for box_id in box_ids_to_path :
412
425
if box_ids_to_path [box_id ] == path :
413
426
number = box_id
414
-
415
427
html_figure = _add_html_text (
416
428
html_figure , number ,
417
429
path_to_box_specs [path ]['top_left_x' ],
@@ -505,7 +517,7 @@ def insert(self, box, side='above', box_id=None, fill_percent=50):
505
517
old_box = self .get_box (box_id )
506
518
self ._insert (
507
519
_container (old_box , box , direction = 'horizontal' ,
508
- size = 100 - fill_percent ),
520
+ size = 100 - fill_percent ),
509
521
box_ids_to_path [box_id ]
510
522
)
511
523
else :
0 commit comments