|
7 | 7 | from IPython.utils.traitlets import Unicode
|
8 | 8 | from IPython.display import Javascript, display
|
9 | 9 |
|
| 10 | +import plotly |
| 11 | + |
10 | 12 | # Load JS widget code
|
11 | 13 | # No officially recommended way to do this in any other way
|
12 | 14 | # http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
|
|
19 | 21 |
|
20 | 22 | __all__ = None
|
21 | 23 |
|
| 24 | + |
22 | 25 | class Graph(widgets.DOMWidget):
|
23 | 26 | """An interactive Plotly graph widget for use in IPython
|
24 | 27 | Notebooks.
|
@@ -88,6 +91,7 @@ def _handle_registration(self, event_type, callback, remove):
|
88 | 91 | self._handle_outgoing_message(message)
|
89 | 92 |
|
90 | 93 | def _handle_outgoing_message(self, message):
|
| 94 | + message['plotlyDomain'] = plotly.plotly.get_config()['plotly_domain'] |
91 | 95 | if self._graphId == '':
|
92 | 96 | self._clientMessages.append(message)
|
93 | 97 | else:
|
@@ -131,3 +135,49 @@ def relayout(self, layout):
|
131 | 135 | def hover(self, hover_obj):
|
132 | 136 | message = {'hover': hover_obj, 'graphId': self._graphId}
|
133 | 137 | 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