Skip to content

Commit

Permalink
fix(graph): Add OA percent for retractions by year
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Oct 12, 2023
1 parent 2094bde commit 709ecdb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import Axios from 'axios';
import { useCallback, useEffect, useState } from 'react';
import { useIntl } from 'react-intl';

import { ES_API_URL, HEADERS } from '../../../../../config/config';
import getFetchOptions from '../../../../../utils/chartFetchOptions';
import { capitalize } from '../../../../../utils/helpers';
import useGlobals from '../../../../../utils/Hooks/useGetGlobals';

function useGetData(observationSnaps, domain = '', isPercent = false) {
const [data, setData] = useState({});
const [isError, setError] = useState(false);
const [isLoading, setLoading] = useState(true);
const { lastObservationSnap } = useGlobals();
const intl = useIntl();

const getDataByObservationSnaps = useCallback(async () => {
const query = getFetchOptions({
Expand All @@ -22,7 +25,13 @@ function useGetData(observationSnaps, domain = '', isPercent = false) {
const buckets = response?.data?.aggregations?.by_field?.buckets?.sort(
(a, b) => b.doc_count - a.doc_count,
);
const categories = buckets.map((item) => item.key);
const categories = buckets.map((item) => capitalize(
intl.formatMessage({
id: `app.discipline.${item.key
.replace(/\n/g, '')
.replace(' ', ' ')}`,
}),
));
const dataGraph = [
{
data: buckets.map(
Expand All @@ -38,7 +47,7 @@ function useGetData(observationSnaps, domain = '', isPercent = false) {
categories,
dataGraph,
};
}, [domain, lastObservationSnap]);
}, [domain, intl, lastObservationSnap]);

useEffect(() => {
async function getData() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import Axios from 'axios';
import { useCallback, useEffect, useState } from 'react';
import { useIntl } from 'react-intl';

import { ES_API_URL, HEADERS } from '../../../../../config/config';
import getFetchOptions from '../../../../../utils/chartFetchOptions';
import { getCSSValue } from '../../../../../utils/helpers';
import useGlobals from '../../../../../utils/Hooks/useGetGlobals';

function useGetData(observationSnaps, domain = '', isPercent = false) {
const [data, setData] = useState({});
const [isError, setError] = useState(false);
const [isLoading, setLoading] = useState(true);
const { lastObservationSnap } = useGlobals();
const intl = useIntl();

const getDataByObservationSnaps = useCallback(async () => {
const query = getFetchOptions({
Expand All @@ -23,22 +26,33 @@ function useGetData(observationSnaps, domain = '', isPercent = false) {
(a, b) => a.key - b.key,
);
const categories = buckets.map((item) => item.key);
const closedData = [];
const oaData = [];
buckets.forEach((item) => {
const retracted = item.by_retraction.buckets.find((i2) => i2.key === 1);
const closedPubs = retracted.by_oa.buckets.find((i2) => i2.key === 0)?.doc_count ?? 0;
closedData.push((closedPubs / item.doc_count) * 100);
const oaPubs = retracted.by_oa.buckets.find((i2) => i2.key === 0)?.doc_count ?? 0;
oaData.push((oaPubs / item.doc_count) * 100);
});
const dataGraph = [
{
data: buckets.map(
(item) => ((item.by_retraction.buckets.find((i2) => i2.key === 1)
?.doc_count ?? 0)
/ item.doc_count)
* 100,
),
color: getCSSValue('--blue-soft-175'),
data: closedData,
name: intl.formatMessage({ id: 'app.type-hebergement.closed' }),
},
{
color: getCSSValue('--orange-soft-100'),
data: oaData,
name: intl.formatMessage({ id: 'app.type-hebergement.open' }),
},
];

return {
categories,
dataGraph,
};
}, [domain, lastObservationSnap]);
}, [domain, intl, lastObservationSnap]);

useEffect(() => {
async function getData() {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/chartFetchOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,13 @@ export default function getFetchOptions({
terms: {
field: 'retraction_details.is_retracted',
},
aggs: {
by_oa: {
terms: {
field: `oa_details.${lastObservationSnap}.is_oa`,
},
},
},
},
},
},
Expand Down
11 changes: 9 additions & 2 deletions src/utils/chartOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4139,13 +4139,20 @@ export const chartOptions = {
title: { text: intl.formatMessage({ id: 'app.publication-year' }) },
categories,
};
options.yAxis = getPercentageYAxis();
options.yAxis = getPercentageYAxis(true, null, false, 3);
options.yAxis.title.text = intl.formatMessage({
id: 'app.publi.percent-publications-retracted',
});
options.legend.enabled = false;
options.legend.enabled = true;
options.legend.reversed = true;
options.plotOptions = {
series: {
dataLabels: {
enabled: true,
},
},
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
formatter() {
Expand Down

0 comments on commit 709ecdb

Please sign in to comment.