Skip to content

Widgets update syntax #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,15 @@ class Stream:
Stream example:
# Initialize a streaming graph
# by embedding stream_id's in the graph's traces
>>> stream_id = "your_stream_id" # See {plotly_domain}/settings
>>> py.plot(Data([Scatter(x=[],
y=[],
stream=dict(token=stream_id, maxpoints=100))])
import plotly.plotly as py
from plotly.graph_objs import Data, Scatter, Stream
stream_id = "your_stream_id" # See {plotly_domain}/settings
py.plot(Data([Scatter(x=[], y=[],
stream=Stream(token=stream_id, maxpoints=100))]))
# Stream data to the import trace
>>> stream = Stream(stream_id) # Initialize a stream object
>>> stream.open() # Open the stream
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
stream = Stream(stream_id) # Initialize a stream object
stream.open() # Open the stream
stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
"""

@utils.template_doc(**tools.get_config_file())
Expand Down
47 changes: 25 additions & 22 deletions plotly/widgets/graphWidget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 29 additions & 18 deletions plotly/widgets/graph_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from IPython.utils.traitlets import Unicode
from IPython.display import Javascript, display

import plotly

# Load JS widget code
# No officially recommended way to do this in any other way
# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
Expand Down Expand Up @@ -88,11 +86,10 @@ def _handle_registration(self, event_type, callback, remove):
event_callbacks = self._event_handlers[event_type].callbacks
if (len(event_callbacks) and event_type not in self._listener_set):
self._listener_set.add(event_type)
message = {'listen': list(self._listener_set)}
message = {'task': 'listen', 'events': list(self._listener_set)}
self._handle_outgoing_message(message)

def _handle_outgoing_message(self, message):
message['plotlyDomain'] = plotly.plotly.get_config()['plotly_domain']
if self._graphId == '':
self._clientMessages.append(message)
else:
Expand Down Expand Up @@ -124,18 +121,24 @@ def on_zoom(self, callback, remove=False):
Set to true to remove the callback from the list of callbacks."""
self._handle_registration('zoom', callback, remove)

def restyle(self, data, traces=None):
message = {'restyle': data, 'graphId': self._graphId}
if traces:
message['traces'] = traces
def restyle(self, data, indices=None):
message = {'task': 'restyle', 'update': data, 'graphId': self._graphId}
if indices:
message['indices'] = indices
self._handle_outgoing_message(message)

def relayout(self, layout):
message = {'relayout': layout, 'graphId': self._graphId}
message = {
'task': 'relayout', 'update': layout, 'graphId': self._graphId
}
self._handle_outgoing_message(message)

def hover(self, hover_obj):
message = {'hover': hover_obj, 'graphId': self._graphId}
def hover(self, hover_obj, subplot=None):
message = {
'task': 'hover', 'selection': hover_obj, 'graphId': self._graphId
}
if subplot is not None:
message['subplot'] = subplot
self._handle_outgoing_message(message)

def add_traces(self, traces, new_indices=None):
Expand All @@ -149,10 +152,11 @@ def add_traces(self, traces, new_indices=None):
added traces should occupy.

"""
body = {'traces': traces}
message = {
'task': 'addTraces', 'traces': traces, 'graphId': self._graphId
}
if new_indices is not None:
body['newIndices'] = new_indices
message = {'addTraces': body}
message['newIndices'] = new_indices
self._handle_outgoing_message(message)

def delete_traces(self, indices):
Expand All @@ -162,7 +166,11 @@ def delete_traces(self, indices):
:param (list[int]) indices: The indices of the traces to be removed

"""
message = {'deleteTraces': {'indices': indices}}
message = {
'task': 'deleteTraces',
'indices': indices,
'graphId': self._graphId
}
self._handle_outgoing_message(message)

def move_traces(self, current_indices, new_indices=None):
Expand All @@ -178,8 +186,11 @@ def move_traces(self, current_indices, new_indices=None):
traces to be moved will occupy.

"""
body = {'currentIndices': current_indices}
message = {
'task': 'moveTraces',
'currentIndices': current_indices,
'graphId': self._graphId
}
if new_indices is not None:
body['newIndices'] = new_indices
message = {'moveTraces': body}
message['newIndices'] = new_indices
self._handle_outgoing_message(message)
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ six==1.8.0

## timezone definitions ##
pytz==2014.9

## 2.6 python dependencies ##
simplejson==3.6.5
ordereddict==1.1
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ def readme():
'plotly/matplotlylib/mplexporter',
'plotly/matplotlylib/mplexporter/renderers'],
package_data={'plotly': ['graph_reference/*.json']},
install_requires=['requests', 'six', 'pytz'],
install_requires=['requests',
'six',
'pytz',
'ordereddict',
'simplejson'],
zip_safe=False)