Skip to content

Commit 0f14ee1

Browse files
committed
Update widget methods with new functionality.
1 parent 9b812f3 commit 0f14ee1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

plotly/widgets/graph_widget.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,49 @@ def relayout(self, layout):
128128
def hover(self, hover_obj):
129129
message = {'hover': hover_obj, 'graphId': self._graphId}
130130
self._handle_outgoing_message(message)
131+
132+
def add_traces(self, traces, new_indices=None):
133+
"""
134+
Add new data traces to a graph.
135+
136+
If `new_indices` isn't specified, they are simply appended.
137+
138+
:param (list[dict]) traces: The list of trace dicts
139+
:param (list[int]|None|optional) new_indices: The final indices the
140+
added traces should occupy.
141+
142+
"""
143+
body = {'traces': traces}
144+
if new_indices is not None:
145+
body['newIndices'] = new_indices
146+
message = {'addTraces': body}
147+
self._handle_outgoing_message(message)
148+
149+
def delete_traces(self, indices):
150+
"""
151+
Delete data traces from a graph.
152+
153+
:param (list[int]) indices: The indices of the traces to be removed
154+
155+
"""
156+
message = {'deleteTraces': {'indices': indices}}
157+
self._handle_outgoing_message(message)
158+
159+
def move_traces(self, current_indices, new_indices=None):
160+
"""
161+
Move data traces around in a graph.
162+
163+
If new_indices isn't specified, the traces at the locations specified
164+
in current_indices are moved to the end of the data array.
165+
166+
:param (list[int]) current_indices: The initial indices the traces to
167+
be moved occupy.
168+
:param (list[int]|None|optional) new_indices: The final indices the
169+
traces to be moved will occupy.
170+
171+
"""
172+
body = {'currentIndices': current_indices}
173+
if new_indices is not None:
174+
body['newIndices'] = new_indices
175+
message = {'moveTraces': body}
176+
self._handle_outgoing_message(message)

0 commit comments

Comments
 (0)