@@ -1407,8 +1407,7 @@ def _send_to_plotly(figure, **plot_options):
1407
1407
fileopt = plot_options ['fileopt' ],
1408
1408
world_readable = plot_options ['world_readable' ],
1409
1409
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 {}),
1412
1411
cls = utils .PlotlyJSONEncoder )
1413
1412
1414
1413
# TODO: It'd be cool to expose the platform for RaspPi and others
@@ -1419,9 +1418,9 @@ def _send_to_plotly(figure, **plot_options):
1419
1418
key = api_key ,
1420
1419
origin = 'plot' ,
1421
1420
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)
1425
1424
1426
1425
url = get_config ()['plotly_domain' ] + "/clientresp"
1427
1426
@@ -1449,10 +1448,6 @@ def _send_to_plotly(figure, **plot_options):
1449
1448
1450
1449
1451
1450
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
- """
1456
1451
url_v2_plot = "https://api.plot.ly/v2/plots"
1457
1452
url_v2_grid = "https://api.plot.ly/v2/grids"
1458
1453
auth = HTTPBasicAuth (str (payload ['un' ]), str (payload ['key' ]))
@@ -1462,8 +1457,12 @@ def create_animations(fig, kwargs, payload):
1462
1457
if 'layout' not in fig :
1463
1458
fig ['layout' ] = {}
1464
1459
1460
+ # make a copy of fig
1461
+ fig_copy = copy .deepcopy (fig )
1462
+
1465
1463
# make grid
1466
1464
cols_dict = {}
1465
+ frames_cols_dict = {}
1467
1466
counter = 0
1468
1467
trace_num = 0
1469
1468
for trace in fig ['data' ]:
@@ -1481,6 +1480,22 @@ def create_animations(fig, kwargs, payload):
1481
1480
counter += 1
1482
1481
trace_num += 1
1483
1482
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
+
1484
1499
grid_info = {
1485
1500
"data" : {"cols" : cols_dict },
1486
1501
"world_readable" : True
@@ -1489,8 +1504,6 @@ def create_animations(fig, kwargs, payload):
1489
1504
r = requests .post ('https://api.plot.ly/v2/grids' , auth = auth ,
1490
1505
headers = headers , json = grid_info )
1491
1506
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 )
1494
1507
1495
1508
# make plot
1496
1509
fid = r_dict ['file' ]['fid' ]
@@ -1509,13 +1522,29 @@ def create_animations(fig, kwargs, payload):
1509
1522
)
1510
1523
cols_index += 2
1511
1524
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
+
1512
1540
plots_info = {
1513
1541
"figure" : fig_copy ,
1514
1542
"world_readable" : True
1515
1543
}
1516
1544
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
+
1519
1548
1520
1549
1521
1550
def _open_url (url ):
0 commit comments