From 08bbe9c85e1ab6883f0dd2d05d83b3d49cd82fd9 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Sun, 31 May 2020 14:19:20 +0200 Subject: [PATCH] fix projects! --- src/components/Layout.js | 1 - .../presentational/Timeline/Events.js | 4 +- .../presentational/Timeline/Project.js | 2 +- src/selectors/index.js | 62 +++++-------------- 4 files changed, 18 insertions(+), 51 deletions(-) diff --git a/src/components/Layout.js b/src/components/Layout.js index f7ff3f5..2a480c2 100644 --- a/src/components/Layout.js +++ b/src/components/Layout.js @@ -65,7 +65,6 @@ class Dashboard extends React.Component { ) // check events before let ptr = idx - 1 - console.log(events) while (events[idx].datetime === events[ptr].datetime) { matchedEvents.push(events[ptr]) ptr -= 1 diff --git a/src/components/presentational/Timeline/Events.js b/src/components/presentational/Timeline/Events.js index 81f6ae9..8acd3fe 100644 --- a/src/components/presentational/Timeline/Events.js +++ b/src/components/presentational/Timeline/Events.js @@ -99,6 +99,8 @@ const TimelineEvents = ({ if (project) { const { offset } = projects[project] eventY = dims.marginTop + offset + sizes.eventDotR + } else { + eventY = 0 } } @@ -112,7 +114,7 @@ const TimelineEvents = ({ return renderShape(event, styles, { x: getDatetimeX(event.datetime), y: eventY, - onSelect: () => onSelect(event), + onSelect: () => { console.log(event); onSelect(event) }, dims, highlights: features.HIGHLIGHT_GROUPS ? getHighlights(event.tags[features.HIGHLIGHT_GROUPS.tagIndexIndicatingGroup]) : [], features diff --git a/src/components/presentational/Timeline/Project.js b/src/components/presentational/Timeline/Project.js index a0ce7db..e162aa0 100644 --- a/src/components/presentational/Timeline/Project.js +++ b/src/components/presentational/Timeline/Project.js @@ -18,7 +18,7 @@ export default ({ onClick={onClick} className='project' x={getX(start)} - y={dims.marginTop + 100} + y={dims.marginTop + offset} width={length} style={{ fill: colour, fillOpacity: 0.2 }} height={2 * sizes.eventDotR} diff --git a/src/selectors/index.js b/src/selectors/index.js index 2e651c7..d06a528 100644 --- a/src/selectors/index.js +++ b/src/selectors/index.js @@ -174,7 +174,12 @@ export const selectEventsWithProjects = createSelector( projects[project].start = dateMin(projects[project].start, event.datetime) projects[project].end = dateMax(projects[project].end, event.datetime) } else { - projects[project] = { start: event.datetime, end: event.datetime, key: project } + projects[project] = { + start: event.datetime, + end: event.datetime, + key: project, + category: event.category + } } } acc.push({ ...event, project }) @@ -185,24 +190,18 @@ export const selectEventsWithProjects = createSelector( projObjs.sort((a, b) => a.start - b.start) // active projects is a data structure with projObjs.length empty slots - let activeProjs = {} - projObjs.forEach((_, idx) => { activeProjs[idx] = null }) + let activeProjs = Object.keys(projects).map((_, idx) => null) const projectsWithOffset = projObjs.reduce((acc, proj, theIdx) => { - if (theIdx >= 1) { acc[proj.key] = proj; return acc } // remove any project that have ended from slots - let j = 0 - while (j < projObjs.length) { - if (!activeProjs[j]) { - j++ - continue + activeProjs.forEach((theProj, theProjIdx) => { + if (theProj !== null) { + const projInSlot = projects[theProj] + if (projInSlot.end < proj.start) { + activeProjs[theProjIdx] = null + } } - const projInSlot = projects[activeProjs[j]] - if (projInSlot.end > proj.start) { - activeProjs[j] = null - } - j++ - } + }) let i = 0 // find the first empty slot while (activeProjs[i]) i++ @@ -210,43 +209,10 @@ export const selectEventsWithProjects = createSelector( activeProjs[i] = proj.key proj.offset = i * projSize - console.log(`${proj.key}:-- ${proj.offset}`) acc[proj.key] = proj return acc }, {}) - /* - events = events.reduce((acc, event) => { - const activeProjects = [] - projKeys.forEach((k, idx) => { - if (event.timestamp >= projects[k].start && event.timestamp <= projects[k].end) { - activeProjects.push(k) - } - }) - - // infer projectOffset using activeProjects - // TODO(lachlan) projects get overlaid if they start at the same time... - const activeIdx = activeProjects.indexOf(event.project) - let projectOffset = activeIdx * projSize - if (activeIdx === -1) { - // project isn't in previously calculated list of projects - projectOffset = -1 - } - if (event.project !== null) { - if (projects[event.project].hasOwnProperty('offset')) { - // project is already active - projectOffset = (activeIdx + 1) * projSize - } - projects[event.project].offset = projectOffset - projects[event.project].category = event.category - } else if (event.project !== null) { - projectOffset = projects[event.project].offset - } - acc.push({ ...event, projectOffset }) - return acc - }, []) - */ - return [events, projectsWithOffset] } )