forked from Flave/Isoscope-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd3-test.html
87 lines (70 loc) · 1.34 KB
/
d3-test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<style>
span {
opacity: .5;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="node_modules/d3/d3.js"></script>
<script type="text/javascript">
var data = [
[
[1,2,3],
[5,6,7]
],
[
[1,2,3],
[5,6,7,8]
]
];
var counter = 0;
function update() {
var container = d3.select('#container');
// DATA lvl1
var lvl1 = container
.selectAll('div.lvl1')
.data(data[counter % 2]);
// ENTER lvl1
lvl1
.enter()
.append('div')
.classed('lvl1', true);
// UPDATE lvl1
lvl1
.text(' --> lvl1 ' + counter)
lvl1
.append('b')
.text('bla');
lvl1
.exit()
.remove();
// DATA lvl2
var lvl2 = lvl1
.selectAll('span.lvl2')
.data(function(d) { return d; });
// ENTER lvl2
lvl2
.enter()
.append('span')
.classed('lvl2', true);
// UPDATE lvl2
lvl2
.text(' -> lvl2 ' + counter);
lvl2
.exit()
.remove();
}
update();
document.addEventListener('click', function() {
counter++;
update();
})
</script>
</body>
</html>