From cde94262be82e93dd68dbf8b55bde18546526a59 Mon Sep 17 00:00:00 2001 From: efarooqui Date: Mon, 12 Oct 2020 14:54:45 -0700 Subject: [PATCH] Events showing up on timeline after interpolating categories from associations and passing into getY --- src/common/utilities.js | 12 +++++ src/components/Timeline.jsx | 8 +-- .../presentational/Timeline/Events.js | 49 ++++++++++++------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/common/utilities.js b/src/common/utilities.js index dac0f4a..989c370 100644 --- a/src/common/utilities.js +++ b/src/common/utilities.js @@ -62,6 +62,18 @@ export function trimAndEllipse (string, stringNum) { return string } +export function getEventCategories (event, categories) { + const matchedCategories = [] + if (event.associations && event.associations.length > 0) { + event.associations.reduce((acc, val) => { + const foundCategory = categories.find(cat => cat.id === val) + if (foundCategory) acc.push(foundCategory) + return acc + }, matchedCategories) + } + return matchedCategories +} + /** * Inset the full source represenation from 'allSources' into an event. The * function is 'curried' to allow easy use with maps. To use for a single diff --git a/src/components/Timeline.jsx b/src/components/Timeline.jsx index 0c177b8..49f375e 100644 --- a/src/components/Timeline.jsx +++ b/src/components/Timeline.jsx @@ -277,13 +277,6 @@ class Timeline extends React.Component { if (!categoriesExist) { return this.state.dims.trackHeight / 2 } - // const eventCategories = event.associations.reduce((acc, a) => { - // const foundCategory = categories.find(cat => cat.id === a) - // if (foundCategory) acc.push(foundCategory) - - // return acc - // }, []) - const { category, project } = event if (GRAPH_NONLOCATED && GRAPH_NONLOCATED.categories.includes(category)) { @@ -375,6 +368,7 @@ class Timeline extends React.Component { { const narIds = narrative ? narrative.steps.map(s => s.id) : [] - function renderEvent (event) { + function renderEvent (aggregated, event) { if (narrative) { if (!(narIds.includes(event.id))) { return null @@ -96,24 +97,33 @@ const TimelineEvents = ({ } } - const eventY = getY(event) + const relatedCategories = getEventCategories(event, categories) + + if (relatedCategories && relatedCategories.length > 0) { + relatedCategories.forEach(cat => { + const eventY = getY({...event, category: cat.id}) - let colour = event.colour ? event.colour : getCategoryColor(event.category) - const styles = { - fill: colour, - fillOpacity: eventY > 0 ? calcOpacity(1) : 0, - transition: `transform ${transitionDuration / 1000}s ease` + let colour = event.colour ? event.colour : getCategoryColor(cat.id) + const styles = { + fill: colour, + fillOpacity: eventY > 0 ? calcOpacity(1) : 0, + transition: `transform ${transitionDuration / 1000}s ease` + } + + aggregated.push( + renderShape(event, styles, { + x: getDatetimeX(event.datetime), + y: eventY, + eventRadius, + onSelect: () => onSelect(event), + dims, + highlights: features.HIGHLIGHT_GROUPS ? getHighlights(event.filters[features.HIGHLIGHT_GROUPS.filterIndexIndicatingGroup]) : [], + features + }) + ) + }) } - - return renderShape(event, styles, { - x: getDatetimeX(event.datetime), - y: eventY, - eventRadius, - onSelect: () => onSelect(event), - dims, - highlights: features.HIGHLIGHT_GROUPS ? getHighlights(event.filters[features.HIGHLIGHT_GROUPS.filterIndexIndicatingGroup]) : [], - features - }) + return aggregated } let renderProjects = () => null @@ -137,7 +147,8 @@ const TimelineEvents = ({ clipPath={'url(#clip)'} > {renderProjects()} - {events.map(event => renderEvent(event))} + {events.reduce(renderEvent, [])} + {/* {events.map(event => renderEvent(event))} */} ) }