Public
Edited
Apr 19, 2022
4 forks
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
alluvial = FileAttachment("alluvial.svg").image()
Insert cell
Insert cell
alluvialSVG = FileAttachment("alluvial.svg").text()
Insert cell
graphic1 = importSVGnode(alluvialSVG)
Insert cell
Insert cell
function importSVGnode (svgText) {
const document = (new DOMParser).parseFromString(svgText, "image/svg+xml");
const svg = d3.select(document.documentElement).remove();
return svg.node();
}
Insert cell
Insert cell
myViz = d3.select(graphic1)
Insert cell
myViz.selectAll("tspan").style("fill","white")
Insert cell
Insert cell
myViz.selectAll("path").on("mouseover",highlight).on("mouseout",showAll)
Insert cell
highlight = (evt) => {
dimAll();
let elem = d3.select(evt.currentTarget);
elem.style("opacity","")
}
Insert cell
dimAll = () => {
myViz.selectAll("path").style("opacity",0.1)
}
Insert cell
showAll = () => {
myViz.selectAll("path").style("opacity","")
}
Insert cell
Insert cell
buttons = {
d3.select(graphic1.parentNode).append("button")
.style("position","absolute")
.style("top","300px")
.style("right","200px")
.text("Gas")
.on("click", () => {showPathsByColor("#7f7f7f")});
d3.select(graphic1.parentNode).append("button")
.style("position","absolute")
.style("top","280px")
.style("right","200px")
.text("Electricity Grid")
.on("click", () => {showPathsByColor("#e377c2")});
}
Insert cell
showPathsByColor = (color) => {
dimAll();
myViz.selectAll("path[stroke='" + color + "']").style("opacity","");
}
Insert cell
Insert cell
Insert cell
arcs = FileAttachment("arcs.svg").text()
Insert cell
graphic2 = importSVGnode(arcs)
Insert cell
myViz2 = d3.select(graphic2);
Insert cell
myViz2.selectAll("circle").style("fill","blue")
Insert cell
myViz2.selectAll("circle").on("click",subdue)
Insert cell
function subdue (evt) {
let elem = d3.select(evt.currentTarget);
elem.style("opacity", 0.1)
}
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