Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting binSpacing to 0 still leaves a gap between marks #9308

Open
joelostblom opened this issue Apr 11, 2024 · 2 comments
Open

Setting binSpacing to 0 still leaves a gap between marks #9308

joelostblom opened this issue Apr 11, 2024 · 2 comments
Labels

Comments

@joelostblom
Copy link
Contributor

Bug Description

I was expecting binSpacing=0 to make bars of a histogram flush against each other, but there is still a small gap as can be seen here:

image
Open the Chart in the Vega Editor

The reason for this seems to be the initial 0.5 offset to the x and x2 encoding, as can be seen here:

"x2": {
  "scale": "x",
  "field": "bin_maxbins_10_IMDB_Rating",
  "offset": {
    "signal": "0.5 + (abs(scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating_end\"]) - scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating\"])) < 0.25 ? -0.5 * (0.25 - (abs(scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating_end\"]) - scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating\"])))) : 0)"
  }
},
"x": {
  "scale": "x",
  "field": "bin_maxbins_10_IMDB_Rating_end",
  "offset": {
    "signal": "0.5 + (abs(scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating_end\"]) - scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating\"])) < 0.25 ? 0.5 * (0.25 - (abs(scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating_end\"]) - scale(\"x\", datum[\"bin_maxbins_10_IMDB_Rating\"])))) : 0)"
  }
},

I believe that the 0.5 offset is there to make the default bar spacing centered, which makes sense, but I think we should shift the scale of the binSpacing parameter with 0.5 pixels, so that setting binSpacing=0 means that there will be 0 pixels between the bars. We can do this by subtracting 0.25 from the x2 encoding and adding 0.25 to the x encoding, e.g. (the final value of the if-clause in the example above, would become 0 - 0.25 for x2 and 0 + 0.25 for x (the 0 there is the binSpacing value). We would also need to indicate in the docs that the default value for the binSpacing is actually 1.5 rather then 1px (and increase it accordingly in the code).

To be clear, I think it is nicer with spacing than without in terms of histograms, but for 2D histograms/binned heatmaps, I would sometimes like to remove it and I think it makes more sense if binSpacing=0 corresponds to no gap.

@kanitw I saw that you did some work on the bin spacing in #6256. Does what I'm suggesting above sound reasonable to you? And would the fix be to just shift the binSpacingOffset/binSpacingOffset2 variables here ?

@joelostblom
Copy link
Contributor Author

joelostblom commented Apr 11, 2024

Hmm, this might be a case of the other bug I just posted in #9307. I thought I saw the behavior even when controlling for that, but I can't reproduce it in the VegaEditor any longer. It still reproduces in JupyterLab, but let's solve the other issue first:

image

@joelostblom
Copy link
Contributor Author

One observations that suggests this might indeed be a different issue than #9307 is that I can see the bin gaps "jump around" as I zoom in and out in the browser, while I don't see that for the charts in #9307

recording-2024-04-13_07.44.02.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant