plot_1 = {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.attr("font-family", "sans-serif")
.attr("font-size", 10);
const group2 = svg.append('g');
group2
.selectAll("rect")
.data(series)
.join("g")
.attr("fill", d => color(d.key))
.selectAll("rect")
.data(d => d)
.join("rect")
.attr("x", d => xScale2(d[0]))
.attr("y", (d, i) => yScale2(d.data.Family))
.attr("width", d => xScale2(d[1]) - xScale2(d[0]))
.attr("height", yScale2.bandwidth())
.on('mouseover', function(d, i) {
tooltip
.html(
`<div style="font-family: sans-serif">Family: ${d.data.Family}</div>
<div style="font-family: sans-serif">Category: ${
d.key
} - ${Math.round(d[1] * 100 - d[0] * 100)}%</div>
<div style="font-family: sans-serif">#Species measured: ${
d.data.N
}</div>`
)
.style('visibility', 'visible');
d3.select(this)
.transition()
.attr('fill', hoverColor);
})
.on('mousemove', function() {
tooltip
.style('top', d3.event.pageY + 10 + 'px')
.style('left', d3.event.pageX + 10 + 'px');
})
.on('mouseout', function() {
tooltip.html(``).style('visibility', 'hidden');
d3.select(this)
.transition()
.attr('fill', d => color(d.key));
});
group2
.append("g")
.call(yAxis)
.selectAll('text')
.style("font-size", 12)
.style("cursor", "pointer")
.on(
"click",
d => window.open(`https://en.wikipedia.org/wiki/${d}`)
);
group2
.append("g")
.attr("transform", `translate(0, ${height})`)
.call(xAxis)
.append("text")
.attr("fill", "black")
.attr("font-family", "sans-serif")
.attr("x", width / 2)
.attr("y", 40)
.style("font-size", 15)
.text("Seed dispersal mode proportion");
const legend = svg
.append("g")
.attr("transform", `translate(${250}, ${0})`);
const size = 30;
const border_padding = 15;
const item_padding = 60;
const text_offset = 20;
legend
.selectAll("boxes")
.data(legend_)
.enter()
.append("rect")
.attr("y", border_padding)
.attr("x", (d, i) => border_padding + i * (size + item_padding))
.attr("width", size)
.attr("height", size)
.style("fill", d => colours(d));
legend
.selectAll("labels")
.data(legend_)
.enter()
.append("text")
.attr("y", border_padding + 16)
.attr(
"x",
(d, i) =>
border_padding + i * (size + item_padding) + size / 2 + text_offset
)
.text(d => d)
.attr("text-anchor", "left")
.style("alignment-baseline", "middle")
.style("font-family", "sans-serif")
.style("font-size", 15);
const orders = svg.append("g");
orders
.selectAll("orderLines")
.data(lineOrders)
.join("line")
.attr("x1", d => d.Dist)
.attr("y1", d => yScale2(d.O1))
.attr("x2", d => d.Dist)
.attr("y2", d => yScale2(d.O2) + yScale2.bandwidth())
.attr("stroke-width", 3)
.attr("stroke", "black");
orders
.selectAll("orderText")
.data(lineOrders)
.join("text")
.attr("x", d => d.Dist + 6)
.attr(
"y",
d =>
yScale2.bandwidth() +
yScale2(d.O1) +
(yScale2(d.O2) - yScale2(d.O1)) / 2
)
.text(d => d.Order)
.style("font-family", "sans-serif")
.style("font-size", 12);
return svg.node();
}