-
Notifications
You must be signed in to change notification settings - Fork 1
/
sliders.js
51 lines (41 loc) · 1.49 KB
/
sliders.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
function sliders(el, state) {
const {dataPoints, views} = state.get()
makeSlider(dataPoints, dataPoint => state.setState({dataPoint}))
makeSlider(views, view => state.setState({view}))
function makeSlider(array, onChange) {
const base = d3.select(el)
const root = base.append('div')
.attr('class', 'row')
.attr('class', 'align-items-center')
root.append('div')
.attr('class', 'col-sm-2')
.append('p')
.attr('class', 'value-step')
root.append('div')
.attr('class', 'col-sm')
.append('div')
.attr('class', 'slider-step')
var sliderStep = d3
.sliderBottom()
.min(0)
.max(array.length - 1)
.width(300)
.tickFormat(d => array[d])
.ticks(array.length - 1)
.step(1)
.on('onchange', val => {
const cur = array[val]
root.select('p.value-step').text(cur);
onChange(cur)
});
var gStep = root
.select('div.slider-step')
.append('svg')
.attr('width', 500)
.attr('height', 100)
.append('g')
.attr('transform', 'translate(30,30)');
gStep.call(sliderStep);
root.select('p.value-step').text(array[sliderStep.value()]);
}
}