From c919c4bfef4ad9e2dc25d040c0727dd29ad541ae Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 20 Oct 2014 13:25:32 +0300 Subject: 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. --- scripts/rhizicore.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'scripts/rhizicore.js') 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 */ -- cgit v1.3.1