mirror of https://github.com/CIRCL/lookyloo
chg: Add square around nodes data
parent
296432a096
commit
bf506b3f87
|
@ -239,11 +239,11 @@ function hostnode_click(d) {
|
||||||
|
|
||||||
function icon(key, icon_path, d){
|
function icon(key, icon_path, d){
|
||||||
var iconContent = d3.create("svg") // WARNING: svg is required there, "g" doesn't have getBBox
|
var iconContent = d3.create("svg") // WARNING: svg is required there, "g" doesn't have getBBox
|
||||||
.attr('class', 'icon');
|
.attr('class', 'icon');
|
||||||
var icon_size = 16;
|
var icon_size = 16;
|
||||||
var has_icon = false;
|
var has_icon = false;
|
||||||
|
|
||||||
iconContent.datum(d);
|
iconContent.datum(d);
|
||||||
iconContent.filter(d => {
|
iconContent.filter(d => {
|
||||||
if (typeof d.data[key] === 'boolean') {
|
if (typeof d.data[key] === 'boolean') {
|
||||||
has_icon = d.data[key];
|
has_icon = d.data[key];
|
||||||
|
@ -277,10 +277,10 @@ function icon(key, icon_path, d){
|
||||||
.attr('x', icon_size + 1)
|
.attr('x', icon_size + 1)
|
||||||
.attr('width', d => d.to_print.toString().length + 'em')
|
.attr('width', d => d.to_print.toString().length + 'em')
|
||||||
.text(d => d.to_print);
|
.text(d => d.to_print);
|
||||||
if (has_icon) {
|
if (has_icon) {
|
||||||
return iconContent.node();
|
return iconContent.node();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
function icon_list(relative_x_pos, relative_y_pos, d) {
|
function icon_list(relative_x_pos, relative_y_pos, d) {
|
||||||
|
@ -288,36 +288,36 @@ function icon_list(relative_x_pos, relative_y_pos, d) {
|
||||||
var icons = d3.create("svg") // WARNING: svg is required there, "g" doesn't have getBBox
|
var icons = d3.create("svg") // WARNING: svg is required there, "g" doesn't have getBBox
|
||||||
.attr('x', relative_x_pos)
|
.attr('x', relative_x_pos)
|
||||||
.attr('y', relative_y_pos)
|
.attr('y', relative_y_pos)
|
||||||
.datum(d);
|
.datum(d);
|
||||||
icon_options = [
|
icon_options = [
|
||||||
['js', "/static/javascript.png"],
|
['js', "/static/javascript.png"],
|
||||||
['exe', "/static/exe.png"],
|
['exe', "/static/exe.png"],
|
||||||
['css', "/static/css.png"],
|
['css', "/static/css.png"],
|
||||||
['font', "/static/font.png"],
|
['font', "/static/font.png"],
|
||||||
['html', "/static/html.png"],
|
['html', "/static/html.png"],
|
||||||
['json', "/static/json.png"],
|
['json', "/static/json.png"],
|
||||||
['iframe', "/static/ifr.png"],
|
['iframe', "/static/ifr.png"],
|
||||||
['image', "/static/img.png"],
|
['image', "/static/img.png"],
|
||||||
['unknown_mimetype', "/static/wtf.png"],
|
['unknown_mimetype', "/static/wtf.png"],
|
||||||
['video', "/static/video.png"],
|
['video', "/static/video.png"],
|
||||||
['request_cookie', "/static/cookie_read.png"],
|
['request_cookie', "/static/cookie_read.png"],
|
||||||
['response_cookie', "/static/cookie_received.png"],
|
['response_cookie', "/static/cookie_received.png"],
|
||||||
['redirect', "/static/redirect.png"],
|
['redirect', "/static/redirect.png"],
|
||||||
['redirect_to_nothing', "/static/cookie_in_url.png"]
|
['redirect_to_nothing', "/static/cookie_in_url.png"]
|
||||||
];
|
];
|
||||||
|
|
||||||
nb_icons = 0
|
nb_icons = 0
|
||||||
icon_options.forEach(entry => {
|
icon_options.forEach(entry => {
|
||||||
bloc = icon(entry[0], entry[1], d);
|
bloc = icon(entry[0], entry[1], d);
|
||||||
if (bloc){
|
if (bloc){
|
||||||
icons
|
icons
|
||||||
.append(() => bloc)
|
.append(() => bloc)
|
||||||
.attr('x', 25 * nb_icons); // FIXME: make that distance a variable
|
.attr('x', 25 * nb_icons); // FIXME: make that distance a variable
|
||||||
nb_icons += 1;
|
nb_icons += 1;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
// FIXME: that need to move somewhere else, doesn't make sense here.
|
// FIXME: that need to move somewhere else, doesn't make sense here.
|
||||||
icons.filter(function(d){
|
icons.filter(function(d){
|
||||||
if (d.data.sane_js_details) {
|
if (d.data.sane_js_details) {
|
||||||
d.libinfo = d.data.sane_js_details[0];
|
d.libinfo = d.data.sane_js_details[0];
|
||||||
|
@ -339,7 +339,7 @@ function text_entry(relative_x_pos, relative_y_pos, onclick_callback, d) {
|
||||||
.attr('height', node_height)
|
.attr('height', node_height)
|
||||||
.attr('x', relative_x_pos)
|
.attr('x', relative_x_pos)
|
||||||
.attr('y', relative_y_pos)
|
.attr('y', relative_y_pos)
|
||||||
.datum(d);
|
.datum(d);
|
||||||
|
|
||||||
// Add labels for the nodes
|
// Add labels for the nodes
|
||||||
var text_nodes = nodeContent.append("text")
|
var text_nodes = nodeContent.append("text")
|
||||||
|
@ -350,8 +350,8 @@ function text_entry(relative_x_pos, relative_y_pos, onclick_callback, d) {
|
||||||
.style("opacity", .9)
|
.style("opacity", .9)
|
||||||
.attr('cursor', 'pointer')
|
.attr('cursor', 'pointer')
|
||||||
.attr("clip-path", "url(#textOverlay)")
|
.attr("clip-path", "url(#textOverlay)")
|
||||||
.text(d.data.name + ' (' + d.data.urls_count + ')')
|
.text(d.data.name + ' (' + d.data.urls_count + ')');
|
||||||
.on('click',onclick_callback);
|
// .on('click',onclick_callback);
|
||||||
return nodeContent.node();
|
return nodeContent.node();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,20 +377,20 @@ function update(root, computed_node_width=0) {
|
||||||
// Set background based on the computed width and height
|
// Set background based on the computed width and height
|
||||||
var background = main_svg.insert('rect', ':first-child')
|
var background = main_svg.insert('rect', ':first-child')
|
||||||
.attr('y', 0)
|
.attr('y', 0)
|
||||||
// FIXME: + 200 doesn't make much sense...
|
// FIXME: + 200 doesn't make much sense...
|
||||||
.attr('width', newWidth + margin.right + margin.left + 200)
|
.attr('width', newWidth + margin.right + margin.left + 200)
|
||||||
.attr('height', newHeight + margin.top + margin.bottom)
|
.attr('height', newHeight + margin.top + margin.bottom)
|
||||||
.style('fill', "url(#backstripes)");
|
.style('fill', "url(#backstripes)");
|
||||||
|
|
||||||
// Update size
|
// Update size
|
||||||
d3.select("body svg")
|
d3.select("body svg")
|
||||||
// FIXME: + 200 doesn't make much sense...
|
// FIXME: + 200 doesn't make much sense...
|
||||||
.attr("width", newWidth + margin.right + margin.left + 200)
|
.attr("width", newWidth + margin.right + margin.left + 200)
|
||||||
.attr("height", newHeight + margin.top + margin.bottom)
|
.attr("height", newHeight + margin.top + margin.bottom)
|
||||||
|
|
||||||
// Update pattern
|
// Update pattern
|
||||||
main_svg.selectAll('pattern')
|
main_svg.selectAll('pattern')
|
||||||
.attr('width', computed_node_width * 2)
|
.attr('width', computed_node_width * 2)
|
||||||
pattern.selectAll('rect')
|
pattern.selectAll('rect')
|
||||||
.attr('width', computed_node_width)
|
.attr('width', computed_node_width)
|
||||||
|
|
||||||
|
@ -412,35 +412,57 @@ function update(root, computed_node_width=0) {
|
||||||
tree_nodes.join(
|
tree_nodes.join(
|
||||||
// Enter any new modes at the parent's previous position.
|
// Enter any new modes at the parent's previous position.
|
||||||
enter => {
|
enter => {
|
||||||
var node_group = enter.append('g');
|
var node_group = enter.append('g')
|
||||||
node_group
|
|
||||||
.attr('class', 'node')
|
.attr('class', 'node')
|
||||||
.attr("id", d => 'node_' + d.data.uuid)
|
.attr("id", d => 'node_' + d.data.uuid)
|
||||||
.attr("transform", "translate(" + root.y0 + "," + root.x0 + ")")
|
.attr("transform", "translate(" + root.y0 + "," + root.x0 + ")")
|
||||||
|
|
||||||
|
node_group
|
||||||
// Add Circle for the nodes
|
// Add Circle for the nodes
|
||||||
.append('circle')
|
.append('circle')
|
||||||
.attr('class', 'node')
|
.attr('class', 'node')
|
||||||
.attr('r', 1e-6)
|
.attr('r', 1e-6)
|
||||||
.style("fill", d => d._children ? "lightsteelblue" : "#fff")
|
.style("fill", d => d._children ? "lightsteelblue" : "#fff")
|
||||||
.on('click', click);
|
.on('click', click);
|
||||||
// Rectangle around the domain name & icons
|
|
||||||
//.append('rect')
|
var node_data = node_group
|
||||||
//.attr("rx", 6)
|
.append('svg')
|
||||||
//.attr("ry", 6)
|
.attr('class', 'node_data')
|
||||||
//.attr('x', 13)
|
.attr('x', 12)
|
||||||
//.attr('y', -23)
|
.attr('y', -30);
|
||||||
//.style("opacity", "0.5")
|
|
||||||
//.attr("stroke", "black")
|
node_data.append('rect')
|
||||||
//.attr('stroke-opacity', "0.8")
|
.attr("rx", 6)
|
||||||
//.attr("stroke-width", "1.5")
|
.attr("ry", 6)
|
||||||
//.attr("stroke-linecap", "round")
|
.attr('x', 0)
|
||||||
//.attr("fill", "white")
|
.attr('y', 0)
|
||||||
|
.style("opacity", "0.5")
|
||||||
|
.attr("stroke", "black")
|
||||||
|
.attr('stroke-opacity', "0.8")
|
||||||
|
.attr("stroke-width", "2")
|
||||||
|
.attr("stroke-linecap", "round")
|
||||||
|
.attr("fill", "white");
|
||||||
|
|
||||||
// Set Hostname text
|
// Set Hostname text
|
||||||
node_group
|
node_data
|
||||||
.append(d => text_entry(15, -20, hostnode_click, d));
|
.append(d => text_entry(2, 5, hostnode_click, d));
|
||||||
// Set list of icons
|
// Set list of icons
|
||||||
node_group
|
node_data
|
||||||
.append(d => icon_list(17, 10, d));
|
.append(d => icon_list(4, 35, d));
|
||||||
|
|
||||||
|
|
||||||
|
node_group.select('.node_data').each(function(p, j){
|
||||||
|
selected_node_bbox = d3.select(this).node().getBBox();
|
||||||
|
// Set the width for all the nodes
|
||||||
|
node_width = node_width > selected_node_bbox.width ? node_width : selected_node_bbox.width;
|
||||||
|
|
||||||
|
d3.select(this).select('rect')
|
||||||
|
// Rectangle around the domain name & icons
|
||||||
|
.attr('height', selected_node_bbox.height + 15)
|
||||||
|
.attr('width', selected_node_bbox.width + 20);
|
||||||
|
});
|
||||||
|
// FIXME: should get the bbox of the whole node group
|
||||||
|
node_width += 50;
|
||||||
|
|
||||||
return node_group;
|
return node_group;
|
||||||
},
|
},
|
||||||
|
@ -448,7 +470,7 @@ function update(root, computed_node_width=0) {
|
||||||
exit => exit
|
exit => exit
|
||||||
// Remove any exiting nodes
|
// Remove any exiting nodes
|
||||||
.call(exit => exit
|
.call(exit => exit
|
||||||
.transition(t)
|
.transition(t)
|
||||||
.attr("transform", "translate(" + root.y0 + "," + root.x0 + ")")
|
.attr("transform", "translate(" + root.y0 + "," + root.x0 + ")")
|
||||||
.remove()
|
.remove()
|
||||||
)
|
)
|
||||||
|
@ -464,12 +486,7 @@ function update(root, computed_node_width=0) {
|
||||||
.attr('r', 10)
|
.attr('r', 10)
|
||||||
.style("fill", node => node._children ? "lightsteelblue" : "#fff")
|
.style("fill", node => node._children ? "lightsteelblue" : "#fff")
|
||||||
.attr('cursor', 'pointer');
|
.attr('cursor', 'pointer');
|
||||||
node.selectAll('text').nodes().forEach(n => {
|
|
||||||
// Set the width for all the nodes
|
|
||||||
node_width = node_width > n.getBBox().width ? node_width : n.getBBox().width;
|
|
||||||
});
|
|
||||||
// FIXME: should get the bbox of the whole node group
|
|
||||||
node_width += 30;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
nodes.forEach(d => {
|
nodes.forEach(d => {
|
||||||
|
@ -531,7 +548,7 @@ function update(root, computed_node_width=0) {
|
||||||
d.children = d._children;
|
d.children = d._children;
|
||||||
d._children = null;
|
d._children = null;
|
||||||
}
|
}
|
||||||
// Call update on the whole Tree
|
// Call update on the whole Tree
|
||||||
update(d.ancestors().reverse()[0]);
|
update(d.ancestors().reverse()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue