Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: gh-pages
@vogievetsky
54 lines (43 sloc) 1.147 kB
<!DOCTYPE html>
<html>
<head>
<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>
Jump to Line
Something went wrong with that request. Please try again.