2010-09-28 22:34:52 +04:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Hello, data!</title>
|
Simplify data join. Add insert & empty.
The data join is now specified as a single function of data, as with all other
properties. This allows the key to be computed on the previously-bound data,
rather than requiring the key to be serialized into the DOM (say, as an
attribute). In the case that there is no previously-bound data, it is still
possible to access the associated node as the `this` context.
The `enter` operator no longer performs an append. For symmetry with the `exit`
operator, you must call `append` after obtaining the entering selection. This
requires a tiny bit more code, but should make the code more clear. Also, it
provides an opportunity to use a different instantiation operator, such as the
new `insert` operator. This takes a second argument, which is a selector for the
insert-before reference element. For example, the selector ":first-child" will
prepend nodes.
The `empty` operator allows you to query whether a selection is empty (i.e.,
contains zero matching nodes).
2011-01-31 22:00:35 +03:00
|
|
|
<script type="text/javascript" src="../../d3.js"></script>
|
2010-09-28 22:34:52 +04:00
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
body {
|
|
|
|
font: 14px Helvetica Neue;
|
|
|
|
text-rendering: optimizeLegibility;
|
|
|
|
margin: 1em;
|
|
|
|
}
|
|
|
|
|
|
|
|
#cells {
|
|
|
|
position: relative;
|
|
|
|
margin-top: .5em;
|
|
|
|
height: 300px;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.cell {
|
|
|
|
position: absolute;
|
|
|
|
background: steelblue;
|
|
|
|
color: white;
|
|
|
|
width: 28px;
|
|
|
|
text-align: center;
|
|
|
|
padding-top: 6px;
|
|
|
|
top: 300px;
|
|
|
|
bottom: 0;
|
|
|
|
background: -webkit-gradient(linear, left top, left bottom, from(transparent), to(steelblue));
|
|
|
|
-webkit-transition-property: top, background-color;
|
|
|
|
-webkit-transition-duration: 500ms;
|
|
|
|
-webkit-transition-timing-function: ease, linear;
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Your lucky numbers are:<br>
|
|
|
|
<div id="cells"></div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var n = 10;
|
|
|
|
|
|
|
|
d3.select("#cells")
|
|
|
|
.selectAll("div")
|
2010-10-24 22:43:32 +04:00
|
|
|
.data(d3.range(n))
|
Simplify data join. Add insert & empty.
The data join is now specified as a single function of data, as with all other
properties. This allows the key to be computed on the previously-bound data,
rather than requiring the key to be serialized into the DOM (say, as an
attribute). In the case that there is no previously-bound data, it is still
possible to access the associated node as the `this` context.
The `enter` operator no longer performs an append. For symmetry with the `exit`
operator, you must call `append` after obtaining the entering selection. This
requires a tiny bit more code, but should make the code more clear. Also, it
provides an opportunity to use a different instantiation operator, such as the
new `insert` operator. This takes a second argument, which is a selector for the
insert-before reference element. For example, the selector ":first-child" will
prepend nodes.
The `empty` operator allows you to query whether a selection is empty (i.e.,
contains zero matching nodes).
2011-01-31 22:00:35 +03:00
|
|
|
.enter().append("div")
|
2010-09-28 22:34:52 +04:00
|
|
|
.attr("class", "cell")
|
2010-10-24 22:43:32 +04:00
|
|
|
.style("left", function(i) { return i * 30; });
|
|
|
|
|
|
|
|
function transform() {
|
|
|
|
d3.selectAll(".cell")
|
|
|
|
.data(d3.range(n).map(Math.random))
|
|
|
|
.style("top", function(d) { return (1 - d) * 300; })
|
|
|
|
.style("background-color", function(d) { return "rgb(" + ~~(d * 255) + ",50,100)"; })
|
|
|
|
.text(function(d) { return ~~(d * 100); });
|
2010-09-28 22:34:52 +04:00
|
|
|
}
|
|
|
|
|
2010-10-24 22:43:32 +04:00
|
|
|
window.addEventListener("keypress", transform, false);
|
|
|
|
|
2010-09-28 22:34:52 +04:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|