I have a data structure that represents a directed graph, and I want to render that dynamically on an HTML page. These graphs will usually be just a few nodes, maybe ten at the very upper end, so my guess is that performance isn't going to be a big deal. Ideally, I'd like to be able to hook it in with jQuery so that users can tweak the layout manually by dragging the nodes around.
Note: I'm not looking for a charting library.
I've just put together what you may be looking for: http://www.graphdracula.net
It's JavaScript with directed graph layouting, SVG and you can even drag the nodes around. Still needs some tweaking, but is totally usable. You create nodes and edges easily with JavaScript code like this:
var g = new Graph();
g.addEdge("strawberry", "cherry");
g.addEdge("cherry", "apple");
g.addEdge("id34", "cherry");
I used the previously mentioned Raphael JS library (the graffle example) plus some code for a force based graph layout algorithm I found on the net (everything open source, MIT license). If you have any remarks or need a certain feature, I may implement it, just ask!
You may want to have a look at other projects, too! Below are two meta-comparisons:
SocialCompare [1] has an extensive list of libraries, and the "Node / edge graph" line will filter for graph visualization ones.
DataVisualization.ch has evaluated many libraries, including node/graph ones. Unfortunately there's no direct link so you'll have to filter for "graph":
Here's a list of similar projects (some have been already mentioned here):
vis.js [2] supports many types of network/edge graphs, plus timelines and 2D/3D charts. Auto-layout, auto-clustering, springy physics engine, mobile-friendly, keyboard navigation, hierarchical layout, animation etc. MIT licensed [3] and developed by a Dutch firm specializing in research on self-organizing networks.
Cytoscape.js [4] - interactive graph analysis and visualization with mobile support, following jQuery conventions. Funded via NIH grants and developed by by @maxkfranz [5] (see his answer below [6]) with help from several universities and other organizations.
The JavaScript InfoVis Toolkit [7] - Jit, an interactive, multi-purpose graph drawing and layout framework. See for example the Hyperbolic Tree [8]. Built by Twitter dataviz architect Nicolas Garcia Belmonte [9] and bought by Sencha [10] in 2010.
D3.js [11] Powerful multi-purpose JS visualization library, the successor of Protovis. See the force-directed graph [12] example, and other graph examples in the gallery [13].
Plotly's [14] JS visualization library uses D3.js with JS, Python, R, and MATLAB bindings. See a nexworkx example in IPython here [15], human interaction example here [16], and JS Embed API [17].
sigma.js [18] Lightweight but powerful library for drawing graphs
jsPlumb [19] jQuery plug-in for creating interactive connected graphs
Springy [20] - a force-directed graph layout algorithm
JS Graph It [21] - drag'n'drop boxes connected by straight lines. Minimal auto-layout of the lines.
RaphaelJS's Graffle [22] - interactive graph example of a generic multi-purpose vector drawing library. RaphaelJS can't layout nodes automatically; you'll need another library for that.
JointJS Core [23] - David Durman's MPL-licensed open source diagramming library. It can be used to create either static diagrams or fully interactive diagramming tools and application builders. Works in browsers supporting SVG. Layout algorithms not-included in the core package
mxGraph [24] Previously commercial HTML 5 diagramming library, now available under Apache v2.0. mxGraph is the base library used in draw.io [25].
GoJS [26] Interactive graph drawing and layout library
yFiles for HTML [27] Commercial graph drawing and layout library
KeyLines [28] Commercial JS network visualization toolkit
ZoomCharts [29] Commercial multi-purpose visualization library
Syncfusion JavaScript Diagram [30] Commercial diagram library for drawing and visualization.
Cytoscape Web [31] Embeddable JS Network viewer (no new features planned; succeeded by Cytoscape.js)
Canviz [32] JS renderer for Graphviz graphs. Abandoned [33] in Sep 2013.
arbor.js [34] Sophisticated graphing with nice physics and eye-candy. Abandoned in May 2012. Several semi-maintained [35] forks exist.
jssvggraph [36] "The simplest possible force directed graph layout algorithm implemented as a Javascript library that uses SVG objects". Abandoned in 2012.
jsdot [37] Client side graph drawing application. Abandoned in 2011 [38].
Protovis [39] Graphical Toolkit for Visualization (JavaScript). Replaced by d3.
Moo Wheel [40] Interactive JS representation for connections and relations (2008)
JSViz [41] 2007-era graph visualization script
dagre [42] Graph layout for JavaScript
Graphviz [43] Sophisticated graph visualization language
Flare [46] Beautiful and powerful Flash based graph drawing
NodeBox [47] Python Graph Visualization
Processing.js [48] Javascript port of the Processing library by John Resig
X,Y
coordinates for each node. (for graphdracula)
- Suhail Gupta
Disclaimer: I'm a developer of Cytoscape.js
Cytoscape.js is a HTML5 graph visualisation library. The API is sophisticated and follows jQuery conventions, including
cy.elements("node[weight >= 50].someClass")
does much as you would expect),cy.nodes().unselect().trigger("mycustomevent")
),If you're thinking about building a serious webapp with graphs, you should at least consider Cytoscape.js. It's free and open-source:
eles.move()
and the following extensions: edgehandles
, edge-editation
, edge-bend-editing
- maxkfranz
In a commercial scenario, a serious contestant for sure is yFiles for HTML [1]:
It offers:
Here is a sample rendering that shows most of the requested features:
Full disclosure: I work for yWorks, but on Stackoverflow I do not represent my employer.
[1] https://www.yworks.com/yfileshtmlAs guruz mentioned, the JIT [1] has several lovely graph/tree layouts, including quite appealing RGraph and HyperTree visualizations.
Also, I've just put up a super simple SVG-based implementation at github [2] (no dependencies, ~125 LOC) that should work well enough for small graphs displayed in modern browsers.
[1] http://philogb.github.io/jit/