{"action":"created","issue":{"url":"https://api.github.com/repos/huei90/snap.svg.zpd/issues/23","labels_url":"https://api.github.com/repos/huei90/snap.svg.zpd/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/huei90/snap.svg.zpd/issues/23/comments","events_url":"https://api.github.com/repos/huei90/snap.svg.zpd/issues/23/events","html_url":"https://github.com/huei90/snap.svg.zpd/issues/23","id":50447792,"number":23,"title":"Zoom to bounding box","user":{"login":"jlgrall","id":1263537,"avatar_url":"https://avatars.githubusercontent.com/u/1263537?v=3","gravatar_id":"","url":"https://api.github.com/users/jlgrall","html_url":"https://github.com/jlgrall","followers_url":"https://api.github.com/users/jlgrall/followers","following_url":"https://api.github.com/users/jlgrall/following{/other_user}","gists_url":"https://api.github.com/users/jlgrall/gists{/gist_id}","starred_url":"https://api.github.com/users/jlgrall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlgrall/subscriptions","organizations_url":"https://api.github.com/users/jlgrall/orgs","repos_url":"https://api.github.com/users/jlgrall/repos","events_url":"https://api.github.com/users/jlgrall/events{/privacy}","received_events_url":"https://api.github.com/users/jlgrall/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/huei90/snap.svg.zpd/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-11-30T05:33:10Z","updated_at":"2015-01-19T07:26:49Z","closed_at":null,"body":"Here is a function to zoom to the bounding box of an element:\r\n```javascript\r\n// Inspired by https://gist.github.com/mbostock/4699541\r\nvar zoomToBBox = function(elem) {\r\n\t\tvar width = svg.node.clientWidth,\r\n\t\t\theight = svg.node.clientHeight,\r\n\t\t\tminScale = zpdElement.options.zoomThreshold[0],\r\n\t\t\tmaxScale = zpdElement.options.zoomThreshold[1],\r\n\t\t\tfilling = 0.9,\r\n\t\t\tbbox = elem.getBBox(),\r\n\t\t\tdx = bbox.x2 - bbox.x,\r\n\t\t\tdy = bbox.y2 - bbox.y,\r\n\t\t\tx = (bbox.x + bbox.x2) / 2,\r\n\t\t\ty = (bbox.y + bbox.y2) / 2,\r\n\t\t\trealScale = filling / Math.max(dx / width, dy / height),\r\n\t\t\tscale = Math.min(Math.max(realScale, minScale), maxScale),\r\n\t\t\ttranslateX = width / 2 - scale * x,\r\n\t\t\ttranslateY = height / 2 - scale * y,\r\n\t\t\tm = Snap.matrix(scale, 0, 0, scale, translateX, translateY);\r\n\t\tzpd.animate({ transform: m }, 400, mina.easeout);\r\n\t};\r\n```\r\nNotes:\r\n* filling = 0.9: the bounding box takes at most 90% of the screen.\r\n* doesn't account for undefined zoomThresholds."},"comment":{"url":"https://api.github.com/repos/huei90/snap.svg.zpd/issues/comments/70454856","html_url":"https://github.com/huei90/snap.svg.zpd/issues/23#issuecomment-70454856","issue_url":"https://api.github.com/repos/huei90/snap.svg.zpd/issues/23","id":70454856,"user":{"login":"huei90","id":2560096,"avatar_url":"https://avatars.githubusercontent.com/u/2560096?v=3","gravatar_id":"","url":"https://api.github.com/users/huei90","html_url":"https://github.com/huei90","followers_url":"https://api.github.com/users/huei90/followers","following_url":"https://api.github.com/users/huei90/following{/other_user}","gists_url":"https://api.github.com/users/huei90/gists{/gist_id}","starred_url":"https://api.github.com/users/huei90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huei90/subscriptions","organizations_url":"https://api.github.com/users/huei90/orgs","repos_url":"https://api.github.com/users/huei90/repos","events_url":"https://api.github.com/users/huei90/events{/privacy}","received_events_url":"https://api.github.com/users/huei90/received_events","type":"User","site_admin":false},"created_at":"2015-01-19T07:26:49Z","updated_at":"2015-01-19T07:26:49Z","body":"@jlgrall It doesn't work :cry: Would you mind see this again?"}}