/
dt.js
48 lines (43 loc) · 1.05 KB
/
dt.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
var worker = new Worker("dt-worker.js");
worker.onmessage = function(event) {
var resultObj = JSON.parse(event.data);
//console.log(resultObj);
if(resultObj.do == undefined){
//console.log(resultObj);
}
else{
switch(resultObj.do){
case "debug":
//console.log(resultObj.data);
break;
case "tree":
$("#tree").html(draw(resultObj.data));
$("#tree").treeview();
//console.log(resultObj.data);
break;
case "stats":
$("#stats").append("<p>"+resultObj.data+"<\/p>");
break;
}
}
//console.log(event.data);
};
worker.onerror = function(error) {
//console.log(error.message);
};
function load_data(url,question){
$("#question").html('<p>'+question+'</p>');
$("#stats").empty();
$("#tree").html("Working... please wait");
$.get(url, function(data){
worker.postMessage(data);
});
}
function draw(data, root){
var result = "<ul>";
for(var i = 0;i<data.children.length;i++){
result += "<li><span>"+data.children[i].name+"<\/span>" + draw(data.children[i]) + "<\/li>";
}
result += "<\/ul>";
return result;
}