-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathw3sink.js
3377 lines (2784 loc) · 92.4 KB
/
w3sink.js
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! w3sink v0.0.1 - 2014-10-14
* License: MIT */
/*
* CSS_tree() is used to store CSS for graphstream.
* It contains two identical tree-like structures, one for 'nodes' and one for 'edges'
* Structure is as follow:
*
* ├─ nodes
* │ ├── default
* │ ├── classes
* │ └── ids
* └─ edges
* ├── default
* ├── classes
* └── ids
*/
// Empty object.
function CSS_tree() {
this.nodes = {};
this.nodes.ids = {};
this.nodes.classes = {};
this.nodes.default = {};
this.edges = {};
this.edges.ids = {};
this.edges.classes = {};
this.edges.default = {};
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// ! !
// ! Problem if node/edge ID is just a number! !
// ! !
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Convert from a string containing CSS data to a CSS_tree() object.
function data_to_obj(data) {
// Use an empty tree structure as a starting point.
var new_CSS = new CSS_tree();
// Parse data.
var parser = new CSSParser();
var data_content = parser.parse(data, false, true);
for (var id_family = 0; id_family < data_content.cssRules.length; id_family++) {
var family = data_content.cssRules[id_family].mSelectorText;
var list = data_content.cssRules[id_family].declarations;
for (var id_property = 0; id_property < list.length; id_property++) {
var prop = list[id_property].property;
var val = list[id_property].values;
// Get a string containing the value(s) of the CSS key:value(s) pair.
var val_cnt = '';
for (var id_value = 0; id_value < val.length; id_value++) {
val_cnt += val[id_value].value + ' ';
}
val_cnt = val_cnt.substring(0, val_cnt.length - 1);
var id_name, class_name;
// NODES
if (family.substring(0, 4) === 'node') {
// IDs
if (family.contains('node#')) {
id_name = family.substring(5);
// If the entry does not exist yet, create it.
if (new_CSS.nodes.ids[id_name] === undefined) {
new_CSS.nodes.ids[id_name] = {};
}
// Feed the entry.
new_CSS.nodes.ids[id_name][prop] = val_cnt;
}
// Classes
else if (family.contains('node.')) {
// If the entry does not exist yet, create it.
class_name = family.substring(5);
if (new_CSS.nodes.classes[class_name] === undefined) {
new_CSS.nodes.classes[class_name] = {};
}
// Feed the entry.
new_CSS.nodes.classes[class_name][prop] = val_cnt;
}
// Root
else {
new_CSS.nodes.default[prop] = val_cnt;
}
}
// EDGES
if (family.substring(0, 4) === 'edge') {
// IDs
if (family.contains('edge#')) {
// If the entry does not exist yet, create it.
id_name = family.substring(5).toString();
if (new_CSS.edges.ids[id_name] === undefined) {
new_CSS.edges.ids[id_name] = {};
}
// Feed the entry.
new_CSS.edges.ids[id_name][prop] = val_cnt;
}
// Classes
else if (family.contains('edge.')) {
class_name = family.substring(5);
// If the entry does not exist yet, create it.
if (new_CSS.edges.classes[class_name] === undefined) {
new_CSS.edges.classes[class_name] = {};
}
// Feed the entry.
new_CSS.edges.classes[class_name][prop] = val_cnt;
}
// Root
else {
new_CSS.edges.default[prop] = val_cnt;
}
}
}
}
return new_CSS;
}
// Convert from "cn/ce id style:style_data" to CSS_tree structure.
// 'type' is 'node' or 'edge'.
function style_to_obj(type, id, style_data) {
var line = type + '#' + id + '{' + style_data + '}';
return data_to_obj(line);
}
// Update 'main_CSS' with 'new_part' (both are CSS_tree).
function update_CSS(main_CSS, new_part) {
var main_clone = _.clone(main_CSS, true);
_.merge(main_CSS, new_part);
// Return true if the update changed main_CSS content.
return is_different(main_CSS, main_clone);
}
// Change a CSS_tree.?.default to a string.
// Useful to update graph.default_node_style and graph.default_edge_style.
function css_to_string(css_default) {
var string = '';
for (var value in css_default) {
string += value + ':' + css_default[value] + ';';
}
return string;
}
// Apply style 'key:value' to 'type' object of ID 'id'.
// E.g.: apply_css('node', 'n1', 'size', '10')
function apply_css(type, id, key, value) {
if (type === 'node') {
graph.nodes[id].setStyle(key + ':' + value);
}
else if (type === 'edge') {
graph.edges[id].setStyle(key + ':' + value);
}
/*
else
console.log('Error of type: ' + type + ' for ' + id + ' in apply_css().');
*/
}
// Refresh a single node according to content of CSS tree.
// Parameters are:
// - tree: CSS object
// - current_node_id : node to refresh
// - is_single: if true, update graph.default_node_style, if needed
function read_css_for_node(tree, current_node_id, is_single) {
var node_default = tree.nodes.default;
var node_classes = tree.nodes.classes;
var node_ids = tree.nodes.ids;
var key;
// If we deal with a single node, update graph.default_node_style, if needed.
if (is_single) {
var old_default = style_to_obj('node', 'dummy_node', graph.default_node_style);
var new_default = style_to_obj('node', 'dummy_node', css_to_string(node_default));
update_CSS(old_default, new_default);
graph.default_node_style = css_to_string(old_default.nodes.ids.dummy_node);
}
//
// node
//
for (key in node_default) {
apply_css('node', current_node_id, key, node_default[key]);
}
//
// node.xyz
//
for (var n_class in node_classes) {
if (n_class === graph.nodes[current_node_id].className) {
for (key in node_classes[n_class]) {
apply_css('node', current_node_id, key, node_classes[n_class][key]);
}
}
}
//
// node#xyz
//
for (var n_id in node_ids) {
if (n_id === current_node_id) {
for (key in node_ids[n_id]) {
apply_css('node', current_node_id, key, node_ids[n_id][key]);
}
}
}
}
// Refresh a single edge according to content of CSS tree.
// Parameters are:
// - tree: CSS object
// - current_edge_id : edge to refresh
// - is_single: if true, update graph.default_edge_style, if needed
function read_css_for_edge(tree, current_edge_id, is_single) {
var edge_default = tree.edges.default;
var edge_classes = tree.edges.classes;
var edge_ids = tree.edges.ids;
var key;
// If we deal with a single edge, update graph.default_edge_style, if needed.
if (is_single) {
var old_default = style_to_obj('edge', 'dummy_edge', graph.default_edge_style);
var new_default = style_to_obj('edge', 'dummy_edge', css_to_string(edge_default));
update_CSS(old_default, new_default);
graph.default_edge_style = css_to_string(old_default.edges.ids.dummy_edge);
}
//
// edge
//
for (key in edge_default) {
apply_css('edge', current_edge_id, key, edge_default[key]);
}
//
// edge.xyz
//
for (var e_class in edge_classes) {
if (e_class === graph.edges[current_edge_id].className) {
for (key in edge_classes[e_class]) {
apply_css('edge', current_edge_id, key, edge_classes[e_class][key]);
}
}
}
//
// edge#xyz
//
for (var e_id in edge_ids) {
if (e_id === current_edge_id) {
for (key in edge_ids[e_id]) {
apply_css('edge', current_edge_id, key, edge_ids[e_id][key]);
}
}
}
}
// Read all content from tree to refresh a single object.
function read_css_for_obj(tree, type, id) {
if (type === 'node') {
read_css_for_node(tree, id, true);
}
else if (type === 'edge') {
read_css_for_edge(tree, id, true);
}
/*
else
console.log('Problem of type: ' + type + ' in read_css_for_obj(' + id + ')...');
*/
}
// Read all 'nodes' content from tree, beginning with 'default', then 'classes', then 'ids'.
function read_nodes_css(tree) {
var node_default = tree.nodes.default;
var node_classes = tree.nodes.classes;
var node_ids = tree.nodes.ids;
// Update, if needed, graph.default_node_style.
var old_default = style_to_obj('node', 'dummy_node', graph.default_node_style);
var new_default = style_to_obj('node', 'dummy_node', css_to_string(node_default));
update_CSS(old_default, new_default);
graph.default_node_style = css_to_string(old_default.nodes.ids.dummy_node);
// Refresh nodes one by one.
for (var id in graph.nodes) {
read_css_for_node(tree, id, false);
}
}
// Read all 'edges' content from tree, beginning with 'default', then 'classes', then 'ids'.
function read_edges_css(tree) {
var edge_default = tree.edges.default;
var edge_classes = tree.edges.classes;
var edge_ids = tree.edges.ids;
// Update, if needed, graph.default_edge_style.
var old_default = style_to_obj('edge', 'dummy_edge', graph.default_edge_style);
var new_default = style_to_obj('edge', 'dummy_edge', css_to_string(edge_default));
update_CSS(old_default, new_default);
graph.default_edge_style = css_to_string(old_default.edges.ids.dummy_edge);
// Refresh edges one by one.
for (var id in graph.edges) {
read_css_for_edge(tree, id, false);
}
}
// Read all content from tree to refresh the whole graph.
function read_css(tree) {
read_nodes_css(tree);
read_edges_css(tree);
}
// Check if old_CSS's content and new_CSS's content are different.
function is_different(old_CSS, new_CSS) {
return !_.isEqual(_.reduce(old_CSS), _.reduce(new_CSS));
}
// Get content from CSS file and apply it to the graph objects as needed.
function handle_css_content(url, main_CSS_object) {
var callback = function(data) {
// Create a new CSS_tree object filled with the CSS file's content from 'url'.
var new_CSS = data_to_obj(data);
// Update the main CSS_tree object with the newly created object's content.
var is_different = update_CSS(main_CSS_object, new_CSS);
// If that update changed the main CSS_tree, refresh the 3D components of the graph.
if (is_different) {
read_css(main_CSS_object);
}
};
$.get(url).success(callback);
}
(function(exports) {
'use strict';
/*
* This object will contains the CSS structure for the whole graph.
*/
var CSS_structure = new exports.CSS_tree();
/**
* Extends a class.
*
* @param source
* the super class prototype
* @param target
* the new class prototype
*/
function extend(source, target) {
for (var element in source) {
if (!target.hasOwnProperty(element))
target[element] = source[element];
}
}
/**
* Convert a string size in pixel size.
*/
function getSize(element, value) {
var re = /(\d+)(\w+)?/;
var s = re.exec(value);
return s[1];
}
/**
* Build a new source object. It allows to connect sinks and send
* events. A source has an id which is used as sourceId for sent
* events.
*
* @param id
* id of the source
*/
function Source(id) {
this.id = id;
this.timeId = 0;
this.sinks = [];
}
/*
* Prototype of Source.
*/
Source.prototype = {
/**
* Register a new Sink on this source.
*/
addSink: function(sink) {
this.sinks.push(sink);
},
/**
* Remove a previously registered sink.
*/
removeSink: function(sink) {
},
/**
* Get a new time id.
*/
newTimeId: function() {
return this.timeId++;
},
/**
* Send a nodeAdded event.
*
* @param nodeId
* id of the added node
*/
sendNodeAdded: function(nodeId) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].nodeAdded(this.id, t, nodeId);
},
/**
* Send a nodeRemoved event.
*
* @param nodeId
* id of the node being removed
*/
sendNodeRemoved: function(nodeId) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].nodeRemoved(this.id, t, nodeId);
},
/**
* Send a nodeAttributeAdded event.
*
* @param nodeId
* id of the node
* @param attrid
* key of the attribute
* @param value
* value of the attribute
*/
sendNodeAttributeAdded: function(nodeId, attrId, value) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].nodeAttributeAdded(this.id, t, nodeId, attrId, value);
},
/**
* Send a nodeAttributeChanged event.
*
* @param nodeId
* id of the node
* @param attrid
* key of the attribute
* @param [optional] oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
sendNodeAttributeChanged: function(nodeId, attrId, oldValue, newValue) {
var t = this.newTimeId();
if (newValue === undefined)
newValue = oldValue;
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].nodeAttributeChanged(this.id, t, nodeId, attrId,
oldValue, newValue);
},
/**
* Send a nodeAttributeRemoved event.
*
* @param nodeId
* id of the node
* @param attrid
* key of the attribute
*/
sendNodeAttributeRemoved: function(nodeId, attrId) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].nodeAttributeRemoved(this.id, t, nodeId, attrId);
},
/**
* Send an edgeAdded event.
*
* @param edgeId
* id of the new edge
* @param source
* id of the source node of the edge
* @param target
* id of the target node of the edge
* @param [optional] directed
* true if edge is directed
*/
sendEdgeAdded: function(edgeId, source, target, directed) {
var t = this.newTimeId();
if (directed === undefined)
directed = false;
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].edgeAdded(this.id, t, edgeId, source, target, directed);
},
/**
* Send an edgeRemoved event.
*
* @param edgeId
* id of the edge being removed
*/
sendEdgeRemoved: function(edgeId) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].edgeRemoved(this.id, t, edgeId);
},
/**
* Send a edgeAttributeAdded event.
*
* @param edgeId
* id of the edge
* @param attrid
* key of the attribute
* @param value
* value of the attribute
*/
sendEdgeAttributeAdded: function(edgeId, attrId, value) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].edgeAttributeAdded(this.id, t, edgeId, attrId, value);
},
/**
* Send a edgeAttributeChanged event.
*
* @param edgeId
* id of the edge
* @param attrid
* key of the attribute
* @param [optional] oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
sendEdgeAttributeChanged: function(edgeId, attrId, oldValue, newValue) {
var t = this.newTimeId();
if (newValue === undefined)
newValue = oldValue;
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].edgeAttributeChanged(this.id, t, edgeId, attrId,
oldValue, newValue);
},
/**
* Send a edgeAttributeRemoved event.
*
* @param edgeId
* id of the edge
* @param attrid
* key of the attribute
*/
sendEdgeAttributeRemoved: function(edgeId, attrId) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].edgeAttributeRemoved(this.id, t, edgeId, attrId);
},
/**
* Send a graphAttributeAdded event.
*
* @param attr
* key of the attribute
* @param value
* value of the attribute
*/
sendGraphAttributeAdded: function(attr, value) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++) {
this.sinks[i].graphAttributeAdded(this.id, t, attr, value);
}
},
/**
* Send a graphAttributeChanged event.
*
* @param attrid
* key of the attribute
* @param [optional] oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
sendGraphAttributeChanged: function(attrId, oldValue, newValue) {
var t = this.newTimeId();
if (newValue === undefined)
newValue = oldValue;
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].graphAttributeChanged(this.id, t, attrId, oldValue,
newValue);
},
/**
* Send a graphAttributeRemoved event.
*
* @param attrid
* key of the attribute
*/
sendGraphAttributeRemoved: function(attrId) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].graphAttributeRemoved(this.id, t, attrId);
},
/**
* Send a graphClearedEvent.
*/
sendGraphCleared: function() {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].graphCleared(this.id, t);
},
/**
* Send a stepBegins event.
*
* @param step
* step
*/
sendStepBegins: function(step) {
var t = this.newTimeId();
for (var i = 0; i < this.sinks.length; i++)
this.sinks[i].stepBegins(this.id, t, step);
}
};
/**
* Build a new Sink object.
*/
function Sink() {}
/*
* The Sink prototype
*/
Sink.prototype = {
/**
* A new node has been added.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param nodeId
* id of the new node
*/
nodeAdded: function(sourceId, timeId, nodeId) {},
/**
* A node will be removed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param nodeId
* id of the node being removed
*/
nodeRemoved: function(sourceId, timeId, nodeId) {},
/**
* A new attribute has been added on a node.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param nodeId
* id of the node
* @param attrId
* key of the attribute
* @param value
* value of the attribute
*/
nodeAttributeAdded: function(sourceId, timeId, nodeId, attrId, value) {},
/**
* An attribute of a node has been changed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param nodeId
* id of the node
* @param attrId
* key of the attribute
* @param oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
nodeAttributeChanged: function(sourceId, timeId, nodeId, attrId, oldValue,
newValue) {},
/**
* An attribute of a node has been removed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param nodeId
* id of the node
* @param attrId
* key of the attribute
*/
nodeAttributeRemoved: function(sourceId, timeId, nodeId, attrId) {},
/**
* A new edge has been added.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param edgeId
* id of the new edge
* @param source
* id of the source node of the edge
* @param target
* id of the target node of the edge
* @param directed
* true if edge is directed
*/
edgeAdded: function(sourceId, timeId, edgeId, source, target, directed) {},
/**
* A new edge will be removed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param edgeId
* id of the edge being removed
*/
edgeRemoved: function(sourceId, timeId, edgeId) {},
/**
* An attribute of an edge has been added.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param edgeId
* id of the edge
* @param attrId
* key of the attribute
* @param value
* value of the attribute
*/
edgeAttributeAdded: function(sourceId, timeId, edgeId, attrId, value) {},
/**
* An attribute of an edge has been changed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param edgeId
* id of the edge
* @param attrId
* key of the attribute
* @param oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
edgeAttributeChanged: function(sourceId, timeId, edgeId, attrId, oldValue,
newValue) {},
/**
* An attribute of an edge has been removed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param edgeId
* id of the edge
* @param attrId
* key of the attribute
* @param oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
edgeAttributeRemoved: function(sourceId, timeId, edgeId, attrId) {},
/**
* An attribute of the graph has been added.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param attrId
* key of the attribute
* @param value
* value of the attribute
*/
graphAttributeAdded: function(sourceId, timeId, attrId, value) {},
/**
* An attribute of the graph has been changed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param attrId
* key of the attribute
* @param oldValue
* previous value of the attribute
* @param newValue
* new value of the attribute
*/
graphAttributeChanged: function(sourceId, timeId, attrId, oldValue,
newValue) {},
/**
* An attribute of the graph has been removed.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param attrId
* key of the attribute
*/
graphAttributeRemoved: function(sourceId, timeId, attrId) {},
/**
* The graph has been cleared.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
*/
graphCleared: function(sourceId, timeId) {},
/**
* A new step has begun.
*
* @param sourceId
* id of the source who send the event
* @param timeId
* timeId of the event
* @param step
* timestamp of the step
*/
stepBegins: function(sourceId, timeId, step) {}
};
/**
* Build a new Element object. Element is the base for GraphStream
* objects with attributes.
*
* @param graph
* the graph object containing the element
* @param type
* type of element given as a string
* @param id
* id of the element, should be unique according to the
* graph and type
*/
function Element(graph, type, id) {
this.id = id;
this.type = type;
this.graph = graph;
this.attributes = {};
}
/*
* The Element prototype
*/
Element.prototype = {
/**
* Get an attribute of this element.
*
* @param key
* key of the attribute
*/
getAttribute: function(key) {
return this.attributes[key];
},
/**
* Set an attribute of this element.
*
* @param key
* key of the attribute
* @param value
* new value of the attribute
*/
setAttribute: function(key, value) {
if (value === null) {
delete this.attributes[key];
} else {
this.attributes[key] = value;
}
},
/**
* Test if this element contains an attribute.
*
* @param key
* key of the attribute
*/
hasAttribute: function(key) {
return this.attributes.hasOwnProperty(key);
},
removeAttribute: function(key) {
delete this.attributes[key];
},
setFill: function(color) {},
setStroke: function(color) {},
setStrokeWidth: function(size) {},
setSize: function(size) {},
setShape: function(shape) {},
setLabel: function(label) {},
setHide: function(is_visible) {},
setClass: function(ui_class) {},
setStyle: function(style) {