I have a multiline graph. The zooming is working fine except that when I zoom in, the lines get out of the graph and I want to fix that. Also, I don't know why the dates on my xAxis stay static and doesn't change respectively when I zoom in.
My code for the brush and zoom functions:
function brushed() {
if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") return;
var s = d3.event.selection || x2.range();
x.domain(s.map(x2.invert, x2));
plot.selectAll(".line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); });
plot.select(".axis--x").call(xAxis);
svg.select(".zoom").call(zoom.transform, d3.zoomIdentity
.scale(width / (s[1] - s[0]))
.translate(-s[0], 0));
}
function zoomed() {
if (d3.event.sourceEvent && d3.event.sourceEvent.type === "brush") return;
var t = d3.event.transform;
x.domain(t.rescaleX(x2).domain());
plot.selectAll(".line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); });
plot.select(".axis--x").call(xAxis);
slider.select(".brush").call(brush.move, x.range().map(t.invertX, t));
}
An image of my graph:
You can see the lines that get out of the graph.
[Edit]
Here's a plunker with my whole code.
Thank you in advance.