Resources¶
Resources are the primary mechanism for defining inputs and outputs in Ocelescope plugins.
A resource can represent almost anything — from process models to tabular datasets.
Resources are automatically uploadable and downloadable, making them easy to share across plugin methods and even between different plugins.
Defining a Resource¶
To create a custom resource:
- Define a Python class that inherits from
Resource
(provided by theocelescope
package). - Resource classes can include any number of properties and methods required by your plugin.
- Metadata such as
label
anddescription
can be added to improve how the resource appears in the frontend. - Resources can be shared across plugins if they have the same class name and field definitions.
Example: Defining a Resource | |
---|---|
Resources Must Be JSON-Serializable
For import and export to work, resources must be serializable and instantiable from their serialized form.
Fields should use standard types such as str
, int
, float
, bool
, list
, or dict
, or any custom subclass that is itself serializable.
To verify that your resource is serializable, try creating an instance from its own serialized output:
Visualization¶
Visualizations in Ocelescope allow resources to render themselves in the frontend using predefined visualization types such as graphs, SVGs, and tables.
To enable visualization for a resource, implement the visualize()
method in your Resource
subclass. This method should return one of the supported visualization objects described below.
Supported Visualization Types¶
Graph¶
A graph composed of nodes and edges. Commonly used for Petri nets, directly-follows graphs, and other graph-based models.
- Classes:
Graph
,GraphNode
,GraphEdge
,GraphvizLayoutConfig
- Layout: Controlled by Graphviz engines and attributes (
GraphvizLayoutConfig
)
GraphNode¶
Defines a visual node in the graph.
Field | Type | Description |
---|---|---|
id | str | Unique node ID |
label | Optional[str] | Display label |
shape | Literal["circle","triangle","rectangle","diamond","hexagon"] | Node shape |
width , height | Optional[float] | Dimensions in pixels |
color | Optional[str] | Fill color (hex or named) |
x , y | Optional[float] | Coordinates after layout (auto-set) |
border_color | Optional[str] | Border/stroke color |
label_pos | Optional[Literal["top","center","bottom"]] | Label position |
GraphEdge¶
Represents a directed connection between nodes.
Field | Type | Description |
---|---|---|
source | str | Source node ID |
target | str | Target node ID |
arrows | tuple[EdgeArrow, EdgeArrow] | Arrowheads at start/end (e.g., (None, "triangle") ) |
color | Optional[str] | Edge color |
label | Optional[str] | Label text |
GraphvizLayoutConfig¶
Specifies layout settings passed to Graphviz.
Field | Type | Description | |||
---|---|---|---|---|---|
engine | GraphVizLayoutingEngine | Graphviz engine (dot , neato , fdp , sfdp , etc.) | |||
graphAttrs | `dict[str, str | int | float | bool]` | Attributes applied to the whole graph (e.g., rankdir , size ) |
nodeAttrs | `dict[str, str | int | float | bool]` | Default attributes for all nodes (e.g., shape , color ) |
edgeAttrs | `dict[str, str | int | float | bool]` | Default attributes for all edges (e.g., arrowsize , color ) |
Example Usage¶
Graphviz will apply the chosen engine and attributes to determine positions (x
, y
) and dimensions (width
, height
) automatically.
SVG¶
Use raw SVG markup when a graph-based layout is not appropriate, or when you need full control over visuals.
- Class:
SVGVis
- Use case: Custom layouts, charts, icons, or any visualization expressible as SVG.
Example
Table¶
A structured table with typed columns and customizable rows. Ideal for datasets, summaries, or event logs.
- Class:
Table
- Column Class:
TableColumn
- Supported Column Types:
string
,number
,boolean
,date
,datetime
The table supports sorting, hiding, and formatting options for each column.
For advanced use cases, you can contribute your own visualization types to the Ocelescope framework
Dot¶
A raw Graphviz DOT visualization, preserving the full DOT source string. Useful when you want direct control over Graphviz rendering or need to reuse an existing DOT description.
- Class:
DotVis
- Layout: Explicitly set by Graphviz via a chosen layout engine (
dot
,neato
,fdp
, etc.)
DotVis¶
Field | Type | Description |
---|---|---|
type | Literal["dot"] | Identifies the visualization type as DOT |
dot_str | str | The raw DOT source string (as produced by graphviz.Digraph or Graph ) |
layout_engine | GraphVizLayoutingEngine | The Graphviz engine used (dot , neato , fdp , sfdp , circo , etc.) |
Supported Layout Engines¶
Engine | Description |
---|---|
dot | Hierarchical layouts, suited for layered graphs and flowcharts |
neato | Spring-model layouts, good for undirected graphs |
fdp | Force-directed placement, similar to neato |
sfdp | Scalable force-directed placement for large graphs |
circo | Circular layouts |
twopi | Radial layouts (nodes placed in concentric circles) |
osage | Clustered layouts |
patchwork | Treemap-style layouts |
nop , nop2 | No-op layout engines (use raw input positions if given) |
Constructing from Graphviz¶
Use .from_graphviz()
to convert an existing graphviz.Digraph
or graphviz.Graph
object into a DotVis
.
The resulting DotVis
object carries both the DOT source (dot_str
) and the layout engine specification, allowing full control over Graphviz rendering.