diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-16 17:37:42 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-12-16 17:37:42 +0200 |
| commit | ade19de410e0a789a921ec1666b278b2a64176d6 (patch) | |
| tree | c4c54b106de93609ca7bb70a20fd4be696715dbe /src/client/model/diff.js | |
| parent | c7d026b1d504323a8c61d51b726e5e8d2337fc4b (diff) | |
moving files around after repository merger
Diffstat (limited to 'src/client/model/diff.js')
| -rw-r--r-- | src/client/model/diff.js | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/src/client/model/diff.js b/src/client/model/diff.js new file mode 100644 index 00000000..8903b161 --- /dev/null +++ b/src/client/model/diff.js @@ -0,0 +1,187 @@ +"use strict" + +/** + * Diff module + */ +define([], + function() { + + /** + * A set of diff objects + */ + function Diff_Set(obj_spec) { + this.__diff_set_topo = []; + this.__diff_set_attr = []; + this.__diff_set_vis = []; + } + Diff_Set.prototype.add_diff_obj = function(diff_obj) { + if (diff_obj instanceof Topo_Diff) { + this.__diff_set_topo.push(diff_obj); + } + if (diff_obj instanceof Attr_Diff) { + this.__diff_set_attr.push(diff_obj); + } + if (diff_obj instanceof Vis_Diff) { + this.__diff_set_vis.push(diff_obj); + } + } + + /** + * Topological diff object + */ + function Topo_Diff(obj_spec) { + + this.link_set_rm = obj_spec.link_set_rm; + this.node_set_rm = obj_spec.node_set_rm; + this.node_set_add = obj_spec.node_set_add; + this.link_set_add = obj_spec.link_set_add; + + } + Topo_Diff.prototype.for_each_node_add = function(callback, this_arg) { + this.node_set_add.forEach(callback, this_arg); + } + + Topo_Diff.prototype.for_each_node_rm = function(callback, this_arg) { + this.node_set_rm.forEach(callback, this_arg); + } + + Topo_Diff.prototype.for_each_link_add = function(callback, this_arg) { + this.link_set_add.forEach(callback, this_arg); + } + + Topo_Diff.prototype.for_each_link_rm = function(callback, this_arg) { + this.link_set_rm.forEach(callback, this_arg); + } + + /** + * Attribute diff object, organized by type, where currently + * node,link types are supported + */ + function Attr_Diff(obj_spec) { + this.__type_node = {}; + this.__type_link = {}; + } + + Attr_Diff.prototype.init_attr_diff = function(type_name, id) { + + if ('node' != type_name && 'link' != type_name) { + console.error('attempt to init attribute diff for unsupported type: ' + type_name); + return; + } + + var type_field = '__type_' + type_name; + this[type_field][id] = { + '__attr_write' : {}, + '__attr_remove' : [] + }; + + return this; + } + + Attr_Diff.prototype.init_attr_diff_node = function(id) { + return this.init_attr_diff('node', id); + } + + Attr_Diff.prototype.init_attr_diff_link = function(id) { + return this.init_attr_diff('link', id); + } + + Attr_Diff.prototype.add_node_attr_write = function(n_id, attr_name, + attr_val) { + + if (undefined == this.__type_node[n_id]) { + this.init_attr_diff_node(n_id); + } + this.__type_node[n_id].__attr_write[attr_name] = attr_val; + return this; + } + + Attr_Diff.prototype.add_node_attr_rm = function(n_id, attr_name) { + if (undefined == this[n_id]) { + this.init_attr_diff(n_id); + } + this.__type_node[n_id].__attr_remove.push(attr_name); + return this; + } + + Attr_Diff.prototype.add_link_attr_write = function(l_id, attr_name, + attr_val) { + + if (undefined == this.__type_link[l_id]) { + this.init_attr_diff_link(l_id); + } + this.__type_link[l_id].__attr_write[attr_name] = attr_val; + return this; + } + + Attr_Diff.prototype.add_link_attr_rm = function(l_id, attr_name) { + if (undefined == this[l_id]) { + this.init_attr_diff(l_id); + } + this.__type_link[l_id].__attr_remove.push(attr_name); + return this; + } + + /** + * Visual diff object expressing any visual change to the state of a + * particular visualization type. + * + * @obj_spec if none is passed a default topo_diff is constructed + * with node,link add sets + */ + function Vis_Diff(obj_spec) { + } + + function new_topo_diff(obj_spec) { + /* + * validate obj_spec + */ + var ret; + if (undefined == obj_spec) { + obj_spec = { + node_set_add : [], + link_set_add : [], + } + ret = new Topo_Diff(obj_spec); + } else { + ret = new Topo_Diff(obj_spec); + } + return ret; + } + + function new_attr_diff(obj_spec) { + /* + * validate obj_spec + */ + // TODO + var ret = new Attr_Diff(obj_spec); + ret.__type_node = {}; // id-to-obj map + ret.__type_link = {}; // id-to-obj map + return ret; + } + + function new_vis_diff(obj_spec) { + /* + * validate obj_spec + */ + // TODO + var ret = new Vis_Diff(obj_spec); + return ret; + } + + function new_diff_set(obj_spec) { + /* + * validate obj_spec + */ + // TODO + var ret = new Diff_Set(obj_spec); + return ret; + } + + return { + new_topo_diff : new_topo_diff, + new_attr_diff : new_attr_diff, + new_vis_diff : new_vis_diff, + new_diff_set : new_diff_set, + } + });
\ No newline at end of file |
