2020-05-17 17:17:39 +02:00
|
|
|
# @sapphirecode/graphviz-builder
|
|
|
|
|
2020-06-05 11:46:58 +02:00
|
|
|
version: 1.2.x
|
2020-05-17 17:17:39 +02:00
|
|
|
|
|
|
|
constructing graphviz files using an easy typescript interface
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
npm:
|
|
|
|
|
|
|
|
> npm i --save @sapphirecode/graphviz-builder
|
|
|
|
|
|
|
|
yarn:
|
|
|
|
|
2020-05-17 17:53:01 +02:00
|
|
|
> yarn add @sapphirecode/graphviz-builder
|
2020-05-17 17:17:39 +02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2020-05-17 17:53:01 +02:00
|
|
|
### Object structure
|
|
|
|
|
|
|
|
```js
|
|
|
|
import {Graph,Color} from '@sapphirecode/graphviz-builder';
|
|
|
|
|
|
|
|
// create a new graph
|
|
|
|
const g = new Graph('foo');
|
|
|
|
|
|
|
|
// add a node to the graph
|
|
|
|
// this function returns the full name of the node that's later used for creating edges
|
|
|
|
const bar = g.add_node('bar');
|
|
|
|
|
|
|
|
// if you want to specify attributes
|
|
|
|
const baz = g.add_node(n => {
|
|
|
|
n.name = 'baz';
|
|
|
|
n.label = 'node baz';
|
|
|
|
n.color = Color.red;
|
|
|
|
});
|
|
|
|
|
|
|
|
// connect nodes
|
|
|
|
g.add_edge(bar, baz);
|
|
|
|
|
|
|
|
// add a subgraph
|
|
|
|
g.add_graph(sg=>{
|
|
|
|
sg.name = 'subgraph';
|
|
|
|
|
|
|
|
sg.add_node('foo');
|
|
|
|
})
|
|
|
|
```
|
2020-05-17 17:17:39 +02:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
MIT © Timo Hocker <timo@scode.ovh>
|