diff options
| author | Alon Levy <alon@pobox.com> | 2014-08-17 18:31:30 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-08-17 18:31:31 +0300 |
| commit | 49c6e53c2b677abfa8aa2adabd77f92605ee3744 (patch) | |
| tree | 147004e1ab2b4140d8b3497862cfbdaa2ed9cfe7 /scripts/rhizicore.js | |
| parent | a4206a91a314226bbff69094069e118bbd54bb65 (diff) | |
drag&drop load of json, plus save (kinda), some refactoring
save & load json moved from buttons to rhizicore.js
added a save as button (need to switch to normal ui for that menu, it's
fixed right now)
save not correct - instead of a save dialog since it is a json file the
browser just displays it (even though it's base64 encoded).
Diffstat (limited to 'scripts/rhizicore.js')
| -rw-r--r-- | scripts/rhizicore.js | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js index f72d5176..ac3988a8 100644 --- a/scripts/rhizicore.js +++ b/scripts/rhizicore.js @@ -379,6 +379,53 @@ function myGraph(el) { force.resume(); } + function load_from_json(json) { + var data = JSON.parse(json); + if (data == null) { + console.log('load callback: no data to load'); + return; + } + for(var i=0; i<data["nodes"].length; i++){ + var node=data.nodes[i]; + graph.addNodeComplete(node.id,node.type,"perm",new Date(node.start),new Date(node.end),node.status); + } + + for(var j=0; j<data["links"].length; j++){ + var link=data.links[j]; + graph.addLink(link.source,link.target,link.name,"perm"); + } + graph.recenterZoom(); + graph.update(); + } + this.load_from_json = load_from_json; + + function save_to_json() { + var d = {"nodes":[], "links":[]}; + console.log(nodes); + for(var i = 0 ; i < nodes.length ; i++){ + var node = nodes[i]; + d['nodes'].push({ + "id":node.id, + "type":node.type, + "state":"perm", + "start":node.start, + "end":node.end, + "status": node.status + }); + } + for(var j=0 ; j < links.length ; j++){ + var link = links[j]; + d['links'].push({ + "source":link.source.id, + "target":link.target.id, + "name":link.name + }); + } + return JSON.stringify(d); + } + this.save_to_json = save_to_json; + + force = d3.layout.force() .distance(120) .gravity(0.12) @@ -389,8 +436,6 @@ function myGraph(el) { nodes = force.nodes(); links = force.links(); - - var update = function() { vis.selectAll(".graph").remove(); |
