API change: addNode() now accepts string or Node
This commit is contained in:
parent
d3e7db95df
commit
6c04b2416f
15
springy.js
15
springy.js
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Springy v1.1.1
|
* Springy v1.2.0
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Dennis Hotson
|
* Copyright (c) 2010 Dennis Hotson
|
||||||
*
|
*
|
||||||
|
@ -61,7 +61,14 @@ var Edge = function(id, source, target, data) {
|
||||||
// this.data.type
|
// this.data.type
|
||||||
};
|
};
|
||||||
|
|
||||||
Graph.prototype.addNode = function(node) {
|
Graph.prototype.addNode = function(mixed) {
|
||||||
|
// mixed can be Node object or a string
|
||||||
|
var node;
|
||||||
|
if (typeof mixed == "string" || mixed instanceof String) {
|
||||||
|
node = new Node(mixed, {label:mixed});
|
||||||
|
} else {
|
||||||
|
node = mixed;
|
||||||
|
}
|
||||||
if (!(node.id in this.nodeSet)) {
|
if (!(node.id in this.nodeSet)) {
|
||||||
this.nodes.push(node);
|
this.nodes.push(node);
|
||||||
}
|
}
|
||||||
|
@ -76,9 +83,7 @@ Graph.prototype.addNodes = function() {
|
||||||
// accepts variable number of arguments, where each argument
|
// accepts variable number of arguments, where each argument
|
||||||
// is a string that becomes both node identifier and label
|
// is a string that becomes both node identifier and label
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
var name = arguments[i];
|
this.addNode(arguments[i]);
|
||||||
var node = new Node(name, {label:name});
|
|
||||||
this.addNode(node);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user