88from IPython .utils .traitlets import Unicode
99from IPython .display import Javascript , display
1010
11- import plotly
12-
1311# Load JS widget code
1412# No officially recommended way to do this in any other way
1513# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
@@ -88,11 +86,10 @@ def _handle_registration(self, event_type, callback, remove):
8886 event_callbacks = self ._event_handlers [event_type ].callbacks
8987 if (len (event_callbacks ) and event_type not in self ._listener_set ):
9088 self ._listener_set .add (event_type )
91- message = {'listen' : list (self ._listener_set )}
89+ message = {'task' : ' listen' , 'events ' : list (self ._listener_set )}
9290 self ._handle_outgoing_message (message )
9391
9492 def _handle_outgoing_message (self , message ):
95- message ['plotlyDomain' ] = plotly .plotly .get_config ()['plotly_domain' ]
9693 if self ._graphId == '' :
9794 self ._clientMessages .append (message )
9895 else :
@@ -124,18 +121,24 @@ def on_zoom(self, callback, remove=False):
124121 Set to true to remove the callback from the list of callbacks."""
125122 self ._handle_registration ('zoom' , callback , remove )
126123
127- def restyle (self , data , traces = None ):
128- message = {'restyle' : data , 'graphId' : self ._graphId }
129- if traces :
130- message ['traces ' ] = traces
124+ def restyle (self , data , indices = None ):
125+ message = {'task' : ' restyle' , 'update ' : data , 'graphId' : self ._graphId }
126+ if indices :
127+ message ['indices ' ] = indices
131128 self ._handle_outgoing_message (message )
132129
133130 def relayout (self , layout ):
134- message = {'relayout' : layout , 'graphId' : self ._graphId }
131+ message = {
132+ 'task' : 'relayout' , 'update' : layout , 'graphId' : self ._graphId
133+ }
135134 self ._handle_outgoing_message (message )
136135
137- def hover (self , hover_obj ):
138- message = {'hover' : hover_obj , 'graphId' : self ._graphId }
136+ def hover (self , hover_obj , subplot = None ):
137+ message = {
138+ 'task' : 'hover' , 'selection' : hover_obj , 'graphId' : self ._graphId
139+ }
140+ if subplot is not None :
141+ message ['subplot' ] = subplot
139142 self ._handle_outgoing_message (message )
140143
141144 def add_traces (self , traces , new_indices = None ):
@@ -149,10 +152,11 @@ def add_traces(self, traces, new_indices=None):
149152 added traces should occupy.
150153
151154 """
152- body = {'traces' : traces }
155+ message = {
156+ 'task' : 'addTraces' , 'traces' : traces , 'graphId' : self ._graphId
157+ }
153158 if new_indices is not None :
154- body ['newIndices' ] = new_indices
155- message = {'addTraces' : body }
159+ message ['newIndices' ] = new_indices
156160 self ._handle_outgoing_message (message )
157161
158162 def delete_traces (self , indices ):
@@ -162,7 +166,11 @@ def delete_traces(self, indices):
162166 :param (list[int]) indices: The indices of the traces to be removed
163167
164168 """
165- message = {'deleteTraces' : {'indices' : indices }}
169+ message = {
170+ 'task' : 'deleteTraces' ,
171+ 'indices' : indices ,
172+ 'graphId' : self ._graphId
173+ }
166174 self ._handle_outgoing_message (message )
167175
168176 def move_traces (self , current_indices , new_indices = None ):
@@ -178,8 +186,11 @@ def move_traces(self, current_indices, new_indices=None):
178186 traces to be moved will occupy.
179187
180188 """
181- body = {'currentIndices' : current_indices }
189+ message = {
190+ 'task' : 'moveTraces' ,
191+ 'currentIndices' : current_indices ,
192+ 'graphId' : self ._graphId
193+ }
182194 if new_indices is not None :
183- body ['newIndices' ] = new_indices
184- message = {'moveTraces' : body }
195+ message ['newIndices' ] = new_indices
185196 self ._handle_outgoing_message (message )
0 commit comments