Skip to content

Commit f732045

Browse files
committed
Merge branch 'widgets' into js-import
Conflicts: plotly/widgets/graph_widget.py
2 parents 432fa10 + 695dd28 commit f732045

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

plotly/widgets/graphWidget.js

Lines changed: 1 addition & 1 deletion
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from IPython.utils.traitlets import Unicode
88
from IPython.display import Javascript, display
99

10+
import plotly
11+
1012
# Load JS widget code
1113
# No officially recommended way to do this in any other way
1214
# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
@@ -19,6 +21,7 @@
1921

2022
__all__ = None
2123

24+
2225
class Graph(widgets.DOMWidget):
2326
"""An interactive Plotly graph widget for use in IPython
2427
Notebooks.
@@ -88,6 +91,7 @@ def _handle_registration(self, event_type, callback, remove):
8891
self._handle_outgoing_message(message)
8992

9093
def _handle_outgoing_message(self, message):
94+
message['plotlyDomain'] = plotly.plotly.get_config()['plotly_domain']
9195
if self._graphId == '':
9296
self._clientMessages.append(message)
9397
else:
@@ -131,3 +135,49 @@ def relayout(self, layout):
131135
def hover(self, hover_obj):
132136
message = {'hover': hover_obj, 'graphId': self._graphId}
133137
self._handle_outgoing_message(message)
138+
139+
def add_traces(self, traces, new_indices=None):
140+
"""
141+
Add new data traces to a graph.
142+
143+
If `new_indices` isn't specified, they are simply appended.
144+
145+
:param (list[dict]) traces: The list of trace dicts
146+
:param (list[int]|None|optional) new_indices: The final indices the
147+
added traces should occupy.
148+
149+
"""
150+
body = {'traces': traces}
151+
if new_indices is not None:
152+
body['newIndices'] = new_indices
153+
message = {'addTraces': body}
154+
self._handle_outgoing_message(message)
155+
156+
def delete_traces(self, indices):
157+
"""
158+
Delete data traces from a graph.
159+
160+
:param (list[int]) indices: The indices of the traces to be removed
161+
162+
"""
163+
message = {'deleteTraces': {'indices': indices}}
164+
self._handle_outgoing_message(message)
165+
166+
def move_traces(self, current_indices, new_indices=None):
167+
"""
168+
Move data traces around in a graph.
169+
170+
If new_indices isn't specified, the traces at the locations specified
171+
in current_indices are moved to the end of the data array.
172+
173+
:param (list[int]) current_indices: The initial indices the traces to
174+
be moved occupy.
175+
:param (list[int]|None|optional) new_indices: The final indices the
176+
traces to be moved will occupy.
177+
178+
"""
179+
body = {'currentIndices': current_indices}
180+
if new_indices is not None:
181+
body['newIndices'] = new_indices
182+
message = {'moveTraces': body}
183+
self._handle_outgoing_message(message)

0 commit comments

Comments
 (0)