ts-graphviz / deno

🦕 Simple Graphviz library for Deno.

Home Page:https://deno.land/x/graphviz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


This project has been merged into ts-graphviz.


tag deno-ci deno doc License: MIT PRs Welcome tag nest badge

graphviz

Graphviz library for Deno🦕

Runtime independent APIs and specifications are compatible with the ts-graphviz package.

Usages

Draw diagrams

renderDot function outputs the dot command execution result to the specified path by supplying diagram object.

renderDot function requires allow-write, allow-run permission, and dot command.

import * as path from "https://deno.land/std@0.67.0/path/mod.ts";
import {
  attribute,
  digraph,
  renderDot,
} from "https://deno.land/x/graphviz/mod.ts";

const G = digraph("G", (g) => {
  const a = g.node("aa");
  const b = g.node("bb");
  const c = g.node("cc");
  g.edge([a, b, c], {
    [attribute.color]: "red",
  });
  g.subgraph("A", (A) => {
    const Aa = A.node("Aaa", {
      [attribute.color]: "pink",
    });
    const Ab = A.node("Abb", {
      [attribute.color]: "violet",
    });
    const Ac = A.node("Acc");
    A.edge([Aa.port({ compass: "c" }), Ab, Ac, "E"], {
      [attribute.color]: "red",
    });
  });
});

const __dirname = new URL(".", import.meta.url).pathname;
await renderDot(G, path.resolve(__dirname, "./example.svg"), {
  format: "svg",
});

Parse DOT Language

The https://deno.land/x/graphviz/perser/mod.ts provide parse function that parses a string written in dot language and convert it to a model.

The return value is a Graph or Digraph that inherits from RootCluster.

import { parse } from "https://deno.land/x/graphviz/perser/mod.ts";

const G = parse(`
  digraph G {
    a -> b;
  }
`);

This is equivalent to the code below.

import { digraph } from "https://deno.land/x/graphviz/mod.ts";

const G = digraph("G", (g) => {
  g.edge(["a", "b"]);
});

The "https://deno.land/x/graphviz/mod.ts" module also provides other features such as handling AST.

This module is a translation of @ts-graphviz/parser to work with the Deno runtime.

Please refer to the repository for details of the provided API.

License

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

About

🦕 Simple Graphviz library for Deno.

https://deno.land/x/graphviz

License:MIT License


Languages

Language:TypeScript 99.6%Language:Makefile 0.4%