Skip to content

Commit feca305

Browse files
committed
Merge pull request #177 from plotly/widgets-update-syntax
Widgets update syntax
2 parents 7b5abf3 + f0d571b commit feca305

File tree

5 files changed

+71
-48
lines changed

5 files changed

+71
-48
lines changed

plotly/plotly/plotly.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,15 @@ class Stream:
406406
Stream example:
407407
# Initialize a streaming graph
408408
# by embedding stream_id's in the graph's traces
409-
>>> stream_id = "your_stream_id" # See {plotly_domain}/settings
410-
>>> py.plot(Data([Scatter(x=[],
411-
y=[],
412-
stream=dict(token=stream_id, maxpoints=100))])
409+
import plotly.plotly as py
410+
from plotly.graph_objs import Data, Scatter, Stream
411+
stream_id = "your_stream_id" # See {plotly_domain}/settings
412+
py.plot(Data([Scatter(x=[], y=[],
413+
stream=Stream(token=stream_id, maxpoints=100))]))
413414
# Stream data to the import trace
414-
>>> stream = Stream(stream_id) # Initialize a stream object
415-
>>> stream.open() # Open the stream
416-
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
415+
stream = Stream(stream_id) # Initialize a stream object
416+
stream.open() # Open the stream
417+
stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
417418
"""
418419

419420
@utils.template_doc(**tools.get_config_file())

plotly/widgets/graphWidget.js

Lines changed: 25 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plotly/widgets/graph_widget.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from IPython.utils.traitlets import Unicode
99
from 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)

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ six==1.8.0
1313

1414
## timezone definitions ##
1515
pytz==2014.9
16+
17+
## 2.6 python dependencies ##
18+
simplejson==3.6.5
19+
ordereddict==1.1

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ def readme():
4040
'plotly/matplotlylib/mplexporter',
4141
'plotly/matplotlylib/mplexporter/renderers'],
4242
package_data={'plotly': ['graph_reference/*.json']},
43-
install_requires=['requests', 'six', 'pytz'],
43+
install_requires=['requests',
44+
'six',
45+
'pytz',
46+
'ordereddict',
47+
'simplejson'],
4448
zip_safe=False)

0 commit comments

Comments
 (0)