-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
93 lines (71 loc) · 1.5 KB
/
index.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
/**
* Dependencies
*/
var crossfilter = require('crossfilter').crossfilter;
var config = window.CONFIG;
var d3 = require('d3');
var loc = require('./lib/location');
var Table = require('./lib/table');
/**
* Max options
*/
var MAX_OPTIONS = 5;
/**
* Options
*/
var options = crossfilter();
/**
* Dimensions
*/
var dimensions = window.dimensions = {
segments: options.dimension(function(d) {
return d.segments.length;
}),
average: options.dimension(function(d) {
return d.stats.avg;
}),
max: options.dimension(function(d) {
return d.stats.max;
}),
min: options.dimension(function(d) {
return d.stats.min;
})
};
/**
* Currently sorted by...
*/
var currentSort;
/**
* Table
*/
var table = null;
/**
* Display data
*/
loc.on('change', function(data, od) {
if (data.options.length < 1) return window.alert('No routes found.');
$('#results').css('display', 'block');
options.remove();
options.add(data.options);
if (!table) table = new Table(document.querySelector('.data'),
Object.keys(dimensions.min.bottom(1)[0]));
window.sortBy(currentSort || 'min', od);
window.animateTo('results');
});
/**
* Sort by
*/
window.sortBy = function(dimension, od) {
var d = dimensions[dimension];
var data = d.bottom(MAX_OPTIONS * 2);
table.render(data, od);
$('.routes-count').html(data.length);
};
/**
* Animate a scroll to a link
*/
window.animateTo = function(id) {
$('html, body').animate({
scrollTop: $('#' + id).offset().top - 50
}, 500);
};