-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebt-ma.js
65 lines (55 loc) · 1.74 KB
/
ebt-ma.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
$(document).ready(function() {
d3.csv("MA.csv", function(data) {
window.data = data;
console.log(data);
//the columns that we'd like to display
var columns = ['Store_Name', 'Address', 'City', 'County', 'State'];
//add data to the html
d3.select("#number-of-retail").html(data.length);
var results = d3.select("#results").html(null),
table = results.append("table")
.attr("class", "tblResults")
.attr("class", "table"),
thead = table.append("thead"),
tbody = table.append("tbody");
// append the header row
thead.append("tr")
.selectAll("th")
.data(columns)
.enter()
.append("th")
.text(function(column) { return column; })
.on("click", function(d){
d3.select('#results table tbody')
.selectAll('tr').sort(function(a, b){
if (ascending)
return d3.ascending(a[d], b[d]);
else
return d3.descending(a[d], b[d]);
});
//flip the bit:
ascending = !ascending;
}
);
//append some data
//initialize ascending as true
var ascending = true;
//add sort icon to the list
d3.selectAll('#results table tr th').append('span').html(' <i class="fa fa-sort"></i>')
// create a row for each object in the data
var rows = tbody.selectAll("tr")
.data(data)
.enter()
.append("tr");
// create a cell in each row for each column
var cells = rows.selectAll("td")
.data(function(row) {
return columns.map(function(column) {
return {column: column, value: row[column]};
});
})
.enter()
.append("td")
.text(function(d) { return d.value; });
});
});