-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_time.html
More file actions
90 lines (68 loc) · 1.73 KB
/
example_time.html
File metadata and controls
90 lines (68 loc) · 1.73 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<style>
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
.circle {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
</style>
<head>
<title>Test</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://d3js.org/d3-timer.v1.min.js"></script>
</head>
<body>
<!-- Page elements and content go here. -->
<body>
<script>
// Our D3 code will go here.
//var dat = [];
var dat = [0,1,2,3,4,5,6,7,8,9,10];
var dat2 = [10,10,10,10,10,10,10,10,10,10,10];
var w = 1000;
var h = 400;
var drawFlag = true
var frameRate = 500
var xMax = d3.max(dat, function(d) { return d;} );
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h)
.attr("style", "outline: thin solid black;");
var anim = d3.interval(function (elapsed) {if (drawFlag) {draw(elapsed);}},frameRate);
var points = svg.selectAll("circle")
.data(dat)
.enter()
.append("circle")
.attr("cx", function(d) {return (d/xMax)*w; })
.attr("cy", function(d) {return 50.;})
.attr("r", 4);
function draw(elapsed) {
// Take step in simulations
//dat.forEach(function(d) {
// d = d + Math.floor(Math.random() *h)});
for(var i=0;i<dat.length;i++){
dat[i]=dat[i] + (Math.random()-0.5)*50 ;
console.log(dat[i])
}
console.log(dat)
// update point data
points.data(dat);
// animate step
points
.transition()
.duration(frameRate)
.ease("linear")
.attr("cy", function(d) {return d;})
//.attr("r", function() {return Math.floor(Math.random() *40.);})
// console.log(Math.floor(Math.random() * 100));
}
</script>
</body>
</html>