question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve mark vs. axis alignment offset.

See original GitHub issue

When I display the following spec:

{
    "encoding": {
        "x": {
            "field": "a",
            "type": "quantitative"
        },
        "y": {
            "field": "b",
            "type": "quantitative"
        }
    },
    "data": {
        "values": [
            {
                "b": 2,
                "a": 2
            },
            {
                "b": 1,
                "a": 1
            }
        ]
    },
    "mark": "point"
}

And then zoom into it, I see that the point isn’t really centered on the grid lines:

image

is a zoomed version of the middle point.

I’m using the SVG renderer, and then of course the same happens if I convert to PNG, PDF etc.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Aug 22, 2019

@davidanthoff Thanks for sharing. This is a known, long-standing issue as @domoritz mentions. We just don’t (yet) happen to have a clean solution that doesn’t introduce other problems elsewhere. The issue is particularly salient with scalable vector graphics because when you zoom in, what used to be 0.5 pixel offset gets magnified. I’d certainly love to find a solution.

@kanitw what is the problem with the image you shared? Is it that the bars are not perfectly centered? (Keep in mind the time span for each bar is inclusive of its left gridline but not the right gridline…)

0reactions
jheercommented, Aug 27, 2019

@kanitw: That sounds reasonable for many cases, but likely fails as a general rule if the spans get much larger or smaller. In your case the gridlines are stroked (centered between pixels by default) and the bars are filled (pixel aligned by default), so I believe our offset is actually making the alignment better (not worse), by snapping lines to proper pixels. I think the lack of centering arises due to the left-inclusive / right-exclusive span, which should be mathematically correct.

I’ll keep the issue focused on the point / grid alignment issue @davidanthoff raises. In the worst case, I could imagine adding config to control the offset, which at least might be useful for exported images, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How-To: X/Y Offset - Carlson Design
We then need to make sure our Z-axis is properly aligned. Do this by standing directly in front of the cutting head and...
Read more >
Offset alignment in CMM software
A cmm programmer can easily figure out that the angle offset from datum C hole to the main axis is 42.338645 deg. (or...
Read more >
Axis | Vega-Lite
By default, axes are translated by a 0.5 pixel offset for both the x and y coordinates in order to align stroked lines...
Read more >
Ender 3 alignment: problems and solutions - YouTube
Walkthrough of the various issues with adjusting the Creality3D Ender 3 printer. This vid includes several different methods, ...
Read more >
How do I align gridlines for two y-axis scales using Matplotlib?
I could solve it by deactivating ax.grid(None) in one of the ... total tick marks ax1 and ax2 are matplotlib axes Spacing between...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found