-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathHelpersForSelectionsUI.js
39 lines (34 loc) · 1.24 KB
/
HelpersForSelectionsUI.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
/**
* Created by rostam on 31.10.16.
*/
var pathColors = {};
var itin_opts = ['Shortest', 'Optimal'];
var pathTypes = d3.set(itin_opts); // can add back 'Through Centers' eventually..
var pathInitialSelections = d3.set(itin_opts);
pathColors[itin_opts[0]] = '#f00';
pathColors[itin_opts[1]] = '#345C1D';
function selectionsUI(identifier, initialSelections, colors) {
var space = d3.select(identifier).selectAll('input')
.data(pathTypes.values())
.enter().append("label");
space.append("input")
.attr('type', 'checkbox')
.property('checked', function(d) {
return initialSelections === undefined || initialSelections.has(d)
})
.attr("value", function(d) { return d });
space.append("span")
.attr('class', 'key')
.style('background-color', function(d) { return colors[d] });
space.append("span")
.text(function(d) { return d })
.attr("class", "english");
}
selectionsUI('#itinerary-options', pathInitialSelections, pathColors);
var selectedTypes = function(identifier) {
return d3.selectAll('#' + identifier + ' input[type=checkbox]')[0].filter(function(elem) {
return elem.checked;
}).map(function(elem) {
return elem.value;
})
};