|
|
@ -2083,21 +2083,43 @@ function stableGraph(){ |
|
|
|
// run on entire wiki though whereas previous D3 instance limited to 10 pages and their targets |
|
|
|
// run on entire wiki though whereas previous D3 instance limited to 10 pages and their targets |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let edges_to_display = [] |
|
|
|
function displayLeafs(graph, graphEl, rootId, rootEl, depth=3){ |
|
|
|
function displayLeafs(graph, graphEl, rootId, rootEl, depth=3){ |
|
|
|
console.log( graph[rootId].Id ) |
|
|
|
console.log( graph[rootId].Id ) |
|
|
|
if (depth<1) return |
|
|
|
if (depth<1) return |
|
|
|
graph[rootId].Targets.map( l => { |
|
|
|
graph[rootId].Targets.map( l => { |
|
|
|
console.log( "-", graph[l].Id ) |
|
|
|
console.log( "-", graph[l].Id ) |
|
|
|
let x = addNodeFromGraph(graph[l].Id, "" + (Math.random()*2) + " " + (Math.random()*2) + " -" + (Math.random()*2) ) |
|
|
|
let x = addNodeFromGraph(graph[l].Id, "" + (Math.random()*2) + " " + (Math.random()*2) + " -" + (Math.random()*2) ) |
|
|
|
//nodes.push(x) |
|
|
|
x.setAttribute('update-links-on-pinchended', true) |
|
|
|
console.log("linking:", rootEl, x) |
|
|
|
console.log("linking:", rootEl, x) |
|
|
|
setTimeout( _ => { addEdgeBetweenNodesFromGraph(graphEl, rootEl, x) }, 2000) // otherwise null positions |
|
|
|
edges_to_display.push({graphel:graphEl, source:rootEl, target:x}) |
|
|
|
// might need to delay that differently |
|
|
|
|
|
|
|
//edges.push({source:root, target:x}) |
|
|
|
|
|
|
|
displayLeafs( graph, graphEl, graph[l].Id, x, --depth) |
|
|
|
displayLeafs( graph, graphEl, graph[l].Id, x, --depth) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AFRAME.registerComponent('update-links-on-pinchended', { |
|
|
|
|
|
|
|
init: function(){ |
|
|
|
|
|
|
|
let rootEl = document.querySelector("#graphroot") |
|
|
|
|
|
|
|
let el = this.el |
|
|
|
|
|
|
|
this.el.addEventListener('released', function (event) { |
|
|
|
|
|
|
|
Object.keys( rootEl.components ) // get all links |
|
|
|
|
|
|
|
.filter( i => i.indexOf(el.id) > -1 ) // keeps links related to the moved node |
|
|
|
|
|
|
|
.map( i => { // for each link |
|
|
|
|
|
|
|
let newpos = el.getAttribute("position") |
|
|
|
|
|
|
|
let [src,tgt] = i.replace("line__","").split("__to__"); |
|
|
|
|
|
|
|
srcpos = AFRAME.utils.coordinates.stringify( rootEl.getAttribute(i).start ) |
|
|
|
|
|
|
|
tgtpos = AFRAME.utils.coordinates.stringify( rootEl.getAttribute(i).end ) |
|
|
|
|
|
|
|
if (src==el.id){ |
|
|
|
|
|
|
|
rootEl.setAttribute(i, { start: newpos, end: tgtpos }) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
rootEl.setAttribute(i, { start: srcpos, end: newpos }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// somehow works once... |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
fetch('https://vatelier.benetou.fr/MyDemo/newtooling/wiki_graph.json').then( r => r.json() ).then( r => displayGraph(r.Nodes) ); |
|
|
|
fetch('https://vatelier.benetou.fr/MyDemo/newtooling/wiki_graph.json').then( r => r.json() ).then( r => displayGraph(r.Nodes) ); |
|
|
|
function displayGraph(mynodes){ |
|
|
|
function displayGraph(mynodes){ |
|
|
|
// add few nodes with few edges for testing |
|
|
|
// add few nodes with few edges for testing |
|
|
@ -2107,13 +2129,17 @@ function displayGraph(mynodes){ |
|
|
|
let root = mynodes[startingNode] |
|
|
|
let root = mynodes[startingNode] |
|
|
|
|
|
|
|
|
|
|
|
let graphEl = document.createElement("a-entity") |
|
|
|
let graphEl = document.createElement("a-entity") |
|
|
|
|
|
|
|
graphEl.id = "graphroot" |
|
|
|
AFRAME.scenes[0].appendChild( graphEl ) |
|
|
|
AFRAME.scenes[0].appendChild( graphEl ) |
|
|
|
let nodes = [] |
|
|
|
let nodes = [] |
|
|
|
let edges = [] |
|
|
|
let edges = [] |
|
|
|
let node_names = Object.keys( mynodes ) |
|
|
|
let node_names = Object.keys( mynodes ) |
|
|
|
|
|
|
|
|
|
|
|
let rootEl = addNodeFromGraph(root.Id, "" + (Math.random()*2) + " " + (Math.random()*2) + " -" + (Math.random()*2) ) |
|
|
|
let rootEl = addNodeFromGraph(root.Id, "" + (Math.random()*2) + " " + (Math.random()*2) + " -" + (Math.random()*2) ) |
|
|
|
|
|
|
|
rootEl.setAttribute('update-links-on-pinchended', true) |
|
|
|
displayLeafs( mynodes, graphEl, root.Id, rootEl, 2) |
|
|
|
displayLeafs( mynodes, graphEl, root.Id, rootEl, 2) |
|
|
|
|
|
|
|
setTimeout( _ => { edges_to_display.map( i => addEdgeBetweenNodesFromGraph( i.graphel, i.source, i.target ))}, 2000 ) |
|
|
|
|
|
|
|
// quite unreliable |
|
|
|
|
|
|
|
|
|
|
|
// random graph, no preferential attachement |
|
|
|
// random graph, no preferential attachement |
|
|
|
/* |
|
|
|
/* |
|
|
|