# Diagrams
import OpenCode from '../../src/components/OpenCode.tsx';
## Overview
Diagrams-as-code.
Allows using syntax for multiple visualization libraries inside HTML to produce diagrams.
The rendered diagrams are added to the [result page](../features/result.html.md) as either:
- SVG elements (which you can style with CSS or manipulate with JavaScript)
- HTML images (which you can right-click and save or open in a new window)
Diagrams from multiple libraries can be used in the same page. Only the libraries used will be loaded in the LiveCodes playground. The result page will have no libraries (only the output SVG or images).
Open starter template in LiveCodes
## Usage
This code: ()
```html
```
produces this output:

Steps
#### 1. Add a diagram target:
The target element should have a `data-src` attribute.
It can be an HTML element (the SVG of the diagram will be embedded as a child element)
```html
```
becomes
```html
```
or an HTML image element (the diagram will be added to its `src` attribute as a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs))
```html
```
becomes
```html
```
There can be more that one target element for the same diagram if they have the same `data-src` attribute.
```html
```
#### 2. Add a script element with the diagram syntax:
It should have:
- an attribute `type="application/diagram-{diagram type}"` that specifies the diagram type (e.g. `type="application/diagram-mermaid"`).
- a `data-output` attribute that matches the `data-src` attribute of the target element.
- the syntax of the diagram is the content of the script element or the content of a file linked by the `src` attribute.
```html
```
## Supported Libraries
### [Cytoscape](https://js.cytoscape.org/)
The diagram syntax is JSON representing [Cytoscape options](https://js.cytoscape.org/#getting-started/specifying-basic-options).
Please note that reference to JavaScript objects cannot be used. e.g. do not use `{container: document.getElementById('cy')}`.
Example: ()
```html
```
### [ELK](https://www.eclipse.org/elk/)
Diagram layout is produced using [elkjs](https://github.com/kieler/elkjs) and rendered using [elkjs-svg](https://github.com/EmilStenstrom/elkjs-svg).
The syntax used is [ELK JSON](https://www.eclipse.org/elk/documentation/tooldevelopers/graphdatastructure/jsonformat.html) format. ELK text format is not supported! (You may use [this tool](https://rtsys.informatik.uni-kiel.de/elklive/conversion.html) to convert formats)
Example: ()
```html
```
### [Gnuplot](http://www.gnuplot.info/)
using [gnuplot-JS](https://github.com/chhu/gnuplot-JS)
Instead of using `data-output` attribute in the [script element](#2-add-a-script-element-with-the-diagram-syntax), the statement `set output` is used in the diagram syntax (see highlighted lines below).
Data files are also specified in the diagram syntax (see highlighted lines below).
They are defined in script elements with the attribute `type="application/diagram-gnuplot-file"`. The file name is specified in `data-file` attribute and either have inline content or linked to with a `src` attribute.
Example: ()
```html {4,22}
```
### [Graphviz](https://graphviz.org/)
using [@hpcc-js/wasm](https://github.com/hpcc-systems/hpcc-js-wasm)
The following [layout engines](https://graphviz.org/docs/layouts/) are supported:
- dot
- neato
- fdp
- sfdp
- circo
- twopi
- osage
- patchwork
By default, the `dot` layout engine is used. To use a different engine add the attribute `data-layout` to the [script element](#2-add-a-script-element-with-the-diagram-syntax) with the value of the required engine name, like this:
```html
```
Example: ()
```html
```
### [Mermaid](https://mermaid-js.github.io/mermaid/)
Example: ()
```html
```
### [Nomnoml](https://nomnoml.com/)
Example: ()
```html
```
### [Pintora](https://pintorajs.vercel.app/)
[Pintora config](https://pintorajs.vercel.app/docs/configuration/config) object can be specified in [custom settings](../advanced/custom-settings.html.md), under the key `pintora`.
Example Custom Settings:
```json
{
"pintora": {
"themeConfig": {
"theme": "dark"
}
}
}
```
Example: ()
```html
```
### [Plotly](https://plotly.com/graphing-libraries/)
The diagram syntax is a JSON object with `data` and `layout` properties (see [Plotly reference](https://plotly.com/javascript/reference/index/)).
Please note that the output is a non-interactive SVG element or image. The plotly library is not loaded in the result page, so any JavaScript functionality is not available.
Example: ()
```html
```
### [Svgbob](https://github.com/ivanceras/svgbob)
Example: ()
```html
```
### [Vega](https://vega.github.io/vega/)
The diagram syntax is [Vega JSON specification](https://vega.github.io/vega/docs/#specification).
Please note that the output is a non-interactive SVG element or image. The Vega library is not loaded in the result page, so any JavaScript functionality is not available.
Example: ()
```html
```
### [VegaLite](https://vega.github.io/vega-lite/)
The diagram syntax is [Vega-Lite View JSON Specification](https://vega.github.io/vega-lite/docs/spec.html).
Please note that the output is a non-interactive SVG element or image. The Vega-Lite library is not loaded in the result page, so any JavaScript functionality is not available.
Example: ()
```html
```
### [WaveDrom](https://wavedrom.com/)
The diagram syntax is [WaveJSON](https://wavedrom.com/tutorial.html) format.
Example: ()
```html
```