diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-22 08:48:38 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:06:06 +0200 |
| commit | 3bf073f46e74667df4d2be9488a9f8f44ac84421 (patch) | |
| tree | 75731c952d6965cf5075b03f504193936348780f /src/components/timeline/TimelineControlsComponent.js | |
| parent | d6455f1c9e57934b76ce95b3fb204072300a1991 (diff) | |
Make timeline clickable
Diffstat (limited to 'src/components/timeline/TimelineControlsComponent.js')
| -rw-r--r-- | src/components/timeline/TimelineControlsComponent.js | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/src/components/timeline/TimelineControlsComponent.js b/src/components/timeline/TimelineControlsComponent.js index 2e093583..bd98afc3 100644 --- a/src/components/timeline/TimelineControlsComponent.js +++ b/src/components/timeline/TimelineControlsComponent.js @@ -1,33 +1,39 @@ import React from "react"; import PlayButtonContainer from "../../containers/timeline/PlayButtonContainer"; +import {convertTickToPercentage} from "../../util/timeline"; -function getXPercentage(tick, maxTick) { - if (maxTick === 0) { - return "0%"; - } else if (tick > maxTick) { - return ((maxTick / (maxTick + 1)) * 100) + "%"; +class TimelineControlsComponent extends React.Component { + onTimelineClick(e) { + const percentage = e.nativeEvent.offsetX / this.timeline.clientWidth; + const tick = Math.floor(percentage * (this.props.lastSimulatedTick + 1)); + this.props.goToTick(tick); } - return ((tick / (maxTick + 1)) * 100) + "%"; -} - -const TimelineControlsComponent = ({currentTick, lastSimulatedTick, sectionTicks}) => ( - <div className="timeline-controls"> - <PlayButtonContainer/> - <div className="timeline"> - <div - className="time-marker" - style={{left: getXPercentage(currentTick, lastSimulatedTick)}} - /> - {sectionTicks.map(sectionTick => ( + render() { + return ( + <div className="timeline-controls"> + <PlayButtonContainer/> <div - key={sectionTick} - className="section-marker" - style={{left: getXPercentage(sectionTick, lastSimulatedTick)}} - /> - ))} - </div> - </div> -); + className="timeline" + ref={timeline => this.timeline = timeline} + onClick={this.onTimelineClick.bind(this)} + > + <div + className="time-marker" + style={{left: convertTickToPercentage(this.props.currentTick, this.props.lastSimulatedTick)}} + /> + {this.props.sectionTicks.map(sectionTick => ( + <div + key={sectionTick} + className="section-marker" + style={{left: convertTickToPercentage(sectionTick, this.props.lastSimulatedTick)}} + title="Topology changes at this tick" + /> + ))} + </div> + </div> + ); + } +} export default TimelineControlsComponent; |
