Published
Edited
Aug 21, 2020
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { checkbox } from "@jashkenas/inputs"
Insert cell
sc = (await require(await FileAttachment("api@2.js").url())).default
Insert cell
Insert cell
repo = "sourcecred/cred"
Insert cell
credView = loadCredView(repo)
Insert cell
pluginSummaries = sc.experimental
.pluginSummaries(credView)
.filter(n => n.name !== "Identity")
.filter(n => showInitiativesPlugin || n.name !== "Initiatives")
Insert cell
pluginMintData = {
return credView.intervalEnds().map((end, i) => {
const result = { date: new Date(end) };
for (const { name, mintByInterval } of pluginSummaries) {
result[name] = mintByInterval[i];
}
return result;
});
}
Insert cell
series = d3
.stack()
.keys(pluginSummaries.map(p => p.name))(pluginMintData)
Insert cell
d3.schemeSpectral
Insert cell
intervals = credView.intervalEnds()
Insert cell
intervalDates = intervals.map(i => new Date(i))
Insert cell
bandWidth = Math.floor((x.range()[1] - x.range()[0]) / intervals.length)
Insert cell
area = d3
.area()
.x(d => x(d.data.date))
.y0(d => y(d[0]))
.y1(d => y(d[1]))
Insert cell
x = d3
.scaleUtc()
.domain(d3.extent(intervalDates))
.range([margin.left, width - margin.right])
Insert cell
import { legend } from "@d3/color-legend"
Insert cell
y = d3
.scaleLinear()
.domain([0, d3.max(series, d => d3.max(d, d => d[1]))])
.nice()
.range([height - margin.bottom, margin.top])
Insert cell
color = d3
.scaleOrdinal()
.domain(pluginSummaries.map(p => p.name))
.range(d3.schemeCategory10)
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))
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("Minted Cred")
)
Insert cell
height = 500
Insert cell
margin = ({ top: 20, right: 30, bottom: 30, left: 40 })
Insert cell
c = d3.format(",.1f")
Insert cell
_ = require("lodash")
Insert cell
d3 = require("d3@5")
Insert cell
d3.scaleTime
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