-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_script.html
78 lines (67 loc) · 2.16 KB
/
test_script.html
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
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title> Oklahoma college costs </title>
</head>
<body>
<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<script>
// set the dimensions and margins of the graph
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 460 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
// append the svg object to the body of the page
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
//Read the data
d3.csv("https://github.com/dnajera27/cs498-final/blob/master/test_dataset.csv", function(data) {
// Add X axis
var x = d3.scaleLinear()
.domain([0, 1])
.range([ 0, width ]);
svg.append("g")
.attr("class", "myXaxis") // Note that here we give a class to the X axis, to be able to call it later and modify it
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.attr("opacity", "0")
// Add Y axis
var y = d3.scaleLinear()
.domain([0, 1])
.range([ height, 0]);
svg.append("g")
.call(d3.axisLeft(y));
// Add dots
svg.append('g')
.selectAll("dot")
.data(data)
.enter()
.append("circle")
.attr("cx", function (d) { return x(d.x); } )
.attr("cy", function (d) { return y(d.y); } )
.attr("r", 1.5)
.style("fill", "#69b3a2")
// new X axis
x.domain([0, 4000])
svg.select(".myXaxis")
.transition()
.duration(2000)
.attr("opacity", "1")
.call(d3.axisBottom(x));
svg.selectAll("circle")
.transition()
.delay(function(d,i){return(d.t)})
.duration(2000)
.attr("cx", function (d) { return x(d.x); } )
.attr("cy", function (d) { return y(d.y); } )
})
</script>
</body>