I have a force layout with a zooming behavior.
var min_zoom = 0.3;
var max_zoom = 3;
var zoom = d3.behavior.zoom().scaleExtent([min_zoom,max_zoom]);
Before form submission, zooming (using the mouse wheel) and translation work just fine just as expected.
svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")" );
To this end, life is good.
When the form is submitted, the current translate
and scale
values are saved to the session. As an example, say that the current scale
is 2
. After the submission of the form and loading the page again, the saved scale
is applied, restoring the zoom to its state before submission.
However, after this loading of the page, the value for d3.event.scale
is set again to its initial value (I guess it is 1
). Hence, trying to perform an in or out zoom again (using mouse wheel) applies the scale factor to the initial base value of the zoom (supposedly 1
for d3.event.scale
), instead of using the values saved from the session 2
, and will make a sudden, unexpected change of the zoom.
PS. Trying to manually assign a value to d3.event.scale
doesn't work! I think the most straightforward workaround would be altering d3.event.scale
in case that's possible. Otherwise, manually controlling the zoom seems an exhaustive and non-intuitive option to take.