Published
Edited
Mar 17, 2019
9 forks
33 stars
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(graphWidth, graphHeight));
svg.attr("id", "myGraph");
svg.append("circle")
.attr("id", "circle")
.attr("cx", graphWidth/2)
.attr("cy", graphHeight/2)
.attr("r", 40)
.attr("fill", "#69b3a2")
return svg.node();
}
Insert cell
tooltip = {
chart
const tooltip = d3.select("body").append("div")
.attr("class", "svg-tooltip")
.style("position", "absolute")
.style("visibility", "hidden")
.text("I'm a circle!");

d3.select("#circle")
.on("mouseover", function(){
return tooltip.style("visibility", "visible");
})
.on("mousemove", function(){
return tooltip.style("top", (d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px");
})
.on("mouseout", function(){
return tooltip.style("visibility", "hidden");
});
}
Insert cell
width
Insert cell
height = width * 0.4
Insert cell
margin = ({
top: 0,
bottom: 0,
left: 0,
right: 0
})
Insert cell
graphWidth = width - margin.left - margin.right
Insert cell
graphHeight = height - margin.top - margin.bottom
Insert cell
d3 = require("d3@5")
Insert cell
styles = html`
<style>

.svg-tooltip {
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
background: rgba(69,77,93,.9);
border-radius: .1rem;
color: #fff;
display: block;
font-size: 11px;
max-width: 320px;
padding: .2rem .4rem;
position: absolute;
text-overflow: ellipsis;
white-space: pre;
z-index: 300;
visibility: hidden;
}
</style>`
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