-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.dendogram.html
159 lines (123 loc) · 4.02 KB
/
index.dendogram.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
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>CAPEC Visualization</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
.node circle {
fill: #999;
}
.node text {
font: 10px sans-serif;
}
.node--internal circle {
fill: #555;
}
.node--internal text {
text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}
.link {
fill: none;
stroke: #555;
stroke-opacity: 0.4;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<svg width="2200" height="6600"></svg>
<script>
/*
auth = btoa('username:password');
body = "{"statements":[{"statement": "MATCH p=((:Category)<-[:CHILD_OF]-(:AttackPattern)<-[:CHILD_OF*]-(:AttackPattern)) RETURN p", "resultDataContents":["graph"]}]}";
var request = $.ajax({
type: "POST",
url: "http://localhost:7474/db/data/transaction/commit",
accepts: { json: "application/json" },
dataType: "json",
contentType:"application/json",
authorization: auth,
data: JSON.stringify(body),
//now pass a callback to success to do something with the data
success: function (data) {
}
});*/
</script>
<script>
function formatJson(json) {
var node_map = {};
var data = json.results[0].data;
for (var idx_g = 0; idx_g < data.length; idx_g++) {
var nodes = data[idx_g].graph.nodes;
var rss = data[idx_g].graph.relationships;
for (var idx_n = 0; idx_n < nodes.length; idx_n++) {
var n = nodes[idx_n];
if (n.id in node_map == false)
node_map[n.id] = {
value: n.labels[0] + ' ' + n.properties.id,
rdn: n.properties.name,
parent: null
};
}
for (var idx_r = 0; idx_r < rss.length; idx_r++) {
var rs = rss[idx_r];
var sNode = node_map[rs.startNode];
var eNode = node_map[rs.endNode];
sNode.parent = eNode;
}
}
var node_list = []
var i = 0;
for (var key in node_map) {
node = node_map[key];
dn = node.rdn;
while (node.parent != null) {
node = node.parent;
dn = node.rdn + "#" + dn;
}
node_list.push({ id: "Capec#" + dn });
}
node_list.push({ id: "Capec" });
return node_list;
}
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height"),
g = svg.append("g").attr("transform", "translate(40,0)");
var cluster = d3.cluster()
.size([height, width - 600]);
var stratify = d3.stratify()
.parentId(function(d) { return d.id.substring(0, d.id.lastIndexOf("#")); });
d3.json("https://raw.githubusercontent.com/alexis-/Capec-Visualization/master/capec_v2.10.json", function(error, data) {
if (error) throw error;
data = formatJson(data);
var root = stratify(data)
.sort(function(a, b) { return (a.height - b.height) || a.id.localeCompare(b.id); });
cluster(root);
var link = g.selectAll(".link")
.data(root.descendants().slice(1))
.enter().append("path")
.attr("class", "link")
.attr("d", function(d) {
return "M" + d.y + "," + d.x
+ "C" + (d.parent.y + 100) + "," + d.x
+ " " + (d.parent.y + 100) + "," + d.parent.x
+ " " + d.parent.y + "," + d.parent.x;
});
var node = g.selectAll(".node")
.data(root.descendants())
.enter().append("g")
.attr("class", function(d) { return "node" + (d.children ? " node--internal" : " node--leaf"); })
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
node.append("circle")
.attr("r", 2.5);
node.append("text")
.attr("dy", 3)
.attr("x", function(d) { return d.children ? -8 : 8; })
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.text(function(d) { return d.id.substring(d.id.lastIndexOf("#") + 1); });
});
</script>
</body>
</html>