아래 코드를 버전 4에서 업데이트하면 도움이 될 것입니다. zoom.behaviour를 d3.zoom으로 변경했는데 필요한 다른 변경 사항이 명확하지 않습니다. v3보다 복잡해 보입니다!d3 확대/축소 버전 4로 업그레이드
.call(d3.zoom().on("zoom", function() {
svg.attr("transform", "translate(" + d3.event.translate
+ ")" + " scale(" + d3.event.scale + ")")
}))
이 사람 :이
<!DOCTYPE html>
<html>
<head>
<!-- <script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>-->
<script data-require="[email protected]" data-semver="4.0.0" src="https://d3js.org/d3.v4.min.js"></script>
<style type="text/css">
body, html {
width: 100%;
height: 100%;
margin: 0;
}
svg {
position: absolute;
top: 0;
left: 0;
}
p {
text-align: center;
}
</style>
</head>
<body>
<p>Use the mouse to pan (click and move)/zoom (scrollwheel)</p>
</body>
<script type="text/javascript">
var svg = d3.select("body")
.append("svg")
.attr("width", "100%")
.attr("height", "100%")
.call(d3.zoom().on("zoom", function() {
svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")")
}))
.append("g")
svg.append("circle")
.attr("cx", document.body.clientWidth/2)
.attr("cy", document.body.clientHeight/2)
.attr("r", 50)
.style("fill", "#B8DEE6")
</script>
</html>
입니다 대단히 감사합니다. x 축 만 확대 할 수 있는지 알고 있습니까? 이전에 나는 zoom = d3.zoom.transform() .x (xRange) //.y(yy) – user3359706
을 사용했습니다. 이것은 SVG에서 뷰 박스를 사용하고 있는데, 그것은 깨지기 쉬운 것 같습니다. – SumNeuron