Skip to content

Instantly share code, notes, and snippets.

@lrowe
Created September 12, 2012 17:58
Show Gist options
  • Save lrowe/3708615 to your computer and use it in GitHub Desktop.
Save lrowe/3708615 to your computer and use it in GitHub Desktop.
/*global document, jQuery */
(function($) {
$(function() {
var g, renderer;
var width = $(document).width() - 20;
var height = $(document).height() - 60;
g = new Graph();
/* add a simple node */
g.addNode("apple");
g.addNode("strawberry");
g.addNode("cherry");
/* connect nodes with edges */
g.addEdge("strawberry", "cherry", {directed: true, label: 'to_cherry'});
g.addEdge("cherry", "apple", {directed: true, label: 'to_apple'});
g.addEdge("cherry", "apple", {directed: true, label: 'to_apple2'})
/* layout the graph using the Spring layout implementation */
var layouter = new Graph.Layout.Spring(g);
/* draw the graph using the RaphaelJS draw implementation */
renderer = new Graph.Renderer.Raphael('canvas', g, width, height);
$('button#redraw').click(function () {
layouter.layout();
renderer.draw();
});
});
}(jQuery));
<html>
<head>
<script type="text/javascript" src="https://raw.github.com/strathausen/dracula/master/js/raphael-min.js"></script>
<script type="text/javascript" src="https://raw.github.com/strathausen/dracula/master/js/dracula_graffle.js"></script>
<script type="text/javascript" src="https://raw.github.com/strathausen/dracula/master/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/strathausen/dracula/master/js/dracula_graph.js"></script>
<script type="text/javascript" src="example.js"></script>
</head>
<body>
<div id="canvas"></div>
<button id="redraw">redraw</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment