-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedgeManager.js
86 lines (75 loc) · 3.29 KB
/
edgeManager.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
function addEdge(An, Bn,biDir,fromTxt){
if (contains(adjList[An],Bn)){ console.log(nodeA+"->"+nodeB+" already exists."); return;}
if(An==Bn){console.log("No self-loops!");return;}
var n0 = nodes[An]['Pos'], n1 = nodes[Bn]['Pos'];
var edgeEl = document.createElement('a-entity');
var pAth = pathParse(n0)+" ,"+pathParse(n1);
setAttributes(edgeEl,{'id':An+"-"+Bn,'meshline': { path:pAth,lineWidth: 10,lineWidthStyler: 1,color: '#55575b'}});
addSquares(n0,n1,edgeEl,An+"-"+Bn);
graphEl.appendChild(edgeEl);
if (!fromTxt){
adjList[An].push(Bn);
}
if(biDir){addEdge(Bn,An,false,fromTxt);}
nodeA=null;
nodeB=null;
return;
}
function addSquares(fRom,tO,edgeEl,iD){
var box1 = document.createElement('a-box');
var motion = document.createElement('a-animation');
var bool = 'false';
if (edgeAni){bool='true';}
setAttributes(box1,{'id':'~'+iD,'color':'#66FF00','height':'.125','width':'.125','depth':'.125','position':fRom,'visible':bool});
setAttributes(motion,{'attribute':'position','dur':3000,'from':pathParse(fRom),'to':pathParse(tO),'repeat':'indefinite'});
box1.appendChild(motion);
var box2 = document.createElement('a-box');
setAttributes(box2,{'id':'!'+iD,'visible':'false','opacity':'.55','height':'.25','width':'.25','depth':'.25'});
var motion1 = document.createElement('a-animation');
setAttributes(motion1,{'attribute':'position','dur':1000,'from':pathParse(calcFracDist(fRom,tO,3.15)),'to':pathParse(calcFracDist(fRom,tO,3)),'repeat':'indefinite'});
box2.appendChild(motion1);
box2.onmouseenter = function(){setAttributes(this,{'class':'delEDGE','color':'#ff275d'})}
box2.onmouseleave = function(){this.removeAttribute('class');this.removeAttribute('color');}
graphEl.appendChild(box1);
graphEl.appendChild(box2);
//if this doesnt work as planned, have from = 0,0,0 and to = frOm-tO (in order to be with respect topoint)
}
function calcFracDist(Pos1,Pos2,n){
return {x:(((Pos2.x)*(1/n))+((Pos1.x)*(1-(1/n)))),
y:(((Pos2.y)*(1/n))+((Pos1.y)*(1-(1/n)))),
z:(((Pos2.z)*(1/n))+((Pos1.z)*(1-(1/n))))}
}
function deleteEdge(){
if (document.querySelector('.delEDGE')){
var detectedEdge = document.querySelector('.delEDGE').getAttribute('id');
console.log(detectedEdge);
detectedEdge = detectedEdge.substring(1);
console.log(detectedEdge);
var vertices = detectedEdge.split('-');
for (var j = 0; j< adjList[vertices[0]].length;j++){
if (adjList[vertices[0]][j]==vertices[1]){
adjList[vertices[0]].splice(j,1);
j = adjList[vertices[0]].length;
}
}
for (var i = 0; i<graphEl.children.length;i++){
elem = graphEl.children[i];
if(elem.getAttribute('id').includes(detectedEdge)){
graphEl.removeChild(graphEl.children[i]);
i--;
}
}
}
else{
console.log("No Edge Detected");
}
}
function selectEdge(){
var bool = (del) ? 'true':'false';
console.log(bool);
for (var i =0; i<graphEl.children.length;i++){
if (graphEl.children[i].getAttribute('id').includes('!')){
graphEl.children[i].setAttribute('visible',bool);
}
}
}