Skip to content

Commit b149e0d

Browse files
committed
html preview not working
1 parent 1b09e21 commit b149e0d

File tree

1 file changed

+59
-47
lines changed

1 file changed

+59
-47
lines changed

plotly/dashboard_objs/dashboard_objs.py

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
IPython = optional_imports.get_module('IPython')
1717

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+
2223

2324
ID_NOT_VALID_MESSAGE = (
2425
"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,
7778
</style>
7879
</head>
7980
<body>
80-
<canvas id="myCanvas" width="400" height="400"></canvas>
81+
<canvas id="myCanvas" width="{width}" height="{height}"></canvas>
8182
<script>
8283
var canvas = document.getElementById('myCanvas');
8384
var context = canvas.getContext('2d');
@@ -94,11 +95,13 @@ def _container(box_1=None, box_2=None,
9495

9596

9697
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):
10099
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
102105
new_top_left_y = top_left_y
103106
new_box_w = 1
104107
new_box_h = box_h
@@ -299,9 +302,9 @@ def get_box(self, box_id):
299302
loc_in_dashboard = loc_in_dashboard[first_second]
300303
return loc_in_dashboard
301304

302-
def set_height(self, dashboard_height):
305+
def resize(self, dashboard_height):
303306
"""Sets the height (in pixels) of dashboard"""
304-
# problem when no box is inserted
307+
# TODO: problem when no box is inserted
305308
self['layout']['size'] = dashboard_height
306309
self['layout']['sizeUnit'] = 'px'
307310

@@ -335,17 +338,17 @@ def get_preview(self):
335338
elif self['layout'] is None:
336339
return IPython.display.HTML(dashboard_html)
337340

338-
x = 0
339-
y = 0
341+
top_left_x = 0
342+
top_left_y = 0
340343
box_w = MASTER_WIDTH
341344
box_h = MASTER_HEIGHT
342345
html_figure = dashboard_html
343346
box_ids_to_path = self._compute_box_ids()
344347
# used to store info about box dimensions
345348
path_to_box_specs = {}
346349
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,
349352
'box_w': box_w,
350353
'box_h': box_h
351354
}
@@ -361,57 +364,66 @@ def get_preview(self):
361364
current_box_specs = path_to_box_specs[path]
362365

363366
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')
372371

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']
379374
box_w = current_box_specs['box_w']
380375
box_h = current_box_specs['box_h']
381376

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
382384
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.)
384389
new_box_h = box_h
385-
new_top_left_x = x + box_w / 2
386-
new_top_left_y = y
387390

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
388395
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+
389402
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.)
393406

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,
397410
'box_w': new_box_w,
398411
'box_h': new_box_h
399412
}
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
405418
}
406419

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
409422

410423
elif self._path_to_box(path)['type'] == 'box':
411424
for box_id in box_ids_to_path:
412425
if box_ids_to_path[box_id] == path:
413426
number = box_id
414-
415427
html_figure = _add_html_text(
416428
html_figure, number,
417429
path_to_box_specs[path]['top_left_x'],
@@ -505,7 +517,7 @@ def insert(self, box, side='above', box_id=None, fill_percent=50):
505517
old_box = self.get_box(box_id)
506518
self._insert(
507519
_container(old_box, box, direction='horizontal',
508-
size=100 - fill_percent),
520+
size =100 - fill_percent),
509521
box_ids_to_path[box_id]
510522
)
511523
else:

0 commit comments

Comments
 (0)