Published
Edited
Jan 19, 2021
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

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

const axisLinear = svg
.append("g")
.style("opacity", 1)
.call(yAxis, yLinear);

const axisPower = svg
.append("g")
.style("opacity", 0)
.call(yAxis, yPower, ",")
.call(yTickPosition, yLinear);

const path = svg
.append("g")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 0.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.selectAll("path")
.data(sigmaInterfaces)
.join("path")
.style("mix-blend-mode", "multiply")
.attr("d", line(yLinear));

return Object.assign(svg.node(), {
update(y) {
const t = svg.transition().duration(750);

axisLinear.transition(t).style("opacity", y === yLinear ? 1 : 0)
.call(yTickPosition, y);

axisPower.transition(t).style("opacity", y === yPower ? 1 : 0)
.call(yTickPosition, y);

path.transition(t).attr("d", line(y));
}
});
}
Insert cell
chart.update(yType === "linear" ? yLinear : yPower)
Insert cell
line = y =>
d3
.line()
.x(d => x(d.x))
.y(d => y(d.y))
Insert cell
Insert cell
yLinear = d3
.scaleLinear()
.domain(yExtent)
.nice()
.range(yRange)
Insert cell
yPower = d3
.scalePow()
.exponent(25)
.domain([700, 500])
.range(yRange)
Insert cell
Insert cell
xAxis = g =>
g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(10))
Insert cell
yAxis = (g, y, format) =>
g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(height / 80, format))
.call(g =>
g
.append("text")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text("depth")
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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