-
Notifications
You must be signed in to change notification settings - Fork 59
/
example_sort.html
54 lines (44 loc) · 1.15 KB
/
example_sort.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Sorting</title>
<script type="text/javascript" src="d3/d3.v3.js"></script>
<style type="text/css">
body {
padding: 100px;
}
svg {
border: 1px solid black;
}
rect {
fill: steelblue;
}
</style>
</head>
<body>
<button onclick="go()">GO</button><br/>
</body>
<script type="text/javascript">
var svg = d3.select('body')
.append('svg:svg')
.attr('width', 400)
.attr('height', 400)
var data = d3.range(20).map(Math.random)
svg.selectAll('rect').data(data)
.enter().append('svg:rect')
.attr('width', 10)
.attr('height', function(d) { return d*400; })
.attr('x', function(d, i) { return i * 20 + 5; })
.attr('y', function(d) { return 400 - d*400; })
var go = function() {
data.sort(function(a,b) { return a-b; })
svg.selectAll('rect')
.data(data, function(d) { return d; })
.transition()
.duration(500)
.delay(function(d, i) { return i * 50; })
.attr('x', function(d, i) { return i * 20 + 5; })
}
</script>
</html>