8
8
from IPython .utils .traitlets import Unicode
9
9
from IPython .display import Javascript , display
10
10
11
- import plotly
12
-
13
11
# Load JS widget code
14
12
# No officially recommended way to do this in any other way
15
13
# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
@@ -88,11 +86,10 @@ def _handle_registration(self, event_type, callback, remove):
88
86
event_callbacks = self ._event_handlers [event_type ].callbacks
89
87
if (len (event_callbacks ) and event_type not in self ._listener_set ):
90
88
self ._listener_set .add (event_type )
91
- message = {'listen' : list (self ._listener_set )}
89
+ message = {'task' : ' listen' , 'events ' : list (self ._listener_set )}
92
90
self ._handle_outgoing_message (message )
93
91
94
92
def _handle_outgoing_message (self , message ):
95
- message ['plotlyDomain' ] = plotly .plotly .get_config ()['plotly_domain' ]
96
93
if self ._graphId == '' :
97
94
self ._clientMessages .append (message )
98
95
else :
@@ -124,18 +121,24 @@ def on_zoom(self, callback, remove=False):
124
121
Set to true to remove the callback from the list of callbacks."""
125
122
self ._handle_registration ('zoom' , callback , remove )
126
123
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
131
128
self ._handle_outgoing_message (message )
132
129
133
130
def relayout (self , layout ):
134
- message = {'relayout' : layout , 'graphId' : self ._graphId }
131
+ message = {
132
+ 'task' : 'relayout' , 'update' : layout , 'graphId' : self ._graphId
133
+ }
135
134
self ._handle_outgoing_message (message )
136
135
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
139
142
self ._handle_outgoing_message (message )
140
143
141
144
def add_traces (self , traces , new_indices = None ):
@@ -149,10 +152,11 @@ def add_traces(self, traces, new_indices=None):
149
152
added traces should occupy.
150
153
151
154
"""
152
- body = {'traces' : traces }
155
+ message = {
156
+ 'task' : 'addTraces' , 'traces' : traces , 'graphId' : self ._graphId
157
+ }
153
158
if new_indices is not None :
154
- body ['newIndices' ] = new_indices
155
- message = {'addTraces' : body }
159
+ message ['newIndices' ] = new_indices
156
160
self ._handle_outgoing_message (message )
157
161
158
162
def delete_traces (self , indices ):
@@ -162,7 +166,11 @@ def delete_traces(self, indices):
162
166
:param (list[int]) indices: The indices of the traces to be removed
163
167
164
168
"""
165
- message = {'deleteTraces' : {'indices' : indices }}
169
+ message = {
170
+ 'task' : 'deleteTraces' ,
171
+ 'indices' : indices ,
172
+ 'graphId' : self ._graphId
173
+ }
166
174
self ._handle_outgoing_message (message )
167
175
168
176
def move_traces (self , current_indices , new_indices = None ):
@@ -178,8 +186,11 @@ def move_traces(self, current_indices, new_indices=None):
178
186
traces to be moved will occupy.
179
187
180
188
"""
181
- body = {'currentIndices' : current_indices }
189
+ message = {
190
+ 'task' : 'moveTraces' ,
191
+ 'currentIndices' : current_indices ,
192
+ 'graphId' : self ._graphId
193
+ }
182
194
if new_indices is not None :
183
- body ['newIndices' ] = new_indices
184
- message = {'moveTraces' : body }
195
+ message ['newIndices' ] = new_indices
185
196
self ._handle_outgoing_message (message )
0 commit comments