Skip to content

Instantly share code, notes, and snippets.

@DeBraid
Created February 19, 2014 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeBraid/9095081 to your computer and use it in GitHub Desktop.
Save DeBraid/9095081 to your computer and use it in GitHub Desktop.
simple zoom
{"description":"simple zoom","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
var w = 1200,
h = 500,
x = d3.time.scale().range([0, w]),
xAxis = d3.svg.axis().scale(x).orient("bottom").tickSize(-h, 0).tickPadding(6);
var svg = d3.select("svg")
.attr("width", w)
.attr("height", h+50)
.append("svg:g");
svg.append("svg:g")
.attr("class", "x axis")
.attr("transform", "translate(0," + h + ")");
svg.append("svg:rect")
.attr("class", "pane")
.attr("width", w)
.attr("height", h)
.call(d3.behavior.zoom().on("zoom", zoom));
x.domain([new Date(1999, 0, 1), new Date(2014, 0, 0)]);
draw();
function draw() {
console.log ("drawing");
svg.select("g.x.axis").call(xAxis);
}
function zoom() {
console.log("zooming");
d3.event.transform(x); // TODO d3.behavior.zoom should support extents
draw();
}
svg {
font-size: 10px;
fill: red;
}
g {
overflow: visible;
stroke: green;
}
text {
z-index: 20;
}
rect.pane {
cursor: move;
fill: none;
pointer-events: all;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment