Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphviz-cli

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphviz-cli

Command-line tool for generating graph images from Graphviz source scripts.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.9K
increased by44.79%
Maintainers
1
Weekly downloads
 
Created
Source

graphviz-cli

npm codecov codebeat badge Dependency status

Command-line tool and API for generating graph images from Graphviz source scripts.

Features:

  • Runs in pure JavaScript. Except for the png output.
  • No need to install the native Graphviz package.
  • Most output formats of the native Graphviz (inluding svg and png) available.
  • TypeScript type declarations (typings) for the API.
  • A lot faster then calling dot as a separate process.

Uses @aduh95/viz.js to render Graphviz scripts in pure JavaScript by WASM. Uses node-canvas for the optional png output.

Related tools:

Synopsis

graphviz -Tsvg -ohello.svg hello.dot
import { renderGraphFromSource } from 'graphviz-cli'
// Render a string with the graph script to a string with the SVG output.
const svg = await renderGraphFromSource({ input: 'graph G { ... }' }, { format: 'svg' })
// Render a file with a graph script to a file with the PNG output.
await renderGraphFromSource({ name: 'hello.dot' }, { format: 'png', name: 'hello.png' })

Installation

Make sure that you have installed Node.js 14.8 or newer.

If you want to use the command-line tool, install this package globally using your favourite package manager (NPM, Yarn or PNPM):

npm i -g graphviz-cli
yarn global add graphviz-cli
pnpm i -g graphviz-cli

If you want to use this package programmatically, install it locally using your favourite package manager. Add -D on the command line if you need the tool only to build you package:

npm i graphviz-cli
yarn add graphviz-cli
pnpm i graphviz-cli

If you want to render graphs to png, install the node-canvas module in addition. Add -g/global or -D arguments according to you choice above:

npm i canvas
yarn add canvas
pnpm i canvas

Starting from the version 2.0.0, node-canvas is not a peer dependency any more, because NPM installs the peer dependencies automatically, making them not optional any more.

Command-line

Command-line parameters are the same as for the dot tool from the Graphviz package, as long as they are implemented, of course.

$ graphviz -?

Generates graph images from Graphviz source scripts.

Usage: graphviz [-Vvy?] [-(KTon)<value>] <dot files>

Options:
  -Tv           - set output format to 'v'
  -Kv           - set layout engine to 'v' (overrides source script)
  -ofile        - write output to 'file'
  -O            - automatically generate an output filename based on the input
                  filename with a .'format' appended. (Causes all -ofile
                  options to be ignored.)
  -y            - invert y coordinate in output
  -n[v]         - no layout mode 'v' (=1)
  -v            - enable verbose mode
  -V            - print version and exit
  -?            - print usage and exit

Examples:
  graphviz -Tsvg -O diagrams/*.dot
  graphviz -Tpng -Kneato -odiagram.png diagram.dot

API

renderGraphFromSource(source: object, options: object): Promise<string | Buffer>

Renders a graph script to a specified output. If the output format is binary (png, for example), the Promise will contain Buffer instead of string.

import { renderGraphFromSource } from 'graphviz-cli'
// Render a string with the graph script to a string with the SVG output.
const svg = await renderGraphFromSource({ input: 'graph G { ... }' }, { format: 'svg' })
// Render a file with a graph script to a file with the PNG output.
await renderGraphFromSource({ name: 'hello.dot' }, { format: 'png', name: 'hello.png' })

Source properties:

nametypedescription
namestringfile name with the graph script
inputstringgraph script

If neither name nor input are provided, or the whole source parameter is omitted, the graph script will be read from the standard input.

Available options:

nametypedescription
namestringfile name for the generated graph output
enginestringtype of the layout to use for the graph rendering (circo, dot, fdp, neato, osage, twopi, default is dot)
formatstringtype of the output for the rendered graph (svg, png, dot, xdot, plain, plain-ext, ps, ps2, json, json0, canon, default is dot)
yInvertbooleaninvert the y-coordinate in the graph output
nopnumberno layout mode 'v' (0 or 1)

If name is not provided the output will be available only in the Promise. If the format png is specified, the NPM module node-canvas has to be installed, which is required as a peer-dependency of this package.

engines

List of available graph layout engines: circo, dot, fdp, neato, osage, twopi.

formats

List of available graph outout formats: svg, png, dot, xdot, plain, plain-ext, ps, ps2, json, json0, canon.

License

Copyright (c) 2020-2022 Ferdinand Prantl

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 11 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc