Skip to content

Commit eb57218

Browse files
committed
rewrote create_animations to take frames - still beta
1 parent efa390e commit eb57218

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

plotly/plotly/plotly.py

+42-13
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,7 @@ def _send_to_plotly(figure, **plot_options):
14071407
fileopt=plot_options['fileopt'],
14081408
world_readable=plot_options['world_readable'],
14091409
sharing=plot_options['sharing'],
1410-
layout=fig['layout'] if 'layout' in fig else {},
1411-
frames=fig['frames'] if 'frames' in fig else {}),
1410+
layout=fig['layout'] if 'layout' in fig else {}),
14121411
cls=utils.PlotlyJSONEncoder)
14131412

14141413
# TODO: It'd be cool to expose the platform for RaspPi and others
@@ -1419,9 +1418,9 @@ def _send_to_plotly(figure, **plot_options):
14191418
key=api_key,
14201419
origin='plot',
14211420
kwargs=kwargs)
1422-
1423-
if 'frames' in kwargs:
1424-
r = create_animations(fig, kwargs, payload)
1421+
#print fig
1422+
#if 'frames' in fig:
1423+
# r = create_animations(fig, kwargs, payload)
14251424

14261425
url = get_config()['plotly_domain'] + "/clientresp"
14271426

@@ -1449,10 +1448,6 @@ def _send_to_plotly(figure, **plot_options):
14491448

14501449

14511450
def create_animations(fig, kwargs, payload):
1452-
"""
1453-
The plan is to create a grid then a plot by deconstructing the fig if
1454-
frames is found in the kwargs.
1455-
"""
14561451
url_v2_plot = "https://api.plot.ly/v2/plots"
14571452
url_v2_grid = "https://api.plot.ly/v2/grids"
14581453
auth = HTTPBasicAuth(str(payload['un']), str(payload['key']))
@@ -1462,8 +1457,12 @@ def create_animations(fig, kwargs, payload):
14621457
if 'layout' not in fig:
14631458
fig['layout'] = {}
14641459

1460+
# make a copy of fig
1461+
fig_copy = copy.deepcopy(fig)
1462+
14651463
# make grid
14661464
cols_dict = {}
1465+
frames_cols_dict = {}
14671466
counter = 0
14681467
trace_num = 0
14691468
for trace in fig['data']:
@@ -1481,6 +1480,22 @@ def create_animations(fig, kwargs, payload):
14811480
counter += 1
14821481
trace_num += 1
14831482

1483+
# add frames data to grid
1484+
for j in range(len(fig['frames'])):
1485+
for var in ['x', 'y']:
1486+
if 'name' in fig['frames'][j]['data']:
1487+
cols_dict["{name}, {x_or_y}".format(name=fig['frames'][j]['data'][0]['name'],
1488+
x_or_y=var)] = {
1489+
"data": list(fig['frames'][j]['data'][0][var]), "order": counter
1490+
}
1491+
else:
1492+
cols_dict["Trace {num}, {x_or_y}".format(num=trace_num,
1493+
x_or_y=var)] = {
1494+
"data": list(fig['frames'][j]['data'][0][var]), "order": counter
1495+
}
1496+
counter += 1
1497+
trace_num += 1
1498+
14841499
grid_info = {
14851500
"data": {"cols": cols_dict},
14861501
"world_readable": True
@@ -1489,8 +1504,6 @@ def create_animations(fig, kwargs, payload):
14891504
r = requests.post('https://api.plot.ly/v2/grids', auth=auth,
14901505
headers=headers, json=grid_info)
14911506
r_dict = json.loads(r.text)
1492-
# make a copy of the fig so that we not altering the original fig
1493-
fig_copy = copy.deepcopy(fig)
14941507

14951508
# make plot
14961509
fid = r_dict['file']['fid']
@@ -1509,13 +1522,29 @@ def create_animations(fig, kwargs, payload):
15091522
)
15101523
cols_index += 2
15111524

1525+
# replace data in frames by grid ids
1526+
for j in range(len(fig['frames'])):
1527+
if 'x' in fig_copy['frames'][j]['data'][0]:
1528+
del fig_copy['frames'][j]['data'][0]['x']
1529+
if 'y' in fig_copy['frames'][j]['data'][0]:
1530+
del fig_copy['frames'][j]['data'][0]['y']
1531+
1532+
fig_copy['frames'][j]['data'][0]["xsrc"] = "{fid}:{idlocal}".format(
1533+
fid=fid, idlocal=r_dict['file']['cols'][cols_index]['uid']
1534+
)
1535+
fig_copy['frames'][j]['data'][0]["ysrc"] = "{fid}:{idlocal}".format(
1536+
fid=fid, idlocal=r_dict['file']['cols'][cols_index + 1]['uid']
1537+
)
1538+
cols_index += 2
1539+
15121540
plots_info = {
15131541
"figure": fig_copy,
15141542
"world_readable": True
15151543
}
15161544

1517-
return requests.post('https://api.plot.ly/v2/plots', auth=auth,
1518-
headers=headers, json=plots_info)
1545+
requests.post('https://api.plot.ly/v2/plots', auth=auth,
1546+
headers=headers, json=plots_info)
1547+
15191548

15201549

15211550
def _open_url(url):

0 commit comments

Comments
 (0)