1 | <html><!-- |
---|
2 | ########################################################################## |
---|
3 | Author: Yushan WANG |
---|
4 | yushan.wang@lsce.ipsl.fr |
---|
5 | ########################################################################## |
---|
6 | --><head> |
---|
7 | <meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
---|
8 | |
---|
9 | <meta charset="utf-8"> |
---|
10 | <style type="text/css"> |
---|
11 | body { |
---|
12 | font-family: arial; |
---|
13 | font-size: 12px; |
---|
14 | } |
---|
15 | |
---|
16 | .row { |
---|
17 | margin-top: 10px; |
---|
18 | margin-bottom: 20px; |
---|
19 | } |
---|
20 | |
---|
21 | #mynetwork { |
---|
22 | width: 1500px; |
---|
23 | height: 1000px; |
---|
24 | border: 1px solid lightgray; |
---|
25 | } |
---|
26 | |
---|
27 | input { |
---|
28 | padding: 10px; |
---|
29 | } |
---|
30 | |
---|
31 | ul li { |
---|
32 | display: inline; |
---|
33 | border: 1px solid gray; |
---|
34 | padding: 4px; |
---|
35 | margin: 2px; |
---|
36 | border-radius: 4px; |
---|
37 | } |
---|
38 | button { |
---|
39 | background-color: rgb(132,197,255); |
---|
40 | border-radius: 8px; |
---|
41 | } |
---|
42 | |
---|
43 | /* /!\ Use border-top-color not border-color for firefox compatibility */ |
---|
44 | </style> |
---|
45 | |
---|
46 | </head> |
---|
47 | |
---|
48 | <body> |
---|
49 | <script type="text/javascript" src="graph_files/jquery.js"></script> |
---|
50 | <script type="text/javascript" src="graph_files/jquery-ui.js"></script> |
---|
51 | <script type="text/javascript" src="graph_files/bootstrap.js"></script> |
---|
52 | <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" type="text/css"> |
---|
53 | <script type="text/javascript" src="graph_files/vis.js"></script> |
---|
54 | <link href="graph_files/vis.css" rel="stylesheet" type="text/css"> |
---|
55 | <link href="graph_files/bootstrap-toggle.css" rel="stylesheet"> |
---|
56 | <script src="graph_files/bootstrap-toggle.js"></script> |
---|
57 | <script type="text/javascript"> |
---|
58 | |
---|
59 | //###################################################################################################### |
---|
60 | $(document).ready(function() |
---|
61 | { |
---|
62 | var styleArr = { |
---|
63 | 1: { // source filter |
---|
64 | background: 'LightSlateGray', |
---|
65 | border: 'SlateGray', |
---|
66 | shape: 'box'}, |
---|
67 | 2: { // pass through filter |
---|
68 | background: 'Khaki', |
---|
69 | border: 'DarkKhaki', |
---|
70 | shape: 'ellipse'}, |
---|
71 | 3: { // arithmtic filter |
---|
72 | background: 'Orchid', |
---|
73 | border: 'DarkOrchid', |
---|
74 | shape: 'ellipse'}, |
---|
75 | 4: { // spatial transform filter |
---|
76 | background: 'Orange', |
---|
77 | border: 'DarkOrange', |
---|
78 | shape: 'ellipse'}, |
---|
79 | 5: { // temporal filter |
---|
80 | background: 'YellowGreen', |
---|
81 | border: 'OliveDrab', |
---|
82 | shape: 'box'}, |
---|
83 | 6: { // file writer filter |
---|
84 | background: 'LightGray', |
---|
85 | border: 'Gray', |
---|
86 | shape: 'ellipse'}, |
---|
87 | 7: { // store filter |
---|
88 | background: 'LightBlue', |
---|
89 | border: 'Gray', |
---|
90 | shape: 'ellipse'}} |
---|
91 | |
---|
92 | var transparentNode = { |
---|
93 | background: 'white', |
---|
94 | border: 'LightGray'} |
---|
95 | |
---|
96 | var redNode = { |
---|
97 | background: 'Red', |
---|
98 | border: 'DarkRed'} |
---|
99 | |
---|
100 | var transparentEdge = { |
---|
101 | color: '#00000000', |
---|
102 | font: 0} |
---|
103 | |
---|
104 | |
---|
105 | var container = $('#mynetwork')[0]; |
---|
106 | |
---|
107 | var node; |
---|
108 | var nodes; |
---|
109 | var edges; |
---|
110 | var network; |
---|
111 | |
---|
112 | var allParentNodes = []; |
---|
113 | var allChildNodes = []; |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | //=========================================================== |
---|
119 | |
---|
120 | $('#file').on('change', function() |
---|
121 | { |
---|
122 | var file = $("#file").prop('files')[0]; |
---|
123 | handleFileSelect(file); |
---|
124 | }); |
---|
125 | |
---|
126 | |
---|
127 | function handleFileSelect(file) |
---|
128 | { |
---|
129 | if (!window.File || !window.FileReader || !window.FileList || !window.Blob) |
---|
130 | { |
---|
131 | alert('The File APIs are not fully supported in this browser.'); |
---|
132 | return; |
---|
133 | } |
---|
134 | |
---|
135 | var reader = new FileReader(); |
---|
136 | var json; |
---|
137 | |
---|
138 | reader.onload = (function(file) |
---|
139 | { |
---|
140 | return function(e) |
---|
141 | { |
---|
142 | try |
---|
143 | { |
---|
144 | json = JSON.parse(e.target.result); |
---|
145 | json.nodes.forEach(function(node, index) |
---|
146 | { |
---|
147 | var classVal = node.class; |
---|
148 | var entryVal = node.entry; |
---|
149 | var attrVal = node.attributes; |
---|
150 | var labelVal = node.label; |
---|
151 | |
---|
152 | node.color = { |
---|
153 | background: styleArr[classVal].background, |
---|
154 | border: styleArr[classVal].border, |
---|
155 | hover: styleArr[classVal].background, |
---|
156 | highlight: { |
---|
157 | background: styleArr[classVal].background, |
---|
158 | border: 'green' |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | node.shape = styleArr[classVal].shape; |
---|
163 | |
---|
164 | if (node.class == 1 || node.class >= 6) |
---|
165 | node.title = "node id = " + node.id + "</br>" + labelVal + "</br>field attributes : </br>" + attrVal; |
---|
166 | else if (node.class == 5) |
---|
167 | node.title = "node id = " + node.id + "</br>" + labelVal + "</br> entry nb = " + entryVal ; |
---|
168 | else |
---|
169 | node.title = "node id = " + node.id + "</br>" + labelVal; |
---|
170 | |
---|
171 | if (node.filled == 1) |
---|
172 | { |
---|
173 | node.title += "</br></br> filter has no child!!!</br>" + "</br>field attributes : </br>" + attrVal + "</br> entry nb = " + entryVal; |
---|
174 | node.color = { |
---|
175 | background: 'Red', |
---|
176 | border: 'DarkRed', |
---|
177 | hover: 'Red', |
---|
178 | highlight: { |
---|
179 | background: 'Red', |
---|
180 | border: 'blue' |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | node.level = node.distance; |
---|
186 | |
---|
187 | }); |
---|
188 | |
---|
189 | json.edges.forEach(function(node, index) |
---|
190 | { |
---|
191 | var dateVal = node.date; |
---|
192 | var fidVal = node.fid; |
---|
193 | var fnameVal = node.fname; |
---|
194 | var gidVal = node.gid; |
---|
195 | var attVal = node.attributes; |
---|
196 | var idVal = node.id |
---|
197 | |
---|
198 | node.title = "id = " + idVal + "</br>field attributes : </br>" + attVal + "</br> date = " + dateVal; |
---|
199 | }); |
---|
200 | |
---|
201 | |
---|
202 | nodes = new vis.DataSet(); |
---|
203 | nodes.add(json.nodes); |
---|
204 | |
---|
205 | edges = new vis.DataSet(); |
---|
206 | edges.add(json.edges); |
---|
207 | |
---|
208 | var data = { |
---|
209 | nodes: nodes, |
---|
210 | edges: edges |
---|
211 | }; |
---|
212 | |
---|
213 | var options = { |
---|
214 | edges: { |
---|
215 | smooth: false, |
---|
216 | arrows: 'to', |
---|
217 | font: { |
---|
218 | align: 'middle', |
---|
219 | size: 14, |
---|
220 | }, |
---|
221 | color: { |
---|
222 | //color: 'black', |
---|
223 | //highlight: 'black', |
---|
224 | //hover: 'black', |
---|
225 | inherit: 'both', |
---|
226 | } |
---|
227 | }, |
---|
228 | physics: { |
---|
229 | enabled: false |
---|
230 | }, |
---|
231 | nodes: { |
---|
232 | borderWidth: 2 |
---|
233 | }, |
---|
234 | interaction: { |
---|
235 | hover: true |
---|
236 | }, |
---|
237 | layout: { |
---|
238 | hierarchical: { |
---|
239 | enabled: true, |
---|
240 | direction: "LR", |
---|
241 | sortMethod: "directed", |
---|
242 | levelSeparation: 300, |
---|
243 | nodeSpacing: 100, |
---|
244 | treeSpacing: 100, |
---|
245 | blockShifting: true, |
---|
246 | edgeMinimization: true |
---|
247 | } |
---|
248 | }, |
---|
249 | }; |
---|
250 | |
---|
251 | |
---|
252 | network = new vis.Network(container, data, options); |
---|
253 | |
---|
254 | timeSelect = document.getElementById('minTimeSelect'); |
---|
255 | var length = timeSelect.options.length; |
---|
256 | for (i = length-1; i >= 1; i--) |
---|
257 | { |
---|
258 | timeSelect.options[i] = null; |
---|
259 | } |
---|
260 | |
---|
261 | timeSelect = document.getElementById('maxTimeSelect'); |
---|
262 | var length = timeSelect.options.length; |
---|
263 | for (i = length-1; i >= 1; i--) |
---|
264 | { |
---|
265 | timeSelect.options[i] = null; |
---|
266 | } |
---|
267 | |
---|
268 | var TimeList=[]; |
---|
269 | var previousTimeRecord="0"; |
---|
270 | |
---|
271 | for(var i=0; i<edges.length; i++) |
---|
272 | { |
---|
273 | var thisTime=edges.get()[i].date; |
---|
274 | if(thisTime == previousTimeRecord) |
---|
275 | { |
---|
276 | continue; |
---|
277 | } |
---|
278 | else |
---|
279 | { |
---|
280 | previousTimeRecord = thisTime; |
---|
281 | var timeExist = TimeList.includes(thisTime) |
---|
282 | if (!timeExist) |
---|
283 | { |
---|
284 | TimeList.push(thisTime) |
---|
285 | timeSelect = document.getElementById('minTimeSelect'); |
---|
286 | timeSelect.options[timeSelect.options.length] = new Option(thisTime, thisTime); |
---|
287 | timeSelect = document.getElementById('maxTimeSelect'); |
---|
288 | timeSelect.options[timeSelect.options.length] = new Option(thisTime, thisTime); |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | } |
---|
293 | |
---|
294 | |
---|
295 | Array.prototype.unique = function() |
---|
296 | { |
---|
297 | var a = this.concat(); |
---|
298 | for (var i = 0; i < a.length; ++i) |
---|
299 | { |
---|
300 | for (var j = i + 1; j < a.length; ++j) |
---|
301 | { |
---|
302 | if (a[i] === a[j]) |
---|
303 | a.splice(j--, 1); |
---|
304 | } |
---|
305 | } |
---|
306 | return a; |
---|
307 | }; |
---|
308 | |
---|
309 | function findAllParentNodes(nodesArray) |
---|
310 | { |
---|
311 | if (nodesArray.length == 0) return 1; |
---|
312 | |
---|
313 | var parentsArray = network.getConnectedNodes(nodesArray[0], 'from'); |
---|
314 | nodesArray = nodesArray.concat(parentsArray).unique(); |
---|
315 | allParentNodes = allParentNodes.concat(nodesArray[0]).unique(); |
---|
316 | |
---|
317 | nodesArray.splice(0, 1); |
---|
318 | return findAllParentNodes(nodesArray); |
---|
319 | } |
---|
320 | |
---|
321 | function findAllChildNodes(nodesArray) |
---|
322 | { |
---|
323 | if (nodesArray.length == 0) return 1; |
---|
324 | |
---|
325 | var childArray = network.getConnectedNodes(nodesArray[0], 'to'); |
---|
326 | nodesArray = nodesArray.concat(childArray).unique(); |
---|
327 | allChildNodes = allChildNodes.concat(nodesArray[0]).unique(); |
---|
328 | nodesArray.splice(0, 1); |
---|
329 | return findAllChildNodes(nodesArray); |
---|
330 | } |
---|
331 | |
---|
332 | function getEdgeConnections(node) |
---|
333 | { |
---|
334 | var connectedEdgeArray = network.getConnectedEdges(node); |
---|
335 | } |
---|
336 | |
---|
337 | network.on("click", function(params) |
---|
338 | { |
---|
339 | params.event = "[original event]"; |
---|
340 | console.log('__________________________'); |
---|
341 | nodeSelected = this.getNodeAt(params.pointer.DOM); |
---|
342 | if (nodeSelected === undefined) return 0; |
---|
343 | |
---|
344 | var node = nodes.get(nodeSelected); |
---|
345 | var connectedChild = nodes.get(network.getConnectedNodes(node.id, "to")); |
---|
346 | console.log('------->', connectedChild.length); |
---|
347 | |
---|
348 | |
---|
349 | var connectedEdgeArray = getEdgeConnections(nodeSelected); |
---|
350 | var parentsArray = network.getConnectedNodes(nodeSelected, 'from'); |
---|
351 | allParentNodes = [nodeSelected]; |
---|
352 | findAllParentNodes(parentsArray); |
---|
353 | // remove selected node |
---|
354 | var index = allParentNodes.indexOf(nodeSelected); |
---|
355 | if (index !== -1) allParentNodes.splice(index, 1); |
---|
356 | console.log('Final parent nodes: ', allParentNodes); |
---|
357 | |
---|
358 | |
---|
359 | var node = this.getNodeAt(params.pointer.DOM); |
---|
360 | var childArray = network.getConnectedNodes(nodeSelected, 'to'); |
---|
361 | |
---|
362 | |
---|
363 | allChildNodes = [nodeSelected]; |
---|
364 | findAllChildNodes(childArray); |
---|
365 | // remove selected node |
---|
366 | var index = allChildNodes.indexOf(nodeSelected); |
---|
367 | if (index !== -1) allChildNodes.splice(index, 1); |
---|
368 | console.log('Final child nodes: ', allChildNodes); |
---|
369 | }); |
---|
370 | |
---|
371 | } |
---|
372 | catch (ex) |
---|
373 | { |
---|
374 | alert('ex when trying to parse json = ' + ex); |
---|
375 | } |
---|
376 | } |
---|
377 | })(file); |
---|
378 | |
---|
379 | reader.readAsText(file); |
---|
380 | |
---|
381 | } |
---|
382 | |
---|
383 | //#################### ADD BUTTON DEFINITIONS HERE####################################################### |
---|
384 | |
---|
385 | $('#zoomEdge').on('change', function() |
---|
386 | { |
---|
387 | var options = { |
---|
388 | layout: { |
---|
389 | hierarchical: { |
---|
390 | levelSeparation: parseInt(this.value) |
---|
391 | } |
---|
392 | } |
---|
393 | } |
---|
394 | network.setOptions(options); |
---|
395 | }); |
---|
396 | |
---|
397 | |
---|
398 | $('#hideAll').on('click', function() |
---|
399 | { |
---|
400 | var all_edges = edges.get() |
---|
401 | for(j=0; j<all_edges.length; j++) |
---|
402 | { |
---|
403 | all_edges[j].hidden = true |
---|
404 | } |
---|
405 | edges.update(all_edges) |
---|
406 | |
---|
407 | var all_nodes = nodes.get(); |
---|
408 | for (i = 0; i < all_nodes.length; i++) |
---|
409 | { |
---|
410 | all_nodes[i].hidden = true; |
---|
411 | } |
---|
412 | nodes.update(all_nodes); |
---|
413 | }); |
---|
414 | |
---|
415 | |
---|
416 | $('#showAll').on('click', function() |
---|
417 | { |
---|
418 | var all_edges = edges.get() |
---|
419 | for(j=0; j<all_edges.length; j++) |
---|
420 | { |
---|
421 | all_edges[j].hidden = false |
---|
422 | } |
---|
423 | edges.update(all_edges) |
---|
424 | |
---|
425 | var all_nodes = nodes.get(); |
---|
426 | for (i = 0; i < all_nodes.length; i++) |
---|
427 | { |
---|
428 | all_nodes[i].hidden = false; |
---|
429 | } |
---|
430 | nodes.update(all_nodes); |
---|
431 | }); |
---|
432 | |
---|
433 | |
---|
434 | $('#showInputs').on('click', function() |
---|
435 | { |
---|
436 | var all_edges = edges.get() |
---|
437 | for(j=0; j<all_edges.length; j++) |
---|
438 | { |
---|
439 | all_edges[j].hidden = false |
---|
440 | } |
---|
441 | edges.update(all_edges) |
---|
442 | |
---|
443 | var all_nodes = nodes.get(); |
---|
444 | for (i = 0; i < all_nodes.length; i++) |
---|
445 | { |
---|
446 | if (all_nodes[i].class == 1) all_nodes[i].hidden = false; |
---|
447 | else all_nodes[i].hidden = true; |
---|
448 | } |
---|
449 | nodes.update(all_nodes); |
---|
450 | }); |
---|
451 | |
---|
452 | |
---|
453 | $('#showOutputs').on('click', function() |
---|
454 | { |
---|
455 | var all_edges = edges.get() |
---|
456 | for(j=0; j<all_edges.length; j++) |
---|
457 | { |
---|
458 | all_edges[j].hidden = false |
---|
459 | } |
---|
460 | edges.update(all_edges) |
---|
461 | |
---|
462 | var all_nodes = nodes.get(); |
---|
463 | for (i = 0; i < all_nodes.length; i++) |
---|
464 | { |
---|
465 | if (all_nodes[i].class >= 6 || all_nodes[i].filled == 1) all_nodes[i].hidden = false; |
---|
466 | else all_nodes[i].hidden = true; |
---|
467 | } |
---|
468 | nodes.update(all_nodes); |
---|
469 | }); |
---|
470 | |
---|
471 | $('#showSubgraph').on('click', function() |
---|
472 | { |
---|
473 | // do nothing if no node is selected |
---|
474 | var thisNode = nodes.get(nodeSelected); |
---|
475 | if(!thisNode) return; |
---|
476 | |
---|
477 | var all_edges = edges.get() |
---|
478 | for(j=0; j<all_edges.length; j++) |
---|
479 | { |
---|
480 | all_edges[j].hidden = false |
---|
481 | } |
---|
482 | edges.update(all_edges) |
---|
483 | |
---|
484 | // hide all nodes |
---|
485 | var all_nodes = nodes.get(); |
---|
486 | for (i = 0; i < all_nodes.length; i++) |
---|
487 | { |
---|
488 | all_nodes[i].hidden = true; |
---|
489 | } |
---|
490 | nodes.update(all_nodes); |
---|
491 | |
---|
492 | // enable selected node |
---|
493 | thisNode.hidden = false; |
---|
494 | nodes.update(thisNode); |
---|
495 | |
---|
496 | // enable all parents |
---|
497 | console.log("showAllParents: allParentNodes = ", allParentNodes); |
---|
498 | var parent_nodes = nodes.get(allParentNodes); |
---|
499 | |
---|
500 | for (i = 0; i < parent_nodes.length; i++) |
---|
501 | { |
---|
502 | var node = parent_nodes[i]; |
---|
503 | node.font = { |
---|
504 | color: 'black' |
---|
505 | } |
---|
506 | node.hidden = false; |
---|
507 | if (node.filled == 1) { |
---|
508 | node.color = { |
---|
509 | background: redNode.background, |
---|
510 | border: redNode.border, |
---|
511 | hover: redNode.background, |
---|
512 | highlight: { |
---|
513 | background: redNode.background, |
---|
514 | border: 'blue' |
---|
515 | } |
---|
516 | } |
---|
517 | } |
---|
518 | else |
---|
519 | { |
---|
520 | node.color = { |
---|
521 | background: styleArr[node.class].background, |
---|
522 | border: styleArr[node.class].border, |
---|
523 | highlight: { |
---|
524 | background: styleArr[node.class].background, |
---|
525 | border: 'blue' |
---|
526 | } |
---|
527 | } |
---|
528 | } |
---|
529 | } |
---|
530 | nodes.update(parent_nodes); |
---|
531 | |
---|
532 | var connectedEdgeArray = edges.get(network.getConnectedEdges(thisNode.id)); |
---|
533 | for (j = 0; j < connectedEdgeArray.length; j++) |
---|
534 | { |
---|
535 | var edge = connectedEdgeArray[j]; |
---|
536 | if (edge.to == thisNode.id) edge.hidden = false; |
---|
537 | } |
---|
538 | edges.update(connectedEdgeArray); |
---|
539 | |
---|
540 | all_nodes = nodes.get(); |
---|
541 | nodes.update(all_nodes); |
---|
542 | |
---|
543 | //===== enable all children |
---|
544 | console.log("showAllChildren: allChildNodes = ", allChildNodes); |
---|
545 | var child_nodes = nodes.get(allChildNodes); |
---|
546 | for (i = 0; i < child_nodes.length; i++) |
---|
547 | { |
---|
548 | node = child_nodes[i]; |
---|
549 | node.font = { |
---|
550 | color: 'black' |
---|
551 | } |
---|
552 | node.hidden = false; |
---|
553 | if (node.filled == 1) { |
---|
554 | node.color = { |
---|
555 | background: redNode.background, |
---|
556 | border: redNode.border, |
---|
557 | hover: redNode.background, |
---|
558 | highlight: { |
---|
559 | background: redNode.background, |
---|
560 | border: 'blue' |
---|
561 | } |
---|
562 | } |
---|
563 | } |
---|
564 | else |
---|
565 | { |
---|
566 | node.color = { |
---|
567 | background: styleArr[node.class].background, |
---|
568 | border: styleArr[node.class].border, |
---|
569 | highlight: { |
---|
570 | background: styleArr[node.class].background, |
---|
571 | border: 'blue' |
---|
572 | } |
---|
573 | } |
---|
574 | } |
---|
575 | } |
---|
576 | nodes.update(child_nodes); |
---|
577 | |
---|
578 | connectedEdgeArray = edges.get(network.getConnectedEdges(thisNode.id)); |
---|
579 | for (j = 0; j < connectedEdgeArray.length; j++) |
---|
580 | { |
---|
581 | var edge = connectedEdgeArray[j]; |
---|
582 | if (edge.from == thisNode.id) edge.hidden = false; |
---|
583 | } |
---|
584 | edges.update(connectedEdgeArray); |
---|
585 | }); |
---|
586 | |
---|
587 | $('#showSubgraphBis').on('click', function() |
---|
588 | { |
---|
589 | // do nothing if no node is selected |
---|
590 | var thisNode = nodes.get(nodeSelected); |
---|
591 | if(!thisNode) return; |
---|
592 | |
---|
593 | var all_edges = edges.get() |
---|
594 | for(j=0; j<all_edges.length; j++) |
---|
595 | { |
---|
596 | all_edges[j].hidden = false |
---|
597 | } |
---|
598 | edges.update(all_edges) |
---|
599 | |
---|
600 | // enable selected node |
---|
601 | thisNode.hidden = false; |
---|
602 | nodes.update(thisNode); |
---|
603 | |
---|
604 | // enable all parents |
---|
605 | console.log("showAllParents: allParentNodes = ", allParentNodes); |
---|
606 | var parent_nodes = nodes.get(allParentNodes); |
---|
607 | |
---|
608 | for (i = 0; i < parent_nodes.length; i++) |
---|
609 | { |
---|
610 | var node = parent_nodes[i]; |
---|
611 | node.font = { |
---|
612 | color: 'black' |
---|
613 | } |
---|
614 | node.hidden = false; |
---|
615 | if (node.filled == 1) { |
---|
616 | node.color = { |
---|
617 | background: redNode.background, |
---|
618 | border: redNode.border, |
---|
619 | hover: redNode.background, |
---|
620 | highlight: { |
---|
621 | background: redNode.background, |
---|
622 | border: 'blue' |
---|
623 | } |
---|
624 | } |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | node.color = { |
---|
629 | background: styleArr[node.class].background, |
---|
630 | border: styleArr[node.class].border, |
---|
631 | highlight: { |
---|
632 | background: styleArr[node.class].background, |
---|
633 | border: 'blue' |
---|
634 | } |
---|
635 | } |
---|
636 | } |
---|
637 | } |
---|
638 | nodes.update(parent_nodes); |
---|
639 | |
---|
640 | var connectedEdgeArray = edges.get(network.getConnectedEdges(thisNode.id)); |
---|
641 | for (j = 0; j < connectedEdgeArray.length; j++) |
---|
642 | { |
---|
643 | var edge = connectedEdgeArray[j]; |
---|
644 | if (edge.to == thisNode.id) edge.hidden = false; |
---|
645 | } |
---|
646 | edges.update(connectedEdgeArray); |
---|
647 | |
---|
648 | all_nodes = nodes.get(); |
---|
649 | nodes.update(all_nodes); |
---|
650 | |
---|
651 | //===== enable all children |
---|
652 | console.log("showAllChildren: allChildNodes = ", allChildNodes); |
---|
653 | var child_nodes = nodes.get(allChildNodes); |
---|
654 | for (i = 0; i < child_nodes.length; i++) |
---|
655 | { |
---|
656 | node = child_nodes[i]; |
---|
657 | node.font = { |
---|
658 | color: 'black' |
---|
659 | } |
---|
660 | node.hidden = false; |
---|
661 | if (node.filled == 1) { |
---|
662 | node.color = { |
---|
663 | background: redNode.background, |
---|
664 | border: redNode.border, |
---|
665 | hover: redNode.background, |
---|
666 | highlight: { |
---|
667 | background: redNode.background, |
---|
668 | border: 'blue' |
---|
669 | } |
---|
670 | } |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | node.color = { |
---|
675 | background: styleArr[node.class].background, |
---|
676 | border: styleArr[node.class].border, |
---|
677 | highlight: { |
---|
678 | background: styleArr[node.class].background, |
---|
679 | border: 'blue' |
---|
680 | } |
---|
681 | } |
---|
682 | } |
---|
683 | } |
---|
684 | nodes.update(child_nodes); |
---|
685 | |
---|
686 | connectedEdgeArray = edges.get(network.getConnectedEdges(thisNode.id)); |
---|
687 | for (j = 0; j < connectedEdgeArray.length; j++) |
---|
688 | { |
---|
689 | var edge = connectedEdgeArray[j]; |
---|
690 | if (edge.from == thisNode.id) edge.hidden = false; |
---|
691 | } |
---|
692 | edges.update(connectedEdgeArray); |
---|
693 | }); |
---|
694 | |
---|
695 | |
---|
696 | $('#showDirectChild').on('click', function() |
---|
697 | { |
---|
698 | // do nothing if no node is selected |
---|
699 | var thisNode = nodes.get(nodeSelected); |
---|
700 | if(!thisNode) return; |
---|
701 | |
---|
702 | var all_edges = edges.get() |
---|
703 | for(j=0; j<all_edges.length; j++) |
---|
704 | { |
---|
705 | all_edges[j].hidden = false |
---|
706 | } |
---|
707 | edges.update(all_edges) |
---|
708 | |
---|
709 | //===== enable all children |
---|
710 | var directChildNodes = nodes.get(network.getConnectedNodes(nodeSelected, 'to')); |
---|
711 | |
---|
712 | if(!directChildNodes.length) return; |
---|
713 | console.log("showDirectChild: directChildNodes = ", directChildNodes); |
---|
714 | |
---|
715 | for (i = 0; i < directChildNodes.length; i++) |
---|
716 | { |
---|
717 | directChildNodes[i].hidden = false; |
---|
718 | } |
---|
719 | nodes.update(directChildNodes); |
---|
720 | }); |
---|
721 | |
---|
722 | $('#showDirectParent').on('click', function() |
---|
723 | { |
---|
724 | // do nothing if no node is selected |
---|
725 | var thisNode = nodes.get(nodeSelected); |
---|
726 | if(!thisNode) return; |
---|
727 | |
---|
728 | var all_edges = edges.get() |
---|
729 | for(j=0; j<all_edges.length; j++) |
---|
730 | { |
---|
731 | all_edges[j].hidden = false |
---|
732 | } |
---|
733 | edges.update(all_edges) |
---|
734 | |
---|
735 | //===== enable all parents |
---|
736 | var directParentNodes = nodes.get(network.getConnectedNodes(nodeSelected, 'from')); |
---|
737 | |
---|
738 | if(!directParentNodes.length) return; |
---|
739 | console.log("directParentNodes: directParentNodes = ", directParentNodes); |
---|
740 | |
---|
741 | for (i = 0; i < directParentNodes.length; i++) |
---|
742 | { |
---|
743 | directParentNodes[i].hidden = false; |
---|
744 | } |
---|
745 | nodes.update(directParentNodes); |
---|
746 | }); |
---|
747 | |
---|
748 | $('#showNode').on('click', function() |
---|
749 | { |
---|
750 | // do nothing if no node is selected |
---|
751 | var thisNode = nodes.get(nodeSelected); |
---|
752 | if(!thisNode) return; |
---|
753 | |
---|
754 | var all_edges = edges.get() |
---|
755 | for(j=0; j<all_edges.length; j++) |
---|
756 | { |
---|
757 | all_edges[j].hidden = false |
---|
758 | } |
---|
759 | edges.update(all_edges) |
---|
760 | |
---|
761 | |
---|
762 | var all_nodes = nodes.get(); |
---|
763 | for (i = 0; i < all_nodes.length; i++) |
---|
764 | { |
---|
765 | all_nodes[i].hidden = true; |
---|
766 | } |
---|
767 | |
---|
768 | nodes.update(all_nodes); |
---|
769 | |
---|
770 | thisNode.hidden = false; |
---|
771 | nodes.update(thisNode) |
---|
772 | }); |
---|
773 | |
---|
774 | $('#minTimeSelect').on('change', function() |
---|
775 | { |
---|
776 | var all_edges = edges.get() |
---|
777 | |
---|
778 | var minTime = document.querySelector('#minTimeSelect').value; |
---|
779 | var maxTime = document.querySelector('#maxTimeSelect').value; |
---|
780 | |
---|
781 | console.log("min : ", minTime) |
---|
782 | console.log("max : ", maxTime) |
---|
783 | |
---|
784 | for(j=0; j<all_edges.length; j++) |
---|
785 | { |
---|
786 | all_edges[j].hidden = true |
---|
787 | if(minTime <= all_edges[j].date && all_edges[j].date <= maxTime) |
---|
788 | { |
---|
789 | all_edges[j].hidden = false |
---|
790 | } |
---|
791 | } |
---|
792 | edges.update(all_edges) |
---|
793 | |
---|
794 | var all_nodes=nodes.get(); |
---|
795 | |
---|
796 | for (i=0; i<all_nodes.length; i++) |
---|
797 | { |
---|
798 | all_nodes[i].hidden = true |
---|
799 | var edgeList = edges.get(network.getConnectedEdges(all_nodes[i].id)); |
---|
800 | for(j=0; j<edgeList.length; j++) |
---|
801 | { |
---|
802 | if(edgeList[j].hidden == false) |
---|
803 | { |
---|
804 | all_nodes[i].hidden = false |
---|
805 | break |
---|
806 | } |
---|
807 | } |
---|
808 | } |
---|
809 | nodes.update(all_nodes) |
---|
810 | }); |
---|
811 | |
---|
812 | $('#maxTimeSelect').on('change', function() |
---|
813 | { |
---|
814 | var all_edges = edges.get() |
---|
815 | |
---|
816 | var minTime = document.querySelector('#minTimeSelect').value; |
---|
817 | var maxTime = document.querySelector('#maxTimeSelect').value; |
---|
818 | |
---|
819 | console.log("min : ", minTime) |
---|
820 | console.log("max : ", maxTime) |
---|
821 | |
---|
822 | for(j=0; j<all_edges.length; j++) |
---|
823 | { |
---|
824 | all_edges[j].hidden = true |
---|
825 | if(minTime <= all_edges[j].date && all_edges[j].date <= maxTime) |
---|
826 | { |
---|
827 | all_edges[j].hidden = false |
---|
828 | } |
---|
829 | } |
---|
830 | edges.update(all_edges) |
---|
831 | |
---|
832 | var all_nodes=nodes.get(); |
---|
833 | |
---|
834 | for (i=0; i<all_nodes.length; i++) |
---|
835 | { |
---|
836 | all_nodes[i].hidden = true |
---|
837 | var edgeList = edges.get(network.getConnectedEdges(all_nodes[i].id)); |
---|
838 | for(j=0; j<edgeList.length; j++) |
---|
839 | { |
---|
840 | if(edgeList[j].hidden == false) |
---|
841 | { |
---|
842 | all_nodes[i].hidden = false |
---|
843 | break |
---|
844 | } |
---|
845 | } |
---|
846 | |
---|
847 | } |
---|
848 | |
---|
849 | nodes.update(all_nodes) |
---|
850 | }); |
---|
851 | |
---|
852 | |
---|
853 | |
---|
854 | //#################### END OF BUTTON DEFINITIONS ######################################################## |
---|
855 | }); |
---|
856 | |
---|
857 | </script> |
---|
858 | |
---|
859 | <div class="container"> |
---|
860 | |
---|
861 | <div class="row"> |
---|
862 | <label for="file"> Choose your JSON file |
---|
863 | <input type="file" id="file" onchange="$('#upload-file-info').html(this.files[0].name)"> |
---|
864 | </label> |
---|
865 | </div> |
---|
866 | |
---|
867 | <div class="row"> |
---|
868 | <button type="button" id="showAll">Show all</button> |
---|
869 | <button type="button" id="hideAll">Hide all</button> |
---|
870 | </div> |
---|
871 | |
---|
872 | <div class="row"> |
---|
873 | <button type="button" id="showInputs">Show all inputs</button> |
---|
874 | <button type="button" id="showOutputs">Show all outputs</button> |
---|
875 | </div> |
---|
876 | |
---|
877 | <div class="row"> |
---|
878 | <button type="button" id="showDirectChild">Show direct child(ren)</button> |
---|
879 | <button type="button" id="showDirectParent">Show direct parent(s)</button> |
---|
880 | </div> |
---|
881 | |
---|
882 | <div class="row"> |
---|
883 | <button type="button" id="showNode">Show this node (and hide other)</button> |
---|
884 | <button type="button" id="showSubgraph">Show subgraph (and hide other)</button> |
---|
885 | <button type="button" id="showSubgraphBis">Show subgraph (and keep other)</button> |
---|
886 | </div> |
---|
887 | |
---|
888 | <div class="row" style="width:300px"> |
---|
889 | <p> Choose Edge Length : </p> |
---|
890 | <input autocomplete="off" type="range" id="zoomEdge" min="200" max="600" value="300" step="10"> |
---|
891 | |
---|
892 | |
---|
893 | </div> |
---|
894 | |
---|
895 | <div class="row" style="width:800px"> |
---|
896 | <p>Focus on time : </p> |
---|
897 | From |
---|
898 | <select id="minTimeSelect"> |
---|
899 | <option value="0000-00-00 00:00:00" selected="selected" hidden="">-</option> |
---|
900 | </select> |
---|
901 | To |
---|
902 | <select id="maxTimeSelect"> |
---|
903 | <option value="9999-00-00 00:00:00" selected="selected" hidden="">-</option> |
---|
904 | </select> |
---|
905 | |
---|
906 | </div> |
---|
907 | |
---|
908 | |
---|
909 | <div class="row"> |
---|
910 | <div id="mynetwork"></div> |
---|
911 | </div> |
---|
912 | |
---|
913 | |
---|
914 | |
---|
915 | |
---|
916 | </div></body></html> |
---|