-
Notifications
You must be signed in to change notification settings - Fork 0
/
D3_14.html
38 lines (34 loc) · 1.11 KB
/
D3_14.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./D3.js" charset="utf-8"></script>
</head>
<body>
</body>
<script charset="utf-8">
var width = 500;
var height = 500;
var svg = d3.select('body').append('svg').attr('width',width).attr('height',height);
var data = [ { cx: 150, cy: 200, r: 30 }, { cx: 250, cy: 200, r: 30 }];
var drag = d3.drag().subject(function(d,i){
return {x:d.cx,y:d.cy};
}).on('start',function(){
console.log('dragstart');
}).on('end',function(){
console.log('dragend')
}).on('drag',function(d){
d3.select(this).attr('cx',d.cx = d3.event.x);
d3.select(this).attr('cy',d.cy = d3.event.y);
});
svg.selectAll('circle').data(data).enter().append('circle')
.attr('cx',function(d){return d.cx;})
.attr('cy',function(d){return d.cy;})
.attr('r',function(d){return d.r;})
.attr('fill','orange')
.call(drag);
</script>
</html>