Nasdankia provides two Maven modules for working with Drawio diagrams - API and Model. The modules require Java 17 or above.
Drawio module provides Java API for reading and manipulating Drawio diagrams. It is built on top of Graph.
The module provides the following interfaces representing elements of a diagram file:
The below diagram shows relationships between the above interfaces including their super-interfaces:
Util provides utility methods such as layout()
and methods to navigate and query documents and their elements.
Nasdanika Drawio API extends the concept of linking to pages to cross-document linking to pages and page elements by name or ID. Link targets (pages or elements) are available via getLinkTarget()
method.
Drawio page links have the following format: data:page/id,<page id>
with page/id
being the “media type” and <page id>
being the “data” of a Data URL.
Nasdanika Drawio API extends it to additional media types:
page/name
element/id
element/name
The data (selector) format has the following format:
[<diagram resource>#]<page selector>
[<diagram resource>#][<page selector>/]<element selector>]
id,<page id>
name,<URL encoded page name>
For elements URL’s page selector is required if diagram resource URI is present.
Examples:
data:page/name,compressed.drawio#Page-1
- Link to compressed first pagedata:page/name,compressed.drawio#Page+2
- Link to compressed second pagedata:element/id,7KSC1_O8d7ACaxm1iSCq-1
- Link by ID to an element on the same pagedata:element/name,name,Page+2/Linked
- Link by name to Linked on Page 2 referenced by namedata:element/name,compressed.drawio#name,Page+2/Linked
- Link to Linked on compressed second pageThis approach allows to create a multi-resource graph of diagrams. Nasdanika Drawio API also supports loading of documents from arbitrary URI’s using a URI resolver. For example, maven://<gav>/<resource path>
to load from Maven resources or gitlab://<project>/<path>
to load resources from GitLab without cloning a repository, provided there is a handler (Function<URI,InputStream>
) supporting the aforementioned URI’s.
With Nasdanika CLI drawio > html-app > site command pipeline can be used to generate documentation web sites from Drawio diagrams:
With Nasdanika Drawio API and other products you can make your diagrams executable as explained in the following sections.
You may set diagram element properties to URIs of processors. This approach is explained in General Purpose Executable Graphs and Diagrams Medium story. A demo repository is here - https://github.com/Nasdanika-Demos/executable-diagram-dynamic-proxy. You can use this site/ repository as a starting point for your diagramming ecosystem:
You can create graph element processors for diagram elements in Java.
Executable (computational) graphs & diagrams story provides a high level overview of executable graphs and diagrams. Graph documentation features more technical details and code samples. Compute Graph Demo provides examples of this and semantic mapping (below) approaches using the compute graph from the “Executable (computational) graphs & diagrams” story.
Drawio Model module provides an EMF Ecore model for diagrams. A model instance can be obtained from the API document by calling Document.toModelDocument()
method.
The model makes it more convenient to work with the diagram elements by: