8
8
from IPython .display import Javascript , display
9
9
10
10
from plotly import utils
11
+ import plotly .plotly .plotly as py
11
12
from pkg_resources import resource_string
12
13
13
14
# Load JS widget code
@@ -28,6 +29,11 @@ class GraphWidget(widgets.DOMWidget):
28
29
_view_name = Unicode ('GraphView' , sync = True )
29
30
_message = Unicode (sync = True )
30
31
_graph_url = Unicode (sync = True )
32
+ _new_url = Unicode (sync = True )
33
+ _filename = ''
34
+ _flags = {
35
+ 'save_pending' : False
36
+ }
31
37
32
38
# TODO: URL for offline enterprise
33
39
def __init__ (self , graph_url = 'https://plot.ly/~playground/7' , ** kwargs ):
@@ -88,6 +94,13 @@ def _handle_msg(self, message):
88
94
message = content ['message' ]['ranges' ]
89
95
90
96
self ._event_handlers [content ['event' ]](self , message )
97
+ if content .get ('event' , '' ) == 'getAttributes' :
98
+ self ._attributes = content .get ('response' , {})
99
+ if self ._flags ['save_pending' ]:
100
+ self ._flags ['save_pending' ] = False
101
+ url = py .plot (self ._attributes , auto_open = False ,
102
+ filename = self ._filename , validate = False )
103
+ self ._new_url = url
91
104
92
105
def _handle_registration (self , event_type , callback , remove ):
93
106
self ._event_handlers [event_type ].register_callback (callback ,
@@ -605,3 +618,15 @@ def reorder_traces(self, current_indices, new_indices=None):
605
618
message ['newIndices' ] = new_indices
606
619
self ._handle_outgoing_message (message )
607
620
621
+ def save (self , ignore_defaults = False , filename = '' ):
622
+ """
623
+ Save a copy of the current state of the widget in plotly.
624
+
625
+ :param (bool) ignore_defaults: Auto-fill in unspecified figure keys?
626
+ :param (str) filename: Name of the file on plotly.
627
+
628
+ """
629
+ self ._flags ['save_pending' ] = True
630
+ self ._filename = filename
631
+ message = {'task' : 'getAttributes' , 'ignoreDefaults' : ignore_defaults }
632
+ self ._handle_outgoing_message (message )
0 commit comments