-
Notifications
You must be signed in to change notification settings - Fork 43
/
application.js
804 lines (692 loc) · 27.4 KB
/
application.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
"use strict";
/*
Stix2viz and visjs are packaged in a way that makes them work as Jupyter
notebook extensions. Part of the extension installation process involves
copying them to a different location, where they're available via a special
"nbextensions" path. This path is hard-coded into their "require" module
IDs. Perhaps it's better to use abstract names, and add special config
in all cases to map the IDs to real paths, thus keeping the modules free
of usage-specific hard-codings. But packaging in a way I know works in
Jupyter (an already complicated environment), and having only this config
here, seemed simpler. At least, for now. Maybe later someone can structure
these modules and apps in a better way.
*/
require.config({
paths: {
"nbextensions/stix2viz/vis-network": "stix2viz/visjs/vis-network"
}
});
require(["domReady!", "stix2viz/stix2viz/stix2viz"], function (document, stix2viz) {
// Init some stuff
let view = null;
let uploader = document.getElementById('uploader');
let canvasContainer = document.getElementById('canvas-container');
let canvas = document.getElementById('canvas');
/**
* Build a message and display an alert window, from an exception object.
* This will follow the exception's causal chain and display all of the
* causes in sequence, to produce a more informative message.
*/
function alertException(exc, initialMessage=null)
{
let messages = [];
if (initialMessage)
messages.push(initialMessage);
messages.push(exc.toString());
while (exc instanceof Error && exc.cause)
{
exc = exc.cause;
messages.push(exc.toString());
}
let message = messages.join("\n\n Caused by:\n\n");
alert(message);
}
/**
* Handle clicks on the visjs graph view.
*
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
*/
function graphViewClickHandler(event, edgeDataSet, stixIdToObject)
{
if (event.nodes.length > 0)
{
// A click on a node
let stixObject = stixIdToObject.get(event.nodes[0]);
if (stixObject)
populateSelected(stixObject, edgeDataSet, stixIdToObject);
}
else if (event.edges.length > 0)
{
// A click on an edge
let stixRel = stixIdToObject.get(event.edges[0]);
if (stixRel)
populateSelected(stixRel, edgeDataSet, stixIdToObject);
else
// Just make something up to show for embedded relationships
populateSelected(
new Map([["", "(Embedded relationship)"]]),
edgeDataSet, stixIdToObject
);
}
// else, just a click on the canvas
}
/**
* Handle clicks on the list view.
*
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
*/
function listViewClickHandler(event, edgeDataSet, stixIdToObject)
{
let clickedItem = event.target;
if (clickedItem.tagName === "LI")
{
let stixId = clickedItem.id;
let stixObject = stixIdToObject.get(stixId);
view.selectNode(stixId);
if (stixObject)
populateSelected(stixObject, edgeDataSet, stixIdToObject);
else
// Just make something up to show for embedded relationships
populateSelected(
new Map([["", "(Embedded relationship)"]]),
edgeDataSet, stixIdToObject
);
}
}
/* ******************************************************
* Initializes the view, then renders it.
* ******************************************************/
function vizStixWrapper(content, customConfig) {
if (customConfig)
try
{
customConfig = JSON.parse(customConfig);
}
catch(err)
{
alertException(err, "Invalid configuration: must be JSON");
return;
}
else
customConfig = {};
// Hard-coded working icon directory setting for this application.
customConfig.iconDir = "stix2viz/stix2viz/icons";
toggleView();
try
{
let [nodeDataSet, edgeDataSet, stixIdToObject]
= stix2viz.makeGraphData(content, customConfig);
let wantsList = false;
if (nodeDataSet.length > 200)
wantsList = confirm(
"This graph contains " + nodeDataSet.length.toString()
+ " nodes. Do you wish to display it as a list?"
);
if (wantsList)
{
view = stix2viz.makeListView(
canvas, nodeDataSet, edgeDataSet, stixIdToObject,
customConfig
);
view.on(
"click",
e => listViewClickHandler(e, edgeDataSet, stixIdToObject)
);
}
else
{
view = stix2viz.makeGraphView(
canvas, nodeDataSet, edgeDataSet, stixIdToObject,
customConfig
);
view.on(
"click",
e => graphViewClickHandler(e, edgeDataSet, stixIdToObject)
);
}
populateLegend(...view.legendData);
}
catch (err)
{
console.log(err);
alertException(err);
}
}
/* ----------------------------------------------------- *
* ******************************************************
* This group of functions is for handling file "upload."
* They take an event as input and parse the file on the
* front end.
* ******************************************************/
function handleFileSelect(evt) {
handleFiles(evt.target.files);
}
function handleFileDrop(evt) {
evt.stopPropagation();
evt.preventDefault();
handleFiles(evt.dataTransfer.files);
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
function handleFiles(files) {
// files is a FileList of File objects (in our case, just one)
for (var i = 0, f; f = files[i]; i++) {
document.getElementById('chosen-files').innerText += f.name + " ";
let customConfig = document.getElementById('paste-area-custom-config').value;
var r = new FileReader();
r.onload = function(e) {vizStixWrapper(e.target.result, customConfig);};
r.readAsText(f);
}
linkifyHeader();
}
/* ---------------------------------------------------- */
/* ******************************************************
* Handles content pasted to the text area.
* ******************************************************/
function handleTextarea() {
let customConfig = document.getElementById('paste-area-custom-config').value;
let content = document.getElementById('paste-area-stix-json').value;
vizStixWrapper(content, customConfig);
linkifyHeader();
}
/* ******************************************************
* Fetches STIX 2.0 data from an external URL (supplied
* user) via AJAX. Server-side Access-Control-Allow-Origin
* must allow cross-domain requests for this to work.
* ******************************************************/
function handleFetchJson() {
var url = document.getElementById("url").value;
let customConfig = document.getElementById('paste-area-custom-config').value;
fetchJsonAjax(url, function(content) {
vizStixWrapper(content, customConfig);
});
linkifyHeader();
}
/**
* Toggle the display of graph nodes of a particular STIX type.
*/
function legendClickHandler(event)
{
if (!view)
return;
let td;
let clickedTagName = event.target.tagName.toLowerCase();
if (clickedTagName === "td")
// ... if the legend item text was clicked
td = event.target;
else if (clickedTagName === "img")
// ... if the legend item icon was clicked
td = event.target.parentElement;
else
return;
// The STIX type the user clicked on
let toggledStixType = td.textContent.trim().toLowerCase();
view.toggleStixType(toggledStixType);
// style change to remind users what they've hidden.
td.classList.toggle("typeHidden");
}
/* ******************************************************
* Adds icons and information to the legend.
* ******************************************************/
function populateLegend(iconURLMap, defaultIconURL) {
let tbody, tr, td;
let colIdx = 0;
let table = document.getElementById('legend-content');
// Reset table content if necessary.
if (table.tBodies.length === 0)
tbody = table.createTBody();
else
tbody = table.tBodies[0];
tbody.replaceChildren();
tr = tbody.insertRow();
for (let [stixType, iconURL] of iconURLMap)
{
let img = document.createElement('img');
img.onerror = function() {
// set the node's icon to the default if this image could not
// load
this.src = defaultIconURL;
// our default svg is enormous... shrink it down!
this.width = "37";
this.height = "37";
}
img.src = iconURL;
if (colIdx > 1)
{
colIdx = 0;
tr = tbody.insertRow();
}
td = tr.insertCell();
++colIdx;
td.append(img);
td.append(stixType.charAt(0).toUpperCase() + stixType.substr(1).toLowerCase());
}
}
/**
* A JSON.stringify() replacer function to enable it to handle Map objects
* like plain javascript objects.
*/
function mapReplacer(key, value)
{
if (value instanceof Map)
{
let plainObj = {};
for (let [subKey, subValue] of value)
plainObj[subKey] = subValue;
value = plainObj;
}
return value;
}
/**
* Create a rendering of an array as part of rendering an overall STIX
* object.
*
* @param arrayContent The array to render
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
* @param isRefs Whether the array is the value of a _refs property, i.e.
* an array of STIX IDs. Used to produce a distinctive rendering for
* references.
* @return The rendering as an array of DOM elements
*/
function stixArrayContentToDOMNodes(
arrayContent, edgeDataSet, stixIdToObject, isRefs=false
)
{
let nodes = [];
let ol = document.createElement("ol");
ol.className = "selected-object-list";
for (let elt of arrayContent)
{
let contentNodes;
if (isRefs)
contentNodes = stixStringContentToDOMNodes(
elt, edgeDataSet, stixIdToObject, /*isRef=*/true
);
else
contentNodes = stixContentToDOMNodes(
elt, edgeDataSet, stixIdToObject
);
let li = document.createElement("li");
li.append(...contentNodes);
ol.append(li);
}
nodes.push(document.createTextNode("["));
nodes.push(ol);
nodes.push(document.createTextNode("]"));
return nodes;
}
/**
* Create a rendering of an object/dictionary as part of rendering an
* overall STIX object.
*
* @param objectContent The object/dictionary to render, as a Map instance
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
* @param topLevel Whether objectContent is itself a whole STIX object,
* i.e. the top level of a content tree. This is used to adjust the
* rendering, e.g. omit the surrounding braces at the top level.
* @return The rendering as an array of DOM elements
*/
function stixObjectContentToDOMNodes(
objectContent, edgeDataSet, stixIdToObject, topLevel=false
)
{
let nodes = [];
if (!topLevel)
nodes.push(document.createTextNode("{"));
for (let [propName, propValue] of objectContent)
{
let propNameSpan = document.createElement("span");
propNameSpan.className = "selected-object-prop-name";
propNameSpan.append(propName + ":");
let contentNodes;
if (propName.endsWith("_ref"))
contentNodes = stixStringContentToDOMNodes(
propValue, edgeDataSet, stixIdToObject, /*isRef=*/true
);
else if (propName.endsWith("_refs"))
contentNodes = stixArrayContentToDOMNodes(
propValue, edgeDataSet, stixIdToObject, /*isRefs=*/true
);
else
contentNodes = stixContentToDOMNodes(
propValue, edgeDataSet, stixIdToObject
);
let propDiv = document.createElement("div");
propDiv.append(propNameSpan);
propDiv.append(...contentNodes);
if (!topLevel)
propDiv.className = "selected-object-object-content";
nodes.push(propDiv);
}
if (!topLevel)
nodes.push(document.createTextNode("}"));
return nodes;
}
/**
* Create a rendering of a string value as part of rendering an overall
* STIX object.
*
* @param stringContent The string to render
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
* @param isRef Whether the string is the value of a _ref property. Used
* to produce a distinctive rendering for references.
* @return The rendering as an array of DOM elements
*/
function stixStringContentToDOMNodes(
stringContent, edgeDataSet, stixIdToObject, isRef=false
)
{
let nodes = [];
let spanWrapper = document.createElement("span");
spanWrapper.append(stringContent);
if (isRef)
{
let referentObj = stixIdToObject.get(stringContent);
if (referentObj)
{
spanWrapper.className = "selected-object-text-value-ref";
spanWrapper.addEventListener(
"click", e => {
e.stopPropagation();
view.selectNode(referentObj.get("id"));
populateSelected(
referentObj, edgeDataSet, stixIdToObject
);
}
);
}
else
spanWrapper.className = "selected-object-text-value-ref-dangling";
}
else
spanWrapper.className = "selected-object-text-value";
nodes.push(spanWrapper);
return nodes;
}
/**
* Create a rendering of a value for which no other special rendering
* applies, as part of rendering an overall STIX object.
*
* @param otherContent The content to render
* @return The rendering as an array of DOM elements
*/
function stixOtherContentToDOMNodes(otherContent)
{
let nodes = [];
let asText;
if (otherContent === null)
asText = "null";
else if (otherContent === undefined)
asText = "undefined"; // also just in case??
else
asText = otherContent.toString();
let spanWrapper = document.createElement("span");
spanWrapper.append(asText);
spanWrapper.className = "selected-object-nontext-value";
nodes.push(spanWrapper);
return nodes;
}
/**
* Create a rendering of a value, as part of rendering an overall STIX
* object. This function dispatches to one of the more specialized
* rendering functions based on the type of the value.
*
* @param stixContent The content to render
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
* @return The rendering as an array of DOM elements
*/
function stixContentToDOMNodes(stixContent, edgeDataSet, stixIdToObject)
{
let nodes;
if (stixContent instanceof Map)
nodes = stixObjectContentToDOMNodes(
stixContent, edgeDataSet, stixIdToObject
);
else if (Array.isArray(stixContent))
nodes = stixArrayContentToDOMNodes(
stixContent, edgeDataSet, stixIdToObject
);
else if (
typeof stixContent === "string" || stixContent instanceof String
)
nodes = stixStringContentToDOMNodes(
stixContent, edgeDataSet, stixIdToObject
);
else
nodes = stixOtherContentToDOMNodes(stixContent);
return nodes;
}
/**
* Populate the Linked Nodes box with the connections of the given STIX
* object.
*
* @param stixObject The STIX object to display connection information
* about
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
*/
function populateConnections(stixObject, edgeDataSet, stixIdToObject)
{
let objId = stixObject.get("id");
let edges = edgeDataSet.get({
filter: item => (item.from === objId || item.to === objId)
});
let eltConnIncoming = document.getElementById("connections-incoming");
let eltConnOutgoing = document.getElementById("connections-outgoing");
eltConnIncoming.replaceChildren();
eltConnOutgoing.replaceChildren();
let listIn = document.createElement("ol");
let listOut = document.createElement("ol");
eltConnIncoming.append(listIn);
eltConnOutgoing.append(listOut);
for (let edge of edges)
{
let targetList;
let summaryNode = document.createElement("summary");
let otherEndSpan = document.createElement("span");
let otherEndObj;
if (objId === edge.from)
{
otherEndObj = stixIdToObject.get(edge.to);
otherEndSpan.append(otherEndObj.get("type"));
summaryNode.append(edge.label + " ");
summaryNode.append(otherEndSpan);
targetList = listOut;
}
else
{
otherEndObj = stixIdToObject.get(edge.from);
otherEndSpan.append(otherEndObj.get("type"));
summaryNode.append(otherEndSpan);
summaryNode.append(" " + edge.label);
targetList = listIn;
}
otherEndSpan.className = "selected-object-text-value-ref";
otherEndSpan.addEventListener(
"click", e => {
view.selectNode(otherEndObj.get("id"));
populateSelected(otherEndObj, edgeDataSet, stixIdToObject);
}
);
let li = document.createElement("li");
let detailsNode = document.createElement("details");
targetList.append(li);
li.append(detailsNode);
detailsNode.append(summaryNode);
let objRenderNodes = stixObjectContentToDOMNodes(
otherEndObj, edgeDataSet, stixIdToObject, /*topLevel=*/true
);
detailsNode.append(...objRenderNodes);
}
}
/**
* Populate relevant webpage areas according to a particular STIX object.
*
* @param stixObject The STIX object to display information about
* @param edgeDataSet A visjs DataSet instance with graph edge data derived
* from STIX content
* @param stixIdToObject A Map instance mapping STIX IDs to STIX objects as
* Maps, containing STIX content.
*/
function populateSelected(stixObject, edgeDataSet, stixIdToObject) {
// Remove old values from HTML
let selectedContainer = document.getElementById('selection');
selectedContainer.replaceChildren();
let contentNodes = stixObjectContentToDOMNodes(
stixObject, edgeDataSet, stixIdToObject, /*topLevel=*/true
);
selectedContainer.append(...contentNodes);
populateConnections(stixObject, edgeDataSet, stixIdToObject);
}
/* ******************************************************
* Toggle the view between the data entry container and
* the view container
* ******************************************************/
function toggleView() {
uploader.classList.toggle("hidden");
canvasContainer.classList.toggle("hidden");
}
/* ******************************************************
* Turns header into a "home" "link"
* ******************************************************/
function linkifyHeader() {
var header = document.getElementById('header');
header.classList.add('linkish');
}
/* *****************************************************
* Returns the page to its original load state
* *****************************************************/
function resetPage() {
var header = document.getElementById('header');
if (header.classList.contains('linkish')) {
toggleView();
if (view)
{
view.destroy();
view = null;
}
document.getElementById('files').value = ""; // reset the files input
document.getElementById('chosen-files').innerHTML = ""; // reset the subheader text
document.getElementById('selection').innerHTML = ""; // reset the selected node in the sidebar
// Reset legend table
let table = document.getElementById('legend-content');
if (table.tBodies.length > 0)
{
let tbody = table.tBodies[0];
tbody.replaceChildren();
}
// reset connections box
let eltConnIncoming = document.getElementById("connections-incoming");
let eltConnOutgoing = document.getElementById("connections-outgoing");
eltConnIncoming.replaceChildren();
eltConnOutgoing.replaceChildren();
header.classList.remove('linkish');
}
}
/* ******************************************************
* Generic AJAX 'GET' request.
*
* Takes a URL and a callback function as input.
* ******************************************************/
function fetchJsonAjax(url, cfunc) {
var regex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i;
if (!regex.test(url)) {
alert("ERROR: Double check url provided");
}
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP"); // For IE5 and IE6 luddites
}
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
cfunc(xhttp.responseText);
} else if (xhttp.status != 200 && xhttp.status != 0) {
alert("ERROR: " + xhttp.status + ": " + xhttp.statusText + " - Double check url provided");
return;
}
xhttp.onerror = function() {
alert("ERROR: Unable to fetch JSON. The domain entered has either rejected the request, \
is not serving JSON, or is not running a webserver.\n\nA GitHub Gist can be created to host RAW JSON data to prevent this.");
};
}
xhttp.open("GET", url, true);
xhttp.send();
}
/* ******************************************************
* AJAX 'GET' request from `?url=` parameter
*
* Will check the URL during `window.onload` to determine
* if `?url=` parameter is provided
* ******************************************************/
function fetchJsonFromUrl() {
var url = window.location.href;
// If `?` is not provided, load page normally
if (/\?/.test(url)) {
// Regex to see if `url` parameter has a valid url value
var regex = /\?url=https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i;
var res = regex.exec(url);
if (res != null) {
// Get the value from the `url` parameter
let req_url = res[0].substring(5);
// Fetch JSON from the url
fetchJsonAjax(req_url, function(content) {
vizStixWrapper(content)
});
linkifyHeader();
} else {
alert("ERROR: Invalid url - Request must start with '?url=http[s]://' and be a valid domain");
}
}
}
function selectedNodeClick() {
let selected = document.getElementById('selected');
if (selected.className.indexOf('clicked') === -1) {
selected.className += " clicked";
selected.style.position = 'absolute';
selected.style.left = '25px';
selected.style.width = (window.innerWidth - 110) + "px";
selected.style.top = (document.getElementById('canvas').offsetHeight + 25) + "px";
selected.scrollIntoView(true);
} else {
selected.className = "sidebar"
selected.removeAttribute("style")
}
}
/* ******************************************************
* When the page is ready, setup the visualization and bind events
* ******************************************************/
document.getElementById('files').addEventListener('change', handleFileSelect, false);
document.getElementById('paste-parser').addEventListener('click', handleTextarea, false);
document.getElementById('fetch-url').addEventListener('click', handleFetchJson, false);
document.getElementById('header').addEventListener('click', resetPage, false);
uploader.addEventListener('dragover', handleDragOver, false);
uploader.addEventListener('drop', handleFileDrop, false);
document.getElementById('selected').addEventListener('click', selectedNodeClick, false);
document.getElementById("legend").addEventListener("click", legendClickHandler, {capture: true});
fetchJsonFromUrl();
});