1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
"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;
undefined == obj_spec && (obj_spec = {});
undefined == obj_spec.node_set_add && (obj_spec.node_set_add = []);
undefined == obj_spec.link_set_add && (obj_spec.link_set_add = []);
undefined == obj_spec.node_set_rm && (obj_spec.node_set_rm = []);
undefined == obj_spec.link_set_rm && (obj_spec.link_set_rm = []);
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,
is_attr_diff: function (obj) { return obj instanceof Attr_Diff; },
}
});
|