Skip to content

Commit

Permalink
Show PREreviews per year
Browse files Browse the repository at this point in the history
Refs #26
  • Loading branch information
thewilkybarkid committed Jul 2, 2024
1 parent c7be725 commit 0874cf4
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ const now = new Date()
const firstReview = d3.min(reviews, review => review.createdAt)
```

```js
const chosenYear = view(
Inputs.select([null, ..._.range(now.getUTCFullYear(), firstReview.getUTCFullYear() - 1)], {
label: 'Year',
format: year => year ?? 'All-time',
}),
)
```
```js
const reviewsSelected = chosenYear
? reviews.filter(review => review.createdAt.getUTCFullYear() === chosenYear)
: reviews
```
<div class="grid grid-cols-4">
<div class="card">
<h2>PREreviews</h2>
<span class="big">${reviews.length.toLocaleString("en-US")}</span>
<h2>PREreviews ${chosenYear ? ` in ${chosenYear}` : ''}</h2>
<span class="big">${reviewsSelected.length.toLocaleString("en-US")}</span>
</div>
</div>
Expand All @@ -33,10 +48,15 @@ function reviewsTimeline({ width } = {}) {
width: Math.max(width, 600),
height: 400,
y: { grid: true, label: 'PREreviews', tickFormat: Math.floor, interval: 1 },
x: { label: '', domain: [d3.utcMonth.floor(firstReview), d3.utcMonth.ceil(now)] },
x: {
label: '',
domain: chosenYear
? [new Date(chosenYear, 0, 1, 0, 0, 0, 0), new Date(chosenYear + 1, 0, 1, 0, 0, 0, 0)]
: [d3.utcMonth.floor(firstReview), d3.utcMonth.ceil(now)],
},
marks: [
Plot.rectY(
reviews,
reviewsSelected,
Plot.binX(
{ y: 'count' },
{
Expand Down

0 comments on commit 0874cf4

Please sign in to comment.