Skip to content

Commit

Permalink
Filter by year
Browse files Browse the repository at this point in the history
Refs #31
  • Loading branch information
thewilkybarkid committed Jul 4, 2024
1 parent fdeef4e commit b0c59de
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ const now = new Date()
const firstUser = d3.min(users, user => user.timestamp)
```

```js
const chosenYear = view(
Inputs.select([null, ..._.range(now.getUTCFullYear(), firstUser.getUTCFullYear() - 1)], {
label: 'Year',
format: year => year ?? 'All-time',
}),
)
```
```js
const usersInTimePeriod = chosenYear ? users.filter(user => user.timestamp.getUTCFullYear() === chosenYear) : users
```
<div class="grid grid-cols-4">
<div class="card">
<h2>PREreviewers</h2>
Expand All @@ -30,22 +43,27 @@ const firstUser = d3.min(users, user => user.timestamp)
console.log(users)
function usersTimeline({ width } = {}) {
return Plot.plot({
title: 'PREreviewers joining per month',
title: `PREreviewers joining ${chosenYear ? `in ${chosenYear} per week` : 'per month'}`,
width: Math.max(width, 600),
height: 400,
y: { grid: true, label: 'PREreviewers', tickFormat: Math.floor, interval: 1 },
x: {
label: '',
domain: [d3.utcMonth.floor(firstUser), d3.utcMonth.ceil(now)],
domain: chosenYear
? [
d3.utcSunday.floor(new Date(chosenYear, 0, 1, 0, 0, 0, 0)),
d3.utcSunday.ceil(new Date(chosenYear + 1, 0, 1, 0, 0, 0, 0)),
]
: [d3.utcSunday.floor(firstUser), d3.utcSunday.ceil(now)],
},
marks: [
Plot.rectY(
users,
usersInTimePeriod,
Plot.binX(
{ y: 'count' },
{
x: 'timestamp',
interval: d3.utcMonth,
interval: chosenYear ? d3.utcWeek : d3.utcMonth,
tip: true,
},
),
Expand Down

0 comments on commit b0c59de

Please sign in to comment.