Skip to content

Instantly share code, notes, and snippets.

@fidothe
Last active December 16, 2015 04:39
Show Gist options
  • Save fidothe/5378483 to your computer and use it in GitHub Desktop.
Save fidothe/5378483 to your computer and use it in GitHub Desktop.
demonstrate d3.behavior.zoom tap-eating
<html>
<head>
<title>tap eating</title>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
svg.append('g').append('rect')
.attr('x', 200)
.attr('y', 200)
.attr('width', 100)
.attr('height', 100)
.attr('fill', 'black')
.on('click', function() {
var node = d3.select(this);
if (node.attr('fill') == 'black') {
node.attr('fill', 'red');
}
else {
node.attr('fill', 'black');
}
});
var g = d3.select('g');
var zoom = d3.behavior.zoom();
zoom.on('zoom', function() {
g.attr('transform', 'translate(' + d3.event.translate[0] + ',' + d3.event.translate[1] + ')');
})
svg.call(zoom)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment