Code
= Inputs.radio(
viewof repo
["pandas-dev/pandas",
"tidyverse/ggplot2",
,
]label: "仓库:", value: "pandas-dev/pandas"}
{ )
展示如何使用GitHub API。
---
title: "GitHub API"
format:
html:
toc: false
code-tools: true
---
展示如何使用[GitHub API](https://developer.github.com/v3)。
```{ojs}
//| code-fold: true
viewof repo = Inputs.radio(
[
"pandas-dev/pandas",
"tidyverse/ggplot2",
],
{ label: "仓库:", value: "pandas-dev/pandas"}
)
```
```{ojs}
//| code-fold: true
import { chart } with { commits as data } from "@d3/d3-bubble-chart"
chart
```
## 数据
```{ojs}
d3 = require('d3')
contributors = await d3.json(
"https://api.github.com/repos/" + repo + "/stats/contributors"
)
commits = contributors.map(contributor => {
const author = contributor.author;
return {
name: author.login,
title: author.login,
group: author.type,
value: contributor.total
}
})
```
```{ojs}
Inputs.table(commits, { sort: "value", reverse: true })
```