Skip to content

Commit

Permalink
Added/improved description of scripted diagrams (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mprinkezs authored Dec 19, 2024
1 parent 4e56674 commit f1e9d6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
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

0 comments on commit f1e9d6f

Please sign in to comment.