Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
115 lines (88 sloc) 3.5 KB

GraphJS logo

GraphJS is a framework for representing mathematical graphs in JavaScript. It is more or less a direct port of the popular NetworkX Python library. Such JavaScript, very math, etc. etc.


  • Nodes can represent anything (e.g. text, atoms, people)
  • Edges can hold arbitrary data (e.g. weights, distances)
  • Standard graph algorithms included
  • API is similar to NetworkX, with support for core classes and algorithms.
  • Works in Node.JS and Browser
  • Open-source BSD License
  • Synchronous/Asynchronous APIs


The entire library ships in a single file. You can include this directly in Node.JS or within the Browser.


npm install GraphJS
GraphJS = require('GraphJS'); // or require('./graph.min.js')


<script src='graph.min.js'></script>
	var g = GraphJS.Graph();

No external dependencies are required.

Building GraphJS from Source

Note: this feature is not quite ready yet.

The source is written in CoffeeScript. If you only need a few classes/algorithms from GraphJS, you can build GraphJS to only include the features you want.

To compile for the browser, install browserify and coffeeify and build using the following:

$ browserify -t coffeeify --extension=".coffee" > graph.min.js


Choose which type of graph is best suited for your application:

  • Graph: undirected graph with self-loops (basic)
  • DiGraph: directed graph with self-loops
  • MultiGraph: undirected graphs with self loops and parallel edges
  • MultiDiGraph: directed graph with self loops and parallel edges

This is a graph

This is a Multigraph

Inheriting Graphs

Modeling a social network is easy:

var SocialNetworkClass = function() {
	// redefining nodes as people and edges as relationships
	this.people = this.node;
	this.relationships = this.adj;	
SocialNetwork.prototype = new GraphJS.classes.Graph();
SocialNetwork.prototype.constructor = SocialNetwork;
var exampleNetwork = new SocialNetwork();

GraphJS-NetworkX Compatibility Notes


How You Can Help

GraphJS is developed in my spare time, and usually out of necessity for a graph algorithm or two in some other project of mine. You can support this project in several ways:

  1. File issues, bug reports, feature requests.
  2. Contribute Code!
    • Source code is written in CoffeeScript, which is syntactically similar to Python.
    • Read NetworkX documentation to understand GraphJS's desired architecture.
    • Implement a feature or two and submit a pull request.
  3. You can buy me a donut! Here is a bitcoin donation link:
<script src=""></script> <script> CoinWidgetCom.go({ wallet_address: "1MLX2kMhTSRiq3Uz7R2JsECreuQEmofQy6" , currency: "bitcoin" , counter: "hide" , alignment: "bl" , qrcode: true , auto_show: false , lbl_button: "Donate" , lbl_address: "My Bitcoin Address:" , lbl_count: "donations" , lbl_amount: "BTC" }); </script>