Skip to content

fix hex offset (how?)#2377

Draft
mbostock wants to merge 1 commit intombostock/simpler-offsetfrom
mbostock/fix-hex-offset
Draft

fix hex offset (how?)#2377
mbostock wants to merge 1 commit intombostock/simpler-offsetfrom
mbostock/fix-hex-offset

Conversation

@mbostock
Copy link
Member

@mbostock mbostock commented Mar 7, 2026

Per @Fil: we want the same image independently of the slight translation we apply on lower DPI screens

@mbostock mbostock requested a review from Fil March 7, 2026 18:29
@mbostock mbostock changed the title fix offset bug; we want the same image independently of the slight translation we apply on lower DPI screens fix hex offset Mar 7, 2026
@mbostock mbostock changed the title fix hex offset remove hex offset Mar 7, 2026
Copy link
Member Author

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description and the code feel inconsistent: the description says “we want the same image independently of the slight translation we apply on lower DPI screens” which I interpret to mean that the hexbin transform should not consider the offset, but the code changes seem to do the opposite — now the hexbin transform depends on the offset.

Also, the hexgrid mark now in effect applies the opposite offset (negative rather than positive), which means that the hexgrid won’t line up with a dot mark or line mark.

Can you elaborate on what we are trying to fix here? I’m not following, sorry.

@mbostock mbostock marked this pull request as draft March 7, 2026 18:38
@mbostock mbostock changed the title remove hex offset fix hex offset (how?) Mar 7, 2026
@mbostock
Copy link
Member Author

mbostock commented Mar 7, 2026

Here’s a notebook that demonstrates the inconsistency. We need Plot.dot to be consistent with Plot.hexgrid because the two are often used together, and more generally we want all marks to be positioned consistently.

The test code is:

Plot.plot({
  width: 640,
  height: 400,
  x: { type: "identity" },
  y: { type: "identity" },
  marks: [
    Plot.frame(),
    Plot.dot(
      d3.cross(d3.ticks(0, 640, 40), d3.ticks(0, 400, 40)),
      Plot.hexbin(
        {},
        {
          r: r,
          binWidth: r * 2,
          stroke: "magenta",
          strokeWidth: 3,
          clip: true
        }
      )
    ),
    Plot.hexgrid({
      binWidth: r * 2,
      stroke: "cyan",
      strokeWidth: 1.5,
      strokeOpacity: 1
    })
  ]
})

Here is the desired behavior from main:

untitled - 2026-03-07T110328 348

And here is the behavior in this branch (note the shift between cyan and magenta):

untitled - 2026-03-07T110407 984

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant