laysent / ts-graphviz

Simple Graphviz library for TypeScript.

Home Page:https://kamiazya.github.io/ts-graphviz/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub Action npm version License: MIT code style: prettier Maintainability Test Coverage

ts-graphviz

Graphviz library for TypeScript.

Key Feature

  • Export Dot language.
  • Support Node.js and Browser.
    • UMD, ESM, CommonJS
  • No dependency.

Installation

The plugin can then be installed using npm:

NPM

Package manager

# yarn
yarn add ts-graphviz
# or npm
npm install ts-graphviz

Browser

<script src="//unpkg.com/ts-graphviz/lib/bundle.min.js"></script>

Usage

Script

import { digraph } from 'ts-graphviz';

const g = digraph('G');

const subgraphA = g.createSubgraph('A');
const nodeA1 = subgraphA.createNode('A_node1');
const nodeA2 = subgraphA.createNode('A_node2');
subgraphA.createEdge(nodeA1, nodeA2);

const subgraphB = g.createSubgraph('B');
const nodeB1 = subgraphB.createNode('B_node1');
const nodeB2 = subgraphB.createNode('B_node2');
subgraphA.createEdge(nodeB1, nodeB2);

const node1 = g.createNode('node1');
const node2 = g.createNode('node2');
g.createEdge(node1, node2);
const dot = g.toDot();
console.log(dot);

Callback style API

import { digraph } from 'ts-graphviz';

const G = digraph('G', g => {
  g.subgraph('A', A => {
    const node1 = A.node('A_node1');
    const node2 = A.node('A_node2');
    A.edge([node1, node2]);
  });
  g.subgraph('B', B => {
    const node1 = B.node('B_node1');
    const node2 = B.node('B_node2');
    B.edge([node1, node2]);
  });
  g.edge(['node1', 'node2']);
});
const dot = G.toDot();
console.log(dot);

Output

digraph "G" {
  "node1";
  "node2";
  subgraph "A" {
    "A_node1";
    "A_node2";
    "A_node1" -> "A_node2";
  }
  subgraph "B" {
    "B_node1";
    "B_node2";
    "B_node1" -> "B_node2";
  }
  "node1" -> "node2";
}

See Also

Graphviz-dot Test and Integration

  • jest-graphviz
    • Jest matchers that supports graphviz integration.
  • setup-graphviz
    • GitHub Action to set up Graphviz cross-platform(Linux, macOS, Windows).

License

This software is released under the MIT License, see LICENSE.

Author

kamiazya(Yuki Yamazaki)

ko-fi

About

Simple Graphviz library for TypeScript.

https://kamiazya.github.io/ts-graphviz/

License:MIT License


Languages

Language:TypeScript 99.6%Language:JavaScript 0.4%