<p>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.</p>

<p>Note: I'm not looking for a charting library.</p>

[{'answer_id': 12844, 'author': 'Sam Coles', 'author_id': 804, 'author_profile': 'https://Stackoverflow.com/users/804', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://www.jsviz.org" rel="nofollow noreferrer">JsVIS</a> was pretty nice, but slow with larger graphs, and has been abandoned since 2007.</p>\n\n<p><a href="https://github.com/prefuse/Prefuse" rel="nofollow noreferrer">prefuse</a> is a set of software tools for creating rich interactive data visualizations in Java. <a href="https://github.com/prefuse/Flare" rel="nofollow noreferrer">flare</a>  is an ActionScript library for creating visualizations that run in the Adobe Flash Player, abandoned since 2012.</p>\n'}, {'answer_id': 2366237, 'author': 'Johann Philipp Strathausen', 'author_id': 284708, 'author_profile': 'https://Stackoverflow.com/users/284708', 'pm_score': 11, 'selected': True, 'text': '<p>I\'ve just put together what you may be looking for: <a href="http://www.graphdracula.net" rel="noreferrer">http://www.graphdracula.net</a></p>\n<p>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:</p>\n<pre><code>var g = new Graph();\ng.addEdge(&quot;strawberry&quot;, &quot;cherry&quot;);\ng.addEdge(&quot;cherry&quot;, &quot;apple&quot;);\ng.addEdge(&quot;id34&quot;, &quot;cherry&quot;);\n</code></pre>\n<p>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!</p>\n<hr />\n<p>You may want to have a look at other projects, too! Below are two meta-comparisons:</p>\n<ul>\n<li><p><a href="http://socialcompare.com/en/comparison/javascript-graphs-and-charts-libraries" rel="noreferrer">SocialCompare</a> has an extensive list of libraries, and the &quot;Node / edge graph&quot; line will filter for graph visualization ones.</p>\n</li>\n<li><p>DataVisualization.ch has evaluated many libraries, including node/graph ones. Unfortunately there\'s no direct link so you\'ll have to filter for &quot;graph&quot;:<a href="http://selection.datavisualization.ch/" rel="noreferrer"><img src="https://i.stack.imgur.com/o4lwD.jpg" alt="Selection DataVisualization.ch" /></a></p>\n</li>\n</ul>\n<p>Here\'s a list of similar projects (some have been already mentioned here):</p>\n<h3>Pure JavaScript Libraries</h3>\n<ul>\n<li><p><a href="http://visjs.org/#gallery" rel="noreferrer">vis.js</a> 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. <a href="https://github.com/almende/vis" rel="noreferrer">MIT licensed</a> and developed by a Dutch firm specializing in research on self-organizing networks.</p>\n</li>\n<li><p><a href="http://js.cytoscape.org" rel="noreferrer">Cytoscape.js</a> - interactive graph analysis and visualization with mobile support, following jQuery conventions. Funded via NIH grants and developed by by <a href="https://stackoverflow.com/users/947225/maxkfranz">@maxkfranz</a> (see <a href="https://stackoverflow.com/a/10319429/1269037">his answer below</a>) with help from several universities and other organizations.</p>\n</li>\n<li><p><a href="http://thejit.org/demos.html" rel="noreferrer">The JavaScript InfoVis Toolkit</a> - Jit, an interactive, multi-purpose graph drawing and layout framework. See for example the <a href="http://philogb.github.io/jit/static/v20/Docs/files/Visualizations/Hypertree-js.html" rel="noreferrer">Hyperbolic Tree</a>. Built by Twitter dataviz architect <a href="http://www.sencha.com/conference/session/sencha-charting-visualization" rel="noreferrer">Nicolas Garcia Belmonte</a> and <a href="http://philogb.github.io/infovis/" rel="noreferrer">bought by Sencha</a> in 2010.</p>\n</li>\n<li><p><a href="http://d3js.org/" rel="noreferrer">D3.js</a> Powerful multi-purpose JS visualization library, the successor of Protovis. See the <a href="http://bl.ocks.org/mbostock/4062045" rel="noreferrer">force-directed graph</a> example, and other graph examples in the <a href="https://github.com/mbostock/d3/wiki/Gallery" rel="noreferrer">gallery</a>.</p>\n</li>\n<li><p><a href="https://plot.ly./" rel="noreferrer">Plotly\'s</a> JS visualization library uses D3.js with JS, Python, R, and MATLAB bindings. See a nexworkx example in IPython <a href="https://plot.ly/ipython-notebooks/network-graphs/" rel="noreferrer">here</a>, human interaction example <a href="https://plot.ly/ipython-notebooks/bioinformatics/#In-%5B54%5D" rel="noreferrer">here</a>, and <a href="https://github.com/plotly/Embed-API" rel="noreferrer">JS Embed API</a>.</p>\n</li>\n<li><p><a href="http://sigmajs.org/" rel="noreferrer">sigma.js</a> Lightweight but powerful library for drawing graphs</p>\n</li>\n<li><p><a href="http://jsplumbtoolkit.com/" rel="noreferrer">jsPlumb</a> jQuery plug-in for creating interactive connected graphs</p>\n</li>\n<li><p><a href="http://getspringy.com/" rel="noreferrer">Springy</a> - a force-directed graph layout algorithm</p>\n</li>\n<li><p><a href="http://js-graph-it.sourceforge.net/" rel="noreferrer">JS Graph It</a> - drag\'n\'drop boxes connected by straight lines. Minimal auto-layout of the lines.</p>\n</li>\n<li><p><a href="http://raphaeljs.com/graffle.html" rel="noreferrer">RaphaelJS\'s Graffle</a> - interactive graph example of a generic multi-purpose vector drawing library. RaphaelJS can\'t layout nodes automatically; you\'ll need another library for that.</p>\n</li>\n<li><p><a href="http://www.jointjs.com/demos" rel="noreferrer">JointJS Core</a> - 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</p>\n</li>\n<li><p><a href="https://github.com/jgraph/mxgraph" rel="noreferrer">mxGraph</a> Previously commercial HTML 5 diagramming library, now available under Apache v2.0. mxGraph is the base library used in <a href="https://www.draw.io?splash=0" rel="noreferrer">draw.io</a>.</p>\n</li>\n</ul>\n<h3>Commercial libraries</h3>\n<ul>\n<li><p><a href="http://gojs.net/latest/index.html" rel="noreferrer">GoJS</a> Interactive graph drawing and layout library</p>\n</li>\n<li><p><a href="http://www.yworks.com/yfileshtml" rel="noreferrer">yFiles for HTML</a> Commercial graph drawing and layout library</p>\n</li>\n<li><p><a href="http://keylines.com/" rel="noreferrer">KeyLines</a> Commercial JS network visualization toolkit</p>\n</li>\n<li><p><a href="https://zoomcharts.com" rel="noreferrer">ZoomCharts</a> Commercial multi-purpose visualization library</p>\n</li>\n<li><p><a href="https://www.syncfusion.com/javascript-ui-controls/diagram" rel="noreferrer">Syncfusion JavaScript Diagram</a> Commercial diagram library for drawing and visualization.</p>\n</li>\n</ul>\n<h3>Abandoned libraries</h3>\n<ul>\n<li><p><a href="http://cytoscapeweb.cytoscape.org/" rel="noreferrer">Cytoscape Web</a> Embeddable JS Network viewer (no new features planned; succeeded by Cytoscape.js)</p>\n</li>\n<li><p><a href="http://code.google.com/p/canviz/" rel="noreferrer">Canviz</a> JS <strong>renderer</strong> for Graphviz graphs. <a href="https://code.google.com/p/canviz/source/list" rel="noreferrer">Abandoned</a> in Sep 2013.</p>\n</li>\n<li><p><a href="http://arborjs.org/" rel="noreferrer">arbor.js</a> Sophisticated graphing with nice physics and eye-candy. Abandoned in May 2012. Several <a href="https://github.com/samizdatco/arbor/issues/56#issuecomment-62842532" rel="noreferrer">semi-maintained</a> forks exist.</p>\n</li>\n<li><p><a href="http://github.com/jackrusher/jssvggraph" rel="noreferrer">jssvggraph</a> &quot;The simplest possible force directed graph layout algorithm implemented as a Javascript library that uses SVG objects&quot;. Abandoned in 2012.</p>\n</li>\n<li><p><a href="https://code.google.com/p/jsdot/" rel="noreferrer">jsdot</a> Client side graph drawing application. <a href="https://code.google.com/p/jsdot/source/list" rel="noreferrer">Abandoned in 2011</a>.</p>\n</li>\n<li><p><a href="http://vis.stanford.edu/protovis/ex/force.html" rel="noreferrer">Protovis</a> Graphical Toolkit for Visualization (JavaScript). Replaced by d3.</p>\n</li>\n<li><p><a href="http://labs.unwieldy.net/moowheel/" rel="noreferrer">Moo Wheel</a> Interactive JS representation for connections and relations (2008)</p>\n</li>\n<li><p><a href="http://www.jsviz.org/" rel="noreferrer">JSViz</a> 2007-era graph visualization script</p>\n</li>\n<li><p><a href="https://github.com/cpettitt/dagre" rel="noreferrer">dagre</a> Graph layout for JavaScript</p>\n</li>\n</ul>\n<h3>Non-Javascript Libraries</h3>\n<ul>\n<li><p><a href="http://www.graphviz.org/" rel="noreferrer">Graphviz</a> Sophisticated graph visualization language</p>\n<ul>\n<li>Graphviz has been compiled to Javascript using Emscripten <a href="https://github.com/mdaines/viz.js/" rel="noreferrer">here</a> with an <a href="http://mdaines.github.io/viz.js/" rel="noreferrer">online interactive demo here</a></li>\n</ul>\n</li>\n<li><p><a href="http://flare.prefuse.org/" rel="noreferrer">Flare</a> Beautiful and powerful Flash based graph drawing</p>\n</li>\n<li><p><a href="http://nodebox.net/code/index.php/Graph" rel="noreferrer">NodeBox</a> Python Graph Visualization</p>\n</li>\n<li><p><a href="http://processingjs.org/" rel="noreferrer">Processing.js</a> Javascript port of the Processing library by John Resig</p>\n</li>\n</ul>\n'}, {'answer_id': 2571954, 'author': 'Jack Rusher', 'author_id': 308349, 'author_profile': 'https://Stackoverflow.com/users/308349', 'pm_score': 3, 'selected': False, 'text': '<p>As guruz mentioned, the <a href="http://philogb.github.io/jit/" rel="nofollow noreferrer">JIT</a> has several lovely graph/tree layouts, including quite appealing RGraph and HyperTree visualizations.</p>\n\n<p>Also, I\'ve just put up a super simple SVG-based <a href="http://github.com/jackrusher/jssvggraph" rel="nofollow noreferrer">implementation at github</a> (no dependencies, ~125 LOC) that should work well enough for small graphs displayed in modern browsers.</p>\n'}, {'answer_id': 10319429, 'author': 'maxkfranz', 'author_id': 947225, 'author_profile': 'https://Stackoverflow.com/users/947225', 'pm_score': 6, 'selected': False, 'text': '<p><em>Disclaimer: I\'m a developer of Cytoscape.js</em></p>\n\n<p>Cytoscape.js is a HTML5 graph visualisation library.  The API is sophisticated and follows jQuery conventions, including </p>\n\n<ul>\n<li>selectors for querying and filtering (<code>cy.elements("node[weight &gt;= 50].someClass")</code> does much as you would expect),</li>\n<li>chaining (e.g. <code>cy.nodes().unselect().trigger("mycustomevent")</code>),</li>\n<li>jQuery-like functions for binding to events,</li>\n<li>elements as collections (like jQuery has collections of HTMLDomElements),</li>\n<li>extensibility (can add custom layouts, UI, core &amp; collection functions, and so on),</li>\n<li>and more.</li>\n</ul>\n\n<p>If you\'re thinking about building a serious webapp with graphs, you should at least consider Cytoscape.js.  It\'s free and open-source:</p>\n\n<p><a href="http://js.cytoscape.org">http://js.cytoscape.org</a></p>\n'}, {'answer_id': 14194536, 'author': 'Sebastian', 'author_id': 351836, 'author_profile': 'https://Stackoverflow.com/users/351836', 'pm_score': 3, 'selected': False, 'text': '<p>In a commercial scenario, a serious contestant for sure is <a href="https://www.yworks.com/yfileshtml" rel="noreferrer">yFiles for HTML</a>:</p>\n\n<p>It offers:</p>\n\n<ul>\n<li>Easy <em>import</em> of custom data (<a href="http://live.yworks.com/yfiles-for-html/2.0/databinding/graphbuilder/index.html" rel="noreferrer">this interactive online demo</a> seems to pretty much do exactly what the OP was looking for)</li>\n<li>Interactive editing for creating and manipulating the diagrams through user gestures (see the complete <a href="https://www.yworks.com/products/yed-live" rel="noreferrer">editor</a>)</li>\n<li>A huge <a href="http://docs.yworks.com/yfileshtml/" rel="noreferrer">programming API</a> for customizing each and every aspect of the library </li>\n<li>Support for <em>grouping</em> and <em>nesting</em> (both interactive, as well as through the layout algorithms)</li>\n<li>Does not depend on a specfic UI toolkit but supports <em>integration</em> into almost any existing Javascript toolkit (see the <a href="http://live.yworks.com/yfiles-for-html/2.0/#integration" rel="noreferrer">"integration" demos</a>)</li>\n<li>Automatic layout (various styles, like "hierarchic", "organic", "orthogonal", "tree", "circular", "radial", and more)</li>\n<li>Automatic sophisticated edge routing (orthogonal and organic edge routing with obstacle avoidance)</li>\n<li>Incremental and partial layout (adding and removing elements and only slightly or not at all changing the rest of the diagram)</li>\n<li>Support for grouping and nesting (both interactive, as well as through the layout algorithms)</li>\n<li>Implementations of <a href="http://live.yworks.com/yfiles-for-html/2.0/#analysis" rel="noreferrer">graph analysis algorithms</a> (paths, centralities, network flows, etc.)</li>\n<li>Uses HTML 5 technologies like SVG+CSS and Canvas and modern Javascript leveraging properties and other more ES5 and ES6 features (but for the same reason will not run in IE versions 8 and lower).</li>\n<li>Uses a modular API that can be loaded on-demand using UMD loaders</li>\n</ul>\n\n<p>Here is a sample rendering that shows most of the requested features:</p>\n\n<p><img src="https://i.stack.imgur.com/9RrCz.png" alt="Screenshot of a sample rendering created by the BPMN demo."></p>\n\n<p>Full disclosure: I work for yWorks, but on Stackoverflow I do not represent my employer.</p>\n'}]
['https://Stackoverflow.com/questions/7034', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/404/']