-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDynamicGraph.js
26 lines (26 loc) · 1.64 KB
/
DynamicGraph.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
//dynamic_graph.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
define(["LayeredGraph.js","d3/d3.min.js"],function(LayeredGraph,d3){return function DynamicGraph(layerG,height,width){//define a dynamic graph : nodes can be of differents classes : "action", "agent" "key_rs", "region", "flag", "attribute", action should have a second subclass : "mod", "bnd","brk","syn", "deg","r_link","l_link" other can have a subclass : "abstract", "set"
var layerG=layerG;
var force=d3.layout.force()
.size([width, height]);
this.init = function init(){
force
.nodes(layerG.nodes)
.links(layerG.links)
.linkDistance(function(d){
if((d.source.classes[0]=="action" && d.source.classes[1]=="binder") || (d.target.classes[0]=="action" && d.target.classes[1]=="binder") || d.e_class=="positive" || d.e_class=="negative")
return 100;
else if((d.target.classes[0]=="action" && d.source.classes[0]=="attribute"))
return (d.source.toInt()+d.target.toInt()/2)/2;
else return (d.source.toInt()+d.target.toInt())/2;
})
.linkStrength(function(d){if((d.source.classes[0]=="action" && d.source.classes[1]=="binder") || (d.target.classes[0]=="action" && d.target.classes[1]=="binder")|| d.e_class=="positive"|| d.e_class=="negative") return 0.7; else return 5})
.charge(function(d){if((d.classes[0]=="action" && d.classes[1]=="binder" )||(d.classes[0]=="attribute" && (d.father==null || layerG.nodes[layerG.nodesHash[d.father]].classes[0]=="action")))return -300; else return -600})
};
this.getForce = function getForce(){
return force;
};
}})