Skip to content

Commit

Permalink
fix(graph): remove percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Oct 16, 2023
1 parent 6256cd7 commit 3eaf95f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Toggle } from '@dataesr/react-dsfr';
import { Radio, RadioGroup } from '@dataesr/react-dsfr';
import Highcharts from 'highcharts';
import HCExportingData from 'highcharts/modules/export-data';
import HCExporting from 'highcharts/modules/exporting';
Expand All @@ -23,7 +23,7 @@ const Chart = ({ domain, hasComments, hasFooter, id }) => {
const chartRef = useRef();
const intl = useIntl();
const [chartComments, setChartComments] = useState('');
const [isPercent, setPercent] = useState(false);
const [isPercent, setPercent] = useState(true);
const { observationSnaps } = useGlobals();
const { data, isError, isLoading } = useGetData(
observationSnaps,
Expand Down Expand Up @@ -55,11 +55,25 @@ const Chart = ({ domain, hasComments, hasFooter, id }) => {
isError={isError}
isLoading={isLoading || !dataGraph}
>
<Toggle
checked={isPercent}
label={intl.formatMessage({ id: 'app.proportion' })}
<RadioGroup
className='d-inline-block'
isInline
onChange={() => setPercent(!isPercent)}
/>
value={isPercent}
>
<Radio
label={intl.formatMessage({
id: 'app.publi.display-percent-retracted',
})}
value
/>
<Radio
label={intl.formatMessage({
id: 'app.publi.display-number-retracted',
})}
value={false}
/>
</RadioGroup>
<HighchartsReact
highcharts={Highcharts}
id={idWithDomain}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ function useGetData(observationSnaps, domain = '', isPercent = false) {
objectType: ['publications'],
});
const numberOfRetracted = (item) => item.by_retraction.buckets.find((i2) => i2.key === 1)?.doc_count ?? 0;
const percentageOfRetracted = (item) => (numberOfRetracted(item) / item.doc_count) * 100;

const response = await Axios.post(ES_API_URL, query, HEADERS);
const buckets = response?.data?.aggregations?.by_publisher?.buckets
?.sort((a, b) => numberOfRetracted(b) - numberOfRetracted(a))
?.sort((a, b) => percentageOfRetracted(b) - percentageOfRetracted(a))
.slice(0, 20);
const categories = buckets.map((item) => item.key);
const dataGraph = {
data: buckets.map((item, catIndex) => ({
y_tot: item.doc_count ?? 0,
y_tot: item.doc_count,
y_abs: numberOfRetracted(item),
y_rel: (numberOfRetracted(item) / item.doc_count) * 10000,
y: isPercent
? (numberOfRetracted(item) / item.doc_count) * 10000
: numberOfRetracted(item),
y_rel: percentageOfRetracted(item),
y: isPercent ? percentageOfRetracted(item) : numberOfRetracted(item),
x: catIndex,
publisher: categories[catIndex],
})),
Expand Down
5 changes: 4 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,8 @@
"app.health-publi.data.hosted-documents-pmc": "of the publications in the health field from {publicationYear} are hosted on PubMed Central",
"app.national-publi.data.documents-by-types-by-oa": "of the journal articles are open access, compared to {oaBooksRate}% of books",
"app.national-publi.others.collaborations.international-collaborations.title": "Top 10 of the international collaborations with France",
"app.national-publi.others.retractions.chart-by-publisher.tooltip": "<b>{point.publisher}</b><br>• Share of retracted publications :<br>{point.y_rel:.1f} ‱ ({point.y_abs} / {point.y_tot})",
"app.national-publi.others.retractions.chart-by-publisher.title": "Retracted publications by publisher",
"app.national-publi.others.retractions.chart-by-publisher.tooltip": "<b>{point.publisher}</b><br>• Share of retracted publications :<br>{point.y_rel:.1f}% ({point.y_abs}/{point.y_tot})",
"app.national-publi.others.retractions.chart-by-year.title": "Rate of retracted publications by year of publication",
"app.national-publi.others.retractions.chart-by-field.title": "Rate of retracted publications by scientific field",
"app.navigation.objet-recherche": "Research object navigation",
Expand Down Expand Up @@ -965,6 +966,8 @@
"app.publi.display": "Display:",
"app.publi.display-open-access": "Open access rate (%)",
"app.publi.display-staff-open-access": "Number of publications",
"app.publi.display-percent-retracted": "Percentage of retracted publications",
"app.publi.display-number-retracted": "Number of retracted publications",
"app.publi.type-apc": "Type of publication fee",
"app.publi.type-auteur-rang-utile": "Affiliation of the first and last authors",
"app.publi.type-hebergement": "Hosting type",
Expand Down
5 changes: 4 additions & 1 deletion src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,8 @@
"app.health-publi.data.hosted-documents-pmc": "des publications en santé de {publicationYear} sont hébergées sur PubMed Central",
"app.national-publi.data.documents-by-types-by-oa": "des articles de revue sont en accès ouvert, contre {oaBooksRate} % des ouvrages",
"app.national-publi.others.collaborations.international-collaborations.title": "Top 10 des collaborations internationales avec la France",
"app.national-publi.others.retractions.chart-by-publisher.tooltip": "<b>{point.publisher}</b><br>• Part de publications retirées :<br>{point.y_rel:.1f} ‱ ({point.y_abs} / {point.y_tot})",
"app.national-publi.others.retractions.chart-by-publisher.title": "Publications retirées par éditeur",
"app.national-publi.others.retractions.chart-by-publisher.tooltip": "<b>{point.publisher}</b><br>• Pourcentage de publications retirées :<br>{point.y_rel:.1f}% ({point.y_abs}/{point.y_tot})",
"app.national-publi.others.retractions.chart-by-year.title": "Taux de publications retirées par année de publication",
"app.national-publi.others.retractions.chart-by-field.title": "Taux de publications retirées par discipline",
"app.navigation.objet-recherche": "Navigation par objet de recherche",
Expand Down Expand Up @@ -1131,6 +1132,8 @@
"app.publi.display": "Afficher :",
"app.publi.display-open-access": "Taux d'accès ouvert (%)",
"app.publi.display-staff-open-access": "Nombre de publications",
"app.publi.display-percent-retracted": "Pourcentage de publications retirées",
"app.publi.display-number-retracted": "Nombre de publications retirées",
"app.publi.type-apc": "Type de frais de publication",
"app.publi.type-auteur-rang-utile": "Affiliation des premiers et derniers auteurs",
"app.publi.type-hebergement": "Voie d'ouverture",
Expand Down
8 changes: 4 additions & 4 deletions src/utils/chartOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4198,15 +4198,15 @@ export const chartOptions = {
'publi.others.retractions.chart-by-publisher': {
getOptions: (id, intl, categories, graph, isPercent, dataTitle) => {
const options = getGraphOptions({ id, intl, dataTitle });
options.chart.type = 'column';
options.chart.type = 'bar';
options.xAxis = {
title: { text: intl.formatMessage({ id: 'app.publishers' }) },
categories,
};
options.yAxis = getPertenthousandYAxis(false, null, !isPercent);
options.yAxis = getPercentageYAxis(false, null, !isPercent);
options.yAxis.title.text = intl.formatMessage({
id: isPercent
? 'app.publi.pertenthousand-publications-retracted'
? 'app.publi.percent-publications-retracted'
: 'app.publi.nb-publications-retracted',
});
options.legend.enabled = false;
Expand All @@ -4216,7 +4216,7 @@ export const chartOptions = {
enabled: true,
formatter() {
if (isPercent) {
return this.y === 0 ? '' : this.y.toFixed(1).concat(' ');
return this.y === 0 ? '' : this.y.toFixed(3).concat(' %');
}
return this.y === 0 ? '' : this.y.toFixed();
},
Expand Down

0 comments on commit 3eaf95f

Please sign in to comment.