PAIR-code / megaplot

Apache License 2.0
19 stars 5 forks source link

Fix resize drift bug, may depend on devicePixelRatio #62

Open jimbojw opened 2 years ago

jimbojw commented 2 years ago

The Scene's resize() method allows the caller to recompute the offset and the underlying canvas element's dimensions after the canvas DOM size has been changed. If resize() is not called, then the canvas element's dimensions will often have a different aspect ratio from the DOM size and cause the rendered visualization to appear stretched or squished.

The resize() method takes an optional fixed canvas point. This point specifies the pixel location to keep fixed after the aspect ratio transformation. By default, the fixed canvas point used will be the center point of the canvas. Using scene.offset as the fixed point should have the effect of preserving the location of the world origin (0,0).

There is a bug where one or both of the offset components may be a pixel off after the resize(). If calls to resize() are repeated, this can cause the offset to creep in one direction or the other. This seems to occur more readily when the devicePixelRatio is 1.

Develop an example which consistently produces this behavior, then fix it.