diff --git a/src/client/components/Pie.js b/src/client/components/Pie.js index 466f357e0c1af2ee457eb4ae0da65591b2247e58..8e37ec4b5a7079c32a6aa0847b39ab3318f32cdd 100644 --- a/src/client/components/Pie.js +++ b/src/client/components/Pie.js @@ -44,13 +44,12 @@ const styles = theme => ({ const combineSmallGroups = (dataArray) => { const totalLength = dataArray.length; const threshold = 0.1; - let other = { x: 'Other', y: 0, values: [] }; + let other = { x: 'Other', y: 0 }; let newArray = []; for (let item of dataArray) { const portion = item.y / totalLength; if (portion < threshold) { other.y += item.y; - other.values.push(item.values); } else { newArray.push(item); } @@ -69,21 +68,32 @@ let Pie = (props) => { if (resultCount < 1) { return ''; } - const grouped = _.groupBy(data, groupBy); - let dataArray = []; - for (let key in grouped) { - const length = grouped[key].length; - dataArray.push({ - x: key, - y: length, - values: grouped[key] - }); - } + // const grouped = _.groupBy(data, groupBy); + // let dataArray = []; + // for (let key in grouped) { + // const length = grouped[key].length; + // dataArray.push({ + // x: key, + // y: length, + // 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 = combineSmallGroups(dataArray); + dataArray = combineSmallGroups(dataArray, placeLinks); + const legendArray = dataArray.map(group => ({ name: group.x + ' (' + group.y + ')' })); const legendHeigth = legendArray.length * 33; - const pieTitle = resultCount + ' results for the query "' + query + '"'; + + const pieTitle = placeLinks + ' creation place links in total'; return ( <div className={classes.root}> @@ -102,14 +112,14 @@ let Pie = (props) => { }} colorScale={'qualitative'} data={dataArray} - labelComponent={<PieTooltip resultCount={resultCount} />} + labelComponent={<PieTooltip resultCount={placeLinks} />} /> </Grid> <Grid className={classes.legend} item xs={12} sm={6}> <Paper className={classes.legendPaper}> <VictoryLegend height={legendHeigth} - title={groupBy} + title={'Creation place'} colorScale={'qualitative'} data={legendArray} style={{ diff --git a/src/client/containers/MapApp.js b/src/client/containers/MapApp.js index 047b43a619316b7e671b11d1e65dff46a468db4f..7e53045e0cd370b720c7bda0da5917b546bdde09 100644 --- a/src/client/containers/MapApp.js +++ b/src/client/containers/MapApp.js @@ -193,11 +193,12 @@ let MapApp = (props) => { } } + //console.log(creationPlaces) let statistics = ''; if ((oneColumnView && options.resultFormat === 'statistics') || (!oneColumnView)) { 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> ); } diff --git a/src/client/reducers/search.js b/src/client/reducers/search.js index a2f0f6740619a45fd80a2b7b413db8902053e3a4..811e62fbbf944357dd8ed9db7e51e234962cc9d8 100644 --- a/src/client/reducers/search.js +++ b/src/client/reducers/search.js @@ -46,7 +46,7 @@ export const INITIAL_STATE = { }, sortBy: 'author', sortDirection: 'asc', - groupBy: 'creationPlace', + groupBy: 'label', resultsQuery: '', fetchingResults: false, };