-
Notifications
You must be signed in to change notification settings - Fork 18
/
supergraph.js
171 lines (144 loc) · 4.17 KB
/
supergraph.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
function cleanFunc(func) {
let dllIndex = func.indexOf(".dll@");
if (dllIndex != -1) {
return func.substring(0, dllIndex + 4);
}
return func;
}
function generateGraph(signature) {
if (!signature) {
return;
}
let query;
if (signature.startsWith("https://crash-stats.mozilla.org/")) {
if (signature.startsWith("https://crash-stats.mozilla.org/search/")) {
signature =
"https://crash-stats.mozilla.org/api/SuperSearch/" +
signature.substring("https://crash-stats.mozilla.org/search/".length);
}
query = new URL(signature);
query.searchParams.set("_facets", "proto_signature");
query.searchParams.set("_facets_size", 50);
query.searchParams.set("_results_number", 0);
} else {
query = new URL(
"https://crash-stats.mozilla.org/api/SuperSearch/?signature=%3D" +
signature +
"&_results_number=0&_facets=proto_signature&_facets_size=50"
);
}
console.log(query.href);
fetch(query.href)
.then((response) => response.json())
.then((data) => {
let addedNodes = new Map();
let addedEdges = new Map();
for (let proto_signature of data["facets"]["proto_signature"]) {
let funcs = proto_signature["term"].split(" | ");
let stack_count = proto_signature["count"];
for (let i = funcs.length - 1; i > 0; i--) {
let func = cleanFunc(funcs[i]);
if (!addedNodes.has(func)) {
addedNodes.set(func, stack_count);
} else {
addedNodes.set(func, addedNodes.get(func) + stack_count);
}
if (i != 0) {
let edge = func + "|" + cleanFunc(funcs[i - 1]);
if (!addedEdges.has(edge)) {
addedEdges.set(edge, stack_count);
} else {
addedEdges.set(edge, addedEdges.get(edge) + stack_count);
}
}
}
}
let nodes = [];
for (let node of addedNodes) {
nodes.push({
id: node[0],
label: node[0],
value: node[1],
});
}
let edges = [];
for (let edge of addedEdges) {
let from_to = edge[0].split("|");
edges.push({
from: from_to[0],
to: from_to[1],
value: edge[1],
});
}
console.log(nodes.length);
console.log(edges.length);
var data = {
nodes: nodes,
edges: edges,
};
var opts = {
layout: {
hierarchical: {
direction: "UD",
sortMethod: "directed",
nodeSpacing: 1,
blockShifting: false,
},
},
edges: {
arrows: {
to: true,
},
},
nodes: {
shape: "box",
font: {
face: "monospace",
},
scaling: {
label: {
enabled: true,
min: 5,
max: 40,
maxVisible: 40,
},
},
},
};
let network = new vis.Network(
document.getElementById("graph"),
data,
opts
);
network.on("stabilizationIterationsDone", function () {
network.setOptions({
physics: false,
});
});
});
}
new Promise((resolve, reject) => (window.onload = resolve))
.then(function () {
let elem = document.getElementById("signature");
let queryVars = new URL(location.href).search.substring(1).split("&");
for (let queryVar of queryVars) {
if (queryVar.startsWith("s=")) {
elem.value = decodeURIComponent(queryVar.substring("s=".length));
break;
}
}
document.getElementById("signatureButton").onclick = function () {
let s = elem.value.trim();
let url = new URL(location.href);
url.searchParams.set("s", s);
history.replaceState({}, document.title, url.href);
generateGraph(s);
};
generateGraph(elem.value.trim());
})
.catch(function (err) {
console.error(err);
});