Published
Edited
Nov 3, 2018
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height));

svg.append("g")
.call(xAxis);

svg.append("g")
.call(xAxisDate);
svg.append("g")
.call(yAxis);

svg.append("g")
.call(yAxisBlockTime);
svg.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", lineDifficulty);
svg.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "red")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", lineBlocktime);
return svg.node();
}
Insert cell
height = 500
Insert cell
margin = ({top: 20, right: 30, bottom: 100, left: 40})
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(data, d => d.block))
.range([margin.left, width - margin.right])
Insert cell
Insert cell
y = d3.scaleLog()
.domain([1000000000000000, d3.max(data, d => d.difficulty)]).nice()
.range([height - margin.bottom, margin.top])
Insert cell
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom + 30})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))
Insert cell
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.y))
Insert cell
Insert cell
lineDifficulty = d3.line()
.defined(d => !isNaN(d.difficulty))
.x(d => x(d.block))
.y(d => y(d.difficulty))
Insert cell
Insert cell
dataOld = {
let data = await require("@observablehq/aapl");
data = data.map(({date, close}) => ({date, value: close}));
data.y = "$ AAPL Close";
return data;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
3 * Math.pow(10, 15) // 15 for trillion
// Difficulty: 3,094,300,564,990,609
// 3094300564990609
// 3000000000000000

// 2**45 = 35184372088832
35184372088832
3000000000000000
140737488355328

// 2**50 = 1125899906842624
1125899906842624
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more