Simplify addNodes() even more by using variable number of arguments.
This commit is contained in:
parent
90b23f131e
commit
9ac764d634
|
@ -5,8 +5,8 @@
|
|||
<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'});
|
||||
|
|
13
springy.js
13
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user