chg: moar cleanup

pull/81/head
Raphaël Vinot 2020-08-12 20:09:40 +02:00
parent 022d7a8612
commit 5e6e784ee5
1 changed files with 34 additions and 43 deletions

View File

@ -218,50 +218,41 @@ function icon_list(relative_x_pos, relative_y_pos, d) {
// Put all the icone in one sub svg document // Put all the icone in one sub svg document
let icons = d3.create("svg") let icons = d3.create("svg")
.attr('x', relative_x_pos) .attr('x', relative_x_pos)
.attr('y', relative_y_pos); .attr('y', relative_y_pos)
.attr('class', 'icons_list');
icon_options.forEach(function(icon_path, key) { icon_options.forEach(function(icon_path, key) {
icons let has_icon = false;
.datum(d) let counter = 0;
.filter(d => { if (typeof d.data[key] === 'boolean') {
let has_icon = false; has_icon = d.data[key];
if (typeof d.data[key] === 'boolean') { } else if (typeof d.data[key] === 'number') {
has_icon = d.data[key]; has_icon = d.data[key] > 0;
} else if (typeof d.data[key] === 'number') { counter = d.data[key]
has_icon = d.data[key] > 0; } else if (d.data[key] instanceof Array) {
} else if (d.data[key] instanceof Array) { has_icon = d.data[key].length > 0;
has_icon = d.data[key].length > 0; counter = d.data[key].length
} };
return has_icon; if (has_icon) {
}) let icon_group = icons
.append("svg") .append("svg")
.attr('class', 'icon') .attr('class', 'icon')
.attr('id', key) .attr("id", `icons_${key}`);
.append('image') icon_group
.attr("width", icon_size) .append('image')
.attr("height", icon_size) .attr("width", icon_size)
.attr("xlink:href", icon_path); .attr("height", icon_size)
}); .attr("xlink:href", icon_path);
if (counter > 0) {
icons.selectAll('.icon') icon_group
.datum(d) .append('text')
.filter(function(d) { .attr("dy", 8)
if (typeof d.data[this.id] === 'boolean') { .style("font-size", "10px")
return false; .attr('x', icon_size + 1)
} else if (typeof d.data[this.id] === 'number') { .text(counter);
d.to_print = d.data[this.id] };
return d.data[this.id] > 0; };
} else if (d.data[this.id] instanceof Array) { })
d.to_print = d.data[this.id].length
return d.data[this.id].length > 0;
}
return false;
}).append('text')
.attr("dy", 8)
.style("font-size", "10px")
.attr('x', icon_size + 1)
.text(d => d.to_print);
return icons.node(); return icons.node();
} }
@ -485,7 +476,7 @@ function update(root, computed_node_width=0) {
return node_group; return node_group;
}, },
update => update, update => update,
exit => exit exit => exit
.transition() .transition()
// Remove any exiting nodes // Remove any exiting nodes