-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTable.js
59 lines (46 loc) · 1.48 KB
/
Table.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
class Table {
constructor(state, setGlobalState) {
const columns = ["D Seats", "R Seats", "Efficiency Gap"];
this.table = d3.select("#table").append("table");
this.table
.append("thead")
.append("tr")
.selectAll("th")
.data(columns)
.join("th")
.text(d => d);
}
draw(state) {
const formatValue = d3.format(".3");
if (state.clickedData !== null) {
const selectData = [state.clickedData].map(d => ({
"D Seats": +d.D_seats,
"R Seats": 34 - +d.D_seats,
"Efficiency Gap": formatValue(d.eg),
}))
// this.table
// .selectAll("table.child")
// .data(selectData)
// .join(enter => enter
// // .append("tbody") //or should this be tr?
// .call(sel => sel.append("tr")
// .join("td")
// .text(d => Object.values(d))
// ),
// update => update,
// exit => exit.remove()
// );
this.tableRows = this.table
.append("tbody")
.selectAll("tr")
.data(selectData)
.join("tr")
this.tableRows
.selectAll("td")
.data(d => Object.values(d))
.join("td")
.text(d => d);
}
}
}
export { Table };