Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. var x0 = d3.scale.linear().domain(…).range(…), // initial scale
  2. x = x0.copy(); // copy to use for axes and zoom behaviour
  3.  
  4. setInterval(function() {
  5. var translate = zoom.translate(),
  6. scale = zoom.scale(),
  7. xd = x0.domain(),
  8. dx = 1;
  9.  
  10. // Set a new x-domain: offset by dx.
  11. x0.domain([xd[0] += dx, xd[1] += dx]);
  12.  
  13. // Set the zoom x-domain (this resets the domain at zoom scale=1).
  14. zoom.x(x.domain(xd));
  15.  
  16. // Reset the domain relative to the current zoom offsets.
  17. x.domain(x0.range().map(function(x) {
  18. return (x - translate[0]) / scale;
  19. }).map(x0.invert));
  20. }, 1e3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement