summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/buttons.js48
-rw-r--r--scripts/rhizicore.js82
-rw-r--r--scripts/robot.js19
-rw-r--r--scripts/textanalysis.js13
4 files changed, 79 insertions, 83 deletions
diff --git a/scripts/buttons.js b/scripts/buttons.js
index 346e576b..69f0a6c7 100644
--- a/scripts/buttons.js
+++ b/scripts/buttons.js
@@ -17,24 +17,46 @@ $('.saveToFile').click(function() {
location.href = 'data:text/json;base64,' + window.btoa(json);
});
-$('.load').click(function(){
- var acceptLoad=true;
-
- if (nodes.length>0){
- acceptLoad = confirm('All unsaved changes will be deleted, are you sure?');
+var really_load = function() {
+ if (nodes.length > 0){
+ return confirm('All unsaved changes will be deleted, are you sure?');
}
+ return true;
+}
- if(acceptLoad){
- links=[]; // TODO - not global
- nodes=[]; // TODO - not global
- var json_blob = localStorage.getItem(key)
- graph.load_from_json(json_blob);
- }
+$('.file-load').on('change', function(event) {
+ var file = event.target.files[0];
+ var reader;
+ if (!really_load()) {
+ return;
+ }
+ if (file === undefined) {
+ return;
+ }
+ console.log(file);
+ reader = new FileReader();
+ reader.onload = (function(theFile) {
+ return function(e) {
+ var result = e.target.result;
+ if (e.target.readyState === FileReader.DONE) {
+ console.log('done reading ' + theFile.name);
+ console.log('got #' + result.length + ' bytes in ' + typeof(result));
+ graph.load_from_json(result);
+ }
+ }
+ })(file);
+ reader.readAsText(file, "text/javascript");
});
-$('.deliverabletest').click(function(){
- deliverableTest();
+$('.local-storage-load').click(function(){
+ if (!really_load()) {
+ return;
+ }
+ links=[]; // TODO - not global
+ nodes=[]; // TODO - not global
+ var json_blob = localStorage.getItem(key)
+ graph.load_from_json(json_blob);
});
$('.set-user').click(function() {
diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js
index 4692602b..d39471d1 100644
--- a/scripts/rhizicore.js
+++ b/scripts/rhizicore.js
@@ -31,7 +31,7 @@ function myGraph(el) {
function makeNewNode(spec) {
return {
'id': spec.id,
- 'text': spec.text,
+ 'name': spec.name,
'type': spec.type,
'state': spec.state,
'start': spec.start,
@@ -46,13 +46,13 @@ function myGraph(el) {
var start = 0,
end = 0;
var status = "unknown";
- var text = id;
+ var name = id;
id = id.toLowerCase();
var node = findNode(id, null);
if (node === undefined) {
var new_node = makeNewNode({
"id": id,
- "text": text,
+ "name": name,
"type": type,
"state": state,
"start": start,
@@ -66,9 +66,8 @@ function myGraph(el) {
}
}
- this.addNodeComplete = function(id, type, state, start, end, status) {
+ this.addNodeComplete = function(id, name, type, state, start, end, status) {
// No history recorded - this is a helper for loading from files / constant graphs
- var text = id;
id = id.toLowerCase();
var node = findNode(id, null);
if (node !== undefined) {
@@ -76,7 +75,7 @@ function myGraph(el) {
} else {
nodes.push(makeNewNode({
"id": id,
- "text": text,
+ "name": name,
"type": type,
"state": state,
"start": start,
@@ -224,7 +223,7 @@ function myGraph(el) {
}
this.editName = function(id, type, newname) {
- var new_text = newname;
+ var new_name = newname;
id = id && id.toLowerCase();
var new_id = newname.toLowerCase();
var index2 = undefined;
@@ -251,7 +250,7 @@ function myGraph(el) {
}
}else{
index.id = new_id;
- index.text = new_text;
+ index.name = new_name;
}
}
}
@@ -426,17 +425,19 @@ function myGraph(el) {
function load_from_json(json) {
var data = JSON.parse(json);
+ var i, node, link;
+
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(i = 0; i < data["nodes"].length; i++){
+ node = data.nodes[i];
+ graph.addNodeComplete(node.id, node.name, node.type,"perm",new Date(node.start),new Date(node.end),node.status);
autoSuggestAddName(node.id);
}
- for(var j=0; j<data["links"].length; j++){
- var link=data.links[j];
+ for(i = 0; i < data["links"].length; i++){
+ link = data.links[i];
graph.addLink(link.source,link.target,link.name,"perm");
}
graph.recenterZoom();
@@ -598,13 +599,16 @@ function myGraph(el) {
node.select('g.node text')
.text(function(d) {
+ if (!d.name) {
+ return "";
+ }
if (d.state === "temp" || d.state === 'chosen') {
- return d.text;
+ return d.name;
} else {
- if (d.text.length < 28) {
- return d.text;
+ if (d.name.length < 28) {
+ return d.name;
} else {
- return d.text.substring(0, 25) + "...";
+ return d.name.substring(0, 25) + "...";
}
}
});
@@ -676,8 +680,6 @@ function myGraph(el) {
node.exit().remove();
- //d3.select("body").on("mousedown", mousedown);
-
force.on("tick", tick);
//update deliverables
@@ -833,41 +835,6 @@ function tick(e) {
node.attr('visibility', 'visible');
}
-
-
-
-function deliverableTest() {
- links=[];
- nodes=[];
- var status = "unknown";
- var nodecounter = 150;
- for (var i = 0; i < nodecounter; i++) {
- if (Math.random() > 0.7) status = "done";
- else if (Math.random() > 0.5) status = "current";
- else status = "waiting";
- var end = randomDate(new Date(), new Date("01/01/2018"));
- var start = randomDate(new Date(), end);
- graph.addNodeComplete("Task " + i, "deliverable", "perm", start, end, status);
- }
-
- for (var i = 0; i < nodecounter; i++) {
- var endindex = Math.floor(Math.random() * nodecounter);
- var startindex = Math.floor(Math.random() * nodecounter);
- if (nodes[endindex].start > nodes[startindex].start && startindex !== endindex) {
- graph.addLink("Task " + startindex, "Task " + endindex, "depends on", "perm");
- } else {
- graph.addLink("Task " + endindex, "Task " + startindex, "depends on", "perm");
- }
- }
-
- function randomDate(start, end) {
- return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
- }
-
- graph.update();
-}
-
-
function showInfo(d, i) {
if (d.state !== "chosen") {
graph.highlightNode(d.id, null);
@@ -1066,8 +1033,15 @@ function customSize(type) {
}
function expand(obj){
+<<<<<<< HEAD
+ if (!obj.savesize) {
+ obj.savesize = obj.size;
+ }
+ obj.size = Math.max(obj.savesize, obj.value.length);
+=======
if (!obj.savesize)
obj.savesize = obj.size;
obj.size = Math.max(obj.savesize,obj.value.length);
+>>>>>>> #62
}
diff --git a/scripts/robot.js b/scripts/robot.js
index c8e2a0c8..3d499864 100644
--- a/scripts/robot.js
+++ b/scripts/robot.js
@@ -6,23 +6,18 @@ sentence+="#links and #nodes have #context and #meaning|";
sentence+="#entities and #concepts are #nodes|";
sentence+="We built this entire graph in 30 seconds, try it out yourself!";*/
-sentence+=' #Hi, this is #Rhizibot!|';
-sentence+='#Rhizi is a tool for creating interactive #Networks|';
-sentence+='With #Rhizi your #Text becomes a #Network"|';
-sentence+='Use the #hashtag(#) before a word to create it as #Node|';
+sentence+='##Rhizi is a tool for creating interactive #Networks|';
+sentence+='Create #Networks by writing #Sentences|';
+sentence+='like a #Tweet you can put a #Hashtag in your #Sentences|';
sentence+='#Hello|';
sentence+='#John|';
-sentence+='Use #commas("") if what you want to write #"multiple words" as a #Node|';
+sentence+='Put your text between #Commas to use #"Multiple words"|';
sentence+='#"John Smith"|';
sentence+='#"Beauty and the beast"|';
-sentence+='a #Node is connected to all other #Nodes in the #sentence|';
-sentence+='#John is a friend of #Tim|';
-sentence+='#"Beauty and the beast" is film by #Disney|';
-sentence+='Use the word #"and" to #"connect multiple things together"|';
+sentence+='Use the word #And to #"Connect multiple things together"|';
sentence+='#John likes #Apples and #Oranges and #Pistachio|';
-sentence+='You can choose the node type by using #"right arrow" or #"left arrow|"';
-sentence+='#Rhizi is useful for #"Mapping ideas" and "#"Creating info graphics" and #"Organising knowledge"|';
-sentence+="#You can click on any #Node to change and modify it's #Properties|";
+//sentence+='Choose the #"node type" by using the #"TAB key"|';
+sentence+='#Click on any #Node to change and modify it|';
sentence+='#Play around and have #Fun!|';
var robot = function (sentence) {
diff --git a/scripts/textanalysis.js b/scripts/textanalysis.js
index ecebdbeb..c1b02b38 100644
--- a/scripts/textanalysis.js
+++ b/scripts/textanalysis.js
@@ -76,7 +76,7 @@ var textAnalyser2 = function (newtext, finalize) {
ret.nodes.push({'id':id, 'type':type, 'state':state});
}
function addLink(src, dst, name, state) {
- ret.links.push({'sourceId':src, 'targetId':dst, 'name':name, 'state':state});
+ ret.links.push({'sourceId':src, 'targetId':dst, 'name':name ? name.trim() : "", 'state':state});
}
//Sentence Sequencing
@@ -138,7 +138,7 @@ var textAnalyser2 = function (newtext, finalize) {
}
}
if (newnodes.length === 0) {
- prefix += sentence[m];
+ prefix += (prefix.length > 0 ? ' ' : '') + sentence[m];
}
break;
}
@@ -146,7 +146,11 @@ var textAnalyser2 = function (newtext, finalize) {
//PREFIX not null case - put complete sentence in first link.
if (prefix) {
- newlinks[1] = prefix + " " + newnodes[0] + " " + newlinks[1] + newnodes[1];
+ newlinks[1] = prefix + " " + newnodes[0] +
+ (newlinks[1] !== undefined || newnodes[1] !== undefined ?
+ " " : "")
+ + (newlinks[1] !== undefined ? newlinks[1] : "")
+ + (newnodes[1] !== undefined ? newnodes[1] : "");
}
//WRITE COMPLETE SENTENCE
@@ -203,7 +207,8 @@ var textAnalyser2 = function (newtext, finalize) {
case "NODE":
addNode(newnodes[nodeindex], typeStack[nodeindex], typesetter);
if (!abnormalGraph) {
- addLink(newnodes[nodeindex - 1], newnodes[nodeindex], newlinks[linkindex], typesetter);
+ addLink(newnodes[nodeindex - 1], newnodes[nodeindex],
+ newlinks[linkindex], typesetter);
}
nodeindex++;
break;