summaryrefslogtreecommitdiff
path: root/scripts/rhizicore.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-20 13:25:32 +0300
committerAlon Levy <alon@pobox.com>2014-10-20 21:36:37 +0300
commitc919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch)
treedd6394603680976c48801b53321e8085b0db1505 /scripts/rhizicore.js
parentf1f4e937932f52c630831d0d501f8f8756b37531 (diff)
introduce require.js and rewrite tests
Yes, I'm being lazy. The purpose of require.js is to allow writing modules, i.e. individual smaller then the whole files with clear dependencies. This is achieved by using a new api provided by require.js: define, require, requirejs Read more at [requirejs] (http://requirejs.org) Tests have been rewritten to work correctly with require.js; they still use jsdom. Test output is now stored in the repository, all tests are run via run_tests.js; This is a hack - once a good harness (with assertions, suites - unittest like) presents itself it will be used. Hidden here is also using FileSaver for history saving, so history is saved to history.json instead to a random name. Plus dropping some dead code.
Diffstat (limited to 'scripts/rhizicore.js')
-rw-r--r--scripts/rhizicore.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js
index c73929f0..70ce0229 100644
--- a/scripts/rhizicore.js
+++ b/scripts/rhizicore.js
@@ -1,6 +1,9 @@
"use strict"
-//CORE VARIABLES
+define('rhizicore',
+['jquery', 'd3', 'util', 'history', 'textanalysis'],
+function($, d3, util, history, textanalysis) {
+var History = history.History;
var addednodes = [];
var vis;
@@ -200,12 +203,12 @@ function myGraph(el) {
}
return {graph_same: false};
}
- changed_nodes = set_diff(set_from_array(state_nodes.map(function(d) { return d.id.toLowerCase(); })),
- set_from_array(new_nodes.map(function (f) { return f.id.toLowerCase(); })));
+ changed_nodes = util.set_diff(util.set_from_array(state_nodes.map(function(d) { return d.id.toLowerCase(); })),
+ util.set_from_array(new_nodes.map(function (f) { return f.id.toLowerCase(); })));
// we allow any number of changed nodes as long as we it is 1 or 2 :)
if (changed_nodes.a_b.length <= 2) {
- set_old_id = set_from_array(changed_nodes.a_b);
- set_new_id = set_from_array(changed_nodes.b_a);
+ set_old_id = util.set_from_array(changed_nodes.a_b);
+ set_new_id = util.set_from_array(changed_nodes.b_a);
} else {
if (verbose) {
console.log('changed too many nodes');
@@ -499,10 +502,21 @@ function myGraph(el) {
}
}
+ function clear() {
+ nodes.length = 0;
+ links.length = 0;
+ }
+
+ function empty() {
+ return nodes.length == 0 && links.length == 0;
+ }
+ this.empty = empty;
+
function load_from_json(json) {
var data = JSON.parse(json);
var i, node, link;
+ clear();
if (data == null) {
console.log('load callback: no data to load');
return;
@@ -514,7 +528,7 @@ function myGraph(el) {
start:new Date(node.start),
end:new Date(node.end),
status:node.status});
- autoSuggestAddName(node.id);
+ textanalysis.autoSuggestAddName(node.id);
}
for(i = 0; i < data["links"].length; i++){
link = data.links[i];
@@ -1029,7 +1043,7 @@ function AddedUnique(newnode) {
$('#editform').keypress(function(e) {
if (graph.history !== undefined) {
- graph.history.record_keystrokes(KEYSTROKE_WHERE_EDIT_NODE, [e.which]);
+ graph.history.record_keystrokes(history.KEYSTROKE_WHERE_EDIT_NODE, [e.which]);
}
if (e.which == 13) {
$('.editinfo').css('top', -100);
@@ -1143,3 +1157,8 @@ function expand(obj){
}
obj.size = Math.max(obj.savesize, obj.value.length);
}
+return {
+ expand: expand,
+ graph: graph,
+}
+}); /* close define call */