[ Launch: limit zoom ] 5148348 by enjalot
[ Launch: Tributary inlet ] 4617523 by enjalot
[ Launch: Tributary inlet ] 4617513 by enjalot
-
-
Save enjalot/5148348 to your computer and use it in GitHub Desktop.
limit zoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"limit zoom","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"test.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/oaqk8dt.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select("svg"); | |
var box = { | |
x: 200, | |
y: 200, | |
width: 200, | |
height: 200 | |
}; | |
//cache the values as starting points; | |
var x = box.x; | |
var y = box.y; | |
var bwidth = box.width; | |
var bheight = box.height; | |
var rect = svg.append("rect") | |
.attr({ | |
fill:"#A6E6E9", | |
"fill-opacity": 0.5, | |
stroke: "#1F2D92", | |
"stroke-width":3, | |
rx: 5 | |
}) | |
.attr(box) | |
var zoom = d3.behavior.zoom() | |
.on("zoom", function() { | |
var translate = d3.event.translate; | |
var scale = d3.event.scale; | |
svg.select("text").text(translate + " " + scale) | |
box.width = scale * bwidth; | |
box.height = scale * bheight; | |
//limit x in left direction | |
var newx = x + translate[0]; | |
if(newx < 100) { | |
newx = 100; | |
zoom.translate([0, 0]) | |
} | |
box.x = newx; | |
box.y = y + translate[1]; | |
rect.attr(box); | |
}) | |
svg.call(zoom); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment