-
Notifications
You must be signed in to change notification settings - Fork 1
/
enupex.js
60 lines (54 loc) · 1.56 KB
/
enupex.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
var main = d3.select('svg')
var height = main.attr("height");
var width = main.attr("width");
//Function that works on real data
function printD(data){
//console.log(data)
main.selectAll("circle")
.data(data)
.join("circle")
.transition()
.duration(1000)
.attr("cx", (d ,i) => i * 10)
.attr("cy", d => height - +d.lynx_trapped / 100)
.attr('r', 5)
main.selectAll('text').remove()
main.append('g')
.selectAll('text')
.data(data)
.join('text')
.attr('transform', `translate(200,10)`)
.attr('y', (d, i) => i * 15)
.text(d => `${d.Year} , ${d.lynx_trapped}`)
}
const realPop = () =>{
console.log('recieved')
d3.csv('Lynx_trapped.csv').then((d)=>{
printD(d.slice(0,20));
});
}
var realB = document.getElementById("real")
realB.addEventListener('click',realPop)
//Fuction that works on random data
const ranPop = () =>{
var ranData = d3.range(50).map(d =>({
x: Math.round(150 * Math.random()),
y: Math.round(150 * Math.random())
}))
main.selectAll("circle")
.data(ranData)
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr('r', 5)
main.selectAll('text').remove()
main.append('g')
.selectAll('text')
.data(ranData)
.join("text")
.attr('transform', `translate(200,10)`)
.attr('y', (d, i) => i * 15)
.text(d => `${d.x}, ${d.y}`)
}
var ranB = document.getElementById('random');
ranB.addEventListener('click',ranPop)