@@ -54,7 +54,132 @@ This code is distributed under MIT license.
54
54
* Use ` black . ` to autoformat.
55
55
* Use ` flake8 . ` to lint.
56
56
* Use ` pytest . ` to run the tests.
57
+ * Use ` python update_docs_in_readme.py ` to update the readme when needed.
57
58
58
59
On every PR, an app with the same name as your branch is deployed to the Dash
59
60
playground instance so that you can change whether your changes did not break
60
61
the package.
62
+
63
+
64
+ ## Reference
65
+
66
+ ### The VolumeSlicer class
67
+
68
+ ** class ` VolumeSlicer(app, volume, *, spacing=None, origin=None, axis=0, reverse_y=True, scene_id=None, color=None, thumbnail=True) ` **
69
+
70
+ A slicer object to show 3D image data in Dash. Upon
71
+ instantiation one can provide the following parameters:
72
+
73
+ * ` app ` (` dash.Dash ` ): the Dash application instance.
74
+ * ` volume ` (` ndarray ` ): the 3D numpy array to slice through. The dimensions
75
+ are assumed to be in zyx order. If this is not the case, you can
76
+ use ` np.swapaxes ` to make it so.
77
+ * ` spacing ` (tuple of ` float ` ): The distance between voxels for each
78
+ dimension (zyx).The spacing and origin are applied to make the slice
79
+ drawn in "scene space" rather than "voxel space".
80
+ * ` origin ` (tuple of ` float ` ): The offset for each dimension (zyx).
81
+ * ` axis ` (` int ` ): the dimension to slice in. Default 0.
82
+ * ` reverse_y ` (` bool ` ): Whether to reverse the y-axis, so that the origin of
83
+ the slice is in the top-left, rather than bottom-left. Default True.
84
+ Note: setting this to False affects performance, see #12 .
85
+ * ` scene_id ` (` str ` ): the scene that this slicer is part of. Slicers
86
+ that have the same scene-id show each-other's positions with
87
+ line indicators. By default this is derived from ` id(volume) ` .
88
+ * ` color ` (` str ` ): the color for this slicer. By default the color is
89
+ red, green, or blue, depending on the axis. Set to empty string
90
+ for "no color".
91
+ * ` thumbnail ` (` int ` or ` bool ` ): preferred size of low-resolution data to be
92
+ uploaded to the client. If ` False ` , the full-resolution data are
93
+ uploaded client-side. If ` True ` (default), a default value of 32 is
94
+ used.
95
+
96
+ Note that this is not a Dash component. The components that make
97
+ up the slicer (and which must be present in the layout) are:
98
+ ` slicer.graph ` , ` slicer.slider ` , and ` slicer.stores ` .
99
+
100
+ ** method ` VolumeSlicer.create_overlay_data(mask, color=None) ` **
101
+
102
+ Given a 3D mask array and an index, create an object that
103
+ can be used as output for ` slicer.overlay_data ` . The color
104
+ can be a hex color or an rgb/rgba tuple. Alternatively, color
105
+ can be a list of such colors, defining a colormap.
106
+
107
+ ** property ` VolumeSlicer.axis ` ** (` int ` ): The axis at which the slicer is slicing.
108
+
109
+ ** property ` VolumeSlicer.graph ` ** : The ` dcc.Graph ` for this slicer. Use ` graph.figure ` to access the
110
+ Plotly Figure object.
111
+
112
+ ** property ` VolumeSlicer.nslices ` ** (` int ` ): The number of slices for this slicer.
113
+
114
+ ** property ` VolumeSlicer.overlay_data ` ** : A ` dcc.Store ` containing the overlay data. The form of this
115
+ data is considered an implementation detail; users are expected to use
116
+ ` create_overlay_data ` to create it.
117
+
118
+ ** property ` VolumeSlicer.scene_id ` ** (` str ` ): The id of the "virtual scene" for this slicer. Slicers that have
119
+ the same scene_id show each-other's positions.
120
+
121
+ ** property ` VolumeSlicer.slider ` ** : The ` dcc.Slider ` to change the index for this slicer. If you
122
+ don't want to use the slider, wrap it in a div with style
123
+ ` display: none ` .
124
+
125
+ ** property ` VolumeSlicer.state ` ** : A ` dcc.Store ` representing the current state of the slicer (present
126
+ in slicer.stores). Its data is a dict with the fields:
127
+
128
+ * "index": the integer slice index.
129
+ * "index_changed": a bool indicating whether the index changed since last time.
130
+ * "xrange": the view range (2 floats) in the x-dimension (2D).
131
+ * "yrange": the view range (2 floats) in the y-dimension (2D).
132
+ * "zpos": the float position aling the axis, in scene coordinates.
133
+ * "axis": the axis (int) for this slicer.
134
+ * "color": the color (str) for this slicer.
135
+
136
+ The id of the store is a dictionary so it can be used in a
137
+ pattern matching Input. Its field are: context, scene, name.
138
+ Where scene is the scene_id and name is "state".
139
+
140
+ ** property ` VolumeSlicer.stores ` ** : A list of ` dcc.Store ` objects that the slicer needs to work.
141
+ These must be added to the app layout.
142
+
143
+
144
+
145
+ ### Reacting to slicer state
146
+
147
+ It is possible to get notified of updates to slicer position and
148
+ view ranges. To get this for all slicers with a specific scene_id, create
149
+ a [ pattern matching input] ( https://dash.plotly.com/pattern-matching-callbacks )
150
+ like this:
151
+ ``` py
152
+ Input({" scene" : scene_id, " context" : ALL , " name" : " state" })
153
+ ```
154
+
155
+ See the ` state ` property for details.
156
+
157
+
158
+ ### Setting slicer positions
159
+
160
+ To programatically set the position of the slicer, create a ` dcc.Store ` with
161
+ a dictionary-id that has the following fields:
162
+
163
+ * 'context': a unique name for this store.
164
+ * 'scene': the scene_id of the slicer objects to set the position for.
165
+ * 'name': 'setpos'
166
+
167
+ The value in the store must be an 3-element tuple (x, y, z) in scene coordinates.
168
+ To apply the position for one dimension only, use e.g ` (None, None, x) ` .
169
+
170
+
171
+ ### Performance tips
172
+
173
+ There tends to be a lot of interaction in an application that contains
174
+ slicer objects. Therefore, performance matters to realize a smooth user
175
+ experience. Here are some tips to help with that:
176
+
177
+ * Most importantly, when running the server in debug mode, consider setting
178
+ ` dev_tools_props_check=False ` .
179
+ * Also consider creating the ` Dash ` application with ` update_title=None ` .
180
+ * Setting ` reverse_y ` to False negatively affects performance. This will be
181
+ fixed in a future version of Plotly/Dash.
182
+ * For a smooth experience, avoid triggering unnecessary figure updates.
183
+ * When adding a callback that uses the slicer position, use the (rate limited)
184
+ ` state ` store rather than the slider value.
185
+
0 commit comments