-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdataset_lockdown.js
65 lines (58 loc) · 1.91 KB
/
dataset_lockdown.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
/*
EVENTS DATA
*/
class LockdownDataset extends BaseDataset {
constructor(options) {
super({
name: "lockdown",
path: 'lockdown_dates.csv'
// path: "events.csv"
});
this.REPOSITORY_URL = './data/';
// this.REPOSITORY_URL = 'https://covid19-lockdown-tracker.netlify.com/';
this.filter_column = 'Country';
this.label_column = 'Country';
this.date_column = 'Start date';
// this.filter_column = 'country';
// this.date_column = 'date';
this.can_be_filtered = false;
}
init_html() {
super.init_html();
this.$select = $("select[name='" + this.prefix + "_filter']");
}
populate_html() {
var self = this;
var values = this.table.get_column_distinct(this.filter_column);
this.$select.empty();
this.$select.append("<option value=''>all</option>");
values.forEach(function(val) {
self.$select.append("<option value='" + val + "'>" + val + "</option>");
});
}
get_options() {
var options = super.get_options();
options.value = this.$select.children("option:selected").val();
return options;
}
get_series(options) {
var value = options.value;
var subtable = this.table;
var label = this.name;
if (value) {
subtable = subtable.filter(this.filter_column, value);
label += " " + value;
}
var data_x = [];
var data_y = [];
var x_col = subtable.headers.indexOf(this.date_column);
var y_col = subtable.headers.indexOf(this.label_column);
subtable.rows.forEach(function(row) {
data_x.push(string_to_date(row[x_col]));
data_y.push(row[y_col]);
})
var series = new Series(data_x, data_y, label);
series.y_axis = 'events';
return series;
}
}