Skip to content
Snippets Groups Projects
Commit 4a596b32 authored by esikkala's avatar esikkala
Browse files

Add creation place distribution

parent 19c00641
No related branches found
No related tags found
No related merge requests found
...@@ -44,13 +44,12 @@ const styles = theme => ({ ...@@ -44,13 +44,12 @@ const styles = theme => ({
const combineSmallGroups = (dataArray) => { const combineSmallGroups = (dataArray) => {
const totalLength = dataArray.length; const totalLength = dataArray.length;
const threshold = 0.1; const threshold = 0.1;
let other = { x: 'Other', y: 0, values: [] }; let other = { x: 'Other', y: 0 };
let newArray = []; let newArray = [];
for (let item of dataArray) { for (let item of dataArray) {
const portion = item.y / totalLength; const portion = item.y / totalLength;
if (portion < threshold) { if (portion < threshold) {
other.y += item.y; other.y += item.y;
other.values.push(item.values);
} else { } else {
newArray.push(item); newArray.push(item);
} }
...@@ -69,21 +68,32 @@ let Pie = (props) => { ...@@ -69,21 +68,32 @@ let Pie = (props) => {
if (resultCount < 1) { if (resultCount < 1) {
return ''; return '';
} }
const grouped = _.groupBy(data, groupBy); // const grouped = _.groupBy(data, groupBy);
let dataArray = []; // let dataArray = [];
for (let key in grouped) { // for (let key in grouped) {
const length = grouped[key].length; // const length = grouped[key].length;
dataArray.push({ // dataArray.push({
x: key, // x: key,
y: length, // y: length,
values: grouped[key] // values: grouped[key]
}); // });
} // }
let placeLinks = 0;
let dataArray = data.map(item => {
const msCount = parseInt(item.manuscriptCount);
placeLinks += msCount;
return {
x: item.label,
y: msCount,
};
});
dataArray = _.orderBy(dataArray, 'y', 'desc'); dataArray = _.orderBy(dataArray, 'y', 'desc');
dataArray = combineSmallGroups(dataArray); dataArray = combineSmallGroups(dataArray, placeLinks);
const legendArray = dataArray.map(group => ({ name: group.x + ' (' + group.y + ')' })); const legendArray = dataArray.map(group => ({ name: group.x + ' (' + group.y + ')' }));
const legendHeigth = legendArray.length * 33; const legendHeigth = legendArray.length * 33;
const pieTitle = resultCount + ' results for the query "' + query + '"';
const pieTitle = placeLinks + ' creation place links in total';
return ( return (
<div className={classes.root}> <div className={classes.root}>
...@@ -102,14 +112,14 @@ let Pie = (props) => { ...@@ -102,14 +112,14 @@ let Pie = (props) => {
}} }}
colorScale={'qualitative'} colorScale={'qualitative'}
data={dataArray} data={dataArray}
labelComponent={<PieTooltip resultCount={resultCount} />} labelComponent={<PieTooltip resultCount={placeLinks} />}
/> />
</Grid> </Grid>
<Grid className={classes.legend} item xs={12} sm={6}> <Grid className={classes.legend} item xs={12} sm={6}>
<Paper className={classes.legendPaper}> <Paper className={classes.legendPaper}>
<VictoryLegend <VictoryLegend
height={legendHeigth} height={legendHeigth}
title={groupBy} title={'Creation place'}
colorScale={'qualitative'} colorScale={'qualitative'}
data={legendArray} data={legendArray}
style={{ style={{
......
...@@ -193,11 +193,12 @@ let MapApp = (props) => { ...@@ -193,11 +193,12 @@ let MapApp = (props) => {
} }
} }
//console.log(creationPlaces)
let statistics = ''; let statistics = '';
if ((oneColumnView && options.resultFormat === 'statistics') || (!oneColumnView)) { if ((oneColumnView && options.resultFormat === 'statistics') || (!oneColumnView)) {
statistics = ( statistics = (
<div className={oneColumnView ? classes.statisticsOneColumn : classes.statistics}> <div className={oneColumnView ? classes.statisticsOneColumn : classes.statistics}>
<Pie data={manuscripts} groupBy={props.search.groupBy} query={props.search.query} /> <Pie data={creationPlaces} groupBy={props.search.groupBy} query={props.search.query} />
</div> </div>
); );
} }
......
...@@ -46,7 +46,7 @@ export const INITIAL_STATE = { ...@@ -46,7 +46,7 @@ export const INITIAL_STATE = {
}, },
sortBy: 'author', sortBy: 'author',
sortDirection: 'asc', sortDirection: 'asc',
groupBy: 'creationPlace', groupBy: 'label',
resultsQuery: '', resultsQuery: '',
fetchingResults: false, fetchingResults: false,
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment