diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 2c1e9c7..ed45246 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -1023,7 +1023,7 @@ class Graph { .force( "link", d3.forceLink( this.directions ).id( d => d['@id'] ).strength(0) ) // .force( "charge", d3.forceManyBody().strength( 100 ) ) // .force( "center", d3.forceCenter( this.width / 2, this.height / 2 ) ) - .force( "collide", d3.forceCollide( this.nodeSize * 2.3 ) ) + .force( "collide", d3.forceCollide( this.nodeSize * 2.3 ).strength(2) ) .force( "forceX", d3.forceX(function(m){ let fx = panopticon.graph.distances[m['@id']] !== null ? panopticon.graph.distances[m['@id']] * panopticon.graph.nodeSize * 4 : 0 console.log('fx', m['@id'], panopticon.graph.distances[m['@id']], fx); @@ -1031,7 +1031,7 @@ class Graph { }).strength(50)) .force( "forceY", d3.forceY(m => panopticon.graph.distances[m['@id']] !== null ? 0 : panopticon.graph.nodeSize * 3 ).strength(30)) ; - this.simulation.velocityDecay(.98); + this.simulation.velocityDecay(.99); // Update existing nodes let node = this.nodesG @@ -1190,34 +1190,70 @@ class Graph { distances[msg['@id']] = msg === startMsg ? 0 : null; } - let directionsPerMsg = {}; + let targetsPerMsg = {}; + let sourcesPerMsg = {}; console.log("dir", this.directions); for(let direction of this.directions) { let from = typeof direction['source'] == "string" ? direction['source'] : direction['source']['@id']; let to = typeof direction['target'] == "string" ? direction['target'] : direction['target']['@id']; - if(!directionsPerMsg.hasOwnProperty(from)) { - directionsPerMsg[from] = []; + if(!targetsPerMsg.hasOwnProperty(from)) { + targetsPerMsg[from] = []; } - directionsPerMsg[from].push(to); + targetsPerMsg[from].push(to); + + + if(!sourcesPerMsg.hasOwnProperty(to)) { + sourcesPerMsg[to] = []; + } + sourcesPerMsg[to].push(from); } - let traverseMsg = function(msgId, depth) { - if(!directionsPerMsg.hasOwnProperty(msgId)) { + let traverseMsg = function(msgId, depth, goingDown) { + let msgsPerMsg = goingDown ? targetsPerMsg : sourcesPerMsg; + console.log(goingDown, msgId, depth); + if(!msgsPerMsg.hasOwnProperty(msgId)) { // end of trail return; } - for(let childMsgId of directionsPerMsg[msgId]) { - if(distances[childMsgId] === null || distances[childMsgId] > depth) { + for(let childMsgId of msgsPerMsg[msgId]) { + if(distances[childMsgId] === null || (goingDown && distances[childMsgId] > depth)) { distances[childMsgId] = depth; - traverseMsg(childMsgId, depth+1); +// console.log(goingDown, childMsgId, depth); + traverseMsg(childMsgId, goingDown ? (depth+1) : (depth - 1), goingDown); + } + else if(!goingDown && distances[childMsgId] < depth) { +// console.log('a', depth); + traverseMsg(childMsgId, depth - 1, goingDown); } else { // apparently, there is a loop. Don't traverse it. } } } - traverseMsg(startMsg['@id'], 1); + traverseMsg(startMsg['@id'], 1 , true); + + // now we have the formal tree, lets try to polish the rest: + for(let msgId in distances) { + if(distances[msgId] === null) { + continue; + } +// let's see if there are parent nodes that are not in the distances array + // traverse up and see whether we encounter anything new + traverseMsg(msgId, distances[msgId] -1, false) + } + +// let additionalsDepth = 0; +//// now the secondary strands: +// for(let msgId in distances) { +// if(distances[msgId] !== null || sourcesPerMsg.hasOwnProperty(msgId)) { +// // it is already calculated, or it has a parent node (which we should traverse instead) +// continue; +// } +// distances[msgId] = additionalsDepth; +// traverseMsg(msgId, additionalsDepth+1, true); +// +// } return distances; }