types_bar = {
var width = 400,
height = 250;
var dataset = types_entries;
var xScale = d3.scaleBand()
.domain(d3.range(dataset.length))
.rangeRound([0, width])
.padding(0.05);
var yScale = d3.scaleLinear()
.domain([0, d3.max(dataset.map(d => d[1].length))])
.range([0, height]);
const svg = d3.select(DOM.svg(width, height));
svg.selectAll("rect")
.data(dataset)
.enter().append("rect")
.attr("x", (d, i) => xScale(i))
.attr("y", d => height - yScale(d[1].length))
.attr("width", xScale.bandwidth())
.attr("height", d => yScale(d[1].length))
.attr("fill", "steelblue")
.on("mouseover", function (d) {
var xpos = parseFloat(d3.select(this).attr("x")) + xScale.bandwidth() / 2;
var ypos = parseFloat(d3.select(this).attr("y"));
var tgrp = svg.append("g")
.attr("id", "tooltip")
.attr("transform", (d, i) => `translate(${xpos},${ypos})`);
tgrp.append("rect")
.attr("width", "140px")
.attr("height", "22px")
.attr("fill", "rgba(240,240,240,0.8)")
tgrp.append("text")
.attr("x", 5)
.attr("y", 14)
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.text(d[0]);
})
.on("mouseout", (d) => {
d3.select("#tooltip").remove();
})
.on("click", function(d, i) {
var found = types_selection.indexOf(i);
if (found > -1) {
mutable types_selection.splice(found, 1);
mutable num_types_selected -= 1;
d3.select(this).attr("fill", "steelblue");
} else {
mutable types_selection.push(i);
mutable num_types_selected += 1;
d3.select(this).attr("fill", "#c51d1d");
}
});
return svg.node();
}