-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path7-4.html
65 lines (65 loc) · 2.33 KB
/
7-4.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
55
56
57
58
59
60
61
62
63
64
65
<!doctype html>
<html>
<head>
<title>D3 tutorial</title>
<!--[if lte IE 8]><script src="r2d3.min.js" charset="utf-8"></script><![endif]-->
<!--[if gte IE 9]><!-->
<script src="http://d3js.org/d3.v3.min.js"></script>
<!--<![endif]-->
<script src="https://google-code-prettify.googlecode.com/svn/loader/prettify.js"></script>
<link href="https://google-code-prettify.googlecode.com/svn/loader/prettify.css" type="text/css" rel="stylesheet" />
</head>
<h3>Enter, Update, Exit, part4</h3>
<a href="index.html">Back to table of contents</a>
<body onload="prettyPrint()">
<pre class="prettyprint">
var data = [10];
var width = 500;
var height = 500;
var canvas = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var circle1 = canvas.append("circle")
.attr("cx", 50)
.attr("cy", 100)
.attr("r", 25);
var circle2 = canvas.append("circle")
.attr("cx", 100)
.attr("cy", 200)
.attr("r", 50);
// Exit example. (There are more dom elements than data elements)
// DOM elements > data elements (exit)
// two circles were selected but only one was bounded because only element in data
// notice the routine still passes through exit and colored circle blue.
var circle = canvas.selectAll("circle")
.data(data)
// update any existing circles selected and color those green.
.attr("fill", "green")
.exit()
.attr("fill", "blue");
</pre>
<script>
var data = [10];
var width = 500;
var height = 500;
var canvas = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var circle1 = canvas.append("circle")
.attr("cx", 50)
.attr("cy", 100)
.attr("r", 25);
var circle2 = canvas.append("circle")
.attr("cx", 100)
.attr("cy", 200)
.attr("r", 50);
var circle = canvas.selectAll("circle")
.data(data)
.attr("fill", "green")
.exit()
.attr("fill", "blue");
</script>
</body>
</html>