-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathadjust-speed.js
97 lines (85 loc) · 2.63 KB
/
adjust-speed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Adjust speed on a route
*/
import React, { Component, PropTypes } from 'react'
import {Button, Group} from './components/buttons'
import {Group as FormGroup, Number} from './components/input'
import {HOP_SELECTION} from './scenario-map/state'
import SelectFeedRouteAndPatterns from './select-feed-route-and-patterns'
export default class AdjustSpeed extends Component {
static propTypes = {
feeds: PropTypes.array.isRequired,
feedsById: PropTypes.object.isRequired,
modification: PropTypes.object.isRequired,
replaceModification: PropTypes.func.isRequired,
setMapState: PropTypes.func.isRequired
}
onSelectorChange = (value) => {
let {feed, routes, trips} = value
let modification = Object.assign({}, this.props.modification, { feed, routes, trips, hops: null })
this.props.replaceModification(modification)
}
newSelection = (e) => {
const {modification, setMapState} = this.props
setMapState({
state: HOP_SELECTION,
modification,
action: 'new'
})
}
addToSelection = (e) => {
const {modification, setMapState} = this.props
setMapState({
state: HOP_SELECTION,
modification,
action: 'add'
})
}
removeFromSelection = (e) => {
const {modification, setMapState} = this.props
setMapState({
state: HOP_SELECTION,
modification,
action: 'remove'
})
}
clearSegment = (e) => {
this.props.replaceModification({...this.props.modification, hops: null})
}
/** set the factor by which we are scaling, or the speed which we are replacing */
setScale = (e) => {
this.props.replaceModification({...this.props.modification, scale: e.target.value})
}
render () {
const {feeds, feedsById, modification} = this.props
return (
<form>
<SelectFeedRouteAndPatterns
feeds={feeds}
onChange={this.onSelectorChange}
routes={modification.routes}
selectedFeed={feedsById[modification.feed]}
trips={modification.trips}
/>
{modification.routes &&
<FormGroup>
<label>Segment</label>
<Group justified>
<Button onClick={this.newSelection}>Select</Button>
<Button onClick={this.addToSelection}>Add to</Button>
<Button onClick={this.removeFromSelection}>Remove from</Button>
<Button onClick={this.clearSegment}>Clear</Button>
</Group>
</FormGroup>
}
<Number
label='Scale'
name='Scale'
onChange={this.setScale}
step='any'
value={modification.scale}
/>
</form>
)
}
}