-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphicGraph.js
2044 lines (2021 loc) · 84.1 KB
/
GraphicGraph.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
//GraphicGraph.js
//author : Adrien Basso Blandin, ENS Lyon / Harvard Medical School
//this file is under Gnu LGPL licence
//this file is part of the Executable Knowledge project
//graphical graph version
define(["d3/d3.min.js","d3/d3-context-menu.js","LayeredGraph.js","DynamicGraph.js"],function (d3,d3ContextMenu,LayeredGraph,DynamicGraph){ return function GraphicGraph(containerid){//define a graphical graph with svg objects
(function(){console.log("Graph G loaded")}())
var rewriter;//the current modification stack
var containerID=containerid;
var layerG;//the current layered graph data structure
var width;
var height;//menu is 30px heigth
var svg;
var svg_content;
var drag;
var dynG;//the force layout graph for this graphical graph
var s_node,s_action,s_link,s_binder;//graphical object for node,action,link and binders
var node_count=0;
var binder_count=0;
var first_init;
var nugget_add,edition,kr_show,lcg_view,kappa_view;//edition mod
var ctx_mode=false;
var self=this;
var nuggets=[];
var lcgG,nuggG,lcgDynG,lcgDrag;//layered graph for lcg and nuggets
var lcgS,nuggS,nuggDynG,nuggDrag;//stack for lcg and nuggets
var modified=true;
var bnd_cp =0;
var rev_cp =0;
var brk_cp =0;
var mod_cp =0;
var syn_cp =0;
var deg_cp =0;
this.findByName = function findByName(label,cls,fcls,path){//find a node by its name+path+class+father class
var cl_ok=false,lb_ok=false,p_ok=true;
for(var i=0;i<layerG.nodes.length;i++){
var tmp_node=layerG.nodes[i];
cl_ok=(tmp_node.classes.join(",")==cls.join(",")) && (fcls==null || fcls.length==0 || (tmp_node.father!=null && typeof(layerG.nodesHash[tmp_node.father])!="undefined" && layerG.nodesHash[tmp_node.father]!=null && layerG.nodes[layerG.nodesHash[tmp_node.father]].classes.join(",")==fcls.join(",")));
if(cl_ok) {
for(var j=0;j<label.length;j++)
lb_ok=lb_ok || (tmp_node.label.indexOf(label[j])!=-1);
}
if(cl_ok && lb_ok){
for(var j=path.length-1;j>=0;j--){
if(tmp_node.father!=null){
tmp_node=layerG.nodes[layerG.nodesHash[tmp_node.father]];
p_ok=tmp_node.label.indexOf(path[j])!=-1 && p_ok;
}
else if(j!=0) p_ok = false;
}
}
if(cl_ok && lb_ok && p_ok) return layerG.nodes[i];
else{
cl_ok=false;
lb_ok=false;
p_ok=true;
}
}return null;
}
this.lastNode = function lastNode(){//return the last node ID
return "n"+(node_count-1);
}
this.getLG = function getLG(){//return a pointer to the current layered graph warning : modifying the lg can result in incoherences
return layerG;
}
this.wakeUp = function wakeUp(val){//speed up tick function
dynG.getForce().start();
var fixed_ids=svg_content.selectAll("g").filter(function(d){return d.fixed});
if(!(typeof(val)!="undefined" && val!=null && !val)){
svg_content.selectAll("g").filter(function(d){return d.classes[0]=="agent" || d.classes[0]=="action"}).classed("fixed",function(d){return d.fixed=false;});
}
for(var i=0;i<300;i++){
dynG.getForce().tick();
}
if(first_init)
svg_content.selectAll("g").filter(function(d){return d.classes[0]=="agent" || d.classes[0]=="action"}).classed("fixed",function(d){return d.fixed=true;});
first_init=true;
fixed_ids.classed("fixed",function(d){return d.fixed=true;});
};
this.log = function log(){//output layerGraph data
layerG.log();
};
//init the graphic graph
this.init = function init(){
//defining graph representation size
width=document.getElementById(containerID).getBoundingClientRect().width;
height =document.getElementById(containerID).getBoundingClientRect().height-30;//menu is 30px heigth
//LCG View
lcgG=new LayeredGraph();//layered graph for lcg
lcgS=[];//stack for LCG transformation
lcgDynG=new DynamicGraph(lcgG,height,width);
lcgDynG.init();
lcgDynG.getForce().on("tick",tick);
lcgDrag=lcgDynG.getForce().drag().on("dragstart", dragstart);
//KR View
nuggG=new LayeredGraph();//layered grap for nuggets
nuggS=[];//stack for nugget transformation
nuggDynG=new DynamicGraph(nuggG,height,width);
nuggDynG.init();
nuggDynG.getForce().on("tick",tick);
nuggDrag=nuggDynG.getForce().drag().on("dragstart", dragstart);
//initialize
first_init=false;
var zoom = d3.behavior.zoom()
.scaleExtent([0.02, 1])
.on("zoom", zoomed);
/*var drg = d3.behavior.drag()
.origin(function(d) { return d; })
.on("dragstart", dragstarted)
.on("drag", dragged)
.on("dragend", dragended);*/
svg=d3.select("#"+containerID).append("svg:svg")
.attr("width",width)
.attr("height",height);
svg.append("svg:defs").selectAll("marker")
.data(["pos_end","neg_end"]) // Different link/path types can be defined here
.enter().append("svg:marker") // This section adds in the arrows
.attr("id", function(d){return d;})
.attr("refX", 40)
.attr("refY", 7)
.attr("markerWidth", 13)
.attr("markerHeight", 13)
.attr("orient", "auto")
.attr("markerUnits","strokeWidth")
.append("svg:path")
.attr("d", "M2,2 L2,13 L8,7 L2,2");
svg.on("contextmenu",d3ContextMenu(function(){return svgMenu();}));
//svg=svg_pan.append("g").call(zoom).call(drg);
svg.call(zoom);
svg_content=svg.append("g").classed("svg_zoom_content",true);
d3.select("#"+containerID).append("div")
.classed("n_tooltip",true)
.style("visibility","hidden");
d3.select("#"+containerID).append("div")
.classed("s_tooltip",true)
.style("visibility","hidden");
this.setState("kr_view");
//dynG.getForce().start();
};
function zoomed() {
if(d3.event.sourceEvent==null || !d3.event.sourceEvent.ctrlKey)return;
//d3.event.stopPropagation;
svg_content.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
//update all the SVG elements
var update = function(){
//links svg representation
dynG.init();
s_link = svg_content.selectAll(".link")
.data(layerG.links, function(d) { return d.source.id + "-" + d.target.id; });
s_link.enter().insert("line","g")
.classed("link",true)
.classed("links",function(d){return d.e_class=="link"})
.classed("parent",function(d){return d.e_class=="parent"})
.classed("influence",function(d){return d.e_class=="positive" || d.e_class=="negative"})
.classed("positive",function(d){return d.e_class=="positive"})
.classed("negative",function(d){return d.e_class=="negative"});
d3.selectAll(".links").on("contextmenu",d3ContextMenu(function(){return edgeCtMenu();}));
d3.selectAll(".influence").on("contextmenu",d3ContextMenu(function(){return edgeCtMenu();}));
d3.selectAll(".positive").attr("marker-end", "url(#pos_end)");
d3.selectAll(".negative").attr("marker-end", "url(#neg_end)");
s_link.exit().remove();
//none action nodes svg representation
s_node = svg_content.selectAll("g.node")
.data(function(){return layerG.nodes.filter(function(d){return d.classes[0]!="action"})}, function(d) { return d.id;});
var nodeEnter = s_node.enter().insert("g")
.classed("node",true)
.classed("agent",function(d){return d.classes[0]=="agent"})
.classed("key_res",function(d){return d.classes[0]=="key_res"})
.classed("attribute",function(d){return d.classes[0]=="attribute"})
.classed("flag",function(d){return d.classes[0]=="flag"})
.classed("region",function(d){return d.classes[0]=="region"})
.call(drag)
.on("mouseover",mouseOver)
.on("mouseout",mouseOut)
.on("click",clickHandler)
.on("contextmenu",d3ContextMenu(function(){return nodeCtMenu();}));
nodeEnter.insert("circle")
.attr("r", function(d){return d.toInt()});
nodeEnter.insert("text")
.classed("nodeLabel",true)
.attr("x", 0)
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.text(function(d) {if(d.label.length>0) {return d.label[0].length>7?d.label[0].substring(0,5).concat("..."):d.label[0];} else return d.id})
.attr("font-size", function(d){if(d.classes[0]!="action")return (d.toInt()/2)+"px"; else (d.toInt()/3)+"px";})
.on("dblclick",clickText);
s_node.exit().remove();
//action nodes svg representation
s_action = svg_content.selectAll("g.action")
.data(function(){return layerG.nodes.filter(function(d){return d.classes[0]=="action" && d.classes[1]!="binder"})}, function(d) { return d.id;});
var actionEnter = s_action.enter().insert("g")
.classed("action",true)
.classed("mod",function(d){return d.classes[1]=="mod"})
.classed("bnd",function(d){return d.classes[1]=="bnd"})
.classed("revers",function(d){return d.classes[1]=="bnd" && d.classes[2]=="revers"})
.classed("brk",function(d){return d.classes[1]=="brk"})
.classed("syn",function(d){return d.classes[1]=="syn"})
.classed("deg",function(d){return d.classes[1]=="deg"})
.classed("pos",function(d){return d.classes[1]=="mod" && d.classes[2]=="pos"})
.classed("neg",function(d){return d.classes[1]=="mod" && d.classes[2]=="neg"})
.call(drag)
.on("mouseover",mouseOver)
.on("mouseout",mouseOut)
.on("click",clickHandler)
.on("contextmenu",d3ContextMenu(function(){return actCtMenu();}));
actionEnter.insert("rect")
.attr("width", function(d){return d.toInt()})
.attr("height", function(d){return d.toInt()/2});
actionEnter.insert("text")
.classed("nodeLabel",true)
.attr("x", function(d){return d.toInt()/2;})
.attr("dy", function(d){return d.toInt()/4;})
.attr("text-anchor", "middle")
.text(function(d) {if(d.label.length>0) {return d.label[0].length>7?d.label[0].substring(0,5).concat("..."):d.label[0];} else return d.id})
.attr("font-size", function(d){if(d.classes[0]!="action")return (d.toInt()/2)+"px"; else (d.toInt()/3)+"px";})
.on("dblclick",clickText);
s_action.exit().remove();
s_binder = svg_content.selectAll("circle.binder")
.data(function(){return layerG.nodes.filter(function(d){return d.classes[0]=="action" && d.classes[1]=="binder"})}, function(d) { return d.id;});
var binderEnter = s_binder.enter().insert("circle")
.classed("binder",true)
.attr("r", function(d){return d.toInt()})
.on("contextmenu",d3ContextMenu(function(){return binderCtMenu();}));
s_binder.exit().remove();
dynG.getForce().start();
//layerG.log();
};
//show up new svg element only if there position datas have been computed
var tick = function(){
if(first_init || dynG.getForce().alpha()<=0.00501){
s_node.attr("transform", function(d) {
d.x=Math.max(d.toInt(), Math.min(width - d.toInt(), d.x));
d.y=Math.max(d.toInt(), Math.min(height - d.toInt(), d.y));
return "translate(" + d.x + "," + d.y + ")";
});
s_action.attr("transform", function(d) {
d.x=Math.max(d.toInt()/4, Math.min(width - d.toInt(), d.x));
d.y=Math.max(d.toInt()/8, Math.min(height - d.toInt()/4, d.y));
return "translate(" + d.x + "," + d.y + ")";
});
s_binder.attr("cx",function(d) {return getNodeX(d);})
.attr("cy",function(d) {return getNodeY(d);});
s_link.attr("x1", function(d){return getNodeX(d.source);})
.attr("y1", function(d){return getNodeY(d.source);})
.attr("x2", function(d){return getNodeX(d.target);})
.attr("y2", function(d){return getNodeY(d.target);});
first_init=true;
}
};
var getNodeX = function(node){//return the x position on a specific node
if(node.classes[0]=="action" && node.classes[1]=="binder"){
if(node.classes[2]=="left" && node.father!=null)
return layerG.nodes[layerG.nodesHash[node.father]].x;
else if(node.classes[2]=="right" && node.father!=null)
return layerG.nodes[layerG.nodesHash[node.father]].x+layerG.nodes[layerG.nodesHash[node.father]].toInt();
}else if(node.classes[0]=="action"){
return node.x+node.toInt()/2
}else{
return node.x;
}
};
var getNodeY = function(node){//return the y position on a specific node
if(node.classes[0]=="action" && node.classes[1]=="binder" && node.father!=null)
return layerG.nodes[layerG.nodesHash[node.father]].y+layerG.nodes[layerG.nodesHash[node.father]].toInt()/4;
else if(node.classes[0]=="action")
return node.y+node.toInt()/4
else
return node.y;
};
this.getSvg = function getSvg(){//return the svg
return svg;
};
this.addNode = function addNode(classes,label,path,x,y){//add a new node in the svg AND in the graph structure
dynG.getForce().stop();
layerG.addNode(classes,"n"+node_count,x,y,(typeof(x)!='undefined' && typeof(y)!='undefined'));
stack(layerG,layerG.removeNode,["n"+node_count]);
layerG.addLabel("n"+node_count,label);
stack(layerG,layerG.rmLabel,["n"+node_count,label]);
for(var i=path.length-1;i>0;i--){
if(typeof(layerG.nodesHash[path[i]])=='undefined'){
console.log("undefined path : "+path[i]+"for n"+node_count);
return;
}if(layerG.nodes[layerG.nodesHash[path[i]]].father==null || layerG.nodes[layerG.nodesHash[path[i]]].father!=path[i-1]){
console.log("incorrect path !");
console.log(path);
return;
}
}if(path.length>0){
layerG.setFather("n"+node_count,path[path.length-1]);
stack(layerG,layerG.removeParenting,["n"+node_count]);
}
node_count++;
update();
//dynG.getForce().on("tick",tick);
//dynG.getForce().start();
};
this.mergeNode = function mergeNode(new_nodeID,old_nodeID){//mergeDIFF both
dynG.getForce().stop();
if(layerG.nodes[layerG.nodesHash[new_nodeID]].classes.join('_') == layerG.nodes[layerG.nodesHash[old_nodeID]].classes.join('_') /*&& layerG.getPath(new_nodeID).join('_') == layerG.getPath(old_nodeID).join('_')*/){
/* if action : call merge on both binders and then on action!*/
if(layerG.nodes[layerG.nodesHash[new_nodeID]].classes[0]=="action" && layerG.nodes[layerG.nodesHash[new_nodeID]].classes[1]!="binder"){
for(var i=0;i<layerG.nodes[layerG.nodesHash[new_nodeID]].sons.length;i++){
var tmp_nd=layerG.nodes[layerG.nodesHash[layerG.nodes[layerG.nodesHash[new_nodeID]].sons[i]]];
if(tmp_nd.classes[0]=="action" && tmp_nd.classes[1]=="binder"){
for(var j=0;j<layerG.nodes[layerG.nodesHash[old_nodeID]].sons.length;j++){
var tmp_nd2=layerG.nodes[layerG.nodesHash[layerG.nodes[layerG.nodesHash[old_nodeID]].sons[j]]];
if(tmp_nd2.classes[0]=="action" && tmp_nd2.classes[1]=="binder" && tmp_nd2.classes[2]==tmp_nd.classes[2]){
i--;//carefull !!!! the node is removed from the sons of the "new_node" ! i need to be decremented !
this.mergeNode(tmp_nd.id,tmp_nd2.id);
}
}
}
}
}
/*stacking modifications */
for(var i=0;i<layerG.links.length;i++){
if(layerG.links[i].sourceID==new_nodeID || layerG.links[i].sourceID==old_nodeID || layerG.links[i].targetID==new_nodeID || layerG.links[i].targetID==old_nodeID)
stack(layerG,layerG.addEdge,[layerG.links[i].sourceID,layerG.links[i].targetID]);//add all the links
}for(var i=0;i<layerG.nodes[layerG.nodesHash[new_nodeID]].sons.length;i++)
stack(layerG,layerG.setFather,[layerG.nodes[layerG.nodesHash[new_nodeID]].sons[i],new_nodeID]);//add all the sons
for(var i=0;i<layerG.nodes[layerG.nodesHash[old_nodeID]].sons.length;i++)
stack(layerG,layerG.setFather,[layerG.nodes[layerG.nodesHash[old_nodeID]].sons[i],old_nodeID]);
stack(layerG,layerG.setFather,[new_nodeID,layerG.nodes[layerG.nodesHash[new_nodeID]].father]);//put fathers
stack(layerG,layerG.setFather,[old_nodeID,layerG.nodes[layerG.nodesHash[old_nodeID]].father]);
stack(layerG,layerG.addLabel,[old_nodeID,layerG.nodes[layerG.nodesHash[old_nodeID]].label.concat()]);//put label and context
stack(layerG,layerG.addCtx,[old_nodeID,layerG.nodes[layerG.nodesHash[old_nodeID]].context.concat(),layerG.copyVCtx(layerG.nodes[layerG.nodesHash[old_nodeID]].valued_context),layerG.copyACtx(layerG.nodes[layerG.nodesHash[old_nodeID]].apply_context)]);
stack(layerG,layerG.addLabel,[new_nodeID,layerG.nodes[layerG.nodesHash[new_nodeID]].label.concat()]);
stack(layerG,layerG.addCtx,[new_nodeID,layerG.nodes[layerG.nodesHash[new_nodeID]].context.concat(),layerG.copyVCtx(layerG.nodes[layerG.nodesHash[new_nodeID]].valued_context),layerG.copyACtx(layerG.nodes[layerG.nodesHash[new_nodeID]].apply_context)]);
stack(layerG,layerG.addNode,[layerG.nodes[layerG.nodesHash[new_nodeID]].classes,new_nodeID]);//add the old and new nodes
stack(layerG,layerG.addNode,[layerG.nodes[layerG.nodesHash[old_nodeID]].classes,old_nodeID]);
stack(layerG,layerG.removeNode,[old_nodeID]);//remove the merged node
/* end stack -> modification */
layerG.mergeDiff(new_nodeID,old_nodeID);
}
else{
console.log("unable to merge : too different nodes : ");
console.log(layerG.nodes[layerG.nodesHash[new_nodeID]]);
console.log(layerG.nodes[layerG.nodesHash[old_nodeID]]);
}
update();
};
this.removeNode = function removeNode(nID){//remove a node from the svg AND the graph structure
dynG.getForce().stop();
for(var i=0;i<layerG.links.length;i++){
if(layerG.links[i].sourceID==nID || layerG.links[i].targetID==nID)
stack(layerG,layerG.addEdge,[layerG.links[i].sourceID,layerG.links[i].targetID]);//add all the links
}for(var i=0;i<layerG.nodes[layerG.nodesHash[nID]].sons.length;i++)
stack(layerG,layerG.setFather,[layerG.nodes[layerG.nodesHash[nID]].sons[i],nID]);//add all the sons
if(layerG.nodes[layerG.nodesHash[nID]].father!=null)
stack(layerG,layerG.setFather,[nID,layerG.nodes[layerG.nodesHash[nID]].father]);
stack(layerG,layerG.addLabel,[nID,layerG.nodes[layerG.nodesHash[nID]].label.concat()]);
stack(layerG,layerG.addCtx,[nID,layerG.nodes[layerG.nodesHash[nID]].context.concat(),layerG.copyVCtx(layerG.nodes[layerG.nodesHash[nID]].valued_context),layerG.copyACtx(layerG.nodes[layerG.nodesHash[nID]].apply_context)]);
stack(layerG,layerG.addNode,[layerG.nodes[layerG.nodesHash[nID]].classes.concat(),nID]);
layerG.removeNode(nID);
update();
};
this.removeNodeR = function removeNodeR(nID){
for(var i=0;i<layerG.nodes[layerG.nodesHash[nID]].sons.length;i){
this.removeNodeR(layerG.nodes[layerG.nodesHash[nID]].sons[i]);
}this.removeNode(nID);
}
this.addEdge = function addEdge(id1,id2){//add a LINK edge between two nodes in the svg AND in the graph structure
dynG.getForce().stop();
var tmp_l=layerG.links.length;
layerG.addEdge(id1,id2);
if(layerG.links.length>tmp_l)
stack(layerG,layerG.removeEdge,[id1,id2]);
update();
};
this.addInfluence = function addInfluence(id1,id2,type){//add an INFLUENCE edge (positive or negative) between two node of a graph
dynG.getForce().stop();
var tmp_l=layerG.links.length;
layerG.addInfluence(id1,id2,type);
if(layerG.links.length>tmp_l)
stack(layerG,layerG.removeInfluence,[id1,id2,type]);
update();
}
this.removeEdge = function removeEdge(id1,id2){//remove a LINK edge between two nodes in the svg AND in the graph structure
dynG.getForce().stop();
stack(layerG,layerG.addEdge,[id1,id2]);
layerG.removeEdge(id1,id2);
update();
};
this.removeInfluence = function removeInfluence(id1,id2,type){//remove an INFLUENCE edge (positive or negative) between two nodes in the svg AND in the graph structure
dynG.getForce().stop();
stack(layerG,layerG.addInfluence,[id1,id2,type]);
layerG.removeInfluence(id1,id2,type);
update();
};
this.addParent = function addParent(son,fath){//add a PARENT edge between two node in the graph structure and un the svg and update graph structure
dynG.getForce().stop();
if(layerG.nodes[layerG.nodesHash[son]].father != fath){
stack(layerG,layerG.removeParenting,[son]);
layerG.setFather(son,fath);
update();
}
};
this.rmParent = function rmParent(son){//idem for removing parenting
dynG.getForce().stop();
//stack(layerG,layerG.setFather,[son,layerG.nodes[son].father]);
layerG.removeParenting(son);
update();
};
this.addCtx = function addCtx(id,ctx,vctx,actx){//add a context to a specific node
dynG.getForce().stop();
var tmp_l=layerG.nodes[layerG.nodesHash[id]].context.length;
layerG.addCtx(id,ctx,vctx,actx);
if(layerG.nodes[layerG.nodesHash[id]].context.length > tmp_l)
stack(layerG,layerG.rmCtx,[id,ctx]);
update();
};
this.rmCtx = function rmCtx(id,ctx){//remove a context from a specific node
dynG.getForce().stop();
stack(layerG,layerG.addCtx,[id,layerG.nodes[layerG.nodesHash[id]].context.concat(),layerG.copyVCtx(layerG.nodes[layerG.nodesHash[id]].valued_context),layerG.copyACtx(layerG.nodes[layerG.nodesHash[id]].apply_context)]);
layerG.rmCtx(id,ctx);
update();
};
this.getCtx = function getCtx(id){//get a specific node context
return layerG.nodes[layerG.nodeHash[id]].context.concat();
};
this.getCtxV = function getCtxV(id){//get a specific node context values
return layerG.copyVCtx(layerG.nodes[layerG.nodesHash[id]].valued_context);
};
this.addLabel = function addLabel(id,lbl){//add a label to a specific node
dynG.getForce().stop();
var tmp_l=layerG.nodes[layerG.nodesHash[id]].label.length;
layerG.addLabel(id,lbl);
if(layerG.nodes[layerG.nodesHash[id]].label.length>tmp_l)
stack(layerG,layerG.rmLabel,[id,lbl]);
update();
};
this.rmLabel = function rmLabel(id,lbl){//remove a label from a specific node
dynG.getForce().stop();
stack(layerG,layerG.addLabel,[id,layerG.nodes[layerG.nodesHash[id]].label.concat()]);
layerG.rmLabel(id,lbl);
update();
};
this.getLabel = function getLabel(id){//get a specific node label
return layerG.nodes[layerG.nodeHash[id]].label.concat();
};
var dragstart = function(d) {//allow only to move agents and actions.
d3.event.sourceEvent.stopPropagation();
//if(d3.select(this).classed("agent") || d3.select(this).classed("action"))
d3.select(this).classed("fixed", d.fixed = true);
};
this.getCoord = function getCoord(){//return all the node coordinates
layerG.log();
var ret=[];
for(var i=0;i<layerG.nodes.length;i++){
ret.push({x:layerG.nodes[i].x,y:layerG.nodes[i].y});
}
return ret;
};
var stack = function(obj,fun,param){//add an element to the undo stack
/*rewriter.push({f:fun,o:obj,p:param});
d3.select("#undo").property("disabled",false)
.style("display","initial");*/
};
this.unStack = function unStack(){//remove element from the undo stack and apply it !
};
this.unStackAll = function unStackAll(){//undo all the stack
/*
while(rewriter.length>0)
this.unStack();
d3.select("#undo").property("disabled",true)
.style("display","none");*/
};
this.clearStack = function clearStack(){//clear the undo stack
/*
rewriter=[];
d3.select("#undo").property("disabled",true)
.style("display","none");
*/
};
this.save = function save(){//save the current graph (clear the undo stack and set it to modified)
this.clearStack();
modified=true;
};
this.setState = function setState(state){//set the graphical interface state : "nugget_view", "kr_view", "kr_edit", "lcg_view", "kappa_view"
switch(state){
case "kr_view":
if(!first_init){
rewriter=nuggS;
layerG=nuggG;
dynG=nuggDynG;
drag=nuggDrag;
}
nugget_add=false;
edition=false;
kr_show=true;
lcg_view=false;
kappa_view=false;
svg_content.selectAll("g").filter(function(d){return d.classes[0]!="action" || d.classes[1]!="binder"}).classed("selected",function(d){return d.selected=false;});
d3.select("#menu_f").selectAll(".tab_el").style("background","none");
d3.select("#menu_f").select("#kr").style("background","linear-gradient(to bottom, #3fa4f0 0%, #0f71ba 100%)");
d3.select("#menu_f").selectAll(".removable_tab").property("disabled",false).style("display","initial");
d3.select("#menu_f").select("#kappa").property("disabled",true).style("display","none");
if(layerG===lcgG){
layerG=nuggG;
rewriter=nuggS;
dynG.getForce().stop();
dynG=nuggDynG;
drag=nuggDrag;
svg_content.selectAll("*").remove();
update();
modified=false;
}
break;
case "kr_edit":
this.setState("kr_view");
d3.select("#menu_f").selectAll(".tab_el").style("background","none");
d3.select("#menu_f").select("#edit").style("background","linear-gradient(to bottom, #3fa4f0 0%, #0f71ba 100%)");
d3.select("#menu_f").selectAll(".removable_tab").property("disabled",false).style("display","initial");
d3.select("#menu_f").select("#kappa").property("disabled",true).style("display","none");
if(!edition){
svg_content.selectAll("g").filter(function(d){return d.classes[0]!="action" || d.classes[1]!="binder"}).classed("selected",function(d){return d.selected=false;});
}
nugget_add=true;
edition=true;
kr_show=false;
lcg_view=false;
kappa_view=false;
break;
case "lcg_view":
var selected_l=[];
svg_content.selectAll("g").filter(".selected").filter(".action").each(function(d){selected_l.push(d.id)});
if(selected_l==null || selected_l.length==0){
svg_content.selectAll("g").filter(".action").each(function(d){selected_l.push(d.id)});
}
d3.select("#menu_f").selectAll(".tab_el").style("background","none");
d3.select("#menu_f").select("#lcg").style("background","linear-gradient(to bottom, #3fa4f0 0%, #0f71ba 100%)");
d3.select("#menu_f").selectAll(".removable_tab").property("disabled",true).style("display","none");
d3.select("#menu_f").select("#kappa").property("disabled",false).style("display","initial");
nugget_add=false;
edition=false;
kr_show=false;
lcg_view=true;
kappa_view=false;
//this.clearStack();
if(layerG===nuggG){
layerG=lcgG;
rewriter=lcgS;
dynG.getForce().stop();
dynG=lcgDynG;
drag=lcgDrag;
svg_content.selectAll("*").remove();
update();
if(modified || confirm("Generate a new LCG ?")){
layerG.init();
lcgConvert(selected_l);
}
svg_content.selectAll("g").filter(function(d){return d.classes[0]!="action" || d.classes[1]!="binder"}).classed("selected",function(d){return d.selected=false;});
}
break;
case "kappa_view"://nobody care : open jasim !
kappaConvert();
break;
}
};
this.getState = function getState(state){//get the graphical interface state
if(nugget_add) return "nugget_view";
if(kr_show) return "kr_view";
if(edition) return "kr_edit";
if(lcg_view) return "lcg_view";
if(kappa_view) return "kappa_view";
};
var mouseOver = function(d){//handling mouse over nodes/actions
if(d3.select(this).classed("node")){
var div_ct="<p><h3><b><center>id: "+d.id+"</center></b>";
if(d.label.length>0)
div_ct+="\n labels: <ul style='padding: 3px 15px;margin:1px;'><li>"+d.label.join("<li>")+"</ul>";
if(d.context.length>0)
div_ct+="values: <ul style='padding: 7px;margin:1px;'><li>"+d.context.join("<li>")+"</ul>";
div_ct+="</p>";
d3.select(".n_tooltip").style("visibility","visible")
.html(div_ct);
}else if(d3.select(this).classed("action") && !d3.select(this).classed("binder")){
var ctx_lst=[];
for(var i=0;i<d.context.length;i++){
var ctx_el=svg_content.selectAll("g").filter(function(e){return e.id==d.context[i];});
ctx_el.classed("selected_overlay",layerG.nodes[layerG.nodesHash[d.context[i]]].selected_over=true);
if(typeof(d.apply_context)!="undefined" && d.apply_context!=null){
var tmp_node=ctx_el.datum();
if(checkExist(d.apply_context[tmp_node.id])){
if(d.apply_context[tmp_node.id][0]=="E" && ((d.apply_context[tmp_node.id].length>1 && d.apply_context[tmp_node.id][1]=="E") || d.apply_context[tmp_node.id].length==1) ){
ctx_el.classed("exist",true);
}else if(d.apply_context[tmp_node.id].length>1 && d.apply_context[tmp_node.id][0]!=d.apply_context[tmp_node.id][1])
ctx_el.classed("existAlway",true);
}else{
ctx_el.classed("alway",true);
}
}
else{
ctx_el.classed("alway",true);
}
if(d3.event.shiftKey && d.valued_context!=null && (ctx_el.classed("attribute") || ctx_el.classed("flag") )){
var tmp_node=ctx_el.datum();
var tmp_id;
tmp_id=tmp_node.classes[0]+":"+tmp_node.id;
ctx_lst.push({id:tmp_id,x:tmp_node.x,values:d.valued_context[tmp_node.id]});
ctx_lst.sort(function(a,b){return a.x-b.x});
}
}
var div_ct="<p><h3><b><center>id: "+d.classes.join("/")+"</center></b>";
if(ctx_lst.length>0){
div_ct+="detailed values : <ul style='padding: 7px;margin:1px;'>";
for(var i=0;i<ctx_lst.length;i++)
div_ct+="<li>"+ctx_lst[i].id+" : "+ctx_lst[i].values.join(",");
div_ct+="</ul></p>"
d3.select(".n_tooltip").style("visibility","visible")
.html(div_ct);
}
}
var divs_ct="<h5><b><center>class: "+d.classes.join("/")+"</center></b></h5>";
d3.select(".s_tooltip").style("visibility","visible")
.html(divs_ct);
};
var mouseOut = function(d){//handling mouse out of nodes/actions
if(d3.select(this).classed("node")){
d3.select(".n_tooltip").style("visibility","hidden")
.text("");
}else if(d3.select(this).classed("action") && !d3.select(this).classed("binder")){
d3.select(".n_tooltip").style("visibility","hidden")
.text("");
for(var i=0;i<d.context.length;i++){
svg_content.selectAll("g").filter(function(e){return e.id==d.context[i];}).classed("selected_overlay",layerG.nodes[layerG.nodesHash[d.context[i]]].selected_over=false)
.classed("exist",false)
.classed("existAlway",false)
.classed("alway",false);
}
}
d3.select(".s_tooltip").style("visibility","hidden")
.text("");
};
var edgeCtMenu = function(){
var menu;
if(ctx_mode){
window.alert("Please fill all values for the action context");
return [];
}
menu=[{
title: "Select Source-target",
action: function(elm,d,i){
svg_content.selectAll("g").filter(function(e){return (e.id==d.sourceID || e.id==d.targetID || (d.source.classes[0]=="action" && d.source.father!=null && d.source.father==e.id) || (d.target.classes[0]=="action" && d.target.father!=null && d.target.father==e.id));})
.classed("selected",function(d){ return layerG.nodes[layerG.nodesHash[d.id]].selected=true;});
}
}];
if(edition || nugget_add || lcg_view){//be carefull in lcg view !
menu.push({
title: "remove",
action: function(elm,d,i){
if(d.e_class=="link" && confirm('Are you sure you want to delete this Edge ? The linked element wont be removed from the context'))
self.removeEdge(d.sourceID,d.targetID);
if((d.e_class=="positive" || d.e_class=="negative") && confirm('Are you sure you want to delete this Influence ?'))
self.removeInfluence(d.sourceID,d.targetID,d.e_class);
}
});
}
return menu;
}
var nodeCtMenu = function(){
if(ctx_mode){
window.alert("Please fill all values for the action context");
return [];
}
var evt_trg=d3.select(d3.event.target.parentNode);
var menu;
menu=[{
title: "Unlock",
action: function(elm,d,i){
d3.select(elm).classed("fixed",function(d){return d.fixed=false;});
update();
}
}];
if(lcg_view && evt_trg.classed("attribute")){
menu.push({
title: "Edit Values",
action: function(elm,d,i){
var lbl=window.prompt("define Attributes",d.context.join(","));
self.rmCtx(d.id,[]);
if(lbl!=null && lbl!="") self.addCtx(d.id,lbl.split(","));
}
});
}
if(edition || nugget_add){
if(!evt_trg.classed("attribute") && !evt_trg.classed("flag")){
menu.push({
title: "Add Attribute",
child:[
{
title:"list",
action: function(elm,d,i){
var lbl=window.prompt("define attribute labels","");
var values=window.prompt("define attribute values","vrai,faux");
if(lbl=="")self.addNode(["attribute","list"],[],[d.id]);
else self.addNode(["attribute","list"],lbl.split(","),[d.id]);
if(values=="")self.addCtx(layerG.nodes[layerG.nodes.length-1].id,["t","f"]);
else self.addCtx(layerG.nodes[layerG.nodes.length-1].id,values.split(","));
}
},{
title:"interval",
action: function(elm,d,i){
var lbl=window.prompt("define attribute labels","");
var values=window.prompt("define attribute values","0,INF");
if(values.split(",").length>2){
console.log("This attribute is not an interval !");
return;
}
if(lbl=="")self.addNode(["attribute","interval"],[],[d.id]);
else self.addNode(["attribute","interval"],lbl.split(","),[d.id]);
if(values=="") self.addCtx(layerG.nodes[layerG.nodes.length-1].id,["0","INF"]);
else self.addCtx(layerG.nodes[layerG.nodes.length-1].id,values.split(","));
}
}]
},{
title: "Add Flag",
action: function(elm,d,i){
var lbl=window.prompt("define flag labels","");
var values=window.prompt("define flag values","vrai,faux");
if(lbl=="")self.addNode(["flag"],[],[d.id]);
else self.addNode(["flag"],lbl.split(","),[d.id]);
if(values=="")self.addCtx(layerG.nodes[layerG.nodes.length-1].id,["t","f"]);
else self.addCtx(layerG.nodes[layerG.nodes.length-1].id,values.split(","));
}
});
}if(evt_trg.classed("agent") || evt_trg.classed("region")){
menu.push({
title: "Add Key Residue",
action: function(elm,d,i){
var lbl=window.prompt("define key residue labels","");
if(lbl=="")self.addNode(["key_res"],[],[d.id]);
else self.addNode(["key_res"],lbl.split(","),[d.id]);
}
});
}if(evt_trg.classed("agent")){
menu.push({
title: "Add Region",
action: function(elm,d,i){
var lbl=window.prompt("define region labels","");
if(lbl=="")self.addNode(["region"],[],[d.id]);
else self.addNode(["region"],lbl.split(","),[d.id]);
}
});
}if(evt_trg.classed("attribute") || evt_trg.classed("flag")){
menu.push({
title: "Edit Values",
action: function(elm,d,i){
var lbl=window.prompt("define Attributes",d.context.join(","));
self.rmCtx(d.id,[]);
if(lbl!="") self.addCtx(d.id,lbl.split(","));
}
});
}if((evt_trg.classed("attribute") || evt_trg.classed("flag") || evt_trg.classed("region") || evt_trg.classed("key_res")) && !svg_content.select("g.selected").empty()&& correctParenting(evt_trg,svg_content.select("g.selected"))){
menu.push({
title: "Change Parent",
action: function(elm,d,i){
if(d.father)
self.rmParent(d.id);
self.addParent(d.id,svg_content.select("g.selected").datum().id);
}
});
}
menu.push({
title: "Remove",
action: function(elm,d,i){
if(confirm('Are you sure you want to delete this Node ? All its sons will be removed'))
self.removeNodeR(d.id);
}
});
}if(edition || lcg_view){
var tmp_select = svg_content.selectAll("g.selected").filter(function(d){
for(var i=0;i<d.classes.length;i++){
if(!evt_trg.classed(d.classes[i]))
return false;
}return true;
});
if(!tmp_select.empty()){
menu.push(
{
title: "Merge with selected nodes",
action:function(elm,d,i){
var tmp_select = svg_content.selectAll("g.selected").filter(function(d){
for(var i=0;i<d.classes.length;i++){
if(!evt_trg.classed(d.classes[i]))
return false;
}return true;
});
tmp_select.each(function(d2){self.mergeNode(d.id,d2.id);});
}
});
}
}
if(edition && svg_content.selectAll("g.selected").size()==1){//allow to add influence between action
menu.push(
{
title: "Add influence from Selected Node",
child:[
{
title:"Positive",
action: function(elm,d,i){
var select=svg_content.select("g.selected").each(function(d2){self.addInfluence(d2.id,d.id,"positive");});
}
},{
title:"Negative",
action: function(elm,d,i){
var select=svg_content.select("g.selected").each(function(d2){self.addInfluence(d2.id,d.id,"negative");});
}
}]
});
}
return menu;
}
var correctParenting = function(d3el_son,d3el_father){
if(d3el_son.classed("region"))
return d3el_father.classed("agent");
if(d3el_son.classed("flag") || d3el_son.classed("attribute"))
return d3el_father.classed("agent") || d3el_father.classed("region") || d3el_father.classed("key_res");
if(d3el_son.classed("key_res"))
return d3el_father.classed("agent") || d3el_father.classed("region");
return false;
};
var binderCtMenu = function(){//handling right click on action binders
var menu;
if(ctx_mode){
window.alert("Please fill all forms");
return [];
}
if((edition || nugget_add) && !svg_content.selectAll("g.selected").empty()){
menu=[
{
title: "link to all selected",
action: function(elm,d,i){
d3.event.stopPropagation();
var selected=svg_content.selectAll("g.selected");
selected.each(function(d2){
if(layerG.nodes[layerG.nodesHash[d.father]].classes[1]!="mod"){
if((layerG.nodes[layerG.nodesHash[d.father]].classes[1]=="bnd"|| layerG.nodes[layerG.nodesHash[d.father]].classes[1]=="brk") &&(d2.classes[0]=="attribute" || d2.classes[0]=="flag")){
console.log("can't bind a flag/attribute");
return;
}
self.addEdge(d.id,d2.id);
self.addCtx(d.father,[d2.id]);
}
else if(layerG.nodes[layerG.nodesHash[d.father]].classes[1]=="mod" && d2.classes[0]!="attribute" && d2.classes[0]!="flag"){
console.log("can't modify a none flag/attribute");
}
else{
ctx_mode=true;
var el = d3.select(this);
var tab=d2.context;
var ret = inputMenu("attribute of : "+d2.id,null,tab,null,true,false,'center',function(cb){
if(cb.radio){
var tmp_obj={};
tmp_obj[d2.id]=cb.radio;
for(var i=0;i<tmp_obj[d2.id].length;i++){
if(d2.context.indexOf(tmp_obj[d2.id][i])==-1)
self.addCtx(d2.id,[tmp_obj[d2.id][i]],null);
}
self.addCtx(d.father,[d2.id],tmp_obj);
self.addEdge(d.id,d2.id);
if(svg_content.selectAll("input").empty())ctx_mode=false;
}
},d2);
}
});
selected.classed("selected",function(d){return d.selected=false;});
}
}];
}else menu=[];
return menu;
}
var actCtMenu = function(){//handling right click on actions
var menu;
if(ctx_mode){
window.alert("Please fill all forms");
return [];
}
// by default an action can only be moved around
menu = [
{
title: "Unlock",
action: function(elm,d,i){
d3.select(elm).classed("fixed",function(d){return d.fixed=false;});
update();
}
}
];
if((d3.select(d3.event.target.parentNode).classed("bnd") || d3.select(d3.event.target.parentNode).classed("brk"))){
menu.push({
title: "invert binders",
action: function(elm,d,i){
var act_bind=d.sons.filter(function(e){
return layerG.nodes[layerG.nodesHash[e]].classes[0]=="action" && layerG.nodes[layerG.nodesHash[e]].classes[1]=="binder";
});
act_bind.forEach(function(e){
layerG.nodes[layerG.nodesHash[e]].classes[2]=layerG.nodes[layerG.nodesHash[e]].classes[2]=="left"?"right":"left";
});
update();
}
});
}
if(edition || nugget_add){//in case of edition or nugget mod : we can add attributes to an action or remove it or select its context
menu.push(
{
title: "Add Attribute",
child:[
{
title:"list",
action: function(elm,d,i){
var lbl=window.prompt("define attribute labels","");
var values=window.prompt("define attribute values","vrai,faux");
if(lbl=="")self.addNode(["attribute","list"],[],[d.id]);
else self.addNode(["attribute","list"],lbl.split(","),[d.id]);
if(values=="")self.addCtx(layerG.nodes[layerG.nodes.length-1].id,["t","f"]);
else self.addCtx(layerG.nodes[layerG.nodes.length-1].id,values.split(","));
}
},{
title:"interval",
action: function(elm,d,i){
var lbl=window.prompt("define attribute labels","");
var values=window.prompt("define attribute values","0,INF");
if(values.split(",").length>2){
console.log("This attribute is not an interval !");
return;
}
if(lbl=="")self.addNode(["attribute","interval"],[],[d.id]);
else self.addNode(["attribute","interval"],lbl.split(","),[d.id]);
if(values=="") self.addCtx(layerG.nodes[layerG.nodes.length-1].id,["0","INF"]);
else self.addCtx(layerG.nodes[layerG.nodes.length-1].id,values.split(","));
}
}]
},{
title: "Remove",
action: function(elm,d,i){
if(confirm('Are you sure you want to delete this Action ?'))
self.removeNodeR(d.id);
}
},{
title: "Select context",
action: function(elm,d,i){
for(var i=0;i<d.context.length;i++)
svg_content.selectAll("g").filter(function(e){return e.id==d.context[i];}).classed("selected",layerG.nodes[layerG.nodesHash[d.context[i]]].selected=true);
}
});
}
if(nugget_add && !svg_content.selectAll("g.selected").filter(function(dd){return d3.select(d3.event.target.parentNode).datum().context.indexOf(dd.id)!=-1;}).empty()){//edition of the element special context
menu.push(
{
title: "specify element application",
action:function(elm,d,i){
var selected=svg_content.selectAll("g.selected").filter(function(dd){return d.context.indexOf(dd.id)!=-1;});
var ret={};
selected.each(function(d2){
ctx_mode=true;
var el = d3.select(this);
var tab;
if(typeof(d.apply_context)!="undefined" && d.apply_context!=null && checkExist(d.apply_context[d2.id]))
tab = d.apply_context[d2.id];
else
tab=null;
var ret = inputMenu("attribute of : "+d2.id,null,null,tab,true,false,'center',function(cb){
if(cb.check){
self.addCtx(d.id,[],null,cb.check);
}
},d2);
});
}
});
}
if(nugget_add && !svg_content.selectAll("g.selected").empty()){//in nugget mode, allow to link elements to the action
var selected_elt=d3.select(d3.event.target.parentNode);
var tmp_child=null;
if(selected_elt.classed("bnd") || selected_elt.classed("brk")){ //for bnd & break : link is on both binders, the elemet is also added to the context. we only can link agent, region and key_res
tmp_child=[{
title: "link right",
action:function(elm,d,i){
var selected=svg_content.selectAll("g.selected");
d3.event.stopPropagation();
for(var i=0;i<d.sons.length;i++){
if(layerG.nodes[layerG.nodesHash[d.sons[i]]].classes[0]=="action" && layerG.nodes[layerG.nodesHash[d.sons[i]]].classes[1] == "binder" && layerG.nodes[layerG.nodesHash[d.sons[i]]].classes[2]=="right"){
selected.each(function(d2){
if(d2.classes[0]!="action" && d2.classes[0]!="attribute" && d2.classes[0]!="flag"){
self.addEdge(d.sons[i],d2.id);
self.addCtx(d.id,[d2.id]);
}else console.log("can't link two action or flags or attributes : put it in context instead");
});
selected.classed("selected",function(d){return d.selected=false;});
}
}