I'm looking to plot a set of boxes (over time, like a stock chart) but am having trouble getting them to zoom in/out along with the grid.
Im working off this example and trying to achieve the same effect of how the line on the chart zooms along with the grid. My code for plotting the boxes resides in the update()
method (same place the line and circles are updated in the example)
SimpleGraph.prototype.update = function () {
var self = this;
self.vis.selectAll("rect")
.data(data.boxes)
.enter().append("svg:rect")
.attr("x", function(box) { return self.x(box.StartTimeStamp); })
.attr("y", function(box) { return self.y(box.Top); })
.attr("height", function(box) { return self.y(box.Bottom) - self.y(box.Top); })
.attr("width", function(box) { return self.x(box.StartTimeStamp + 5*60000) - self.x(box.StartTimeStamp); });
}
Here are my scales:
self.x = d3.time.scale()
.domain(d3.extent(data.boxes, function(box) { return box.StartTimeStamp]; }))
.range([0, self.innerWidth]);
self.y = d3.scale.linear() //inverted domain
.domain([d3.max(data.boxes.map(function (box) { return box.Top; })),
d3.min(data.boxes.map(function (box) { return box.Bottom]; }))])
.nice().range([0, self.innerHeight]).nice();
Other than the scales my code is mostly identical. The result is that the grid zooms accordingly but my boxes stay fixed. I've been playing around with setting the x,y,width,height on the boxes but I can't seem to get the calculation right.
Edit: Here's picture of result with a lot of data