Skip to content

Commit

Permalink
refactor(datasets): Refactor insights calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Mar 13, 2024
1 parent b441322 commit 22d902a
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions client/src/pages/datasetsInsightsTab.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import PropTypes, { object } from 'prop-types';
import PropTypes from 'prop-types';
import React from 'react';
import { useSearchParams } from 'react-router-dom';

Expand All @@ -22,25 +22,27 @@ export default function DatasetsInsightsTab({ allDatasets }) {
publishers[publisher][i] += 1;
});
const colors = ['#ea5545', '#f46a9b', '#ef9b20', '#edbf33', '#ede15b', '#bdcf32', '#87bc45', '#27aeef', '#b33dc6'];
let series = Object.keys(publishers).map((name) => ({
name,
data: publishers[name],
total: publishers[name].reduce((accumulator, currentValue) => accumulator + currentValue, 0),
}));
series = series.sort((a, b) => b.total - a.total);
series.forEach((s, ix) => {
s.color = colors[ix];
});
const NB_TOP = 8;
const series = Object.keys(publishers)
.map((name) => ({
name,
data: publishers[name],
total: publishers[name].reduce((accumulator, currentValue) => accumulator + currentValue, 0),
}))
.sort((a, b) => b.total - a.total)
.map((item, index) => ({
...item,
color: colors[index],
}));
const topSeries = series.slice(0, NB_TOP);
const tailData = new Array(categories.length).fill(0);
series.slice(NB_TOP).forEach((e) => {
e.data.forEach((d, ix) => {
tailData[ix] += d;
series.slice(NB_TOP).forEach((serie) => {
serie.data.forEach((d, index) => {
tailData[index] += d;
});
});
topSeries.push({
name: 'others',
name: 'Others',
data: tailData,
color: colors[NB_TOP],
});
Expand All @@ -59,7 +61,7 @@ export default function DatasetsInsightsTab({ allDatasets }) {
reversed: true,
},
title: {
text: 'Yearly distribution of the number of datasets by repositories',
text: `Yearly distribution of the number of datasets by repositories (top ${NB_TOP})`,
},
xAxis: {
categories,
Expand Down

0 comments on commit 22d902a

Please sign in to comment.