-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselection.js
70 lines (60 loc) · 1.55 KB
/
selection.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
//Lets bring the data in as seperate divs
d3.csv('Lynx_trapped.csv').then((d)=>{
printD(d);
printS(d.slice(0, 10));
makeTable(d.slice(0,10));
})
function printD(data){
//console.log(data)
d3.select("body")
.selectAll("div.trouble")
.data(data.slice(0,10))
.enter()
.append("div")
.attr("class","trouble")
.html(d => d.Year)
}
//How about bring the text onto the svg element?
function printS(data){
d3.select('svg')
.selectAll('text')
.data(data)
.join('text')
.text(d => `In ${d.Year} ${d.lynx_trapped} were trapped`)
.attr('x',25)
.attr('y', (d, i) => i * 20)
}
function makeTable(data){
var myTable = d3.select('body')
.append('div')
.attr('class','tbl')
.append('table')
.selectAll('tr')
.data(data)
.enter()
.append('tr')
myTable.append('td')
.text(d => d.Year)
// myTable.selectAll('tr')
// .data(data)
myTable.append('td')
.text(d => d.lynx_trapped)
}
//How about populating a table?
var main = d3.select('svg')
var height = main.attr("height");
var width = main.attr("width");
// main.append('p')
// .html(`${height + width}`)
//simple append and show, easy.
d3.select('body')
.append('p')
.text(`${height + width}`)
//doing the same at the click of the button, and it works
var clik = d3.select('button')
.on('click',show)
function show(){
d3.select('body')
.append('p')
.text(`${height + width}`)
}