From e8a883dbaca978b8f564ed5936571fb01a02cf68 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Sun, 31 May 2020 16:54:31 +0200 Subject: [PATCH] fix markers (again) --- src/components/Timeline.jsx | 18 +++++++++++++++--- .../presentational/Timeline/Events.js | 17 +++-------------- .../presentational/Timeline/Markers.js | 13 ++++--------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/components/Timeline.jsx b/src/components/Timeline.jsx index 4437408..0ac6351 100644 --- a/src/components/Timeline.jsx +++ b/src/components/Timeline.jsx @@ -5,6 +5,7 @@ import * as selectors from '../selectors' import hash from 'object-hash' import copy from '../common/data/copy.json' +import { sizes } from '../common/global' import Header from './presentational/Timeline/Header' import Axis from './TimelineAxis.jsx' import Clip from './presentational/Timeline/Clip' @@ -20,6 +21,7 @@ class Timeline extends React.Component { super(props) this.styleDatetime = this.styleDatetime.bind(this) this.getDatetimeX = this.getDatetimeX.bind(this) + this.getY = this.getY.bind(this) this.onApplyZoom = this.onApplyZoom.bind(this) this.svgRef = React.createRef() this.state = { @@ -269,6 +271,16 @@ class Timeline extends React.Component { return this.state.scaleX(datetime) } + getY (event) { + const { category, project } = event + const { features, domain } = this.props + const { GRAPH_NONLOCATED } = features + if (GRAPH_NONLOCATED && GRAPH_NONLOCATED.categories.includes(category)) { + return this.state.dims.marginTop + domain.projects[project].offset + sizes.eventDotR + } + return this.state.scaleY(category) + } + /** * Determines additional styles on the for each location. * A location consists of an array of events (see selectors). The function @@ -340,8 +352,8 @@ class Timeline extends React.Component { this.getDatetimeX(ev.datetime)} + getEventY={this.getY} transitionDuration={this.state.transitionDuration} styles={this.props.ui.styles} features={this.props.features} @@ -352,7 +364,7 @@ class Timeline extends React.Component { styleDatetime={this.styleDatetime} narrative={this.props.app.narrative} getDatetimeX={this.getDatetimeX} - getCategoryY={this.state.scaleY} + getY={this.getY} getHighlights={group => { if (group === 'None') { return [] diff --git a/src/components/presentational/Timeline/Events.js b/src/components/presentational/Timeline/Events.js index 9e588e1..a71edc4 100644 --- a/src/components/presentational/Timeline/Events.js +++ b/src/components/presentational/Timeline/Events.js @@ -63,7 +63,7 @@ const TimelineEvents = ({ projects, narrative, getDatetimeX, - getCategoryY, + getY, getCategoryColor, getHighlights, onSelect, @@ -92,18 +92,7 @@ const TimelineEvents = ({ } } - let eventY = getCategoryY ? getCategoryY(event.category) : 0 - const isNonlocated = !event.latitude && !event.longitude - if (features.GRAPH_NONLOCATED && isNonlocated) { - const { project } = event - if (project) { - const { offset } = projects[project] - eventY = dims.marginTop + offset + sizes.eventDotR - } else { - eventY = 0 - } - } - + const eventY = getY(event) let colour = event.colour ? event.colour : getCategoryColor(event.category) const styles = { fill: colour, @@ -114,7 +103,7 @@ const TimelineEvents = ({ return renderShape(event, styles, { x: getDatetimeX(event.datetime), y: eventY, - onSelect: () => { console.log(event); onSelect(event) }, + onSelect: () => onSelect(event), dims, highlights: features.HIGHLIGHT_GROUPS ? getHighlights(event.tags[features.HIGHLIGHT_GROUPS.tagIndexIndicatingGroup]) : [], features diff --git a/src/components/presentational/Timeline/Markers.js b/src/components/presentational/Timeline/Markers.js index d5326a7..dbd0dee 100644 --- a/src/components/presentational/Timeline/Markers.js +++ b/src/components/presentational/Timeline/Markers.js @@ -4,7 +4,7 @@ import colors, { sizes } from '../../../common/global' const TimelineMarkers = ({ styles, getEventX, - getCategoryY, + getEventY, transitionDuration, selected, dims, @@ -12,10 +12,6 @@ const TimelineMarkers = ({ }) => { function renderMarker (event) { function renderCircle () { - const yVal = (features.GRAPH_NONLOCATED && !event.latitude && !event.longitude) - ? event.projectOffset >= 0 ? dims.trackHeight - event.projectOffset : dims.marginTop - : getCategoryY ? getCategoryY(event.category) : () => null - return } const isNonlocated = !event.latitude && !event.longitude - const isBar = (!features.GRAPH_NONLOCATED && isNonlocated) || (features.GRAPH_NONLOCATED && features.GRAPH_NONLOCATED.categories.includes(event.category)) switch (event.shape) { case 'circle': return renderCircle() @@ -63,7 +58,7 @@ const TimelineMarkers = ({ case 'star': return renderCircle() default: - return isBar ? renderBar() : renderCircle() + return (!features.GRAPH_NONLOCATED && isNonlocated) ? renderBar : renderCircle() } }