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

ngraph.todot

v4.0.0

Published

Save ngraph.graph to dot format

Downloads

757

Readme

ngraph.todot build status

Save ngraph.graph to dot format.

usage

// Let's say we have a graph with two edges:
var graph = require('ngraph.graph')();
graph.addLink(1, 2);
graph.addLink(2, 3);


// Now save it to dot format:
var toDot = require('ngraph.todot');
var dotContent = toDot(graph);

This will set dotContent to a string with a graph, described in dot format:

digraph G {
1 -> 2
2 -> 3
}

What to do with this? dot is very well supported format by multiple graph analysis software (e.g. gephi, graphviz).

You can easily transfer ngraph.graph to your favorite platform!

To read it back to ngraph.graph, use ngraph.fromdot module:

var fromDot = require('ngraph.fromdot');
var newGraph = fromDot(dotContent);

Now newGraph is an instance of ngraph.graph

Attributes

The library will store attributes of nodes/edges, with a few limitations

  1. Attribute must be an object and not a primitive type
  2. Composite nested objects are JSON.stringified.
var graph = require('ngraph.graph')();
graph.addNode(1, { name: 'ngraph' });
graph.addLink(1, 2, { version: '42' });


// Now save it to dot format:
var toDot = require('ngraph.todot');
var dotContent = toDot(graph);

// you can parse it back:
var fromDot = require('ngraph.fromdot');
var restored = fromDot(dotContent);
// and expect attributes to be present:

restored.getNode(1).data.name === 'ngraph'
restored.getLink(1, 2).data.version === '42'

Streaming

By default, when you toDot(graph) the output is buffered into an array, and flushed at the end. This may not be feasible for huge graphs, since it takes extra memory.

For this uses case ngraph.todot exposes a low level method write(graph, writer) which allows your code to own how actual output is stored/processed.

For example:

var graph = require('ngraph.graph')();
graph.addLink(1, 2);
graph.addLink(2, 3);

var toDot = require('ngraph.todot');

toDot.write(graph, function customWriter(line) {
  console.log(line);
});

This will print dot file on the console without using extra memory:

digraph G {
1 -> 2
2 -> 3
}

install

With npm do:

npm install ngraph.todot

license

MIT