-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlive-code.html
71 lines (64 loc) · 1.84 KB
/
live-code.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
div {
height:0px;
width:0px;
margin: 2px;
background-color: gold;
}
</style>
</head>
<body>
<button onclick= "refreshChart()"> push me </button>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="data.js" charset="utf-8"></script>
<script type="text/javascript">
var data = dataFromOtherFile;
// console.log(data);
d3.select("body").selectAll(".bars")
.data(data)
.enter()
.append("div")
.classed("bars", true)
.transition()
.duration(2000)
.style("height", "15px")
.style("width", "100px")
.style("background-color", function(d,i){
return d3.rgb(i*50%255, 150, 150);
})
.style("transform", function(d, i){
return "translate(0px,0px)"
});
function refreshChart(){
data = data.map(function(x){
return x +Math.random()*100-50;
})
var color = d3.scale.linear()
.domain([0,1])
.range(["red","green"]);
var maxLength = data.reduce(function(prev, cur){return Math.max(prev, cur)},0);
console.log(maxLength);
d3.select("body").selectAll("div")
.data(data)
.transition()
.duration(2000)
//.style("height", "15px")
.style("width", function(dataElem, index){
// console.log(dataElem);
return dataElem + "px";
})
.style("background-color", function(d,i){
return color(d/maxLength);
})
// .style("transform", function(d, i){
// return "rotate(" + Math.random()*360 + "deg)translate("+d * d * Math.random()+"px,"+i*200%7+"px)";
// })
}
</script>
</body>
</html>