diff options
Diffstat (limited to 'animism-align/frontend/views/align/components/timeline.component.js')
| -rw-r--r-- | animism-align/frontend/views/align/components/timeline.component.js | 87 |
1 files changed, 21 insertions, 66 deletions
diff --git a/animism-align/frontend/views/align/components/timeline.component.js b/animism-align/frontend/views/align/components/timeline.component.js index 0a97c3a..5e07c0b 100644 --- a/animism-align/frontend/views/align/components/timeline.component.js +++ b/animism-align/frontend/views/align/components/timeline.component.js @@ -1,28 +1,25 @@ import React, { Component } from 'react' // import { Link } from 'react-router-dom' -// import { bindActionCreators } from 'redux' +import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import actions from '../../../actions' -// import * as uploadActions from './upload.actions' +// import * as alignActions from '../align.actions' +import Waveform from './waveform.component' import Ticks from './ticks.component' -import { DEFAULT_HEIGHT, WAVEFORM_HEIGHT, ZOOM_STEPS, ZOOM_LABEL_STEPS, ZOOM_TICK_STEPS } from '../constants' +import { ZOOM_STEPS } from '../constants' +import { clamp } from '../../../util' class Timeline extends Component { constructor(props){ super(props) - this.canvasRef = React.createRef() this.handleKeydown = this.handleKeydown.bind(this) + this.handleWheel = this.handleWheel.bind(this) } componentDidMount() { this.bind() - this.resize() - this.draw() - } - componentDidUpdate() { - this.draw() } componentWillUnmount() { this.unbind() @@ -34,65 +31,24 @@ class Timeline extends Component { document.removeEventListener('keydown', this.handleKeydown) } handleKeydown(e) { - // console.log(e.shiftKey, e.keyCode) - } - resize() { - const canvas = this.canvasRef.current - canvas.width = window.innerWidth - canvas.height = DEFAULT_HEIGHT - } - draw() { - const canvas = this.canvasRef.current - const ctx = canvas.getContext('2d') - const w = window.innerWidth - this.clearCanvas(ctx, w) - this.drawCurve(ctx, w) - } - clearCanvas(ctx, w) { - const h = WAVEFORM_HEIGHT - ctx.clearRect(0, 0, w, h) - ctx.fillStyle = 'rgba(0,0,0,0.5)' - ctx.fillRect(0, 0, w, h) - ctx.fillStyle = 'rgba(64,128,192,0.5)' - } - drawCurve(ctx, w) { - let { peaks, timeline } = this.props - let { start_ts, zoom, duration } = timeline - let stepsPerPixel = ZOOM_STEPS[zoom] // 0.1 sec / step - let indexesPerPixel = stepsPerPixel * 2 - let stepMin = start_ts * 10 - let stepDuration = duration * 10 / stepsPerPixel - let stepMax = stepDuration - stepMin - let stepWidth = Math.min(stepMax, w) - stepWidth += 2 + (stepWidth % 2) - let i = 0 - let step = stepMin - let waveformPeak = WAVEFORM_HEIGHT / 2 - let origin = (1 - peaks[step]) * waveformPeak - let y = origin - let peak - ctx.beginPath() - ctx.moveTo(0, y) - for (i = 0; i < stepWidth; i++) { - step = i * indexesPerPixel + stepMin - peak = peaks[step] - y = (1 - peak) * waveformPeak - ctx.lineTo(i, y) - } - for (i = stepWidth - 1; i > 0; i--) { - step = i * indexesPerPixel + stepMin - peak = peaks[step] - y = (1 + peaks[step]) * waveformPeak - ctx.lineTo(i, y) + if (e.shiftKey && e.keyCode === 189) { + actions.align.setZoom(this.props.timeline.zoom - 1) + } else if (e.shiftKey && e.keyCode === 187) { + actions.align.setZoom(this.props.timeline.zoom + 1) } - ctx.lineTo(0, origin) - ctx.fillStyle = 'rgba(255,255,255,0.8)' - ctx.fill() + } + handleWheel(e) { + let { start_ts, zoom, duration } = this.props.timeline + let secondsPerPixel = ZOOM_STEPS[zoom] / 10 // 0.1 sec / step + let widthTimeDuration = window.innerWidth * secondsPerPixel // secs per pixel + + start_ts = clamp(start_ts + e.deltaY * ZOOM_STEPS[zoom], 0, duration - widthTimeDuration / 2) + actions.align.setScrollPosition(start_ts) } render() { return ( - <div className='timeline'> - <canvas ref={this.canvasRef} /> + <div className='timeline' onWheel={this.handleWheel}> + <Waveform /> <Ticks timeline={this.props.timeline} /> </div> ) @@ -101,11 +57,10 @@ class Timeline extends Component { const mapStateToProps = state => ({ timeline: state.align.timeline, - peaks: state.site.peaks, }) const mapDispatchToProps = dispatch => ({ - // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), + // alignActions: bindActionCreators({ ...alignActions }, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(Timeline) |
