Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ Springy 1.1+ supports simplified API for adding nodes and edges, see
['mark', 'other']
);

Springy 1.2+ also accepts JSON, see
Springy 1.2+ also accepts JSON with node attributes, see
[demo-json.html](http://dhotson.github.com/springy/demo-json.html):

graphJSON = {
"nodes": ["mark", "higgs", "other", "etc"],
"nodes": [
["mark", {"label":"Mark", "color":"#0000ff"}],
"higgs",
"other",
"etc"
],
"edges": [
["mark", "higgs"],
["mark", "higgs", {"label":"Foo", "color":"#ff0000"}],
["mark", "etc"],
["mark", "other"]
]
Expand Down
17 changes: 12 additions & 5 deletions springy.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,19 @@
// 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, {label:name});
var arg = arguments[i];
var node;
if (typeof arg === "string") {
node = new Node(arg, {label:arg});
} else {
node = new Node(arg[0], arg[1]);
}

this.addNode(node);
}
};


Graph.prototype.addEdge = function(edge) {
var exists = false;
this.edges.forEach(function(e) {
Expand Down Expand Up @@ -168,14 +175,15 @@

{
"nodes": [
"center",
["center", {"label":"Center","color":"#ff0000"}],
"left",
"right",
"up",
"satellite"
],
"edges": [
["center", "left"],
["center", "left", {"label":"Foo"},"color":"#0000ff"],

["center", "right"],
["center", "up"]
]
Expand All @@ -193,7 +201,6 @@
}
}


// find the edges from node1 to node2
Graph.prototype.getEdges = function(node1, node2) {
if (node1.id in this.adjacency
Expand Down