-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(open-alex): Add number of retracted publications by country by p…
…ublication year
- Loading branch information
Showing
6 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
client/src/pages/open-alex/charts/retracted-by-country-by-year.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useQueries, useQuery } from '@tanstack/react-query'; | ||
import Highcharts from 'highcharts'; | ||
import HighchartsReact from 'highcharts-react-official'; | ||
|
||
export default function RetractedByCountryByYear() { | ||
const { data: data1, isLoading: isLoading1 } = useQuery({ | ||
queryKey: ['OpenAlexRetractionsByCountry'], | ||
queryFn: () => fetch('https://api.openalex.org/works?page=1&filter=is_retracted:true&group_by=authorships.countries').then((response) => response.json()) | ||
}); | ||
|
||
const countries = (data1?.group_by?.slice(0, 20) ?? []).map((item) => ({ name: item.key_display_name, iso2: item.key })); | ||
const results = useQueries({ | ||
queries: countries.map((country: string, index: number) => { | ||
return { | ||
queryKey: ['OpenAlexRetractionsByCountryByYear', country.iso2], | ||
queryFn: () => fetch(`https://api.openalex.org/works?page=1&filter=is_retracted:true,institutions.country_code:${country.iso2},publication_year:2000-&group_by=publication_year`).then((response) => response.json()), | ||
retry: 3, | ||
retryDelay: (attempt) => index * attempt * 1000, | ||
} | ||
}), | ||
}); | ||
|
||
if (isLoading1 || results.some((query) => query.isLoading)) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
const years = [...Array(25).keys()].map((item) => item + 2000); | ||
const series = results.map((result, index) => ({ | ||
...countries[index], | ||
data: years.map((year) => (result?.data?.group_by ?? []).find((item) => item.key === year.toString())?.count ?? 0), | ||
})); | ||
|
||
const options = { | ||
legend: { align: 'right', layout: 'vertical', verticalAlign: 'middle' }, | ||
plotOptions: { series: { label: { connectorAllowed: false } } }, | ||
series, | ||
title: { text: 'Number of retracted publications by country by publication year since 2000 (top 20)' }, | ||
xAxis: { categories: years, title: { text: 'Publication year' } }, | ||
yAxis: { title: { text: 'Number of retracted publications' } } | ||
}; | ||
|
||
return ( | ||
<HighchartsReact | ||
highcharts={Highcharts} | ||
options={options} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters