Skip to content

Commit

Permalink
Filter reviews by type
Browse files Browse the repository at this point in the history
Refs #47
  • Loading branch information
thewilkybarkid committed Jul 12, 2024
1 parent b2e7ab9 commit e0ade98
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ const now = new Date()
const firstReview = d3.min(reviews, review => review.createdAt)

const preprintServerName = id => preprintServers[id]

const reviewType = id => {
switch (id) {
case 'full':
return 'Full'
case 'structured':
return 'Structured'
default:
return id
}
}
```

```js
Expand All @@ -31,13 +42,24 @@ const chosenYear = view(
format: year => year ?? 'All-time',
}),
)

const chosenType = view(
Inputs.select([null, 'full', 'structured'], {
label: 'PREreview type',
format: type => reviewType(type) ?? 'All',
}),
)
```
```js
const reviewsSelected = chosenYear
const reviewsInTimePeriod = chosenYear
? reviews.filter(review => review.createdAt.getUTCFullYear() === chosenYear)
: reviews

const reviewsSelected = chosenType
? reviewsInTimePeriod.filter(review => review.type === chosenType)
: reviewsInTimePeriod

const languageColor = Plot.scale({
color: {
type: 'categorical',
Expand All @@ -58,15 +80,15 @@ const languageColor = Plot.scale({
<div class="grid grid-cols-4">
<div class="card">
<h2>PREreviews ${chosenYear ? ` in ${chosenYear}` : ''}</h2>
<h2>${chosenType ? reviewType(chosenType) : ''} PREreviews ${chosenYear ? ` in ${chosenYear}` : ''}</h2>
<span class="big">${reviewsSelected.length.toLocaleString("en-US")}</span>
</div>
</div>
```js
function reviewsTimeline({ width } = {}) {
return Plot.plot({
title: `PREreviews per ${chosenYear ? 'week' : 'month'}`,
title: `${chosenType ? reviewType(chosenType) : ''} PREreviews per ${chosenYear ? 'week' : 'month'}`,
width: Math.max(width, 600),
height: 400,
color: {
Expand Down Expand Up @@ -113,7 +135,7 @@ function reviewsTimeline({ width } = {}) {
```js
function reviewsByPreprintServer({ width } = {}) {
return Plot.plot({
title: `Reviews ${chosenYear ? `in ${chosenYear}` : ''} by preprint server`,
title: `${chosenType ? reviewType(chosenType) : ''} PREreviews ${chosenYear ? `in ${chosenYear}` : ''} by preprint server`,
width: Math.max(width, 600),
color: {
...languageColor,
Expand Down

0 comments on commit e0ade98

Please sign in to comment.