Skip to content

Commit ad6736a

Browse files
authored
Merge pull request #60 from CopyDemon/issue-59-update-documentation-how-to-use-send-back-diagram-image
Issue 59 update documentation how to use send back diagram image
2 parents 042f565 + 3b61af8 commit ad6736a

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

Diff for: docs/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
README for IDAES-UI docs
2+
=========================
3+
4+
5+
### Merge and build
6+
* When merging changes to IDAES-UI, the CI will automatically run and build the documentation to the online server.
7+
8+
### Run as developer
9+
```bash
10+
# Change to the docs directory
11+
12+
# Install the required packages
13+
pip install -r requirements.txt
14+
15+
# Install sphinx-autobuild
16+
# This is necessary for building a local development server to view live changes.
17+
pip install sphinx-autobuild
18+
19+
# Run the live server using Sphinx-autobuild.
20+
sphinx-autobuild . _build/html
21+
```

Diff for: docs/README.txt

-4
This file was deleted.
Binary file not shown.

Diff for: docs/user/fv/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tasks with the {{ visabbr }}.
1212

1313
* [Flowsheet Visualizer Concepts](fv-concepts)
1414
* [Flowsheet Visualizer How-to](fv-howto)
15+
* [Save and Preview Diagram](save-preview-diagram)
1516

1617
```{toctree}
1718
:hidden: true

Diff for: docs/user/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ If you wish to develop or extend IDAES UIs, please also see the [developer docum
1111

1212
* [Installation](installation)
1313
* [{{vistitle}}](fv_main_page)
14+
* [Save and Preview Diagram](save_diagram)
1415

1516
```{toctree}
1617
---
1718
hidden: true
1819
---
1920
install
2021
fv/index
22+
save-diagram/index
2123
```

Diff for: docs/user/save-diagram/index.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(save-preview-diagram)=
2+
# Save and Preview Flowsheet Diagram
3+
4+
### Overview:
5+
IDAES UI allows you to preview your flowsheet diagram at any time while working on it by calling `export_flowsheet_diagram`.
6+
7+
### Usage:
8+
The export_flowsheet_diagram function is used to return the current view of the flowsheet diagram at any time after you have initialized your model.
9+
* It can save the diagram to your preferred path or the default path.
10+
* It can display the current view of the flowsheet diagram in a Jupyter Notebook.
11+
12+
### Parameters:
13+
`export_flowsheet_diagram` takes three parameters:
14+
* `flowsheet`: The flowsheet object
15+
* `name`: The diagram filename or full path where you prefer to save the diagram. The output format is determined by the file extension (".svg" for SVG and ".png" for PNG).
16+
* `display`: Boolean, to determent if you want to review current flowsheet in jupyter notebook
17+
18+
#### Let's go over it step by step.
19+
1. Import `export_flowsheet_diagram` function from `idaes_ui` package
20+
```python
21+
from idaes_ui.fv.fsvis import export_flowsheet_diagram
22+
```
23+
2. Create your model. Here we assume the model is called `m` and
24+
the top-level flowsheet that you want to view is `m.fs`.
25+
26+
3. After initializing your model, you should have `m.fs`.
27+
Then, you can call `export_flowsheet_diagram`.
28+
```python
29+
export_flowsheet_diagram(m.fs, '~/Download/my_flowsheet_diagram.svg', display=True)
30+
```
31+
32+
4. Then, you can see the flowsheet diagram's saved path in the log.
33+
34+
### View flowsheet diagram
35+
1. To view the image, after calling `export_flowsheet_diagram`, you can visit the path shown in the log.
36+
2. To view the flowsheet diagram in a Jupyter Notebook, set `display=True`. This will automatically display the flowsheet diagram in the notebook.
37+
38+
### Demo
39+
```{video} /static/save_diagram/videos/demo_video_export_flowsheet_diagram.mp4
40+
:width: 800
41+
:nocontrols:
42+
:autoplay: true
43+
:loop:
44+
```

Diff for: idaes_ui/fv/fsvis.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ def _init_logging(lvl):
269269
ui_logger.setLevel(lvl)
270270

271271

272-
def export_flowsheet_diagram(flowsheet, name: Union[str, Path]) -> Path:
272+
def export_flowsheet_diagram(
273+
flowsheet, name: Union[str, Path], display: bool = False
274+
) -> Path:
273275
"""Export the flowsheet as a diagram.
274276
275277
Some example invocations (flowsheet is in `m.fs`)::
@@ -322,13 +324,13 @@ def export_flowsheet_diagram(flowsheet, name: Union[str, Path]) -> Path:
322324
try:
323325
d.mkdir(parents=True, exist_ok=True)
324326
except Exception as err:
325-
raise IOError(f"Cannot make directory {d}: {err}")
327+
raise IOError(f"Cannot make directory {d}: {err}") from err
326328
if imtype not in ("svg", "png"):
327329
raise ValueError(f"File extension must be '.svg' or '.png' (got: '.{imtype}')")
328330
r = visualize(flowsheet, basename, browser=False).save_diagram(
329331
screenshot_name=basename,
330332
screenshot_save_to=str(d),
331333
image_type=imtype,
332-
display=False,
334+
display=display,
333335
)
334336
return Path(r["diagram_saved_path"])

0 commit comments

Comments
 (0)