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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mgraph.fromdot

v1.0.1

Published

Load DOT files into mgraph.graph

Readme

mgraph.fromdot

Modern DOT file parser for JavaScript — Load Graphviz DOT files into mgraph.graph

npm version License

About This Project

mgraph.fromdot is a modern ES module refactoring of ngraph.fromdot, originally developed by Andrei Kashcha. This project retains the functionality of the original library while updating it to modern JavaScript standards.

This project is not affiliated with or endorsed by Andrei Kashcha, and any modifications are the responsibility of the maintainers of mgraph.fromdot.

Installation

Via npm

npm install mgraph.fromdot

Via CDN

<script src="https://cdn.jsdelivr.net/npm/mgraph.fromdot/dist/mgraph.fromdot.umd.min.js"></script>

When loaded from a CDN, the library is available as the global variable mgraphFromDot.

Usage

ES Modules (Recommended)

import fromDot from 'mgraph.fromdot';

// Load an empty graph
const emptyGraph = fromDot('digraph G {}');

// Load a graph with edges only
const twoEdgesGraph = fromDot('digraph G { a -> b }');

// The above graph is equivalent to
const sameAsAbove = fromDot('digraph G { a; b; a -> b }');

CommonJS

const fromDot = require('mgraph.fromdot').default;

TypeScript

import fromDot from 'mgraph.fromdot';
import { Graph } from 'mgraph.graph';

const graph: Graph = fromDot('digraph G { a -> b }');

CDN Usage

<script src="https://cdn.jsdelivr.net/npm/mgraph.fromdot/dist/mgraph.fromdot.umd.min.js"></script>
<script>
  const graph = mgraphFromDot('digraph G { a -> b }');
</script>

Advanced Usage

Appending to Existing Graphs

import fromDot from 'mgraph.fromdot';
import createGraph from 'mgraph.graph';

const existingGraph = createGraph();
existingGraph.addNode('existing');

// Append DOT data to existing graph
fromDot('digraph B { a -> b }', existingGraph);

console.log(existingGraph.getLinksCount()); // returns 1
console.log(existingGraph.getNodesCount()); // returns 3 (existing + a + b)

Parsing Attributes

const graph = fromDot(`
  digraph G {
    node1 [label="My Node" color="red" weight=5];
    node2 [shape=box];
    node1 -> node2 [style=dotted weight=2];
  }
`);

// Access node attributes
const node1 = graph.getNode('node1');
console.log(node1.data.label);  // "My Node"
console.log(node1.data.color);  // "red"
console.log(node1.data.weight); // 5

// Access edge attributes
const link = graph.getLink('node1', 'node2');
console.log(link.data.style);   // "dotted"
console.log(link.data.weight);  // 2

Complex DOT Files

const complexGraph = fromDot(`
  digraph G {
    rankdir=LR;
    
    subgraph cluster_0 {
      label="Process #1";
      style=filled;
      color=lightgrey;
      a0 -> a1 -> a2 -> a3;
    }
    
    subgraph cluster_1 {
      label="Process #2";
      b0 -> b1 -> b2 -> b3;
    }
    
    start -> a0;
    start -> b0;
    a1 -> b3;
    b2 -> a3;
    a3 -> end;
    b3 -> end;
  }
`);

Framework Integration

React

import { useEffect, useState } from 'react';
import fromDot from 'mgraph.fromdot';

function GraphComponent({ dotString }) {
  const [graph, setGraph] = useState(null);
  
  useEffect(() => {
    const parsedGraph = fromDot(dotString);
    setGraph(parsedGraph);
  }, [dotString]);
  
  return <div>{/* Render your graph */}</div>;
}

Vue

<script setup>
import { ref, watch } from 'vue';
import fromDot from 'mgraph.fromdot';

const props = defineProps(['dotString']);
const graph = ref(null);

watch(() => props.dotString, (newDot) => {
  graph.value = fromDot(newDot);
}, { immediate: true });
</script>

API

fromDot(dotString, appendTo?)

Parameters:

  • dotString (string) - A graph in DOT format
  • appendTo (Graph, optional) - An existing mgraph.graph instance to append to

Returns:

  • Graph - An mgraph.graph instance loaded with DOT data

Throws:

  • Error - If DOT string contains multiple graphs and appendTo is provided

Supported DOT Features

  • ✅ Directed and undirected graphs
  • ✅ Node declarations with attributes
  • ✅ Edge declarations with attributes
  • ✅ Subgraphs and clusters
  • ✅ Node and edge styling attributes
  • ✅ Numeric and string attribute values
  • ✅ Array attribute values (JSON format)
  • ✅ Comments

Part of the mgraph Ecosystem

  • mgraph.graph - Core graph data structure
  • mgraph.events - Event system
  • mgraph.forcelayout - Force-directed layouts
  • mgraph.generators - Graph generators
  • mgraph.fromdot - DOT file parser ← You are here
  • mgraph.merge - Object merging utility
  • mgraph.random - Seeded random numbers

License

This project is released under the BSD 3-Clause License, in compliance with the original ngraph.fromdot licensing terms. See LICENSE for details.

Contributing

Issues and pull requests are welcome on GitHub.

Credits

Original ngraph.fromdot by Andrei Kashcha. Modern mgraph.fromdot maintained by Michael Feldman.

This updated README:

  • ✅ Fixes the CDN URLs and global variable names
  • ✅ Adds proper badges and links
  • ✅ Shows comprehensive usage examples
  • ✅ Includes TypeScript examples
  • ✅ Shows framework integration (React, Vue)
  • ✅ Documents the API properly
  • ✅ Lists supported DOT features
  • ✅ Mentions the mgraph ecosystem
  • ✅ Adds proper attribution and licensing info