-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.html
More file actions
68 lines (45 loc) · 3.11 KB
/
tutorial.html
File metadata and controls
68 lines (45 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Graph.js</title>
<style type="text/css">
.graph { border-style:solid;border-width:1px;display:block;margin-left:auto;margin-right:auto;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="graph.js"></script>
<script type="text/javascript" src="tutorial.js"></script>
</head>
<body>
<div>
<canvas class="graph" width="200" height="150" id="ex1"></canvas>
</div>
<h3>Basic Usage</h3>
<p>
<a href="http://github.com/ANorwell/graph">Graph.js</a> is a tool for creating editable graphs on the HTML canvas element. Vertices and edges are created by clicking on the canvas. Initializing a graph is simple:
</p>
<script src="https://gist.github.com/761390.js?file=gistfile1.js"></script>
<p>Graph.js supports JSON serialization, meaning that the vertex and edge information of a graph can be saved and loaded.</p>
<script src="https://gist.github.com/761394.js?file=gistfile1.js"></script>
<p>Graphs may also be saved and loaded from <a href="http://diveintohtml5.org/storage.html">Local Storage</a>.
</p>
<script src="https://gist.github.com/761414.js?file=gistfile1.js"></script>
<p>Graph.js supports graphs that are editable: that is, vertices can be added and moved, as in the example below (try clicking and dragging a vertex).</p>
<div>
<canvas class="graph" width="200" height="150" id="ex2"></canvas>
</div>
<p>Making a graph editable is also very easy:</p>
<script src="https://gist.github.com/761411.js?file=gistfile1.js"></script>
<h3>Configuration Options</h3>
<p> Graph.js is designed to be customizeable. The <strong>setOption</strong> command provides several configurable settings, including <em>vertexDrawFunction</em>, <em>edgeDrawFunction</em>, and <em>physics</em>. The following code snippet gives a usage example:</p>
<script src="https://gist.github.com/761421.js?file=gistfile1.js"></script>
<p> The vertex and edge draw functions shown above give the following result:</p>
<div>
<canvas class="graph" width="200" height="150" id="ex3"></canvas>
</div>
<p>As well, the underlying graph structure can be manipulated programmatically by accessing and modifying the <strong>graph</strong> member object of the Graph.js Graph class. This writeup won't go into detail about this process.</p>
<h3>Server-side storage</h3>
<p>The JSON serialization lends itself naturally to server-side storage of graphs. This allows a graph to be constructed using a graph creation application such as the one I created <a href="http://anorwell.com/graph/?gid=34">here</a>, and then displayed later in a different format (for example, as a static illustration, such as the ones on this page. </p>
<p>The following code snippet illustrates how a script might fetch a graph, indexed by an id, from a server.</p>
<script src="https://gist.github.com/761427.js?file=gistfile1.js"></script>
</body>
</html>