npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphviz-cli

v2.0.0

Published

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

Downloads

23,480

Readme

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:

| name | type | description | |---------|----------|---------------------------------| | name | string | file name with the graph script | | input | string | graph 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:

| name | type | description | |-----------|-----------|---------------------------------------------| | name | string | file name for the generated graph output | | engine | string | type of the layout to use for the graph rendering (circo, dot, fdp, neato, osage, twopi, default is dot) | | format | string | type of the output for the rendered graph (svg, png, dot, xdot, plain, plain-ext, ps, ps2, json, json0, canon, default is dot) | | yInvert | boolean | invert the y-coordinate in the graph output | | nop | number | no 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.