Update simplified API demo.
This commit is contained in:
parent
1f5b8ab9ca
commit
de68f67d83
37
demo2.html
37
demo2.html
|
@ -1,4 +1,3 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
|
||||||
|
@ -6,30 +5,20 @@
|
||||||
<script src="springyui.js"></script>
|
<script src="springyui.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var graph = new Graph();
|
var graph = new Graph();
|
||||||
graph.addNodes(['Dennis', 'Michael', 'Jessica', 'Timothy', 'Barbara', 'Franklin'])
|
graph.addNodes('Dennis', 'Michael', 'Jessica', 'Timothy', 'Barbara', 'Franklin')
|
||||||
graph.addNodes(['Monty', 'James', 'Bianca']);
|
graph.addNodes('Monty', 'James');
|
||||||
|
|
||||||
var dennis = graph.newNode({label: 'Dennis'});
|
graph.addEdges(
|
||||||
var michael = graph.newNode({label: 'Michael'});
|
['Dennis', 'Michael', {color: '#00A0B0', label: 'Foo bar'}],
|
||||||
var jessica = graph.newNode({label: 'Jessica'});
|
['Michael', 'Dennis', {color: '#6A4A3C'}],
|
||||||
var timothy = graph.newNode({label: 'Timothy'});
|
['Michael', 'Jessica', {color: '#CC333F'}],
|
||||||
var barbara = graph.newNode({label: 'Barbara'});
|
['Jessica', 'Barbara', {color: '#EB6841'}],
|
||||||
var franklin = graph.newNode({label: 'Franklin'});
|
['Michael', 'Timothy', {color: '#EDC951'}],
|
||||||
var monty = graph.newNode({label: 'Monty'});
|
['Franklin', 'Monty', {color: '#7DBE3C'}],
|
||||||
var james = graph.newNode({label: 'James'});
|
['Dennis', 'Monty', {color: '#000000'}],
|
||||||
var bianca = graph.newNode({label: 'Bianca'});
|
['Monty', 'James'],
|
||||||
|
['Barbara', 'Timothy', {color: '#6A4A3C'}]
|
||||||
graph.newEdge(dennis, michael, {color: '#00A0B0', label: 'Foo bar'});
|
);
|
||||||
graph.newEdge(michael, dennis, {color: '#6A4A3C'});
|
|
||||||
graph.newEdge(michael, jessica, {color: '#CC333F'});
|
|
||||||
graph.newEdge(jessica, barbara, {color: '#EB6841'});
|
|
||||||
graph.newEdge(michael, timothy, {color: '#EDC951'});
|
|
||||||
graph.newEdge(franklin, monty, {color: '#7DBE3C'});
|
|
||||||
graph.newEdge(dennis, monty, {color: '#000000'});
|
|
||||||
graph.newEdge(monty, james, {color: '#00A0B0'});
|
|
||||||
graph.newEdge(barbara, timothy, {color: '#6A4A3C'});
|
|
||||||
graph.newEdge(dennis, bianca, {color: '#CC333F'});
|
|
||||||
graph.newEdge(bianca, monty, {color: '#EB6841'});
|
|
||||||
|
|
||||||
jQuery(function(){
|
jQuery(function(){
|
||||||
var springy = jQuery('#springydemo').springy({
|
var springy = jQuery('#springydemo').springy({
|
||||||
|
|
32
springy.js
32
springy.js
|
@ -69,12 +69,13 @@ Graph.prototype.addNode = function(node) {
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|
||||||
Graph.prototype.addNodes = function(list) {
|
Graph.prototype.addNodes = function() {
|
||||||
if (typeof(list[0]) == "string") {
|
// accepts variable number of arguments, where each argument
|
||||||
list.forEach(function(name) {
|
// is a string that becomes both node identifier and label
|
||||||
var node = new Node(name, data = {label:name});
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
this.addNode(node);
|
var name = arguments[i];
|
||||||
}, this);
|
var node = new Node(name, data = {label:name});
|
||||||
|
this.addNode(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,6 +109,25 @@ Graph.prototype.addEdge = function(edge) {
|
||||||
return edge;
|
return edge;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Graph.prototype.addEdges = function() {
|
||||||
|
// accepts variable number of arguments, where each argument
|
||||||
|
// is a triple [nodeid1, nodeid2, attributes]
|
||||||
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
|
var e = arguments[i];
|
||||||
|
var node1 = this.nodeSet[e[0]];
|
||||||
|
if (node1 == undefined) {
|
||||||
|
throw new TypeError("invalid node name: " + e[0]);
|
||||||
|
}
|
||||||
|
var node2 = this.nodeSet[e[1]];
|
||||||
|
if (node2 == undefined) {
|
||||||
|
throw new TypeError("invalid node name: " + e[1]);
|
||||||
|
}
|
||||||
|
var attr = e[2];
|
||||||
|
|
||||||
|
this.newEdge(node1, node2, attr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Graph.prototype.newNode = function(data) {
|
Graph.prototype.newNode = function(data) {
|
||||||
var node = new Node(this.nextNodeId++, data);
|
var node = new Node(this.nextNodeId++, data);
|
||||||
this.addNode(node);
|
this.addNode(node);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user