4
<title>Hello, sort!</title>
5
<script type="text/javascript" src="../../d3.v2.js"></script>
6
<style type="text/css">
9
font: 14px Helvetica Neue;
32
<input id="sort" type="checkbox" checked>
33
<label for="sort">Ascending</label>
35
<script type="text/javascript">
39
.attr("viewBox", "0 0 1000 1000");
46
function transform() {
47
var circle = d3.select("svg")
49
.data(d3.range(400).map(Math.random));
51
circle.enter().append("circle")
52
.attr("cx", function() { return 100 + Math.random() * 800; })
53
.attr("cy", function() { return 100 + Math.random() * 800; })
54
.attr("r", function(d) { return 50 * d; });
59
.attr("r", function(d) { return 50 * d; });
65
d3.selectAll("circle")
66
.sort(d3.select("#sort").property("checked")
67
? function(a, b) { return b - a; }
68
: function(a, b) { return a - b; });
71
window.addEventListener("keypress", transform, false);