https://github.com/ericjang/graphjs
Mathematical Graph representation in JavaScript
https://github.com/ericjang/graphjs
Last synced: about 1 year ago
JSON representation
Mathematical Graph representation in JavaScript
- Host: GitHub
- URL: https://github.com/ericjang/graphjs
- Owner: ericjang
- Created: 2012-11-15T07:25:47.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2014-03-23T13:45:35.000Z (over 12 years ago)
- Last Synced: 2025-03-25T00:42:42.557Z (over 1 year ago)
- Language: CoffeeScript
- Size: 247 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

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.
## Features
- 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
## Installation
The entire library ships in a single file. You can include this directly in Node.JS or within the Browser.
node.js:
```
npm install GraphJS
GraphJS = require('GraphJS'); // or require('./graph.min.js')
```
browser:
```html
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" index.coffee > graph.min.js
```
### GraphJS.structures
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:
```JavaScript
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
TODO
## 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:
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"
});