2011-05-02 03:15:09 +04:00
|
|
|
<!DOCTYPE html>
|
2010-09-28 22:34:52 +04:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Hello, world!</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
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Your lucky numbers are:<br>
|
|
|
|
<span></span>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var data = [4, 8, 15, 16, 23, 42];
|
|
|
|
|
|
|
|
d3.select("span")
|
|
|
|
.selectAll("svg")
|
|
|
|
.data(data)
|
2011-11-24 02:46:37 +04:00
|
|
|
.enter().append("svg")
|
2010-09-28 22:34:52 +04:00
|
|
|
.attr("width", 100)
|
|
|
|
.attr("height", 100)
|
2011-11-24 02:46:37 +04:00
|
|
|
.append("text")
|
2010-09-28 22:34:52 +04:00
|
|
|
.attr("x", "50%")
|
|
|
|
.attr("y", "50%")
|
|
|
|
.attr("dy", ".35em")
|
|
|
|
.attr("text-anchor", "middle")
|
|
|
|
.attr("fill", "white")
|
|
|
|
.attr("stroke", "black")
|
|
|
|
.attr("stroke-width", 1.5)
|
|
|
|
.attr("cursor", "pointer")
|
|
|
|
.style("font", "36pt Comic Sans MS")
|
|
|
|
.style("text-shadow", "3px 3px 3px rgba(0,0,0,.4)")
|
|
|
|
.text(function(d) { return d; })
|
2010-10-24 21:56:29 +04:00
|
|
|
.on("click", click)
|
|
|
|
.on("mouseover", mouseover)
|
|
|
|
.on("mouseout", mouseout);
|
|
|
|
|
|
|
|
function click(d, i) {
|
|
|
|
console.log("click", d, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseover(d, i) {
|
|
|
|
d3.select(this)
|
|
|
|
.attr("fill", "brown")
|
|
|
|
.attr("stroke", "grey");
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseout(d, i) {
|
|
|
|
d3.select(this)
|
|
|
|
.attr("fill", "orange");
|
|
|
|
}
|
2010-09-28 22:34:52 +04:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|