diff --git a/src/requests.md b/src/requests.md index 3910a46..c3826d1 100644 --- a/src/requests.md +++ b/src/requests.md @@ -26,6 +26,15 @@ const now = new Date() const firstRequest = d3.min(requests, request => request.timestamp) ``` +```js +const chosenYear = view( + Inputs.select([null, ..._.range(now.getUTCFullYear(), firstRequest.getUTCFullYear() - 1)], { + label: 'Year', + format: year => year ?? 'All-time', + }), +) +``` + ```js const chosenDomain = view( Inputs.select([null, ...Object.keys(openAlexDomains)], { @@ -56,11 +65,15 @@ const chosenField = view( ``` ```js +const requestsInTimePeriod = chosenYear + ? requests.filter(request => request.timestamp.getUTCFullYear() === chosenYear) + : requests + const requestsSelected = chosenField - ? requests.filter(d => d.fields.includes(chosenField)) + ? requestsInTimePeriod.filter(d => d.fields.includes(chosenField)) : chosenDomain - ? requests.filter(d => d.domains.includes(chosenDomain)) - : requests + ? requestsInTimePeriod.filter(d => d.domains.includes(chosenDomain)) + : requestsInTimePeriod ``` ```js @@ -106,16 +119,16 @@ const requestsBySubfield = requestsSelected