processGraph = ({ exhibitionLimit = 1 } = {}) => {
const exhibitionGroupedNodes = d3.group(rawData, d => d.exhibitionName);
const exhibitionNodes = Array.from(exhibitionGroupedNodes)
.map(([id, value]) => {
return {
id,
type: 'exhibition',
items: value,
artists: groupBy(value, 'artistId').map(([id, value]) => {
return {
id,
type: 'artist',
title: value[0].artistFirstName,
items: value
};
}),
catalogues: groupBy(value, 'catalogeName').map(([id, value]) => {
return {
id,
type: 'catalogue',
title: value[0].catalogueName
};
})
};
})
.splice(0, exhibitionLimit);
const artistNodes = exhibitionNodes.reduce((prev, curr) => {
return [...prev, ...curr.artists];
}, []);
const itemNodes = artistNodes.reduce((prev, curr) => {
return [
...prev,
...curr.items.map(item => {
return {
id: item.id,
type: 'item',
title: item.title,
artistId: item.artistId
};
})
];
}, []);
const artistItemLinks = artistNodes.reduce((prev, curr) => {
return [
...prev,
...curr.items.map(item => {
return {
source: item.id,
target: curr.id
};
})
];
}, []);
const exhibitionArtistLinks = exhibitionNodes.reduce((prev, curr) => {
return [
...prev,
...curr.artists.map(artist => {
return {
source: artist.id,
target: curr.id
};
})
];
}, []);
const exhibitionItemLinks = exhibitionNodes.reduce((prev, curr) => {
return [
...prev,
...curr.items.map(item => {
return {
source: item.id,
target: curr.id
};
})
];
}, []);
return {
nodes: [...exhibitionNodes, ...artistNodes, ...itemNodes],
links: [
...artistItemLinks,
...exhibitionArtistLinks,
...exhibitionItemLinks
]
};
}