I created a graph using D3 v4 that allows x-axis panning and zooming. I'm updating the graph differently when panning and zooming in order to decrease the amount of times we regenerate the graph.
As For Panning
When the user pans left or right i simply update the transform attribute as such:
path.attr("transform", d3.event.transform).
It works well.
As For Zooming
I rescale the domain and re-generate the graph when the user zooms in order to achieve the desired behavior as such:
t = d3.event.transform;
xScale.domain(t.rescaleX(x2).domain()); //update xScale domain
xAxis =d3.axisBottom(xScale)...
focus.select(".axis--x").call(xAxis);
usageAreaPath.attr("d", area); //area being a reference to the generator
usageLinePath.attr('d',line); //line being the name of the generator
The problem is, performing a pan after zoom or zoom after pan results in the graph jumping to different zoom levels. I'm not sure what I'm doing wrong, or how to rebind the scale after zooming/panning to update the proper scale, but I have attached a JSBIN below:
.on("zoom", redraw);. - Gerardo FurtadousageAreaPath.attr("transform", d3.event.transform);but if there is a zoom then, I'd like to use the redraw contents. i.e.usageAreaPath.attr("d", area); usageLinePath.attr('d',line);- Abdullah Rasheed