-
Notifications
You must be signed in to change notification settings - Fork 21
/
github-api.ojs
81 lines (67 loc) · 1.67 KB
/
github-api.ojs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
FileAttachments:
source_ojs: ./github-api.ojs
*/
md`
# GitHub API Notebook
A notebook that demonstrates using the [GitHub API](https://docs.github.com/en/rest) in Dataflow.
`;
viewof repo = Inputs.select( `denoland/deno
JuliaLang/julia
facebook/react
streamlit/streamlit
observablehq/runtime
d3/d3
asg017/dataflow`.split("\n"), {label: "Repository"});
Plot.plot({
marginLeft: 100,
padding: 0,
x: {
round: true,
grid: true
},
color: {
scheme: "YlGnBu"
},
facet: {
data: data,
marginLeft: 100,
y: "author"
},
marks: [
Plot.barX(data, Plot.binX({fill: "count"}, {x: "date", inset: 0.5}))
]
})
Plot.plot({
y: {
domain: Array.from({length:7}, (_,i)=>i),
tickFormat: Plot.formatWeekday("en", "narrow"),
},
color: {
scheme: "YlGnBu"
},
marks: [
Plot.cell(data, {
x: d => d.date.getUTCHours(),
y: d => d.date.getUTCDay(),
fill: (d, i) => i > 0 ? (d.date - data[i - 1].date) / data[i - 1].date : NaN,
title: (d, i) => i > 0 ? ((d.date - data[i - 1].date) / data[i - 1].date * 100).toFixed(1) : NaN,
inset: 0.5
})
]
});
r = fetch(`https://api.github.com/repos/${repo}`)
.then(r=>r.json());
commits = fetch(r.commits_url.replace(/{\/sha}$/, "?per_page=100&since=1990-01-01T00:00:00Z"))
.then(r=>r.json())
data = commits.filter(d=>d.author).map(d=>({
date: new Date(d.commit.author.date),
author: d.author.login,
message: d.commit.message
}));
md`## Source Code
This is the original source code for this notebook, the \`github-api.ojs\` file.`
md`~~~javascript
${(await FileAttachment("source_ojs").text()).replace(/~~~/g, "```")}
~~~`
document.title = "GitHub API Example / Dataflow";