Mercurial > hg > Members > nobuyasu > html > graphViewer
comparison show.html @ 11:8c4171f77fcc draft
add show.html
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Mar 2013 15:25:09 +0900 |
parents | |
children | 549962a324ac |
comparison
equal
deleted
inserted
replaced
10:3fa1be92ab48 | 11:8c4171f77fcc |
---|---|
1 #{extends 'main.html' /} | |
2 #{set title:messages.get('AAEvidenceSiftingModel.userdesktops.show.title') /} | |
3 <link rel='stylesheet' href="/aat/public/viewer/css/viewer_form.css"> | |
4 <script src="@{'/public/viewer/js/lib/jquery-1.8.1-min.js'}" type="text/javascript" charset="${_response_encoding}"></script> | |
5 <script type="text/javascript" src="@{'/public/viewer/js/lib/jquery-ui-1.8.23-min.js'}" charset="${_response_encoding}"></script> | |
6 <script type="text/javascript" src="@{'/public/viewer/js/lib/jquery.ui.touch-punch.min.js'}" charset="${_response_encoding}"></script> | |
7 <script type="text/javascript" src="@{'/public/viewer/js/lib/jsBezier-0.4-min.js'}" charset="${_response_encoding}"></script> | |
8 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-util-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
9 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-dom-adapter-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
10 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
11 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-defaults-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
12 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-renderers-svg-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
13 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-renderers-canvas-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
14 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jsPlumb-renderers-vml-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
15 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jquery.jsPlumb-1.3.15-RC1.js'}" charset="${_response_encoding}"></script> | |
16 <script type="text/javascript" src="@{'/public/viewer/js/1.3.15/jquery.jsPlumb-1.3.15-all-min.js'}" charset="${_response_encoding}"></script> | |
17 | |
18 <div id="page"> | |
19 <div class="title"> | |
20 &{'AAEvidenceSiftingModel.userdesktops.show.title'} [ ${desktop.project.name} ] | |
21 </div> | |
22 <ul > | |
23 <li>> <a href="@{AAEvidenceSiftingModel.UserHomes.index()}">&{'navigation.back'}</a></li> | |
24 <li>> <a href="@{AAEvidenceSiftingModel.Projects.show(desktop.id)}">&{'AAEvidenceSiftingModel.projects.show.title'}</a></li> | |
25 </ul> | |
26 </div> | |
27 | |
28 | |
29 <div id="traverseDisplay" style='position:fixed; width:250px; height:250px; border:solid 1px; border-radius:5px; opacity:1; z-index:10; visibility:visible;'> | |
30 <div style='position:absolute; left:0; top:0; width:100%; height:100%; background:black; opacity:0.7;'></div> | |
31 <div id="closeTraverseDisplay" style='position:absolute; right:5; top:-3; z-index:10; color:white;' onclick="$('#traverseDisplay').css('visibility','hidden');" onmouseover="$('#closeTraverseDisplay').css('color','yellow');" onmouseout="$('#closeTraverseDisplay').css('color','white')" >CLOSE</div> | |
32 <div style='position:absolute; width:90%; height:90%;'> | |
33 <div style='position:absolute; left:5%; top:5%; width:100%; height:100%; background:white;'> | |
34 <div id="traverseDisplayTitle" style='position:absolute; left:10px; top:5px; font-size:24px; width:100%; text-align:left;'> | |
35 Traverse | |
36 </div> | |
37 <div style='position:absolute; top:30px; width:100%; margin-left:10px;'> Direction: | |
38 <label style='position:relative;' ><input id="direction_in" type='checkbox' checked value='in'/>IN</label> | |
39 <label style='position:relative;'><input id="direction_out" type='checkbox' checked value='out'/>OUT</label> | |
40 </div> | |
41 <div id="traverseDisplayBody" style='position:absolute; left:20px; top:50px;'> | |
42 Please click any node. | |
43 </div> | |
44 </div> | |
45 </div> | |
46 <span class='button display' style='position:absolute; width:100; left:75; bottom:5; opacity:1;' onclick='traverseAction();'>traverse</span> | |
47 </div> | |
48 | |
49 <div id="miniDisplay" style='position:fixed; width:250px; height:250px; border:solid 1px; border-radius:5px; opacity:1; z-index:10; visibility:visible;'> | |
50 <div style='position:absolute; left:0; top:0; width:100%; height:100%; background:black; opacity:0.5;'></div> | |
51 <div id="closeMiniDisplay" style='position:absolute; right:5; top:-3; z-index:10; color:white;' onclick="$('#miniDisplay').css('visibility','hidden');" onmouseover="$('#closeMiniDisplay').css('color','yellow');" onmouseout="$('#closeMiniDisplay').css('color','white')" >CLOSE</div> | |
52 <div style='position:absolute; width:90%; height:90%;'> | |
53 <div style='position:absolute; left:5%; top:5%; width:100%; height:100%; background:white;'> | |
54 <div id="miniDisplayTitle" style='position:absolute; left:10px; top:5px; font-size:24px; width:100%; text-align:left;'> | |
55 </div> | |
56 <div id="miniDisplayBody" style='position:absolute; left:20px; top:40px;'> | |
57 Please click any node. | |
58 </div> | |
59 </div> | |
60 </div> | |
61 </div> | |
62 | |
63 <div class="graphMainCss" style="position:absolute; left:0; bottom:0; width:100%; height:75%;" id='graphMain'> | |
64 <div style="position:absolute; width:0; height:0;left:0;" id='graphRoot'> | |
65 </div> | |
66 </div> | |
67 | |
68 | |
69 <script type="text/javascript"> | |
70 var BASE_URL = ""; | |
71 | |
72 | |
73 if(!Array.prototype.filter){ | |
74 Array.prototype.filter=function(func){ | |
75 var arr=[]; | |
76 for(var i=0;i<this.length;i++)if(func(this[i]))arr.push(this[i]); | |
77 return arr; | |
78 } | |
79 } | |
80 | |
81 function GraphData() { | |
82 var graphData = {}; | |
83 graphData.nodes = {}; | |
84 graphData.edges = {}; | |
85 return graphData; | |
86 } | |
87 | |
88 | |
89 function Edge(fromNode, toNode, relation) { | |
90 var obj = {from:fromNode, to:toNode, rel:relation }; | |
91 return obj; | |
92 } | |
93 | |
94 function beginScript() { | |
95 DragHandler.attach($('#miniDisplay')[0]); | |
96 DragHandler.attach($('#traverseDisplay')[0]); | |
97 } | |
98 | |
99 var DragHandler = { | |
100 _oElem : null, | |
101 _id : null, | |
102 attach : function(oElem) { | |
103 oElem.onmousedown = DragHandler._dragBegin; | |
104 return oElem; | |
105 }, | |
106 attach : function(oElem, id) { | |
107 oElem.onmousedown = DragHandler._dragBegin; | |
108 _id = id; | |
109 return oElem; | |
110 }, | |
111 _dragBegin : function(e) { | |
112 var oElem = DragHandler._oElem = this; | |
113 if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; } | |
114 if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; } | |
115 var x = parseInt(oElem.style.left); | |
116 var y = parseInt(oElem.style.top); | |
117 e = e ? e : window.event; | |
118 oElem.mouseX = e.clientX; | |
119 oElem.mouseY = e.clientY; | |
120 document.onmousemove = DragHandler._drag; | |
121 document.onmouseup = DragHandler._dragEnd; | |
122 return false; | |
123 }, | |
124 _drag : function(e) { | |
125 var oElem = DragHandler._oElem; | |
126 var x = parseInt(oElem.style.left); | |
127 var y = parseInt(oElem.style.top); | |
128 e = e ? e : window.event; | |
129 var nextX = x + (e.clientX - oElem.mouseX); | |
130 var nextY = y + (e.clientY - oElem.mouseY); | |
131 oElem.style.left = nextX + 'px'; | |
132 oElem.style.top = nextY + 'px'; | |
133 oElem.mouseX = e.clientX; | |
134 oElem.mouseY = e.clientY; | |
135 if (_id) { | |
136 var node = GRAPH_DATA.nodes[_id]; | |
137 node.position.x = nextX; | |
138 node.position.x = nextY; | |
139 } | |
140 return false; | |
141 }, | |
142 _dragEnd : function() { | |
143 var oElem = DragHandler._oElem; | |
144 var x = parseInt(oElem.style.left); | |
145 var y = parseInt(oElem.style.top); | |
146 document.onmousemove = null; | |
147 document.onmouseup = null; | |
148 DragHandler._oElem = null; | |
149 } | |
150 | |
151 }; | |
152 | |
153 function addLoadEvent(func) { | |
154 var oldonload = window.onload; | |
155 if (typeof window.onload != 'function') { | |
156 window.onload = func; | |
157 } else { | |
158 window.onload = function() { | |
159 if (oldonload) { | |
160 oldonload(); | |
161 } | |
162 func(); | |
163 } | |
164 } | |
165 } | |
166 | |
167 addLoadEvent(function() { | |
168 beginScript(); | |
169 }); | |
170 | |
171 function writeMiniDisplay(title,str) { | |
172 $('#miniDisplayBody')[0].innerHTML = str; | |
173 if(title) { | |
174 $('#miniDisplayTitle')[0].innerHTML = title; | |
175 } | |
176 } | |
177 | |
178 function writeJSONDataToMiniDisplay(jsonObj) { | |
179 var str = ""; | |
180 for (var key in jsonObj.property) { | |
181 if (key != 'edgeInfo' ) { | |
182 str = str + key + ": "+ jsonObj.property[key] + "<br>"; | |
183 } | |
184 } | |
185 writeMiniDisplay(jsonObj.property.title, str); | |
186 } | |
187 | |
188 function getTraverseDivTemplate(kind, inNum, outNum) { | |
189 return "<div><label id='traverseLabel'><input type='checkbox' checked value='"+kind+"'/>"+kind+"</label><br>in:"+inNum+" out:"+outNum+"</div>"; | |
190 } | |
191 | |
192 function createTraverseView(info) { | |
193 var viewHtml = ""; | |
194 for (var kind in info) { | |
195 var data = info[kind]; | |
196 var inNum = 0; | |
197 var outNum = 0; | |
198 if (data['in']) { | |
199 inNum = data['in']; | |
200 } | |
201 if (data['out']) { | |
202 outNum = data['out']; | |
203 } | |
204 viewHtml = viewHtml + getTraverseDivTemplate(kind, inNum, outNum); | |
205 } | |
206 return viewHtml; | |
207 } | |
208 | |
209 function createEdgeInfoView(node) { | |
210 var id = node.property.id; | |
211 var edgeInfo = node.property.edgeInfo; | |
212 var str = ""; | |
213 var info = {}; | |
214 for (var i=0; i<edgeInfo.length; i++) { | |
215 var kind = edgeInfo[i].kind; | |
216 var dir = edgeInfo[i].direction; | |
217 var num = edgeInfo[i].num; | |
218 info[kind] = {}; | |
219 info[kind][dir] = num; | |
220 } | |
221 var viewHTML = createTraverseView(info); | |
222 edgeInfo.viewHtml = viewHTML; | |
223 $('#traverseDisplayBody')[0].innerHTML = viewHTML; | |
224 } | |
225 | |
226 function init() { | |
227 jsPlumb.importDefaults({ | |
228 Connector : [ "Straight", { curviness:50 } ], | |
229 PaintStyle : { strokeStyle:"gray", lineWidth:2 }, | |
230 EndpointStyle : {}, | |
231 Anchors: ["BottomCenter","TopCenter"], | |
232 }); | |
233 var rootDiv = $('#graphMain'); | |
234 var rootLeft = rootDiv.offset().left; | |
235 var rootTop = rootDiv.offset().top; | |
236 $('#traverseDisplay').css( { | |
237 left: rootLeft, | |
238 top: rootTop | |
239 }); | |
240 var heightStr = $('#traverseDisplay').css('height').split('px')[0]; | |
241 var height = parseInt(heightStr); | |
242 $('#miniDisplay').css( { | |
243 left: rootLeft, | |
244 top: rootTop + height + 50 | |
245 }); | |
246 } | |
247 | |
248 function showMiniDisplay(node) { | |
249 $("#miniDisplay").css("visibility", "visible"); | |
250 writeJSONDataToMiniDisplay(node); | |
251 } | |
252 | |
253 function showTraverseDisplay(node) { | |
254 this.id = node.property.id; | |
255 if (!node.property.edgeInfo) { console.log("not found node.edgeInfo "); return; } | |
256 if (!node.property.edgeInfo.viewHtml) { | |
257 createEdgeInfoView(node); | |
258 } | |
259 $('#traverseDisplayBody')[0].innerHTML = node.property.edgeInfo.viewHtml; | |
260 $("#traverseDisplay").css("visibility", "visible"); | |
261 } | |
262 | |
263 var nodeNum = 0; | |
264 var OFFSET = 200; | |
265 var miniD = $('#miniDisplay')[0].style; | |
266 var offsetLeft = parseInt(miniD.width.split('px')[0]); | |
267 var offsetTop = parseInt(miniD.height.split('px')[0]); | |
268 function calcNewNodePosition() { | |
269 var position = {}; | |
270 position = {x: offsetLeft, y: nodeNum*OFFSET + offsetTop / 3}; | |
271 nodeNum++; | |
272 return position; | |
273 } | |
274 | |
275 /* | |
276 * | |
277 */ | |
278 function clickNodeDiv(id) { | |
279 var graphData = GRAPH_DATA; | |
280 var node = graphData.nodes[id]; | |
281 var rels = {evidence:1, | |
282 dependency:1, | |
283 derived:1, | |
284 version:1, | |
285 agreement:1}; | |
286 showRelationNodes(graphData, node, rels); | |
287 } | |
288 | |
289 function addEdgeInfo(id, kind, direction) { | |
290 var nodes = GRAPH_DATA.nodes; | |
291 var edges = GRAPH_DATA.edges; | |
292 | |
293 } | |
294 | |
295 function showEdgesAndNodes(graphData,jsonData) { | |
296 var nodes = graphData.nodes; | |
297 var jsonNodes = jsonData.nodes; | |
298 for (var i=0; i<jsonNodes.length; i++) { | |
299 var id = jsonNodes[i].id; | |
300 updateNode(nodes[id]); | |
301 } | |
302 var edges = graphData.edges; | |
303 var jsonEdges = jsonData.edges; | |
304 for (var i=0; i<edges.lenght; i++) { | |
305 var id = jsonEdges[i].id; | |
306 showEdge(graphData, edges[id]); | |
307 } | |
308 showAllEdge(graphData); | |
309 } | |
310 | |
311 function getEvidence(id, kind, direction) { | |
312 var u = "/aat/aaevidencesiftingmodel.userdesktops/get?id="+id+"&kind="+kind/*+"?direction="+direction;*/; | |
313 $.ajax({ | |
314 url:u, | |
315 success:function(o) { parseJSONGraphData(GRAPH_DATA, o); recursiveCalcPosition(GRAPH_DATA, GRAPH_DATA.nodes[id]); showEdgesAndNodes(GRAPH_DATA, o);}, | |
316 type:"GET", cache:true, | |
317 error:function(o) { console.log("getEvidence error : ", o); } | |
318 }); | |
319 } | |
320 | |
321 function traverseAction() { | |
322 var inDirChecked = $('#direction_in')[0].checked; | |
323 var outDirChecked = $('#direction_out')[0].checked; | |
324 var labelTags = $('[id=traverseLabel]'); | |
325 var kinds = []; | |
326 for (var i=0;i<labelTags.length; i++ ) { | |
327 var inputTag = labelTags[i].children[0]; | |
328 if (inputTag.checked) { | |
329 kinds.push(inputTag.value); | |
330 } | |
331 } | |
332 var id = this.id; | |
333 for (var i=0; i<kinds.length; i++) { | |
334 var kind = kinds[i]; | |
335 if (inDirChecked) getEvidence(id, kind, "in"); | |
336 if (outDirChecked) getEvidence(id, kind, "out"); | |
337 } | |
338 | |
339 } | |
340 | |
341 function createNodeDiv(node) { | |
342 node.view = $("<div class='graphNode'/>"); | |
343 node.view.click(function(){ clickNodeDiv(node.property.id) }); | |
344 if(!node.position) node.position = calcNewNodePosition(); | |
345 node.view.hover(); | |
346 var div = $("<div class='graphNodeContent' />")[0]; | |
347 div.innerHTML = node.property.title; | |
348 node.view[0].appendChild(div); | |
349 return node; | |
350 } | |
351 | |
352 function updateNodeElement(node) { | |
353 var created = false; | |
354 console.log("node = +",node); | |
355 if(!node.view) { | |
356 created = true; | |
357 createNodeDiv(node); | |
358 } | |
359 var div = node.view; | |
360 // div.text(node.property.title); | |
361 div.click(function(){showMiniDisplay(node); showTraverseDisplay(node);}); | |
362 DragHandler.attach($(node.view)[0], node.property.id); | |
363 var kindBackground = {agree:"#aaf", rejected:"#fff"}; | |
364 var kindBorder = {agree:"#66a", rejected:"#a66"}; | |
365 div.css("background", kindBackground[node.kind]||"white"); | |
366 div.css("border-color", kindBorder[node.kind] ||"#58f"); | |
367 div.css({ | |
368 left: node.position.x, | |
369 top: node.position.y | |
370 }); | |
371 return created; | |
372 } | |
373 | |
374 | |
375 function updateNode(node) { | |
376 if(updateNodeElement(node)) { | |
377 var fc = $('#graphRoot')[0].firstChild; | |
378 if(fc) { | |
379 $('#graphRoot')[0].insertBefore(node.view[0], fc); | |
380 } else { | |
381 $('#graphRoot').append(node.view); | |
382 } | |
383 } | |
384 } | |
385 | |
386 var ViewParam = { | |
387 offsetTop:100, | |
388 offsetBottom:100, | |
389 offsetLeft:100, | |
390 offsetRight:100, | |
391 nodeWidth:120, | |
392 nodeHeight:60, | |
393 intervalX:140, | |
394 intervalY:120 | |
395 }; | |
396 | |
397 var arrowConnector = { | |
398 connector:"StateMachine", | |
399 // paintStyle:{lineWidth:3,strokeStyle:"#056"}, | |
400 paintStyle:{lineWidth:2,strokeStyle:"#aaf"}, | |
401 hoverPaintStyle:{strokeStyle:"#dbe300"}, | |
402 endpoint:"Blank", | |
403 anchor:"Continuous", | |
404 overlays:[ ["PlainArrow", {location:1, width:20, length:12} ]] | |
405 }; | |
406 | |
407 var arrowBothConnector = { | |
408 connector:"StateMachine", | |
409 paintStyle:{lineWidth:2,strokeStyle:"#aaf"}, | |
410 hoverPaintStyle:{strokeStyle:"#dbe300"}, | |
411 endpoint:"Blank", | |
412 }; | |
413 | |
414 function parseJSONGraphData(memory ,jsonObj) { | |
415 var nodes = jsonObj.nodes; | |
416 for (var i=0; i<nodes.length; i++) { | |
417 var node = nodes[i]; | |
418 if (memory.nodes[node.id]) continue; | |
419 memory.nodes[node.id] = {}; | |
420 memory.nodes[node.id].in = []; | |
421 memory.nodes[node.id].out = []; | |
422 memory.nodes[node.id].both = []; | |
423 memory.nodes[node.id].property = node; | |
424 } | |
425 if (!jsonObj.edges) return memory; | |
426 var edges = jsonObj.edges; | |
427 for (var i=0; i<edges.length; i++) { | |
428 var edge = edges[i]; | |
429 var edgeId = edge.id; | |
430 if (memory.edges[edgeId]) continue; | |
431 memory.edges[edgeId] = {}; | |
432 memory.edges[edgeId].property = edge; | |
433 if (edge.kind == "both") { | |
434 memory.nodes[edge.from].both.push(edgeId); | |
435 memory.nodes[edge.to].both.push(edgeId); | |
436 } else { | |
437 memory.nodes[edge.from].out.push(edgeId); | |
438 memory.nodes[edge.to].in.push(edgeId); | |
439 } | |
440 } | |
441 return memory; | |
442 } | |
443 | |
444 function showEdge(graphData, edge) { | |
445 function connectEdge(fromNode, toNode, rel, type) { | |
446 var c; | |
447 if (type == 'both') { | |
448 c = jsPlumb.connect({source:fromNode.view[0], target:toNode.view[0]}, arrowBothConnector); | |
449 } else { | |
450 c = jsPlumb.connect({source:fromNode.view[0], target:toNode.view[0]}, arrowConnector); | |
451 } | |
452 // jsPlumb.select({source:fromNode.view[0]}).removeAllOverlays(); | |
453 c.setLabel({label:"<span style='color:#129; font-size:1.5em;'>"+rel+"</span>",cssStyle:""}); | |
454 return c; | |
455 } | |
456 if (edge.visible) return; | |
457 var fromNode = graphData.nodes[edge.property.from]; | |
458 var toNode = graphData.nodes[edge.property.to]; | |
459 if (!fromNode.view && !toNode.view) return; | |
460 var rel = edge.property.rel; | |
461 var type = edge.property.type; | |
462 connectEdge(fromNode, toNode, rel, type); | |
463 edge.visible = true; | |
464 } | |
465 | |
466 function createNodeFromEdge(graphData, edge, baseNode) { | |
467 if(edge.visible) return; | |
468 var fromNode = graphData.nodes[edge.property.from]; | |
469 if (!fromNode.view) { | |
470 updateNode(fromNode); | |
471 } | |
472 var toNode = graphData.nodes[edge.property.to]; | |
473 if (!toNode.view) { | |
474 updateNode(toNode); | |
475 } | |
476 showEdge(graphData, edge); | |
477 } | |
478 | |
479 function getRelationEdgeIds(node) { | |
480 var edgeIds = []; | |
481 for (var i=0; i<node.in.length; i++) edgeIds.push(node.in[i]); | |
482 for (var i=0; i<node.out.length; i++) edgeIds.push(node.out[i]); | |
483 for (var i=0; i<node.both.length; i++) edgeIds.push(node.both[i]); | |
484 return edgeIds; | |
485 } | |
486 | |
487 function getRelationNodeIds(graphData, node) { | |
488 var nodes = graphData.nodes; | |
489 var edges = graphData.edges; | |
490 var nodeIds = []; | |
491 for (var i=0; i<node.in.length; i++) { | |
492 var edgeId = node.in[i]; | |
493 nodeIds.push(edges[edgeId].property.from); | |
494 } | |
495 for (var i=0; i<node.out.length; i++) { | |
496 var edgeId = node.out[i]; | |
497 nodeIds.push(edges[edgeId].property.to); | |
498 } | |
499 for (var i=0; i<node.both.length; i++) { | |
500 var edgeId = node.both[i]; | |
501 var fromId = edges[edgeId].property.from; | |
502 var toId = edges[edgeId].property.to; | |
503 if (fromId == node.property.id) { | |
504 nodeIds.push(toId); | |
505 } else { | |
506 nodeIds.push(fromId); | |
507 } | |
508 } | |
509 return nodeIds; | |
510 } | |
511 | |
512 /* | |
513 * This function output all NODE that are related [node] | |
514 */ | |
515 function updateRelationNodes(graphData, node) { | |
516 var id = node.property.id; | |
517 var edges = graphData.edges; | |
518 var edgeIds = getRelationEdgeIds(node); | |
519 for (var i=0; i<edgeIds.length; i++ ) { | |
520 createNodeFromEdge(graphData, edges[edgeIds[i]]); | |
521 } | |
522 jsPlumb.removeAllEndpoints(); | |
523 jsPlumb.draggable($('.graphNode')); | |
524 } | |
525 | |
526 /* | |
527 * rels = {dependency:1, evidence:1}; | |
528 * showRelationNodes(graphData, node, rels); | |
529 */ | |
530 function showRelationNodes(graphData, node, rels) { | |
531 var id = node.property.id; | |
532 var edges = graphData.edges; | |
533 var edgeIds = getRelationEdgeIds(node); | |
534 for (var i=0; i<edgeIds.length; i++) { | |
535 var edge = edges[edgeIds[i]]; | |
536 if (rels[edge.property.rel]) { | |
537 createNodeFromEdge(graphData, edges[edgeIds[i]]); | |
538 } | |
539 } | |
540 jsPlumb.removeAllEndpoints(); | |
541 jsPlumb.draggable($('.graphNode')); | |
542 } | |
543 | |
544 var BASE_THETA = -30; | |
545 var BASE_ANGLE = 180; | |
546 var BASE_DISTANCE = 180; | |
547 function calcChildNodePosition(parent, num) { | |
548 var pX = parent.position.x; | |
549 var pY = parent.position.y; | |
550 var deg = BASE_ANGLE - num * BASE_THETA; | |
551 var theta = deg * (Math.PI / 180); | |
552 var cX = pX - (BASE_DISTANCE * Math.cos(theta)); | |
553 var cY = pY - (BASE_DISTANCE * Math.sin(theta)); | |
554 return {x:cX, y:cY}; | |
555 } | |
556 | |
557 function showAllEdge(graphData) { | |
558 var edges = graphData.edges; | |
559 for (var id in edges) { | |
560 showEdge(graphData, edges[id]); | |
561 } | |
562 jsPlumb.removeAllEndpoints(); | |
563 jsPlumb.draggable($('.graphNode')); | |
564 } | |
565 | |
566 var EDGE_LIST = { | |
567 evidence:'evidence', | |
568 dependency:'dependency', | |
569 version:'version', | |
570 derived:'derived', | |
571 agreement:'agreement' | |
572 }; | |
573 | |
574 function recursiveCalcPosition(graphData, parentNode) { | |
575 if (!parentNode.position) updateNode(parentNode); | |
576 childNodeIds = getRelationNodeIds(graphData, parentNode); | |
577 /* calcration of childNode position */ | |
578 var numCalcChild = 0; | |
579 var childArray = {}; | |
580 for (var i=0; i<childNodeIds.length; i++) { | |
581 var id = childNodeIds[i]; | |
582 var childNode = graphData.nodes[id]; | |
583 childArray[id] = childNode; | |
584 if (!childNode.position) { | |
585 childNode.position = calcChildNodePosition(parentNode, numCalcChild); | |
586 numCalcChild++; | |
587 } | |
588 } | |
589 /* calcration of grandchildNode position */ | |
590 for (var id in childArray) { | |
591 var childNode = childArray[id]; | |
592 var grandChildIds = getRelationNodeIds(graphData, childNode); | |
593 for (var i=0; i<grandChildIds.length; i++) { | |
594 var gId = grandChildIds[i]; | |
595 var grandChild = graphData.nodes[gId]; | |
596 if (!grandChild.position) { | |
597 recursiveCalcPosition(graphData, childNode); | |
598 } | |
599 } | |
600 } | |
601 } | |
602 | |
603 var GRAPH_DATA = new GraphData(); | |
604 function startUserDesktopUI() { | |
605 function showFirstEvidenceList(graphData) { | |
606 var nodes = graphData.nodes; | |
607 for (var id in nodes) { | |
608 updateNode(nodes[id]); | |
609 } | |
610 } | |
611 var gData = GRAPH_DATA; | |
612 showFirstEvidenceList(gData); | |
613 } | |
614 | |
615 function start() { | |
616 init(); | |
617 $.ajax({ | |
618 url:"/aat/aaevidencesiftingmodel.userdesktops/get", | |
619 success:function(o) { parseJSONGraphData(GRAPH_DATA, o); startUserDesktopUI();}, | |
620 type:"GET", cache:false, | |
621 error:function(o) { console.log("first get error : ",o); } | |
622 }); | |
623 } | |
624 | |
625 $(function() { | |
626 start(); | |
627 }) | |
628 | |
629 | |
630 </script> | |
631 | |
632 | |
633 | |
634 | |
635 |