rect_time_tree_chart_recomb = {
var root = tree_root
var filteredTips = removeRecombinationLeaves(root);
const svg = d3.create("svg")
.attr("viewBox", [-widthMargin, -10 , width + 2*widthMargin, height + heightMargin])
.attr("font-family", "sans-serif")
.attr("font-size", 10);
svg.append("g")
.attr('transform', `translate(50, ${height-200})`)
.call(legend);
var baseTipColor = "#36454f"
svg.append("style").text(`
.recombLink--active {
stroke: #36454f !important;
stroke-width: 5px;
stroke-opacity: 1.0;
}
.link--active {
stroke: #36454f !important;
stroke-width: 5px;
stroke-opacity: 1.0;
}
.tips--active {
fill: #36454f !important;
r: 8;
opacity: 1.0;
}
.label--active {
font-weight: bold !important;
opacity: 1.0;
}
`);
// #AAFF00
const link = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#696969")
.attr("stroke-width", "2px")
.selectAll("path")
//.data(root.edges) //if want to include all links in single object structurer
.data(root.links())
.join("path")
.each(function(d) { d.target.linkNode = this; }) //this is used for the highlighted path
.attr("d", linkVariableHorizontal);
// color settings for recomblinks
const colorRecombLinks = d3.scaleOrdinal(d3.schemeTableau10)
.domain(recombLinks.map(d => d.gene));
//could style recombination links separately. Add color by option here.
const recombLink = svg.append("g")
.attr("fill", "none")
.attr("stroke-width", "2px")
.selectAll("path")
.data(recombLinks)
.join("path")
.each(function(d) { d.target.recombLinkNode = this; }) //to include recombination events in highlighting
.style("stroke-dasharray", ("20, 5"))
.attr("d", linkVariableHorizontal)
.attr("stroke", d => colorRecombLinks(d.gene));
var x = d3.scaleTime()
.domain([new Date(1983, 5, 1), new Date(2019, 6, 1)])
.range([ 0, width ]);
var xAxis = svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom()
.scale(x)
// .tickSize(-height)
.ticks(d3.timeYear.every(10)));
xAxis.selectAll(".tick text")
.attr("font-size","30px");
const labels = svg.append("g")
.selectAll("text")
.data(filteredTips)
.join("text")
.attr("dy", ".31em")
.each(function(d) { d.label = this; })
.attr("transform", d => `translate(${d.radius + tipLabelPadding},${d.x})`) //time scaled tree
.attr("opacity", 0)
.attr("font-size","12px")
.text(d => `Strain Name: ${d.data.name.replace(/_/g, " ").split(' ', 1)}`)
.call(wrap, 10)
// tip shapes
const tips = svg.append("g")
.selectAll("circle").lower()
//.data(root.leaves())
.data(filteredTips)
.join("circle")
.attr("dy", ".31em")
.attr("fill", baseTipColor)
.attr("fill-opacity", 1)
.attr("transform", d => `translate(${d.radius},${d.x})`) //time scaled tree
.attr("r", 4.5);
// .on("mouseover", mouseovered(true))
// .on("mouseout", mouseovered(false));
tips
.on('mouseover', mouseovered(true))
.on('mouseout', mouseovered(false))
recombLink
.on("mouseover", function () {
d3.select(this)
.style("stroke-width", '5px')
.append('title')
.text(d => `estimated breakpoint: nuc ${d.breakpoint}`);
}).on("mouseout", function () {
d3.select(this).style("stroke-width", '2px');
});
// make lineage bold on mouseover
function mouseovered(active) {
return function(event, d) {
if (active) {
link.style('stroke', "#B8B8B8").style("opacity", 1.0)
recombLink.style('stroke', "#B8B8B8").style("opacity", 1.0)
//tips.style('fill', "#AAC5D5")
tips.style('fill', "#B8B8B8").style("opacity", 0.4).lower()
}
else {
link.style('stroke', "#708090").style("opacity", 1.0)
recombLink.style('stroke', d => colorRecombLinks(d.gene)).style("opacity", 1.0).style('stroke-width', '2px')
tips.style('fill', baseTipColor).style("opacity", 1)
}
d3.select(this).classed("tips--active", active).style("opacity", 1).raise();
d3.select(d.label).classed("label--active", active).raise();
if (active) {
d3.select(d.label).style('opacity', 1);
d3.select(d.label).classed("label--active", active).raise();
} else {
d3.select(d.label).style('opacity', 0)
}
do {
d3.select(d.linkNode).classed("link--active", active).raise();
//d3.select(d.recombLinkNode).classed("recombLink--active", active).raise();
if (active) {
d3.select(d.recombLinkNode).style('stroke', d => colorRecombLinks(d.gene)).style('stroke-width', '5px')
} else {
d3.select(d.recombLinkNode).style('stroke', d => colorRecombLinks(d.gene)).style('stroke-width', '2px')
}
if (d.recombParent) {
var p = d.recombParent;
do {
d3.select(p.linkNode).classed("recombLink--active", active).raise();
} while(p = p.parent);
}
}
while (d = d.parent); // follows child-parent path
};
}
return Object.assign(svg.node());
}