Conversation
|
keeping as a draft since it's just a stepping stone for #2373 |
src/style.js
Outdated
| import {warn} from "./warnings.js"; | ||
|
|
||
| export const offset = (typeof window !== "undefined" ? window.devicePixelRatio > 1 : typeof it === "undefined") ? 0 : 0.5; // prettier-ignore | ||
| export const offset = 0; |
There was a problem hiding this comment.
This breaks a feature of Plot, though? This offset is used to have crisp rendering for lo-dpi screens. I’m okay with fixing the behavior in tests, but it seems wrong to remove this feature from production usage of Plot.
There was a problem hiding this comment.
Yes, but I'm doing it here only to get the tests right — the offset is restored in #2373, which is the "second part" of this PR (one to fix the snapshots, the other to swap the test framework).
(I could have spent more time to try and figure out how to fix the tests in mocha, but that would only have been to drop them immediately after.)
There was a problem hiding this comment.
We shouldn’t need to change the behavior in production in order to get the tests right; we can target the test environment. We can’t land this PR if it removes support for lo-dpi screens.
There was a problem hiding this comment.
I thought it might be complicated but in fact I can just use the new logic (which defaults offset to 0 when there is no window), to prepare the new snapshots.
And I've also applied your suggestion (as below), as a fly-by "consistency fix".
|
Your description says the “D3 axes have an offset of 0 (window is not defined when we load the module)”, but as I understand it, we only use d3-axis in exactly one place: We can (and should) use axis.offset to ensure that any use of d3-axis explicitly uses the same offset we use internally in Plot. |
…anslation we apply on lower DPI screens
… Plot internally, rather than d3-axis's own window.devicePixelRatio detection
|
I see several decomposable pieces here:
I’ve implemented (1) and (2) in #2376 which is a tiny +10 -2 PR. I’m torn on whether we should do (3). On the one hand, this would mean we are testing the common case rather than the edge case. But the no-offset case is simpler, and I’d still want to have some tests somewhere for the offset case. So I’m tempted to continue testing the 0.5 offset even if it’s the uncommon case… ideally we have both? In theory that should be possible using the new We should do (4) independently of any code changes, since it will cause a massive diff. We should do (5) independently of any (other) snapshot changes, so that we can review what changed. |
|
I’ve now broken (5) out into #2377 so we can review the isolated changes. |
Context:
The diff for #2373 was hard to read initially because a lot of changes stem from the fact that the axis offsets are removed.
To get deep in the woods: our snapshots in main, still using mocha, are in fact inconsistent. The D3 axes have an offset of 0 (
windowis not defined when we load the module), whereas other elements in Plot use an offset of 0.5 (the fakeglobal.windowhas been defined).This branch adds devicePixelRatio = 2 to
global.window, and hard-codesoffset = 0so that the snapshots are now consistently using an offset 0 both in d3-axis and in Plot 😅Lots of diff, but easy to grep … the only changes (ideally) are in the Plot axes translate property, for instance:
However! when we actually regenerate the snapshots, we also get the updated "3 digits after decimal dot" precision change which we had never pushed, so we'll have to put a bit more effort into verifying the diff.
And also! By changing the offset, we modify some scales, and the hexbin/hexgrid coordinates change too, resulting in sometimes strikingly different images. So we have to fix that issue (which in my book is a bug: the fact that we render on a low DPI screen should not change the binning), and make hexbin independent of the offset.
So overall the changes to the snapshots fall into several categories. It's a lot to review manually, but a script can make this easier:
Details
Results: