Team:Heidelberg/js/notebook tree

From 2014.igem.org

(Difference between revisions)
Line 274: Line 274:
function highlightData(typeName){
function highlightData(typeName){
var array = [].concat(typeName);
var array = [].concat(typeName);
-
console.log(array);
 
node.attr("opacity", function(d){
node.attr("opacity", function(d){
var h = false;
var h = false;
Line 296: Line 295:
function unhighlightData(typeName){
function unhighlightData(typeName){
var array = [].concat(typeName);
var array = [].concat(typeName);
-
console.log(array);
 
node.attr("opacity", function(d){
node.attr("opacity", function(d){
var h = false;
var h = false;
Line 412: Line 410:
var json = getJSONForDate(date);
var json = getJSONForDate(date);
if(json !== -1){
if(json !== -1){
-
console.log(md5);
+
console.log(json.file);
d3.json(json.file, function(error, data){
d3.json(json.file, function(error, data){
if(error) console.warn(error);
if(error) console.warn(error);

Revision as of 19:14, 17 October 2014

function md5cycle(e,t){var n=e[0],r=e[1],i=e[2],s=e[3];n=ff(n,r,i,s,t[0],7,-680876936);s=ff(s,n,r,i,t[1],12,-389564586);i=ff(i,s,n,r,t[2],17,606105819);r=ff(r,i,s,n,t[3],22,-1044525330);n=ff(n,r,i,s,t[4],7,-176418897);s=ff(s,n,r,i,t[5],12,1200080426);i=ff(i,s,n,r,t[6],17,-1473231341);r=ff(r,i,s,n,t[7],22,-45705983);n=ff(n,r,i,s,t[8],7,1770035416);s=ff(s,n,r,i,t[9],12,-1958414417);i=ff(i,s,n,r,t[10],17,-42063);r=ff(r,i,s,n,t[11],22,-1990404162);n=ff(n,r,i,s,t[12],7,1804603682);s=ff(s,n,r,i,t[13],12,-40341101);i=ff(i,s,n,r,t[14],17,-1502002290);r=ff(r,i,s,n,t[15],22,1236535329);n=gg(n,r,i,s,t[1],5,-165796510);s=gg(s,n,r,i,t[6],9,-1069501632);i=gg(i,s,n,r,t[11],14,643717713);r=gg(r,i,s,n,t[0],20,-373897302);n=gg(n,r,i,s,t[5],5,-701558691);s=gg(s,n,r,i,t[10],9,38016083);i=gg(i,s,n,r,t[15],14,-660478335);r=gg(r,i,s,n,t[4],20,-405537848);n=gg(n,r,i,s,t[9],5,568446438);s=gg(s,n,r,i,t[14],9,-1019803690);i=gg(i,s,n,r,t[3],14,-187363961);r=gg(r,i,s,n,t[8],20,1163531501);n=gg(n,r,i,s,t[13],5,-1444681467);s=gg(s,n,r,i,t[2],9,-51403784);i=gg(i,s,n,r,t[7],14,1735328473);r=gg(r,i,s,n,t[12],20,-1926607734);n=hh(n,r,i,s,t[5],4,-378558);s=hh(s,n,r,i,t[8],11,-2022574463);i=hh(i,s,n,r,t[11],16,1839030562);r=hh(r,i,s,n,t[14],23,-35309556);n=hh(n,r,i,s,t[1],4,-1530992060);s=hh(s,n,r,i,t[4],11,1272893353);i=hh(i,s,n,r,t[7],16,-155497632);r=hh(r,i,s,n,t[10],23,-1094730640);n=hh(n,r,i,s,t[13],4,681279174);s=hh(s,n,r,i,t[0],11,-358537222);i=hh(i,s,n,r,t[3],16,-722521979);r=hh(r,i,s,n,t[6],23,76029189);n=hh(n,r,i,s,t[9],4,-640364487);s=hh(s,n,r,i,t[12],11,-421815835);i=hh(i,s,n,r,t[15],16,530742520);r=hh(r,i,s,n,t[2],23,-995338651);n=ii(n,r,i,s,t[0],6,-198630844);s=ii(s,n,r,i,t[7],10,1126891415);i=ii(i,s,n,r,t[14],15,-1416354905);r=ii(r,i,s,n,t[5],21,-57434055);n=ii(n,r,i,s,t[12],6,1700485571);s=ii(s,n,r,i,t[3],10,-1894986606);i=ii(i,s,n,r,t[10],15,-1051523);r=ii(r,i,s,n,t[1],21,-2054922799);n=ii(n,r,i,s,t[8],6,1873313359);s=ii(s,n,r,i,t[15],10,-30611744);i=ii(i,s,n,r,t[6],15,-1560198380);r=ii(r,i,s,n,t[13],21,1309151649);n=ii(n,r,i,s,t[4],6,-145523070);s=ii(s,n,r,i,t[11],10,-1120210379);i=ii(i,s,n,r,t[2],15,718787259);r=ii(r,i,s,n,t[9],21,-343485551);e[0]=add32(n,e[0]);e[1]=add32(r,e[1]);e[2]=add32(i,e[2]);e[3]=add32(s,e[3])}function cmn(e,t,n,r,i,s){t=add32(add32(t,e),add32(r,s));return add32(t<>>32-i,n)}function ff(e,t,n,r,i,s,o){return cmn(t&n|~t&r,e,t,i,s,o)}function gg(e,t,n,r,i,s,o){return cmn(t&r|n&~r,e,t,i,s,o)}function hh(e,t,n,r,i,s,o){return cmn(t^n^r,e,t,i,s,o)}function ii(e,t,n,r,i,s,o){return cmn(n^(t|~r),e,t,i,s,o)}function md51(e){txt="";var t=e.length,n=[1732584193,-271733879,-1732584194,271733878],r;for(r=64;r<=e.length;r+=64){md5cycle(n,md5blk(e.substring(r-64,r)))}e=e.substring(r-64);var i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(r=0;r<e.length;r++)i[r>>2]|=e.charCodeAt(r)<<(r%4<<3);i[r>>2]|=128<<(r%4<<3);if(r>55){md5cycle(n,i);for(r=0;r<16;r++)i[r]=0}i[14]=t*8;md5cycle(n,i);return n}function md5blk(e){var t=[],n;for(n=0;n<64;n+=4){t[n>>2]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24)}return t}function rhex(e){var t="",n=0;for(;n<4;n++)t+=hex_chr[e>>n*8+4&15]+hex_chr[e>>n*8&15];return t}function hex(e){for(var t=0;t<e.length;t++)e[t]=rhex(e[t]);return e.join("")}function md5(e){return hex(md51(e))}function add32(e,t){return e+t&4294967295}var hex_chr="0123456789abcdef".split("");if(md5("hello")!="5d41402abc4b2a76b9719d911017c592"){function add32(e,t){var n=(e&65535)+(t&65535),r=(e>>16)+(t>>16)+(n>>16);return r<<16|n&65535}}

var svg; var color = d3.scale.category20();

var firstDate = 1388530801;//1407861000; var date = firstDate;

var heightOfSecond = 100 / 86400; // = 300 Pixel per day?! var viewportHeight = 300/heightOfSecond; var bufferHeight = 1000/heightOfSecond; var scrollSpeed = 6000; // = 20 minutes

var width = 1; var height = 1;

var bigNodes = []; //Contains [{containsDate(), [data]},...] var bigLinks = [];

var fnodes = []; var flinks = []; var force;

var node; var link;

var selectedProject;

var unhighlightedData = []

var jsonFiles = {"Toolbox":[{"end":1388786400,"begin":1388530800},{"end":1392300000,"begin":1392072300},{"end":1397206800,"begin":1396951200},{"end":1402063200,"begin":1402056000},{"end":1402329600,"begin":1402234200},{"end":1402826400,"begin":1402825080},{"end":1403289600,"begin":1403172000},{"end":1403560800,"begin":1403390400},{"end":1403857800,"begin":1403789400},{"end":1404118800,"begin":1403958600},{"end":1404393600,"begin":1404388800},{"end":1404662880,"begin":1404660346},{"end":1404924000,"begin":1404849600},{"end":1405191600,"begin":1405186800},{"end":1405452600,"begin":1405447200},{"end":1405717200,"begin":1405641000},{"end":1405980000,"begin":1405980000},{"end":1406280360,"begin":1406278800},{"end":1406541600,"begin":1406539200},{"end":1406803080,"begin":1406757600},{"end":1407067200,"begin":1407067200},{"end":1407330000,"begin":1407330000},{"end":1407589800,"begin":1407580200},{"end":1407855900,"begin":1407855600},{"end":1408116600,"begin":1408115700},{"end":1408376820,"begin":1408376700},{"end":1408636800,"begin":1408636800},{"end":1408901400,"begin":1408901220},{"end":1409170800,"begin":1409170200},{"end":1409432400,"begin":1409432400},{"end":1409695200,"begin":1409695200},{"end":1409956200,"begin":1409955000},{"end":1410217140,"begin":1410215400},{"end":1410480000,"begin":1410453000},{"end":1410771600,"begin":1410771600},{"end":1411034400,"begin":1411034400},{"end":1411295400,"begin":1411295400},{"end":1411596000,"begin":1411596000},{"end":1411857480,"begin":1411855200},{"end":1412123040,"begin":1412114700},{"end":1412393700,"begin":1412380800},{"end":1412674080,"begin":1412655300},{"end":1412940600,"begin":1412905020},],"LOV":[{"end":1388790000,"begin":1388530800},{"end":1392300000,"begin":1392044400},{"end":1402063200,"begin":1402000800},{"end":1402329600,"begin":1402234200},{"end":1402826400,"begin":1402825080},{"end":1403289600,"begin":1403172000},{"end":1403560800,"begin":1403560800},{"end":1403863200,"begin":1403863200},{"end":1404126000,"begin":1404064800},{"end":1404462720,"begin":1404424800},{"end":1404770400,"begin":1404770400},{"end":1405066800,"begin":1404938700},{"end":1405371600,"begin":1405371600},{"end":1405706400,"begin":1405641000},{"end":1405980000,"begin":1405871100},{"end":1406280360,"begin":1406278800},{"end":1406541600,"begin":1406500200},{"end":1406803080,"begin":1406757600},{"end":1407067200,"begin":1407024000},{"end":1407330000,"begin":1407323460},{"end":1407628800,"begin":1407623400},{"end":1407889800,"begin":1407841200},{"end":1408219200,"begin":1408140000},{"end":1408536900,"begin":1408536000},{"end":1408800600,"begin":1408744800},{"end":1409068800,"begin":1409065200},{"end":1409329800,"begin":1409329800},{"end":1409592000,"begin":1409589000},{"end":1409860800,"begin":1409847600},{"end":1410201000,"begin":1410192000},{"end":1410469200,"begin":1410469200},{"end":1410732000,"begin":1410732000},{"end":1411008600,"begin":1410991200},{"end":1411275480,"begin":1411252200},{"end":1411538400,"begin":1411531500},{"end":1411801200,"begin":1411794960},{"end":1412085600,"begin":1412082000},{"end":1412347680,"begin":1412345340},{"end":1412608140,"begin":1412577300},{"end":1412883900,"begin":1412877600},],"DNMT1":[{"end":1388786400,"begin":1388530800},{"end":1402063200,"begin":1402000800},{"end":1402390800,"begin":1402174800},{"end":1402826400,"begin":1402581600},{"end":1403355600,"begin":1403355600},{"end":1403863200,"begin":1403820000},{"end":1404150480,"begin":1403953200},{"end":1404489600,"begin":1404424800},{"end":1404900000,"begin":1404722700},{"end":1405720800,"begin":1405615500},{"end":1406413800,"begin":1406293200},{"end":1406916000,"begin":1406656800},{"end":1407189600,"begin":1407024000},{"end":1407485700,"begin":1407321900},{"end":1407882600,"begin":1407841200},{"end":1408573800,"begin":1408399800},{"end":1408894500,"begin":1408821780},{"end":1409608800,"begin":1409349600},{"end":1409942700,"begin":1409841600},{"end":1410215340,"begin":1410199200},{"end":1410512400,"begin":1410420600},{"end":1410782400,"begin":1410781200},{"end":1411052400,"begin":1411036200},{"end":1411313580,"begin":1411232400},{"end":1411654500,"begin":1411601100},{"end":1411916400,"begin":1411916400},{"end":1412181900,"begin":1412181900},],"Lyso":[{"end":1388790000,"begin":1388530800},{"end":1397206800,"begin":1396951200},{"end":1402063200,"begin":1401984600},{"end":1402826400,"begin":1402825080},{"end":1403289600,"begin":1403101800},{"end":1403560800,"begin":1403560800},{"end":1405706400,"begin":1405706400},{"end":1406073600,"begin":1405871100},{"end":1406754000,"begin":1406642400},{"end":1407016800,"begin":1407016800},{"end":1407279600,"begin":1407263400},{"end":1407548400,"begin":1407518100},{"end":1407848400,"begin":1407799800},{"end":1408116600,"begin":1408115700},{"end":1408399200,"begin":1408312800},{"end":1408707000,"begin":1408656240},{"end":1409004000,"begin":1408834560},{"end":1409324400,"begin":1409320800},{"end":1409608800,"begin":1409603400},{"end":1409922000,"begin":1409768100},{"end":1410296400,"begin":1410213600},{"end":1410624000,"begin":1410618600},{"end":1410942600,"begin":1410904800},{"end":1411205400,"begin":1411153200},{"end":1411567200,"begin":1411558200},{"end":1411898400,"begin":1411855200},{"end":1412168400,"begin":1412164800},{"end":1412442000,"begin":1412442000},],"Xyla":[{"end":1388790000,"begin":1388530800},{"end":1402063200,"begin":1401973800},{"end":1403084280,"begin":1403084280},{"end":1405630800,"begin":1405630800},{"end":1405900200,"begin":1405871100},{"end":1406280360,"begin":1406278800},{"end":1406541600,"begin":1406500200},{"end":1407882600,"begin":1407799800},{"end":1408219200,"begin":1408217040},{"end":1408485600,"begin":1408484700},{"end":1408749960,"begin":1408744800},{"end":1409061600,"begin":1408834560},{"end":1409502600,"begin":1409429700},{"end":1409862600,"begin":1409781600},{"end":1410418800,"begin":1410418800},{"end":1410703200,"begin":1410688800},{"end":1411034400,"begin":1410962400},{"end":1411331400,"begin":1411320600},{"end":1411749000,"begin":1411742700},{"end":1412013600,"begin":1411941600},{"end":1412276400,"begin":1412269200},],"General":[{"end":1388790000,"begin":1388790000},{"end":1402063200,"begin":1402056000},{"end":1402329600,"begin":1402261200},{"end":1402826400,"begin":1402825080},{"end":1403289600,"begin":1403172000},{"end":1403560800,"begin":1403390400},{"end":1403870400,"begin":1403856000},{"end":1404151200,"begin":1404043200},{"end":1404578400,"begin":1404576000},{"end":1404846600,"begin":1404832260},{"end":1405156920,"begin":1405066500},{"end":1406073600,"begin":1406047200},{"end":1406365200,"begin":1406235600},{"end":1406707200,"begin":1406671200},{"end":1407011400,"begin":1406934000},{"end":1407279600,"begin":1407257040},{"end":1407542400,"begin":1407512700},{"end":1407855900,"begin":1407794400},{"end":1408148100,"begin":1408130100},{"end":1408493700,"begin":1408476000},{"end":1408878000,"begin":1408626000},{"end":1409140800,"begin":1409058000},{"end":1409435940,"begin":1409405580},{"end":1409698800,"begin":1409486400},{"end":1410184800,"begin":1410159600},{"end":1410465600,"begin":1410264000},{"end":1410865200,"begin":1410825240},{"end":1411191000,"begin":1411088400},{"end":1411680600,"begin":1411421400},{"end":1412013600,"begin":1411992000},{"end":1412424000,"begin":1412377200},],};

var mapping = { "p/3cuNZHSvzbmc5wGLz" : "Make a liquid culture", "p/3wt4jvadcLzkvFn9X" : "Make a liquid culture", "p/4jCgLAziJ2DSmmcvR" : "Streak bacteria onto an agar plate", "p/53yEPDJz7oRihLz3M" : "Dilute DNA", "p/5K8vL8t4egnG8SRtc" : "PCA", "p/9S64Hy4vyzPvM4aiC" : "DNA purification (\"PCR Purification\")", "p/9TiKPrpdykEiSHFcy" : "Make a liquid culture", "p/ATv6a4HMeQZMa9WYX" : "Dilute DNA", "p/Ae7BXywPx8nNApvPK" : "Golden Gate Assembly", "p/CdKqzhX6FqmmHYKdE" : "Maxens neues Protokoll", "p/D9hHrT2Ere5rrcuXK" : "Make competent cells", "p/E8wraGbztRq8EsET7" : "Make a glycerol stock", "p/ENCvtL4jWZQW72hE5" : "Restriction digest", "p/F2oNT7tGTyGFCjAB9" : "Make competent cells", "p/FY69K4x7xdaJT6Lzk" : "Pick a colony from an agar plate", "p/HA9CLF2Z4kgY3J5rE" : "Make a liquid culture", "p/JPmjNykwWASQiD9PX" : "Agarose Gel Electrophoresis", "p/NgpLzurL2RKFojWWA" : "PCR", "p/Nm75fDvHCr38nXJBo" : "Plasmid Preparation", "p/P6LsqW4xkJYaXHFJN" : "Heat shock transformation", "p/PxYonEdgff39dmkhq" : "DNA purification (\"PCR Purification\")", "p/TD9txcymCuToDta7x" : "Annealing of complementary oligonucleotides", "p/WSMMH3bg6CcrcAJ3x" : "PCR", "p/ZuE3NijkBg4WwpzKc" : "Recovery of plasmid DNA from filter paper", "p/bSEHCZgLpXJ6nb9ze" : "Streak bacteria onto an agar plate", "p/gM7FyZeyNrM4hwxZk" : "Dissolve plasmid DNA from the registry distribution", "p/hmhE7AHgjXE8Khw6M" : "Gel extraction", "p/jT9cdZ9T5JgFDEJXe" : "Heat shock transformation", "p/kKiCHxutJLzPKayCC" : "Streak bacteria onto an agar plate", "p/kxBySpW3SnbWuYMRw" : "Streak bacteria onto an agar plate", "p/mJNyMCoEko3JKRv5x" : "Heat shock transformation", "p/maDx7F6ry8Mw5JmKf" : "Pick a colony from an agar plate", "p/ms6uHrB9Fv23Tge2J" : "Make a glycerol stock", "p/mzGLz4CZBhmDHNivi" : "Make Medium", "p/n4Sg8s8AfhMEtQtFH" : "Ligation", "p/oFoQguhSKQKC2Hfms" : "Gather bacteria from an agar plate", "p/ojKqKzgeLkvNvLDgw" : "Heat shock transformation", "p/ovMK2ktEeSommgLa2" : "Heat shock transformation", "p/pk9LqRH9ot8JiKx23" : "Make a glycerol stock", "p/qGNf5sATkiC4P7RqF" : "Gather bacteria from an agar plate", "p/v97Nktv4idauP3hYh" : "Make competent cells", "p/vB88pigyWbKvmKir6" : "Pick a colony from an agar plate", "p/vj752RxeBbHsHi83w" : "Pick a colony from an agar plate", "p/xBmBAjXPQntkvc8d5" : "Make a glycerol stock", "p/z46dHCjoZpLkNgm4k" : "CPEC" }

var colorMapping = {"Make a liquid culture":"#1f77b4","Streak bacteria onto an agar plate":"#aec7e8","Dilute DNA":"#ff7f0e","PCA":"#ffbb78","DNA purification (\"PCR Purification\")":"#2ca02c","Golden Gate Assembly":"#98df8a","Maxens neues Protokoll":"#d62728","Make competent cells":"#ff9896","Make a glycerol stock":"#9467bd","Restriction digest":"#c5b0d5","Pick a colony from an agar plate":"#8c564b","Agarose Gel Electrophoresis":"#c49c94","PCR":"#e377c2","Plasmid Preparation":"#f7b6d2","Heat shock transformation":"#7f7f7f","Annealing of complementary oligonucleotides":"#c7c7c7","Recovery of plasmid DNA from filter paper":"#bcbd22","Dissolve plasmid DNA from the registry distribution":"#dbdb8d","Gel extraction":"#17becf","Make Medium":"#9edae5","Ligation":"#1f77b4","Gather bacteria from an agar plate":"#aec7e8","CPEC":"#ff7f0e"};


//var circle; $(document).ready(function(){

svg = d3.selectAll("#graph"); $svg = $("#graph"); width = $svg.width(); height = $svg.height();

$svg.bind('DOMMouseScroll mousewheel', handleScrolling);

node = svg.selectAll(".node"); link = svg.selectAll(".link"); force = d3.layout.force() .charge(-500) .linkDistance(function (d) { var dist = getHeight(d.target.date) - getHeight(d.source.date); var minDist = 50; if (dist < minDist) dist = minDist; return dist; }) .linkStrength(.1) .gravity(0) .size([width, height]) .links(flinks) .nodes(fnodes) .on("tick", tick);


setSubproject("Lyso", firstDate);


});

function update(){ if(dataUpdated){ dataUpdated=false; var links = flatten(bigLinks); var nodes = flatten(bigNodes); //console.log(bigNodes, nodes);

node = node.data(nodes, function(d) { return d.id;}); node.enter() .append("circle") .attr("class", "node") .attr("r", 11) .attr("fill", function (d) { return colorMapping[mapping[d.type]]; }) .on("click", function(){if(d3.event.defaultPrevented) return ; alert("Silvan show Overlay");}) .call(force.drag) .each(function(d) { d.y = (d.date - firstDate) * heightOfSecond; fnodes.push(d); }) .append("svg:title") .text(function(d){return mapping[d.type] + ", " + d.groups;});

node.exit() .each(function(d) { removeByID(fnodes, d.id); }) .remove();

links = links.filter(function(d) { return findByID(d.target) !== undefined && findByID(d.source) !== undefined; }); links.forEach(function(d) { d.source = findByID(d.source); d.target = findByID(d.target); });

link = link.data(links); var lines = link.enter() .append("line") .each(function (d) { flinks.push(d); }) .on("click", function (d){if(d3.event.defaultPrevented) return ; scrollToDate(d.target.date-100000);}) .attr("class", "link");

//lines.filter(function () { return Math.random() > 0.5; }).attr("opacity", "0");

link.exit() .each(function(d) { var index = flinks.indexOf(findByID(d)); if(index >-1) flinks.splice(index, 1); removeLinksByIDs(flinks, d.source.id, d.target.id); }) .remove();

force.start();

unhighlightData(unhighlightedData); }


updateVis();

}

function tick(e) { force.nodes().forEach(function(d){ if(!d.fixed){ d.y += (getHeight(d.date) - d.y) * e.alpha; //d.y = getHeight(d.date); if(d.x > width * 8/10){ d.x += (width*8/10 - d.x) * e.alpha; }else if(d.x < width * 2/10){ d.x += (width* 2/10 - d.x) * e.alpha; } else{ d.x += (width/2 - d.x) * e.alpha * 0.2 ; } } });

updateVis(); }


function updateVis(){ node.attr("cx", function(d) { return d.x; }) .attr("cy", function(d) { return d.y - (date - firstDate) * heightOfSecond; });

link .attr("x1", function(d) { if(d.source !== undefined) return d.source.x; else return d.target.x; }) .attr("y1", function(d) { if(d.source !== undefined) return d.source.y - (date - firstDate) * heightOfSecond; else return 0;}) .attr("x2", function(d) { if(d.target !== undefined) return d.target.x; else return d.source.x; }) .attr("y2", function(d) { if(d.target !== undefined) return d.target.y - (date - firstDate) * heightOfSecond; else return viewportHeight * heightOfSecond;}); }

function setSubproject(project, d){ dateJSONMatchingList = undefined; if(d === undefined) d = date; this.selectedProject = project; unhighlightedData = []; unloadGreaterDate(firstDate-1);

loadDate(d-bufferHeight); loadDate(d); loadDate(d+viewportHeight); loadDate(d+viewportHeight+bufferHeight); setDate(d); }

function setDate(date){ /*if(date < firstDate){ date = firstDate; }*/ var lastDateDisplayed = date + viewportHeight; loadDate(date - bufferHeight); loadDate(lastDateDisplayed + bufferHeight); unloadSmallerDate(date - bufferHeight); unloadGreaterDate(lastDateDisplayed + bufferHeight); this.date = date; update(); }

/*function animateFlow(){ var links = flatten(bigLinks); var x = Math.floor(links.length * Math.random()); xs.push(x); var l = links[x]; svg.append("ellipse") .attr("fill", "#33CC33") .attr("rx", ( l.target.x - l.source.x)/100) .attr("ry", ( l.target.y - l.source.y)/100) .attr("cx", l.source.x) .attr("cy", l.source.y) .transition() .duration(1000000/(( l.target.x - l.source.x) + ( l.target.y - l.source.y))) .ease("linear") .attr("cx", l.target.x) .attr("cy", l.target.y) .remove();

}*/

function scrollToDate(d){ var currentDate = date; var dif = d - currentDate; console.log(dif); var smoothness = 60; //30 FPS var i = 0; var max = 1 * smoothness; //1 sec. var interval = setInterval(function(){ i=i+1; if(i > max){ clearInterval(interval); } setDate(date+ dif/max) }, max*1000/smoothness/smoothness); }

function highlightData(typeName){ var array = [].concat(typeName); node.attr("opacity", function(d){ var h = false; for(var g = 0; g < array.length; g=g+1) { h = h || d.groups.indexOf(array[g]) !== -1; } if(h) return 1.0; else return 0.1; }); link.attr("opacity", function(d){ var h = false; for(var g = 0; g < array.length; g=g+1) { h = h || (d.target && d.target.groups.indexOf(array[g]) !== -1 && d.source && d.source.groups.indexOf(array[g]) !== -1); }

if(h) return 1; else return 0.1; }); }

function unhighlightData(typeName){ var array = [].concat(typeName); node.attr("opacity", function(d){ var h = false; for(var g = 0; g < array.length; g=g+1) { h = h || d.groups.indexOf(array[g]) !== -1; } if(h) return 0.1; else return 1.0; }); link.attr("opacity", function(d){ var h = false; for(var g = 0; g < array.length; g=g+1) { h = h || ((d.target && d.target.groups.indexOf(array[g]) !== -1) || (d.source && d.source.groups.indexOf(array[g]) !== -1)); }

if(h) return 0.1; else return 1.0; }); for(i = 0; i < array.length; i=i+1){ if(unhighlightedData.indexOf(array[i]) === -1) unhighlightedData.push(array[i]); } }


//////***************************************Helper Function*************************************/

function findByID(id){ return $.grep(fnodes, function(e){return e === id || e.id === id;})[0]; }

function removeByID(array, id){ var index = -1; for(i = 0; i<array.length; i=i+1){ if(array[i].id === id){ index = i; break; } } array.splice(index, 1); }

function removeLinksByIDs(array, sourceId, targetId){ var index = -1; for(i = 0; i<array.length; i=i+1){ if(array[i].source.id === sourceId && array[i].target.id === targetId){ index = i; break; } } array.splice(index, 1); }

function getHeight(date){ return (date - firstDate)*heightOfSecond;

}

/***************************************************************************************************/

/************************************Scrolling and JSON loading stuff*******************************/


/*var loadedJSONFiles = []; var lastLoadedJSON = -1; var firstLoadedJSON = 0;*/

var dateJSONMatchingList; var dataUpdated = false;


var loadingData = false;

function flatten(a){ return a.reduce(extractAndMergeData, []); }

function extractAndMergeData(a, b){ return a.concat(b.data); }

function getFileURL(file) { var md5Name = md5(file); return '/wiki/images/' + md5Name.substr(0, 1) + '/' + md5Name.substr(0, 2) + '/' + file; }

function getJSONForDate(date){ if(dateJSONMatchingList === undefined){ dateJSONMatchingList = []; for(i = 0; i < jsonFiles[selectedProject].length; i=i+1){ var file = jsonFiles[selectedProject][i]; var f = (function (file) { return function(d){ return d >= file.begin && d <= file.end; }; })(file); dateJSONMatchingList.push({ fun: f, file: getFileURL('Heidelberg_Notebook_Data_' + selectedProject + '_summary_' + file.end + '_' + file.begin + '.txt'), end: file.end, begin: file.begin, }); } } for(j = 0; j < dateJSONMatchingList.length; j=j+1){ if(dateJSONMatchingList[j].fun(date)) return dateJSONMatchingList[j]; } return -1; }

function loadDate(date){

//Check if date is already loaded if(!isDateLoaded(date)){ //Load new date var json = getJSONForDate(date); if(json !== -1){ console.log(json.file); d3.json(json.file, function(error, data){ if(error) console.warn(error); var containsFnc = json.fun; var smallerFnc = (function(l1, l2){ return function(d){ return d < l1 && d < l2; }; })(json.end, json.begin); var greaterFnc = (function(l1, l2){ return function(d){ return d > l1 && d > l2; }; })(json.end, json.begin); if(!isDateLoaded(date)){ //Attention this could lead due to the asynchronous nature of d3.json to a race condition and double adding of the nodes and links... bigNodes.push({ contains: containsFnc, greater: greaterFnc, smaller: smallerFnc, data: data.nodes }); bigLinks.push({ contains: containsFnc, greater: greaterFnc, smaller: smallerFnc, data: data.links }); dataUpdated = true; } update(); }); } }

}

function unloadSmallerDate(date){ if(bigNodes.reduce(function(a, b){return a || b.greater(date);}, false)){ bigNodes = bigNodes.filter(function(d){return !d.greater(date);}); bigLinks = bigLinks.filter(function(d){return !d.greater(date);}); dataUpdated = true;

} }

function unloadGreaterDate(date){ if(bigNodes.reduce(function(a, b){return a || b.smaller(date);}, false)){ bigNodes = bigNodes.filter(function(d){return !d.smaller(date);}); bigLinks = bigLinks.filter(function(d){return !d.smaller(date);}); dataUpdated = true; } }

function parseFileName(name){ var l = name.substring(0, name.length-4).split("_"); if(l === undefined || l.length !== 2) console.warn("erroneous file name", name, l); return l; }

function parseFileNameToContainsFnc(name){ var l = parseFileName(name); var f = function(l1, l2){ return function(d){ return d >= l1 && d <= l2; }; }(l[0], l[1]); return f; }

function parseFileNameToSmallerFnc(name){ var l = parseFileName(name); var f = function(l1, l2){ return function(d){ return d < l1 && d < l2; }; }(l[0], l[1]); return f; } function parseFileNameToGreaterFnc(name){ var l = parseFileName(name); var f = function(l1, l2){ return function(d){ return d > l1 && d > l2; }; }(l[0], l[1]); return f; }

function isDateLoaded(date){ for(i = 0; i < bigNodes.length; i=i+1){ if(bigNodes[i].contains(date)){ return true; } } return false; }

function handleScrolling(e) { var scrollTo = 0;

   		e.preventDefault();

if (e.type == 'mousewheel') { scrollTo = (e.originalEvent.wheelDelta * -scrollSpeed/100); }else if (e.type == 'DOMMouseScroll') { scrollTo = e.originalEvent.detail * scrollSpeed; } setDate(date+scrollTo); }