-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmakeRadioControl.js
29 lines (27 loc) · 1.02 KB
/
makeRadioControl.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
import { keys, select } from 'd3';
export default function makeRadioControl(control, control_wrap) {
let changers = control_wrap
.selectAll('label')
.data(control.values || keys(this.data[0]))
.enter()
.append('label')
.attr('class', 'radio')
.text((d, i) => (control.relabels ? control.relabels[i] : d))
.append('input')
.attr('type', 'radio')
.attr('class', 'changer')
.attr('name', control.option.replace('.', '-') + '-' + this.targets[0].id)
.property('value', d => d)
.property('checked', d => {
return this.stringAccessor(this.targets[0].config, control.option) === d;
});
changers.on('change', d => {
let value = null;
changers.each(function(c) {
if (select(this).property('checked')) {
value = select(this).property('value') === 'none' ? null : c;
}
});
this.changeOption(control.option, value, control.callback, control.draw);
});
}