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

node-graphviz

v0.1.1

Published

Compile graphs written in DOT to images, using GraphViz in Node.js

Downloads

9,211

Readme

node-graphviz

A JS + WASM module for compiling graphs written in DOT to images, using GraphViz in Node.js.

No annoying native build system or native dependencies that need to be compiled.

Installation

npm install node-graphviz --save

Usage

See The DOT Language for more information about DOT, and GraphViz Pocket Reference for some examples.

const fs = require('fs');
const { graphviz } = require('node-graphviz');

// Define a graph using DOT notation
const graph = `
    digraph {
        a -> b;
        b -> c;
        c -> d;
        d -> a;
    }
`;

// Compile the graph to SVG using the `circo` layout algorithm
graphviz.circo(graph, 'svg').then((svg) => {
  // Write the SVG to file
  fs.writeFileSync('graph.svg', svg);
});

Running the above produces the following SVG:

SVG Image showing compiled graph

API

The module exports the following API:

declare type Format = 'svg' | 'dot' | 'json' | 'dot_json' | 'xdot_json';

declare type Engine = 'circo' | 'dot' | 'fdp' | 'neato' | 'osage' | 'patchwork' | 'twopi';

export declare const graphviz = {
    layout(dotSource: string, outputFormat?: Format, layoutEngine?: Engine): Promise<string>;
    circo(dotSource: string, outputFormat?: Format): Promise<string>;
    dot(dotSource: string, outputFormat?: Format): Promise<string>;
    fdp(dotSource: string, outputFormat?: Format): Promise<string>;
    neato(dotSource: string, outputFormat?: Format): Promise<string>;
    osage(dotSource: string, outputFormat?: Format): Promise<string>;
    patchwork(dotSource: string, outputFormat?: Format): Promise<string>;
    twopi(dotSource: string, outputFormat?: Format): Promise<string>;
};

graphviz.layout(dotSource[, outputFormat][, layoutengine])

Performs layout for the supplied dotSource.

Where:

  • outputFormat is one of the following (see Output Formats for details):
    • dot
    • dot_json
    • json
    • svg (default)
    • xdot_json
  • layoutEngine is one of the following (see Layout documentation for details):
    • circo
    • dot (default)
    • fdp
    • neato
    • osage
    • patchwork
    • twopi

graphviz.circo(dotSource[, outputFormat])

Convenience function that performs circo layout, is equivalent to layout(dotSource, outputFormat, 'circo').

graphviz.dot(dotSource[, outputFormat])

Convenience function that performs dot layout, is equivalent to layout(dotSource, outputFormat, 'dot').

graphviz.fdp(dotSource[, outputFormat])

Convenience function that performs circo layout, is equivalent to layout(dotSource, outputFormat, 'fdp').

graphviz.neato(dotSource[, outputFormat])

Convenience function that performs neato layout, is equivalent to layout(dotSource, outputFormat, 'neato').

graphviz.osage(dotSource[, outputFormat])

Convenience function that performs osage layout, is equivalent to layout(dotSource, outputFormat, 'osage').

graphviz.patchwork(dotSource[, outputFormat])

Convenience function that performs patchwork layout, is equivalent to layout(dotSource, outputFormat, 'patchwork').

graphviz.twopi(dotSource[, outputFormat])

Convenience function that performs twopi layout, is equivalent to layout(dotSource, outputFormat, 'twopi').

Credits

This module is based on hpcc-systems/hpcc-js-wasm, which is designed for use in a browser, not Node.js. The following changes were made to support Node and simplify the module to include only GraphViz:

  • Rewrote WASM binary location and fetching to read from the filesystem
  • Added the compiled WASM binary to the source
  • Reduced the JS code by half to include only GraphViz, removed Expat and other unrelated code
  • Removed build system and TypeScript, in favor of a single source file (based on the compiled dist file from hpcc-systems/hpcc-js-wasm)

Licence

MIT