Skip to content

Add support for extra traces #40

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 5 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ can be a list of such colors, defining a colormap.

**property `VolumeSlicer.axis`** (`int`): The axis to slice.

**property `VolumeSlicer.extra_traces`**: A `dcc.Store` that can be used as an output to define
additional traces to be shown in this slicer. The data must be
a list of dictionaries, with each dict representing a raw trace
object.

**property `VolumeSlicer.graph`**: The `dcc.Graph` for this slicer. Use `graph.figure` to access the
Plotly Figure object.

Expand Down
19 changes: 17 additions & 2 deletions dash_slicer/slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ def state(self):
"""
return self._state

@property
def extra_traces(self):
"""A `dcc.Store` that can be used as an output to define
additional traces to be shown in this slicer. The data must be
a list of dictionaries, with each dict representing a raw trace
object.
"""
return self._extra_traces

@property
def overlay_data(self):
"""A `dcc.Store` containing the overlay data. The form of this
Expand Down Expand Up @@ -420,6 +429,9 @@ def _create_dash_components(self):
# Store indicator traces for the slicer.
self._indicator_traces = Store(id=self._subid("indicator-traces"), data=[])

# Store user traces for the slider.
self._extra_traces = Store(id=self._subid("extra-traces"), data=[])

# A timer to apply a rate-limit between slider.value and index.data
self._timer = Interval(id=self._subid("timer"), interval=100, disabled=True)

Expand All @@ -436,6 +448,7 @@ def _create_dash_components(self):
self._server_data,
self._img_traces,
self._indicator_traces,
self._extra_traces,
self._timer,
self._state,
self._setpos,
Expand Down Expand Up @@ -787,11 +800,12 @@ def _create_client_callbacks(self):

app.clientside_callback(
"""
function update_figure(img_traces, indicators, info, ori_figure) {
function update_figure(img_traces, indicator_traces, extra_traces, info, ori_figure) {
// Collect traces
let traces = [];
for (let trace of img_traces) { traces.push(trace); }
for (let trace of indicators) { if (trace.line.color) traces.push(trace); }
for (let trace of extra_traces) { traces.push(trace); }
for (let trace of indicator_traces) { if (trace.line.color) traces.push(trace); }
// Update figure
let figure = {...ori_figure};
figure.data = traces;
Expand All @@ -802,6 +816,7 @@ def _create_client_callbacks(self):
[
Input(self._img_traces.id, "data"),
Input(self._indicator_traces.id, "data"),
Input(self._extra_traces.id, "data"),
],
[State(self._info.id, "data"), State(self._graph.id, "figure")],
)
7 changes: 0 additions & 7 deletions examples/threshold_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
mi, ma = vol.min(), vol.max()
slicer = VolumeSlicer(app, vol)

slicer.graph.config.update(
modeBarButtonsToAdd=[
"drawclosedpath",
"eraseshape",
]
)


app.layout = html.Div(
[
Expand Down