Skip to content

Commit aa24c8d

Browse files
committed
Trying to convert previous code to d3. Should be doable.
1 parent 9f417d2 commit aa24c8d

File tree

6 files changed

+866
-176
lines changed

6 files changed

+866
-176
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ __pycache__/
99
*.sublime-workspace
1010

1111
.vagrant/
12-
tmp/**/*
12+
tmp/
1313
node_modules/
1414
suricata/

js/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define(['config'], function () {
2020
count_by_file: {
2121
terms: {
2222
field: "file",
23-
size : 20
23+
size : 50
2424
}
2525
}
2626
}

js/menu.js

+45-37
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,53 @@
1-
define(['elasticsearch', 'config'], function (elasticsearch, config){
2-
var d3_button_binding = "context-button";
3-
var menu = document.createElement("NAV");
4-
var lv1 = document.createElement("UL");
5-
var lv1_list = document.createElement("LI");
6-
var lv1_link = document.createElement("A");
7-
lv1_link.className = d3_button_binding;
8-
lv1_link.href = "#"
1+
define(['d3', 'elasticsearch', 'config'], function (d3, elasticsearch, config){
92

10-
lv1_link.appendChild(document.createTextNode(config.ruleset_index));
11-
lv1_list.appendChild(lv1_link);
123
var client = new elasticsearch.Client(config.serverOptions);
13-
client.search(config.getTypesInRulesetIndex).then(function (response){
14-
var types = response.aggregations.count_by_type.buckets;
15-
var lv2 = document.createElement("UL");
16-
types.forEach(function(d){
17-
var lv2_list = document.createElement("LI");
18-
var lv2_link = document.createElement("A");
19-
lv2_link.href = "#";
20-
lv2_link.appendChild(document.createTextNode(d.key));
21-
lv2_link.className = d3_button_binding;
22-
lv2_list.appendChild(lv2_link);
23-
lv2.appendChild(lv2_list);
244

25-
var files = d.count_by_file.buckets;
26-
var lv3 = document.createElement("UL");
27-
files.forEach(function(d){
28-
var lv3_list = document.createElement("LI");
29-
var lv3_link = document.createElement("A");
30-
lv3_link.href = "#";
31-
lv3_link.appendChild(document.createTextNode(d.key));
32-
lv3_list.appendChild(lv3_link);
33-
lv3.appendChild(lv3_list);
34-
});
35-
lv2_list.appendChild(lv3);
36-
});
5+
var menu = d3.select("#menu");
376

38-
lv1_list.appendChild(lv2);
7+
client.search(config.getTypesInRulesetIndex).then(function(response){
8+
var data = response.aggregations['count_by_type'].buckets;
9+
//console.log(data);
10+
menu.selectAll("li")
11+
.data(data)
12+
.enter().append("li")
13+
.text(function(d) { return d['key']; })
14+
.on("click", expand);
15+
function expand(d) {
16+
console.log(d);
17+
d3.select(this)
18+
.on("click", null)
19+
.append("ul")
20+
.selectAll("li")
21+
.data(d['count_by_file'].buckets)
22+
.enter().append("li")
23+
.text(function(d) { console.log(d); return d['key']; });
24+
}
3925
});
4026

41-
lv1.appendChild(lv1_list);
42-
menu.appendChild(lv1);
43-
document.getElementById("menu").appendChild(menu);
27+
28+
// client.search(config.getTypesInRulesetIndex).then(function (response){
29+
// var menu = d3.select("#menu")
30+
// .append("nav")
31+
// .append("ul")
32+
// .append("li")
33+
// .attr("id", function(d){
34+
// return config.ruleset_index;
35+
// })
36+
// .append("a")
37+
// .text(config.ruleset_index)
38+
// .on("click", expand);
39+
//
40+
// });
41+
// function expand(d) {
42+
// d3.select(this)
43+
// .on("click", null)
44+
// .append("ul")
45+
// .selectAll("li")
46+
// .data(d.aggregations.count_by_type.buckets)
47+
// .enter()
48+
// .append("li")
49+
// .text(function(d) {return d.key;});
50+
// }
51+
4452

4553
});

0 commit comments

Comments
 (0)