-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathEDAV5_2.html
executable file
·67 lines (47 loc) · 1.39 KB
/
EDAV5_2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EDAV5_2</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script id="s1">
// Create svg and initial bars
var svg = d3.select("body")
.append("svg")
.attr("width", "500")
.attr("height", "400");
var bardata = [300, 100, 150, 225, 75, 275];
var bars = svg.selectAll("rect")
.data(bardata);
bars.enter().append("rect")
.attr("x", (d, i) => 50*i + 50) // CHANGE
.attr("y", d => 400 - d) // CHANGE
.attr("width", "35") // CHANGE
.attr("height", d => d) // CHANGE
.attr("fill", "lightgreen");
// General Update Pattern
function update(data) {
var bars = svg.selectAll("rect")
.data(data);
bars.enter().append("rect")
.attr("x", (d, i) => 50*i + 50) // CHANGE
.attr("y", d => 400 - d) // CHANGE
.attr("width", "35") // CHANGE
.attr("height", d => d) // CHANGE
.attr("fill", "yellow")
.merge(bars)
.transition()
.duration(2000)
.attr("y", d => 400 - d) // CHANGE
.attr("height", d => d) // CHANGE
.attr("fill", "orange");
bars.exit().remove();
};
// Add add / remove buttons
</script>
<p id="add"></p>
<p id="remove"></p>
</body>
</html>