Published
Edited
May 25, 2021
2 forks
Importers
9 stars
Insert cell
Insert cell
start = 6000
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
flow.diff
Insert cell
Insert cell
Insert cell
Insert cell
mutable path = []
Insert cell
x = d3.scaleTime()
.domain(timeDomain)
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain([0, 5 * start])
.range([height - margin.bottom, margin.top])
Insert cell
scaleTimeToValue = d3.scaleLinear()
.domain(path.map(({x: x0}) => new Date(+x.invert(x0))))
.range(path.map(({y: y0}) => y.invert(y0)))
// .clamp(true)
Insert cell
flow = new CashFlow(scaleTimeToValue, {domain: timeDomain})
Insert cell
timeDomain = [d3.timeYear.offset(new Date(), -1), new Date()].map(date => d3.timeMonth.floor(date))
Insert cell
style = `
svg[tabindex] {
display: block;
border: solid 2px transparent;
box-sizing: border-box;
}
svg[tabindex]:focus {
outline: none;
border: solid 2px lightblue;
}
`
Insert cell
mutable points = d3.range(0, 4).map(i => [
x(d3.interpolate(...timeDomain)(i / 3)),
y(start * Math.exp(0.4 * i))
])
Insert cell
line = d3.line().curve(d3.curveMonotoneX)
Insert cell
height = 300
Insert cell
width = 640
Insert cell
margin = ({left: 40, top: 20, right: 20, bottom: 30})
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0).tickFormat(dateFormat))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(4).tickFormat(d => d3.format("$")(d / 1000)))
.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text("Flow / mo."))
Insert cell
import {CashFlow, dateFormat} from "@observablehq/cash-flow"
Insert cell
import {copy} from "@mbostock/pbcopy"
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