function renderFT(opts = {}) {
var data = opts.data,
node = opts.node,
height = d3.select(node).attr("height"),
width = d3.select(node).attr("width"),
margin = {
left: 7,
right: 1,
top: 1,
bottom: 2
},
x = d3
.scaleBand()
.domain(data.map(d => d.judge))
.range([margin.left, d3.select(node).attr("width") - margin.right])
.padding(0.1),
y = d3
.scaleLinear()
.domain([0, d3.max(data.map(d => d.value))])
.range([d3.select(node).attr("height") - margin.bottom, margin.top]);
var color = d3
.scaleOrdinal()
.domain(['FN', 'TN', 'FP', 'TP'])
.range(['red', 'grey', 'yellow', 'green']);
var svg = d3.select(node);
const g = svg.append('g');
g.append("g")
.append("rect")
.attr("x", margin.left)
.attr("y", margin.top)
.attr("width", width - margin.right - margin.left)
.attr("height", height - margin.bottom - margin.top)
.attr("fill", 'none')
.attr("stroke-width", 1)
.attr("stroke", "black");
let bar = g
.selectAll('.bar')
.data(data)
.enter()
.append('g')
.attr('class', 'bar-group');
bar
.append('rect')
.attr('class', '.bar')
.attr('x', d => x(d.judge))
.attr('y', d => y(d.value))
.attr('width', x.bandwidth())
.attr('height', d => height - margin.bottom - y(d.value))
.style('fill', d => color(d.judge));
bar
.append('text')
.text(d => d.judge)
.attr('x', d => x(d.judge) + x.bandwidth() / 2)
.attr('y', height - margin.bottom)
.attr('text-anchor', 'middle')
.style('font-family', 'sans-serif')
.style('font-size', 7)
.style('fill', 'black');
bar
.append('text')
.text('0')
.attr('x', margin.left * 0.8)
.attr('y', height - margin.bottom)
.attr('text-anchor', 'end')
.style('font-family', 'sans-serif')
.style('font-size', margin.left)
.style('fill', 'black');
bar
.append('text')
.text(d3.max(data.map(d => d.value)))
.attr('text-anchor', 'end')
.attr('dominant-baseline', d => {
if (d3.max(data.map(d => d.value)) >= 10) {
return 'auto';
} else {
return "hanging";
}
})
.attr("transform", d => {
if (d3.max(data.map(d => d.value)) >= 10) {
return `translate(${margin.left * 0.8},${margin.top})rotate(-90)`;
} else {
return `translate(${margin.left * 0.8},${margin.top})`;
}
})
.style('font-family', 'sans-serif')
.style('font-size', margin.left)
.style('fill', 'black');
}