import React from 'react'; import { connect } from 'react-redux'; import * as selectors from '../selectors'; import hash from 'object-hash'; import copy from '../js/data/copy.json'; import { formatterWithYear, isNotNullNorUndefined } from '../js/utilities'; import TimelineHeader from './presentational/TimelineHeader'; import TimelineHandles from './TimelineHandles.jsx'; import TimelineZoomControls from './TimelineZoomControls.jsx'; import TimelineLogic from '../js/timeline/timeline.js'; class Timeline extends React.Component { constructor(props) { super(props); this.svgRef = React.createRef() this.state = { isFolded: false }; } componentDidMount() { this.timeline = new TimelineLogic(this.svgRef.current, this.props.app, this.props.ui, this.props.methods); this.timeline.update(this.props.domain, this.props.app); } componentWillReceiveProps(nextProps) { if (hash(nextProps) !== hash(this.props)) { this.timeline.update(nextProps.domain, nextProps.app); } } onClickArrow() { this.setState((prevState, props) => { return {isFolded: !prevState.isFolded}; }); } getClientDims() { const WIDTH_CONTROLS = 100; const HEIGHT = 140; let WIDTH = 0; if (document.querySelector(`#${this.props.ui.dom.timeline}`) !== null) { const boundingClient = document.querySelector(`#${this.props.ui.dom.timeline}`).getBoundingClientRect(); WIDTH = boundingClient.width; } return { height: HEIGHT, width: WIDTH, width_controls: WIDTH_CONTROLS, height_controls: 115, margin_left: 120 } } onMoveTime(dir) { if (this.timeline) { return this.timeline.moveTime(dir); } return ''; } onApplyZoom(zoom) { if (this.timeline) { return this.timeline.applyZoom(zoom); } return ''; } renderSVG() { const dims = this.getClientDims(); return ( ); } render() { const { isNarrative, app, ui } = this.props let classes = `timeline-wrapper ${(this.state.isFolded) ? ' folded' : ''}`; classes += (app.narrative !== null) ? ' narrative-mode' : ''; return (