chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.attr("fill", "skyblue")
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => x(i))
.attr("y", d => y(d.p_value))
.attr("height", d => y(0) - y(d.p_value))
.attr("width", x.bandwidth())
.on("mouseover", function(event, d) {
console.log(d);
d3.select(this).style("fill", "steelblue");
tooltip.html(`<div class="chart-tooltip">
<div class="chart-tooltip-desc">
<span class="highlight-data">p-value: </span>
<span>${parseFloat(d.p_value).toFixed(20)}</span></div>
<span class="highlight-data">user geneset: </span>
<span>${d.user_geneset}</span>
</div>
</div>`);
tooltip.style("visibility", "visible");
})
.on("mousemove", function(){
return tooltip.style("top", (parseInt(this.getBoundingClientRect().y)-10)+"px").style("left",(parseInt(this.getBoundingClientRect().x)+10)+"px");
})
.on("mouseout", function(d) {
d3.select(this).style("fill", "skyblue");
tooltip.style("visibility", "hidden");
});
let tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.style("background", "#fff")
.text("an empty tooltip");
svg.append("g")
.attr("class", "bar-label-group")
.selectAll(".bar-label")
.data(data)
.join(
enter => {
enter
.append("text")
.attr("class", "bar-label")
.attr("x", (d, i) => x(i) + (x.bandwidth() / 2))
.attr("y", d => y(d.p_value) - 5)
.attr("width", x.bandwidth())
.attr('text-anchor','middle')
}
)
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
svg.append("path")
.attr("d", d3.line()([[0, height/2], [width, height/2]]))
.attr("stroke", "black")
.style("stroke-dasharray", ("3, 3"));
svg.append("text")
.text(`[PLACEHOLDER] threshold line
${parseFloat(data[0].p_value).toFixed(20)}%`) //MAKE THRESHOLD CHANGEABLE
.attr("y", height / 2 - 5)
.attr("x", width - 5)
.attr('text-anchor','end')
.attr('class','label');
let legendLabels = ["P-value between one of the user genesets to the reference genesets"];
let legend = svg.append('g')
.attr('class', 'legend');
legend.selectAll('rect')
.data(legendLabels)
.enter()
.append('rect')
.attr('x', 20)
.attr('y', 20)
.attr('width', 12)
.attr('height', 12)
.attr('fill', "skyblue");
legend.selectAll('text')
.data(legendLabels)
.enter()
.append('text')
.text("P-value between one of the user genesets to the reference genesets")
.attr('x', 40)
.attr('y', 20)
.attr('text-anchor', 'start')
.attr('alignment-baseline', 'hanging');
return svg.node();
}