Published
Edited
Sep 24, 2020
1 star
Insert cell
Insert cell
Insert cell
fig={
const svg = d3.select(document.getElementById("simpleTree"))
// doing this because observable tries to rerender and we don't want to overplot
svg.selectAll("g").remove();
svg.selectAll("rect").remove();
svg
.append("rect")
.attr("id","reset-catcher")
.attr("width",width)
.attr("height",400)



const fig = new ft.FigTree(document.getElementById("simpleTree"),margins, tree)
const figureGroup = d3.select(`.${fig.id}`)


fig.layout(ft.rectangularZoomedLayout(tree.rootNode))
.nodes(ft.roughCircle()
.radius(20)
.fillAttr("stroke","steelblue")
.fillAttr("stroke-width",2)
.strokeAttr("stroke-width",2)
.strokeAttr("stroke","grey")
)
.branches(ft.roughBranch()
.attr("stroke-width",2)
.attr("stroke","grey")
.attr("cursor","pointer")
.on("click",(edge,n,i)=>{
fig.layout(ft.rectangularZoomedLayout(tree.getNode(edge.v1.id)))
}))

svg
.select("#reset-catcher")
.on("click",()=>{
console.log("click")
fig.layout(ft.rectangularZoomedLayout(tree.rootNode))
})

return fig;
}
Insert cell
Insert cell
html `<svg width=${width} height="400" id="simpleTree2"/>`
Insert cell
fig2={
const svg = d3.select(document.getElementById("simpleTree2"))
// doing this because observable tries to rerender and we don't want to overplot
svg.selectAll("g").remove();

const fig = new ft.FigTree(document.getElementById("simpleTree2"),margins, tree)
fig.layout(ft.rectangularZoomedLayout(tree.rootNode))
.nodes(ft.roughCircle()
.radius(20)
.fillAttr("stroke","steelblue")
.fillAttr("stroke-width",2)
.strokeAttr("stroke-width",2)
.strokeAttr("stroke","grey")
)
.branches(ft.roughBranch()
.attr("stroke-width",2)
.attr("stroke","grey")
)
const figGroup =svg.select(`#${fig.id}`)
// console.log(figGroup)
// const zoom = d3.zoom()
// .scaleExtent([1, 5])
// .on("zoom", () => svg.attr("transform", d3.event.transform));
// svg.call(zoom).call(zoom.transform, d3.zoomIdentity);
function zoomed({transform}) {
svg.attr("transform", transform);
}
svg.call(d3.zoom()
.scaleExtent([1, 8])
.on("zoom", zoomed));


return fig
}
Insert cell
Insert cell
Insert cell
tree.orderByNodeDensity(false)
Insert cell
ft=import("https://cdn.jsdelivr.net/gh/rambaut/figtree.js@8f3ad96/dist/figtree.esm.js")
Insert cell
d3 = require("d3@6")
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more