Skip to content

Commit e2b2e83

Browse files
authored
Some more doc tweaks (#38)
* Tweak docs a bit * Woops, forgot to add this in previous pr :/ * update readme
1 parent 81d0c80 commit e2b2e83

File tree

3 files changed

+75
-38
lines changed

3 files changed

+75
-38
lines changed

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,29 @@ import dash_html_components as html
2828
from dash_slicer import VolumeSlicer
2929
import imageio
3030

31-
app = dash.Dash(__name__)
31+
app = dash.Dash(__name__, update_title=None)
3232

3333
vol = imageio.volread("imageio:stent.npz")
3434
slicer = VolumeSlicer(app, vol)
35+
3536
app.layout = html.Div([slicer.graph, slicer.slider, *slicer.stores])
3637

3738
if __name__ == "__main__":
38-
app.run_server()
39+
app.run_server(debug=True, dev_tools_props_check=False)
3940
```
4041

4142

4243
## License
4344

44-
This code is distributed under MIT license.
45+
This code is distributed under the MIT license.
4546

4647

4748
## Developers
4849

4950

5051
* Make sure that you have Python with the appropriate dependencies installed, e.g. via `venv`.
5152
* Run `pip install -e .` to do an in-place install of the package.
52-
* Run the examples using e.g. `python examples/slicer_with_1_view.py`
53+
* Run the examples using e.g. `python examples/all_features.py`
5354

5455
* Use `black .` to autoformat.
5556
* Use `flake8 .` to lint.
@@ -74,26 +75,26 @@ instantiation one can provide the following parameters:
7475
* `volume` (`ndarray`): the 3D numpy array to slice through. The dimensions
7576
are assumed to be in zyx order. If this is not the case, you can
7677
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
78+
* `spacing` (tuple of `float`): the distance between voxels for each
79+
dimension (zyx). The spacing and origin are applied to make the slice
7980
drawn in "scene space" rather than "voxel space".
80-
* `origin` (tuple of `float`): The offset for each dimension (zyx).
81+
* `origin` (tuple of `float`): the offset for each dimension (zyx).
8182
* `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+
* `reverse_y` (`bool`): whether to reverse the y-axis, so that the origin of
8384
the slice is in the top-left, rather than bottom-left. Default True.
84-
Note: setting this to False affects performance, see #12.
85+
Note: setting this to False affects performance, see #12. This has been
86+
fixed, but the fix has not yet been released with Dash.
8587
* `scene_id` (`str`): the scene that this slicer is part of. Slicers
8688
that have the same scene-id show each-other's positions with
8789
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
90+
* `color` (`str`): the color for this slicer. By default the color
91+
is a shade of blue, orange, or green, depending on the axis. Set
92+
to empty string to prevent drawing indicators for this slicer.
93+
* `thumbnail` (`int` or `bool`): the preferred size of low-resolution data
94+
to be uploaded to the client. If `False`, the full-resolution data are
95+
uploaded client-side. If `True` (default), a default value of 32 is used.
96+
97+
Note that this is not a Dash Component. The components that make
9798
up the slicer (and which must be present in the layout) are:
9899
`slicer.graph`, `slicer.slider`, and `slicer.stores`.
99100

@@ -104,7 +105,7 @@ can be used as output for `slicer.overlay_data`. The color
104105
can be a hex color or an rgb/rgba tuple. Alternatively, color
105106
can be a list of such colors, defining a colormap.
106107

107-
**property `VolumeSlicer.axis`** (`int`): The axis at which the slicer is slicing.
108+
**property `VolumeSlicer.axis`** (`int`): The axis to slice.
108109

109110
**property `VolumeSlicer.graph`**: The `dcc.Graph` for this slicer. Use `graph.figure` to access the
110111
Plotly Figure object.
@@ -171,8 +172,8 @@ To apply the position for one dimension only, use e.g `(None, None, x)`.
171172
### Performance tips
172173

173174
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:
175+
slicer objects. To realize a smooth user experience, performance matters.
176+
Here are some tips to help with that:
176177

177178
* Most importantly, when running the server in debug mode, consider setting
178179
`dev_tools_props_check=False`.

dash_slicer/slicer.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
### Performance tips
3333
3434
There tends to be a lot of interaction in an application that contains
35-
slicer objects. Therefore, performance matters to realize a smooth user
36-
experience. Here are some tips to help with that:
35+
slicer objects. To realize a smooth user experience, performance matters.
36+
Here are some tips to help with that:
3737
3838
* Most importantly, when running the server in debug mode, consider setting
3939
`dev_tools_props_check=False`.
@@ -69,26 +69,26 @@ class VolumeSlicer:
6969
* `volume` (`ndarray`): the 3D numpy array to slice through. The dimensions
7070
are assumed to be in zyx order. If this is not the case, you can
7171
use `np.swapaxes` to make it so.
72-
* `spacing` (tuple of `float`): The distance between voxels for each
73-
dimension (zyx).The spacing and origin are applied to make the slice
72+
* `spacing` (tuple of `float`): the distance between voxels for each
73+
dimension (zyx). The spacing and origin are applied to make the slice
7474
drawn in "scene space" rather than "voxel space".
75-
* `origin` (tuple of `float`): The offset for each dimension (zyx).
75+
* `origin` (tuple of `float`): the offset for each dimension (zyx).
7676
* `axis` (`int`): the dimension to slice in. Default 0.
77-
* `reverse_y` (`bool`): Whether to reverse the y-axis, so that the origin of
77+
* `reverse_y` (`bool`): whether to reverse the y-axis, so that the origin of
7878
the slice is in the top-left, rather than bottom-left. Default True.
79-
Note: setting this to False affects performance, see #12.
79+
Note: setting this to False affects performance, see #12. This has been
80+
fixed, but the fix has not yet been released with Dash.
8081
* `scene_id` (`str`): the scene that this slicer is part of. Slicers
8182
that have the same scene-id show each-other's positions with
8283
line indicators. By default this is derived from `id(volume)`.
83-
* `color` (`str`): the color for this slicer. By default the color is
84-
red, green, or blue, depending on the axis. Set to empty string
85-
for "no color".
86-
* `thumbnail` (`int` or `bool`): preferred size of low-resolution data to be
87-
uploaded to the client. If `False`, the full-resolution data are
88-
uploaded client-side. If `True` (default), a default value of 32 is
89-
used.
90-
91-
Note that this is not a Dash component. The components that make
84+
* `color` (`str`): the color for this slicer. By default the color
85+
is a shade of blue, orange, or green, depending on the axis. Set
86+
to empty string to prevent drawing indicators for this slicer.
87+
* `thumbnail` (`int` or `bool`): the preferred size of low-resolution data
88+
to be uploaded to the client. If `False`, the full-resolution data are
89+
uploaded client-side. If `True` (default), a default value of 32 is used.
90+
91+
Note that this is not a Dash Component. The components that make
9292
up the slicer (and which must be present in the layout) are:
9393
`slicer.graph`, `slicer.slider`, and `slicer.stores`.
9494
"""
@@ -189,7 +189,7 @@ def scene_id(self) -> str:
189189

190190
@property
191191
def axis(self) -> int:
192-
"""The axis at which the slicer is slicing."""
192+
"""The axis to slice."""
193193
return self._axis
194194

195195
@property

update_docs_in_readme.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Run this script to update the README.md with tha current reference docs.
4+
"""
5+
6+
import os
7+
from dash_slicer.docs import get_reference_docs
8+
9+
10+
HERE = os.path.dirname(os.path.abspath(__file__))
11+
12+
13+
def write_reference_docs():
14+
"""Write the reference docs to the README."""
15+
# Prepare
16+
header = "## Reference"
17+
filename = os.path.join(HERE, "README.md")
18+
assert os.path.isfile(filename), "README.md not found"
19+
# Load first part of the readme
20+
with open(filename, "rb") as f:
21+
text = f.read().decode()
22+
text1, _, _ = text.partition(header)
23+
text1 = text1.strip()
24+
# Create second part of the readme
25+
text2 = "\n\n\n" + header + "\n\n" + get_reference_docs()
26+
if "\r" in text1:
27+
text2 = text2.replace("\n", "\r\n")
28+
# Wite
29+
with open(filename, "wb") as f:
30+
f.write(text1.encode())
31+
f.write(text2.encode())
32+
print("Updated the reference docs in README.md")
33+
34+
35+
if __name__ == "__main__":
36+
write_reference_docs()

0 commit comments

Comments
 (0)