Skip to content

Commit

Permalink
feat(charts): Add scientific field selector for graph "publi.general.…
Browse files Browse the repository at this point in the history
…langues.chart-publications-by-year"
  • Loading branch information
annelhote committed Dec 5, 2024
1 parent 2ad909a commit 6df8078
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const Chart = ({ domain, id, hasComments, hasFooter }) => {
const idWithDomain = withDomain(id, domain);
const publisherTitle = publisher !== '*' ? ` (${publisher})` : '';
const dataTitle = {
publisherTitle,
publicationYear: beforeLastObservationSnap,
publisherTitle,
};
const optionsGraph = chartOptions[id].getOptions(
idWithDomain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const colors = {
others: getCSSValue('--purple-medium-100'),
};

function useGetData(observationSnap, domain, isPercent) {
function useGetData(observationSnap, domain, isPercent, needle = '*') {
const intl = useIntl();
const [allData, setData] = useState({});
const [isLoading, setLoading] = useState(true);
Expand All @@ -23,7 +23,7 @@ function useGetData(observationSnap, domain, isPercent) {
const query = getFetchOptions({
key: 'publicationsByYear',
domain,
parameters: [lastObservationSnap, 'lang.keyword'],
parameters: [lastObservationSnap, 'lang.keyword', needle],
objectType: ['publications'],
});
const res = await Axios.post(ES_API_URL, query, HEADERS);
Expand Down Expand Up @@ -129,7 +129,7 @@ function useGetData(observationSnap, domain, isPercent) {
dataGraph,
};
},
[domain, intl, isPercent],
[domain, intl, isPercent, needle],
);

useEffect(() => {
Expand All @@ -147,7 +147,7 @@ function useGetData(observationSnap, domain, isPercent) {
}
getData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [observationSnap, isPercent]);
}, [isPercent, needle, observationSnap]);

return { allData, isError, isLoading };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Radio, RadioGroup } from '@dataesr/react-dsfr';
import Axios from 'axios';
import Highcharts from 'highcharts';
import HCExportingData from 'highcharts/modules/export-data';
import HCExporting from 'highcharts/modules/exporting';
Expand All @@ -7,11 +8,18 @@ import PropTypes from 'prop-types';
import React, { useEffect, useRef, useState } from 'react';
import { useIntl } from 'react-intl';

import { ES_API_URL, HEADERS } from '../../../../../config/config';
import customComments from '../../../../../utils/chartComments';
import getFetchOptions from '../../../../../utils/chartFetchOptions';
import { chartOptions } from '../../../../../utils/chartOptions';
import { domains, graphIds } from '../../../../../utils/constants';
import { getObservationLabel, withDomain } from '../../../../../utils/helpers';
import {
capitalize,
getObservationLabel,
withDomain,
} from '../../../../../utils/helpers';
import useGlobals from '../../../../../utils/Hooks/useGetGlobals';
import SearchableSelect from '../../../../SearchableSelect';
import WrapperChart from '../../../../WrapperChart';
import GraphComments from '../../../graph-comments';
import useGetData from './get-data';
Expand All @@ -22,17 +30,22 @@ HCExportingData(Highcharts);
const Chart = ({ domain, hasComments, hasFooter, id }) => {
const [chartComments, setChartComments] = useState('');
const [isPercent, setPercent] = useState(false);
const [options, setOptions] = useState([]);
const [scientificField, setScientificField] = useState('*');
const chartRef = useRef();
const intl = useIntl();
const { beforeLastObservationSnap, lastObservationSnap } = useGlobals();
const { allData, isError, isLoading } = useGetData(
lastObservationSnap,
domain,
isPercent,
scientificField,
);
const { dataGraph, categories } = allData;
const scientificFieldTitle = scientificField !== '*' ? ` (${scientificField})` : '';
const dataTitle = {
publicationYear: getObservationLabel(beforeLastObservationSnap, intl),
scientificFieldTitle,
};
const idWithDomain = withDomain(id, domain);
const optionsGraph = chartOptions[id].getOptions(
Expand All @@ -44,6 +57,35 @@ const Chart = ({ domain, hasComments, hasFooter, id }) => {
isPercent,
);

useEffect(() => {
const query = getFetchOptions({
key: 'scientificFieldList',
domain,
parameters: [lastObservationSnap],
});

Axios.post(ES_API_URL, query, HEADERS).then((response) => {
const opts = response.data.aggregations.by_discipline.buckets.map(
(item) => ({
label: capitalize(
intl.formatMessage({
id: `app.discipline.${item.key}`,
defaultMessage: item.key,
}),
),
value: item.key,
}),
);
opts.unshift({
label: capitalize(
intl.formatMessage({ id: 'app.all-scientific-fields' }),
),
value: '*',
});
setOptions(opts);
});
}, [domain, intl, lastObservationSnap]);

useEffect(() => {
setChartComments(customComments(allData, idWithDomain, intl));
}, [allData, idWithDomain, intl]);
Expand Down Expand Up @@ -77,6 +119,12 @@ const Chart = ({ domain, hasComments, hasFooter, id }) => {
value='percent'
/>
</RadioGroup>
<SearchableSelect
label={intl.formatMessage({ id: 'app.scientific-field-filter-label' })}
onChange={(e) => (e.length > 0 ? setScientificField(e) : null)}
options={options}
selected={scientificField}
/>
<HighchartsReact
highcharts={Highcharts}
id={idWithDomain}
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"app.all-journals": "all journals",
"app.all-publications": "All publications",
"app.all-publishers": "all publishers and platforms",
"app.all-scientific-fields": "all scientific fields",
"app.all-repositories": "All open repositories",
"app.all-sponsor-types": "all types of lead sponsor",
"app.sponsor-type": "Lead sponsor type",
Expand Down Expand Up @@ -735,7 +736,6 @@
"app.health-publi.general.langues-ouverture.chart-repartition-publications.title": "Open access rate by language of publications {commentsName} in health, publications from {publicationYear}",
"app.national-publi.general.langues-ouverture.chart-repartition-publications.comments": "This graph shows the open access rate of publications {commentsName} released in {publicationYear} according to their language of publication, while specifying the open access routes. The language data was extracted from PubMed metadata if available, or inferred from the title and abstract in the remaining cases. <linebreak></linebreak>In particular, we note that among publications published in {publicationYear}, there are {publicationsEnglishTotal} publications in English of which {publicationsEnglishOpen} are open and {publicationsEnglishClosed} are closed (i.e. an open access rate of {publicationsEnglishRate}%), and {publicationsFrenchTotal} publications in French of which {publicationsFrenchOpen} are open and {publicationsFrenchClosed} closed (i.e. a rate of {publicationsFrenchRate}%). French-language publications are therefore less open than English-language publications. Publications in Spanish, German and Portuguese represent smaller numbers, statistically less significant.",
"app.health-publi.general.langues-ouverture.chart-repartition-publications.comments": "This graph shows the open access rate of publications {commentsName} in health released in {publicationYear} according to their language of publication, while specifying the open access routes. The language data was extracted from PubMed metadata if available, or inferred from the title and abstract in the remaining cases. <linebreak></linebreak>In particular, we note that among publications published in {publicationYear}, there are {publicationsEnglishTotal} publications in English of which {publicationsEnglishOpen} are open and {publicationsEnglishClosed} are closed (i.e. an open access rate of {publicationsEnglishRate}%), and {publicationsFrenchTotal} publications in French of which {publicationsFrenchOpen} are open and {publicationsFrenchClosed} closed (i.e. a rate of {publicationsFrenchRate}%). French-language publications are therefore less open than English-language publications. Publications in Spanish, German and Portuguese represent smaller numbers, statistically less significant.",
"app.national-publi.general.langues.chart-publications-by-year.title": "Evolution of the number of publications {commentsName} according to their language of publication",
"app.national-publi.general.voies-ouverture.description": "Open access to scientific publications can be achieved through several routes: natively open access publication by the publisher on a dissemination platform or deposit by the author in an <glossary0>app.glossary.archive-ouverte-min</glossary0>. These two routes are not exclusive, as a publication may be hosted both on an open repository and on the publisher's publishing platform. This simultaneity, which tends to increase over time, is a factor of resilience since it makes it possible to offer editorial quality and guarantee the durability of access to French scientific publications.",
"app.health-publi.general.voies-ouverture.description": "Open access to scientific publications can be achieved through several routes: natively open access publication by the publisher on a dissemination platform or deposit by the author in an <glossary0>app.glossary.archive-ouverte-min</glossary0>. These two routes are not exclusive, as a publication may be hosted both on an open repository and on the publisher's publishing platform. This simultaneity, which tends to increase over time, is a factor of resilience since it makes it possible to offer editorial quality and guarantee the durability of access to French scientific publications.",
"app.national-publi.general.voies-ouverture.chart-evolution-taux.tooltip": "<b>Publication year {point.x}</b><br>• Open access rate<br>with hosting {series.name}:<br>{point.y:.2f}% ({point.y_abs} / {point.y_tot})<br>• Total open access rate:<br>{point.stackTotal:.2f}% ({point.y_oa} / {point.y_tot})",
Expand Down Expand Up @@ -1040,6 +1040,7 @@
"app.publi.general.genres-ouverture.chart-repartition-genres.tooltip": "<b>{point.name} published in {point.publicationDate} ({point.bsoDomain})</b><br>{point.value} in {point.oaType}<br>i.e. {point.percentage:.2f}% of the total of the publications of {point.publicationDate}",
"app.publi.general.genres-ouverture.chart-repartition-taux.tooltip": "<b>{point.x_val} ({point.bsoDomain})</b><br>• Open access rate<br>with hosting {series.name}:<br>{point.y:.2f}% ({point.y_abs} / {point.y_tot})<br>• Total open access rate: {point.stacktotal:.2f}%",
"app.publi.general.langues-ouverture.chart-repartition-publications.tooltip": "<b>{point.name} published in {point.publicationDate} ({point.bsoDomain})</b><br>{point.value} in {point.oaType}<br>that is {point.percentage:.2f}% of the total publications of {point.publicationDate}",
"app.national-publi.general.langues.chart-publications-by-year.title": "Evolution of the number of publications {commentsName} according to their language of publication{scientificFieldTitle}",
"app.publi.general.langues.chart-publications-by-year.tooltip": "<b>{point.lang}: {point.ypercent} % of publications in {point.name}</br>",
"app.publi.general.langues.chart-publications-by-year-percent.tooltip": "<b>{point.lang}: {point.yabs} publications in {point.name}</br>",
"app.publi.navigation.go-to-page": "Go to page",
Expand Down Expand Up @@ -1122,6 +1123,7 @@
"app.publications.document.title": "Publications of the French Open Science Monitor",
"app.publications.global": "French publications (all areas)",
"app.publications.health": "French health publications",
"app.scientific-field-filter-label": "Select a scientific field",
"app.publishers": "publishers and platforms",
"app.publishers-filter-label": "Select a publisher or platform",
"app.publishers.apc-gold": "APC Gold",
Expand Down
8 changes: 5 additions & 3 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"app.all-journals": "toutes les revues",
"app.all-publications": "Toutes les publications",
"app.all-publishers": "tous les éditeurs",
"app.all-scientific-fields": "toutes les disciplines",
"app.all-repositories": "Toutes les archives ouvertes",
"app.all-sponsor-types": "tous types de promoteur",
"app.sponsor-type": "Type de promoteur",
Expand Down Expand Up @@ -966,7 +967,9 @@
"app.health-publi.general.langues-ouverture.chart-repartition-publications.title": "Taux d'accès ouvert par langue de publications {commentsName} dans le domaine de la santé, publications de {publicationYear}",
"app.national-publi.general.langues-ouverture.chart-repartition-publications.comments": "Ce graphique montre le taux d'accès ouvert des publications {commentsName} parues en {publicationYear} en fonction de leur langue de publication, tout en précisant les voies de l'ouverture. La donnée concernant la langue a été extraite des métadonnées de PubMed si disponible, ou inférée à partir du titre et du résumé dans le reste des cas.<linebreak></linebreak>On remarque notamment que, parmi les publications parues en {publicationYear}, on dénombre {publicationsEnglishTotal} publications en anglais dont {publicationsEnglishOpen} ouvertes et {publicationsEnglishClosed} fermées (soit un taux d'accès ouvert de {publicationsEnglishRate} %), et {publicationsFrenchTotal} publications en français dont {publicationsFrenchOpen} ouvertes et {publicationsFrenchClosed} fermées (soit un taux de {publicationsFrenchRate} %). Les publications en langue française sont donc moins ouvertes que les publications en langue anglaise. Les publications en espagnol, allemand et portugais représentent de plus petits effectifs, statistiquement moins significatifs.",
"app.health-publi.general.langues-ouverture.chart-repartition-publications.comments": "Ce graphique montre le taux d'accès ouvert des publications {commentsName} en santé parues en {publicationYear} en fonction de leur langue de publication, tout en précisant les voies de l'ouverture. La donnée concernant la langue a été extraite des métadonnées de PubMed si disponible, ou inférée à partir du titre et du résumé dans le reste des cas.<linebreak></linebreak>On remarque notamment que, parmi les publications parues en {publicationYear}, on dénombre {publicationsEnglishTotal} publications en anglais dont {publicationsEnglishOpen} ouvertes et {publicationsEnglishClosed} fermées (soit un taux d'accès ouvert de {publicationsEnglishRate} %), et {publicationsFrenchTotal} publications en français dont {publicationsFrenchOpen} ouvertes et {publicationsFrenchClosed} fermées (soit un taux de {publicationsFrenchRate} %). Les publications en langue française sont donc moins ouvertes que les publications en langue anglaise. Les publications en espagnol, allemand et portugais représentent de plus petits effectifs, statistiquement moins significatifs.",
"app.national-publi.general.langues.chart-publications-by-year.title": "Évolution du nombre de publications {commentsName} par langue de publication",
"app.national-publi.general.langues.chart-publications-by-year.title": "Évolution du nombre de publications {commentsName} par langue de publication{scientificFieldTitle}",
"app.publi.general.langues.chart-publications-by-year.tooltip": "<b>{point.lang}: {point.ypercent} % des publications en {point.name}</b>",
"app.publi.general.langues.chart-publications-by-year-percent.tooltip": "<b>{point.lang}: {point.yabs} publications en {point.name}</b>",
"app.national-publi.general.voies-ouverture.description": "L'accès ouvert aux publications scientifiques peut se faire par plusieurs voies : la publication nativement en accès ouvert par l'éditeur sur une plateforme de publication ou le dépôt par l'auteur dans une <glossary0>app.glossary.archive-ouverte-min</glossary0>. Ces deux voies ne sont pas exclusives, une publication pouvant être à la fois hébergée sur une archive ouverte et sur la plateforme de publication de l'éditeur. Cette simultanéité, qui tend à s'accroître au cours du temps, est un facteur de résilience puisqu'elle permet à la fois d'offrir la qualité éditoriale et de garantir la pérennité de l'accès aux publications scientifiques françaises.",
"app.health-publi.general.voies-ouverture.description": "L'accès ouvert aux publications scientifiques peut se faire par plusieurs voies : la publication nativement en accès ouvert par l'éditeur sur une plateforme de publication ou le dépôt par l'auteur dans une <glossary0>app.glossary.archive-ouverte-min</glossary0>. Ces deux voies ne sont pas exclusives, une publication pouvant être à la fois hébergée sur une archive ouverte et sur la plateforme de publication de l'éditeur. Cette simultanéité, qui tend à s'accroître au cours du temps, est un facteur de résilience puisqu'elle permet à la fois d'offrir la qualité éditoriale et de garantir la pérennité de l'accès aux publications scientifiques françaises.",
"app.national-publi.general.voies-ouverture.chart-evolution-taux.tooltip": "<b>Année de publication {point.x}</b><br>• Taux d'accès ouvert<br>avec hébergement {series.name} :<br>{point.y:.2f} % ({point.y_abs} / {point.y_tot})<br>• Taux d'accès ouvert total :<br>{point.stackTotal:.2f} % ({point.y_oa} / {point.y_tot})",
Expand Down Expand Up @@ -1234,8 +1237,6 @@
"app.publi.general.genres-ouverture.chart-repartition-genres.tooltip": "<b>{point.name} publiés en {point.publicationDate} ({point.bsoDomain})</b><br>{point.value} en {point.oaType}<br>soit {point.percentage:.2f} % du total des publications de {point.publicationDate}",
"app.publi.general.genres-ouverture.chart-repartition-taux.tooltip": "<b>{point.x_val} ({point.bsoDomain})</b><br>• Taux d'accès ouvert<br>avec hébergement {series.name} :<br>{point.y:.2f} % ({point.y_abs} / {point.y_tot})<br>• Taux d'accès ouvert total :<br>{point.stackTotal:.2f} % ({point.y_oa} / {point.y_tot})",
"app.publi.general.langues-ouverture.chart-repartition-publications.tooltip": "<b>{point.name} publiés en {point.publicationDate} ({point.bsoDomain})</b><br>{point.value} en {point.oaType}<br>soit {point.percentage:.2f} % du total des publications de {point.publicationDate}",
"app.publi.general.langues.chart-publications-by-year.tooltip": "<b>{point.lang}: {point.ypercent} % des publications en {point.name}</b>",
"app.publi.general.langues.chart-publications-by-year-percent.tooltip": "<b>{point.lang}: {point.yabs} publications en {point.name}</b>",
"app.publi.navigation.go-to-page": "Aller à la page",
"app.publi.navigation.affiliation.dynamique": "La dynamique d'ouverture par type d'affiliation",
"app.publi.navigation.affiliation.impact": "Impact des pays d'affiliation",
Expand Down Expand Up @@ -1315,6 +1316,7 @@
"app.publications.health": "publications françaises en santé",
"app.publications.local": "publications {commentsName}",
"app.with-at-least-one-explicit-mention": "Proportion des publications avec au moins une mention explicite à un jeu de données",
"app.scientific-field-filter-label": "Sélectionner une discipline",
"app.publishers": "éditeurs et plateformes",
"app.publishers-filter-label": "Sélectionner un éditeur",
"app.publishers.apc-gold": "APC Gold",
Expand Down
10 changes: 7 additions & 3 deletions src/utils/chartFetchOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export default function getFetchOptions({
},
},
}),
disciplinesList: ([observationSnap, disciplineField]) => ({
scientificFieldList: ([observationSnap]) => ({
size: 0,
query: {
bool: {
Expand All @@ -447,8 +447,8 @@ export default function getFetchOptions({
aggs: {
by_discipline: {
terms: {
field: disciplineField,
size: 30,
field: 'bso_classification.keyword',
size: 50,
},
},
},
Expand Down Expand Up @@ -2220,12 +2220,16 @@ export default function getFetchOptions({
publicationsByYear: ([
lastObservationSnap,
customField,
needleScientificField = '*',
minPublicationDate = 2013,
]) => ({
size: 0,
query: {
bool: {
filter: [
{
wildcard: { 'bso_classification.keyword': needleScientificField },
},
{
range: {
year: {
Expand Down

1 comment on commit 6df8078

@annelhote
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #313

Please sign in to comment.