Published
Edited
Mar 11, 2021
8 stars
Food clockDisambiguating selection in a 2D treePerceptually more-uniform diverging color scatterplotDays since a U.S. President was last shotSingle-serving sitesDo you feel old?Dynamic scales deprive dashboards of institutional memoryNesting chevron pillsColumnar group byDe Moivre by generatorsShowing ESPN Receiver Tracking Metrics using weighted radar chartsCombine consecutive stringsDollar spectrumThe Feedback BathtubIs Visnu’s hex random?Dual axes are a great way to show correlation 🔥Promise.raceHealthcare plan payoff curvePlot image beeswarmGenerations on Google TrendsFor i of myriadChatterjee correlationChecking invariance of round trip-0 and 0Norms and central tendencyDisordering ULsData-driven table sort iconPlot: weather with sunrise and sunsetRecreating Östling’s regression visualizationsMixing knowledge and random guessesHow many five digit numbers are prime?Warping gridspaceSampling moodLow IDsTesting for OmicronAll Too WellDistance from square root to nearest factorSuper BogosortParrots of Telegraph HillNudibranch sightingsDecimal watershedsFirst Ladies of the United StatesEval-in-PlaceClassic Research in Data VisualizationResponsive PrettierObsv, obvsGenerating All Natural NumbersDaily Café PickerConcentration of MeasureDivide SeriesMultiply SeriesMultiplication and Division by Similar TrianglesRecursive typed table (sketch!)Lorenz CurveThe “Select cells” buttonRecursive viewof testBubble Map RaceSensitivity and Specificity (sketch)Reactive transition sketchHow to crash ObservableSpilhaus World TourSimpson’s paradox: CalendarsThe Cauchy DistributionEmoji frequenciesThe Man Comes AroundNot what I meant to doSVG numeral sketchesRSAMandelbrot’s binomial time bending??Re: “Can Moons Have Moons?”Continuous cursorParenthesis matching with vertical offsetsA filter icon that shows filtering instead of funnelingFlag of the Popular VoteFlag of the Popular VoteFlag of the Popular VoteTrailing zeroes in factorials
Bitcoin fractal bubbles (animated)
Bitcoin fractal bubbles
Insert cell
Insert cell
chart = {
const node = html`${style}<svg width="${width}" height="${height}">
${scaledPeaks.slice(0, 4).map(
d => svg`<g transform="translate(${x(d.summit.date)})">
<text y="1em">${formatDate(d.summit.date)}</text>
<text y="2em">${formatValue(d.summit.value)}</text>
</g>`
)}
<path d="${line(data)}"/>
<g id="peaks"/>
</svg>`;

const sel = d3.select(node).select("svg");

const p = sel
.select("g#peaks")
.selectAll("path")
.data(scaledPeaks)
.enter()
.append("path")
.attr("d", peak => line(peak.data))
.style("stroke", d => randColor());

async function drop() {
const t = p
.transition()
.duration(1000)
.delay((d, i) => 500 + i ** (1 / 3) * 500)
.attr(
"transform",
peak => `translate(${x(peak.summit.date)}, ${dx(peak.data.length)})`
)
.attr("d", peak =>
d3
.line()
.x(d => peak.x(d.date))
.y(d => peak.y(d.value))
.defined(d => d)(peak.data)
);
await t.end();
const tt = sel
.select("g#peaks")
.selectAll("path")
.transition()
.duration(1000)
.attr("transform", "translate(0,0)")
.attr("d", peak => line(peak.data));
await tt.end();
drop();
}

drop();

return node;
}
Insert cell
data = FileAttachment("btc-2021-03-09.csv").csv({typed: true})
Insert cell
peaks = getPeaks(data).filter(d => d.length > 3)
Insert cell
scaledPeaks = peaks.map(data => {
const radius = Math.floor(data.length / 2)
const summit = data[radius]
const scaledRadius = r(radius)
let x
if (data[0] === undefined) {
x = d3.scaleTime()
.domain([summit.date, data[data.length - 1].date])
.range([0, scaledRadius])
} else {
x = d3.scaleTime()
.domain([data[0].date, summit.date])
.range([-scaledRadius, 0])
}
const y = d3.scaleLinear()
.domain(d3.extent(data.filter(d => d).map(d => d.value)))
.range([scaledRadius * 0.4, -scaledRadius * 0.4])
return {data, radius, summit, x, y}
}).sort((a, b) => b.data.length - a.data.length)
Insert cell
getPeaks = data => {
const peaks = []
data.forEach((d, i, arr) => {
const peak = [d]
for (let radius = 1; radius < arr.length / 2; radius++) {
const next = arr[i + radius]
const prev = arr[i - radius]
const nextIsLower = !next || next.value < d.value
const prevIsLower = !prev || prev.value < d.value
if (nextIsLower && prevIsLower) {
peak.push(next)
peak.unshift(prev)
} else {
break;
}
}
peaks.push(peak)
})
return peaks
}
Insert cell
height = width * 0.7
Insert cell
h = height / 3.5
Insert cell
marginTop = 32
Insert cell
marginRight = 40
Insert cell
r = d3.scaleLinear()
.domain(d3.extent(peaks.map(d => Math.floor(d.length / 2))))
.range([1, width / 4])
Insert cell
x = d3.scaleTime()
.domain(d3.extent(data.map(d => d.date)))
.range([0, width - marginRight])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(data.map(d => d.value)))
.range([h, marginTop])
Insert cell
dx = d3.scaleLog()
.domain(d3.extent(peaks.map(d => d.length)))
.range([height, h + r.range()[1] / 3])
Insert cell
line = d3.line()
.x(d => x(d.date))
.y(d => y(d.value))
.defined(d => d)
Insert cell
randColor = () => `hsl(${360 * Math.random()}, 50%, 50%)`
Insert cell
style = html`<style>
path {
stroke: black;
fill: none;
}
text {
text-anchor: middle;
font-family: sans-serif;
font-size: 14px;
}
</style>`
Insert cell
formatDate = d3.timeFormat("%B %Y")
Insert cell
formatValue = d3.format("$,.0f")
Insert cell
d3 = require("d3")
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