All examples By author By category About

NJRBailey

Zoom offset bug when resizing window

(To observe bug, make sure to open the block in its own window).

A pretty barebones, mostly unstyled block, used to demonstrate the zoom bug that occurs upon resize (as described here).

This chart is a timeline-style chart, with a time (continuous) scale for the x-axis and a band scale for the y-axis. The chart always fills the width of the window. The bug behaviour is described below:

Bug description

What is happening

We have a chart with a d3.scaleTime as the x-axis, and a d3.scaleBand as the y-axis. We only zoom and pan on the x-axis. When we zoom or pan the chart, there is a 1:1 movement with the mouse cursor. When the window is resized horizontally, the x-axis range is recalculated, so that the chart will shrink or expand to fill the space - however, this results in the zoom and panning having an offset (the mouse moves a longer or shorter distance than the chart, and the zoom will focus in on a point to the left or right of the mouse cursor).

What should be happening

The zoom should stay 1:1 with the mouse (move the same distance, zoom in on the mouse position) after window resize.

How to reproduce

  1. Load block in its own window.
  2. Resize the window - the bug will be more obvious with a larger resize.
  3. Try to zoom on a point - you will see that the chart zooms towards a different point than the mouse is currently at. Also, if you pan the chart, you will see that the chart is moving faster or slower than the mouse cursor (try comparing with one of the axis ticks for reference).

Built with blockbuilder.org