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>
|
||||
<body>
|
||||
<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>
|
||||
var graph = new Graph();
|
||||
graph.addNodes(['Dennis', 'Michael', 'Jessica', 'Timothy', 'Barbara', 'Franklin'])
|
||||
graph.addNodes(['Monty', 'James', 'Bianca']);
|
||||
graph.addNodes('Dennis', 'Michael', 'Jessica', 'Timothy', 'Barbara', 'Franklin')
|
||||
graph.addNodes('Monty', 'James');
|
||||
|
||||
var dennis = graph.newNode({label: 'Dennis'});
|
||||
var michael = graph.newNode({label: 'Michael'});
|
||||
var jessica = graph.newNode({label: 'Jessica'});
|
||||
var timothy = graph.newNode({label: 'Timothy'});
|
||||
var barbara = graph.newNode({label: 'Barbara'});
|
||||
var franklin = graph.newNode({label: 'Franklin'});
|
||||
var monty = graph.newNode({label: 'Monty'});
|
||||
var james = graph.newNode({label: 'James'});
|
||||
var bianca = graph.newNode({label: 'Bianca'});
|
||||
|
||||
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'});
|
||||
graph.addEdges(
|
||||
['Dennis', 'Michael', {color: '#00A0B0', label: 'Foo bar'}],
|
||||
['Michael', 'Dennis', {color: '#6A4A3C'}],
|
||||
['Michael', 'Jessica', {color: '#CC333F'}],
|
||||
['Jessica', 'Barbara', {color: '#EB6841'}],
|
||||
['Michael', 'Timothy', {color: '#EDC951'}],
|
||||
['Franklin', 'Monty', {color: '#7DBE3C'}],
|
||||
['Dennis', 'Monty', {color: '#000000'}],
|
||||
['Monty', 'James'],
|
||||
['Barbara', 'Timothy', {color: '#6A4A3C'}]
|
||||
);
|
||||
|
||||
jQuery(function(){
|
||||
var springy = jQuery('#springydemo').springy({
|
||||
|
|
32
springy.js
32
springy.js
|
@ -69,12 +69,13 @@ Graph.prototype.addNode = function(node) {
|
|||
return node;
|
||||
};
|
||||
|
||||
Graph.prototype.addNodes = function(list) {
|
||||
if (typeof(list[0]) == "string") {
|
||||
list.forEach(function(name) {
|
||||
var node = new Node(name, data = {label:name});
|
||||
this.addNode(node);
|
||||
}, this);
|
||||
Graph.prototype.addNodes = function() {
|
||||
// accepts variable number of arguments, where each argument
|
||||
// is a string that becomes both node identifier and label
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var name = arguments[i];
|
||||
var node = new Node(name, data = {label:name});
|
||||
this.addNode(node);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -108,6 +109,25 @@ Graph.prototype.addEdge = function(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) {
|
||||
var node = new Node(this.nextNodeId++, data);
|
||||
this.addNode(node);
|
||||
|
|
Loading…
Reference in New Issue
Block a user