-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoom.html
87 lines (75 loc) · 1.97 KB
/
zoom.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>
<meta charset="utf-8">
<title>d3</title>
</head>
<body>
<script src="js/d3.v3.min.js"></script>
<script src="js/jquery.js"></script>
<script>
var width = 400;
var height = 400;
var circles = [{
cx: 150,
cy: 200,
r: 30
}, {
cx: 250,
cy: 200,
r: 30
}, ];
// var zoom = d3.behavior.zoom()
// .scaleExtent([1, 10])
// .on("zoomstart", zoomStarted)
// .on("zoom", zoomed)
// .on("zoomend", zoomEnd)
var svg = d3.select("body").append("svg")
.attr("class", "svg-container")
.attr("width", width)
.attr("height", height);
var circles_group = svg.append("g")
// .call(zoom);
circles_group.selectAll("circle")
.data(circles)
.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", "black");
function zoomed() {
//
console.log('arguments', arguments)
console.log('d3.select(this)', d3.select(this))
d3.select(this).attr("transform",
"translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
function zoomClicked(translate, scale) {
// d3.select(".svg-container g").attr("transform", "translate(" + translate + ")scale(" + scale + ")");
d3.select(".svg-container g").attr("transform", "translate(" + translate + ")scale(" + scale + ")")
}
function zoomEnd() {
console.log('zoomEnd')
}
function zoomStarted() {
console.log('zoomStarted')
}
$(document).ready(function() {
$("#zoom").click(function() {
zoomClicked(2, 2)
});
});
</script>
<div id="svg-canvas"></div>
<button id="zoom">
Zoom
</button>
</body>
</html>