-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_2.html
71 lines (49 loc) · 1.15 KB
/
js_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
68
69
70
71
---
layout: default
title: Java Script
---
<svg width="720" height="120">
</svg>
<button id="start">Click</button>
<script>
var dataArray = [
{"x": 40, "radius": 10, "color": "red"},
{"x": 80, "radius": 20, "color": "green"},
{"x": 120, "radius": 15, "color": "blue"},
{"x": 200, "radius": 20, "color": "yellow"}
];
dataArray2 = [
{"x": 40, "radius": 10, "color": "red"},
{"x": 120, "radius": 15, "color": "blue"},
];
function draw(data) {
var circle = d3.select("svg").selectAll("circle")
.data(data, function(d){
return d.color;
});
circle.enter().append("circle")
.attr("cy", 60)
.style("fill", function(d){
return d.color;
})
.attr("r", 0);
circle.transition().duration(1000)
.attr("r", function(datapoint){
return datapoint.radius;
})
.style("fill", function(d){
return d.color;
})
.attr("cx", function(d){
return d.x;
});
console.log("running");
circle.exit().transition().duration(1000)
.attr("r", 0).remove();
}
// draw(dataArray);
draw(dataArray);
d3.select("#start").on("click", function(){
draw(dataArray2);
});
</script>