[ Launch: Tributary inlet ] 4617523 by enjalot
[ Launch: Tributary inlet ] 4617513 by enjalot
-
-
Save enjalot/4617523 to your computer and use it in GitHub Desktop.
zoom and drag
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":"zoom and drag","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}},"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,"fullscreen":false,"thumbnail":"http://i.imgur.com/vtVA2FS.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 = tributary.test; | |
//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 | |
}) | |
//here we access tributary's supplied data | |
.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; | |
box.x = x + translate[0]; | |
box.y = y + translate[1]; | |
//rect.attr(box); | |
updateBox(); | |
}) | |
svg.call(zoom); | |
//this saves the current value of the box variable | |
//into the test.json file | |
//this causes everything to reexcute and thus | |
//rerender the box with those dimension | |
function updateBox() { | |
var cm = tributary.getCodeEditor("test.json") | |
cm.setValue(JSON.stringify(box)); | |
} |
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
{"x":337.50517770036964,"y":234.9301214344293,"width":145.36659866795839,"height":132.07087318003533} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment