Published
Edited
Aug 2, 2020
Insert cell
Insert cell
Insert cell
voronoi = d3.Delaunay
.from(data, d => x(d.date), d => y(d.close))
.voronoi([0, 0, width, height])
Insert cell
Insert cell
class Tooltip {
constructor() {
this._date = svg`<text y="-22"></text>`;
this._close = svg`<text y="-12"></text>`;
this.node = svg`
<g pointer-events="none" display="none" font-family="sans-serif" font-size="10" text-anchor="middle">
<rect x="-27" width="54" y="-30" height="20" fill="white"></rect>
${this._date}
${this._close}
<circle r="2.5"></circle>
</g>`;
}
show(d) {
this.node.removeAttribute("display");
this.node.setAttribute("transform", `translate(${x(d.date)},${y(d.close)})`);
this._date.textContent = formatDate(d.date);
this._close.textContent = formatClose(d.close);
}
hide() {
this.node.setAttribute("display", "none");
}
}
Insert cell
Insert cell
Insert cell
viewof number = html`<input type="range" min="0" max="100" step="1">`
Insert cell
number
Insert cell
viewof name = html`<input type="text" placeholder="Type a name!">`
Insert cell
name
Insert cell
Insert cell
fruit
Insert cell
viewof hover = {
return Object.assign(html`<svg viewBox="0 0 ${width} ${height}">
<path d="${line(data)}" fill="none" stroke="steelblue" stroke-width="1.5" stroke-miterlimit="1"></path>
</svg>`, {
value: null,
onmousemove: event => {
event.currentTarget.value = bisect(data, x.invert(event.offsetX));
event.currentTarget.dispatchEvent(new CustomEvent("input"));
},
onmouseleave: event => {
event.currentTarget.value = null;
event.currentTarget.dispatchEvent(new CustomEvent("input"));
}
});
}
Insert cell
viewof i = Scrubber(d3.range(100), {
autoplay: false,
loop: false
})
Insert cell
i
Insert cell
Insert cell
formatDate = d3.utcFormat("%b %-d, ’%y")
Insert cell
formatClose = d3.format("$.2f")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.upper)])
.range([height - margin.bottom, margin.top])
Insert cell
x = d3.scaleUtc()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
Insert cell
data = d3.csvParse(await FileAttachment("aapl-bollinger.csv").text(), d3.autoType)
Insert cell
margin = ({top: 20, right: 30, bottom: 30, left: 40})
Insert cell
d3 = require("d3@5", "d3-delaunay@5")
Insert cell
import {Scrubber} from "@mbostock/scrubber"
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