-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
683 lines (612 loc) · 25.8 KB
/
index.html
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
<html>
<head>
<title>Hierarchical data visualization</title>
<style>
#frame {
position: absolute;
top: 0;
bottom: 0;
left: 285;
right: 0;
z-index: 0;
}
#sliderObj {
position: absolute;
top: 35;
left: 305;
z-index: 1;
font-family: sans-serif;
}
#labelproperty2 {
position: absolute;
top: 5;
left: 305;
z-index: 1;
color: black;
font-family: sans-serif;
}
#title {
position: absolute;
top: 15;
right: 15;
z-index: 1;
color: white;
font-family: sans-serif;
}
#comboObj {
position: absolute;
top: 260;
left: 15;
z-index: 1;
font-family: sans-serif;
}
#colortable {
position: absolute;
top: 320;
left: 15;
z-index: 1;
font-family: sans-serif;
}
</style>
<style type="text/css">
.fieldset-auto-width {
display: inline-block;
}
</style>
</head>
<body>
<h1 style=" font: 20px Arial ; color: darkblue">Hierarchical data visualization</h1>
<p> </p>
<p> </p>
<p> </p>
<!--UI components-->
<fieldset class="fieldset-auto-width" style="font: 15px Arial">
<legend style=" font: 15px Arial">Search by id, name, category, etc... </legend>
<p> </p>
<input type="text" name="search" id="search" class="textbox" />
<button style=" font: 14px Arial" onclick="searchSequence()" name="button">Search</button>
</fieldset>
<p> </p> <p> </p>
<fieldset class="fieldset-auto-width" style="font: 15px Arial">
<legend style=" font: 15px Arial">Visualization options</legend>
<p> </p>
<input type="checkbox" name="showedges" id="showedges" />
<label style=" font: 15px Arial"> Show links to representatives</label>
<p> </p>
<button style=" font: 14px Arial" onclick="ShowExpandableNodes()" name="button">Show expandables</button>
<button style=" font: 14px Arial" onclick="ReturnAllColors()" name="button">Resume colors</button>
<p> </p>
<button style=" font: 14px Arial" onclick="redrawInitialScene()" name="button">Centralize</button>
</fieldset>
<p> </p>
<div id="frame"></div>
<div id="sliderObj" min="0" step="1" value="0" vertical="false" size="245"></div>
<div id="labelproperty2" style=" font: 15px Arial">Hover over a point to see its information. Press Ctrl+z to close the last open clusters. Right-click to rotate, right-click again to stop a rotation.</div>
<div>
<fieldset class="fieldset-auto-width" style="font: 15px Arial">
<legend style=" font: 15px Arial">Coloring by intensity of property</legend>
<p> Select a property: </p>
<select name="combo" id="combo"></select>
<p> Click inside the field to select a color: </p>
<input type="text" id="inputcolor" colorbox="true">
<p>
<button style=" font: 14px Arial" onclick="ReturnAllColors()" name="button">Resume colors</button>
</p>
</fieldset>
</div>
<link rel="stylesheet" type="text/css" href="src/dhtmlxcolorpicker.css">
<script src="src/dhtmlxcolorpicker.js"></script>
<link rel="stylesheet" type="text/css" href="src/dhtmlxpopup.css">
<script src="src/dhtmlxpopup.js"></script>
<link rel="stylesheet" type="text/css" href="src/dhtmlxslider.css">
<script src="src/dhtmlxslider.js"></script>
<script src="dist/graphosaurus.js"></script>
<script src="src/uifunctions.js"></script>
<script src="data/MetaData.js"></script>
<script charset="4">
//################# global variables definitions start here
var dataFolder = "data";
var smallDataFile = "smalldata.json";
var dataFile = "data.json";
var frameStartsAt = 285;
var edgesShow = document.getElementById("showedges");
var myColorpicker;//UI
var cursorX;//used in Popup for UI
var cursorY;//used in Popup for UI
var mySlider;//UI
var myPop = new dhtmlXPopup();//UI
var myPopSlider;//the popup over the slider
var pointsSet;
var previousNumberOfNodes = []; //is used in ctrl+z, holds the previous number of nodes for every click
var previousNumberOfEdges = []; //is used in ctrl+z, holds the previous number of edges for every click
var clicked = 0; //counter of node clicks, is used in ctrl+z
var lastOpenNode = [];//is used in ctrl+z, holds the open node for every click
var nodesColor = "yellow";
var CurrentDir = [];//for every nodeID
var CurrentLevel = [];//also
var edges = [];//edges is a backup of the current edges in the graph, regardless of whether they are shown or not.
var previoslyhoveredNode;//hovering changes temporarily the color of a node to white, therefore we need to remember this
var previosHoveredcolor;//the color of previoslyhoveredNode
var smallData; // would hold all data in case bigdata == false
var graph = InitializeGraph();
var renderFrame;
var totalNumberOfLevels;// in the hierarchical clustering
var selectedPropertyIndex;//holds the index of the most recently selected numerical property (by the user)
var previousColor = [];//used in resume colors
var expandable = new Object();//expandable[5987][3] is true if and only if node with id 5987 is expandable at level 3
//################# global variables definitions end here
//################# global code starts here
if (bigData == false) {//bigData is defined in "data/MetaData.js"
mySlider = new dhtmlXSlider("sliderObj");
myPopSlider = new dhtmlXPopup({ slider: mySlider });
defineSlider();
updateSliderPopupValue(mySlider.getValue());
}
defineCombo();
defineColorPicker2();
document.onmousemove = function (e) {//we have to track where the mouse is for the pop-up message
cursorX = e.clientX;
cursorY = e.clientY;
}
document.onclick = function (e) {
myPop.hide();
}
if (bigData == false) {
var filename = dataFolder + "/" + smallDataFile;
fetchJSONFile(filename, function (datasmall) {
smallData = datasmall;
totalNumberOfLevels = FindTotalNumberOfLevels(datasmall);
ComputeExpandables(datasmall);
InitDrawing();
var sliderValue = totalNumberOfLevels - 2;
if (sliderValue < 0) { sliderValue = 0;}
mySlider.setValue(sliderValue);
showedges.checked = true;
fastLoadUpToLevel(sliderValue);
});
}
else {
InitDrawing();
}
//################## global code ends here
//################## the functions definitions start here
function InitDrawing() {
//this requests the file and executes a callback with the parsed result once
// it is available. Calling the level zero
var filename = dataFolder + "/" + dataFile;
fetchJSONFile(filename, function (data) {
// do something with your data
totalNumberOfLevels = FindTotalNumberOfLevels(data);
if (bigData == false) {
mySlider.setMax(totalNumberOfLevels - 1);
}
AddLevelZero(data);
renderFrame = graph.renderIn("frame");
renderFrame.reDrawMe();
});
document.onkeydown = KeyPress;//see src/uifunctions.js. This function is for handling ctrl+z events
//edgesShow.checked = false; //hide edges by default
edgesShow.onchange = function () {
redrawSameScene();
}
}
function InitializeGraph() {
return G.graph({
sizeAttenuation: true,//whether to change the size of the nodes for a 3D effect or not
nodeImage: "imgs/disc.png",
nodeImageTransparent: true,
antialias: true,
bgColor: 'lightgrey',//'lightskyblue',
nodeSize: 0.016,//change to 1 if sizeAttenuation = false, otherwise the nodes are too small and not visible
edgeWidth: 0.005,//change to 1 if sizeAttenuation = false
hover: function (node) {//what should happen when a user hovers over a node with the mouse
HandleNodeHovering(node);
},
mousedown: function (node) {//what should happen when a user clicks on a node
HandleNodeClicking(node);
}
});
}
function fetchJSONFile(path, callback) //for asynchronously downloading a file from the server. do not change it
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
var data = JSON.parse(httpRequest.responseText);
if (callback) callback(data);
}
}
};
httpRequest.open('GET', path);
httpRequest.send();
}
function ComputeExpandables(data)//is called in case of small data. Parameter data contains all (small) data. Computes the global double array expandable
{
for (var key in data) {
expandable[key] = [];
for (var i = 0; i < totalNumberOfLevels; i++) {
expandable[key][i] = false;
}
}
for (var key in data) {
var path = data[key].Path.slice();
path.push(key);
for (var i = 0; i < path.length; i++) {
var tempKey = path[i];
for (var j = i + 1; j < path.length; j++) {
if (path[j] != tempKey) {
expandable[tempKey][i] = true;
}
}
}
}
}
function HandleNodeHovering(node) {
if (previoslyhoveredNode != undefined)//if some node was hovered before, return its color
{ previoslyhoveredNode.setColorHex("#" + previosHoveredcolor); }
previosHoveredcolor = node.getColor();
previoslyhoveredNode = node;
node.setColor("white");//make hovered node white
redrawSameScene();
var categories = node._categoriesValues;
var text = node.getId(); //+ "<br>" + props[0] + "<br>" + props[2] + "<br>" + props[4]
for (var i = 0; i < categories.length; i++) { text += "<br>" + categories[i]; }
if (node._expandable) { text = "Click to open! <br> " + text; }
myPop.attachHTML(text);
myPop.show(cursorX, cursorY, 2, 3); //params are: x, y, width, height. 3 and 5 are number of pixels relative to the node where the message should appear(you can play with these numbers)
}
function HandleNodeClicking(node) {
if (node._expandable) {
clicked++;
lastOpenNode[clicked] = node;
previousNumberOfNodes[clicked] = graph.getNodes().length;
if (edges.length == 0)
{ previousNumberOfEdges[clicked] = 0; }
else
{ previousNumberOfEdges[clicked] = edges.length; }
AddNextLevelForNode(node.getId());
}
}
function AddLevelZero(data) //adds all data in 'data', the latter should contain only the zero level
{
for (var key in data) {
AddNodeAtLevelZero(data, key);
CheckIfNodeIsExpandable(key, dataFolder);
}
}
function PrepareColorZero(coords) {
var red = Math.floor((coords[0] * coords[0] * 1643 % 256) + 1);
var green = Math.floor((coords[1] * coords[1] * 328 % 256) + 1);
var blue = Math.floor((coords[2] * coords[2] * 487 % 256) + 1);
return "rgb(" + red + "," + green + "," + blue + ")";
}
function AddNextLevelForNode(nodeId) {
//this requests the file and executes a callback with the parsed result once
// it is available
var path = CurrentDir[nodeId] + "/" + nodeId + "/" + dataFile;
fetchJSONFile(path, function (data) {
var dir = CurrentDir[nodeId];
AddPointsFromList(data, nodeId, CurrentLevel[nodeId], dir);
redrawSameScene();
});
}
function CheckIfNodeIsExpandable(nodeId, startdir) {
var level = NumberOfLevels(startdir);
var node = graph._nodeIds[nodeId];
if (bigData == false) {
node._expandable = expandable[nodeId][level];
}
else {
if (node != undefined) {
node._expandable = false;
if (level < totalNumberOfLevels - 1) {
var file = startdir + "/" + nodeId + "/" + dataFile;
fetchJSONFile(file, function (data) {
if (Object.keys(data).length > 1) {
node._expandable = true;
}
else {
CheckIfNodeIsExpandable(nodeId, startdir + "/" + nodeId);
}
});
}
}
}
}
function NumberOfLevels(startdir) {
var r = (startdir.split("/").length - 1)
return r;
}
function AddPointsFromList(data, parentid, level, dir) {
var colorPoint = PrepareColor(level + 1, parentid);
for (var key in data) {
PrepareNodeAndAddIt(data, key, colorPoint);
var pointid = key;
CurrentDir[pointid] = dir + "/" + parentid;
CurrentLevel[pointid]++;
CheckIfNodeIsExpandable(pointid, CurrentDir[pointid]);
AddNewEdge(parentid, pointid, colorPoint);
}
}
function PrepareColor(level, parentId)// a unique color per parent and level
{
var y = parentId;
return "rgb(" + 111 * (level + 1) * (y + 1) % 256 + "," + 20 * (level + 1) * (y + 1) % 256 + "," + 50 * (level + 1) * (y + 1) % 256 + ")";
}
function PrepareNodeAndAddIt(data, key, colorPoint) {
var point = data[key];
var pointid = key;
var coords = point.Coordinates;
var nodecategories = point.Categories;
var nodeProperties = point.Properties;
var node = G.node(coords, {
id: pointid,
categoriesValues: nodecategories,
propertiesValues: nodeProperties,
color: colorPoint,
});
node.addTo(graph);
var node = graph.getNode(key);
node.setColor(colorPoint);
}
function fastLoadAllData() {
if (bigData == true) {
alert("There is too much data, please click on nodes to expand their clusters");
}
else {
fastLoadUpToLevel(totalNumberOfLevels - 1);
}
}
function fastLoadUpToLevel(level) {
if (smallData == undefined) {
var fileName = dataFolder + "/" + smallDataFile;
fetchJSONFile(fileName, function (data) {
smallData = data;
FastImportData(smallData, level);
});
}
else {
FastImportData(smallData, level);
}
}
function FastImportData(data, level) {
RemoveAllEdges();
RemoveAllNodes();
FastAddUpToLevel(level, totalNumberOfLevels, data);
redrawSameScene();
}
function FindTotalNumberOfLevels(data) {
var levels = 0;
for (var key in data) {
var path = data[key].Path;
levels = path.length + 1;
return levels;
}
return levels;
}
function FastAddUpToLevel(sliderlevel, total, data) {
if (sliderlevel < total) {
FastLoadLevelZero(data, sliderlevel);
for (var level = 1; level <= sliderlevel; level++) {
for (var key in data) {
var system = data[key];
var path = system.Path;
if (level < total - 1) {
if (path[level] == key) {
FastAddNode(path, level, data, key);
var node = graph.getNode(key);
if (level == sliderlevel) {
CheckIfNodeIsExpandable(key, CurrentDir[key]);
}
}
}
else {
FastAddNode(path, level, data, key);
var node = graph.getNode(key);
node._expandable = false;
}
}
}
}
}
function FastAddNode(path, level, data, key) {
var systemId = key;
var parent = path[level - 1];
var colorPoint = PrepareColor(level, parent);
PrepareNodeAndAddIt(data, key, colorPoint);
if (level > 0 && parent != systemId) {
AddNewEdge(parent, systemId, colorPoint);
}
var node = graph.getNode(systemId);
var currentDir = dataFolder;
for (var i = 0; i < level; i++) {
currentDir = currentDir + "/" + parseInt(path[i]);
}
CurrentDir[systemId] = currentDir;
CurrentLevel[systemId]++;
}
function FastLoadLevelZero(data, sliderlevel) {
var level = 0;
for (var key in data) {
var point = data[key];
CurrentLevel[key] = undefined;
CurrentDir[key] = undefined;
var path = point.Path;
if (graph._nodeIds[key] == undefined) {
if (path[level] == key) {
AddNodeAtLevelZero(data, key);
graph.getNode(key)._expandable = false;
if (sliderlevel == 0) {
CheckIfNodeIsExpandable(key, dataFolder);
}
}
}
}
}
function AddNodeAtLevelZero(data, key) {
var point = data[key];
var coords = point.Coordinates;
var colorNode = PrepareColorZero(coords);
PrepareNodeAndAddIt(data, key, colorNode);
var node = graph.getNode(key);
CurrentDir[key] = dataFolder;
CurrentLevel[key] = 0;
}
function AddNewEdge(parentId, pointId, colorPoint) {
var y = parentId;
var newedge = G.edge([y, pointId], {
color: colorPoint,
});
newedge.addTo(graph);
edges.push(newedge);
}
function RemoveAllEdges() {
edges.splice(0, edges.length);
}
function RemoveAllNodes() {
var numberOfNodes = graph.getNodes().length;
for (var i = 0; i < numberOfNodes; i++) {
graph.removeLastNode();
}
}
function RemoveLastNodes() {//when the user has asked to close an open node
var numberOfNodes = graph.getNodes().length;
for (var i = 0; i < numberOfNodes - previousNumberOfNodes[clicked]; i++) {
graph.removeLastNode();
}
}
function RemoveLastEdges() {//when the user has asked to close an open node
edges.splice(previousNumberOfEdges[clicked], edges.length - previousNumberOfEdges[clicked]);
}
function HideAllEdges() {//when the checkbox for show edges is unchecked
var numberOfEdges = graph._edges.length;
graph._edges.splice(0, numberOfEdges);
}
function ShowAllEdges() {// when the checkbox for show edges is checked. edges is a backup of the current edges in the graph, regardless of whether they are shown or not
graph._edges = edges.slice();
}
function Colorize(col, indexOfProperty)//colorizes the nodes that are already loaded in the graph. Means if you color while still loading data, the new data will not be colored
{
// init max and min value of property accross nodes
var max = graph._nodes[0]._propertiesValues[indexOfProperty];
var min = max;
for (var i = 0; i < graph._nodes.length; i++) {
var value = graph._nodes[i]._propertiesValues[indexOfProperty];
if (value > max) { max = value; }
if (value < min) { min = value; }
}
var range = max - min;
//find the max intensity for red or blue or green
var maxColor = col[1][0];
if (col[1][1] > maxColor) { maxColor = col[1][1]; }
if (col[1][2] > maxColor) { maxColor = col[1][2]; }
//adjust the RGB components
var redNew = col[1][0];
var greenNew = col[1][1];
if (maxColor > 0) {
var factor = 255 / maxColor;
redNew = factor * col[1][0];
greenNew = factor * col[1][1];
blueNew = factor * col[1][2];
}
//colorize the nodes with different shades of the color, according to the selecgted property intensity
for (var i = 0; i < graph._nodes.length; i++) {
var node = graph._nodes[i];
var value = node._propertiesValues[indexOfProperty];
var red = col[1][0];
var green = col[1][1];
var blue = col[1][2];
if (range > 0) {
red = Math.floor(redNew * (value - min) / range);
green = Math.floor(greenNew * (value - min) / range);
blue = Math.floor(blueNew * (value - min) / range);
}
var color = "rgb(" + red + "," + green + "," + blue + ")";
ChangeColor(node, color);
}
redrawSameScene();
}
function SearchAndColorizeByName(name)//searches the nodes that are already loaded in the graph. Means if you color while still loading data, the new data will not be colored
{
var count = 0;
var singleNode;
var nodes = graph.getNodes();
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var found = false;
var nodeId = node.getId();
nodeId = nodeId.toLowerCase();
name = name.toLowerCase();
if (nodeId.search(name) > -1) {
found = true;
}
else {
var categories = node._categoriesValues;
for (var j = 0; j < categories.length; j++) {
var prop = categories[j].toLowerCase();
if (prop.search(name) > -1) { found = true; }
}
}
if (found) {
ChangeColor(node, "red");
singleNode = node;
count++;
}
else { ChangeColor(node, "grey"); }
}
redrawSameScene();
alert("Number of data points matching search criteria: " + count); //AK 02/06/2016
}
function redrawSameScene() {
if (edgesShow.checked) {
ShowAllEdges();
}
else {
HideAllEdges();
}
renderFrame.reDrawMeInSameScene();
}
function redrawInitialScene() {
if (edgesShow.checked) {
ShowAllEdges();
}
else {
HideAllEdges();
}
renderFrame.reDrawMe();
}
function ChangeColor(node, color) {
var id = node.getId();
previousColor[id] = node.getColor();
node.setColor(color);
}
function ReturnPreviousColor(node) {
var id = node.getId();
var color = previousColor[id];
if (color != undefined) {
node.setColorHex("#" + color);
}
}
function ReturnAllColors() {
var nodes = graph.getNodes();
for (var i = 0; i < nodes.length; i++) {
ReturnPreviousColor(nodes[i]);
}
redrawSameScene();
}
function ShowExpandableNodes() {
var nodes = graph.getNodes();
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node._expandable) {
ChangeColor(node, "yellow");
}
else { ChangeColor(node, "grey") };
}
redrawSameScene();
}
//################## the functions definitions end here
</script>
</body>
</html>