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