Skip to content
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

Added/improved description of scripted diagrams #243

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docs
on: [pull_request, workflow_dispatch]
on: [push, pull_request, workflow_dispatch]
jobs:
docs:
runs-on: ubuntu-latest
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 29 additions & 3 deletions doc/howtos/using_scripted_diagrams/using_scripted_diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ You can use multiple scripted diagrams at the same time, which will be stacked v

The concept of scripted diagrams builds upon [scripted elements](../scripted_elements/scripted_elements_introduction.md) and [services](../using_services/using_services.md). [Tokens on scripted elements](../scripted_elements/tokens_on_scripted_elements.md) are used to convey data to the diagram service.

![Scripted diagrams relations](assets/scripted_diagrams_relations.png)

Each diagram service combines data from one or more scripted elements to create a single scripted diagram.

## Usage

### 1. Create or modify scripted elements to contribute data to a scripted diagram
Expand Down Expand Up @@ -52,6 +56,28 @@ See <a href="../using_services/using_services.html#service-definition">Using ser
* The service function name must be the same as set in the scripted elements' `"ude_diagram_service"` parameter.
```

#### Diagram service function description

The scripted diagram's service function implementation must adhere to the following interface description:

```{py:function} <function name>(view, element_data): str

Create an SVG diagram based on scripted elements' context data
:param dict view: ZEISS INSPECT 'Inspection Details' canvas properties
- 'width': (int) Canvas width in pixels
- 'height': (int) Canvas height in pixels
- 'dpi': (float) Canvas resolution in dpi
- 'font': (int) Default font size in pt
:param list[dict1, dict2, ..., dictN] element_data: List of dictionaries containing scripted element references and context data
- 'element': (object) Element reference
- 'data': (dict) Context data of the scripted element
- 'type': (str) Element type (always 'SVGDiagram')
:return: SVG diagram
:rtype: str
```

#### Template

The following script serves as a minimum template for a scripted diagram service:
```{code-block} python
:caption: Scripted diagram service template
Expand All @@ -69,15 +95,15 @@ def diagram_service_template(view, element_data)->str:
mpltools.setup_plot(plt, view)

for e in element_data:
# Read the the current element
# Read element reference
element = e['element']

# Read all parameters received from mapped scripted element
# Read scripted element's context data
data = e['data']

# Create your diagram
# Example:
# plt.plot ([element.name], [data['ude_diagram_radius']], 'bx')
plt.plot ([element.name], [data['ude_diagram_radius']], 'bx')

return mpltools.create_svg(plt, view)

Expand Down
Loading